summaryrefslogtreecommitdiff
path: root/java/src/IceGrid/TreeNode/ServerInstance.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2005-07-14 23:40:17 +0000
committerBernard Normier <bernard@zeroc.com>2005-07-14 23:40:17 +0000
commit87236a07f5bd4201cd7c2f43d6e9a5fc5d50fbdb (patch)
treee8ecaf5e21798004eab55cfd6df6a7b9bb0e764b /java/src/IceGrid/TreeNode/ServerInstance.java
parentadding package, adapterDeactivation (diff)
downloadice-87236a07f5bd4201cd7c2f43d6e9a5fc5d50fbdb.tar.bz2
ice-87236a07f5bd4201cd7c2f43d6e9a5fc5d50fbdb.tar.xz
ice-87236a07f5bd4201cd7c2f43d6e9a5fc5d50fbdb.zip
Displaying more properties
Diffstat (limited to 'java/src/IceGrid/TreeNode/ServerInstance.java')
-rwxr-xr-xjava/src/IceGrid/TreeNode/ServerInstance.java457
1 files changed, 345 insertions, 112 deletions
diff --git a/java/src/IceGrid/TreeNode/ServerInstance.java b/java/src/IceGrid/TreeNode/ServerInstance.java
index c3e1a6cc4c6..a08ff349679 100755
--- a/java/src/IceGrid/TreeNode/ServerInstance.java
+++ b/java/src/IceGrid/TreeNode/ServerInstance.java
@@ -10,36 +10,43 @@ package IceGrid.TreeNode;
import java.awt.Component;
import java.awt.event.ActionEvent;
-import javax.swing.JPopupMenu;
-import javax.swing.JPanel;
-import javax.swing.JTree;
-import javax.swing.Icon;
-import javax.swing.JMenuItem;
-import javax.swing.Action;
+
import javax.swing.AbstractAction;
-import javax.swing.JTextField;
+import javax.swing.Action;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
import javax.swing.JTextField;
-import javax.swing.JComboBox;
-import javax.swing.JButton;
import javax.swing.JToggleButton;
+import javax.swing.JTree;
+import javax.swing.UIManager;
+import javax.swing.tree.DefaultTreeCellRenderer;
-import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.factories.Borders;
+import com.jgoodies.forms.layout.FormLayout;
+import com.jgoodies.forms.layout.Sizes;
+import com.jgoodies.forms.util.LayoutStyle;
+import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
-import IceGrid.TreeModelI;
import IceGrid.IceBoxDescriptor;
+import IceGrid.Model;
+import IceGrid.TemplateDescriptor;
+import IceGrid.TreeModelI;
+import IceGrid.ServerDescriptor;
+import IceGrid.ServerDynamicInfo;
import IceGrid.ServerInstanceDescriptor;
import IceGrid.ServerState;
-import IceGrid.TemplateDescriptor;
import IceGrid.Utils;
-import IceGrid.Model;
-import IceGrid.ServerDynamicInfo;
class ServerInstance extends Parent
{
@@ -53,64 +60,53 @@ class ServerInstance extends Parent
//
// Build everything using JGoodies's DefaultFormBuilder
//
- FormLayout layout = new FormLayout("right:pref, 3dlu, fill:pref:grow, 3dlu, pref", "");
+ FormLayout layout = new FormLayout(
+ "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setBorder(Borders.DLU2_BORDER);
builder.setRowGroupingEnabled(true);
- builder.appendSeparator("Server Instance Descriptor");
+
+ builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad());
+
+ //
+ // Type combox box
+ //
+ builder.append("Type");
+ builder.append(_type, 3);
+ builder.nextLine();
- builder.append("Node");
- builder.append(_node, 3);
+ //
+ // Template combox box
+ //
+ builder.append(_templateLabel, _template, _templateButton);
builder.nextLine();
- AbstractAction gotoTemplate = new AbstractAction("->")
- {
- public void actionPerformed(ActionEvent e)
- {
- if(_server != null)
- {
- CommonBase parent = _server.getParent(TreeModelI.APPLICATION_VIEW);
- if(parent != null)
- {
- Application app = (Application)parent.getParent(TreeModelI.APPLICATION_VIEW);
- if(app != null)
- {
- ServerTemplate template = app.findServerTemplate(_template.getText());
- if(template != null)
- {
- _server.getModel().getTreeNodeSelector().selectNode(
- template.getPath(TreeModelI.APPLICATION_VIEW),
- TreeModelI.APPLICATION_VIEW);
- }
- }
- }
- }
- }
- };
- gotoTemplate.putValue(Action.SHORT_DESCRIPTION, "Goto this template");
-
-
- builder.append("Template", _template);
- builder.append(new JButton(gotoTemplate));
+ //
+ // Parameters
+ //
+ builder.append(_parameterValuesLabel, _parameterValues, _parameterValuesButton);
builder.nextLine();
- builder.append("Parameters", _parameterValues);
- builder.append(new JButton("..."));
+ builder.setLineGapSize(LayoutStyle.getCurrent().getParagraphPad());
+
+ //
+ // Node combo box
+ //
+ builder.append("Node");
+ builder.append(_node, _nodeButton);
builder.nextLine();
-
- _myDescriptor = new JComboBox();
- _myDescriptor.addItem("");
- _myDescriptor.addItem("ServerDescriptor");
- _myDescriptor.addItem("IceBoxDescriptor");
- builder.append("My Descriptor", _myDescriptor);
- builder.append(new JToggleButton("Edit"));
-
+
+ //
+ // Targets field
+ //
builder.append("Targets");
+ _targets.setToolTipText("XML-descriptor targets used to deploy this server");
builder.append(_targets, 3);
_targets.setEditable(false);
builder.nextLine();
- _serverDescriptorRenderer.build(builder);
+
+ _serverDescriptorEditor.build(builder);
_scrollPane = new JScrollPane(builder.getPanel(),
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -124,32 +120,197 @@ class ServerInstance extends Parent
{
_server = server;
ServerInstanceDescriptor descriptor = server.getDescriptor();
- _template.setText(descriptor.template);
- _node.setText(descriptor.node);
-
+
+ _node.setModel(_server.getModel().getNodeViewRoot().getComboBoxModel());
+ _node.setSelectedItem(_server.getParent(TreeModelI.NODE_VIEW));
+
+ ServerDescriptor serverDescriptor = null;
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
-
- _parameterValues.setText(Utils.stringify(descriptor.parameterValues, "=",
- ", ", toolTipHolder));
- _parameterValues.setToolTipText(toolTipHolder.value);
+
+ java.util.Map[] variables = null;
+
+ if(descriptor.template.length() == 0)
+ {
+ serverDescriptor = descriptor.descriptor;
+ if(_server.getModel().substituteVariables())
+ {
+ variables = new java.util.Map[] {
+ server.getNodeVariables(),
+ server.getApplication().getVariables()};
+ }
+
+ if(serverDescriptor instanceof IceBoxDescriptor)
+ {
+ _type.setSelectedIndex(ICEBOX);
+ }
+ else
+ {
+ _type.setSelectedIndex(PLAIN_SERVER);
+ }
+
+ _templateLabel.setEnabled(false);
+ _template.setEnabled(false);
+ _template.setModel(new DefaultComboBoxModel());
+ _template.setSelectedItem(null);
+ _templateButton.setEnabled(false);
+
+ _parameterValuesLabel.setEnabled(false);
+ _parameterValues.setEnabled(false);
+ _parameterValues.setText("");
+ _parameterValues.setToolTipText(null);
+ _parameterValuesButton.setEnabled(false);
+ }
+ else
+ {
+ _type.setSelectedIndex(TEMPLATE_INSTANCE);
+
+ _templateLabel.setEnabled(true);
+ _template.setEnabled(true);
+ _templateButton.setEnabled(true);
+
+ Application application = _server.getApplication();
+
+ TemplateDescriptor templateDescriptor =
+ application.findServerTemplateDescriptor(descriptor.template);
+
+ _template.setModel(application.getServerTemplates().getComboBoxModel());
+ _template.setSelectedItem(templateDescriptor);
+ serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor;
+
+ _parameterValuesLabel.setEnabled(true);
+ _parameterValues.setEnabled(true);
+ _parameterValuesButton.setEnabled(true);
+
+ String stringifiedParameterValues;
+ if(_server.getModel().substituteVariables())
+ {
+ java.util.Map substitutedParameters = Utils.substituteVariables(
+ descriptor.parameterValues, _server.getNodeVariables(),
+ application.getVariables());
+
+ stringifiedParameterValues = Utils.stringify(substitutedParameters, "=",
+ ", ", toolTipHolder);
+ _parameterValues.setEditable(false);
+
+ variables = new java.util.Map[]{
+ substitutedParameters,
+ server.getNodeVariables(),
+ application.getVariables()};
+ }
+ else
+ {
+ stringifiedParameterValues = Utils.stringify(descriptor.parameterValues, "=",
+ ", ", toolTipHolder);
+ _parameterValues.setEditable(true);
+ }
+ _parameterValues.setText(stringifiedParameterValues);
+ _parameterValues.setToolTipText(toolTipHolder.value);
+ }
_targets.setText(Utils.stringify(descriptor.targets, ", ", toolTipHolder));
_targets.setToolTipText(toolTipHolder.value);
- _serverDescriptorRenderer.showDescriptor(descriptor.descriptor);
+ _serverDescriptorEditor.show(serverDescriptor, variables);
}
+
+ Editor(boolean editDetails)
+ {
+ _serverDescriptorEditor = new ServerDescriptorEditor(editDetails);
+ //
+ // gotoTemplate action
+ //
+ AbstractAction gotoTemplate = new AbstractAction("->")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ ServerTemplate template = (ServerTemplate)
+ _template.getSelectedItem();
+ if(template != null && _server != null)
+ {
+ _server.getModel().getTreeNodeSelector().
+ selectNode(
+ template.getPath(
+ TreeModelI.APPLICATION_VIEW),
+ TreeModelI.APPLICATION_VIEW);
+ }
+ }
+ };
+ gotoTemplate.putValue(Action.SHORT_DESCRIPTION, "Goto this template");
+ _templateButton = new JButton(gotoTemplate);
+ _parameterValuesButton = new JButton("...");
- private JTextField _node = new JTextField(20);
- private JTextField _template = new JTextField(20);
+ //
+ // gotoNode action
+ //
+ AbstractAction gotoNode = new AbstractAction("->")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Node node = (Node)_node.getSelectedItem();
+ if(node != null)
+ {
+ //
+ // I have the node but I really want to get to the NodeVar;
+ // too bad node does not contain them
+ //
+
+ if(_server != null)
+ {
+ CommonBase parent = _server.getParent(
+ TreeModelI.APPLICATION_VIEW);
+ if(parent != null)
+ {
+ Application app = (Application)parent.getParent(
+ TreeModelI.APPLICATION_VIEW);
+ if(app != null)
+ {
+ NodeVar nodeVar = app.findNodeVar(
+ node.getId());
+
+ //
+ // TODO: offer to create a new nodeVar when
+ // nodeVar == null
+ //
+ if(nodeVar != null)
+ {
+ _server.getModel().getTreeNodeSelector().
+ selectNode(
+ nodeVar.getPath(
+ TreeModelI.APPLICATION_VIEW),
+ TreeModelI.APPLICATION_VIEW);
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+ gotoNode.putValue(Action.SHORT_DESCRIPTION, "Show the variables for this node");
+ _nodeButton = new JButton(gotoNode);
+ }
+
+
+ private final int PLAIN_SERVER = 0;
+ private final int ICEBOX = 1;
+ private final int TEMPLATE_INSTANCE = 2;
+ private String[] _typeList = {"Plain Server", "IceBox Server", "Template Instance"};
+ private JComboBox _type = new JComboBox(_typeList);
+
+ private JLabel _templateLabel = new JLabel("Template");
+ private JComboBox _template = new JComboBox();
+ private JButton _templateButton;
+ private JLabel _parameterValuesLabel = new JLabel("Parameters");
private JTextField _parameterValues = new JTextField(20);
- private JComboBox _myDescriptor;
+ private JButton _parameterValuesButton;
+
+ private JComboBox _node = new JComboBox();
+ private JButton _nodeButton;
+
private JTextField _targets = new JTextField(20);
- private ServerDescriptorRenderer _serverDescriptorRenderer =
- new ServerDescriptorRenderer();
+ private ServerDescriptorEditor _serverDescriptorEditor;
private ServerInstance _server;
-
private JScrollPane _scrollPane;
}
@@ -203,18 +364,38 @@ class ServerInstance extends Parent
return _popup;
}
- public void displayProperties(SimpleInternalFrame frame, int view)
+ public void displayProperties()
{
- frame.setTitle("Properties for " + _id);
+ SimpleInternalFrame propertiesFrame = _model.getPropertiesFrame();
+
+ propertiesFrame.setTitle("Properties for " + _id);
- if(_editor == null)
+ //
+ // Pick the appropriate editor
+ //
+ Editor editor = null;
+ if(_descriptor.template.length() > 0 || _model.substituteVariables())
+ {
+ if(_editor == null)
+ {
+ _editor = new Editor(false);
+ }
+
+ editor = _editor;
+ }
+ else
{
- _editor = new Editor();
+ if(_fullEditor == null)
+ {
+ _fullEditor = new Editor(true);
+ }
+ editor = _fullEditor;
}
- _editor.show(this);
- frame.setContent(_editor.getComponent());
- frame.validate();
- frame.repaint();
+
+ editor.show(this);
+ propertiesFrame.setContent(editor.getComponent());
+ propertiesFrame.validate();
+ propertiesFrame.repaint();
}
@@ -236,11 +417,16 @@ class ServerInstance extends Parent
_icons = new Icon[7];
_icons[0] = Utils.getIcon("/icons/unknown.png");
_icons[ServerState.Inactive.value() + 1] = Utils.getIcon("/icons/inactive.png");
- _icons[ServerState.Activating.value() + 1] = Utils.getIcon("/icons/activating.png");
- _icons[ServerState.Active.value() + 1] = Utils.getIcon("/icons/active.png");
- _icons[ServerState.Deactivating.value() + 1] = Utils.getIcon("/icons/deactivating.png");
- _icons[ServerState.Destroying.value() + 1] = Utils.getIcon("/icons/destroying.png");
- _icons[ServerState.Destroyed.value() + 1] = Utils.getIcon("/icons/destroyed.png");
+ _icons[ServerState.Activating.value() + 1] =
+ Utils.getIcon("/icons/activating.png");
+ _icons[ServerState.Active.value() + 1] =
+ Utils.getIcon("/icons/active.png");
+ _icons[ServerState.Deactivating.value() + 1] =
+ Utils.getIcon("/icons/deactivating.png");
+ _icons[ServerState.Destroying.value() + 1] =
+ Utils.getIcon("/icons/destroying.png");
+ _icons[ServerState.Destroyed.value() + 1] =
+ Utils.getIcon("/icons/destroyed.png");
}
//
@@ -264,13 +450,13 @@ class ServerInstance extends Parent
//
// Builds the server instance and all its sub-tree
//
- ServerInstance(ServerInstanceDescriptor descriptor,
- Model model,
+ ServerInstance(String serverName,
+ ServerInstanceDescriptor descriptor,
+ Application application,
boolean fireNodeViewEvent)
{
- super(descriptor.descriptor.name, model);
-
- rebuild(descriptor, fireNodeViewEvent);
+ super(serverName, application.getModel());
+ rebuild(application, descriptor, fireNodeViewEvent);
}
@@ -300,7 +486,8 @@ class ServerInstance extends Parent
//
// Update the server instance and all its subtree
//
- void rebuild(ServerInstanceDescriptor newDescriptor,
+ void rebuild(Application application,
+ ServerInstanceDescriptor newDescriptor,
boolean fireNodeViewEvent)
{
assert(newDescriptor != null);
@@ -333,28 +520,57 @@ class ServerInstance extends Parent
Node node = _model.getNodeViewRoot().findNode(_descriptor.node);
- if(_descriptor.descriptor instanceof IceBoxDescriptor)
+ java.util.Map appVariables = application.getVariables();
+ _nodeVariables =
+ application.getNodeVariables(_descriptor.node); // can be null
+ java.util.Map parameters = null;
+ ServerDescriptor serverDescriptor = null;
+ boolean editable = false;
+
+ if(_descriptor.template.length() > 0)
{
- _iceBoxDescriptor = (IceBoxDescriptor)_descriptor.descriptor;
+ TemplateDescriptor templateDescriptor =
+ application.findServerTemplateDescriptor(_descriptor.template);
+ serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor;
+ parameters = Utils.substituteVariables(_descriptor.parameterValues,
+ _nodeVariables, appVariables);
+ }
+ else
+ {
+ serverDescriptor = _descriptor.descriptor;
+ editable = true;
+ }
+
+ if(serverDescriptor instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)serverDescriptor;
//
// We need to pass the node to register the adapters
//
- _serviceInstances = new ServiceInstances(_iceBoxDescriptor.services,
- _model, node);
+ _serviceInstances = new ServiceInstances(iceBoxDescriptor.services,
+ editable,
+ application,
+ _nodeVariables,
+ parameters,
+ node);
addChild(_serviceInstances);
_serviceInstances.addParent(this); // no-op when newNode == true
}
- else
- {
- _iceBoxDescriptor = null;
- }
- _adapters = new Adapters(_descriptor.descriptor.adapters, _model, node);
+ java.util.Map[] variables = new java.util.Map[3];
+ variables[0] = parameters;
+ variables[1] = _nodeVariables;
+ variables[2] = appVariables;
+
+ _adapters = new Adapters(serverDescriptor.adapters,
+ editable, variables,
+ _model, node);
addChild(_adapters);
_adapters.addParent(this); // no-op when newNode == true
- _dbEnvs = new DbEnvs(_descriptor.descriptor.dbEnvs, _model, false);
+ _dbEnvs = new DbEnvs(serverDescriptor.dbEnvs,
+ editable, variables, _model);
addChild(_dbEnvs);
_dbEnvs.addParent(this); // no-op when newNode == true
@@ -408,11 +624,13 @@ class ServerInstance extends Parent
}
catch(IceGrid.NodeUnreachableException e)
{
- _model.getStatusBar().setText("Could not reach the node for server '" + _id + "'.");
+ _model.getStatusBar().setText("Could not reach the node for server '" + _id
+ + "'.");
}
catch(Ice.LocalException e)
{
- _model.getStatusBar().setText("Starting server '" + _id + "'... failed: " + e.toString());
+ _model.getStatusBar().setText("Starting server '" + _id + "'... failed: "
+ + e.toString());
}
if(started)
{
@@ -437,11 +655,13 @@ class ServerInstance extends Parent
}
catch(IceGrid.NodeUnreachableException e)
{
- _model.getStatusBar().setText("Could not reach the node for server '" + _id + "'.");
+ _model.getStatusBar().setText("Could not reach the node for server '"
+ + _id + "'.");
}
catch(Ice.LocalException e)
{
- _model.getStatusBar().setText("Stopping server '" + _id + "'... failed: " + e.toString());
+ _model.getStatusBar().setText("Stopping server '" + _id + "'... failed: "
+ + e.toString());
}
_model.getStatusBar().setText("Stopping server '" + _id + "'... done.");
}
@@ -456,7 +676,19 @@ class ServerInstance extends Parent
return _descriptor;
}
+
+ Application getApplication()
+ {
+ CommonBase parent = getParent(TreeModelI.APPLICATION_VIEW);
+ return
+ (Application)parent.getParent(TreeModelI.APPLICATION_VIEW);
+ }
+ java.util.Map getNodeVariables()
+ {
+ return _nodeVariables;
+ }
+
public String toString()
{
String result = _descriptor.descriptor.name;
@@ -487,9 +719,8 @@ class ServerInstance extends Parent
private String _toolTip = toolTip(_state, _pid);
private ServerInstanceDescriptor _descriptor;
- private TemplateDescriptor _templateDescriptor;
- private IceBoxDescriptor _iceBoxDescriptor;
-
+ private java.util.Map _nodeVariables;
+
//
// Children
//
@@ -500,6 +731,8 @@ class ServerInstance extends Parent
static private DefaultTreeCellRenderer _cellRenderer;
static private Icon[] _icons;
static private PopupMenu _popup;
- static private Editor _editor;
+
+ static private Editor _fullEditor; // writable server descriptor
+ static private Editor _editor; // read-only server descriptor
}