/*
* SmartGWT (GWT for SmartClient)
* Copyright 2008 and beyond, Isomorphic Software, Inc.
*
* SmartGWT 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. SmartGWT 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.
*/
package com.smartgwt.sample.showcase.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuButton;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.ItemClickEvent;
import com.smartgwt.client.widgets.menu.events.ItemClickHandler;
public class Showcase implements EntryPoint {
public void onModuleLoad() {
RootPanel.get().add(getViewPanel());
}
public Canvas getViewPanel() {
Canvas main = new Canvas();
Menu mDepartment = new Menu();
mDepartment.setCanSelectParentItems(true);
mDepartment.setData(getLocalItemsAsArray());
mDepartment.setWidth(130);
mDepartment.addItemClickHandler(new ItemClickHandler() {
public void onItemClick(ItemClickEvent event) {
SC.say("You picked the \"" + event.getItem().getTitle()
+ "\" department.");
}
});
MenuButton bDepartment = new MenuButton("Go to department", mDepartment);
bDepartment.setWidth(130);
main.addChild(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.");
}
});
MenuButton bCategory = new MenuButton("Go to category", mCategory);
bCategory.setTop(30);
bCategory.setWidth(140);
main.addChild(bCategory);
return main;
}
private MenuItem[] getLocalItemsAsArray() {
MenuItem[] m = new MenuItem[4];
m[0] = new MenuItem("Marketing");
Menu menuMarketing = new Menu();
menuMarketing.setData(new MenuItem("Advertising"), new MenuItem("Community Relations"));
m[0].setSubmenu(menuMarketing);
m[1] = new MenuItem("Sales");
Menu menuSales = new Menu();
menuSales.setData(new MenuItem("Direct Sales"),new MenuItem("Channel Sales"));
m[1].setSubmenu(menuSales);
m[2] = new MenuItem("Manufacturing");
Menu menuManufacturing = new Menu();
menuManufacturing.setData(new MenuItem("Design"), new MenuItem("Development"), new MenuItem("QA"));
m[2].setSubmenu(menuManufacturing);
m[3] = new MenuItem("Services");
Menu menuServices = new Menu();
menuServices.setData(new MenuItem("Support"), new MenuItem("Consulting"));
m[3].setSubmenu(menuServices);
return m;
}
}
class SupplyCategoryXmlDS extends DataSource {
private static SupplyCategoryXmlDS instance = null;
public static SupplyCategoryXmlDS getInstance() {
if (instance == null) {
instance = new SupplyCategoryXmlDS("supplyCategoryDS");
}
return instance;
}
public SupplyCategoryXmlDS(String id) {
setID(id);
setRecordXPath("/List/supplyCategory");
DataSourceTextField itemNameField = new DataSourceTextField("categoryName", "Item", 128, true);
itemNameField.setPrimaryKey(true);
DataSourceTextField parentField = new DataSourceTextField("parentID", null);
parentField.setHidden(true);
parentField.setRequired(true);
parentField.setRootValue("root");
parentField.setForeignKey("supplyCategoryDS.categoryName");
setFields(itemNameField, parentField);
setDataURL("ds/test_data/supplyCategory.data.xml");
setClientOnly(true);
}
}
SmartGWT.zip( 9,880 k)