I have a checkbox with a valueChangeHandler on it. It works when user check the checkbox.
For some reason, I need to set a value to this checkbox in my code, like this :
checkbox.setValue(true), the checkbox is perfectly checked visually but my problem is that it doesn't fire my valueChangeHandler.
checkBox.setValue(true);
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
#Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
...
}
});
Is there another handler that can be fire when I set a value ? Or another way to dot this?
Thanks
EDIT : I also tried checkbox.setValue(true,true) but it doesn't work.
RESOLVED : the setValue MUST BE after the registration of the handler. Thanks
That's the difference between setValue(Boolean) vs. setValue(Boolean,boolean)
checkBox.setValue(true, true);
Related
How do I clear the selection in my Eclipse RCP application?
Basically I would like to clear it on escape key down:
Display display = PlatformUI.createDisplay();
display.addFilter(SWT.KeyDown, new Listener() {
#Override
public void handleEvent(Event event) {
if (event.character == SWT.ESC) {
// if this is escape key, clear selection in the application
}
}
});
I thought I would be able to do something like PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().clearSelection()/setSelection(IStructuredSelection.EMPTY), but no go.
You need to look up the ISelectionProvider rather than the ISelectionService. That will provide you with a setSelection() method.
You can get the selction provider from the site:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getSelectionProvider();
or
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite().getSelectionProvider();
Note that some of those return values could be null so add the appropriate checks.
You can't clear the selection provided by the selection service directly.
The selection the service returns is provided by a 'selection provider' (ISelectionProvider) for the current part.
You can get the selection provider from an IWorkbenchPart with IWorkbenchPart.getSite().getSelectionProvider().
ISelectionProvider has a setSelection method but it often does nothing or throws an exception so you may not be able to clear the selection.
In GWT I want to handle the click event, but only when user clicks on a day.
There's a valueChangeHandler but it fires when value change, so when I click two times at the same day it will fire once.
Other option is to use addHandler or addDomHandler in which I can add ClickHandler, but it fires always, no matter if I click a day or if I pass to other month.
Both options for me are not functional.
Any ideas how to do it?
Use the addvalueChangeHandler then after that set the value to something else. It's a hack but it works for me.
calendarWidget.addValueChangeHandler(new ValueChangeHandler<Date>() {
#Override
public void onValueChange(ValueChangeEvent<Date> event) {
calendarWidget.setValue(new Date(0));
}
}
Firstly , you should describe more details . I don't know exactly what you really want to do.
Here my advices.
(1). Use Cookies to save infomation of current used user and set expire day to 1day.
(2). Don't use addNewHandler. You should use global variable of one handler instance and initialize it to NULL . At first tought to this , you would be initialized it. That may creat only one time and you can check is it NULL . eg:
private CloseHandler handler;
.......
if (handler == null) {
handler = new CloseHandler<PopupPanel>() {
public void onClose(final CloseEvent<PopupPanel> event) {
........
}
};
}
(3). You can also use simple handler as you with and if fired event to it , save in a Map with current time and unique value (eg:sequence of login user.etc). When after hit it again , you retrive and match the times of both current and previous.
Be useful for you..
You can also add handler on your DateBox.getDatePicker() and your DateBox.getTextBox().
You can add another handlers as like this...
dateBox.addHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("click");
}
}, ClickEvent.getType());
I'm having a problem using a GWT listbox. I have a case where the user selects a value from a listBox, but it can become invalidated if they change data in a related field. To validate the listBox, the user has to either select a new value, or confirm their old selection by selecting the same value again. I can't figure out how to determine if they have selected the same value so that I can restyle the listBox to look validated.
The valueChanged handler only detects if a new value is selected. The clickHandler and focusHandler fire too often because they fire when the user isn't selecting a value. Any ideas?
You can improve the clickHandler with something like this :
ignoreClick = true;
lastSelection = -1 ;
....
listBox.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
if (!ignoreClick) {
lastSelection = listBox.getSelectedIndex();
}
ignoreClick = !ignoreClick;
}
});
I tried it and the event was only fired if you selected an item. But you should rethink your user interface , like said above.
I would like to display all possible values in a SuggestBox.
Naturally, I have the following code (settingName is a SuggestBox)
settingName.getTextBox().addFocusHandler(new FocusHandler() {
#Override
public void onFocus(FocusEvent event) {
settingName.showSuggestionList();
}
});
Unfortunately, the suggestbox displays anything. Of course, the settingName is associated to an oracle with several values inside it.
Am I crazy ?
According to the documentation :
public void showSuggestionList()
Show the current list of suggestions.
You need to set the defaults to show by suggestOracle.setDefaultSuggestionsFromText(..)
When showing the list, the SuggestBox will ask the oracle for values to show. If the text box is empty, then requestDefaultSuggestions will be called (which by default calls requestSuggestions).
How may I block a gwt DisclosurePanel on the open state ?
I mean, how can I prevent this DisclosurePanel to close if the user click the header more than once ?
(My header is a textBox, I want the user to enter a text, and the panel should remain open if the user unfocus the textBox and focus newly by clicking it. The DisclosurePanel content has a "cancel" button that closes the panel)
Thank you very much.
I edit my question after 2 first answers: I would like to avoid to reopen the DisclosurePanel once closed to avoid flashing effect. I actually want to prevent the DisclosurePanel to close. Maybe sinkEvents can help me... if so, how? Thanks.
A NativePreviewHandler receives all events before they are fired to their handlers. By registering a nativePreviewHandler the first time your disclosurePanel is opened, you can cancel the click event. You can later decide to remove this handler by preventClose.removeHandler();
HandlerRegistration preventClose = null;
....
panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (preventClose == null){
preventClose = Event.addNativePreviewHandler(new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt()==Event.ONCLICK && event.getNativeEvent().getEventTarget() == panel.getHeader().getElement().cast())
event.cancel();
}
});
}
}
});
The obvious answer is review the javadoc here: https://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/DisclosurePanel.html
There is a setOpen() method that: Changes the visible state of this DisclosurePanel.
Set it to false from a click event to capture the user action.
The JavaDoc is right here: https://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/DisclosurePanel.html
jamesDrinkard pointed the old 1.5 javadoc.
You can use the addCloseHandler(CloseHandler<DisclosurePanel> handler) method to add a handler so when the user tries to close it you can reopen it again with setOpen().
Maybe not the best way, but it worked for me (maybe just one of both will work too):
dPanel.setOpen(true);
dPanel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});
dPanel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});