// Sample code file: FilesystemMainMenu.java

// Warning: This code has been marked up for HTML

/*
   Copyright (c) 1997-1999 Novell, Inc.  All Rights Reserved.

   THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
   USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT
   ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.
   PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A
   ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
   PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
   DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S
   PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S
   CUSTOMERS WITH RESPECT TO THIS CODE.
*/

package com.novell.sample.snapins.filesystem;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

// ConsoleOne snapin interfaces.
import com.novell.application.console.snapin.*;
import com.novell.application.console.snapin.scope.*;
import com.novell.application.console.snapin.context.*;

  /**
   This example of a main menu snap-in puts two menu items at
   the top level of the menu bar, each with three submenus.
  */
public class FilesystemMainMenu implements MenuSnapin
{
   /** Shell instance */
   private Shell shell = null;

   /*
     Implementation of the MenuSnapin interface.
    */

   /**
    The getSnapinName() method (derived from Snapin interface) is called by
    configurators to display the localized name of this snap-in. It returns
    the translated name for this snap-in. The shell displays the name you
    provide together with all the snap-ins of a given type. The user is then
    allowed to select which snap-ins should be set as active in the current
    configuration. The getSnapinName() method may be called before initSnapin().
    */
   public String getSnapinName()
   {
      return "Novell's Sample Filesystem Namespace MainMenu Name";
   }

   /**
    The getSnapinDescription() method (derived from Snapin interface) is called
    by the configurators to display the localized description information
    about this snap-in. It returns the snap-in description as a String.
    */
   public String getSnapinDescription()
   {
      return "Novell's Sample Filesystem Namespace MainMenu Description";
   }

   /**
    The initSnapin() method initializes this class. You should do any
    onetime initialization here, such as adding event listeners. The method
    returns a boolean set to <i>true</i> if the snap-in is able to successfully
    complete initialization, or <i>false</i> if initialization fails. The 'info'
    parameter contains data the snap-in may use for initialization, such as
    references to the shell and the snap-in type, and may contain a reference
    to snap-in context data.
    */
   public boolean initSnapin(InitSnapinInfo info)
   {
      shell = info.getShell();
      return true;
   }

   /**
    Implement shutdownSnapin() in your extending snap-in if there is
    anything that needs to be cleaned up, such as removing shell event listeners.
    */
   public void shutdownSnapin()
   {
   }

   /**
    The getMenuItems() method should return an array of JMenuItem objects or
    objects derived from JMenuItem (such as JMenu) that are to be placed in
    the ConsoleOne main menu.
    */
   public JMenuItem[] getMenuItems()
   {
      // Build a main menu with two menus. Also leave one space
      // for the insertion point of later snap-in menus.
      JMenuItem[] menuToReturn =  new JMenuItem[3];

      // Create the first menu to be placed on the main menu.
      // Put three menu items in it.
      JMenu menu = new JMenuPlus("Example Menu 1");
      menu.add(new JMenuItem("Snapin submenu 1", KeyEvent.VK_S));
      menu.add(new JMenuItem("Snapin submenu 2", KeyEvent.VK_N));
      menu.add(new JMenuItem("Snapin submenu 3", KeyEvent.VK_A));

      // Add the first menu to the main menu.
      menuToReturn[0] = menu;

      // Add the insertion point to the main menu between the two menu.
      // This means that all menus that are snapped into ConsoleOne
      // after this menu will be inserted here.
      // Shell.MENU_INSERTION_POINT is the placeholder key.
      menuToReturn[1] = new JMenuItem(Shell.MENU_INSERTION_POINT);

      // Create the second menu to be placed on the main menu.
      // also, put three menu items in it.
      menu = new JMenuPlus("Example Menu 2");
      menu.add(new JMenuItem("Snapin submenu 1", KeyEvent.VK_S));
      menu.add(new JMenuItem("Snapin submenu 2", KeyEvent.VK_N));
      menu.add(new JMenuItem("Snapin submenu 3", KeyEvent.VK_A));
      menuToReturn[2] = menu;
      return menuToReturn;
   }

   /**
    The getMenuLocation() method should return the location of the snap-in menu
    item in the main menu hierarchy. If the ancestors returned do not exist,
    they are created. If they do exist, the new menu item is inserted at the
    snap-in point of insertion. Menus in ConsoleOne have locale-independent key
    names that are referred to in the getMenuLocation() method to define what
    menu to snap into. These keys are defined as the ‘action command’ of the menu.
    When defining menus that will be snapped into, set the action command of the
    menu, using the setActionCommand() method, to be the key that other developers
    can use to register against. For ConsoleOne, the console snap-in's main menu uses
    the English menu name as the key. To place items in nested menus, use the % as
    a separator. For example, to snap into the File/New submenu, return File%New
    from the getMenuLocation() method.
   */
   public String getMenuLocation()
   {
      // Insert menu into the top level of the menubar.
      // Top level is specified by returning the empty string.
      return "";
   }
}