Change parent style when clicked on child node via event trigger - event-handling

I have a pane and a text field inside it. I have added mouselistener on pane, so that it changes color when user clicks on it(to mark selection). But the click event is not propagating from child to parent. Hence if I click on the text filed, my parent's color won't change. Is tried to trigger the click event on the parent, but cannot find any working core to trigger event manually.
Is there any way to do this via events, instead of repeating the code inside the handler?
My Event listeners are on the pane(colored container)

Try adding an event filter to the pane, instead of an event handler:
pane.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
// update for selection...
}
});

Related

How to properly pass a single event from one widget to another?

I have two custom widgets:
An output field to display an amount of money
A digital keyboard with number keys to enter an amount
The layout image is here
When a user taps on a number key of the keyboard widget, I want this number to be added to the output field widget. It's just a one-time event for the keyboard and the parent widgets. The pressed number should be added only to the state of the output field's widget, not the parent's widget.
How do I do that properly?
I've implemented this making the output's widget State class public with a public method "onKeyPressed". Then, I use a GlobalKey to make a direct call to that public method when a number on the keyboard is pressed. But this solution seems awkward and going against the UI architecture.

dropdown in dropdown.child trigger parent and it closes

I have a component that opens like dropdown.
In this component I have child component in which I use one more dropdown
and when I click on child component nglDrodownTrigger element, parent component closes.
How can I fix this?

Draggable popup in GWT?

When I use DialogBox to implement Dragable PopupPanel I encounter a problem that when the DialogBox pop up cause The text on the bottom page cannot be copied. How to solve this problem ?
By default DialogBox is modal, which means that:
keyboard and mouse events for widgets not contained by the dialog should be ignored
and thus you can not select nor copy text outside dialog box.
You can change it by calling dialogBox.setModal(false); or by passing modal value to one of the following constructors:
DialogBox(boolean autoHide, boolean modal)
DialogBox(boolean autoHide, boolean modal, DialogBox.Caption captionWidget)

Adding a ClickHandler to the background of a FlowPanel in GWT

I'm new to GWT, and my search queries didn't turn up what I'm looking for, but I'm afraid I'm not phrasing them correctly, so I apologize if this is a simple/duplicate question.
I'm currently trying to figure out how to add a ClickHandler to the area of a FlowPanel that is not occupied by a specific Widget. I know that I can simply add a ClickHandler by wrapping the entire FlowPanel inside a FocusPanel, but that then triggers when any of the widgets inside the flow panel are clicked on. The widgets are typically composite widgets with complicated structures themselves.
My ultimate goal here is to process a click when a user clicks in empty space, but allow the individual widgets to have their own unique click handlers if the user clicks on a specific widget.
Any suggestions?
Thanks!
You have two options.
(A) Add the same click handler to all of your widgets, and then inside onClick perform different actions based on which widget was the source of a click.
(B) Get the mouse position (from ClickEvent), and then iterate through child widgets to see if this mouse position falls inside one of them.

How to override events for extended widgets in gwt?

How would I override events e.g. OnmouseOver, OnMouseOut in extended widgets?
I am trying to extend the Anchor widget and want to set a certain stylename from my CSS.
In this case you could add handlers in you constructor via addMouseOverHandler and addMouseOutHandler and the handlers add/remove your stylenames.
Another option is to override the OnBrowserEvent(Event event) method on catch the mouse over and mouse out events.
However, mouse out events won't work perfect in all browsers. Sometimes the mouse out event is not triggered on the widget and you're style will stay on the widget. If you want to set style on a widget you could also add a yourstylename:hover in you're style sheet, such that you let the browser do the work of adding and removing the stylenames.