import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.naming.*;
import javax.naming.directory.*;
import com.novell.service.server.NWServer;
import com.novell.service.server.ServerVersions;
public class ServerPopupHandler
implements PopupHandler
{
public ServerPopupHandler ()
{
}
public void popupRequested (
JFrame frame,
JPopupMenu popup,
Object obj)
{
Context ctx;
if (obj instanceof ContextTreeNode)
{
ctx = ((ContextTreeNode) obj).getThisContext ();
if ((null != ctx) &&
(ctx instanceof DirContext) &&
(ctx instanceof NWServer))
new NWServerActionListener (obj.toString(), (DirContext) ctx, popup);
}
}
}
class NWServerActionListener
implements ActionListener
{
String serverName;
DirContext serverCtx;
JMenuItem serverMenuItem;
private static int buttonHeight = 25;
public NWServerActionListener () {}
public NWServerActionListener (
String serverName,
DirContext serverCtx,
JPopupMenu popup)
{
this.serverName = serverName;
this.serverCtx = serverCtx;
serverMenuItem = new JMenuItem ("Manage Server");
serverMenuItem.setToolTipText ("NetWare server management functions");
serverMenuItem.addActionListener (this);
popup.add (serverMenuItem);
}
public void actionPerformed (
ActionEvent event)
{
Object object = event.getSource ();
if (object == serverMenuItem)
server_Action (event);
}
void server_Action (
ActionEvent event)
{
ServerMgmtFrame frame = new ServerMgmtFrame (serverName, serverCtx);
Point p = ((Component) event.getSource ()).getLocation ();
p.translate (buttonHeight, buttonHeight);
frame.setLocation (p);
frame.show ();
}
}
class ServerMgmtFrame
extends JFrame
implements ActionListener
{
Context serverCtx;
private static int emptySpace = 5;
private static int buttonHeight = 25;
private static int buttonWidth = 110;
private static int mainPaneHeight = (buttonHeight + emptySpace) * 4;
private static int mainPaneWidth = 400;
private JLabel versionLabel;
private JLabel nlmLabel;
private JTextField nlmTextField;
private JButton loadNLMButton;
private JButton unloadNLMButton;
private JButton closeButton;
public ServerMgmtFrame () {}
public ServerMgmtFrame (
String serverName,
DirContext serverCtx)
{
super ("Server Management: " + serverName);
this.serverCtx = serverCtx;
getContentPane ().setLayout (null);
setSize (mainPaneWidth, mainPaneHeight);
try
{
Attributes attrs;
attrs = serverCtx.getAttributes (
"",
new String [] {ServerVersions.ATTR_ID});
ServerVersions ver;
ver = (ServerVersions) attrs.get (ServerVersions.ATTR_ID).get ();
versionLabel = new JLabel ("Server Version " +
ver.getMajorVersion () + "." +
ver.getMinorVersion () + " rev " +
ver.getRevision ());
versionLabel.setBorder (new EtchedBorder (EtchedBorder.LOWERED));
versionLabel.setBounds (
emptySpace,
emptySpace,
mainPaneWidth - (emptySpace * 3),
buttonHeight);
versionLabel.setHorizontalAlignment (SwingConstants.CENTER);
getContentPane ().add (versionLabel);
}
catch (Exception e)
{
(new MessageBox (
"Error",
"Unable to get attributes for object:\n" +
Util.getExceptionTrace (e))).show ();
}
nlmLabel = new JLabel ("NLM command:");
nlmLabel.setBounds (
emptySpace,
(buttonHeight + emptySpace) + emptySpace,
buttonWidth,
buttonHeight);
getContentPane ().add (nlmLabel);
nlmTextField = new JTextField ();
nlmTextField.setBounds (
(buttonWidth + emptySpace) + emptySpace,
(buttonHeight + emptySpace) + emptySpace,
mainPaneWidth - (buttonWidth + (emptySpace * 3)),
buttonHeight);
nlmTextField.setToolTipText ("<vol:><path>NLMname<.ext> <parameters>");
getContentPane ().add (nlmTextField);
loadNLMButton = new JButton ("Load NLM");
loadNLMButton.setToolTipText ("Load the specified NLM");
loadNLMButton.setBounds (
(mainPaneWidth - buttonWidth) / 2 - (buttonWidth + emptySpace),
((buttonHeight + emptySpace) * 2) + emptySpace,
buttonWidth,
buttonHeight);
loadNLMButton.addActionListener (this);
getContentPane ().add (loadNLMButton);
unloadNLMButton = new JButton ("Unload NLM");
unloadNLMButton.setToolTipText ("Unload the specified NLM");
unloadNLMButton.setBounds (
(mainPaneWidth - buttonWidth) / 2,
((buttonHeight + emptySpace) * 2) + emptySpace,
buttonWidth,
buttonHeight);
unloadNLMButton.addActionListener (this);
getContentPane ().add (unloadNLMButton);
closeButton = new JButton ("Close");
closeButton.setToolTipText ("Exit this window");
closeButton.setBounds (
(mainPaneWidth - buttonWidth) / 2 + (buttonWidth + emptySpace),
((buttonHeight + emptySpace) * 2) + emptySpace,
buttonWidth,
buttonHeight);
closeButton.addActionListener (this);
getContentPane ().add (closeButton);
}
public void actionPerformed (
ActionEvent event)
{
Object object = event.getSource ();
String loadNLMText = nlmTextField.getText ();
if (object == loadNLMButton)
{
if ((null != loadNLMText) && (!loadNLMText.equals ("")))
((NWServer) serverCtx).loadNLM (loadNLMText);
}
else if (object == unloadNLMButton)
{
if ((null != loadNLMText) && (!loadNLMText.equals ("")))
((NWServer) serverCtx).unloadNLM (loadNLMText);
}
else if (object == closeButton)
{
setVisible (false);
}
}
}