This a request for "Smart GWT 101" guidance on component parent/child navigation, walking the tree, so to speak.
The following code does what I want, but produces components that I can't figure out how to access.
Assuming the code approach is OK so far, I want to be able to access the nested components, perhaps like this?
But the furthest I can seem to get with this approach is
It seems I can avoid the issue by adding each nested ListGrid into a top-level ArrayList,
Ultimately it all goes into the GWT Compiler blender, but I still want to understand the fundamentals of how to properly access nested components in a given lineage. Or why I shouldn't attempt it this way.
Thanks for any guidance.
The following code does what I want, but produces components that I can't figure out how to access.
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.util.KeyCallback; import com.smartgwt.client.util.Page; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.Tab; import com.smartgwt.client.widgets.tab.TabSet; public class HowToAccessNestedComponents implements EntryPoint { DataSource dsAnimals = DataSource.get("animals"); VLayout root; @Override public void onModuleLoad() { root = new VLayout() { { setID("root"); setWidth100(); setHeight100(); } }; // Dynamically supplied Tab Titles, might change during session... String[] arbitraryTabs = { "Carnivore", "Herbivore", "Omnivore" }; root.addMember(makeTabSet(arbitraryTabs)); root.draw(); } /******************** makeTabSet ********************/ private Canvas makeTabSet(String[] arbitraryTabs) { TabSet tabSet = new TabSet() { { setID("tabSetAnimals"); } }; for (String tabName : arbitraryTabs) { tabSet.addTab(makeTab(tabName)); } return tabSet; } /******************** makeTab ********************/ private Tab makeTab(final String tabName) { Tab tab = new Tab(tabName) { { setID("tabName" + tabName); } }; tab.setPane(gainPane(tabName)); return tab; } /******************** gainPane ********************/ private Canvas gainPane(final String tabName) { VLayout pane = new VLayout() { { setID("pane" + tabName); } }; pane.addMember(makeListGrid(tabName)); return pane; } /******************** makeListGrid ********************/ private Canvas makeListGrid(final String tabName) { ListGrid listGrid = new ListGrid(dsAnimals) { { setID("listGrid" + tabName); setInitialCriteria(new Criteria("diet", tabName)); setAutoFetchData(true); } }; return listGrid; } }
Code:
// Pseudo code... Record[] records = root.getMember("tabSetAnimals").getTab("tabCarnivore").getPane("paneCarnivore").getListGrid("listGridCarnivore").getSelectedRecords();
Code:
// Half-Pseudo code... root.getChildren().getsMurkyHere... root.getChildren()[0].getWhat? root.getMember("tabSetAnimals").getLostHere...
Code:
... public class HowToAccessNestedComponents implements EntryPoint { ... ArrayList<ListGrid> gridsList = new ArrayList<ListGrid>(); // * ... private Canvas makeListGrid(final String tabName) { ListGrid listGrid = new ListGrid(dsAnimals) { ... gridsList.add(listGrid); // * ... }
Thanks for any guidance.