Vaadin everything shifts after changing view - java

If I change the view from my main menu to another page and then return to my main menu somehow everything on my main menu page shifts to the top left by a about one centimeter. I dont know if I'm missing something?
This is the constructor for my main menu:
public MainMenuView() {
lHeader.setWidth(null);
addButton.setWidth("100px");
addButton.setHeight("100px");
searchButton.setWidth("100px");
searchButton.setHeight("100px");
editButton.setWidth("100px");
editButton.setHeight("100px");
vLayout.addComponent(buttons);
this.setCompositionRoot(vLayout);
buttons.setComponentAlignment(lHeader, Alignment.MIDDLE_CENTER);
addMerchant.setStyleName("mystyle");
showMerchants.setStyleName("mystyle");
merchantSearch.setStyleName("mystyle");
lHeader.addStyleName("mylabelstyle");
addButton.setStyleName("addButtonStyle");
searchButton.addStyleName("searchButtonStyle");
editButton.addStyleName("editButtonStyle");
addLabel.addStyleName("add");
searchLabel.addStyleName("search");
editLabel.addStyleName("edit");
addButton.addClickListener(e -> addMerchant());
editButton.addClickListener(e -> showMerchants());
searchButton.addClickListener(e -> merchantSearch());
}

It is occurred when some styles are duplicated in your first and second pages.
/you need to check them./
You need to check Scope type of your components. /Maybe it will occur when you use any UI component that annotated #SessionScope
How you managed routing between these 2 pages.

Related

JavaFX: How to set a listener to the TabPane header onClick event

This is a weird question so I'll make my best to explain myself properly.
What I'd like is to trigger an event when a Tab in a TabPane get clicked, and by "clicked" I mean just clicked, not necessarily selected.
I already tried using the selectedProperty of the Tab, but that does call the event only if the Tab is clicked when it's not selected, not even if it's clicked when it's already selected.
The reason why I'm doing this is that I'm trying to make a collapsible tab pane that hides the content of the TabPane if you click again on the opened tab, I've already wrote the code for collapsing the TabPane and that works but... I have no idea on how to get a click event from the tab header.
I've even looked into TabPane source code too hoping that I could find the tab header container but I didn't find it there.
No need for a completely new skin - we can access the header nodes by lookup. Beware: implies relying on implementation details, which might change across versions.
The (undocumented!) style id to look for is ".tab-container" - that's the only child of the TabHeaderSkin (== region for a single tab header). It contains the label, the close button (if any) and the focus marker. This "skin" keeps a reference to its tab in its properties (undocumented, of course ;)
So the basic approach is to
lookup all tab-containers after the skin is installed
for each, register an appropriate mouse handler on its parent
on the respective mouseEvent, do whatever is needed
Note that the listeners have to be removed/added when the list of tabs is modified (not included in the snippet below).
In example code:
/**
* looks up the styled part of tab header and installs a mouseHandler
* which calls the work load method.
*
* #param tabPane
*/
private void installTabHandlers(TabPane tabPane) {
Set<Node> headers = tabPane.lookupAll(".tab-container");
headers.forEach(node -> {
// implementation detail: header of tabContainer is the TabHeaderSkin
Parent parent = node.getParent();
parent.setOnMouseClicked(ev -> handleHeader(parent));
});
}
/**
* Workload for tab.
* #param tabHeaderSkin
*/
private void handleHeader(Node tabHeaderSkin) {
// implementation detail: skin keeps reference to associated Tab
Tab tab = (Tab) tabHeaderSkin.getProperties().get(Tab.class);
System.out.println("do stuff for tab: " + tab.getText());
}

How to perform custom navigation through JFace Eclipse Wizard pages?

I have Eclipse JFace wizard with five pages. In the first, I have check buttons to select which pages are to be shown - if you check all, you will pass through the whole wizard, but you can also select only specific pages, and then only that pages will be shown.
So far, I used iterator with enum objects representing each page. I called next object of iterator in getNextPage function and its if..else cases to return certain pages in proper order. The problem is, getNextPage is called not only when Next button is pressed, but also when pageComplete event firing, etc. so iterator does not update its cursor when I want, and it ends up to fast. This is snippet of my assumption:
else if(page == FirstPage )
{
// iterator contains SelectedAction - enum objects representing pages
this.pageIterator = page.getWizardPagesList().iterator();
if(pageIterator.hasNext())
{
return selectedActionToPage(pageIterator.next());
}
}
else
{
if(pageIterator.hasNext())
{
SelectedAction action = pageIterator.next();
if(!pageIterator.hasNext())
{
// we check if current page was last one
setFinished(true);
setLastPage(selectedActionToPage(action));
}
// selectedActionToPage converts enum object to WizardPage class
return selectedActionToPage(action);
}
else if((pageIterator != null) && !pageIterator.hasNext())
{
return page;
}
}
return page;
Especially, things I want to know are:
First, is there any other way to capture Next button click? I know there is NextPressed method in WizardDialog class, but I don't know how to call its instance from my Wizard class, or WizardPage.
Second, is there other way to customize navigation through pages, to go to specified pages?
No, you should not try to intercept the Next button click that logic is private to the wizard dialog and you should not be trying to interfere with it,
You can either override the WizardPage:
public IWizardPage getNextPage()
method or you can override the Wizard
public IWizardPage getNextPage(IWizardPage page)
You may also need to override the matching getPreviousPage method. You must make your code work regardless of when the method is called. You are given the information about which is the current page, your code should use that to determine the next page.

