/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.layout.HStack; import com.smartgwt.client.widgets.layout.VStack; import com.smartgwt.client.widgets.menu.IMenuButton; import com.smartgwt.client.widgets.menu.Menu; import com.smartgwt.client.widgets.menu.MenuItem; import com.smartgwt.client.widgets.menu.events.ItemClickEvent; import com.smartgwt.client.widgets.menu.events.ItemClickHandler; import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeNode; import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS; import com.google.gwt.core.client.EntryPoint; public class MenuTreeBindingSample implements EntryPoint { public void onModuleLoad() { VStack vLayout = new VStack(10); Menu mDepartment = new Menu(); mDepartment.setCanSelectParentItems(true); mDepartment.setData(getLocalItemsAsTree()); mDepartment.setWidth(130); mDepartment.addItemClickHandler(new ItemClickHandler() { public void onItemClick(ItemClickEvent event) { SC.say("You picked the \"" + event.getTreeNode().getName() + "\" department."); } }); IMenuButton bDepartment = new IMenuButton("Go to department", mDepartment); bDepartment.setWidth(160); vLayout.addMember(bDepartment); Menu mCategory = new Menu(); mCategory.setCanSelectParentItems(true); mCategory.setDataSource(SupplyCategoryXmlDS.getInstance()); mCategory.setWidth(130); mCategory.addItemClickHandler(new ItemClickHandler() { public void onItemClick(ItemClickEvent event) { MenuItem item = event.getItem(); SC.say("You picked the \"" + item.getAttributeAsString("categoryName") + "\" category."); } }); IMenuButton bCategory = new IMenuButton("Go to category", mCategory); bCategory.setWidth(160); vLayout.addMember(bCategory); HStack layout = new HStack(); layout.setWidth100(); layout.setMembers(vLayout); layout.draw(); } private Tree getLocalItemsAsTree() { Tree retVal = new Tree(); TreeNode[] treeNodes = new TreeNode[4]; treeNodes[0] = new TreeNode("Marketing"); Tree menuMarketing = new Tree(); menuMarketing.setData(new TreeNode[]{new TreeNode("Advertising"), new TreeNode("Community Relations")}); treeNodes[0].setChildren(menuMarketing.getAllNodes()); treeNodes[1] = new TreeNode("Sales"); Tree menuSales = new Tree(); menuSales.setData(new TreeNode[]{new TreeNode("Direct Sales"), new TreeNode("Channel Sales")}); treeNodes[1].setChildren(menuSales.getAllNodes()); treeNodes[2] = new TreeNode("Manufacturing"); Tree menuManufacturing = new Tree(); menuManufacturing.setData(new TreeNode[]{new TreeNode("Design"), new TreeNode("Development"), new TreeNode("QA")}); treeNodes[2].setChildren(menuManufacturing.getAllNodes()); treeNodes[3] = new TreeNode("Services"); Tree menuServices = new Tree(); menuServices.setData(new TreeNode[]{new TreeNode("Support"), new TreeNode("Consulting")}); treeNodes[3].setChildren(menuServices.getAllNodes()); retVal.setData(treeNodes); return retVal; } @Override protected boolean shouldWrapViewPanel() { return true; } }