Thanks Brian, I will give this a try. But it make sense when I read your comment.
On 15 okt, 00:52, Brian <hibr...@gmail.com> wrote: > aEvent.getSelectedItem() retuns a TreeItem, not a String. So in your > onSelection() method, you want to do something else than compare it > with a string literal. For instance.. > > aItem.addItem("Item 1"); > TreeItem cs = new TreeItem("Item 2"); > cs.setUserObject("Configured Solutions"); > aItem.addItem(cs); > ... > aTree.addSelectionHandler(new SelectionHandler<TreeItem>() { > public void onSelection(SelectionEvent<TreeItem> aEvent) { > String userObj = (String) aEvent.getSelectedItem().getUserObject(); > if (userObj != null && userObj.equals("Configured Solutions")){ > Window.alert("Hello Adis"); > } > > } > > On Oct 14, 5:27 pm, SeniorBeginner <adis.asm...@gmail.com> wrote: > > > Hi all, > > > I spend 2 hours searching for a way to get the SelectionHandler to > > work but it fails... > > Can you please help me out?? > > > Here is my code that I use: > > > @Override public void onModuleLoad() > > { > > // Create a tree with a few items in it. > > > aItem.addItem("Item 1"); > > aItem.addItem("Item 2"); > > aItem.addItem("Item 3"); > > > // define aTree and add the root item to it > > Tree aTree = new Tree(); > > aTree.addItem(aItem); > > > // create Split Layout > > SplitLayoutPanel p = new SplitLayoutPanel(); > > > // add SplitLayout to RootPanel > > RootLayoutPanel.get().add(p); > > > // define the SplitLayout components > > p.addWest(aTree, 200); > > p.addNorth(new HTML("list"), 384); > > p.add(new HTML("list")); > > > // add ItemListener > > aTree.addSelectionHandler(new SelectionHandler<TreeItem>() > > { > > @Override public void onSelection(SelectionEvent<TreeItem> > > aEvent) > > { > > if (aEvent.getSelectedItem().equals("Configured Solutions")) > > { > > Window.alert("Hello Adis"); > > } > > } > > }); > > > /* aTree.addSelectionHandler(new SelectionHandler<TreeItem>() > > { > > @Override public void onSelection(SelectionEvent<TreeItem> > > event) > > { > > Window.alert("Hello SB"); > > } > > });*/ > > } > > > Thanks for your input! > > Regards, > > SB -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.