Validator in ControlsFX Wizard last page

Is there any way of adding a Validator to the last page in ControlsFX Wizards?
I am currently using the following on the last page :
public void onEnteringPage(Wizard wizard) {
wizard.getValidationSupport().registerValidator(cb,
Validator.createEmptyValidator("The instance field is mandatory"));
But since this is the last page I am still able to click finish when the cb(choice box) is empty.
I had the same problem.
I think this is due to a bug in version 8.40.9 of ControlsFX where they forgot to check the FINISH Button against the invalid property, too.
Look here in the Issue Issue 521 at line 633. They have added the necessary call. Just wait for the next update, when the issue will be merged.
For a quick and dirty workaround just add another pane to your wizard. With a text "Finished" for example, because on the "next" buttons the validation works.

How can I navigate the view menu using SWTBot?

Is it possible to the view menu using SWTBot? An example of an view menu is the one of Problems view (see screenshot). For example how can I change the grouping to Type using SWTBot? I've tried:
for (final SWTBotViewMenu a : this.bot.viewById("org.eclipse.ui.views.ProblemView").menus()) {
System.out.println(a.getText());
}
this.bot.viewById("org.eclipse.ui.views.ProblemView").toolbarDropDownButton("View Menu").menuItem("Group By").menu("None").click();
The for loop doesn't give anything at all, and the second one gives an error, that the "View Menu" cannot be found. I have no idea how to navigate this menu ?
It's probably too late for the OP, but here goes:
For some reason, the straight-forward way to activate a view like "Problems" doesn't work. You can use this workaround:
this.bot.menu("Window").menu("Show View").menu("Problems").click();
SWTBotView problemsView = bot.activeView();
This will only help with the first part, though. You now have access to the toolbar buttons via:
List<SWTBotToolbarButton> toolbarButtons = problemsView.getToolbarButtons();
For the Problems view, this gives you access to the "Focus on active task" button, but the three buttons in the cornern, "view menu", "minimize" and "maximize" do not appear in this list. Unfortunately, I have no solution for this as of now.
[Edit]
You can bring up the view menu like that:
this.bot.menu("Window").menu("Navigation").menu("Show View Menu").click();
but I don't know how to select an item from it afterwards. Maybe someone else will know...
try this:
SWTBotView view = bot.viewByTitle("MyView");
view.show();
view.viewMenu().menu("MyContextOption").click();
The problem come from the fact that this menu is populated with dynamic entries. SWTBot doesn't handle this kind of entry.
See ViewMenuFinder.getMenuItem(). Different kind of IContributionItem are handled but in the situation of the Problems View, the items are of type DynamicMenuContributionItem.
I think you can try with:
theView.viewMenu().menu("Group By").menu("Type").click();
I am able to do the same thing with SWTBot 2.8.0 for Project Explorer view

Expand and select node in Ext GWT 3.0 Tree

I've added an accordion layout container with a tree in its first content pane to my layout. No, a requirement calls to expand and select one node when the application is loaded (it's a mockup).
Then I've added this to the constructor of the class, that corresponds with the uibinder layout:
widget = uiBinder.createAndBindUi(this); // everything's bound
accordionLayoutContainer.setActiveWidget(firstPanel); // OK, expands first pane
tree.getSelectionModel().select(mynode, true); // no visible effect
tree.setExpanded(mynode, false); // no visible effect
What's missing here? Do I have to force the layout of "something" after setting the states or is it the wrong place to select and expand nodes?
Found the solution. The call to setExpand has to be deferred until the tree has been attached. So I added an AttachEvent.Handler to a parent widget - adding it to directly to the tree doesn't work, because the handler is called to early, before the models are registered.
widget = uiBinder.createAndBindUi(this); // everything's bound
accordionLayoutContainer.setActiveWidget(firstPanel); // OK, expands first pane
accordionLayoutContainer.addAttachHandler(new AttachEvent.Handler() {
#Override
public void onAttachOrDetach(AttachEvent event) {
clientsTree.getSelectionModel().select(mynode, true);
clientsTree.setExpanded(mynode, true);
}
});

Categories

Resources