// Sample code file: FilesystemPopupMenu.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 popup menu snap-in adds the open and properties
   menu items to the popup menus of all of the items in the file system
   namespace.
  */
public class FilesystemPopupMenu implements PopupMenuSnapin
{
   // variables
   Shell shell = null;
   InitSnapinInfo info = null;

   /*
    Implementation of the PopupMenuSnapin 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 Popup 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 Popup 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();
      this.info = info;
      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 added to
    the popup main.
    */
   public JMenuItem[] getMenuItems()
   {
      // Create a popup menu with two menu items.
      JMenuItem[] items = new JMenuItem[1];

      // Add an example popup menu item.
      items[0] = new DefaultMenuItem("Example");

      // Add an inner-class action listener as a listener that outputs
      // a string on menu selection.
      items[0].addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent event)
         {
            System.out.println("Sample Filesystem menu item selected");
         }
      });

      return items;
   }

   /**
    The getMenuLocation() method will return the location of the items to
    be placed in the current User popup menu hierarchy. If the ancestors returned
    do not exist, they are created. If they do exist, the new popup 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 popup menu to snap into. These keys are defined as the
    ‘action command’ of the popup menu. When defining popup menus items that will
    be snapped into, set the action command of the popup menu, using the
    setActionCommand() method, to be the key that other developers can use to
    register against. For ConsoleOne, the console snap-in's popup menu uses
    the English popup menu name as the key. For this sample popup menu snap-in,
    the popup menu item is placed at the top level because "" is returned.
   */
   public String getMenuLocation()
   {
      return "";
   }
}