// Sample code file: OnLineUserSnapin.java

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

/*
   Copyright (c) 2000 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.Chat;

// Java and Swing imports
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;

// ConsoleOne imports
import com.novell.application.console.snapin.*;

/**
 * This class provides both a toolbar and menu snapin for Chat.
 * This button and menu item display the On-Line Chat Users dialog.
 * Since the purpose of the toolbar button and the menu item is 
 * the same, they have both been included in this class as an
 * AbstractToolBarMenuSnapin.
 */
public class OnLineUserSnapin extends AbstractToolBarMenuSnapin implements SnapinListener
{        
    /**
     * Reference to the ConsoleOne shell.
     */
    private Shell shell;
    
   /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's name.
    */
   public String getSnapinName()
   {
      return Chat.chatRes.getString("OnLineUserSnapin_Name");
   }

        /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's description.
    */
   public String getSnapinDescription()
   {
      return Chat.chatRes.getString("OnLineUserSnapin_Description");
   }

        /**
    * Implementation of the AbstractToolBarMenuSnapin Class
    *
    * This method is called by the shell to allow each snap-in to perform 
    * any necessary initialization; for example adding itself as an event 
    * listener. The snap-in is initialized by passing a reference to the 
    * InitSnapinInfo class. The getSnapinName() and getSnapinDescription() 
    * methods will be called before initSnapin().
    *
    * @param info 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. 
    * @return     If the snap-in is able to successfully complete initialization, 
    *             true is returned, or if initialization fails, false is returned 
    *             and the snap-in will be disabled. 
    */
        public boolean initAbstractSnapin(InitSnapinInfo info)
    {
            shell = info.getShell();
            shell.addSnapinListener(this, new String[]{Chat.EVENT_INIT_COMPLETE});
            setEnabled(Chat.getInstance().isInitialized());
                        
            return true;
    }

   /**
    * Implementation of the AbstractToolBarMenuSnapin Class
    *
    * Called by the shell when the snap-in is being shut down. 
    * Called by the shell for each snap-in when it is no longer required. 
    * This allows the snap-in to perform any necessary cleanup; for example
    * removing itself as an event listener. 
    */
   public void shutdownAbstractSnapin()
   {
       shell.removeSnapinListener(this);
   }
   
   /**
    * Implementation of the AbstractToolBarMenuSnapin Class
    *
    * Returns the icon to be displayed in the toolbar button. 
    *
    * @return The toolbar Icon.
    */
   public Icon getIcon()
   {
       return Chat.getInstance().getIcon("OnlineUsers");    
   }

   /** 
    *Implementation of the AbstractToolBarMenuSnapin Class
    *
    * Returns the language dependent translated menu 
    * display name as a String to be placed in the menu item. 
    *
    * @return The Menu name.
    */
   public String getMenuName()
   {
       return Chat.chatRes.getString("On-line Users Menu");
   }
   
   /** 
    *Implementation of the AbstractToolBarMenuSnapin Class
    *
    * Returns the localized string to be placed in the tool tip 
    * that will be displayed with the toolbar item. 
    *
    * @return The tool tip.
    */
   public String getToolTip()
   {
       return Chat.chatRes.getString("On-line Users Button Tooltip");
   }


   /**
    * AbstractToolBarMenuSnapin implementation
    *
    * @return The menu under which this item will be listed.
    */
        public String getMenuLocation()
        {
            // We'll place this on the Tools->Chat menu. 
            // Since the Chat menu doesn't exist, it will be created by ConsoleOne.
                return "Tools%Chat";
        }      
        
   
   /**
    * AbstractToolBarMenuSnapin implementation.  
    *
    * This is what is called when our menu item or toolbar button
    * is selected.  The same thing will happen regardless of 
    * whether a menu item is selected or a toolbar button is pressed.
    */
   public void execute()
   {
       Chat.getInstance().showOnlineUsersDialog();  
   }
   
   /**
    * Implementation of the SnapinListener Interface.
    *
    * Called when chat's initialization has completed.
    */
   public void snapinListener(SnapinEvent event)
   {
       setEnabled(true);
   }

}