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

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.

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.

TabLayoutPanel finish loading event

I use a GWT TabLayoutPanel which contains several Google Charts Widgets.
I want to know if there's a handler/method that can be called once all the widgets in the tab have finished loading.(after I click the tab)
I need this because I refresh/reload the Charts once I click the tab, but the charts MUST be loaded first or the height/width won't apply on the charts.
Any help?
You can get UI widgets by Iterating or something like widget.getElementBytagName(). You should try gwt.Document.DOMHandler. widget.addDomHandler can get to iterate its sub widget or everythings under this widget. Really you don't need to invoke handlers to each widget. Try with DOMHandler. This can be OK. I don't know clearly what you really want to do. Please describe with your codes as you can.

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.

why GWT Cell widgets are fater?

I wanted to know how cell widgets are faster compared normal (old) GWT widgets?
I have gone through the gwt article
Developer's Guide - Cell Widgets
It says
A cell widget renders its user interface as an HTML string, using innerHTML instead of traditional DOM manipulation
Can anyone please explain the above? and How?
In a normal GWT Grid you have to add each Widget separately, which means the browser can not optimize this in any way. Each widget you add also has its own event handler.
So you will create at least one DOM Element per Widget you add and append it into the grid.
CellWidgets first render all childs into a String which is then added to the DOM, by calling setInnerHTML (the browser can optimize this call and add all childs in a batch) and the event handling is only done once by the CellWidget.

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...