/*
 * 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) {
    MenuBar menu = new MenuBar();
    MenuBar file = new MenuBar(true);
    MenuBar edit = new MenuBar(true);
    MenuBar view = new MenuBar(true);
    menu.addItem("File", file);
    menu.addItem("Edit", edit);
    menu.addItem("View", view);
    
    Command command = new Command() {
      public void execute() {
        Window.alert("Click");
      }
    };
    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);
    view.addItem("Date", true, command, MenuItem.CHECK, false);
    view.addItem("Time", true, command, MenuItem.CHECK, true);
    view.addSeparator();
    view.addItem("Description", command, MenuItem.CHECK, false);
    view.addItem("Quantity", command, MenuItem.CHECK, true);
    view.addSeparator();
    MenuItem item = (MenuItem)view.addItem("Disabled", (Command)command, MenuItem.INDENT);
    item.setEnabled(false);
    item = (MenuItem)view.addItem("Enabled", (Command)command, MenuItem.INDENT);
    item.setEnabled(false);
    item.setEnabled(true);

    root.add(menu);
  }
}
@@ -1284,24 +1284,163 @@
 el root) %7B%0D%0A
+    MenuItem item;%0D%0A    Command command = new Command() %7B%0D%0A      public void execute() %7B%0D%0A        Window.alert(%22Click%22);%0D%0A      %7D%0D%0A    %7D;%0D%0A
     MenuBar 
@@ -1608,32 +1608,49 @@
 e%22, file);%0D%0A    
+item = (MenuItem)
 menu.addItem(%22Ed
@@ -1658,24 +1658,53 @@
 t%22, edit);%0D%0A
+    item.setEnabled(false);%0D%0A
     menu.add
@@ -1732,116 +1732,90 @@
     
-%0D%0A    Command command = new C
+item = (MenuItem)menu.addItem(%22Help%22, c
 ommand
-() %7B
+);
 %0D%0A    
- 
- public void execute() %7B%0D%0A        Window.alert(%22Click%22
+item.setEnabled(false
 );%0D%0A    
   %7D%0D
@@ -1806,35 +1806,24 @@
 alse);%0D%0A    
-  
-%7D%0D%0A    %7D;
 %0D%0A    file.a
@@ -2446,33 +2446,24 @@
 tor();%0D%0A    
-MenuItem 
 item = (Menu

Enhance menu sample.