Click event not firing on label in GWT - java

I have created a click handler on a gwt label, but it fails to fire. Whats wrong? Same method works for other widgets like icon etc.
#UiField Label fileName;
---
---
public void addClickHandler() {
fileName.sinkEvents(Event.ONCLICK);
handler = this.addHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
event.preventDefault();
event.stopPropagation();
Window.alert("UI clicked");
}
}, ClickEvent.getType());
}

As I pointed out in comment. Reason why it is not working is because you are adding native event handler to this, and as i but you need to sink DOM events on element to be able to handle them. As you did not do this for this element but for Label it won't work.
As You want to handle click element on Label, you need to add your handler to fileName and that will work

Related

JavaFX: ImageView on setOnDragDropped not triggering

I am using SceneBuilder to develop a JavaFX application. I have ImageView object and setOnDragDropped is not triggering. I am not getting any errors. For onDragDetected everything is working. I tried these two options: 1) to set it from the SceneBuilder (see the screenshot)
Second way was from the controller code:
#FXML public void sensorDrop(DragEvent event) {
System.out.println("Drooooop!>>");
event.consume();
//TODO More useful code
}
Any thoughts?
The onDragDropped handler is called when you drop something onto the node with which it is registered, not when you drop that node on something. So you need to register the onDragDropped handler on the stack pane.
To make it complete- in order to register it the setOnDragOver has to be registered
label.setOnDragOver(new EventHandler <DragEvent>() {
public void handle(DragEvent event) {
event.acceptTransferModes(TransferMode.ANY);
event.consume();
}
});
I took this answer from:
JavaFX OnDragDropped Not Registering

SWT selection event after deleting selection

I'm making a simple menu to delete items on a tree. However, after deleting the items, the tree does not receive a selection event, therefore, the code in the listener does not execute (the listener, in the full code, updates a part of the UI).
I have simplified the code below, leaving out details. It is something like this:
tree.addListener (SWT.Selection, new Listener(){
public void handleEvent(Event e) {
(....)
}
}
I also tried this:
tree.addSelectionListener (new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e){
(...)
}
public void widgetSelected(SelectionEvent e) {
(...)
}
}
On my menu action (delete selection), there is this:
TreeItem [] selected = tree.getSelection();
tree.deselectAll();
if (selected.length > 0)
{
for( TreeItem i : selected){
i.dispose();
}
}
After deleting the selection, my selection listener does not fire. It does fire if I deselect all itens using the ctrl+click combination.
What should I do? Is there a way to fire the SWT.Selection event to the tree after deleting the itens or should I isolate the code inside the listener to call it again? Shouldn't the tree.deselectAll() fire a Selection event?
You can send a selection event programmatically with:
Event event = new Event();
event.widget = tree;
event.display = tree.getDisplay();
event.type = SWT.Selection;
tree.notifyListeners(SWT.Selection, event);
Have same situation and found
this link mentioning, that programmatically setSelection may never send this event due to design, so always send it (if needed) programmatically after setting too

Vaadin popup should show and hide in the click event makes no appear popup

Having a
public void buttonClick(ClickEvent event) {
MyPopup popup = new MyPopup();
getWindow().addWindow(popup);
log.warn("Added POPUP");
//lot of method calling here then
getWindow().removeWindow(popup);
log.warn("Removed Popup");
}
I would expect to show a popup window and after some milisecundom (after the expensive method calls) it should hide itself. The log says :
2014-02-19 15:26:51 WARN xyzClass:82 - Added POPUP
2014-02-19 15:26:51 WARN xyzClass:135 - Removed Popup
But the truth is that there is no popup showing here.
If i only show it, and not remove it later (the popup will show)
public void buttonClick(ClickEvent event) {
MyPopup popup = new MyPopup();
getWindow().addWindow(popup);
log.warn("Added POPUP");
//lot of method calling here then
log.warn("Removed Popup");
}
My main reason for this i want to achieve a glasspanel/loading screen functionality # Vaadin, and not had found better solution yet. Any solution/description why the popup not shown up i would appreciate
Just do not have time to render it. You add it and immediately remove.
Try this approach, for example:
private MyPopup popup;
public void buttonClick(ClickEvent event) {
Thread workThread = new Thread() {
#Override
public void run() {
// some initialization here
getWindow().removeWindow(popup);
}
};
workThread.start();
popup = new MyPopup();
getWindow().addWindow(popup);
}
Depending on Vaadin version you can make use of ICEPush plugin (Vaadin 6) or built-in feature called Server Push (Vaadin 7).
public void buttonClick(ClickEvent event) {
MyPopup popup = new MyPopup();
getWindow().addWindow(popup);
log.warn("Added POPUP");
// start background thread with ICEPush or ServerPush
}
// Background thread in a separate class
// update UI accordingly when thread finished the job
getWindow().removeWindow(popup);
log.warn("Removed Popup");
Thanks to it you can move your time-consuming operations to another class thus decouple your business logic from the presentation layer. You can find examples of usage in the links above.

GWT addSubmitCompleteHandler called twice

I have a form panel (myForm) with a submit button added onto a simple panel. Every time the submit is pressed myForm.addSubmitCompleteHandler is called twice
mySubmit.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
myForm.submit();
}});
...
myForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {
#Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// what ever's here happens twice
}
});
I've double checked my code and ordering and placing of widgets and panels. What could possibly be causing this?
What I am trying to achieve is an alert that submission is complete.
It seems like adding the line
event.preventDefault()
in the addClickHandler of the submit button helps. Also make sure you don't have duplicate setAction Calls for the form

GWT:adding clickHandler on HyperLink

I am having this HyperLInk in my cellTable ,but its Clickhandler is not working
myHyperLInk.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("test");
}});
It displays a warning :
The method addClickHandler(ClickHandler) from the type Hyperlink is
deprecated
When i click on the link, it simple go to the previous page from history. How can i simply say show a message dialog on pressing a hyperLink?
I think what you want may be an anchor widget vs a hyperlink.
http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/user/client/ui/Anchor.html
Hyperlinks are usually used for working with the history.
Hyperlink link0 = new Hyperlink("link to foo","foo");
link0.addDomHandler(handler, ClickEvent.getType());
ClickHandler handler = new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("test");
}
};

Categories

Resources