I have a Wizard containing two wizard pages (org.eclipse.jface.wizard.WizardPage) and would like to set the focus for each page separately so that always the top input field of each page is focused.
Setting the focus in WizardPage.createControl(Composite), the first page focus is set correctly. The second page does not have a focus.
This is due to Wizard.createPageControls(Composite) which creates all the pages at the beginning.
Where would be the place to handle the focus after switched to the next wizard page?
Override the WizardPage setVisible method and set focus when the page becomes visible:
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
// TODO set focus
}
}
JFace wizards don't offer a designated hook to set the focus. However, as Greg already mentioned, the setVisible() method can be used to set the initial focus of a wizard page.
Usually, the focus of wizard pages should only be set when showing the page for the first time. If a user returns back to a page, the focus should remain where it was when the page was left.
Therefore, I usually guard the focus code so that it is only executed when the page is shown for the first time:
private boolean firstTimeShown = true;
#Override
public void setVisible( boolean visible ) {
super.setVisible( visible );
if( visible && firstTimeShown ) {
firstTimeShown = False;
control.setFocus();
}
}
Related
I have a problem with Wicket Modal Window. I have a Modal Window does a UNIREST call to an external service. The response is used to populate a list. The list is used by a DropDownChoice. The problem is the Wicket Modal Window is inside a repeater, so could happen a page does houndreds of calls to create the modals before the contenitor page is rendered.
class Page{
ListView listView = new ListView(wicket:id, list){
#Override
protected void populateItem(ListItem<Article> item) {
ModalWindow modal = new Modal(){
//the modal inside the constructor do the call to render the DropDownChoice
//and so before the entire page is rendered houndreds of call are done
}
}
}
}
On the browser side this is very bad and make the system very very slow. There is a method to do the call only at the click time, when the modal is effectively shown? There is a method to do asynchronous call to populate the list without Wicket thrown an exception?
I thought to initialize the list with an empty List and at the click time do the CALL and re-render the modal via AJAX. Is it possible? Is it a good way to do so?
I have a VerticalLayout filled with components in Vaadin. PLease i will to print this layout exactly as it is to an A4 paper. Any Idea how to do this, Code Sample will be great.
Straight out of the Vaadin doc…
Printing the Browser Window
Vaadin does not have special support for launching the printing in browser, but you can easily use the JavaScript print() method that opens the print window of the browser.
Button print = new Button("Print This Page");
print.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// Print the current page
JavaScript.getCurrent().execute("print();");
}
});
The button in the above example would print the current page, including the button itself. You can hide such elements in CSS, as well as otherwise style the page for printing. Style definitions for printing are defined inside a #media print {} block in CSS.
There's no "built-in" API for printing in Vaadin.
You have to use the browser's native printing API.
I've created a suggest box and generated HTML page with huge text, so I can scroll.
1. Show suggest list
2. Scroll page
The popup box with suggestion list moves with scrolled page, but I want that it will neither hide when page scrolls nor move with page.
As I understand that suggest popup has absolute position. But is there some non css solution.
Answer to:
I've tried add scroll handler to Window, but I've found out that handle only event when I have and right of them moves, only in this case. If I have one scroll to scroll page like in case with large text - nothing invokes
When constructing a SuggestBox you can provide your own SuggestOracle, TextBox and SuggestionDisplay. DefaultSuggestionDisplay can be used to hide suggestion list. You can do it in Window.scrollHandler.
Here is the code:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
oracle.add("one");
oracle.add("two");
oracle.add("three");
TextBox box = new TextBox();
final DefaultSuggestionDisplay display = new DefaultSuggestionDisplay();
SuggestBox suggestBox = new SuggestBox(oracle, box, display);
Window.addWindowScrollHandler(new ScrollHandler() {
#Override
public void onWindowScroll(ScrollEvent event) {
display.hideSuggestions();
}
});
Note, that you need to use DefaultSuggestionDisplay - see documentation on deprecated hideSuggestionList method.
I hope that the example explains it all.
I've also checked that if you don't use own SuggestionDisplay it uses DefaultSuggestionDisplay anyway. So you can do it even simpler.
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
EDIT:
If not the whole window is scrolled but only content of some panel, you can add a ScrollHandler to the panel:
panel.addDomHandler(new ScrollHandler() {
#Override
public void onScroll(ScrollEvent event) {
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
}
}, ScrollEvent.getType());
I've tried using the new FileDownloader in Vaadin7. Unfortunately, it needs an AbstractComponent for the "extend" component (where it listens for the clicks)
Is there a way to use it with combobox items? As they are not AbstractComponents and thus do not fit with the "extend" method.
The Vaadin forums have discussed this a lot, and there is no scheme now using FileDownloader or the similarly functioning BrowserWindowOpener. They all only work on AbstractComponents, and thus don't work on Action handlers for Table and Tree, or row click handlers on Table, or MenuItem in Menu, etc. The same applies to selected elements in their various select boxes.
You have to revert to the popup window style (so browsers will need to allow popups for it to work) using a regular click/valuechange listener, creating a Resource and passing it to the deprecated, but still working, Page.getCurrent().open(Resource...) method.
Here is my work-around. It works like a charm for me. Hope it will help you.
This example is for the MenuItem, but you can modify for ComboBox.
Create a button and hide it by Css (NOT by code: button.setInvisible(false))
final Button downloadInvisibleButton = new Button();
downloadInvisibleButton.setId("DownloadButtonId");
downloadInvisibleButton.addStyleName("InvisibleButton");
In your theme, add this rule to hide the downloadInvisibleButton:
.InvisibleButton {
display: none;
}
When the user clicks on menuItem: extend the fileDownloader to the downloadInvisibleButton, then simulate the click on the downloadInvisibleButton by JavaScript.
menuBar.addItem("Download", new MenuBar.Command() {
#Override
public void menuSelected(MenuBar.MenuItem selectedItem) {
FileDownloader fileDownloader = new FileDownloader(...);
fileDownloader.extend(downloadInvisibleButton);
//Simulate the click on downloadInvisibleButton by JavaScript
Page.getCurrent().getJavaScript()
.execute("document.getElementById('DownloadButtonId').click();");
}
});
I have a button which opens a pop-up window and an Ajax update panel. Inside that window I have another button.
What code do I have to run if I want that update panel to be refreshed, when I press the button from the parent page, without refreshing the whole page?
I sow this code on a web which refreshes the page:
<div id="Container" onclick="__doPostBack('UpdatePanel1', '');">
I am such a good friend with Java.
You need to utilize window.opener object.
window.opener.document.getElementById('Container').onclick();
I'd suggest using jQuery to ensure cross-browser compatibility. And also adding some null-checks of course.
Use Jquery :
If the DIV ID remains static :
$("#Container").click(function() {
// REFRESH CONTAINER HERE
});
If the Div ID is dynamic then make use of class instead of ID:
$(".Container").click(function() {
// REFRESH CONTAINER HERE
});