Here is my code:
public void onModuleLoad() {
Tree staticTree = new Tree() {
@Override
public void onBrowserEvent(Event event) {
Element el = event.getEventTarget().cast();
if (el == null)
return;
switch (event.getTypeInt()) {
case Event.ONCLICK:
for (int i = 0; i < getItemCount(); i++) {
TreeItem treeItem = getItem(i);
TableElement table = getTableElement(treeItem);
if (table != null) {
NodeList<Element> nodeList = table.getElementsByTagName("div");
if (nodeList.getLength() > 0)
if (el.equals(nodeList.getItem(0))) {
treeItem.setState(!treeItem.getState());
break;
}// end if
}// end if
}// end for
break;
}// end switch
super.onBrowserEvent(event);
}// end onBrowserEvent
private final TableElement getTableElement(TreeItem treeItem) {
return (TableElement) treeItem.getElement().getFirstChildElement();
}// end getTableElement
};
TreeItem item1 = staticTree.addTextItem("Item 1");
item1.addTextItem("Item 1 - 1");
item1.addTextItem("Item 1 - 2");
item1.setStyleName("parent");
DOM.getFirstChild(item1.getElement()).addClassName("nocross");
TreeItem item2 = staticTree.addTextItem("Item 2");
item2.addTextItem("Item 2 - 1");
item2.addTextItem("Item 2 - 2");
item2.setStyleName("parent");
DOM.getFirstChild(item2.getElement()).addClassName("nocross");
Tree t = new Tree();
t.addItem(item1);
t.addItem(item2);
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(t);
}
Le dimanche 28 juillet 2013 13:12:25 UTC+2, michelin pierre a écrit :
--Hello, I want to replace the cross event by clicking on the parent item: It is possible to open the menu on click on the treeitem parent (like click on the little cross on the left)?
Concretely in the example below, by clicking on "Item 1" will open the menu, by clicking a second time closes the menu.
Is there a solution?
String[] composers = new String[]{"Item 1","Item 2","Item 3"}; Resources treeResource = GWT.create(TreeResources.class
); Tree staticTree = new Tree(treeResource); TreeItem item1 = staticTree.addTextItem(composers [0]); TreeItem item2 = staticTree.addTextItem(composers [1]); // add sub items addItemSection(item1, "item 1 - 1",new String[]{}); addItemSection(item1, "item 1 - 2", new String[]{}); addItemSection(item2, "item 2 - 1",new String[]{}); addItemSection(item2, "item 2 - 2", new String[]{}); addItemSection(item2, "item 2 - 3", new String[]{}); TreeItem item = new TreeItem(); item1.addItem(item); item2.addItem(item); Tree t = new Tree(); t.addItem(item1); t.addItem(item2); private void addItemSection(TreeItem parent, String label, String[] composerWorks) { TreeItem section = parent.addTextItem(label); for (String work : composerWorks) { section.addTextItem(work); } }The result:
+ Item 1
Item 1-1
Item 1-2ANd it would be nice if could hide the cross in the left.
Thanks in advance
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment