import java.awt.*;
import java.awt.event.*;
import javax.naming.*;
public class NSILookupFrame extends Frame
implements WindowListener,
ActionListener
{
public static final int width = 350;
public static final int height = 75;
NSIBrowserFrame parent;
Context initCtx;
Context currCtx;
TextField objectNameField;
Button okButton = new Button ("OK");
Button cancelButton = new Button ("Cancel");
public NSILookupFrame
(
NSIBrowserFrame parent,
Context initCtx,
Context currCtx
)
{
super ("Lookup");
this.parent = parent;
this.initCtx = initCtx;
this.currCtx = currCtx;
NSIForm f = new NSIForm (this);
objectNameField = f.addRow ("Object path:");
Panel p = new Panel ();
p.setLayout (new GridLayout (1, 0));
p.add (okButton);
p.add (cancelButton);
f.addRow (p);
addWindowListener (this);
okButton.addActionListener (this);
cancelButton.addActionListener (this);
}
public void actionPerformed (
ActionEvent evt)
{
Object target = evt.getSource();
if (target == okButton)
{
String objectName = objectNameField.getText ();
Context relCtx = initCtx;
if ('.' == objectName.charAt (0))
{
objectName = objectName.substring (1);
relCtx = currCtx;
}
try
{
Object obj = relCtx.lookup (objectName);
if (obj instanceof Context)
parent.startNewContextFrame (objectName, (Context) obj);
else
new NSIMessageBox ("Object not of type Context");
}
catch (NamingException e)
{
new NSIMessageBox ("Error", "Name not found:" + objectName);
}
dispose();
}
else if (target == cancelButton)
{
dispose();
}
}
public void windowClosed (
WindowEvent event)
{
}
public void windowDeiconified (
WindowEvent event)
{
}
public void windowIconified (
WindowEvent event)
{
}
public void windowActivated (
WindowEvent event)
{
}
public void windowDeactivated (
WindowEvent event)
{
}
public void windowOpened (
WindowEvent event)
{
}
public void windowClosing (
WindowEvent event)
{
dispose ();
}
}