/*
* Copyright 2008 Sander Berents
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.gwtlib.samples.menu.client.ui;
import org.gwtlib.client.menu.ui.MenuBar;
import org.gwtlib.client.menu.ui.MenuItem;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
/**
* An example demonstrating the menu with toggle support.
*
* @author Sander Berents
*/
public class MenuBarEntryPoint implements EntryPoint {
private static final String ID = "gwtlib-menubar";
public void onModuleLoad() {
RootPanel root = RootPanel.get(ID);
if(root != null) init(root);
}
private void init(RootPanel root) {
MenuItem item;
Command command = new Command() {
public void execute() {
Window.alert("Click");
}
};
MenuBar menu = new MenuBar();
MenuBar file = new MenuBar(true);
MenuBar edit = new MenuBar(true);
MenuBar view = new MenuBar(true);
menu.addItem("File", file);
MenuItem editItem = (MenuItem)menu.addItem("Edit", edit);
menu.addItem("View", view);
item = (MenuItem)menu.addItem("Help", command);
item.setEnabled(false);
file.addItem("Open", command);
file.addItem("Close", command);
file.addItem("Save", command);
file.addItem("Exit", command);
edit.addItem("Undo", command);
edit.addItem("Redo", command);
edit.addItem("Cut", command);
edit.addItem("Copy", command);
edit.addItem("Paste", command);
editItem.setEnabled(false); // Disable after adding children so they get disabled too
view.addItem("Date", true, command, MenuItem.Type.CHECK, false);
view.addItem("Time", true, command, MenuItem.Type.CHECK, true);
view.addSeparator();
view.addItem("Radio 1", true, command, MenuItem.Type.RADIO, false);
view.addItem("Radio 2", true, command, MenuItem.Type.RADIO, true);
view.addSeparator();
view.addItem("Radio 3", command, MenuItem.Type.RADIO, false, 1);
view.addItem("Radio 4", command, MenuItem.Type.RADIO, true, 1);
view.addSeparator();
view.addItem("Description", command, MenuItem.Type.CHECK, false);
view.addItem("Quantity", command, MenuItem.Type.CHECK, true);
view.addSeparator();
item = (MenuItem)view.addItem("Disabled", (Command)command, MenuItem.Type.INDENT);
item.setEnabled(false);
item = (MenuItem)view.addItem("Enabled", (Command)command, MenuItem.Type.INDENT);
item.setEnabled(false);
item.setEnabled(true);
root.add(menu);
}
}