0
votes

I want to know urgently how to get widget from gwt VerticalPanel that was occured clickEvent. I have a verticalPanel with on or more sub-Widgets (FlexTables). I want to use FlexTable.getCellForEvent(event).getRowIndex(); method. So , firstly I should get FlexTable widget from VerticalPanel firstly. I want to add addClickHandler or DomHandler on this VerticalPanel and when user click on it , I want to retrieve FlexTable widget that userclicked. But I don't want to iterate on verticalPanel and add ClickHandler on each FlexTable widgets. How to develop them ? Any Suggestions would be appreciated. Thanks in advance for careful of my question..

2

2 Answers

1
votes

You can get it by ClickEvent event

    public void onClick(final ClickEvent event) {

    VerticalPanel vp = (VerticalPanel) event.getSource();
    Iterator<Widget> vp = verP.iterator();
    while (vPanelWidgets.hasNext()){
      Widget childWidget = vPanelWidgets.next();
        if (childWidget instanceof FlexTable) {
        ...do stuff with childWidget
  }
  }

}
1
votes

Really my page show list of FlexTables embedded in VerticalPanel. These flexTables were inserted dynamically and there has checkbox in first columns. My trouble is , when users click on any tables and I want to set checkbox in that row to select. When the users click again in it , the checkbox in that row will unchecked. Here my codes.....

        view.getResultPanel().addDomHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            VerticalPanel vpanel = (VerticalPanel) event.getSource();
            for (int i = 0; i < vpanel.getWidgetCount(); i++) {
                Widget childWidget = vpanel.getWidget(i);
                if (childWidget instanceof FlexTable) {
                    FlexTable table = (FlexTable) childWidget;
                    if (table.getCellForEvent(event) != null) { // that will avoid invalid table (that not clicked )
                        int currentRowIndex = table.getCellForEvent(event).getRowIndex();
                        Element elem = table.getCellFormatter().getElement(currentRowIndex, 0);
                        if ("td".equalsIgnoreCase(elem.getTagName())) {
                            elem = elem.getFirstChildElement();
                        }
                        if ("center".equalsIgnoreCase(elem.getTagName())) {
                            elem = elem.getFirstChildElement();
                        }
                        boolean isChecked = false;
                        if ("".equalsIgnoreCase(elem.getAttribute("checked"))) {
                            elem.setAttribute("checked", "on");
                            isChecked = true;
                        }
                        else if ("on".equalsIgnoreCase(elem.getAttribute("checked"))) {
                            elem.removeAttribute("checked");
                        }
                        if (isChecked) {
                            // Do Something
                        }
                    }
                }
            }
        }
    }, ClickEvent.getType());

At UI view... I create this checkbox like that ..

flxResultTable.setHTML(0, 0, "<center><input type = 'checkbox'/></center>");