/**
 * <License>
 */
package edu.colorado.csdms.wmt.client.ui;

import java.util.Iterator;

import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import edu.colorado.csdms.wmt.client.control.DataManager;
import edu.colorado.csdms.wmt.client.ui.handler.ModelActionPanelDeleteHandler;
import edu.colorado.csdms.wmt.client.ui.handler.ModelActionPanelHelpHandler;
import edu.colorado.csdms.wmt.client.ui.handler.ModelActionPanelSaveHandler;
import edu.colorado.csdms.wmt.client.ui.handler.ModelActionPanelStatusHandler;

/**
 * Encapsulates a menu of secondary actions on models -- "Save as", "Delete",
 * "Run status", etc.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class MoreActionsMenu extends PopupPanel {

  @SuppressWarnings("unused")
  private DataManager data;
  
  /**
   * Makes a new {@link MoreActionsMenu}.
   * 
   * @param data the DataManager object for the WMT session
   */
  public MoreActionsMenu(DataManager data) {

    super(true); // autohide
    this.getElement().getStyle().setCursor(Cursor.POINTER); // use pointer
    this.data = data;
    this.setStyleName("wmt-PopupPanel");
    
    // A VerticalPanel for the menu items. (PopupPanels have only one child.)
    VerticalPanel menu = new VerticalPanel();
    this.add(menu);

    // Save As
    HTML saveAsButton =
        new HTML(DataManager.FA_SAVE + "Save model as...");
    saveAsButton.setTitle("Save model as...");
    saveAsButton.addClickHandler(new ModelActionPanelSaveHandler(data, true));    
    menu.add(saveAsButton);

    // Delete
    HTML deleteButton = new HTML(DataManager.FA_DELETE + "Delete model...");
    deleteButton.setTitle("Delete model");
    deleteButton.addClickHandler(new ModelActionPanelDeleteHandler(data));
    menu.add(deleteButton);

    // Run status
    HTML statusButton = new HTML(DataManager.FA_STATUS + "View run status...");
    statusButton.setTitle("Status of model run");
    statusButton.addClickHandler(new ModelActionPanelStatusHandler(data));    
    menu.add(statusButton);
    
    // Help
    HTML helpButton = new HTML(DataManager.FA_HELP + "Help");
    helpButton.setTitle("Help on using WMT");
    helpButton.addClickHandler(new ModelActionPanelHelpHandler(data));        
    menu.add(helpButton);
    
    // Apply a style to each button.
    Iterator<Widget> iter = menu.iterator();
    while (iter.hasNext()) {
      HTML button = (HTML) iter.next();
      button.setStyleName("wmt-PopupPanelItem");
    }    
  }
}

@@ -132,16 +132,120 @@
 Cursor;%0A
+import com.google.gwt.event.dom.client.ClickEvent;%0Aimport com.google.gwt.event.dom.client.ClickHandler;%0A
 import c
@@ -279,16 +279,16 @@
 i.HTML;%0A
-
 import c
@@ -1066,16 +1066,49 @@
 r data;%0A
+  private LabelsMenu labelsMenu;%0A
   %0A  /**
@@ -1597,17 +1597,17 @@
 // Save 
-A
+a
 s%0A    HT
@@ -1714,37 +1714,47 @@
 tle(%22Save model 
-as...
+with a new name
 %22);%0A    saveAsBu
@@ -1849,24 +1849,760 @@
 AsButton);%0A%0A
+    // Manage labels%0A    final HTML labelsButton =%0A        new HTML(DataManager.FA_TAGS + %22Manage labels...%22);%0A    labelsButton.setTitle(%22Manage labels set on models%22);%0A    menu.add(labelsButton);%0A    labelsMenu = new LabelsMenu(data);%0A    labelsButton.addClickHandler(new ClickHandler() %7B%0A      @Override%0A      public void onClick(ClickEvent event) %7B%0A        labelsMenu.setPopupPositionAndShow(new PositionCallback() %7B%0A          final Integer x = labelsButton.getElement().getAbsoluteRight();%0A          final Integer y = labelsButton.getAbsoluteTop();%0A          @Override%0A          public void setPosition(int offsetWidth, int offsetHeight) %7B%0A            labelsMenu.setPopupPosition(x, y);%0A          %7D%0A        %7D);%0A      %7D%0A    %7D);%0A    %0A
     // Delet

Add "Manage labels" button to MoreActionsMenu