Vaadin 14 event propagation - event-handling

I have a Vaadin FlexLayout component, that has a clicklistener added to it, however it has similar FlexLayout children elements, that also have clicklisteners. My problem is that, if I click on the children components, both the parents and the childrens events are fired.
Is there some way to prevent this?

Related

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.

in GWT, How to loop Gui Widget inside a panel?

Let say, I got a VerticalPanel that have some widgets (label, button, ...) that were added into it. How can i loop that VerticalPanel & access the widgets in it?
Well you can use iterator,As i explained in the question How get all widgets of certain type?.
Iterator<Widget> widgets= vpanel.iterator();
Point to remember:
This method only gives the widgets added to the panel.
You have to iterate over child panels also(if its contains).
Or otherwise pick #Manolo's answer from same thread,If you are using GWT third party library GQuery.

How to put gwt panels and widgets in CellList?

I want to put a complex layout with text-fields and operation buttons for each cell in a CellList. So I want to put a GWT panel to organize the widgets.
Is it possible to put gwt panels and widgets in CellList? I tried to extend AbstractCell and override render(). But seems only HTML can be rendered. I didn't find a way to render normal gwt panels and widgets.
CompositeCell seems going through List> automatically, you can not arrange widget as you wish. Also, I don't know whether normal widgets like PushButton can be used in CompositedCell.
Please give me a sample if you tried this before? Thanks a lot.
It is not possible to put GWT widgets or Panels in a CellWidgets.
CellWidgets are designed for rapid rendering of large amounts of data.
If you don't have that use case you can still use a FlexTable.
Otherwise you have to create a CompositeCell or AbstractCell and implement the render and event handling methods yourself.

GWT panels and widgets

Is it safe to conclude the basic relationships among GWT panels and widgets below?
A GWT panel is translated into a parent DOM node that can contain child panels or/and child widgets.
A GWT widget is translated into a leaf DOM node that is merely self-contained.
GWT RootPanel must solely act as the root container of all other panels and widgets.
Here's GWT hierarchy:
A panel is also a widget. Panels are widgets which can contain other widgets and panels. In generally they are used for layout and only rarely have data associated with them directly - the DisclosurePanel for example, can have data in the header, and the TabPanel's tabs. Some are based on an HTML table element(e.g. HorizontalPanel) and some are based on the tag div.
RootPanel is the panel to which contains other widgets. This panel is at the top of the containment hierarchy. The default it wraps tag body of the host-page. RootPanel can contain any number of widgets, which will be laid out in their natural HTML ordering.
See docs.
Every GWT Widget instance has an element (reachable by calling getElement()), and panels are just a kind of Widget - they still have a base element. Most Widgets build more content to do their work (for example: CheckBox is a span with both an input and a label), and panels may need more than one element as well.
Widgets are appended to other widgets not just because this is how the DOM needs to be arranged, but also to track attaching and detaching widgets from the DOM. Among other things, this makes it possible to wire up event handlers only when actually attached, and unwire them when no longer part of the page.
RootPanel is a special widget that represents existing elements, either the body itself, or an element with a given ID. There may be more than one RootPanel, but they should not be nested. (That said, there may only be exactly one RootLayoutPanel, a sort of specialized RootPanel that also handles passing browser size information to child layout panels).
This may be the same idea that you were after, but I wanted to clarify that a Widget is frequently more than a single DOM node.

How do you get GWT 2.0 to accept clicks on two different Widgets added to a LayoutPanel?

Using GWT 2.0 I have an entry point that adds two Widgets to a LayoutPanel which in turn is added to the RootLayoutPanel. The Widgets both handle click events and have click events registered to them. The problem is that only the last widget added to the LayoutPanel can actually be clicked. Switch the order in which the widgets are added switches the widget that works. Add mroe widgets and still the only you can click is the last one added to the LayoutPanel.
Any idea why this is? Is there any reasoning behind the behaviour, or have I missunderstood what is happening under the covers? How do I gat all widgets in the LayoutPanel to accept events? Should I be using another panel class?
I'm not too bothered if the LayoutPanel prevents anything below it from being clicked, but want all Widgets added to it to be clickable.
Stupid Boy! (said in the voice of Captain Mainwaring)
There is no problem having two Widgets on a LayoutPanel accepting clicks. But if you adjust the Widgets' size by manipulating their elements' styles directly then the containing element created by the LayoutPanel will still cover the whole screen. In effect the last Widget added always covered everything else.
GWT school: D- Must try harder. Easily distracted...