summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
committerBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
commit20744ae1f1182d08e26b175f59d14041aabaf754 (patch)
tree937d125b80663966b3a61e13e744e28daf1f22da /java/src
parentJava metadata (diff)
downloadice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.bz2
ice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.xz
ice-20744ae1f1182d08e26b175f59d14041aabaf754.zip
IceGrid GUI refactoring
Diffstat (limited to 'java/src')
-rwxr-xr-xjava/src/IceGrid/AdminGUI.java158
-rwxr-xr-xjava/src/IceGrid/MainPane.java206
-rwxr-xr-xjava/src/IceGrid/Model.java2108
-rwxr-xr-xjava/src/IceGrid/TreeModelI.java132
-rwxr-xr-xjava/src/IceGrid/TreeNode/AbstractServerEditor.java265
-rwxr-xr-xjava/src/IceGrid/TreeNode/Adapter.java308
-rwxr-xr-xjava/src/IceGrid/TreeNode/Adapters.java174
-rwxr-xr-xjava/src/IceGrid/TreeNode/Application.java701
-rwxr-xr-xjava/src/IceGrid/TreeNode/CommonBase.java180
-rwxr-xr-xjava/src/IceGrid/TreeNode/CommonBaseI.java477
-rwxr-xr-xjava/src/IceGrid/TreeNode/DbEnv.java171
-rwxr-xr-xjava/src/IceGrid/TreeNode/DbEnvs.java157
-rwxr-xr-xjava/src/IceGrid/TreeNode/EditableLeaf.java48
-rwxr-xr-xjava/src/IceGrid/TreeNode/EditableParent.java96
-rwxr-xr-xjava/src/IceGrid/TreeNode/Editor.java301
-rwxr-xr-xjava/src/IceGrid/TreeNode/Leaf.java69
-rwxr-xr-xjava/src/IceGrid/TreeNode/ListElementEditor.java135
-rwxr-xr-xjava/src/IceGrid/TreeNode/ListParent.java174
-rwxr-xr-xjava/src/IceGrid/TreeNode/NodeEditor.java401
-rwxr-xr-xjava/src/IceGrid/TreeNode/Parent.java723
-rwxr-xr-xjava/src/IceGrid/TreeNode/PropertiesHolder.java58
-rwxr-xr-xjava/src/IceGrid/TreeNode/ReplicaGroup.java167
-rwxr-xr-xjava/src/IceGrid/TreeNode/Root.java475
-rwxr-xr-xjava/src/IceGrid/TreeNode/Server.java977
-rwxr-xr-xjava/src/IceGrid/TreeNode/ServerTemplate.java363
-rwxr-xr-xjava/src/IceGrid/TreeNode/Service.java397
-rwxr-xr-xjava/src/IceGrid/TreeNode/Services.java472
-rwxr-xr-xjava/src/IceGrid/TreeNode/UpdateFailedException.java87
-rwxr-xr-xjava/src/IceGridGUI/Application/AbstractServerEditor.java176
-rwxr-xr-xjava/src/IceGridGUI/Application/Adapter.java226
-rwxr-xr-xjava/src/IceGridGUI/Application/AdapterEditor.java (renamed from java/src/IceGrid/TreeNode/AdapterEditor.java)1286
-rwxr-xr-xjava/src/IceGridGUI/Application/ApplicationEditor.java (renamed from java/src/IceGrid/TreeNode/ApplicationEditor.java)212
-rwxr-xr-xjava/src/IceGridGUI/Application/Communicator.java1036
-rwxr-xr-xjava/src/IceGridGUI/Application/CommunicatorChildEditor.java121
-rwxr-xr-xjava/src/IceGridGUI/Application/CommunicatorSubEditor.java (renamed from java/src/IceGrid/TreeNode/CommunicatorSubEditor.java)26
-rwxr-xr-xjava/src/IceGridGUI/Application/DbEnv.java198
-rwxr-xr-xjava/src/IceGridGUI/Application/DbEnvEditor.java (renamed from java/src/IceGrid/TreeNode/DbEnvEditor.java)493
-rwxr-xr-xjava/src/IceGridGUI/Application/DescriptorHolder.java (renamed from java/src/IceGrid/TreeNode/Editable.java)33
-rwxr-xr-xjava/src/IceGridGUI/Application/Editable.java80
-rwxr-xr-xjava/src/IceGridGUI/Application/Editor.java163
-rwxr-xr-xjava/src/IceGridGUI/Application/ListTreeNode.java296
-rwxr-xr-xjava/src/IceGridGUI/Application/Node.java (renamed from java/src/IceGrid/TreeNode/Node.java)716
-rwxr-xr-xjava/src/IceGridGUI/Application/NodeEditor.java293
-rwxr-xr-xjava/src/IceGridGUI/Application/Nodes.java (renamed from java/src/IceGrid/TreeNode/Nodes.java)159
-rwxr-xr-xjava/src/IceGridGUI/Application/ReplicaGroup.java222
-rwxr-xr-xjava/src/IceGridGUI/Application/ReplicaGroupEditor.java (renamed from java/src/IceGrid/TreeNode/ReplicaGroupEditor.java)902
-rwxr-xr-xjava/src/IceGridGUI/Application/ReplicaGroups.java (renamed from java/src/IceGrid/TreeNode/ReplicaGroups.java)129
-rwxr-xr-xjava/src/IceGridGUI/Application/Root.java1186
-rwxr-xr-xjava/src/IceGridGUI/Application/Server.java731
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerEditor.java (renamed from java/src/IceGrid/TreeNode/ServerEditor.java)38
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerInstanceEditor.java (renamed from java/src/IceGrid/TreeNode/ServerInstanceEditor.java)57
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerSubEditor.java (renamed from java/src/IceGrid/TreeNode/ServerSubEditor.java)25
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerTemplate.java360
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerTemplateEditor.java (renamed from java/src/IceGrid/TreeNode/ServerTemplateEditor.java)28
-rwxr-xr-xjava/src/IceGridGUI/Application/ServerTemplates.java (renamed from java/src/IceGrid/TreeNode/ServerTemplates.java)111
-rwxr-xr-xjava/src/IceGridGUI/Application/Service.java489
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceEditor.java (renamed from java/src/IceGrid/TreeNode/ServiceEditor.java)44
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceInstanceEditor.java (renamed from java/src/IceGrid/TreeNode/ServiceInstanceEditor.java)60
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceSubEditor.java (renamed from java/src/IceGrid/TreeNode/ServiceSubEditor.java)23
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceTemplate.java (renamed from java/src/IceGrid/TreeNode/ServiceTemplate.java)200
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceTemplateEditor.java (renamed from java/src/IceGrid/TreeNode/ServiceTemplateEditor.java)28
-rwxr-xr-xjava/src/IceGridGUI/Application/ServiceTemplates.java (renamed from java/src/IceGrid/TreeNode/ServiceTemplates.java)101
-rwxr-xr-xjava/src/IceGridGUI/Application/TemplateEditor.java (renamed from java/src/IceGrid/TreeNode/TemplateEditor.java)185
-rwxr-xr-xjava/src/IceGridGUI/Application/TemplateInstance.java16
-rwxr-xr-xjava/src/IceGridGUI/Application/Templates.java (renamed from java/src/IceGrid/TreeNode/Templates.java)50
-rwxr-xr-xjava/src/IceGridGUI/Application/TreeNode.java328
-rwxr-xr-xjava/src/IceGridGUI/Application/UpdateFailedException.java (renamed from java/src/IceGrid/TreeNode/DuplicateIdException.java)31
-rwxr-xr-xjava/src/IceGridGUI/ApplicationActions.java246
-rwxr-xr-xjava/src/IceGridGUI/ApplicationPane.java393
-rwxr-xr-xjava/src/IceGridGUI/BareBonesBrowserLaunch.java (renamed from java/src/IceGrid/BareBonesBrowserLaunch.java)2
-rwxr-xr-xjava/src/IceGridGUI/CellRenderer.java (renamed from java/src/IceGrid/CellRenderer.java)18
-rwxr-xr-xjava/src/IceGridGUI/Coordinator.java1797
-rwxr-xr-xjava/src/IceGridGUI/EditorBase.java139
-rwxr-xr-xjava/src/IceGridGUI/LicenseDialog.java (renamed from java/src/IceGrid/LicenseDialog.java)18
-rwxr-xr-xjava/src/IceGridGUI/ListDialog.java (renamed from java/src/IceGrid/ListDialog.java)18
-rwxr-xr-xjava/src/IceGridGUI/LiveActions.java118
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Adapter.java169
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/AdapterEditor.java140
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java98
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/DbEnv.java75
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/DbEnvEditor.java121
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Editor.java16
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java140
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/ListTreeNode.java81
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Node.java767
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/NodeEditor.java185
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/RegistryEditor.java26
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Root.java377
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Server.java721
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/ServerEditor.java271
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/Service.java166
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/ServiceEditor.java51
-rwxr-xr-xjava/src/IceGridGUI/LiveDeployment/TreeNode.java160
-rwxr-xr-xjava/src/IceGridGUI/LiveDeploymentPane.java342
-rwxr-xr-xjava/src/IceGridGUI/Main.java93
-rwxr-xr-xjava/src/IceGridGUI/MainPane.java156
-rwxr-xr-xjava/src/IceGridGUI/NodeObserverI.java (renamed from java/src/IceGrid/NodeObserverI.java)35
-rwxr-xr-xjava/src/IceGridGUI/ParametersDialog.java (renamed from java/src/IceGrid/ParametersDialog.java)18
-rwxr-xr-xjava/src/IceGridGUI/RegistryObserverI.java (renamed from java/src/IceGrid/RegistryObserverI.java)33
-rwxr-xr-xjava/src/IceGridGUI/SessionKeeper.java (renamed from java/src/IceGrid/SessionKeeper.java)85
-rwxr-xr-xjava/src/IceGridGUI/SimpleInternalFrame.java (renamed from java/src/IceGrid/SimpleInternalFrame.java)2
-rwxr-xr-xjava/src/IceGridGUI/StatusBar.java (renamed from java/src/IceGrid/StatusBar.java)18
-rwxr-xr-xjava/src/IceGridGUI/Tab.java27
-rwxr-xr-xjava/src/IceGridGUI/TableDialog.java (renamed from java/src/IceGrid/TableDialog.java)18
-rwxr-xr-xjava/src/IceGridGUI/TreeNodeBase.java268
-rwxr-xr-xjava/src/IceGridGUI/Utils.java (renamed from java/src/IceGrid/Utils.java)247
-rwxr-xr-xjava/src/IceGridGUI/XMLWriter.java117
107 files changed, 15551 insertions, 13059 deletions
diff --git a/java/src/IceGrid/AdminGUI.java b/java/src/IceGrid/AdminGUI.java
deleted file mode 100755
index 83fb0cbc200..00000000000
--- a/java/src/IceGrid/AdminGUI.java
+++ /dev/null
@@ -1,158 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
-
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-
-import javax.swing.Icon;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.SwingConstants;
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
-
-import javax.swing.border.EmptyBorder;
-import java.awt.BorderLayout;
-
-import java.util.prefs.Preferences;
-
-public class AdminGUI extends JFrame
-{
- class StatusBarI extends JPanel implements StatusBar
- {
- StatusBarI()
- {
- super(new BorderLayout());
- setBorder(new EmptyBorder(0, 13, 10, 13));
-
- _text = new JLabel();
- _text.setHorizontalAlignment(SwingConstants.LEFT);
- add(_text, BorderLayout.LINE_START);
-
- _connectedLabel = new JLabel("Working Offline");
- _connectedLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- add(_connectedLabel, BorderLayout.LINE_END);
- }
-
- public void setText(String text)
- {
- _text.setText(text);
- }
-
- public void setConnected(boolean connected)
- {
- if(connected)
- {
- _connectedLabel.setText("Working Online");
- }
- else
- {
- _connectedLabel.setText("Working Offline");
- }
- }
-
- JLabel _connectedLabel;
- JLabel _text;
- }
-
- public static void main(final String[] args)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- createAndShowGUI(args);
- }
- });
- }
-
- AdminGUI(String[] args)
- {
- super("IceGrid Admin");
- javax.swing.ImageIcon icon = Utils.getIcon("/icons/16x16/grid.png");
- if(icon != null)
- {
- setIconImage(icon.getImage());
- }
-
- setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- if(_model != null)
- {
- _model.exit(0);
- }
- }
- });
-
- _model = new Model(this, args, Preferences.userNodeForPackage(getClass()),
- new StatusBarI());
-
- initComponents();
- _model.showMainFrame();
-
- _model.getSessionKeeper().createSession(true);
- }
-
- private void initComponents()
- {
- //
- // MainPane
- //
- getContentPane().add(new MainPane(_model), BorderLayout.CENTER);
-
- //
- // Menu and tool bars
- //
- _model.createMenuBar();
- _model.createToolBar();
- _model.showActions(null);
-
- //
- // Status bar
- //
- getContentPane().add((StatusBarI)_model.getStatusBar(), BorderLayout.PAGE_END);
- }
-
- private static void createAndShowGUI(String[] args)
- {
- try
- {
- if(UIManager.getSystemLookAndFeelClassName().equals("apple.laf.AquaLookAndFeel"))
- {
- System.setProperty("apple.laf.useScreenMenuBar", "true");
- UIManager.setLookAndFeel("apple.laf.AquaLookAndFeel");
- }
- else // JGoodies L&F
- {
- UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
- }
- }
- catch(Exception e)
- {
- System.err.println(e.toString());
- }
-
- //
- // Create and set up the window.
- //
- new AdminGUI(args);
-
- }
-
- private Model _model;
-}
-
-
diff --git a/java/src/IceGrid/MainPane.java b/java/src/IceGrid/MainPane.java
deleted file mode 100755
index 58e6903c055..00000000000
--- a/java/src/IceGrid/MainPane.java
+++ /dev/null
@@ -1,206 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
-
-import java.util.prefs.Preferences;
-import java.util.prefs.BackingStoreException;
-import javax.swing.*;
-
-import javax.swing.event.ChangeListener;
-import javax.swing.event.ChangeEvent;
-
-import javax.swing.tree.TreeCellRenderer;
-import javax.swing.tree.TreeSelectionModel;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.awt.event.ActionEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-
-
-import com.jgoodies.looks.Options;
-import com.jgoodies.looks.plastic.PlasticLookAndFeel;
-import com.jgoodies.looks.windows.WindowsLookAndFeel;
-import com.jgoodies.forms.factories.Borders;
-
-import javax.swing.border.EmptyBorder;
-import javax.swing.plaf.SplitPaneUI;
-import javax.swing.plaf.basic.BasicSplitPaneUI;
-import javax.swing.border.AbstractBorder;
-
-import IceGrid.TreeNode.CommonBase;
-
-
-public class MainPane extends JSplitPane
-{
- private class WelcomePanel extends JPanel
- {
- WelcomePanel()
- {
- MediaTracker mt = new MediaTracker(this);
- java.net.URL imgURL = Utils.class.getResource("/RedIceCrystal.jpg");
- assert imgURL != null;
- _image = Toolkit.getDefaultToolkit().getImage(imgURL);
- mt.addImage(_image, 0);
-
- try
- {
- mt.waitForAll();
- }
- catch(InterruptedException e)
- {
- }
-
- _aspectRatio = _image.getWidth(null)/_image.getHeight(null);
- }
-
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- Dimension d = _model.getPropertiesFrame().getSize(null);
-
- //
- // Keep the aspect ratio and make the image fill all the space
- //
- if(d.height * _aspectRatio < d.width)
- {
- d.height = (int)((float)d.width / _aspectRatio);
- }
- else
- {
- d.width = (int)((float)d.height * _aspectRatio);
- }
-
- g.drawImage(_image, 0, 0, d.width + 100, d.height, null);
- }
-
- private Image _image;
- private float _aspectRatio;
- }
-
- static class PopupListener extends MouseAdapter
- {
- public void mousePressed(MouseEvent e)
- {
- maybeShowPopup(e);
- }
-
- public void mouseReleased(MouseEvent e)
- {
- maybeShowPopup(e);
- }
-
- private void maybeShowPopup(MouseEvent e)
- {
- if (e.isPopupTrigger())
- {
- JTree tree = (JTree)e.getComponent();
-
- TreePath path = tree.getPathForLocation(e.getX(), e.getY());
-
- if(path != null)
- {
- CommonBase node = (CommonBase)path.getLastPathComponent();
- JPopupMenu popup = node.getPopupMenu();
- if(popup != null)
- {
- node.getModel().showActions(node);
- popup.show(tree, e.getX(), e.getY());
- }
- }
- }
- }
- }
-
-
- public void updateUI()
- {
- super.updateUI();
- setEmptyDividerBorder();
- }
-
- private void setEmptyDividerBorder()
- {
- SplitPaneUI splitPaneUI = getUI();
- if(splitPaneUI instanceof BasicSplitPaneUI)
- {
- BasicSplitPaneUI basicUI = (BasicSplitPaneUI)splitPaneUI;
- basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder());
- }
- }
-
- MainPane(Model model)
- {
- super(JSplitPane.HORIZONTAL_SPLIT, true);
- _model = model;
-
- setBorder(new EmptyBorder(10, 10, 10, 10));
-
- TreeCellRenderer renderer = new CellRenderer();
- PopupListener popupListener = new PopupListener();
-
- JTree tree = new JTree(_model.getTreeModel());
-
- tree.setBorder(new EmptyBorder(5, 5, 5, 5));
- tree.setCellRenderer(renderer);
- ToolTipManager.sharedInstance().registerComponent(tree);
- tree.addMouseListener(popupListener);
-
- tree.getSelectionModel().setSelectionMode
- (TreeSelectionModel.SINGLE_TREE_SELECTION);
-
- tree.setRootVisible(false);
- _model.setTree(tree);
-
- JScrollPane appScroll =
- new JScrollPane(tree,
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- appScroll.setBorder(Borders.EMPTY_BORDER);
-
- SimpleInternalFrame leftPane = new SimpleInternalFrame("Applications");
- leftPane.setContent(appScroll);
- leftPane.setPreferredSize(new Dimension(280, 350));
-
- //
- // Right pane
- //
- JPanel rightPane = new JPanel();
- rightPane.setLayout(new BoxLayout(rightPane, BoxLayout.Y_AXIS));
- rightPane.setBorder(Borders.EMPTY_BORDER);
- rightPane.add(_model.getCurrentStatusFrame());
- rightPane.add(Box.createRigidArea(new Dimension(0, 5)));
- rightPane.add(_model.getPropertiesFrame());
-
- //_model.show(_model.getRoot());
-
- //
- // Welcome panel
- //
- //_welcomePanel = new WelcomePanel();
- //displayWelcomePanel();
-
- setLeftComponent(leftPane);
- setRightComponent(rightPane);
- }
-
- private void displayWelcomePanel()
- {
- SimpleInternalFrame propertiesFrame = _model.getPropertiesFrame();
- propertiesFrame.setContent(_welcomePanel);
- propertiesFrame.validate();
- propertiesFrame.repaint();
- }
-
-
- private Model _model;
- private JPanel _welcomePanel;
-}
diff --git a/java/src/IceGrid/Model.java b/java/src/IceGrid/Model.java
deleted file mode 100755
index 6d8bd172ef2..00000000000
--- a/java/src/IceGrid/Model.java
+++ /dev/null
@@ -1,2108 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
-
-import java.util.prefs.Preferences;
-import java.util.prefs.BackingStoreException;
-
-import java.awt.BorderLayout;
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Frame;
-import java.awt.Rectangle;
-import java.awt.Container;
-import java.awt.Component;
-import java.awt.Toolkit;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.ButtonGroup;
-import javax.swing.JButton;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JEditorPane;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-import javax.swing.JToggleButton;
-import javax.swing.JToolBar;
-import javax.swing.JTree;
-import javax.swing.KeyStroke;
-import javax.swing.SwingUtilities;
-
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
-
-import com.jgoodies.looks.Options;
-import com.jgoodies.looks.HeaderStyle;
-import com.jgoodies.looks.BorderStyle;
-import com.jgoodies.looks.plastic.PlasticLookAndFeel;
-
-import IceGrid.TreeNode.Application;
-import IceGrid.TreeNode.CommonBase;
-import IceGrid.TreeNode.Editor;
-import IceGrid.TreeNode.Root;
-
-//
-// The class that holds all the data and more!
-//
-
-public class Model
-{
- private class SelectionListener implements TreeSelectionListener
- {
- public void valueChanged(TreeSelectionEvent e)
- {
- if(_selectionListenerEnabled)
- {
- TreePath path = null;
- if(e.isAddedPath())
- {
- path = e.getPath();
- }
-
- if(path == null)
- {
- show(_root);
- }
- else
- {
- CommonBase newNode = (CommonBase)path.getLastPathComponent();
- assert newNode.getParent() != null;
-
- if(_currentNode != null)
- {
- if(_currentNode.isEphemeral())
- {
- _currentNode.destroy();
- }
- else if(_currentNode.getParent() != null)
- {
- _previousNodes.add(_currentNode);
- while(_previousNodes.size() >= HISTORY_MAX_SIZE)
- {
- _previousNodes.removeFirst();
- }
- _back.setEnabled(true);
- }
- }
- _nextNodes.clear();
- _forward.setEnabled(false);
-
- _currentNode = newNode;
- show(_currentNode);
- }
- }
- }
- }
-
- private class MenuBar extends JMenuBar
- {
- private MenuBar()
- {
- putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
- putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
-
- //
- // File menu
- //
- JMenu fileMenu = new JMenu("File");
- fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F);
- add(fileMenu);
-
- //
- // New sub-menu
- //
- _newMenu = new JMenu("New");
- _newMenu.setEnabled(false);
- fileMenu.add(_newMenu);
- _newMenu.add(_newApplicationWithDefaultTemplates);
- _newMenu.add(_newApplication);
- _newMenu.addSeparator();
- _newMenu.add(_actions[CommonBase.NEW_ADAPTER]);
- _newMenu.add(_actions[CommonBase.NEW_DBENV]);
- _newMenu.add(_actions[CommonBase.NEW_NODE]);
- _newMenu.add(_actions[CommonBase.NEW_REPLICA_GROUP]);
-
- //
- // New server sub-sub-menu
- //
- _newServerMenu = new JMenu("Server");
- _newServerMenu.setEnabled(false);
- _newMenu.add(_newServerMenu);
- _newServerMenu.add(_actions[CommonBase.NEW_SERVER]);
- _newServerMenu.add(_actions[CommonBase.NEW_SERVER_ICEBOX]);
- _newServerMenu.add(_actions[CommonBase.NEW_SERVER_FROM_TEMPLATE]);
-
- //
- // New service sub-sub-menu
- //
- _newServiceMenu = new JMenu("Service");
- _newServiceMenu.setEnabled(false);
- _newMenu.add(_newServiceMenu);
- _newServiceMenu.add(_actions[CommonBase.NEW_SERVICE]);
- _newServiceMenu.add(_actions[CommonBase.NEW_SERVICE_FROM_TEMPLATE]);
-
- //
- // New template sub-sub-menu
- //
- _newTemplateMenu = new JMenu("Template");
- _newTemplateMenu.setEnabled(false);
- _newMenu.add(_newTemplateMenu);
- _newTemplateMenu.add(_actions[CommonBase.NEW_TEMPLATE_SERVER]);
- _newTemplateMenu.add(_actions[CommonBase.NEW_TEMPLATE_SERVER_ICEBOX]);
- _newTemplateMenu.add(_actions[CommonBase.NEW_TEMPLATE_SERVICE]);
-
- fileMenu.addSeparator();
- fileMenu.add(_login);
- fileMenu.add(_logout);
- fileMenu.addSeparator();
- fileMenu.add(_save);
- fileMenu.add(_discard);
- fileMenu.addSeparator();
- fileMenu.add(_exit);
-
- //
- // Edit menu
- //
- JMenu editMenu = new JMenu("Edit");
- editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E);
- add(editMenu);
- editMenu.add(_actions[CommonBase.COPY]);
- editMenu.add(_actions[CommonBase.PASTE]);
- editMenu.addSeparator();
- editMenu.add(_actions[CommonBase.DELETE]);
-
- //
- // View menu
- //
- JMenu viewMenu = new JMenu("View");
- viewMenu.setMnemonic(java.awt.event.KeyEvent.VK_V);
- add(viewMenu);
- viewMenu.add(_showVarsMenuItem);
- viewMenu.add(_substituteMenuItem);
- viewMenu.addSeparator();
- viewMenu.add(_back);
- viewMenu.add(_forward);
-
- //
- // Tools menu
- //
- JMenu toolsMenu = new JMenu("Tools");
- toolsMenu.setMnemonic(java.awt.event.KeyEvent.VK_T);
- add(toolsMenu);
-
- //
- // Application sub-menu
- //
- _appMenu = new JMenu("Application");
- _appMenu.setEnabled(false);
- toolsMenu.add(_appMenu);
- _appMenu.add(_actions[CommonBase.APPLICATION_INSTALL_DISTRIBUTION]);
-
- //
- // Node sub-menu
- //
- _nodeMenu = new JMenu("Node");
- _nodeMenu.setEnabled(false);
- toolsMenu.add(_nodeMenu);
- _nodeMenu.add(_actions[CommonBase.SHUTDOWN_NODE]);
-
- //
- // Server sub-menu
- //
- _serverMenu = new JMenu("Server");
- _serverMenu.setEnabled(false);
- toolsMenu.add(_serverMenu);
- _serverMenu.add(_actions[CommonBase.START]);
- _serverMenu.add(_actions[CommonBase.STOP]);
- _serverMenu.addSeparator();
- _serverMenu.add(_actions[CommonBase.ENABLE]);
- _serverMenu.add(_actions[CommonBase.DISABLE]);
- _serverMenu.addSeparator();
- _serverMenu.add(_actions[CommonBase.SERVER_INSTALL_DISTRIBUTION]);
-
- //
- // Service sub-menu
- //
- _serviceMenu = new JMenu("Service");
- _serviceMenu.setEnabled(false);
- toolsMenu.add(_serviceMenu);
- _serviceMenu.add(_actions[CommonBase.MOVE_UP]);
- _serviceMenu.add(_actions[CommonBase.MOVE_DOWN]);
-
- //
- // Help menu
- //
- JMenu helpMenu = new JMenu("Help");
- helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H);
- add(helpMenu);
-
- helpMenu.add(_helpContents);
- if(GPL_BUILD)
- {
- helpMenu.addSeparator();
- helpMenu.add(_copying);
- helpMenu.add(_warranty);
- }
-
- helpMenu.addSeparator();
- helpMenu.add(_about);
- }
- }
-
-
- private class ToolBar extends JToolBar
- {
- private ToolBar()
- {
- putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
- putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
- setFloatable(false);
- putClientProperty("JToolBar.isRollover", Boolean.TRUE);
-
- JButton button = new JButton(_login);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/login.png"));
- add(button);
-
- addSeparator();
-
- button = new JButton(_back);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/back.png"));
- add(button);
- button = new JButton(_forward);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/forward.png"));
- add(button);
-
- addSeparator();
-
- button = new JButton(_save);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/save.png"));
- add(button);
- button = new JButton(_discard);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/discard.png"));
- add(button);
-
- addSeparator();
-
- button = new JButton(_actions[CommonBase.COPY]);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/copy.png"));
- add(button);
- button = new JButton(_actions[CommonBase.PASTE]);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/paste.png"));
- add(button);
- button = new JButton(_actions[CommonBase.DELETE]);
- button.setText(null);
- button.setIcon(Utils.getIcon("/icons/24x24/delete.png"));
- add(button);
-
- addSeparator();
-
- add(_showVarsTool);
- add(_substituteTool);
- }
- }
-
- //
- // All Model's methods run in the UI thread
- //
- public Ice.Communicator getCommunicator()
- {
- return _communicator;
- }
-
- public Root getRoot()
- {
- return _root;
- }
-
- public TreeModelI getTreeModel()
- {
- return _treeModel;
- }
-
-
- //
- // From the Registry observer:
- //
-
- void registryInit(int serial, final java.util.List applications)
- {
- assert(_latestSerial == -1);
- _latestSerial = serial;
- _root.init(applications);
- }
-
- void applicationAdded(int serial, ApplicationDescriptor desc)
- {
- if(proceedWithUpdate(serial))
- {
- _root.applicationAdded(desc);
- _statusBar.setText(
- "Last update: new application '" + desc.name + "'");
- checkWriteSerial();
- }
- }
-
- void applicationRemoved(int serial, String name)
- {
- if(proceedWithUpdate(serial))
- {
- _root.applicationRemoved(name);
- _statusBar.setText(
- "Last update: application '" + name + "' was removed");
- checkWriteSerial();
- }
- }
-
- void applicationUpdated(int serial, ApplicationUpdateDescriptor desc)
- {
- if(proceedWithUpdate(serial))
- {
- TreePath path = null;
- CommonBase currentNode = (CommonBase)_tree.getLastSelectedPathComponent();
- if(currentNode != null)
- {
- path = currentNode.getPath();
- }
- _root.applicationUpdated(desc);
- _statusBar.setText("Last update: application '" + desc.name + "' was updated");
- checkWriteSerial();
- restore(path);
- }
- }
-
- boolean proceedWithUpdate(int serial)
- {
- if(_latestSerial == -1 || serial <= _latestSerial)
- {
- //
- // Ignore old messages and messages when we're logged out
- //
- return false;
- }
- else if(serial == _latestSerial + 1)
- {
- boolean doIt = (_latestSerial == -1 || _writeSerial == -1 ||
- _writeSerial > _latestSerial);
-
- if(_writeSerial == _latestSerial)
- {
- _writeSerial = serial;
- }
- _latestSerial = serial;
- return doIt;
- }
- else
- {
- _sessionKeeper.sessionLost(
- "Received message from IceGrid Registry out of order");
- return false;
- }
- }
-
- public CommonBase getSelectedNode()
- {
- return (CommonBase)_tree.getLastSelectedPathComponent();
- }
-
- public CommonBase findNewNode(TreePath path)
- {
- CommonBase node = _root;
- for(int i = 1; i < path.getPathCount(); ++i)
- {
- CommonBase child = node.findChild(((CommonBase)path.getPathComponent(i)).getId());
- if(child == null)
- {
- break;
- }
- else
- {
- node = child;
- }
- }
- return node;
- }
-
- public void setSelectionPath(TreePath path)
- {
- _tree.setSelectionPath(path);
- }
-
- public void refreshDisplay()
- {
- CommonBase currentNode = getSelectedNode();
- if(currentNode != null)
- {
- show(currentNode);
- }
- }
-
- public boolean displayEnabled()
- {
- return _displayEnabled;
- }
-
- public void enableDisplay()
- {
- _displayEnabled = true;
- }
-
- public void disableDisplay()
- {
- _displayEnabled = false;
- }
-
- private void restore(TreePath path)
- {
- if(path != null)
- {
- CommonBase newNode = findNewNode(path);
- if(newNode == getSelectedNode())
- {
- refreshDisplay();
- }
- else
- {
- _tree.setSelectionPath(newNode.getPath());
- }
- }
- }
-
- public boolean canUpdate()
- {
- if(_latestSerial == -1)
- {
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Updates are not allowed while working offline",
- "Working Offline",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
-
- if(isUpdateInProgress())
- {
- return true;
- }
-
- try
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _writeSerial = _sessionKeeper.getSession().startUpdate();
- }
- catch(AccessDeniedException e)
- {
- _writeSerial = -1;
- accessDenied(e);
- return false;
- }
- finally
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- showActions();
-
- if(_writeSerial > _latestSerial)
- {
- //
- // Warn user that his updates were lost
- //
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Your view was not up-to-date;"
- + " you now have exclusive write-access to the" +
- " IceGrid Registry, however your previous changes were lost.",
- "Concurrent update",
- JOptionPane.WARNING_MESSAGE);
-
- //
- // TODO: wait for my view to be up to date
- //
- return false;
- }
- else
- {
- setUpdateInProgress();
- return true;
- }
- }
-
- public boolean isUpdateInProgress()
- {
- return _writeSerial != -1 &&
- _writeSerial >= _latestSerial;
- }
-
-
- private void checkWriteSerial()
- {
- if(_writeSerial != -1 && _writeSerial == _latestSerial)
- {
- setUpdateInProgress();
- }
- }
- private void setUpdateInProgress()
- {
- _statusBar.setText("Update in progress");
- _save.setEnabled(true);
- _discard.setEnabled(true);
- }
-
- private void accessDenied(AccessDeniedException e)
- {
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Another session (username = " + e.lockUserId + ") has exclusive write access to the registry",
- "Access Denied",
- JOptionPane.ERROR_MESSAGE);
-
- }
-
-
- public boolean removeApplication(String applicationName)
- {
- assert _writeSerial == _latestSerial;
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- try
- {
- _sessionKeeper.getSession().removeApplication(applicationName);
- return true;
- }
- catch(AccessDeniedException e)
- {
- // Very unlikely
- accessDenied(e);
- return false;
- }
- catch(ApplicationNotExistException e)
- {
- // Most likely an IceGrid bug, so no need to optimize!
- //
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Can't remove Application '" + e.name + "': it does not exist!",
- "Application does not exist",
- JOptionPane.ERROR_MESSAGE);
- return true;
- }
- finally
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- private boolean saveUpdates()
- {
- assert _writeSerial == _latestSerial;
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- try
- {
- for(int i = 0; i < _root.getChildCount(); ++i)
- {
- Application application = (Application)_root.getChildAt(i);
-
- try
- {
- if(application.isNew())
- {
- _sessionKeeper.getSession().addApplication(
- (ApplicationDescriptor)application.getDescriptor());
- application.commit();
- //
- // Will ignore this update
- //
- _latestSerial++;
- _writeSerial = _latestSerial;
- }
- else
- {
- ApplicationUpdateDescriptor updateDescriptor =
- application.createUpdateDescriptor();
- if(updateDescriptor != null)
- {
- _sessionKeeper.getSession().updateApplication(updateDescriptor);
- application.commit();
- //
- // Will ignore this update
- //
- _latestSerial++;
- _writeSerial = _latestSerial;
- }
- }
- }
- catch(AccessDeniedException e)
- {
- // Very unlikely
- accessDenied(e);
- return false;
- }
- catch(ApplicationNotExistException e)
- {
- // Most likely an IceGrid bug, so no need to optimize!
- //
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Can't update Application '" + e.name + "': it does not exist!",
- "Application does not exist",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- catch(DeploymentException e)
- {
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Application '" + application.getId() + "': "+ e.reason,
- "Deployment Exception",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- }
-
- //
- // Update completed entirely
- //
- try
- {
- _sessionKeeper.getSession().finishUpdate();
- }
- catch(AccessDeniedException e)
- {
- //
- // Very unlikely; we still consider the update a success.
- //
- accessDenied(e);
- }
-
- _writeSerial = -1;
- _save.setEnabled(false);
- _discard.setEnabled(false);
- showActions();
-
- _statusBar.setText("Saving complete");
- return true;
- }
- finally
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
-
- private void discardUpdates()
- {
- assert _writeSerial == _latestSerial;
-
- int reallyDiscard = JOptionPane.showConfirmDialog(
- _mainFrame,
- "Do you want to discard all your updates?",
- "Discard Confirmation",
- JOptionPane.YES_NO_OPTION);
-
- if(reallyDiscard == JOptionPane.YES_OPTION)
- {
- _sessionKeeper.relog(false);
- }
- }
-
-
- //
- // From the Node observer:
- //
-
- void nodeUp(NodeDynamicInfo updatedInfo)
- {
- _root.nodeUp(updatedInfo);
- showActions();
- refreshCurrentStatus();
- }
-
- void nodeDown(String node)
- {
- _root.nodeDown(node);
- showActions();
- refreshCurrentStatus();
- }
-
- void updateServer(String node, ServerDynamicInfo updatedInfo)
- {
- _root.updateServer(node, updatedInfo);
- showActions();
- refreshCurrentStatus();
- }
-
- void updateAdapter(String node, AdapterDynamicInfo updatedInfo)
- {
- _root.updateAdapter(node, updatedInfo);
- showActions();
- refreshCurrentStatus();
- }
-
- //
- // Other methods
- //
- void sessionLost()
- {
- _latestSerial = -1;
- _writeSerial = -1;
- _admin = null;
- showActions();
- _logout.setEnabled(false);
- }
-
- SessionPrx login(SessionKeeper.LoginInfo info, Component parent)
- {
- _root.clear();
- _newApplication.setEnabled(false);
- _newMenu.setEnabled(false);
- _newApplicationWithDefaultTemplates.setEnabled(false);
-
- _previousNodes.clear();
- _nextNodes.clear();
- _currentNode = null;
- _back.setEnabled(false);
- _forward.setEnabled(false);
-
- SessionPrx session = null;
-
- if(_routedAdapter != null)
- {
- //
- // Clean it up!
- //
- _routedAdapter.removeRouter(_communicator.getDefaultRouter());
- _routedAdapter.deactivate();
- _routedAdapter.waitForDeactivate();
- _routedAdapter = null;
- }
-
- _communicator.setDefaultRouter(null);
- _communicator.setDefaultLocator(null);
-
- if(info.routed)
- {
- //
- // Router
- //
-
- String str = info.routerInstanceName + "/router";
- if(!info.routerEndpoints.equals(""))
- {
- str += ":" + info.routerEndpoints;
- }
-
- try
- {
- Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.
- uncheckedCast(_communicator.stringToProxy(str));
-
- //
- // The session must be routed through this router
- //
- _communicator.setDefaultRouter(router);
-
- Glacier2.SessionPrx s =
- router.createSession(
- info.routerUsername, new String(info.routerPassword));
-
- session = SessionPrxHelper.uncheckedCast(s);
- }
- catch(Glacier2.PermissionDeniedException e)
- {
- JOptionPane.showMessageDialog(parent,
- "Permission denied: "
- + e.reason,
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- return null;
- }
- catch(Glacier2.CannotCreateSessionException e)
- {
- JOptionPane.showMessageDialog(parent,
- "Could not create session: "
- + e.reason,
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- return null;
- }
- catch(Ice.LocalException e)
- {
- JOptionPane.showMessageDialog(parent,
- "Could not create session: "
- + e.toString(),
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- return null;
- }
- }
- else
- {
- //
- // The client uses the locator only without routing
- //
- String str = info.registryInstanceName + "/Locator";
- if(!info.registryEndpoints.equals(""))
- {
- str += ":" + info.registryEndpoints;
- }
-
- try
- {
- Ice.LocatorPrx defaultLocator = Ice.LocatorPrxHelper.
- checkedCast(_communicator.stringToProxy(str));
- _communicator.setDefaultLocator(defaultLocator);
- }
- catch(Ice.LocalException e)
- {
- JOptionPane.showMessageDialog(
- parent,
- "Could not contact '" + str + "': " + e.toString(),
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- return null;
- }
-
- //
- // Local session
- //
- str = info.registryInstanceName + "/SessionManager";
-
- SessionManagerPrx sessionManager = SessionManagerPrxHelper.
- uncheckedCast(_communicator.stringToProxy(str));
-
- try
- {
- session = sessionManager.createLocalSession(info.registryUsername);
- }
- catch(Ice.LocalException e)
- {
- JOptionPane.showMessageDialog(parent,
- "Could not create session: "
- + e.toString(),
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- return null;
- }
- }
-
- //
- // Admin
- //
- try
- {
- _admin = session.getAdmin();
- }
- catch(Ice.LocalException e)
- {
- JOptionPane.showMessageDialog(
- parent,
- "Could not retrieve Admin proxy: " + e.toString(),
- "Login failed",
- JOptionPane.ERROR_MESSAGE);
- destroySession(session);
- return null;
- }
-
- _newApplication.setEnabled(true);
- _newApplicationWithDefaultTemplates.setEnabled(true);
- _newMenu.setEnabled(true);
- _logout.setEnabled(true);
-
- return session;
- }
-
- Ice.ObjectAdapter getObjectAdapter()
- {
- Ice.RouterPrx router = _communicator.getDefaultRouter();
-
- if(router == null)
- {
- if(_localAdapter == null)
- {
- _localAdapter =
- _communicator.createObjectAdapter("IceGrid.AdminGUI");
- _localAdapter.activate();
- }
- return _localAdapter;
- }
- else
- {
- if(_routedAdapter == null)
- {
- //
- // Needs a unique name since we destroy this adapter at
- // each new login
- //
- String name = "RoutedAdapter-" + Ice.Util.generateUUID();
-
- _routedAdapter =
- _communicator.createObjectAdapter(name);
- _routedAdapter.addRouter(router);
- _routedAdapter.activate();
- }
- return _routedAdapter;
- }
- }
-
-
- void destroySession(SessionPrx session)
- {
- Ice.RouterPrx router = _communicator.getDefaultRouter();
-
- try
- {
- if(router == null)
- {
- session.destroy();
- }
- else
- {
- Glacier2.RouterPrx gr
- = Glacier2.RouterPrxHelper.uncheckedCast(router);
- gr.destroySession();
- }
- }
- catch(Glacier2.SessionNotExistException e)
- {
- // Ignored
- }
- catch(Ice.LocalException e)
- {
- // Ignored
- }
- }
-
- private void showVars()
- {
- substitute(false);
- }
-
- private void substituteVars()
- {
- substitute(true);
- }
-
- private void substitute(boolean newValue)
- {
- if(_substitute != newValue)
- {
- _substitute = newValue;
-
- if(_substitute)
- {
- _substituteMenuItem.setSelected(true);
- _substituteTool.setSelected(true);
- }
- else
- {
- _showVarsMenuItem.setSelected(true);
- _showVarsTool.setSelected(true);
- }
- refreshDisplay();
- }
- }
-
- public boolean substitute()
- {
- return _substitute;
- }
-
- public AdminPrx getAdmin()
- {
- return _admin;
- }
-
- public StatusBar getStatusBar()
- {
- return _statusBar;
- }
-
- public void setTree(JTree tree)
- {
- _tree = tree;
- _tree.getActionMap().put("copy", _actions[CommonBase.COPY]);
- _tree.getActionMap().put("paste", _actions[CommonBase.PASTE]);
-
- SelectionListener appSelectionListener = new SelectionListener();
- tree.addTreeSelectionListener(
- new SelectionListener());
-
- }
-
- public JTree getTree()
- {
- return _tree;
- }
-
- public SimpleInternalFrame getPropertiesFrame()
- {
- return _propertiesFrame;
- }
-
- public SimpleInternalFrame getCurrentStatusFrame()
- {
- return _currentStatusFrame;
- }
-
- public JFrame getMainFrame()
- {
- return _mainFrame;
- }
-
- static private Ice.Communicator createCommunicator(String[] args)
- {
- Ice.StringSeqHolder argSeq = new Ice.StringSeqHolder(args);
-
- Ice.Properties properties = Ice.Util.createProperties(argSeq);
-
- //
- // Set various default values
- //
- if(properties.getProperty("Ice.Override.ConnectTimeout").equals(""))
- {
- properties.setProperty("Ice.Override.ConnectTimeout", "5000");
- }
-
- if(properties.getProperty("IceGrid.AdminGUI.Endpoints").equals(""))
- {
- properties.setProperty("IceGrid.AdminGUI.Endpoints", "tcp -t 10000");
- }
-
- //
- // For SSL
- //
- if(properties.getProperty("Ice.ThreadPerConnection").equals(""))
- {
- properties.setProperty("Ice.ThreadPerConnection", "1");
- }
-
- //
- // For Glacier
- //
- if(properties.getProperty("Ice.ACM.Client").equals(""))
- {
- properties.setProperty("Ice.ACM.Client", "0");
- }
- if(properties.getProperty("Ice.MonitorConnections").equals(""))
- {
- properties.setProperty("Ice.MonitorConnections", "5");
- }
-
- //
- // Retries are not useful when using Glacier2, however
- // they are not harmful either.
- //
- // For now we retry to work-around bug #574:
- // properties.setProperty("Ice.RetryIntervals", "-1");
-
- return Ice.Util.initializeWithProperties(argSeq, properties);
- }
-
- Model(JFrame mainFrame, String[] args, Preferences prefs, StatusBar statusBar)
- {
- _mainFrame = mainFrame;
- _prefs = prefs;
- _statusBar = statusBar;
- _communicator = createCommunicator(args);
-
- _root = new Root(this);
- _treeModel = new TreeModelI(_root);
-
- _licenseDialog = new LicenseDialog(_mainFrame);
-
- _shutdownHook = new Thread("Shutdown hook")
- {
- public void run()
- {
- destroyCommunicator();
- }
- };
- Runtime.getRuntime().addShutdownHook(_shutdownHook);
-
- //
- // Fixed height for current status frame
- //
- Dimension prefSize = new Dimension(0, 160);
- Dimension maxSize = new Dimension(Short.MAX_VALUE, 160);
- _currentStatusFrame.setMinimumSize(prefSize);
- _currentStatusFrame.setPreferredSize(prefSize);
- _currentStatusFrame.setMaximumSize(maxSize);
- _currentStatusFrame.getTitleLabel().setEnabled(false);
- _propertiesFrame.getTitleLabel().setEnabled(false);
-
- final int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-
- //
- // Common actions (nodes not involved)
- //
- _newApplication = new AbstractAction("Application without default templates")
- {
- public void actionPerformed(ActionEvent e)
- {
- newApplication();
- }
- };
- _newApplication.setEnabled(false);
-
- _newApplicationWithDefaultTemplates =
- new AbstractAction("Application")
- {
- public void actionPerformed(ActionEvent e)
- {
- newApplicationWithDefaultTemplates();
- }
- };
- _newApplicationWithDefaultTemplates.setEnabled(false);
-
- _login = new AbstractAction("Login...")
- {
- public void actionPerformed(ActionEvent e)
- {
- login();
- }
- };
- _login.putValue(Action.SHORT_DESCRIPTION,
- "Log into an IceGrid Registry");
-
- _logout = new AbstractAction("Logout")
- {
- public void actionPerformed(ActionEvent e)
- {
- logout();
- }
- };
- _logout.putValue(Action.SHORT_DESCRIPTION, "Logout");
- _logout.setEnabled(false);
-
- _save = new AbstractAction("Save")
- {
- public void actionPerformed(ActionEvent e)
- {
- saveUpdates();
- }
- };
- _save.setEnabled(false);
- _save.putValue(Action.ACCELERATOR_KEY,
- KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK));
- _save.putValue(Action.SHORT_DESCRIPTION, "Save to IceGrid Registry");
-
- _discard = new AbstractAction("Discard all updates...")
- {
- public void actionPerformed(ActionEvent e)
- {
- discardUpdates();
- }
- };
- _discard.setEnabled(false);
- _discard.putValue(Action.SHORT_DESCRIPTION, "Discard all updates");
-
- _exit = new AbstractAction("Exit")
- {
- public void actionPerformed(ActionEvent e)
- {
- exit(0);
- }
- };
- _exit.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt F4"));
-
-
- _back = new AbstractAction("Go back to the previous node")
- {
- public void actionPerformed(ActionEvent e)
- {
- back();
- }
- };
- _back.setEnabled(false);
- _back.putValue(Action.SHORT_DESCRIPTION, "Go back to the previous node");
-
- _forward = new AbstractAction("Go to the next node")
- {
- public void actionPerformed(ActionEvent e)
- {
- forward();
- }
- };
- _forward.setEnabled(false);
- _forward.putValue(Action.SHORT_DESCRIPTION, "Go to the next node");
-
- _helpContents = new AbstractAction("Contents")
- {
- public void actionPerformed(ActionEvent e)
- {
- helpContents();
- }
- };
-
- _copying = new AbstractAction("Copying conditions")
- {
- public void actionPerformed(ActionEvent e)
- {
- _licenseDialog.show("TOP");
- }
- };
-
- _warranty = new AbstractAction("(Non)Warranty")
- {
- public void actionPerformed(ActionEvent e)
- {
- _licenseDialog.show("WARRANTY");
- }
- };
-
- _about = new AbstractAction("About")
- {
- public void actionPerformed(ActionEvent e)
- {
- about();
- }
- };
-
-
- //
- // Actions implemented by the nodes
- //
- _actions = new Action[CommonBase.ACTION_COUNT];
-
- _actions[CommonBase.NEW_ADAPTER] = new AbstractAction("Adapter")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newAdapter();
- }
- };
-
- _actions[CommonBase.NEW_DBENV] = new AbstractAction("Database environment")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newDbEnv();
- }
- };
-
- _actions[CommonBase.NEW_NODE] = new AbstractAction("Node")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newNode();
- }
- };
-
- _actions[CommonBase.NEW_REPLICA_GROUP] = new AbstractAction("Replica group")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newReplicaGroup();
- }
- };
-
- _actions[CommonBase.NEW_SERVER] = new AbstractAction("Server")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newServer();
- }
- };
-
- _actions[CommonBase.NEW_SERVER_ICEBOX] = new AbstractAction("IceBox server")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newServerIceBox();
- }
- };
-
- _actions[CommonBase.NEW_SERVER_FROM_TEMPLATE] = new AbstractAction("Server from template")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newServerFromTemplate();
- }
- };
-
-
- _actions[CommonBase.NEW_SERVICE] = new AbstractAction("Service")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newService();
- }
- };
-
- _actions[CommonBase.NEW_SERVICE_FROM_TEMPLATE] = new AbstractAction("Service from template")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newServiceFromTemplate();
- }
- };
-
- _actions[CommonBase.NEW_TEMPLATE_SERVER] = new AbstractAction("Server template")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newTemplateServer();
- }
- };
-
- _actions[CommonBase.NEW_TEMPLATE_SERVER_ICEBOX] = new AbstractAction("IceBox server template")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newTemplateServerIceBox();
- }
- };
-
-
- _actions[CommonBase.NEW_TEMPLATE_SERVICE] = new AbstractAction("Service template")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.newTemplateService();
- }
- };
-
-
- _actions[CommonBase.COPY] = new AbstractAction("Copy")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.copy();
- }
- };
- _actions[CommonBase.COPY].putValue(Action.ACCELERATOR_KEY,
- KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK));
- _actions[CommonBase.COPY].putValue(Action.SHORT_DESCRIPTION, "Copy");
-
- _actions[CommonBase.PASTE] = new AbstractAction("Paste")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.paste();
- }
- };
- _actions[CommonBase.PASTE].putValue(Action.ACCELERATOR_KEY,
- KeyStroke.getKeyStroke(KeyEvent.VK_V, MENU_MASK));
- _actions[CommonBase.PASTE].putValue(Action.SHORT_DESCRIPTION, "Paste");
-
- _actions[CommonBase.DELETE] = new AbstractAction("Delete")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.delete();
- }
- };
- _actions[CommonBase.DELETE].putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE"));
- _actions[CommonBase.DELETE].putValue(Action.SHORT_DESCRIPTION, "Delete");
-
- _actions[CommonBase.SHOW_VARS] = new
- AbstractAction("Show variables")
- {
- public void actionPerformed(ActionEvent e)
- {
- showVars();
- }
- };
- _actions[CommonBase.SHOW_VARS].putValue(
- Action.SHORT_DESCRIPTION,
- "Show variables and parameters in the Properties pane");
-
-
- _actions[CommonBase.SUBSTITUTE_VARS] = new
- AbstractAction("Substitute variables")
- {
- public void actionPerformed(ActionEvent e)
- {
- substituteVars();
- }
- };
-
- _actions[CommonBase.SUBSTITUTE_VARS].putValue(
- Action.SHORT_DESCRIPTION,
- "Substitute variables and parameters with their values in the Properties pane");
-
-
- _showVarsMenuItem = new
- JCheckBoxMenuItem(_actions[CommonBase.SHOW_VARS]);
- _showVarsTool = new
- JToggleButton(_actions[CommonBase.SHOW_VARS]);
- _showVarsTool.setIcon(Utils.getIcon("/icons/24x24/show_vars.png"));
- _showVarsTool.setText("");
-
- _substituteMenuItem = new
- JCheckBoxMenuItem(_actions[CommonBase.SUBSTITUTE_VARS]);
- _substituteTool = new
- JToggleButton(_actions[CommonBase.SUBSTITUTE_VARS]);
- _substituteTool.setIcon(Utils.getIcon("/icons/24x24/substitute.png"));
- _substituteTool.setText("");
-
-
- ButtonGroup group = new ButtonGroup();
- group.add(_showVarsMenuItem);
- group.add(_substituteMenuItem);
- group = new ButtonGroup();
- group.add(_showVarsTool);
- group.add(_substituteTool);
-
- _showVarsMenuItem.setSelected(true);
- _showVarsTool.setSelected(true);
-
- _actions[CommonBase.MOVE_UP] = new AbstractAction("Move up")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.moveUp();
- }
- };
-
- _actions[CommonBase.MOVE_DOWN] = new AbstractAction("Move down")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.moveDown();
- }
- };
-
- _actions[CommonBase.START] = new AbstractAction(
- "Start", Utils.getIcon("/icons/16x16/start.png"))
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.start();
- }
- };
- _actions[CommonBase.START].putValue(Action.SHORT_DESCRIPTION,
- "Start this server");
-
-
- _actions[CommonBase.STOP] = new AbstractAction(
- "Stop", Utils.getIcon("/icons/16x16/stop.png"))
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.stop();
- }
- };
- _actions[CommonBase.STOP].putValue(Action.SHORT_DESCRIPTION,
- "Stop this server");
-
-
- _actions[CommonBase.ENABLE] = new AbstractAction(
- "Enable", Utils.getIcon("/icons/16x16/enable.png"))
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.enable();
- }
- };
- _actions[CommonBase.ENABLE].putValue(Action.SHORT_DESCRIPTION,
- "Enable this server");
-
- _actions[CommonBase.DISABLE] = new AbstractAction(
- "Disable", Utils.getIcon("/icons/16x16/disable.png"))
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.disable();
- }
- };
- _actions[CommonBase.DISABLE].putValue(Action.SHORT_DESCRIPTION,
- "Disable this server");
-
- _actions[CommonBase.SHUTDOWN_NODE] = new AbstractAction("Shutdown")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.shutdownNode();
- }
- };
- _actions[CommonBase.APPLICATION_INSTALL_DISTRIBUTION] =
- new AbstractAction("Patch")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.applicationInstallDistribution();
- }
- };
- _actions[CommonBase.SERVER_INSTALL_DISTRIBUTION] =
- new AbstractAction("Patch")
- {
- public void actionPerformed(ActionEvent e)
- {
- _actionsTarget.serverInstallDistribution();
- }
- };
- }
-
- void show(CommonBase node)
- {
- if(_displayEnabled)
- {
- showActions(node);
-
- _currentEditor = node.getEditor();
-
- Ice.StringHolder title = new Ice.StringHolder();
- Component currentStatus = _currentEditor.getCurrentStatus(title);
- if(title.value == null)
- {
- title.value = "Current status";
- }
- _currentStatusFrame.setTitle(title.value);
-
- if(currentStatus == null)
- {
- _currentStatusFrame.setToolBar(null);
- Component oldContent = _currentStatusFrame.getContent();
- if(oldContent != null)
- {
- _currentStatusFrame.remove(oldContent);
- }
- _currentStatusFrame.getTitleLabel().setEnabled(false);
- }
- else
- {
- _currentStatusFrame.setToolBar(
- _currentEditor.getCurrentStatusToolBar());
- _currentStatusFrame.setContent(currentStatus);
- _currentStatusFrame.getTitleLabel().setEnabled(true);
- }
- _currentStatusFrame.validate();
- _currentStatusFrame.repaint();
-
- Component currentProperties = _currentEditor.getProperties();
-
- if(currentProperties == null)
- {
- Component oldContent = _propertiesFrame.getContent();
- if(oldContent != null)
- {
- _propertiesFrame.remove(oldContent);
- }
- _propertiesFrame.getTitleLabel().setEnabled(false);
- }
- else
- {
- _propertiesFrame.setContent(currentProperties);
- _propertiesFrame.getTitleLabel().setEnabled(true);
- }
- _propertiesFrame.validate();
- _propertiesFrame.repaint();
- }
- }
-
- void refreshCurrentStatus()
- {
- if(_currentEditor != null)
- {
- _currentEditor.refreshCurrentStatus();
- }
- }
-
- //
- // New application action
- //
- private void newApplication()
- {
- _root.newApplication();
- }
- private void newApplicationWithDefaultTemplates()
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- try
- {
- ApplicationDescriptor descriptor = _admin.getDefaultApplicationDescriptor();
- descriptor.name = "NewApplication";
- _root.newApplication(descriptor);
- }
- catch(DeploymentException e)
- {
- JOptionPane.showMessageDialog(
- _mainFrame,
- "The default application descriptor from the IceGrid Registry is invalid:\n"
- + e.reason,
- "Deployment Exception",
- JOptionPane.ERROR_MESSAGE);
- }
- catch(Ice.LocalException e)
- {
- JOptionPane.showMessageDialog(
- _mainFrame,
- "Could not retrieve the default application descriptor from the IceGrid Registry: \n"
- + e.toString(),
- "Trouble with IceGrid Registry",
- JOptionPane.ERROR_MESSAGE);
- }
- finally
- {
- _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- //
- // Login and logout action
- //
- private void login()
- {
- if(_latestSerial != -1 && _latestSerial == _writeSerial)
- {
- int saveFirst = JOptionPane.showConfirmDialog(
- _mainFrame,
- "Do you want to save your updates?",
- "Save Confirmation",
- JOptionPane.YES_NO_CANCEL_OPTION);
-
- switch(saveFirst)
- {
- case JOptionPane.YES_OPTION:
- if(saveUpdates())
- {
- _sessionKeeper.relog(true);
- }
- break;
- case JOptionPane.NO_OPTION:
- _sessionKeeper.relog(true);
- break;
- case JOptionPane.CANCEL_OPTION:
- break;
- default:
- assert false;
- }
- }
- else
- {
- _sessionKeeper.relog(true);
- }
- }
-
- private void logout()
- {
- if(_latestSerial != -1 && _latestSerial == _writeSerial)
- {
- int saveFirst = JOptionPane.showConfirmDialog(
- _mainFrame,
- "Do you want to save your updates?",
- "Save Confirmation",
- JOptionPane.YES_NO_CANCEL_OPTION);
-
- switch(saveFirst)
- {
- case JOptionPane.YES_OPTION:
- if(saveUpdates())
- {
- _sessionKeeper.logout(true);
- }
- break;
- case JOptionPane.NO_OPTION:
- _sessionKeeper.logout(true);
- break;
- case JOptionPane.CANCEL_OPTION:
- break;
- default:
- assert false;
- }
- }
- else
- {
- _sessionKeeper.logout(true);
- }
- }
-
- //
- // Navigation
- //
-
- private void cleanList(java.util.LinkedList list)
- {
- CommonBase previous = null;
- java.util.Iterator p = list.iterator();
- while(p.hasNext())
- {
- CommonBase current = (CommonBase)p.next();
- if(current == previous || current.getParent() == null)
- {
- p.remove();
- }
- else
- {
- previous = current;
- }
- }
- }
-
- private void back()
- {
- cleanList(_previousNodes);
-
- if(_previousNodes.size() == 0)
- {
- _back.setEnabled(false);
- }
- else
- {
- CommonBase previousNode = (CommonBase)_previousNodes.removeLast();
- if(_previousNodes.size() == 0)
- {
- _back.setEnabled(false);
- }
-
- if(previousNode != _currentNode)
- {
- assert _currentNode != null;
- if(_currentNode.isEphemeral())
- {
- _currentNode.destroy();
- }
- else
- {
- assert _currentNode.getParent() != null;
- _nextNodes.addFirst(_currentNode);
- _forward.setEnabled(true);
- }
-
- _currentNode = previousNode;
- _selectionListenerEnabled = false;
- _tree.setSelectionPath(_currentNode.getPath());
- _selectionListenerEnabled = true;
- show(_currentNode);
- }
- }
- }
-
- private void forward()
- {
- cleanList(_nextNodes);
-
- if(_nextNodes.size() == 0)
- {
- _forward.setEnabled(false);
- }
- else
- {
- CommonBase nextNode = (CommonBase)_nextNodes.removeFirst();
- if(_nextNodes.size() == 0)
- {
- _forward.setEnabled(false);
- }
-
- if(nextNode != _currentNode)
- {
- assert _currentNode != null;
- assert !_currentNode.isEphemeral();
- assert _currentNode.getParent() != null;
-
- _previousNodes.add(_currentNode);
- _back.setEnabled(true);
-
- _currentNode = nextNode;
- _selectionListenerEnabled = false;
- _tree.setSelectionPath(_currentNode.getPath());
- _selectionListenerEnabled = true;
- show(_currentNode);
- }
- }
- }
-
- private void helpContents()
- {
- BareBonesBrowserLaunch.openURL(
- "http://www.zeroc.com/help/IceGridAdmin/");
- }
-
- private void about()
- {
- String text = "IceGrid Admin version "
- + IceUtil.Version.ICE_STRING_VERSION + "\n"
- + "Copyright \u00A9 2005 ZeroC, Inc. All rights reserved.\n";
-
- JOptionPane.showMessageDialog(
- _mainFrame,
- text,
- "About - IceGrid Admin",
- JOptionPane.INFORMATION_MESSAGE);
- }
-
- public void setClipboard(Object copy)
- {
- _clipboard = copy;
- }
-
- public Object getClipboard()
- {
- return _clipboard;
- }
-
- void showMainFrame()
- {
- if(!loadWindowPrefs())
- {
- _mainFrame.setLocation(100, 100);
- _mainFrame.pack();
- }
- _mainFrame.setVisible(true);
- }
-
- void exit(int status)
- {
- storeWindowPrefs();
- destroyCommunicator();
- _mainFrame.dispose();
- Runtime.getRuntime().removeShutdownHook(_shutdownHook);
- Runtime.getRuntime().exit(status);
- }
-
- //
- // Can be called by the shutdown hook thread
- //
- private void destroyCommunicator()
- {
- try
- {
- _communicator.destroy();
- }
- catch(Ice.LocalException e)
- {
- System.err.println("_communicator.destroy() raised "
- + e.toString());
- }
- }
-
- private boolean loadWindowPrefs()
- {
- try
- {
- if(!_prefs.nodeExists("Window"))
- {
- return false;
- }
- }
- catch(BackingStoreException e)
- {
- return false;
- }
-
- Preferences windowPrefs = _prefs.node("Window");
- int x = windowPrefs.getInt("x", 0);
- int y = windowPrefs.getInt("y", 0);
- int width = windowPrefs.getInt("width", 0);
- int height = windowPrefs.getInt("height", 0);
- _mainFrame.setBounds(new Rectangle(x, y, width, height));
- if(windowPrefs.getBoolean("maximized", false))
- {
- _mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
- }
- return true;
- }
-
- private void storeWindowPrefs()
- {
- Preferences windowPrefs = _prefs.node("Window");
- Rectangle rect = _mainFrame.getBounds();
- windowPrefs.putInt("x", rect.x);
- windowPrefs.putInt("y", rect.y);
- windowPrefs.putInt("width", rect.width);
- windowPrefs.putInt("height", rect.height);
- windowPrefs.putBoolean("maximized",
- _mainFrame.getExtendedState() == Frame.MAXIMIZED_BOTH);
- }
-
-
- SessionKeeper getSessionKeeper()
- {
- if(_sessionKeeper == null)
- {
- _sessionKeeper = new SessionKeeper(this);
- }
- return _sessionKeeper;
- }
-
- Preferences getPrefs()
- {
- return _prefs;
- }
-
-
- public Action[] getActions()
- {
- return _actions;
- }
-
- public void showActions()
- {
- showActions(_actionsTarget);
- }
- public void showActions(CommonBase node)
- {
- _actionsTarget = node;
-
- boolean[] availableActions;
- if(node == null)
- {
- availableActions = new boolean[CommonBase.ACTION_COUNT];
- }
- else
- {
- availableActions = node.getAvailableActions();
- }
-
- for(int i = 0; i < _actions.length; ++i)
- {
- _actions[i].setEnabled(availableActions[i]);
- }
-
-
- _newServerMenu.setEnabled(
- availableActions[CommonBase.NEW_SERVER] ||
- availableActions[CommonBase.NEW_SERVER_ICEBOX] ||
- availableActions[CommonBase.NEW_SERVER_FROM_TEMPLATE]);
-
- _newServiceMenu.setEnabled(
- availableActions[CommonBase.NEW_SERVICE] ||
- availableActions[CommonBase.NEW_SERVICE_FROM_TEMPLATE]);
-
- _newTemplateMenu.setEnabled(
- availableActions[CommonBase.NEW_TEMPLATE_SERVER] ||
- availableActions[CommonBase.NEW_TEMPLATE_SERVER_ICEBOX] ||
- availableActions[CommonBase.NEW_TEMPLATE_SERVICE]);
-
- _appMenu.setEnabled(
- availableActions[CommonBase.APPLICATION_INSTALL_DISTRIBUTION]);
-
- _nodeMenu.setEnabled(
- availableActions[CommonBase.SHUTDOWN_NODE]);
-
- _serverMenu.setEnabled(
- availableActions[CommonBase.START] ||
- availableActions[CommonBase.STOP] ||
- availableActions[CommonBase.ENABLE] ||
- availableActions[CommonBase.DISABLE] ||
- availableActions[CommonBase.SERVER_INSTALL_DISTRIBUTION]);
-
- _serviceMenu.setEnabled(
- availableActions[CommonBase.MOVE_UP] ||
- availableActions[CommonBase.MOVE_DOWN]);
- }
-
- void createMenuBar()
- {
- _mainFrame.setJMenuBar(new MenuBar());
- }
-
- void createToolBar()
- {
- _mainFrame.getContentPane().add(new ToolBar(),
- BorderLayout.PAGE_START);
- }
-
-
- private final Ice.Communicator _communicator;
- private Preferences _prefs;
- private StatusBar _statusBar;
- private AdminPrx _admin;
-
- private Ice.ObjectAdapter _localAdapter;
- private Ice.ObjectAdapter _routedAdapter;
-
- private Root _root;
- private TreeModelI _treeModel;
-
- private int _latestSerial = -1;
- private int _writeSerial = -1;
-
- private JTree _tree;
-
- private boolean _substitute = false;
-
- private boolean _displayEnabled = true;
-
- private SimpleInternalFrame _currentStatusFrame
- = new SimpleInternalFrame("Current status");
- private SimpleInternalFrame _propertiesFrame
- = new SimpleInternalFrame("Properties");
-
- private JFrame _mainFrame;
- private SessionKeeper _sessionKeeper;
-
- private Editor _currentEditor;
-
- private Object _clipboard;
-
- private LicenseDialog _licenseDialog;
-
- //
- // back/forward navigation
- //
- private java.util.LinkedList _previousNodes = new java.util.LinkedList();
- private CommonBase _currentNode;
- private java.util.LinkedList _nextNodes = new java.util.LinkedList();
- private boolean _selectionListenerEnabled = true;
-
- //
- // Actions
- //
- private Action _newApplication;
- private Action _newApplicationWithDefaultTemplates;
- private Action _login;
- private Action _logout;
- private Action _save;
- private Action _discard;
- private Action _exit;
- private Action _back;
- private Action _forward;
- private Action _helpContents;
- private Action _copying;
- private Action _warranty;
- private Action _about;
-
-
- private Action[] _actions;
-
- private JToggleButton _showVarsTool;
- private JToggleButton _substituteTool;
- private JCheckBoxMenuItem _substituteMenuItem;
- private JCheckBoxMenuItem _showVarsMenuItem;
-
- private CommonBase _actionsTarget;
-
- private JMenu _newMenu;
- private JMenu _newServerMenu;
- private JMenu _newServiceMenu;
- private JMenu _newTemplateMenu;
- private JMenu _appMenu;
- private JMenu _nodeMenu;
- private JMenu _serverMenu;
- private JMenu _serviceMenu;
-
- private final Thread _shutdownHook;
-
- static private final int HISTORY_MAX_SIZE = 20;
-
- //
- // TODO: should come from build system
- //
- static private final boolean GPL_BUILD = true;
-}
diff --git a/java/src/IceGrid/TreeModelI.java b/java/src/IceGrid/TreeModelI.java
deleted file mode 100755
index 1defa45ff44..00000000000
--- a/java/src/IceGrid/TreeModelI.java
+++ /dev/null
@@ -1,132 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
-
-import java.util.EventListener;
-
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
-import javax.swing.event.EventListenerList;
-import javax.swing.event.TreeModelListener;
-import javax.swing.event.TreeModelEvent;
-
-public class TreeModelI implements TreeModel
-{
- public Object getRoot()
- {
- return _root;
- }
-
- public Object getChild(Object parent, int index)
- {
- return ((IceGrid.TreeNode.CommonBase)parent).getChildAt(index);
- }
-
- public int getChildCount(Object parent)
- {
- return ((IceGrid.TreeNode.CommonBase)parent).getChildCount();
- }
-
- public boolean isLeaf(Object node)
- {
- return ((IceGrid.TreeNode.CommonBase)node).isLeaf();
- }
-
- public void valueForPathChanged(TreePath path, Object newValue)
- {
- // TODO: implement
- }
-
- public int getIndexOfChild(Object parent, Object child)
- {
- if(parent == null)
- {
- return -1;
- }
- else
- {
- return ((IceGrid.TreeNode.CommonBase)parent).getIndex(child);
- }
- }
-
- public void addTreeModelListener(TreeModelListener listener)
- {
- _listenerList.add(TreeModelListener.class, listener);
- }
-
- public void removeTreeModelListener(TreeModelListener listener)
- {
- _listenerList.remove(TreeModelListener.class, listener);
- }
-
- TreeModelI(Object root)
- {
- _root = root;
- }
-
- public void fireNodesChangedEvent(TreeModelEvent e)
- {
- // Guaranteed to return a non-null array
- Object[] listeners = _listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >=0 ; i -= 2)
- {
- if (listeners[i] == TreeModelListener.class)
- {
- ((TreeModelListener)listeners[i + 1]).treeNodesChanged(e);
- }
- }
- }
-
- public void fireStructureChangedEvent(TreeModelEvent e)
- {
- // Guaranteed to return a non-null array
- Object[] listeners = _listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >=0 ; i -= 2)
- {
- if (listeners[i] == TreeModelListener.class)
- {
- ((TreeModelListener)listeners[i + 1]).treeStructureChanged(e);
- }
- }
- }
-
- public void fireNodesInsertedEvent(TreeModelEvent e)
- {
- // Guaranteed to return a non-null array
- Object[] listeners = _listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >=0 ; i -= 2)
- {
- if (listeners[i] == TreeModelListener.class)
- {
- ((TreeModelListener)listeners[i + 1]).treeNodesInserted(e);
- }
- }
- }
-
- public void fireNodesRemovedEvent(TreeModelEvent e)
- {
- // Guaranteed to return a non-null array
- Object[] listeners = _listenerList.getListenerList();
-
- for(int i = listeners.length - 2; i >=0 ; i -= 2)
- {
- if (listeners[i] == TreeModelListener.class)
- {
- ((TreeModelListener)listeners[i + 1]).treeNodesRemoved(e);
- }
- }
- }
-
- private Object _root;
- private EventListenerList _listenerList = new EventListenerList();
-}
-
diff --git a/java/src/IceGrid/TreeNode/AbstractServerEditor.java b/java/src/IceGrid/TreeNode/AbstractServerEditor.java
deleted file mode 100755
index 8354d5eed6d..00000000000
--- a/java/src/IceGrid/TreeNode/AbstractServerEditor.java
+++ /dev/null
@@ -1,265 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.JOptionPane;
-import javax.swing.JTextField;
-import javax.swing.JToolBar;
-
-import com.jgoodies.looks.Options;
-import com.jgoodies.looks.HeaderStyle;
-import com.jgoodies.looks.BorderStyle;
-import com.jgoodies.looks.plastic.PlasticLookAndFeel;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-
-import IceGrid.Model;
-import IceGrid.ServerDescriptor;
-import IceGrid.ServerInstanceDescriptor;
-import IceGrid.ServerState;
-
-//
-// Base class for ServerEditor and ServerInstanceEditor
-//
-
-abstract class AbstractServerEditor extends Editor
-{
- abstract protected void writeDescriptor();
- abstract protected boolean isSimpleUpdate();
-
- private class ToolBar extends JToolBar
- {
- private ToolBar()
- {
- putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE);
- putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
- setFloatable(false);
- putClientProperty("JToolBar.isRollover", Boolean.TRUE);
-
- add(_model.getActions()[CommonBase.START]);
- add(_model.getActions()[CommonBase.STOP]);
- addSeparator();
- add(_model.getActions()[CommonBase.ENABLE]);
- add(_model.getActions()[CommonBase.DISABLE]);
- }
- }
-
-
- public JToolBar getCurrentStatusToolBar()
- {
- if(_toolBar == null)
- {
- _toolBar = new ToolBar();
- }
- return _toolBar;
- }
-
- public void refreshCurrentStatus()
- {
- Server server = (Server)_target;
-
- ServerState state = server.getState();
- if(state == null)
- {
- _currentState.setText("Unknown");
- _currentPid.setText("");
- }
- else
- {
- _currentState.setText(state.toString());
- int pid = server.getPid();
- if(pid == 0)
- {
- _currentPid.setText("");
- }
- else
- {
- _currentPid.setText(Integer.toString(pid));
- }
- }
- }
-
-
- protected void applyUpdate()
- {
- Server server = (Server)_target;
- Model model = server.getModel();
-
- if(model.canUpdate())
- {
- model.disableDisplay();
-
- try
- {
- if(server.isEphemeral())
- {
- Node node = (Node)server.getParent();
- writeDescriptor();
- ServerInstanceDescriptor instanceDescriptor =
- server.getInstanceDescriptor();
- ServerDescriptor serverDescriptor =
- server.getServerDescriptor();
-
- server.destroy(); // just removes the child
-
- try
- {
- node.tryAdd(instanceDescriptor, serverDescriptor, true);
- }
- catch(UpdateFailedException e)
- {
- //
- // Add back ephemeral child
- //
- try
- {
- node.addChild(server, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- model.setSelectionPath(server.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- if(instanceDescriptor != null)
- {
- _target = node.findChildWithDescriptor(instanceDescriptor);
- }
- else
- {
- _target = node.findChildWithDescriptor(serverDescriptor);
- }
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- //
- // If this new server has a known state, display it
- //
- ((Server)_target).fireNodeChangedEvent(this);
-
- }
- else if(isSimpleUpdate())
- {
- writeDescriptor();
- _target.getEditable().markModified();
- }
- else
- {
- //
- // Save to be able to rollback
- //
- Object savedDescriptor = server.saveDescriptor();
- Node node = (Node)server.getParent();
- writeDescriptor();
-
- ServerInstanceDescriptor instanceDescriptor =
- server.getInstanceDescriptor();
- ServerDescriptor serverDescriptor =
- server.getServerDescriptor();
-
- node.removeChild(server, true);
-
- try
- {
- node.tryAdd(instanceDescriptor, serverDescriptor, false);
- }
- catch(UpdateFailedException e)
- {
- //
- // Restore all
- //
- try
- {
- node.addChild(server, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- server.restoreDescriptor(savedDescriptor);
- model.setSelectionPath(server.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- node.removeElement(server.getId()); // replaced by brand new Server
-
- if(instanceDescriptor != null)
- {
- _target = node.findChildWithDescriptor(instanceDescriptor);
- }
- else
- {
- _target = node.findChildWithDescriptor(serverDescriptor);
- }
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
-
- //
- // If this server has a known state, display it
- //
- ((Server)_target).fireNodeChangedEvent(this);
-
- }
-
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
- }
- finally
- {
- model.enableDisplay();
- }
- }
- }
-
-
- void appendCurrentStatus(DefaultFormBuilder builder)
- {
- builder.append("State");
- builder.append(_currentState, 3);
- builder.nextLine();
-
- builder.append("Process ID");
- builder.append(_currentPid, 3);
- builder.nextLine();
- }
-
- protected AbstractServerEditor(Model model)
- {
- super(true, true);
- _model = model;
-
- _currentState.setEditable(false);
- _currentPid.setEditable(false);
- }
-
- private JTextField _currentState = new JTextField(20);
- private JTextField _currentPid = new JTextField(20);
-
- private JToolBar _toolBar;
- private Model _model;
-}
diff --git a/java/src/IceGrid/TreeNode/Adapter.java b/java/src/IceGrid/TreeNode/Adapter.java
deleted file mode 100755
index f71e94acef6..00000000000
--- a/java/src/IceGrid/TreeNode/Adapter.java
+++ /dev/null
@@ -1,308 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.Icon;
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.SimpleInternalFrame;
-
-import IceGrid.AdapterDescriptor;
-import IceGrid.Model;
-import IceGrid.Utils;
-
-class Adapter extends Leaf
-{
- static public AdapterDescriptor copyDescriptor(AdapterDescriptor d)
- {
- return (AdapterDescriptor)d.clone();
- }
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
-
- if(_parent.getAvailableActions()[PASTE])
- {
- actions[PASTE] = true;
- }
- if(isEditable())
- {
- actions[DELETE] = true;
- }
-
- if(_resolver != null && !_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
- return actions;
- }
-
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_descriptor));
- if(_parent.getAvailableActions()[PASTE])
- {
- _model.getActions()[PASTE].setEnabled(true);
- }
- }
- public void paste()
- {
- _parent.paste();
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _activeIcon = Utils.getIcon("/icons/16x16/adapter_active.png");
- _inactiveIcon = Utils.getIcon("/icons/16x16/adapter_inactive.png");
- }
-
- if(_currentEndpoints == null || _currentEndpoints.equals(""))
- {
- _cellRenderer.setLeafIcon(_inactiveIcon);
- }
- else
- {
- _cellRenderer.setLeafIcon(_activeIcon);
- }
-
-
- _cellRenderer.setToolTipText(_toolTip);
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new AdapterEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
-
- public boolean destroy()
- {
- return _parent == null ? false :
- ((ListParent)_parent).destroyChild(this);
- }
-
- public void setParent(CommonBase parent)
- {
- if(_resolver != null)
- {
- //
- // In a server instance
- //
- _adapterId = _resolver.substitute(_descriptor.id);
- Ice.ObjectPrx proxy =
- _model.getRoot().registerAdapter(_resolver.find("node"),
- this);
- setCurrentEndpoints(proxy);
-
- //
- // No need to fire an event since this node is not yet in the tree
- //
- }
- super.setParent(parent);
- }
-
- public void clearParent()
- {
- if(_parent != null)
- {
- if(_adapterId != null)
- {
- _model.getRoot().unregisterAdapter(_resolver.find("node"),
- this);
- }
- super.clearParent();
- }
- }
-
- public Object getDescriptor()
- {
- return _descriptor;
- }
-
- public Object saveDescriptor()
- {
- return copyDescriptor(_descriptor);
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- AdapterDescriptor ad = (AdapterDescriptor)savedDescriptor;
-
- _descriptor.name = ad.name;
- _descriptor.id = ad.id;
- _descriptor.replicaGroupId = ad.replicaGroupId;
- _descriptor.description = ad.description;
- _descriptor.registerProcess = ad.registerProcess;
- _descriptor.waitForActivation = ad.waitForActivation;
- _descriptor.objects = ad.objects;
- }
-
- Adapter(String adapterName, AdapterDescriptor descriptor,
- Utils.Resolver resolver, Model model)
- {
- super(adapterName, model);
- _descriptor = descriptor;
- _resolver = resolver;
- _ephemeral = false;
- }
-
- //
- // Fresh new temporary Adapter
- // Never becomes permanent; instead a new non-ephemeral Adapter is
- // created upon a successful "apply"
- //
- Adapter(String name, AdapterDescriptor descriptor, Model model)
- {
- super(name, model);
- _descriptor = descriptor;
- _ephemeral = true;
- }
-
- void updateProxy(Ice.ObjectPrx proxy)
- {
- setCurrentEndpoints(proxy);
- fireNodeChangedEvent(this);
- }
-
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- boolean isEditable()
- {
- if(_parent == null)
- {
- return false;
- }
- else
- {
- return ((Adapters)_parent).isEditable();
- }
-
- }
-
- boolean inIceBox()
- {
- return ((Adapters)_parent).inIceBox();
- }
-
- String getProperty(String property)
- {
- PropertiesHolder ph = getParent().getParent().getPropertiesHolder();
- assert ph != null;
- return ph.get(_descriptor.name + "." + property);
- }
- void setProperty(String name, String property, String newValue)
- {
- PropertiesHolder ph = getParent().getParent().getPropertiesHolder();
- assert ph != null;
- ph.set(name + "." + property, newValue);
- }
- void removeProperty(String name, String property)
- {
- PropertiesHolder ph = getParent().getParent().getPropertiesHolder();
- assert ph != null;
- ph.remove(name + "." + property);
- }
-
- String getAdapterId()
- {
- return _adapterId;
- }
-
- String getDefaultAdapterId()
- {
- return getDefaultAdapterId(_id);
- }
-
- String getDefaultAdapterId(String name)
- {
- CommonBase grandParent = _parent.getParent();
-
- return (grandParent instanceof Service ||
- grandParent instanceof ServiceTemplate) ?
- "${server}.${service}." + name: "${server}." + name;
- }
-
- String getCurrentEndpoints()
- {
- return _currentEndpoints;
- }
-
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- private void setCurrentEndpoints(Ice.ObjectPrx proxy)
- {
- if(proxy == null)
- {
- _currentEndpoints = null;
- _toolTip = "Inactive";
- }
- else
- {
- String str = _model.getCommunicator().proxyToString(proxy);
- int index = str.indexOf(':');
- if(index == -1 || index == str.length() - 1)
- {
- _currentEndpoints = "";
- }
- else
- {
- _currentEndpoints = str.substring(index + 1);
- }
- _toolTip = "Published endpoints: " + _currentEndpoints;
- }
- }
-
- private final boolean _ephemeral;
- private AdapterDescriptor _descriptor;
- private Utils.Resolver _resolver;
-
- private String _currentEndpoints;
- private String _toolTip;
-
- private String _adapterId; // resolved adapter id, null when _resolver == null
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private Icon _activeIcon;
- static private Icon _inactiveIcon;
-
- static private AdapterEditor _editor;
-}
diff --git a/java/src/IceGrid/TreeNode/Adapters.java b/java/src/IceGrid/TreeNode/Adapters.java
deleted file mode 100755
index 70770ca227d..00000000000
--- a/java/src/IceGrid/TreeNode/Adapters.java
+++ /dev/null
@@ -1,174 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-
-import IceGrid.AdapterDescriptor;
-import IceGrid.Model;
-import IceGrid.Utils;
-
-class Adapters extends ListParent
-{
- static public java.util.LinkedList
- copyDescriptors(java.util.LinkedList descriptors)
- {
- java.util.LinkedList copy = new java.util.LinkedList();
- java.util.Iterator p = descriptors.iterator();
- while(p.hasNext())
- {
- copy.add(Adapter.copyDescriptor((AdapterDescriptor)p.next()));
- }
- return copy;
- }
-
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
-
- Object descriptor = _model.getClipboard();
- if(descriptor != null)
- {
- actions[PASTE] = canHaveNewChild() &&
- descriptor instanceof AdapterDescriptor;
- }
-
- actions[NEW_ADAPTER] = canHaveNewChild();
- return actions;
- }
-
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_ADAPTER]);
- item.setText("New adapter");
- _popup.add(item);
- }
- if(canHaveNewChild())
- {
- return _popup;
- }
- else
- {
- return null;
- }
- }
-
- public void newAdapter()
- {
- String name = makeNewChildId("NewAdapter");
- AdapterDescriptor descriptor = new AdapterDescriptor(
- name,
- "",
- null,
- "",
- false,
- true,
- new java.util.LinkedList());
-
- newAdapter(descriptor);
- }
-
- public void paste()
- {
- Object descriptor = _model.getClipboard();
- assert canHaveNewChild() &&
- descriptor instanceof AdapterDescriptor;
-
- AdapterDescriptor d = Adapter.copyDescriptor(
- (AdapterDescriptor)descriptor);
- d.name = makeNewChildId(d.name);
- newAdapter(d);
- }
-
-
- Adapters(java.util.List descriptors, boolean isEditable,
- boolean inIceBox, Utils.Resolver resolver,
- Model model)
- throws UpdateFailedException
- {
- super("Adapters", model);
- _descriptors = descriptors;
- _isEditable = isEditable;
- _inIceBox = inIceBox;
- _resolver = resolver;
-
- java.util.Iterator p = _descriptors.iterator();
- while(p.hasNext())
- {
- AdapterDescriptor descriptor = (AdapterDescriptor)p.next();
- addChild(createAdapter(descriptor));
- }
- }
-
- boolean isEditable()
- {
- return _isEditable;
- }
-
- CommonBase addNewChild(Object d) throws UpdateFailedException
- {
- AdapterDescriptor descriptor = (AdapterDescriptor)d;
-
- try
- {
- Adapter adapter = createAdapter(descriptor);
- addChild(adapter, true);
- return adapter;
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
- boolean inIceBox()
- {
- return _inIceBox;
- }
-
- boolean canHaveNewChild()
- {
- return _isEditable && !_inIceBox;
- }
-
- private void newAdapter(AdapterDescriptor descriptor)
- {
- Adapter adapter = new Adapter(descriptor.name, descriptor, _model);
- try
- {
- addChild(adapter, true);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- _model.setSelectionPath(adapter.getPath());
- }
-
- private Adapter createAdapter(AdapterDescriptor descriptor)
- {
- String adapterName = Utils.substitute(descriptor.name, _resolver);
- return new Adapter(adapterName, descriptor, _resolver, _model);
- }
-
- private Utils.Resolver _resolver;
- private boolean _isEditable;
- private boolean _inIceBox;
-
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/Application.java b/java/src/IceGrid/TreeNode/Application.java
deleted file mode 100755
index cfa21aa6a0a..00000000000
--- a/java/src/IceGrid/TreeNode/Application.java
+++ /dev/null
@@ -1,701 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Cursor;
-import java.awt.Component;
-
-import javax.swing.Icon;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPopupMenu;
-import javax.swing.SwingUtilities;
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.AMI_Admin_patchApplication;
-import IceGrid.AdapterDynamicInfo;
-import IceGrid.ApplicationDescriptor;
-import IceGrid.ApplicationUpdateDescriptor;
-import IceGrid.DistributionDescriptor;
-import IceGrid.Model;
-import IceGrid.NodeInfo;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.ServerState;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-
-public class Application extends EditableParent
-{
- static public ApplicationDescriptor
- copyDescriptor(ApplicationDescriptor ad)
- {
- ApplicationDescriptor copy = (ApplicationDescriptor)ad.clone();
-
- copy.replicaGroups =
- ReplicaGroups.copyDescriptors(copy.replicaGroups);
-
- copy.serverTemplates =
- ServerTemplates.copyDescriptors(copy.serverTemplates);
-
- copy.serviceTemplates =
- ServiceTemplates.copyDescriptors(copy.serviceTemplates);
-
- copy.nodes = Nodes.copyDescriptors(copy.nodes);
-
- copy.distrib = (DistributionDescriptor)copy.distrib.clone();
- return copy;
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _cellRenderer.setOpenIcon(
- Utils.getIcon("/icons/16x16/application_open.png"));
- _cellRenderer.setClosedIcon(
- Utils.getIcon("/icons/16x16/application_closed.png"));
- }
-
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
-
- actions[COPY] = true;
- actions[DELETE] = true;
-
- Object descriptor = _model.getClipboard();
- if(descriptor != null)
- {
- actions[PASTE] = descriptor instanceof ApplicationDescriptor;
- }
- if(!_model.isUpdateInProgress() && _model.getAdmin() != null)
- {
- actions[APPLICATION_INSTALL_DISTRIBUTION] =
- !_descriptor.distrib.icepatch.equals("");
- }
-
- if(!_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
-
- actions[NEW_NODE] = (_nodes != null);
- actions[NEW_REPLICA_GROUP] = (_replicaGroups != null);
- actions[NEW_TEMPLATE_SERVER] = (_serverTemplates != null);
- actions[NEW_TEMPLATE_SERVER_ICEBOX] = (_serverTemplates != null);
- actions[NEW_TEMPLATE_SERVICE] = (_serviceTemplates != null);
-
- return actions;
- }
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
-
- JMenuItem newNodeItem = new JMenuItem(_model.getActions()[NEW_NODE]);
- newNodeItem.setText("New node");
- _popup.add(newNodeItem);
-
- JMenuItem newReplicaGroupItem = new JMenuItem(_model.getActions()[NEW_REPLICA_GROUP]);
- newReplicaGroupItem.setText("New replica group");
- _popup.add(newReplicaGroupItem);
- _popup.addSeparator();
-
- JMenuItem newServerItem = new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVER]);
- newServerItem.setText("New server template");
- _popup.add(newServerItem);
- JMenuItem newIceBoxItem =
- new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVER_ICEBOX]);
- newIceBoxItem.setText("New IceBox server template");
- _popup.add(newIceBoxItem);
- _popup.addSeparator();
-
- JMenuItem newServiceItem = new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVICE]);
- newServiceItem.setText("New service template");
- _popup.add(newServiceItem);
- _popup.addSeparator();
-
- _popup.add(_model.getActions()[APPLICATION_INSTALL_DISTRIBUTION]);
- }
- return _popup;
- }
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_descriptor));
- _model.getActions()[PASTE].setEnabled(true);
- }
- public void paste()
- {
- _parent.paste();
- }
- public void newNode()
- {
- _nodes.newNode();
- }
- public void newReplicaGroup()
- {
- _replicaGroups.newReplicaGroup();
- }
- public void newTemplateServer()
- {
- _serverTemplates.newTemplateServer();
- }
- public void newTemplateServerIceBox()
- {
- _serverTemplates.newTemplateServerIceBox();
- }
- public void newTemplateService()
- {
- _serviceTemplates.newTemplateService();
- }
-
- public void applicationInstallDistribution()
- {
- int shutdown = JOptionPane.showConfirmDialog(
- _model.getMainFrame(),
- "You are about to install or refresh"
- + " the distribution of your application onto this node.\n"
- + " Do you want shut down all servers affected by this update?",
- "Patch Confirmation",
- JOptionPane.YES_NO_CANCEL_OPTION);
-
- if(shutdown == JOptionPane.CANCEL_OPTION)
- {
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
-
- return;
- }
-
- final String prefix = "Patching application '" + _id + "'...";
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_patchApplication cb = new AMI_Admin_patchApplication()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to patch " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to patch " + _id, e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- _model.getAdmin().patchApplication_async(cb, _id,
- shutdown == JOptionPane.YES_OPTION);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to patch " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
-
-
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
- }
-
- public ApplicationUpdateDescriptor createUpdateDescriptor()
- {
- ApplicationUpdateDescriptor update = new ApplicationUpdateDescriptor();
- update.name = _descriptor.name;
- if(isModified())
- {
- //
- // Diff description
- //
- if(!_descriptor.description.equals(_origDescription))
- {
- update.description =
- new IceGrid.BoxedString(_descriptor.description);
- }
-
- //
- // Diff variables
- //
- update.variables = (java.util.TreeMap)_descriptor.variables.clone();
- java.util.List removeVariables = new java.util.LinkedList();
-
- java.util.Iterator p = _origVariables.entrySet().iterator();
- while(p.hasNext())
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- Object key = entry.getKey();
- Object newValue = update.variables.get(key);
- if(newValue == null)
- {
- removeVariables.add(key);
- }
- else
- {
- Object value = entry.getValue();
- if(newValue.equals(value))
- {
- update.variables.remove(key);
- }
- }
- }
- update.removeVariables = (String[])removeVariables.toArray(new String[0]);
-
- //
- // Diff distribution
- //
- if(!_descriptor.distrib.equals(_origDistrib))
- {
- update.distrib = new IceGrid.BoxedDistributionDescriptor(
- _descriptor.distrib);
- }
- }
- else
- {
- update.variables = new java.util.TreeMap();
- update.removeVariables = new String[0];
- }
-
- //
- // Replicated Adapters
- //
- update.removeReplicaGroups = _replicaGroups.removedElements();
- update.replicaGroups = _replicaGroups.getUpdates();
-
- //
- // Server Templates
- //
- update.removeServerTemplates = _serverTemplates.removedElements();
- update.serverTemplates = _serverTemplates.getUpdates();
-
- //
- // Service Templates
- //
- update.removeServiceTemplates = _serviceTemplates.removedElements();
- update.serviceTemplates =_serviceTemplates.getUpdates();
-
- //
- // Nodes
- //
- update.removeNodes = _nodes.removedElements();
- update.nodes = _nodes.getUpdates();
-
-
- //
- // Return null if nothing changed
- //
- if(!isModified() &&
- update.removeReplicaGroups.length == 0 &&
- update.replicaGroups.size() == 0 &&
- update.removeServerTemplates.length == 0 &&
- update.serverTemplates.size() == 0 &&
- update.removeServiceTemplates.length == 0 &&
- update.serviceTemplates.size() == 0 &&
- update.removeNodes.length == 0 &&
- update.nodes.size() == 0)
- {
- return null;
- }
- else
- {
- return update;
- }
- }
-
- public void commit()
- {
- super.commit();
- _origVariables = _descriptor.variables;
- _origDescription = _descriptor.description;
- _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
- }
-
- public Object getDescriptor()
- {
- return _descriptor;
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new ApplicationEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- public Object saveDescriptor()
- {
- ApplicationDescriptor clone = (ApplicationDescriptor)_descriptor.clone();
- clone.distrib = (IceGrid.DistributionDescriptor)clone.distrib.clone();
- return clone;
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- ApplicationDescriptor clone = (ApplicationDescriptor)savedDescriptor;
-
- _descriptor.variables = clone.variables;
- _descriptor.distrib.icepatch = clone.distrib.icepatch;
- _descriptor.distrib.directories = clone.distrib.directories;
- _descriptor.description = clone.description;
- }
-
- public boolean destroy()
- {
- if(_parent == null)
- {
- return false;
- }
- Root root = (Root)_parent;
-
- if(_ephemeral || isNew())
- {
- root.removeChild(this, true);
- return true;
- }
- else if(_model.canUpdate())
- {
- int confirm = JOptionPane.showConfirmDialog(
- _model.getMainFrame(),
- "This will immediately remove this application from "
- + "the IceGrid Registry. Do you want to proceed?",
- "Remove Confirmation",
- JOptionPane.YES_NO_OPTION);
-
- //
- // Asks for confirmation
- //
- if(confirm == JOptionPane.YES_OPTION)
- {
- if(_model.removeApplication(_id))
- {
- root.removeChild(this, true);
- return true;
- }
- }
- }
- return false;
- }
-
-
- //
- // Builds the application and all its subtrees
- //
- Application(boolean brandNew, ApplicationDescriptor descriptor, Model model)
- throws UpdateFailedException
- {
- super(brandNew, descriptor.name, model);
- _ephemeral = false;
- _descriptor = descriptor;
- _origVariables = _descriptor.variables;
- _origDescription = _descriptor.description;
- _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
-
- _resolver = new Utils.Resolver(_descriptor.variables);
- _resolver.put("application", descriptor.name);
-
- _replicaGroups = new ReplicaGroups(_descriptor.replicaGroups,
- _model);
- addChild(_replicaGroups);
-
- _serviceTemplates = new ServiceTemplates(_descriptor.serviceTemplates,
- _model);
- addChild(_serviceTemplates);
-
- _serverTemplates = new ServerTemplates(descriptor.serverTemplates,
- this);
- addChild(_serverTemplates);
-
- _nodes = new Nodes(_descriptor.nodes, this);
- addChild(_nodes);
- }
-
- Application(ApplicationDescriptor descriptor, Model model)
- {
- super(false, descriptor.name, model);
- _ephemeral = true;
- _descriptor = descriptor;
- }
-
- //
- // Try to rebuild this application;
- // no-op if it fails!
- //
- void rebuild() throws UpdateFailedException
- {
- Utils.Resolver oldResolver = _resolver;
- _resolver = new Utils.Resolver(_descriptor.variables);
- _resolver.put("application", _id);
-
- try
- {
- _nodes.rebuild();
- }
- catch(UpdateFailedException e)
- {
- _resolver = oldResolver;
- throw e;
- }
- }
-
- //
- // Called when a server-template is deleted, to remove all
- // corresponding instances
- // children.
- //
- void removeServerInstances(String templateId)
- {
- _nodes.removeServerInstances(templateId);
- }
-
- //
- // Called when a service-template is deleted, to remove all
- // corresponding instances
- //
- void removeServiceInstances(String templateId)
- {
- _nodes.removeServiceInstances(templateId);
- _serverTemplates.removeServiceInstances(templateId);
- }
-
- void update(ApplicationUpdateDescriptor desc)
- throws UpdateFailedException
- {
- //
- // Description
- //
- if(desc.description != null)
- {
- _descriptor.description = desc.description.value;
- _origDescription = _descriptor.description;
- }
-
- //
- // Variables
- //
- for(int i = 0; i < desc.removeVariables.length; ++i)
- {
- _descriptor.variables.remove(desc.removeVariables[i]);
- }
- _descriptor.variables.putAll(desc.variables);
-
- //
- // Distrib
- //
- if(desc.distrib != null)
- {
- _descriptor.distrib = desc.distrib.value;
- _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
- }
-
- //
- // Replica groups
- //
- for(int i = 0; i < desc.removeReplicaGroups.length; ++i)
- {
- _descriptor.replicaGroups.remove(desc.
- removeReplicaGroups[i]);
- }
- _descriptor.replicaGroups.addAll(desc.replicaGroups);
- _replicaGroups.update(desc.replicaGroups,
- desc.removeReplicaGroups);
-
-
- //
- // Service templates
- //
- for(int i = 0; i < desc.removeServiceTemplates.length; ++i)
- {
- _descriptor.serviceTemplates.remove(desc.
- removeServiceTemplates[i]);
- }
- _descriptor.serviceTemplates.putAll(desc.serviceTemplates);
- _serviceTemplates.update(desc.serviceTemplates,
- desc.removeServiceTemplates);
-
- //
- // Server templates
- //
- for(int i = 0; i < desc.removeServerTemplates.length; ++i)
- {
- _descriptor.serverTemplates.remove(desc.removeServerTemplates[i]);
- }
- _descriptor.serverTemplates.putAll(desc.serverTemplates);
- _serverTemplates.update(desc.serverTemplates,
- desc.removeServerTemplates,
- desc.serviceTemplates.keySet());
-
- //
- // Nodes
- //
- for(int i = 0; i < desc.removeNodes.length; ++i)
- {
- _descriptor.nodes.remove(desc.removeNodes[i]);
- }
- //
- // Updates also _descriptor.nodes
- //
- _nodes.update(desc.nodes, desc.removeNodes,
- desc.serverTemplates.keySet(),
- desc.serviceTemplates.keySet());
-
- }
-
- ServerTemplate findServerTemplate(String id)
- {
- return (ServerTemplate)_serverTemplates.findChild(id);
- }
-
- ServiceTemplate findServiceTemplate(String id)
- {
- return (ServiceTemplate)_serviceTemplates.findChild(id);
- }
-
- ReplicaGroup findReplicaGroup(String id)
- {
- return (ReplicaGroup)_replicaGroups.findChild(id);
- }
-
- Node findNode(String id)
- {
- return (Node)_nodes.findChild(id);
- }
-
- java.util.List findServerInstances(String template)
- {
- return _nodes.findServerInstances(template);
- }
-
- java.util.List findServiceInstances(String template)
- {
- java.util.List result = _serverTemplates.findServiceInstances(template);
- result.addAll(_nodes.findServiceInstances(template));
- return result;
- }
-
-
- TemplateDescriptor findServerTemplateDescriptor(String templateName)
- {
- return (TemplateDescriptor)
- _descriptor.serverTemplates.get(templateName);
- }
-
- TemplateDescriptor findServiceTemplateDescriptor(String templateName)
- {
- return (TemplateDescriptor)
- _descriptor.serviceTemplates.get(templateName);
- }
-
- ServerTemplates getServerTemplates()
- {
- return _serverTemplates;
- }
-
- ServiceTemplates getServiceTemplates()
- {
- return _serviceTemplates;
- }
-
- ReplicaGroups getReplicaGroups()
- {
- return _replicaGroups;
- }
-
- //
- // Should only be used for reading
- //
- java.util.Map getVariables()
- {
- return _descriptor.variables;
- }
-
- void nodeUp(String nodeName, NodeInfo staticInfo)
- {
- _nodes.nodeUp(nodeName, staticInfo);
- }
-
- void nodeDown(String nodeName)
- {
- _nodes.nodeDown(nodeName);
- }
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- private ApplicationDescriptor _descriptor;
- private final boolean _ephemeral;
- private Utils.Resolver _resolver;
-
- //
- // Keeps original version (as shallow copies) to be able to build
- // ApplicationUpdateDescriptor
- //
- private java.util.TreeMap _origVariables;
- private String _origDescription;
- private DistributionDescriptor _origDistrib;
-
- //
- // Children
- //
- private ReplicaGroups _replicaGroups;
- private ServerTemplates _serverTemplates;
- private ServiceTemplates _serviceTemplates;
- private Nodes _nodes;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private ApplicationEditor _editor;
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/CommonBase.java b/java/src/IceGrid/TreeNode/CommonBase.java
deleted file mode 100755
index a4b2c960fac..00000000000
--- a/java/src/IceGrid/TreeNode/CommonBase.java
+++ /dev/null
@@ -1,180 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.tree.TreePath;
-import javax.swing.tree.TreeCellRenderer;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-
-import IceGrid.Model;
-import IceGrid.SimpleInternalFrame;
-
-//
-// CommonBase is similar to javax.swing.tree.TreeNode
-//
-
-public interface CommonBase extends TreeCellRenderer
-{
- Object getChildAt(int childIndex);
- int getChildCount();
- int getIndex(Object child);
- boolean isLeaf();
-
- CommonBase findChild(String id);
-
- //
- // Unique within the scope of each parent
- //
- String getId();
-
- Model getModel();
-
- //
- // Ephemeral objects are destroyed when you switch selection
- // without "apply"ing the changes.
- //
- boolean isEphemeral();
-
- //
- // Destroys this node, returns true when destroyed
- //
- boolean destroy();
-
- //
- // Get this node's parent;
- // null when the node is not attached to the root
- //
- CommonBase getParent();
-
- //
- // The path to this node;
- // null when the node is not attached to the root
- // typically used by children to create TreeModelEvents
- //
- TreePath getPath();
-
- Editor getEditor();
-
- //
- // Get properties
- //
- PropertiesHolder getPropertiesHolder();
-
- //
- // The enclosing editable
- //
- Editable getEditable();
-
- //
- // The enclosing Application
- //
- Application getApplication();
-
- //
- // Gets the associated descriptor
- //
- Object getDescriptor();
-
- //
- // Find child whose descriptor == the given descriptor
- //
- CommonBase findChildWithDescriptor(Object descriptor);
-
- //
- // Save & restore the descriptor
- // How much needs to be copied depends on how what the corresponding
- // editor writes.
- //
- Object saveDescriptor();
- void restoreDescriptor(Object savedDescriptor);
-
- //
- // Set this child's parent
- //
- void setParent(CommonBase parent);
- void clearParent();
-
- //
- // Find all instances of this child (including this child)
- //
- java.util.List findAllInstances(CommonBase child);
-
-
-
- //
- // Actions
- //
- static final int NEW_ADAPTER = 0;
- static final int NEW_DBENV = 1;
- static final int NEW_NODE = 2;
- static final int NEW_REPLICA_GROUP = 3;
- static final int NEW_SERVER = 4;
- static final int NEW_SERVER_ICEBOX = 5;
- static final int NEW_SERVER_FROM_TEMPLATE = 6;
- static final int NEW_SERVICE = 7;
- static final int NEW_SERVICE_FROM_TEMPLATE = 8;
- static final int NEW_TEMPLATE_SERVER = 9;
- static final int NEW_TEMPLATE_SERVER_ICEBOX = 10;
- static final int NEW_TEMPLATE_SERVICE = 11;
-
- static final int COPY = 12;
- static final int PASTE = 13;
- static final int DELETE = 14;
-
- static final int SHOW_VARS = 15;
- static final int SUBSTITUTE_VARS = 16;
-
- static final int MOVE_UP = 17;
- static final int MOVE_DOWN =18;
- static final int START = 19;
- static final int STOP = 20;
- static final int ENABLE = 21;
- static final int DISABLE = 22;
-
- static final int SHUTDOWN_NODE = 23;
-
- static final int APPLICATION_INSTALL_DISTRIBUTION = 24;
- static final int SERVER_INSTALL_DISTRIBUTION = 25;
-
- static public final int ACTION_COUNT = 26;
-
- boolean[] getAvailableActions();
-
- void newAdapter();
- void newDbEnv();
- void newNode();
- void newReplicaGroup();
- void newServer();
- void newServerIceBox();
- void newServerFromTemplate();
- void newService();
- void newServiceFromTemplate();
- void newTemplateServer();
- void newTemplateServerIceBox();
- void newTemplateService();
-
- void copy();
- void paste();
- void delete();
-
- void moveUp();
- void moveDown();
- void start();
- void stop();
- void enable();
- void disable();
-
- void shutdownNode();
-
- void applicationInstallDistribution();
- void serverInstallDistribution();
-
- JPopupMenu getPopupMenu();
-}
diff --git a/java/src/IceGrid/TreeNode/CommonBaseI.java b/java/src/IceGrid/TreeNode/CommonBaseI.java
deleted file mode 100755
index 020f6f64a88..00000000000
--- a/java/src/IceGrid/TreeNode/CommonBaseI.java
+++ /dev/null
@@ -1,477 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.JOptionPane;
-import javax.swing.JPopupMenu;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JTree;
-import javax.swing.SwingUtilities;
-import javax.swing.event.PopupMenuEvent;
-import javax.swing.event.PopupMenuListener;
-import javax.swing.event.TreeModelEvent;
-import javax.swing.tree.TreePath;
-
-import IceGrid.Model;
-import IceGrid.Utils;
-
-abstract class CommonBaseI implements CommonBase
-{
- static protected class PopupMenu extends JPopupMenu
- {
- PopupMenu(final Model model)
- {
- PopupMenuListener popupListener = new PopupMenuListener()
- {
- public void popupMenuCanceled(PopupMenuEvent e)
- {
- model.showActions(model.getSelectedNode());
- }
-
- public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
- {}
-
- public void popupMenuWillBecomeVisible(PopupMenuEvent e)
- {}
- };
-
- addPopupMenuListener(popupListener);
- }
- }
-
-
- public String toString()
- {
- if(isEphemeral())
- {
- return "*" + _id;
- }
- else
- {
- return _id;
- }
- }
-
- public String getId()
- {
- return _id;
- }
-
- public TreePath getPath()
- {
- return _path;
- }
-
- public CommonBase getParent()
- {
- return _parent;
- }
-
- public Editable getEditable()
- {
- if(_parent != null)
- {
- return _parent.getEditable();
- }
- else
- {
- return null;
- }
- }
-
- public boolean isEphemeral()
- {
- return false;
- }
-
- public boolean destroy()
- {
- //
- // Destruction not allowed
- //
- return false;
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new Editor(false, false);
- }
- return _editor;
- }
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- return null;
- }
-
- public PropertiesHolder getPropertiesHolder()
- {
- return null;
- }
-
- public Object getDescriptor()
- {
- return null;
- }
-
- public Object saveDescriptor()
- {
- assert false;
- return null;
- }
-
- public void restoreDescriptor(Object d)
- {
- assert false;
- }
-
- public java.util.List findAllInstances(CommonBase child)
- {
- assert getIndex(child) != -1;
-
- java.util.List result = new java.util.LinkedList();
- result.add(child);
- return result;
- }
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- return new boolean[ACTION_COUNT];
- }
- public void newAdapter()
- {
- assert false;
- }
- public void newDbEnv()
- {
- assert false;
- }
- public void newNode()
- {
- assert false;
- }
- public void newReplicaGroup()
- {
- assert false;
- }
- public void newServer()
- {
- assert false;
- }
- public void newServerIceBox()
- {
- assert false;
- }
- public void newServerFromTemplate()
- {
- assert false;
- }
- public void newService()
- {
- assert false;
- }
- public void newServiceFromTemplate()
- {
- assert false;
- }
- public void newTemplateServer()
- {
- assert false;
- }
- public void newTemplateServerIceBox()
- {
- assert false;
- }
- public void newTemplateService()
- {
- assert false;
- }
- public void copy()
- {
- assert false;
- }
- public void paste()
- {
- assert false;
- }
- public void delete()
- {
- TreePath parentPath = getParent().getPath();
- if(destroy())
- {
- if(parentPath.getPathCount() > 1)
- {
- _model.setSelectionPath(parentPath);
- }
- else
- {
- // TODO: show splash
- }
- }
- }
- public void moveUp()
- {
- assert false;
- }
- public void moveDown()
- {
- assert false;
- }
- public void start()
- {
- assert false;
- }
- public void stop()
- {
- assert false;
- }
- public void enable()
- {
- assert false;
- }
- public void disable()
- {
- assert false;
- }
- public void shutdownNode()
- {
- assert false;
- }
- public void applicationInstallDistribution()
- {
- assert false;
- }
- public void serverInstallDistribution()
- {
- assert false;
- }
-
- public JPopupMenu getPopupMenu()
- {
- return null;
- }
-
-
- //
- // Fires a nodesChanged event with this node
- //
- void fireNodeChangedEvent(Object source)
- {
- //
- // Bug if I am not attached to the root
- //
- assert _path != null;
-
- int[] childIndices = new int[1];
- Object[] children = new Object[1];
- children[0] = this;
-
- TreeModelEvent event;
-
- if(_parent == null)
- {
- //
- // I am root
- //
- childIndices[0] = 0;
- Object[] path = null;
- event = new TreeModelEvent(source, path, childIndices, children);
- }
- else
- {
- childIndices[0] = _parent.getIndex(this);
- event = new TreeModelEvent(source, _parent.getPath(), childIndices, children);
- }
- _model.getTreeModel().fireNodesChangedEvent(event);
- }
-
- void fireStructureChangedEvent(Object source)
- {
- assert _path != null;
-
- TreeModelEvent event = new TreeModelEvent(source, _path);
- _model.getTreeModel().fireStructureChangedEvent(event);
- }
-
- static String templateLabel(String templateName,
- java.util.List parameters,
- final java.util.Map parameterValues,
- final java.util.Map parameterDefaults)
- {
- String result = templateName + "<";
-
- Utils.Stringifier stringifier = new Utils.Stringifier()
- {
- public String toString(Object obj)
- {
- String name = (String)obj;
- String val = (String)parameterValues.get(name);
- if(val == null)
- {
- val = (String)parameterDefaults.get(name);
- }
- if(val != null)
- {
- return val;
- }
- else
- {
- return "";
- }
- }
- };
-
- result += Utils.stringify(parameters, stringifier, ", ", null);
- result += ">";
- return result;
- }
-
- protected CommonBaseI(String id, Model model, boolean root)
- {
- _id = id;
- _model = model;
-
- if(root)
- {
- _path = new TreePath(this);
- }
- }
-
- public Application getApplication()
- {
- if(_path == null || _path.getPathCount() < 2)
- {
- return null;
- }
- else
- {
- return (Application)_path.getPath()[1];
- }
- }
-
- public Model getModel()
- {
- return _model;
- }
-
- protected void amiSuccess(final String prefix)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _model.getStatusBar().setText(prefix + "done.");
- }
- });
- }
-
- protected void amiFailure(String prefix, String title, Ice.UserException e)
- {
- if(e instanceof IceGrid.ServerNotExistException)
- {
- IceGrid.ServerNotExistException sne =
- (IceGrid.ServerNotExistException)e;
-
- amiFailure(prefix, title,
- "Server '" + sne.id +
- "' was not registered with the IceGrid Registry");
- }
- else if(e instanceof IceGrid.ServerStartException)
- {
- IceGrid.ServerStartException ste = (IceGrid.ServerStartException)e;
- amiFailure(prefix, title, "Server '" +
- ste.id + "' did not start: " + ste.reason);
- }
- else if(e instanceof IceGrid.ApplicationNotExistException)
- {
- amiFailure(prefix, title,
- "This application was not registered with the IceGrid Registry");
- }
- else if(e instanceof IceGrid.PatchException)
- {
- IceGrid.PatchException pe = (IceGrid.PatchException)e;
- amiFailure(prefix, title, pe.reason);
- }
- else if(e instanceof IceGrid.NodeNotExistException)
- {
- IceGrid.NodeNotExistException nnee =
- (IceGrid.NodeNotExistException)e;
-
- amiFailure(prefix, title,
- "Node '" + nnee.name +
- " 'was not registered with the IceGrid Registry.");
- }
- else if(e instanceof IceGrid.NodeUnreachableException)
- {
- IceGrid.NodeUnreachableException nue =
- (IceGrid.NodeUnreachableException)e;
- amiFailure(prefix, title, "Node '" +
- nue.name + "' is unreachable: " + nue.reason);
- }
- else
- {
- amiFailure(prefix, title, e.toString());
- }
- }
-
- protected void amiFailure(final String prefix,
- final String title, final String message)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- failure(prefix, title, message);
- }
- });
- }
-
- protected void failure(String prefix, String title, String message)
- {
- _model.getStatusBar().setText(prefix + "failed!");
-
- JOptionPane.showMessageDialog(
- _model.getMainFrame(),
- message,
- title,
- JOptionPane.ERROR_MESSAGE);
- }
-
- protected TreePath _path;
- protected Parent _parent;
-
- //
- // Id (application name, server instance name etc)
- //
- protected String _id;
-
- //
- // The Model
- //
- protected Model _model;
-
- //
- // The default Editor
- //
- static private Editor _editor;
-}
diff --git a/java/src/IceGrid/TreeNode/DbEnv.java b/java/src/IceGrid/TreeNode/DbEnv.java
deleted file mode 100755
index 8137e8a65d4..00000000000
--- a/java/src/IceGrid/TreeNode/DbEnv.java
+++ /dev/null
@@ -1,171 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.Icon;
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.DbEnvDescriptor;
-import IceGrid.Model;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.Utils;
-
-class DbEnv extends Leaf
-{
- static public DbEnvDescriptor copyDescriptor(DbEnvDescriptor d)
- {
- return (DbEnvDescriptor)d.clone();
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/database.png"));
- }
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
-
- if(_parent.getAvailableActions()[PASTE])
- {
- actions[PASTE] = true;
- }
- if(isEditable())
- {
- actions[DELETE] = true;
- }
-
- if(_resolver != null && !_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
- return actions;
- }
-
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_descriptor));
- if(_parent.getAvailableActions()[PASTE])
- {
- _model.getActions()[PASTE].setEnabled(true);
- }
- }
- public void paste()
- {
- _parent.paste();
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new DbEnvEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
-
- public Object getDescriptor()
- {
- return _descriptor;
- }
-
- public Object copyDescriptor()
- {
- return copyDescriptor(_descriptor);
- }
-
- public Object saveDescriptor()
- {
- return copyDescriptor(_descriptor);
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- DbEnvDescriptor clone = (DbEnvDescriptor)savedDescriptor;
- _descriptor.name = clone.name;
- _descriptor.dbHome = clone.dbHome;
- _descriptor.description = clone.description;
- _descriptor.properties = clone.properties;
- }
-
- public boolean destroy()
- {
- return _parent == null ? false :
- ((ListParent)_parent).destroyChild(this);
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- DbEnv(String dbEnvName, DbEnvDescriptor descriptor,
- Utils.Resolver resolver, Model model)
- {
- super(dbEnvName, model);
- _ephemeral = false;
- _descriptor = descriptor;
- _resolver = resolver;
- }
-
- DbEnv(String dbEnvName, DbEnvDescriptor descriptor, Model model)
- {
- super(dbEnvName, model);
- _ephemeral = true;
- _descriptor = descriptor;
- }
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- boolean isEditable()
- {
- if(_parent == null)
- {
- return false;
- }
- else
- {
- return ((DbEnvs)_parent).isEditable();
- }
-
- }
-
- private DbEnvDescriptor _descriptor;
- private Utils.Resolver _resolver;
- private final boolean _ephemeral;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private DbEnvEditor _editor;
-}
diff --git a/java/src/IceGrid/TreeNode/DbEnvs.java b/java/src/IceGrid/TreeNode/DbEnvs.java
deleted file mode 100755
index 0d2aba1f9bb..00000000000
--- a/java/src/IceGrid/TreeNode/DbEnvs.java
+++ /dev/null
@@ -1,157 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-
-import IceGrid.DbEnvDescriptor;
-import IceGrid.Model;
-import IceGrid.Utils;
-
-class DbEnvs extends ListParent
-{
- static public java.util.LinkedList copyDescriptors(java.util.LinkedList list)
- {
- java.util.LinkedList copy = new java.util.LinkedList();
- java.util.Iterator p = list.iterator();
- while(p.hasNext())
- {
- copy.add(DbEnv.copyDescriptor((DbEnvDescriptor)p.next()));
- }
- return copy;
- }
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
-
- Object descriptor = _model.getClipboard();
- if(descriptor != null)
- {
- actions[PASTE] = _isEditable &&
- descriptor instanceof DbEnvDescriptor;
- }
-
- actions[NEW_DBENV] = _isEditable;
- return actions;
- }
-
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_DBENV]);
- item.setText("New DbEnv");
- _popup.add(item);
- }
- if(_isEditable)
- {
- return _popup;
- }
- else
- {
- return null;
- }
- }
-
- public void newDbEnv()
- {
- DbEnvDescriptor descriptor = new DbEnvDescriptor(
- "NewDbEnv",
- "",
- "",
- new java.util.LinkedList());
-
- newDbEnv(descriptor);
- }
- public void paste()
- {
- Object descriptor = _model.getClipboard();
- assert _isEditable &&
- descriptor instanceof DbEnvDescriptor;
-
- DbEnvDescriptor d = DbEnv.copyDescriptor(
- (DbEnvDescriptor)descriptor);
- d.name = makeNewChildId(d.name);
- newDbEnv(d);
- }
-
-
- CommonBase addNewChild(Object d) throws UpdateFailedException
- {
- DbEnvDescriptor descriptor = (DbEnvDescriptor)d;
-
- try
- {
- DbEnv dbEnv = createDbEnv(descriptor);
- addChild(dbEnv, true);
- return dbEnv;
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
- DbEnvs(java.util.List descriptors,
- boolean isEditable,
- Utils.Resolver resolver,
- Model model)
- throws UpdateFailedException
- {
- super("DbEnvs", model);
- _isEditable = isEditable;
- _descriptors = descriptors;
- _resolver = resolver;
-
- java.util.Iterator p = _descriptors.iterator();
- while(p.hasNext())
- {
- addChild(createDbEnv((DbEnvDescriptor)p.next()));
- }
- }
-
- boolean isEditable()
- {
- return _isEditable;
- }
-
- private DbEnv createDbEnv(DbEnvDescriptor descriptor)
- {
- String dbEnvName = Utils.substitute(descriptor.name, _resolver);
- return new DbEnv(dbEnvName, descriptor, _resolver, _model);
- }
-
- private void newDbEnv(DbEnvDescriptor descriptor)
- {
- descriptor.name = makeNewChildId(descriptor.name);
- DbEnv dbEnv = new DbEnv(descriptor.name, descriptor, _model);
- try
- {
- addChild(dbEnv, true);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- _model.setSelectionPath(dbEnv.getPath());
-
- }
-
- private final boolean _isEditable;
- private Utils.Resolver _resolver;
-
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/EditableLeaf.java b/java/src/IceGrid/TreeNode/EditableLeaf.java
deleted file mode 100755
index 348497abd72..00000000000
--- a/java/src/IceGrid/TreeNode/EditableLeaf.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-import IceGrid.Model;
-
-class EditableLeaf extends Leaf implements Editable
-{
- public boolean isNew()
- {
- return _isNew;
- }
-
- public boolean isModified()
- {
- return _modified;
- }
-
- public void markModified()
- {
- _modified = true;
- }
-
- public Editable getEditable()
- {
- return this;
- }
-
- public void commit()
- {
- _isNew = false;
- _modified = false;
- }
-
- protected EditableLeaf(boolean brandNew, String id, Model model)
- {
- super(id, model);
- _isNew = brandNew;
- }
-
- private boolean _isNew;
- private boolean _modified;
-}
diff --git a/java/src/IceGrid/TreeNode/EditableParent.java b/java/src/IceGrid/TreeNode/EditableParent.java
deleted file mode 100755
index 6f6cdf0aed5..00000000000
--- a/java/src/IceGrid/TreeNode/EditableParent.java
+++ /dev/null
@@ -1,96 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.Model;
-
-//
-// Corresponds to "root" editable descriptors such as Server,
-// ServerTemplate, ServiceTemplate, Node etc.
-//
-class EditableParent extends Parent implements Editable
-{
- public boolean isNew()
- {
- return _isNew;
- }
-
- public boolean isModified()
- {
- return _modified;
- }
-
- public void markModified()
- {
- _modified = true;
- }
-
- public Editable getEditable()
- {
- return this;
- }
-
- public void commit()
- {
- _isNew = false;
- _modified = false;
- _removedElements.clear();
-
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Object child = p.next();
- if(child instanceof Editable)
- {
- Editable editable = (Editable)child;
- editable.commit();
- }
- }
- }
-
- public void markNew()
- {
- _isNew = true;
- }
-
- void removeElement(CommonBase child, boolean fireEvent)
- {
- _removedElements.add(child.getId());
- removeChild(child, fireEvent);
- }
-
- void removeElement(String id)
- {
- _removedElements.add(id);
- }
-
- String[] removedElements()
- {
- return (String[])_removedElements.toArray(new String[0]);
- }
-
- protected EditableParent(boolean brandNew, String id, Model model, boolean root)
- {
- super(id, model, root);
- _isNew = brandNew;
- }
-
- protected EditableParent(boolean brandNew, String id, Model model)
- {
- this(brandNew, id, model, false);
- }
-
-
-
- private boolean _isNew = false;
- private boolean _modified = false;
- protected java.util.TreeSet _removedElements = new java.util.TreeSet();
-}
-
-
diff --git a/java/src/IceGrid/TreeNode/Editor.java b/java/src/IceGrid/TreeNode/Editor.java
deleted file mode 100755
index eedef56c8f9..00000000000
--- a/java/src/IceGrid/TreeNode/Editor.java
+++ /dev/null
@@ -1,301 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JToolBar;
-
-import javax.swing.tree.TreePath;
-
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.factories.Borders;
-import com.jgoodies.forms.factories.ButtonBarFactory;
-import com.jgoodies.forms.factories.DefaultComponentFactory;
-import com.jgoodies.forms.layout.FormLayout;
-import com.jgoodies.forms.util.LayoutStyle;
-
-import IceGrid.Model;
-import IceGrid.PropertyDescriptor;
-import IceGrid.Utils;
-
-//
-// Base class for all editors
-//
-public class Editor
-{
- public JComponent getProperties()
- {
- if(_propertiesPanel == null && _hasProperties)
- {
- buildPropertiesPanel();
- }
- return _propertiesPanel;
- }
-
- public JComponent getCurrentStatus(Ice.StringHolder title)
- {
- if(_currentStatusPanel == null && _hasCurrentStatus)
- {
- buildCurrentStatusPanel();
- }
- return _currentStatusPanel;
- }
-
- public JToolBar getCurrentStatusToolBar()
- {
- return null;
- }
-
- void appendProperties(DefaultFormBuilder builder)
- {}
-
- void appendCurrentStatus(DefaultFormBuilder builder)
- {}
-
- public void refreshCurrentStatus()
- {}
-
- protected void applyUpdate()
- {
- assert false;
- }
-
- private void buildCurrentStatusPanel()
- {
- assert _hasCurrentStatus;
-
- 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.setLineGapSize(LayoutStyle.getCurrent().getLinePad());
- appendCurrentStatus(builder);
-
- JScrollPane scrollPane =
- new JScrollPane(builder.getPanel(),
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
-
- scrollPane.setBorder(Borders.DIALOG_BORDER);
-
- _currentStatusPanel = new JPanel(new BorderLayout());
- _currentStatusPanel.add(scrollPane, BorderLayout.CENTER);
- _currentStatusPanel.setBorder(Borders.EMPTY_BORDER);
- }
-
- private void buildPropertiesPanel()
- {
- assert _hasProperties;
-
- 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.setLineGapSize(LayoutStyle.getCurrent().getLinePad());
-
- appendProperties(builder);
-
- JScrollPane scrollPane =
- new JScrollPane(builder.getPanel(),
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
-
- scrollPane.setBorder(Borders.DIALOG_BORDER);
-
- _propertiesPanel = new JPanel(new BorderLayout());
- _propertiesPanel.add(scrollPane, BorderLayout.CENTER);
- _propertiesPanel.setBorder(Borders.EMPTY_BORDER);
-
- JComponent buttonBar =
- ButtonBarFactory.buildRightAlignedBar(_applyButton,
- _discardButton);
- buttonBar.setBorder(Borders.DIALOG_BORDER);
- _propertiesPanel.add(buttonBar, BorderLayout.SOUTH);
- }
-
- //
- // Used by the sub-editor (when there is one)
- //
- Object getSubDescriptor()
- {
- return null;
- }
-
- Utils.Resolver getDetailResolver()
- {
- return null;
- }
-
- protected Editor(boolean hasCurrentStatus, boolean hasProperties)
- {
- _hasCurrentStatus = hasCurrentStatus;
- _hasProperties = hasProperties;
-
- if(_hasProperties)
- {
- //
- // _applyButton
- //
- AbstractAction apply = new AbstractAction("Apply")
- {
- public void actionPerformed(ActionEvent e)
- {
- applyUpdate();
- }
- };
- _applyButton = new JButton(apply);
-
- //
- // _discardButton
- //
- AbstractAction discard = new AbstractAction("Discard")
- {
- public void actionPerformed(ActionEvent e)
- {
- discardUpdate();
- }
- };
- _discardButton = new JButton(discard);
-
- _updateListener = new DocumentListener()
- {
- public void changedUpdate(DocumentEvent e)
- {
- updated();
- }
-
- public void insertUpdate(DocumentEvent e)
- {
- updated();
- }
-
- public void removeUpdate(DocumentEvent e)
- {
- updated();
- }
- };
- }
- }
-
- protected void setTarget(CommonBase target)
- {
- _target = target;
- }
-
- CommonBase getTarget()
- {
- return _target;
- }
-
- void updated()
- {
- if(_detectUpdates)
- {
- _applyButton.setEnabled(true);
- _discardButton.setEnabled(true);
- }
- }
-
- DocumentListener getUpdateListener()
- {
- return _updateListener;
- }
-
- protected void detectUpdates(boolean val)
- {
- _detectUpdates = val;
- }
-
- protected void discardUpdate()
- {
- if(_target.isEphemeral())
- {
- _target.delete();
- }
- else
- {
- _target.getModel().refreshDisplay();
- }
- }
-
- static java.util.Map propertiesToMap(java.util.List props)
- {
- java.util.Map result = new java.util.HashMap(props.size());
- java.util.Iterator p = props.iterator();
- while(p.hasNext())
- {
- PropertyDescriptor pd = (PropertyDescriptor)p.next();
- result.put(pd.name, pd.value);
- }
- return result;
- }
-
- static java.util.LinkedList mapToProperties(java.util.Map map)
- {
- java.util.LinkedList result = new java.util.LinkedList();
- java.util.Iterator p = map.entrySet().iterator();
- while(p.hasNext())
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- String name = (String)entry.getKey();
- String value = (String)entry.getValue();
- result.add(new PropertyDescriptor(name, value));
- }
- return result;
- }
-
- static java.util.Map makeParameterValues(
- java.util.Map oldParameterValues,
- java.util.List newParameters)
- {
- java.util.Map result = new java.util.HashMap();
-
- java.util.Iterator p = newParameters.iterator();
- while(p.hasNext())
- {
- Object name = p.next();
- Object value = oldParameterValues.get(name);
- if(value != null)
- {
- result.put(name, value);
- }
- }
- return result;
- }
-
- private final boolean _hasCurrentStatus;
- private final boolean _hasProperties;
-
- protected JButton _applyButton;
- protected JButton _discardButton;
- protected DocumentListener _updateListener;
-
- protected CommonBase _target;
- private boolean _detectUpdates = true;
-
- protected JPanel _currentStatusPanel;
- protected JPanel _propertiesPanel;
-
-}
diff --git a/java/src/IceGrid/TreeNode/Leaf.java b/java/src/IceGrid/TreeNode/Leaf.java
deleted file mode 100755
index 0562fb323d9..00000000000
--- a/java/src/IceGrid/TreeNode/Leaf.java
+++ /dev/null
@@ -1,69 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.tree.TreePath;
-import IceGrid.Model;
-
-//
-// Common implementation for leaf nodes.
-//
-
-class Leaf extends CommonBaseI
-{
- public Object getChildAt(int childIndex)
- {
- return null;
- }
-
- public int getChildCount()
- {
- return 0;
- }
-
- public int getIndex(Object child)
- {
- return -1;
- }
-
- public boolean isLeaf()
- {
- return true;
- }
-
- public CommonBase findChild(String id)
- {
- return null;
- }
-
- public CommonBase findChildWithDescriptor(Object d)
- {
- return null;
- }
-
- public void setParent(CommonBase parent)
- {
- assert parent != null;
- _parent = (Parent)parent;
- TreePath parentPath = _parent.getPath();
- _path = parentPath.pathByAddingChild(this);
- }
-
- public void clearParent()
- {
- _parent = null;
- _path = null;
- }
-
-
- protected Leaf(String id, Model model)
- {
- super(id, model, false);
- }
-}
diff --git a/java/src/IceGrid/TreeNode/ListElementEditor.java b/java/src/IceGrid/TreeNode/ListElementEditor.java
deleted file mode 100755
index b16fabc5dd7..00000000000
--- a/java/src/IceGrid/TreeNode/ListElementEditor.java
+++ /dev/null
@@ -1,135 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.JOptionPane;
-
-import IceGrid.Model;
-
-abstract class ListElementEditor extends Editor
-{
- abstract void writeDescriptor();
- abstract boolean isSimpleUpdate();
- void postUpdate() {}
-
- protected ListElementEditor(boolean hasCurrentStatus)
- {
- super(hasCurrentStatus, true);
- }
-
- //
- // Update when parent is a ListParent
- //
- protected void applyUpdate()
- {
- Model model = _target.getModel();
-
- if(model.canUpdate())
- {
- boolean refreshDisplay = false;
- model.disableDisplay();
-
- try
- {
- if(_target.isEphemeral())
- {
- ListParent parent = (ListParent)_target.getParent();
- writeDescriptor();
- Object descriptor = _target.getDescriptor();
- _target.destroy(); // just removes the child
-
- try
- {
- parent.tryAdd(descriptor);
- }
- catch(UpdateFailedException e)
- {
- //
- // Restore ephemeral
- //
- try
- {
- parent.addChild(_target, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
-
- model.setSelectionPath(_target.getPath());
- return;
- }
-
- //
- // Success
- //
- _target = parent.findChildWithDescriptor(descriptor);
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- refreshDisplay = true;
- }
- else if(isSimpleUpdate())
- {
- writeDescriptor();
- }
- else
- {
- //
- // Save to be able to rollback
- //
- Object savedDescriptor = _target.saveDescriptor();
- ListParent parent = (ListParent)_target.getParent();
- writeDescriptor();
-
- try
- {
- parent.tryUpdate(_target);
- }
- catch(UpdateFailedException e)
- {
- _target.restoreDescriptor(savedDescriptor);
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- _target = parent.findChildWithDescriptor(_target.getDescriptor());
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- }
-
- postUpdate();
-
- _target.getEditable().markModified();
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
- }
- finally
- {
- model.enableDisplay();
- }
- if(refreshDisplay)
- {
- model.refreshDisplay();
- }
- }
- }
-}
diff --git a/java/src/IceGrid/TreeNode/ListParent.java b/java/src/IceGrid/TreeNode/ListParent.java
deleted file mode 100755
index 13c4082648d..00000000000
--- a/java/src/IceGrid/TreeNode/ListParent.java
+++ /dev/null
@@ -1,174 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.Model;
-
-//
-// A parent that holds a list of children
-//
-abstract class ListParent extends Parent
-{
- protected ListParent(String id, Model model, boolean root)
- {
- super(id, model, root);
- }
-
- protected ListParent(String id, Model model)
- {
- this(id, model, false);
- }
-
- protected void addDescriptor(Object descriptor)
- {
- _descriptors.add(descriptor);
- }
-
- protected void removeDescriptor(Object descriptor)
- {
- //
- // A straight remove uses equals(), which is not the desired behavior
- //
- java.util.Iterator p = _descriptors.iterator();
- while(p.hasNext())
- {
- if(descriptor == p.next())
- {
- p.remove();
- break;
- }
- }
- }
-
- //
- // Try to add this new element
- //
- void tryAdd(Object descriptor)
- throws UpdateFailedException
- {
- _descriptors.add(descriptor);
-
- java.util.List newChildren = new java.util.LinkedList();
- java.util.List list = _parent.findAllInstances(this);
-
- java.util.Iterator p = list.iterator();
- while(p.hasNext())
- {
- ListParent container = (ListParent)p.next();
-
- try
- {
- newChildren.add(container.addNewChild(descriptor));
- }
- catch(UpdateFailedException e)
- {
- //
- // Rollback
- //
- java.util.Iterator q = newChildren.iterator();
- p = list.iterator();
- while(q.hasNext())
- {
- container = (ListParent)p.next();
- container.removeChild((CommonBase)q.next());
- }
- removeDescriptor(descriptor);
- throw e;
- }
- }
- }
-
- //
- // Try to update this child
- //
- void tryUpdate(CommonBase child)
- throws UpdateFailedException
- {
- java.util.List list = _parent.findAllInstances(this);
- Object descriptor = child.getDescriptor();
-
- java.util.List backupList = new java.util.Vector();
- java.util.List children = new java.util.Vector();
- java.util.List editables = new java.util.LinkedList();
-
- java.util.Iterator p = list.iterator();
- while(p.hasNext())
- {
- ListParent parent = (ListParent)p.next();
- try
- {
- child = parent.findChildWithDescriptor(descriptor);
- backupList.add(parent.rebuildChild(child, editables));
- children.add(child);
- }
- catch(UpdateFailedException e)
- {
- for(int i = backupList.size() - 1; i >= 0; --i)
- {
- parent = (ListParent)list.get(i);
- child = (CommonBase)children.get(i);
- parent.restoreChild(child, backupList.get(i));
- }
- throw e;
- }
- }
-
- //
- // Success
- //
- p = editables.iterator();
- while(p.hasNext())
- {
- Editable editable = (Editable)p.next();
- editable.markModified();
- }
- }
-
-
- boolean destroyChild(CommonBase child)
- {
- if(child.isEphemeral())
- {
- removeChild(child, true);
- return true;
- }
- else
- {
- if(_model.canUpdate())
- {
- Object descriptor = child.getDescriptor();
- removeDescriptor(descriptor);
- getEditable().markModified();
-
- //
- // List of Services, Adapters etc
- //
- java.util.List list = _parent.findAllInstances(this);
- java.util.Iterator p = list.iterator();
- while(p.hasNext())
- {
- ListParent parent = (ListParent)p.next();
- parent.removeChild(
- parent.findChildWithDescriptor(descriptor),
- true);
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
-
- protected java.util.List _descriptors;
-}
-
-
diff --git a/java/src/IceGrid/TreeNode/NodeEditor.java b/java/src/IceGrid/TreeNode/NodeEditor.java
deleted file mode 100755
index 071b34849d9..00000000000
--- a/java/src/IceGrid/TreeNode/NodeEditor.java
+++ /dev/null
@@ -1,401 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.KeyStroke;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-
-import IceGrid.Model;
-import IceGrid.NodeDescriptor;
-import IceGrid.NodeInfo;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
-
-class NodeEditor extends Editor
-{
- protected void applyUpdate()
- {
- Node node = (Node)_target;
- Model model = node.getModel();
-
- if(model.canUpdate())
- {
- model.disableDisplay();
-
- try
- {
- if(node.isEphemeral())
- {
- Nodes nodes = (Nodes)node.getParent();
- writeDescriptor();
- NodeDescriptor descriptor = (NodeDescriptor)node.getDescriptor();
- node.destroy(); // just removes the child
- try
- {
- nodes.tryAdd(_name.getText(), descriptor);
- }
- catch(UpdateFailedException e)
- {
- //
- // Add back ephemeral child
- //
- try
- {
- node.addChild(node, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- model.setSelectionPath(node.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- _target = nodes.findChildWithDescriptor(descriptor);
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- }
- else if(isSimpleUpdate())
- {
- writeDescriptor();
- node.markModified();
- }
- else
- {
- //
- // Save to be able to rollback
- //
- Object savedDescriptor = node.saveDescriptor();
- writeDescriptor();
- try
- {
- if(node.inRegistry())
- {
- //
- // Rebuild node; don't need the backup
- // since it's just one node
- //
- java.util.List editables =
- new java.util.LinkedList();
-
- node.rebuild(editables);
- java.util.Iterator p = editables.iterator();
- while(p.hasNext())
- {
- Editable editable = (Editable)p.next();
- editable.markModified();
- }
- node.markModified();
- }
- else
- {
- node.moveToRegistry();
- }
- }
- catch(UpdateFailedException e)
- {
- node.restoreDescriptor(savedDescriptor);
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- //
- // Success
- //
- model.showActions(_target);
- }
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
- }
- finally
- {
- model.enableDisplay();
- }
- }
- }
-
- Utils.Resolver getDetailResolver()
- {
- Node node = (Node)_target;
- if(node.getModel().substitute())
- {
- return node.getResolver();
- }
- else
- {
- return null;
- }
- }
-
- NodeEditor(JFrame parentFrame)
- {
- super(true, true);
-
- _name.getDocument().addDocumentListener(_updateListener);
- _name.setToolTipText("Must match the IceGrid.Node.Name property of the desired icegridnode process");
- _description.getDocument().addDocumentListener(_updateListener);
- _description.setToolTipText("An optional description for this node");
- _variables.setEditable(false);
-
- _hostname.setEditable(false);
- _os.setEditable(false);
- _machineType.setEditable(false);
- _loadAverage.setEditable(false);
-
- Action refresh = new AbstractAction("Refresh")
- {
- public void actionPerformed(ActionEvent e)
- {
- Node node = (Node)_target;
- node.getLoad();
- }
- };
- refresh.putValue(Action.SHORT_DESCRIPTION,
- "Fetch the latest values from this IceGrid Node");
- _refreshButton = new JButton(refresh);
-
-
- //
- // Variables
- //
- _variablesDialog = new TableDialog(parentFrame,
- "Variables", "Name", "Value", true);
-
- Action openVariablesDialog = new AbstractAction("...")
- {
- public void actionPerformed(ActionEvent e)
- {
- java.util.TreeMap result = _variablesDialog.show(_variablesMap,
- getProperties());
- if(result != null)
- {
- updated();
- _variablesMap = result;
- setVariablesField();
- }
- }
- };
- openVariablesDialog.putValue(Action.SHORT_DESCRIPTION,
- "Edit variables");
- _variablesButton = new JButton(openVariablesDialog);
-
- _loadFactor.getDocument().addDocumentListener(_updateListener);
- _loadFactor.setToolTipText("<html>A floating point value.<br>"
- + "When not specified, IceGrid uses 1.0 on all platforms<br>"
- + "except Windows where it uses 1.0 divided by <i>number of processors</i>.<html>");
- }
-
- public JComponent getCurrentStatus(Ice.StringHolder title)
- {
- title.value = "System information";
- return super.getCurrentStatus(title);
- }
-
- public void refreshCurrentStatus()
- {
- Node node = (Node)_target;
- NodeInfo info = node.getStaticInfo();
-
- if(info == null)
- {
- _hostname.setText("Unknown");
- _os.setText("Unknown");
- _machineType.setText("Unknown");
- _loadAverageLabel.setText("Load Average");
- _loadAverage.setText("Unknown");
- }
- else
- {
- _hostname.setText(info.hostname);
- _os.setText(info.os + " " + info.release + " " + info.version);
- _machineType.setText(info.machine + " with " +
- info.nProcessors
- + " CPU"
- + (info.nProcessors >= 2 ? "s" : ""));
-
- if(node.isRunningWindows())
- {
- _loadAverageLabel.setText("CPU Usage");
- _loadAverage.setToolTipText(
- "CPU usage in the past 1 min, 5 min and 15 min period");
- }
- else
- {
- _loadAverageLabel.setText("Load Average");
- _loadAverage.setToolTipText(
- "Load average in the past 1 min, 5 min and 15 min period");
- }
- _loadAverage.setText("Refreshing...");
- node.getLoad();
- }
- }
-
- void setLoad(String load, Node node)
- {
- if(node == _target)
- {
- _loadAverage.setText(load);
- }
- //
- // Otherwise, we've already moved to another node
- //
- }
-
-
- void appendCurrentStatus(DefaultFormBuilder builder)
- {
- builder.append("Hostname");
- builder.append(_hostname, 3);
- builder.nextLine();
- builder.append("Operating System");
- builder.append(_os, 3);
- builder.nextLine();
- builder.append("Machine Type");
- builder.append(_machineType, 3);
- builder.append(_loadAverageLabel, _loadAverage);
- builder.append(_refreshButton);
- builder.nextLine();
- }
-
- void appendProperties(DefaultFormBuilder builder)
- {
- builder.append("Name");
- builder.append(_name, 3);
- builder.nextLine();
-
- builder.append("Description");
- builder.nextLine();
- builder.append("");
- builder.nextRow(-2);
- CellConstraints cc = new CellConstraints();
- JScrollPane scrollPane = new JScrollPane(_description);
- builder.add(scrollPane,
- cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
- builder.nextRow(2);
- builder.nextLine();
-
- builder.append("Variables", _variables);
- builder.append(_variablesButton);
- builder.nextLine();
- builder.append("Load Factor");
- builder.append(_loadFactor, 3);
- builder.nextLine();
- }
-
- boolean isSimpleUpdate()
- {
- NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
- return (_variablesMap.equals(descriptor.variables));
- }
-
- void writeDescriptor()
- {
- NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
- descriptor.description = _description.getText();
- descriptor.variables = _variablesMap;
- descriptor.loadFactor = _loadFactor.getText();
- }
-
- void show(Node node)
- {
- detectUpdates(false);
- setTarget(node);
-
- Utils.Resolver resolver = getDetailResolver();
- boolean isEditable = (resolver == null);
-
- _name.setText(_target.getId());
- _name.setEditable(_target.isEphemeral());
-
- NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
-
- _description.setText(
- Utils.substitute(descriptor.description, resolver));
- _description.setEditable(isEditable);
- _description.setOpaque(isEditable);
-
- _variablesMap = descriptor.variables;
- setVariablesField();
- _variablesButton.setEnabled(isEditable);
-
- _loadFactor.setText(
- Utils.substitute(descriptor.loadFactor, resolver));
- _loadFactor.setEditable(isEditable);
-
- _applyButton.setEnabled(node.isEphemeral());
- _discardButton.setEnabled(node.isEphemeral());
- detectUpdates(true);
-
- refreshCurrentStatus();
- }
-
- private void setVariablesField()
- {
- Utils.Stringifier stringifier = new Utils.Stringifier()
- {
- final Utils.Resolver resolver = getDetailResolver();
-
- public String toString(Object obj)
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)obj;
-
- return (String)entry.getKey() + "="
- + Utils.substitute((String)entry.getValue(), resolver);
- }
- };
-
- Ice.StringHolder toolTipHolder = new Ice.StringHolder();
- _variables.setText(
- Utils.stringify(_variablesMap.entrySet(), stringifier,
- ", ", toolTipHolder));
- _variables.setToolTipText(toolTipHolder.value);
- }
-
- private JTextField _name = new JTextField(20);
- private JTextArea _description = new JTextArea(3, 20);
- private JTextField _variables = new JTextField(20);
- private JButton _variablesButton;
- private TableDialog _variablesDialog;
- private java.util.TreeMap _variablesMap;
- private JTextField _loadFactor = new JTextField(20);
-
- private JTextField _hostname = new JTextField(20);
- private JTextField _os = new JTextField(20);
- private JTextField _machineType = new JTextField(20);
- private JLabel _loadAverageLabel = new JLabel();
- private JTextField _loadAverage = new JTextField(20);
- private JButton _refreshButton;
-}
diff --git a/java/src/IceGrid/TreeNode/Parent.java b/java/src/IceGrid/TreeNode/Parent.java
deleted file mode 100755
index c6a0eb1ebaa..00000000000
--- a/java/src/IceGrid/TreeNode/Parent.java
+++ /dev/null
@@ -1,723 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.JTree;
-
-import javax.swing.tree.DefaultTreeCellRenderer;
-import javax.swing.tree.TreeCellRenderer;
-import javax.swing.tree.TreePath;
-
-import javax.swing.event.TreeModelEvent;
-import IceGrid.Model;
-import IceGrid.TreeModelI;
-import IceGrid.Utils;
-
-//
-// Common implementation for non-leaf nodes
-//
-
-class Parent extends CommonBaseI
-{
-
- //
- // Adapts parent to a ComboBoxModel
- //
- class ComboBoxModel extends javax.swing.AbstractListModel
- implements javax.swing.ComboBoxModel
- {
- public Object getElementAt(int index)
- {
- if(_firstItem != null)
- {
- if(index == 0)
- {
- return _firstItem;
- }
- else
- {
- return getChildAt(index - 1);
- }
- }
- else
- {
- return getChildAt(index);
- }
- }
-
- public int getSize()
- {
- if(_firstItem != null)
- {
- return getChildCount() + 1;
- }
- else
- {
- return getChildCount();
- }
- }
-
- public Object getSelectedItem()
- {
- return _selectedItem;
- }
-
- public void setSelectedItem(Object obj)
- {
- if(obj != _selectedItem)
- {
- _selectedItem = obj;
- fireContentsChanged(this, -1, -1);
- }
- }
-
- ComboBoxModel(Object firstItem)
- {
- _firstItem = firstItem;
- }
-
- ComboBoxModel()
- {
- _firstItem = null;
- }
-
- private final Object _firstItem;
- private Object _selectedItem;
- }
-
- static class ChildComparator implements java.util.Comparator
- {
- public int compare(Object o1, Object o2)
- {
- CommonBase child1 = (CommonBase)o1;
- CommonBase child2 = (CommonBase)o1;
- return child1.getId().compareTo(child2.getId());
- }
- }
-
- //
- // TreeCellRenderer
- //
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- //
- // Initialization
- //
- _cellRenderer = new DefaultTreeCellRenderer();
- _cellRenderer.setOpenIcon(
- Utils.getIcon("/icons/16x16/folder_open.png"));
- _cellRenderer.setClosedIcon(
- Utils.getIcon("/icons/16x16/folder_closed.png"));
- }
-
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
- public Object getChildAt(int childIndex)
- {
- try
- {
- return _children.get(childIndex);
- }
- catch(IndexOutOfBoundsException e)
- {
- return null;
- }
- }
-
- public int getChildCount()
- {
- return _children.size();
- }
-
- public int getIndex(Object child)
- {
- return _children.indexOf(child);
- }
-
- public boolean isLeaf()
- {
- return false;
- }
-
-
- public CommonBase findChild(String id)
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase child = (CommonBase)p.next();
- if(id.equals(child.getId()))
- {
- return child;
- }
- }
- return null;
- }
-
- public CommonBase findChildWithDescriptor(Object descriptor)
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase child = (CommonBase)p.next();
- if(descriptor == child.getDescriptor())
- {
- return child;
- }
- }
- return null;
- }
-
- public void setParent(CommonBase parent)
- {
- _parent = (Parent)parent;
-
- TreePath parentPath = _parent.getPath();
- _path = parentPath.pathByAddingChild(this);
-
- //
- // Propagate to children
- //
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBaseI child = (CommonBaseI)p.next();
- child.setParent(this);
- }
- }
-
- public void clearParent()
- {
- if(_parent != null)
- {
- _parent = null;
- _path = null;
-
- //
- // Propagate to children
- //
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBaseI child = (CommonBaseI)p.next();
- child.clearParent();
- }
- }
- }
-
-
- void addChild(CommonBase child) throws UpdateFailedException
- {
- addChild(child, false);
- }
-
- void addChild(CommonBase child, boolean fireEvent)
- throws UpdateFailedException
- {
- if(_sortChildren)
- {
- //
- // Sorted insert
- //
- String id = child.getId();
- int i = 0;
- java.util.Iterator p = _children.iterator();
-
- while(p.hasNext())
- {
- CommonBase existingChild = (CommonBase)p.next();
- int cmp = id.compareTo(existingChild.getId());
-
- if(cmp == 0)
- {
- throw new UpdateFailedException(this, id);
- }
- if(cmp < 0)
- {
- break; // while
- }
- i++;
- }
-
- if(i < _children.size())
- {
- _children.add(i, child);
- }
- else
- {
- _children.add(child);
- }
- if(_path != null)
- {
- child.setParent(this);
- }
-
- if(fireEvent)
- {
- fireNodeInsertedEvent(this, child, i);
- }
- }
- else
- {
- //
- // Unsorted insert (i.e. at the end)
- //
- String id = child.getId();
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase existingChild = (CommonBase)p.next();
- if(id.equals(existingChild.getId()))
- {
- throw new UpdateFailedException(this, id);
- }
- }
-
- _children.add(child);
- if(_path != null)
- {
- child.setParent(this);
- }
-
- if(fireEvent)
- {
- fireNodeInsertedEvent(this, child, _children.size() - 1);
- }
- }
- }
-
- void addChild(int index, CommonBase child, boolean fireEvent)
- throws UpdateFailedException
- {
- assert !_sortChildren;
-
- String id = child.getId();
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase existingChild = (CommonBase)p.next();
- if(id.equals(existingChild.getId()))
- {
- throw new UpdateFailedException(this, id);
- }
- }
-
- _children.add(index, child);
-
- if(_path != null)
- {
- child.setParent(this);
- }
-
- if(fireEvent)
- {
- fireNodeInsertedEvent(this, child, index);
- }
- }
-
- void moveChild(int index, boolean up, boolean fireEvent)
- {
- assert !_sortChildren;
-
- Object child = _children.remove(index);
- assert child != null;
-
- if(fireEvent)
- {
- fireNodeRemovedEvent(this, child, index);
- }
-
- if(up)
- {
- _children.add(index - 1, child);
- if(fireEvent)
- {
- fireNodeInsertedEvent(this, child, index - 1);
- }
- }
- else
- {
- _children.add(index + 1, child);
- if(fireEvent)
- {
- fireNodeInsertedEvent(this, child, index + 1);
- }
- }
- }
-
-
- void removeChild(CommonBase child)
- {
- if(_children.remove(child))
- {
- child.clearParent();
- }
- }
-
- void removeChild(CommonBase child, boolean fireEvent)
- {
- int index = _children.indexOf(child);
- if(index > -1)
- {
- _children.remove(child);
- child.clearParent();
- if(fireEvent)
- {
- fireNodeRemovedEvent(this, child, index);
- }
- }
- }
-
- void removeChild(String id, boolean fireEvent)
- {
- int i = -1;
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase child = (CommonBase)p.next();
- i++;
- if(id.equals(child.getId()))
- {
- p.remove();
- child.clearParent();
- if(fireEvent)
- {
- fireNodeRemovedEvent(this, child, i);
- }
- break;
- }
- }
- }
-
- void clearChildren()
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase child = (CommonBase)p.next();
- child.clearParent();
- }
- _children.clear();
- }
-
- void expandChildren()
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- CommonBase child = (CommonBase)p.next();
- _model.getTree().expandPath(child.getPath());
- }
- }
-
- //
- // The following methods fire events
- //
-
- void updateChildren(CommonBaseI[] children)
- {
- for(int i = 0; i < children.length; ++i)
- {
- children[i].fireStructureChangedEvent(this);
- }
- }
-
- void addChildren(CommonBaseI[] newChildren)
- throws UpdateFailedException
- {
- if(newChildren.length == 0)
- {
- //
- // Nothing to do;
- //
- return;
- }
-
- if(_sortChildren)
- {
- //
- // Shallow copy
- //
- CommonBaseI[] children = (CommonBaseI[])newChildren.clone();
-
- java.util.Arrays.sort(children, _childComparator);
-
- int[] indices = new int[children.length];
-
- int i = 0;
- boolean checkInsert = true;
- for(int j = 0; j < children.length; ++j)
- {
- String id = children[j].getId();
-
- if(checkInsert)
- {
- while(i < _children.size())
- {
- CommonBase existingChild = (CommonBase)_children.get(i);
- int cmp = id.compareTo(existingChild.getId());
- if(cmp == 0)
- {
- throw new UpdateFailedException(this, id);
- }
- if(cmp < 0)
- {
- break; // while
- }
- i++;
- }
-
- if(i < _children.size())
- {
- // Insert here, and increment i (since children is sorted)
- _children.add(i, children[j]);
- indices[j] = i;
- i++;
- if(_path != null)
- {
- children[j].setParent(this);
- }
- continue; // for
- }
- }
-
- //
- // Append
- //
- checkInsert = false;
- _children.add(children[j]);
- indices[j] = i;
- i++;
-
- if(_path != null)
- {
- children[j].setParent(this);
- }
- }
- fireNodesInsertedEvent(this, children, indices);
- }
- else
- {
- //
- // Could optimize later!
- //
- for(int i = 0; i < newChildren.length; ++i)
- {
- addChild(newChildren[i], true);
- }
- }
- }
-
-
- void removeChildren(String[] childIds)
- {
- if(childIds.length == 0)
- {
- //
- // Nothing to do;
- //
- return;
- }
-
- if(_sortChildren)
- {
- //
- // Shallow copy
- //
- String[] ids = (String[])childIds.clone();
-
- java.util.Arrays.sort(ids);
-
- Object[] childrenToRemove = new Object[ids.length];
- int[] indices = new int[ids.length];
-
- int i = 0;
- int j = 0;
- int k = 0;
- java.util.Iterator p = _children.iterator();
-
- while(p.hasNext() && j < ids.length)
- {
- CommonBase child = (CommonBase)p.next();
- if(ids[j].equals(child.getId()))
- {
- child.clearParent();
- childrenToRemove[k] = child;
- indices[k] = i;
- p.remove();
- ++j;
- ++k;
- }
- ++i;
- }
-
- //
- // Should be all removed
- //
- assert(k == ids.length);
- fireNodesRemovedEvent(this, childrenToRemove, indices);
- }
- else
- {
- //
- // Could optimize later!
- //
- for(int i = 0; i < childIds.length; ++i)
- {
- removeChild(childIds[i], true);
- }
- }
- }
-
- java.util.List findChildrenWithType(Class type)
- {
- java.util.List result = new java.util.LinkedList();
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Object child = p.next();
- if(child.getClass() == type)
- {
- result.add(child);
- }
- }
- return result;
- }
-
- void fireNodeInsertedEvent(Object source, Object child, int index)
- {
- int[] childIndices = new int[1];
- childIndices[0] = index;
- Object[] children = new Object[1];
- children[0] = child;
-
- fireNodesInsertedEvent(source, children, childIndices);
- }
-
- void fireNodesInsertedEvent(Object source, Object[] children, int[] childIndices)
- {
- assert _path != null;
- TreeModelEvent event = new TreeModelEvent(source, _path, childIndices, children);
- _model.getTreeModel().fireNodesInsertedEvent(event);
- }
-
- void fireNodeRemovedEvent(Object source, Object child, int index)
- {
- int[] childIndices = new int[1];
- childIndices[0] = index;
- Object[] children = new Object[1];
- children[0] = child;
-
- fireNodesRemovedEvent(source, children, childIndices);
- }
-
- void fireNodesRemovedEvent(Object source, Object[] children, int[] childIndices)
- {
- assert _path != null;
-
- TreeModelEvent event = new TreeModelEvent(source, _path,
- childIndices, children);
- _model.getTreeModel().fireNodesRemovedEvent(event);
- }
-
- javax.swing.ComboBoxModel createComboBoxModel()
- {
- return new ComboBoxModel();
- }
-
- javax.swing.ComboBoxModel createComboBoxModel(Object item)
- {
- return new ComboBoxModel(item);
- }
-
- Parent(String id, Model model, boolean root)
- {
- super(id, model, root);
- }
-
- Parent(String id, Model model)
- {
- this(id, model, false);
- }
-
-
- CommonBase addNewChild(Object descriptor)
- throws UpdateFailedException
- {
- assert false;
- return null;
- }
-
- Object rebuildChild(CommonBase child, java.util.List editables)
- throws UpdateFailedException
- {
- Object descriptor = child.getDescriptor();
- removeChild(child, true);
- try
- {
- addNewChild(descriptor);
- }
- catch(UpdateFailedException e)
- {
- addChild(child, true);
- throw e;
- }
- return null;
- }
-
- void restoreChild(CommonBase child, Object backup)
- {
- CommonBase badChild = findChildWithDescriptor(child.getDescriptor());
- removeChild(badChild, true);
-
- try
- {
- addChild(child, true);
- }
- catch(UpdateFailedException e)
- {
- assert false; // impossible
- }
- }
-
- protected void sortChildren(boolean val)
- {
- _sortChildren = val;
- }
-
- protected String makeNewChildId(String base)
- {
- String id = base;
- int i = 0;
- while(findChild(id) != null)
- {
- id = base + "-" + (++i);
- }
- return id;
- }
-
- protected java.util.LinkedList _children = new java.util.LinkedList();
- private ChildComparator _childComparator = new ChildComparator();
- protected boolean _sortChildren = true;
-
- static private DefaultTreeCellRenderer _cellRenderer;
-}
diff --git a/java/src/IceGrid/TreeNode/PropertiesHolder.java b/java/src/IceGrid/TreeNode/PropertiesHolder.java
deleted file mode 100755
index 0e8d1f0500e..00000000000
--- a/java/src/IceGrid/TreeNode/PropertiesHolder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.CommunicatorDescriptor;
-import IceGrid.Model;
-import IceGrid.PropertyDescriptor;
-
-class PropertiesHolder
-{
- PropertiesHolder(CommunicatorDescriptor descriptor)
- {
- assert descriptor != null;
-
- _descriptor = descriptor;
- }
-
- String get(String key)
- {
- java.util.Iterator p = _descriptor.properties.iterator();
- while(p.hasNext())
- {
- PropertyDescriptor pd = (PropertyDescriptor)p.next();
- if(pd.name.equals(key))
- {
- return pd.value;
- }
- }
- return null;
- }
-
- void set(String key, String newValue)
- {
- remove(key);
- _descriptor.properties.add(new PropertyDescriptor(key, newValue));
- }
-
- void remove(String key)
- {
- java.util.Iterator p = _descriptor.properties.iterator();
- while(p.hasNext())
- {
- PropertyDescriptor pd = (PropertyDescriptor)p.next();
- if(pd.name.equals(key))
- {
- p.remove();
- }
- }
- }
-
- private CommunicatorDescriptor _descriptor;
-}
diff --git a/java/src/IceGrid/TreeNode/ReplicaGroup.java b/java/src/IceGrid/TreeNode/ReplicaGroup.java
deleted file mode 100755
index 57bd5611fb6..00000000000
--- a/java/src/IceGrid/TreeNode/ReplicaGroup.java
+++ /dev/null
@@ -1,167 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.Model;
-import IceGrid.ReplicaGroupDescriptor;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.Utils;
-
-class ReplicaGroup extends EditableLeaf
-{
- static public ReplicaGroupDescriptor
- copyDescriptor(ReplicaGroupDescriptor d)
- {
- return (ReplicaGroupDescriptor)d.clone();
- }
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _cellRenderer.setLeafIcon(
- Utils.getIcon("/icons/16x16/replica_group.png"));
- }
-
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
-
- if(_parent.getAvailableActions()[PASTE])
- {
- actions[PASTE] = true;
- }
- actions[DELETE] = true;
-
- if(!_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
- return actions;
- }
-
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_descriptor));
- _model.getActions()[PASTE].setEnabled(true);
-
- }
- public void paste()
- {
- _parent.paste();
- }
-
- public boolean destroy()
- {
- if(_parent == null)
- {
- return false;
- }
- ReplicaGroups replicaGroups = (ReplicaGroups)_parent;
-
- if(_ephemeral)
- {
- replicaGroups.removeChild(this, true);
- return true;
- }
- else if(_model.canUpdate())
- {
- replicaGroups.removeDescriptor(_descriptor);
- replicaGroups.removeElement(this, true);
- return true;
- }
- return false;
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new ReplicaGroupEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
-
- public Object getDescriptor()
- {
- return _descriptor;
- }
-
- public Object saveDescriptor()
- {
- return _descriptor.clone();
- }
- public void restoreDescriptor(Object savedDescriptor)
- {
- ReplicaGroupDescriptor clone = (ReplicaGroupDescriptor)savedDescriptor;
- _descriptor.id = clone.id;
- _descriptor.description = clone.description;
- _descriptor.objects = clone.objects;
- _descriptor.loadBalancing = clone.loadBalancing;
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- ReplicaGroup(boolean brandNew,
- ReplicaGroupDescriptor descriptor,
- Model model)
- {
- super(brandNew, descriptor.id, model);
- _ephemeral = false;
- rebuild(descriptor);
- }
-
- ReplicaGroup(ReplicaGroupDescriptor descriptor,
- Model model)
- {
- super(false, descriptor.id, model);
- _ephemeral = true;
- rebuild(descriptor);
- }
-
- void rebuild(ReplicaGroupDescriptor descriptor)
- {
- _descriptor = descriptor;
- //
- // And that's it since there is no children
- //
- }
-
- private ReplicaGroupDescriptor _descriptor;
- private final boolean _ephemeral;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private ReplicaGroupEditor _editor;
-}
diff --git a/java/src/IceGrid/TreeNode/Root.java b/java/src/IceGrid/TreeNode/Root.java
deleted file mode 100755
index 36a883c865b..00000000000
--- a/java/src/IceGrid/TreeNode/Root.java
+++ /dev/null
@@ -1,475 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.tree.TreePath;
-
-import IceGrid.AdapterDynamicInfo;
-import IceGrid.ApplicationDescriptor;
-import IceGrid.ApplicationUpdateDescriptor;
-import IceGrid.Model;
-import IceGrid.NodeDynamicInfo;
-import IceGrid.NodeInfo;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.ServerState;
-import IceGrid.TreeModelI;
-
-
-public class Root extends Parent
-{
- static class DynamicInfo
- {
- NodeInfo staticInfo;
-
- //
- // ServerId to ServerDynamicInfo
- //
- java.util.Map serverInfoMap = new java.util.HashMap();
-
- //
- // AdapterId to Ice.ObjectPrx
- //
- java.util.Map adapterInfoMap = new java.util.HashMap();
- }
-
- public void paste()
- {
- ApplicationDescriptor ad =
- (ApplicationDescriptor)_model.getClipboard();
- newApplication(Application.copyDescriptor(ad));
- }
- public void newApplication()
- {
- newApplication(
- new ApplicationDescriptor("NewApplication",
- new java.util.TreeMap(),
- new java.util.LinkedList(),
- new java.util.HashMap(),
- new java.util.HashMap(),
- new java.util.HashMap(),
- new IceGrid.DistributionDescriptor(
- "", new java.util.LinkedList()),
- ""));
- }
-
- public void newApplication(ApplicationDescriptor descriptor)
- {
- descriptor.name = makeNewChildId(descriptor.name);
-
- Application application = new Application(descriptor, _model);
- try
- {
- addChild(application, true);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- _model.setSelectionPath(application.getPath());
- }
-
- public Root(Model model)
- {
- super("Applications", model, true);
- }
-
- public void init(java.util.List descriptors)
- {
- assert(_children.size() == 0);
-
- java.util.Iterator p = descriptors.iterator();
- while(p.hasNext())
- {
- ApplicationDescriptor descriptor = (ApplicationDescriptor)p.next();
- try
- {
- Application child = new Application(false, descriptor, _model);
- addChild(child);
- }
- catch(UpdateFailedException e)
- {
- //
- // Bug in the IceGrid registry
- //
- System.err.println("Failed to create application "
- + descriptor.name + ": "
- + e.toString());
- assert false;
- }
- }
- fireStructureChangedEvent(this);
- expandChildren();
- }
-
- public void clear()
- {
- clearChildren();
- _dynamicInfoMap.clear();
- _nodeAdapterMap.clear();
- _nodeServerMap.clear();
-
- fireStructureChangedEvent(this);
- }
-
- public void applicationAdded(ApplicationDescriptor desc)
- {
- try
- {
- Application child = new Application(false, desc, _model);
- addChild(child, true);
- }
- catch(UpdateFailedException e)
- {
- //
- // Bug in the IceGrid registry
- //
- System.err.println("Failed to create application "
- + desc.name + ": "
- + e.toString());
- assert false;
- }
- expandChildren();
- }
-
- public void applicationRemoved(String name)
- {
- Application application = (Application)findChild(name);
- removeChild(name, true);
- }
-
- public void applicationUpdated(ApplicationUpdateDescriptor desc)
- {
- try
- {
- Application application = (Application)findChild(desc.name);
- application.update(desc);
- }
- catch(UpdateFailedException e)
- {
- //
- // Bug in the IceGrid registry
- //
- System.err.println("Failed to update application "
- + desc.name + ": "
- + e.toString());
- assert false;
- }
- expandChildren();
- }
-
- public void nodeUp(NodeDynamicInfo updatedInfo)
- {
- String nodeName = updatedInfo.name;
-
- DynamicInfo info = new DynamicInfo();
- _dynamicInfoMap.put(nodeName, info);
-
- info.staticInfo = updatedInfo.info;
-
- for(int i = 0; i < updatedInfo.servers.length; ++i)
- {
- info.serverInfoMap.put(updatedInfo.servers[i].id, updatedInfo.servers[i]);
- }
-
- for(int i = 0; i < updatedInfo.adapters.length; ++i)
- {
- assert(updatedInfo.adapters[i].proxy != null);
- info.adapterInfoMap.put(updatedInfo.adapters[i].id, updatedInfo.adapters[i].proxy);
- }
-
- //
- // Need to tell *every* server on this node
- //
- java.util.List serverList = (java.util.List)_nodeServerMap.get(nodeName);
- if(serverList != null)
- {
- java.util.Iterator p = serverList.iterator();
- while(p.hasNext())
- {
- Server server = (Server)p.next();
- ServerDynamicInfo serverInfo = (ServerDynamicInfo)
- info.serverInfoMap.get(server.getId());
- if(serverInfo == null)
- {
- server.updateDynamicInfo(ServerState.Inactive, 0, true);
- }
- else
- {
- server.updateDynamicInfo(serverInfo.state,
- serverInfo.pid, serverInfo.enabled);
- }
- }
- }
-
- //
- // Tell adapters
- //
- java.util.List adapterList = (java.util.List)_nodeAdapterMap.get(nodeName);
- if(adapterList != null)
- {
- java.util.Iterator p = adapterList.iterator();
- while(p.hasNext())
- {
- Adapter adapter = (Adapter)p.next();
- Ice.ObjectPrx proxy =
- (Ice.ObjectPrx)info.adapterInfoMap.get(adapter.getAdapterId());
- if(proxy != null)
- {
- adapter.updateProxy(proxy);
- }
- }
- }
-
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Application application = (Application)p.next();
- application.nodeUp(nodeName, info.staticInfo);
- }
- }
-
- public void nodeDown(String nodeName)
- {
- _dynamicInfoMap.remove(nodeName);
-
- java.util.List serverList = (java.util.List)_nodeServerMap.get(nodeName);
- if(serverList != null)
- {
- java.util.Iterator p = serverList.iterator();
- while(p.hasNext())
- {
- Server server = (Server)p.next();
- server.updateDynamicInfo(null, 0, true);
- }
- }
-
- java.util.List adapterList = (java.util.List)_nodeAdapterMap.get(nodeName);
- if(adapterList != null)
- {
- java.util.Iterator p = adapterList.iterator();
- while(p.hasNext())
- {
- Adapter adapter = (Adapter)p.next();
- adapter.updateProxy(null);
- }
- }
-
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Application application = (Application)p.next();
- application.nodeDown(nodeName);
- }
- }
-
- java.util.Set getNodesUp()
- {
- return _dynamicInfoMap.keySet();
- }
-
- NodeInfo getStaticNodeInfo(String nodeName)
- {
- DynamicInfo info = (DynamicInfo)_dynamicInfoMap.get(nodeName);
- if(info == null)
- {
- return null;
- }
- else
- {
- return info.staticInfo;
- }
- }
-
- ServerState registerServer(String nodeName, Server server,
- Ice.IntHolder pid, Ice.BooleanHolder enabled)
- {
- java.util.List serverList = (java.util.List)_nodeServerMap.get(nodeName);
- if(serverList == null)
- {
- serverList = new java.util.LinkedList();
- _nodeServerMap.put(nodeName, serverList);
- }
- serverList.add(server);
-
- DynamicInfo info = (DynamicInfo)_dynamicInfoMap.get(nodeName);
- if(info == null)
- {
- // Node is down
- pid.value = 0;
- enabled.value = true;
- return null;
- }
- else
- {
- ServerDynamicInfo serverInfo =
- (ServerDynamicInfo)info.serverInfoMap.get(server.getId());
- if(serverInfo == null)
- {
- pid.value = 0;
- enabled.value = true;
- return ServerState.Inactive;
- }
- else
- {
- pid.value = serverInfo.pid;
- enabled.value = serverInfo.enabled;
- return serverInfo.state;
- }
- }
- }
-
- void unregisterServer(String nodeName, Server server)
- {
- java.util.List serverList = (java.util.List)_nodeServerMap.get(nodeName);
- serverList.remove(server);
- }
-
- public void updateServer(String nodeName, ServerDynamicInfo updatedInfo)
- {
- //
- // This node must be up
- //
- DynamicInfo info = (DynamicInfo)_dynamicInfoMap.get(nodeName);
- assert info != null;
-
- if((updatedInfo.state == ServerState.Destroyed ||
- updatedInfo.state == ServerState.Inactive) && updatedInfo.enabled)
- {
- info.serverInfoMap.remove(updatedInfo.id);
- }
- else
- {
- info.serverInfoMap.put(updatedInfo.id, updatedInfo);
- }
-
- java.util.List serverList = (java.util.List)_nodeServerMap.get(nodeName);
-
- if(serverList != null)
- {
- java.util.Iterator p = serverList.iterator();
- while(p.hasNext())
- {
- Server server = (Server)p.next();
- if(server.getId().equals(updatedInfo.id))
- {
- server.updateDynamicInfo(updatedInfo.state,
- updatedInfo.pid, updatedInfo.enabled);
- }
- }
- }
- }
-
- Ice.ObjectPrx registerAdapter(String nodeName, Adapter adapter)
- {
- java.util.List adapterList = (java.util.List)_nodeAdapterMap.get(nodeName);
- if(adapterList == null)
- {
- adapterList = new java.util.LinkedList();
- _nodeAdapterMap.put(nodeName, adapterList);
- }
- adapterList.add(adapter);
-
- DynamicInfo info = (DynamicInfo)_dynamicInfoMap.get(nodeName);
- if(info == null)
- {
- // Node is down
- return null;
- }
- else
- {
- return (Ice.ObjectPrx)info.adapterInfoMap.get(adapter.getAdapterId());
- }
- }
-
- void unregisterAdapter(String nodeName, Adapter adapter)
- {
- java.util.List adapterList = (java.util.List)_nodeAdapterMap.get(nodeName);
- adapterList.remove(adapter);
- }
-
- public void updateAdapter(String nodeName,
- AdapterDynamicInfo updatedInfo)
- {
- //
- // This node must be up
- //
- DynamicInfo info = (DynamicInfo)_dynamicInfoMap.get(nodeName);
- assert info != null;
- info.adapterInfoMap.put(updatedInfo.id, updatedInfo.proxy);
-
- java.util.List adapterList =
- (java.util.List)_nodeAdapterMap.get(nodeName);
-
- if(adapterList != null)
- {
- java.util.Iterator p = adapterList.iterator();
- while(p.hasNext())
- {
- Adapter adapter = (Adapter)p.next();
- if(adapter.getAdapterId().equals(updatedInfo.id))
- {
- adapter.updateProxy(updatedInfo.proxy);
- }
- }
- }
- }
-
- void tryAdd(ApplicationDescriptor ad) throws UpdateFailedException
- {
- try
- {
- Application app = new Application(true, ad, _model);
- addChild(app, true);
- expandChildren();
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
-
-
- String identify(TreePath path)
- {
- String result = "";
- for(int i = 1; i < path.getPathCount(); ++i)
- {
- if(!result.equals(""))
- {
- result += "/";
- }
- result += ((CommonBase)path.getPathComponent(i)).getId();
- }
- return result;
- }
-
- //
- // Nodename to DynamicInfo
- //
- private java.util.Map _dynamicInfoMap = new java.util.HashMap();
-
- //
- // Nodename to list of Adapters
- // Note that we can have several adapters with the same id
- // even on the same node
- // (a temporary inconsistency to support copy/paste)
- //
- private java.util.Map _nodeAdapterMap = new java.util.HashMap();
-
- //
- // Nodename to list of Servers
- // Note that we can have several servers with the same id
- // even on the same node (but in different applications)
- // (a temporary inconsistency to support copy/paste)
- //
- private java.util.Map _nodeServerMap = new java.util.HashMap();
-
-}
diff --git a/java/src/IceGrid/TreeNode/Server.java b/java/src/IceGrid/TreeNode/Server.java
deleted file mode 100755
index 3041b66367b..00000000000
--- a/java/src/IceGrid/TreeNode/Server.java
+++ /dev/null
@@ -1,977 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import java.awt.Cursor;
-
-import javax.swing.Icon;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPopupMenu;
-import javax.swing.JTree;
-import javax.swing.SwingUtilities;
-
-import javax.swing.tree.TreeCellRenderer;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.AMI_Admin_startServer;
-import IceGrid.AMI_Admin_stopServer;
-import IceGrid.AMI_Admin_enableServer;
-import IceGrid.AMI_Admin_patchServer;
-
-import IceGrid.AdapterDescriptor;
-import IceGrid.DistributionDescriptor;
-import IceGrid.IceBoxDescriptor;
-import IceGrid.Model;
-import IceGrid.PropertyDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.TreeModelI;
-import IceGrid.ServerDescriptor;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.ServerInstanceDescriptor;
-import IceGrid.ServerState;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.Utils;
-
-//
-// We can have 4 kinds of servers:
-// - Plain server (no template)
-// - Icebox server (no template)
-// - Server instance
-// - Icebox instance
-//
-class Server extends EditableParent
-{
- static public ServerDescriptor
- copyDescriptor(ServerDescriptor sd)
- {
- ServerDescriptor copy = (ServerDescriptor)sd.clone();
- copy.adapters = Adapters.copyDescriptors(copy.adapters);
- copy.dbEnvs = DbEnvs.copyDescriptors(copy.dbEnvs);
-
- //
- // Update to properties is not atomic because of Adapter endpoints
- // (and possibly other properties set through a PropertiesHolder)
- //
- copy.properties = (java.util.LinkedList)copy.properties.clone();
- copy.distrib = (DistributionDescriptor)copy.distrib.clone();
-
- if(copy instanceof IceBoxDescriptor)
- {
- IceBoxDescriptor ib = (IceBoxDescriptor)copy;
- ib.services = Services.copyDescriptors(ib.services);
- }
- return copy;
- }
-
- static public ServerInstanceDescriptor
- copyDescriptor(ServerInstanceDescriptor sid)
- {
- return (ServerInstanceDescriptor)sid.clone();
- }
-
- static public void shallowRestore(ServerDescriptor from, ServerDescriptor into)
- {
- //
- // When editing a server or server template, if we update properties,
- // we replace the entire field
- into.properties = from.properties;
-
- into.description = from.description;
- into.id = from.id;
- into.exe = from.exe;
- into.options = from.options;
- into.envs = from.envs;
- into.activation = from.activation;
- into.activationTimeout = from.activationTimeout;
- into.deactivationTimeout = from.deactivationTimeout;
- into.applicationDistrib = from.applicationDistrib;
- into.distrib.icepatch = from.distrib.icepatch;
- into.distrib.directories = from.distrib.directories;
- }
-
- static public ServerDescriptor newServerDescriptor()
- {
- return new ServerDescriptor(
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- "",
- "NewServer",
- "",
- "",
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- "manual",
- "",
- "",
- true,
- new IceGrid.DistributionDescriptor("", new java.util.LinkedList()));
- }
-
- static public IceBoxDescriptor newIceBoxDescriptor()
- {
- AdapterDescriptor serviceManager = new AdapterDescriptor(
- "IceBox.ServiceManager",
- "",
- "", // direct-adapter by default
- "",
- true,
- true,
- new java.util.LinkedList()
- );
-
- java.util.LinkedList adapterList = new java.util.LinkedList();
- adapterList.add(serviceManager);
-
- PropertyDescriptor pd =
- new PropertyDescriptor("IceBox.ServiceManager.Endpoints",
- "tcp -h 127.0.0.1");
- java.util.LinkedList properties = new java.util.LinkedList();
- properties.add(pd);
-
- return new IceBoxDescriptor(
- adapterList,
- properties,
- new java.util.LinkedList(),
- "",
- "NewIceBox",
- "",
- "",
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- "manual",
- "",
- "",
- true,
- new IceGrid.DistributionDescriptor("", new java.util.LinkedList()),
- new java.util.LinkedList()
- );
- }
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
-
- Object clipboard = _model.getClipboard();
- if(clipboard != null &&
- (clipboard instanceof ServerDescriptor
- || clipboard instanceof ServerInstanceDescriptor))
- {
- actions[PASTE] = true;
- }
-
- actions[DELETE] = true;
- if(!_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
-
- if(_instanceDescriptor == null)
- {
- actions[NEW_ADAPTER] = (_adapters != null && _services == null);
- actions[NEW_SERVICE] = (_services != null);
- actions[NEW_DBENV] = (_dbEnvs != null);
- }
-
- ServerState state = getState();
- if(state != null && _model.getAdmin() != null)
- {
- actions[START] = state == ServerState.Inactive && _enabled;
- actions[STOP] = state != ServerState.Inactive;
- actions[ENABLE] = !_enabled;
- actions[DISABLE] = _enabled;
-
- if(!_model.isUpdateInProgress())
- {
- actions[SERVER_INSTALL_DISTRIBUTION] =
- !_serverDescriptor.distrib.icepatch.equals("");
- }
- }
-
- return actions;
- }
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
-
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_ADAPTER]);
- item.setText("New adapter");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_DBENV]);
- item.setText("New DbEnv");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_SERVICE]);
- item.setText("New service");
- _popup.add(item);
-
- _popup.addSeparator();
- _popup.add(_model.getActions()[START]);
- _popup.add(_model.getActions()[STOP]);
- _popup.addSeparator();
- _popup.add(_model.getActions()[ENABLE]);
- _popup.add(_model.getActions()[DISABLE]);
- _popup.addSeparator();
- _popup.add(_model.getActions()[SERVER_INSTALL_DISTRIBUTION]);
- }
- return _popup;
- }
- public void copy()
- {
- if(_instanceDescriptor != null)
- {
- _model.setClipboard(copyDescriptor(_instanceDescriptor));
- }
- else
- {
- _model.setClipboard(copyDescriptor(_serverDescriptor));
- }
- _model.getActions()[PASTE].setEnabled(true);
- }
- public void paste()
- {
- _parent.paste();
- }
- public void newAdapter()
- {
- _adapters.newAdapter();
- }
- public void newDbEnv()
- {
- _dbEnvs.newDbEnv();
- }
- public void newService()
- {
- _services.newService();
- }
-
- public void start()
- {
- final String prefix = "Starting server '" + _id + "'...";
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_startServer cb = new AMI_Admin_startServer()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to start " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to start " + _id, e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _model.getAdmin().startServer_async(cb, _id);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to start " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
-
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
- }
-
- public void stop()
- {
- final String prefix = "Stopping server '" + _id + "'...";
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_stopServer cb = new AMI_Admin_stopServer()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to stop " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to stop " + _id, e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _model.getAdmin().stopServer_async(cb, _id);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to stop " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
- }
-
- public void enable()
- {
- enableServer(true);
- }
-
- public void disable()
- {
- enableServer(false);
- }
-
- public void serverInstallDistribution()
- {
- int shutdown = JOptionPane.showConfirmDialog(
- _model.getMainFrame(),
- "You are about to install or refresh your"
- + " server distribution and your application distribution onto this node.\n"
- + " Do you want shut down all servers affected by this update?",
- "Patch Confirmation",
- JOptionPane.YES_NO_CANCEL_OPTION);
-
- if(shutdown == JOptionPane.CANCEL_OPTION)
- {
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
-
- return;
- }
-
- final String prefix = "Patching server '" + _id + "'...";
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_patchServer cb = new AMI_Admin_patchServer()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to patch " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to patch " + _id, e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _model.getAdmin().patchServer_async(cb, _id,
- shutdown == JOptionPane.YES_OPTION);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to patch " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
-
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
- }
-
- private void enableServer(boolean enable)
- {
- final String prefix = (enable ?
- "Enabling" : "Disabling") + " server '" + _id + "'...";
-
- final String action = enable ? "enable" : "disable";
-
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_enableServer cb = new AMI_Admin_enableServer()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to " + action + " " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to " + action + " " + _id, e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _model.getAdmin().enableServer_async(cb, _id, enable);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to " + action + " " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
-
- }
-
- public Editor getEditor()
- {
- //
- // Pick the appropriate editor
- //
- Editor editor = null;
- if(_instanceDescriptor == null)
- {
- if(_serverEditor == null)
- {
- _serverEditor = new ServerEditor(_model, _model.getMainFrame());
- }
- _serverEditor.show(this);
- return _serverEditor;
- }
- else
- {
- if(_serverInstanceEditor == null)
- {
- _serverInstanceEditor = new ServerInstanceEditor(
- _model, _model.getMainFrame());
- }
- _serverInstanceEditor.show(this);
- return _serverInstanceEditor;
- }
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- //
- // Initialization
- //
- _cellRenderer = new DefaultTreeCellRenderer();
-
- //
- // Regular servers
- //
- _icons = new Icon[7][2][2];
- _icons[0][0][0] = Utils.getIcon("/icons/16x16/server_unknown.png");
- _icons[ServerState.Inactive.value() + 1][0][0]
- = Utils.getIcon("/icons/16x16/server_inactive.png");
- _icons[ServerState.Activating.value() + 1][0][0] =
- Utils.getIcon("/icons/16x16/server_activating.png");
- _icons[ServerState.Active.value() + 1][0][0] =
- Utils.getIcon("/icons/16x16/server_active.png");
- _icons[ServerState.Deactivating.value() + 1][0][0] =
- Utils.getIcon("/icons/16x16/server_deactivating.png");
- _icons[ServerState.Destroying.value() + 1][0][0] =
- Utils.getIcon("/icons/16x16/server_destroying.png");
- _icons[ServerState.Destroyed.value() + 1][0][0] =
- Utils.getIcon("/icons/16x16/server_destroyed.png");
-
- //
- // IceBox servers
- //
- _icons[0][1][0] = Utils.getIcon("/icons/16x16/icebox_server_unknown.png");
- _icons[ServerState.Inactive.value() + 1][1][0]
- = Utils.getIcon("/icons/16x16/icebox_server_inactive.png");
- _icons[ServerState.Activating.value() + 1][1][0] =
- Utils.getIcon("/icons/16x16/icebox_server_activating.png");
- _icons[ServerState.Active.value() + 1][1][0] =
- Utils.getIcon("/icons/16x16/icebox_server_active.png");
- _icons[ServerState.Deactivating.value() + 1][1][0] =
- Utils.getIcon("/icons/16x16/icebox_server_deactivating.png");
- _icons[ServerState.Destroying.value() + 1][1][0] =
- Utils.getIcon("/icons/16x16/icebox_server_destroying.png");
- _icons[ServerState.Destroyed.value() + 1][1][0] =
- Utils.getIcon("/icons/16x16/icebox_server_destroyed.png");
-
- //
- // Regular servers (disabled)
- //
- _icons[0][0][1] = Utils.getIcon("/icons/16x16/server_unknown.png");
- _icons[ServerState.Inactive.value() + 1][0][1]
- = Utils.getIcon("/icons/16x16/server_disabled_inactive.png");
- _icons[ServerState.Activating.value() + 1][0][1] =
- Utils.getIcon("/icons/16x16/server_disabled_activating.png");
- _icons[ServerState.Active.value() + 1][0][1] =
- Utils.getIcon("/icons/16x16/server_disabled_active.png");
- _icons[ServerState.Deactivating.value() + 1][0][1] =
- Utils.getIcon("/icons/16x16/server_disabled_deactivating.png");
- _icons[ServerState.Destroying.value() + 1][0][1] =
- Utils.getIcon("/icons/16x16/server_disabled_destroying.png");
- _icons[ServerState.Destroyed.value() + 1][0][1] =
- Utils.getIcon("/icons/16x16/server_disabled_destroyed.png");
-
- //
- // IceBox servers (disabled)
- //
- _icons[0][1][1] = Utils.getIcon("/icons/16x16/icebox_server_unknown.png");
- _icons[ServerState.Inactive.value() + 1][1][1]
- = Utils.getIcon("/icons/16x16/icebox_server_disabled_inactive.png");
- _icons[ServerState.Activating.value() + 1][1][1] =
- Utils.getIcon("/icons/16x16/icebox_server_disabled_activating.png");
- _icons[ServerState.Active.value() + 1][1][1] =
- Utils.getIcon("/icons/16x16/icebox_server_disabled_active.png");
- _icons[ServerState.Deactivating.value() + 1][1][1] =
- Utils.getIcon("/icons/16x16/icebox_server_disabled_deactivating.png");
- _icons[ServerState.Destroying.value() + 1][1][1] =
- Utils.getIcon("/icons/16x16/icebox_server_disabled_destroying.png");
- _icons[ServerState.Destroyed.value() + 1][1][1] =
- Utils.getIcon("/icons/16x16/icebox_server_disabled_destroyed.png");
-
- }
-
- int icebox = _serverDescriptor instanceof IceBoxDescriptor ? 1 : 0;
- int disabled = _enabled ? 0 : 1;
-
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_icons[_stateIconIndex][icebox][disabled]);
- }
- else
- {
- _cellRenderer.setClosedIcon(_icons[_stateIconIndex][icebox][disabled]);
- }
-
- _cellRenderer.setToolTipText(_toolTip);
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- public PropertiesHolder getPropertiesHolder()
- {
- return _propertiesHolder;
- }
-
- public boolean destroy()
- {
- if(_parent == null)
- {
- return false;
- }
- Node node = (Node)_parent;
-
- if(_ephemeral)
- {
- node.removeChild(this, true);
- return true;
- }
- else if(_model.canUpdate())
- {
- if(_instanceDescriptor != null)
- {
- node.removeDescriptor(_instanceDescriptor);
- }
- else
- {
- node.removeDescriptor(_serverDescriptor);
- }
- node.removeElement(this, true);
- return true;
- }
- return false;
- }
-
-
- public Object getDescriptor()
- {
- if(_instanceDescriptor != null)
- {
- return _instanceDescriptor;
- }
- else
- {
- return _serverDescriptor;
- }
- }
-
- public Object saveDescriptor()
- {
- if(_instanceDescriptor != null)
- {
- return _instanceDescriptor.clone();
- }
- else
- {
- ServerDescriptor clone = (ServerDescriptor)_serverDescriptor.clone();
- clone.distrib = (IceGrid.DistributionDescriptor)clone.distrib.clone();
- return clone;
- }
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- if(_instanceDescriptor != null)
- {
- ServerInstanceDescriptor copy = (ServerInstanceDescriptor)savedDescriptor;
-
- _instanceDescriptor.template = copy.template;
- _instanceDescriptor.parameterValues = copy.parameterValues;
-
- ServerTemplate t = getApplication().findServerTemplate(_instanceDescriptor.template);
- _serverDescriptor = (ServerDescriptor)
- ((TemplateDescriptor)t.getDescriptor()).descriptor;
- }
- else
- {
- shallowRestore((ServerDescriptor)savedDescriptor, _serverDescriptor);
- }
- }
-
- //
- // Builds the server and all its sub-tree
- //
- Server(boolean brandNew, String serverId,
- Utils.Resolver resolver, ServerInstanceDescriptor instanceDescriptor,
- ServerDescriptor serverDescriptor,
- Application application) throws UpdateFailedException
- {
- super(brandNew, serverId, application.getModel());
- _ephemeral = false;
- rebuild(resolver, instanceDescriptor, serverDescriptor, application);
- }
-
- Server(String serverId, ServerInstanceDescriptor instanceDescriptor,
- ServerDescriptor serverDescriptor, Model model)
- {
- super(false, serverId, model);
- _ephemeral = true;
- try
- {
- rebuild(null, instanceDescriptor, serverDescriptor, null);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- }
-
- //
- // Update the server and all its subtree
- //
- void rebuild(Utils.Resolver resolver,
- ServerInstanceDescriptor instanceDescriptor,
- ServerDescriptor serverDescriptor,
- Application application) throws UpdateFailedException
- {
- assert serverDescriptor != null;
- _resolver = resolver;
- _instanceDescriptor = instanceDescriptor;
- _serverDescriptor = serverDescriptor;
- clearChildren();
-
- boolean isEditable = (instanceDescriptor == null);
- _propertiesHolder = new PropertiesHolder(serverDescriptor);
-
- if(_ephemeral)
- {
- _services = null;
- _dbEnvs = null;
- _adapters = null;
- }
- else
- {
- try
- {
- if(serverDescriptor instanceof IceBoxDescriptor)
- {
- IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)serverDescriptor;
-
- _services = new Services(iceBoxDescriptor.services,
- isEditable, _resolver, application);
- addChild(_services);
- //
- // IceBox has not dbEnv
- //
- assert serverDescriptor.dbEnvs.size() == 0;
- _dbEnvs = null;
- }
- else
- {
- _services = null;
- _dbEnvs = new DbEnvs(serverDescriptor.dbEnvs,
- isEditable, _resolver, _model);
- addChild(_dbEnvs);
- }
-
- _adapters = new Adapters(serverDescriptor.adapters,
- isEditable, _services != null,
- _resolver, _model);
- addChild(_adapters);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
- }
-
- public void setParent(CommonBase parent)
- {
- if(!_ephemeral)
- {
- Ice.IntHolder pid = new Ice.IntHolder();
- Ice.BooleanHolder enabled = new Ice.BooleanHolder();
- _state = _model.getRoot().registerServer(_resolver.find("node"),
- this,
- pid, enabled);
-
- _pid = pid.value;
- _enabled = enabled.value;
- _toolTip = toolTip(_state, _pid, _enabled);
- if(_state != null)
- {
- _stateIconIndex = _state.value() + 1;
- }
- }
- super.setParent(parent);
- }
-
- public void clearParent()
- {
- if(_parent != null)
- {
- if(!_ephemeral)
- {
- _model.getRoot().unregisterServer(_resolver.find("node"),
- this);
- }
- super.clearParent();
- }
- }
-
- java.util.List findServiceInstances(String template)
- {
- if(_services != null)
- {
- return _services.findServiceInstances(template);
- }
- else
- {
- return new java.util.LinkedList();
- }
- }
-
- void removeServiceInstances(String template)
- {
- if(_services != null)
- {
- _services.removeServiceInstances(template);
- }
- }
-
-
- void updateDynamicInfo(ServerState state, int pid, boolean enabled)
- {
- if(state != _state || pid != _pid || enabled != _enabled)
- {
- _state = state;
- _pid = pid;
- _enabled = enabled;
-
- _toolTip = toolTip(_state, _pid, _enabled);
- if(_state == null)
- {
- _stateIconIndex = 0;
- }
- else
- {
- _stateIconIndex = _state.value() + 1;
- }
-
- //
- // Change the node representation
- //
- fireNodeChangedEvent(this);
- }
- }
-
- ServerState getState()
- {
- return _state;
- }
-
- int getPid()
- {
- return _pid;
- }
-
- ServerInstanceDescriptor getInstanceDescriptor()
- {
- return _instanceDescriptor;
- }
-
- ServerDescriptor getServerDescriptor()
- {
- return _serverDescriptor;
- }
-
- void setServerDescriptor(ServerDescriptor sd)
- {
- _serverDescriptor = sd;
- }
-
- Services getServices()
- {
- return _services;
- }
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- Utils.Resolver getParentResolver()
- {
- if(_parent != null)
- {
- return ((Node)_parent).getResolver();
- }
- else
- {
- return null;
- }
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- public String toString()
- {
- if(_instanceDescriptor == null || _ephemeral)
- {
- return super.toString();
- }
- else
- {
- return _id + ": " + _instanceDescriptor.template + "<>";
- }
- }
-
- static private String toolTip(ServerState state, int pid, boolean enabled)
- {
- String result = (state == null ? "Unknown" : state.toString());
-
- if(!enabled)
- {
- result += ", disabled";
- }
-
- if(pid != 0)
- {
- result += ", pid: " + pid;
- }
- return result;
- }
-
- private ServerState _state = null;
- private boolean _enabled = true;
- private int _stateIconIndex = 0;
- private int _pid = 0;
- private String _toolTip;
-
- private ServerInstanceDescriptor _instanceDescriptor;
- private ServerDescriptor _serverDescriptor;
- private final boolean _ephemeral;
-
- private Utils.Resolver _resolver;
-
- private PropertiesHolder _propertiesHolder;
-
- //
- // Children
- //
- private Services _services;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private Icon[][][] _icons;
-
- static private ServerEditor _serverEditor;
- static private ServerInstanceEditor _serverInstanceEditor;
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/ServerTemplate.java b/java/src/IceGrid/TreeNode/ServerTemplate.java
deleted file mode 100755
index 178706cf41a..00000000000
--- a/java/src/IceGrid/TreeNode/ServerTemplate.java
+++ /dev/null
@@ -1,363 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.SimpleInternalFrame;
-
-import IceGrid.IceBoxDescriptor;
-import IceGrid.Model;
-import IceGrid.ServerDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.TreeModelI;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-
-class ServerTemplate extends EditableParent
-{
- static public TemplateDescriptor
- copyDescriptor(TemplateDescriptor templateDescriptor)
- {
- TemplateDescriptor copy = (TemplateDescriptor)
- templateDescriptor.clone();
-
- copy.descriptor = Server.copyDescriptor(
- (ServerDescriptor)copy.descriptor);
- return copy;
- }
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _plainIcon =
- Utils.getIcon("/icons/16x16/server_template.png");
- _iceboxIcon =
- Utils.getIcon("/icons/16x16/icebox_server_template.png");
- }
-
- if(_templateDescriptor.descriptor instanceof IceBoxDescriptor)
- {
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_iceboxIcon);
- }
- else
- {
- _cellRenderer.setClosedIcon(_iceboxIcon);
- }
- }
- else
- {
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_plainIcon);
- }
- else
- {
- _cellRenderer.setClosedIcon(_plainIcon);
- }
- }
-
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
- if(_parent.getAvailableActions()[PASTE])
- {
- actions[PASTE] = true;
- }
-
- actions[DELETE] = true;
-
- actions[NEW_ADAPTER] = (_adapters != null && _services == null);
- actions[NEW_SERVICE] = (_services != null);
- actions[NEW_SERVICE_FROM_TEMPLATE] = (_services != null);
- actions[NEW_DBENV] = (_dbEnvs != null);
-
- return actions;
- }
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_templateDescriptor));
- _model.getActions()[PASTE].setEnabled(true);
- }
- public void paste()
- {
- _parent.paste();
- }
- public void newAdapter()
- {
- _adapters.newAdapter();
- }
- public void newDbEnv()
- {
- _dbEnvs.newDbEnv();
- }
- public void newService()
- {
- _services.newService();
- }
- public void newServiceFromTemplate()
- {
- _services.newServiceFromTemplate();
- }
-
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
-
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_ADAPTER]);
- item.setText("New adapter");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_DBENV]);
- item.setText("New DbEnv");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_SERVICE]);
- item.setText("New service");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_SERVICE_FROM_TEMPLATE]);
- item.setText("New service from template");
- _popup.add(item);
- }
- return _popup;
- }
-
- public Editor getEditor()
- {
- if(_editor == null)
- {
- _editor = new ServerTemplateEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
-
- public boolean destroy()
- {
- ServerTemplates serverTemplates = (ServerTemplates)_parent;
-
- if(serverTemplates != null && _ephemeral)
- {
- serverTemplates.removeChild(this, true);
- return true;
- }
- else if(serverTemplates != null && _model.canUpdate())
- {
- serverTemplates.removeDescriptor(_id);
- getApplication().removeServerInstances(_id);
- serverTemplates.removeElement(this, true);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- public java.util.List findAllInstances(CommonBase child)
- {
- java.util.List result = super.findAllInstances(child);
-
- java.util.List serverInstances =
- getApplication().findServerInstances(_id);
-
- java.util.Iterator p = serverInstances.iterator();
- while(p.hasNext())
- {
- Server server = (Server)p.next();
- result.addAll(server.findChildrenWithType(child.getClass()));
- }
-
- return result;
- }
-
- public PropertiesHolder getPropertiesHolder()
- {
- return _propertiesHolder;
- }
-
- public Object getDescriptor()
- {
- return _templateDescriptor;
- }
-
- public Object saveDescriptor()
- {
- //
- // Shallow copy
- //
- TemplateDescriptor clone = (TemplateDescriptor)_templateDescriptor.clone();
- clone.descriptor = (ServerDescriptor)_templateDescriptor.descriptor.clone();
- return clone;
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- TemplateDescriptor clone = (TemplateDescriptor)savedDescriptor;
- //
- // Keep the same object
- //
- _templateDescriptor.parameters = clone.parameters;
-
- Server.shallowRestore((ServerDescriptor)clone.descriptor,
- (ServerDescriptor)_templateDescriptor.descriptor);
- }
-
- //
- // Application is needed to lookup service templates
- //
- ServerTemplate(boolean brandNew, String name, TemplateDescriptor descriptor,
- Application application)
- throws UpdateFailedException
- {
- super(brandNew, name, application.getModel());
- _ephemeral = false;
- rebuild(descriptor, application);
- }
-
- ServerTemplate(String name, TemplateDescriptor descriptor,
- Application application)
- {
- super(false, name, application.getModel());
- _ephemeral = true;
- try
- {
- rebuild(descriptor, application);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- }
-
- java.util.List findServiceInstances(String template)
- {
- if(_services != null)
- {
- return _services.findServiceInstances(template);
- }
- else
- {
- return new java.util.LinkedList();
- }
- }
-
- void rebuild(TemplateDescriptor descriptor, Application application)
- throws UpdateFailedException
- {
- _templateDescriptor = descriptor;
- _propertiesHolder = new PropertiesHolder(_templateDescriptor.descriptor);
- clearChildren();
-
- if(_ephemeral)
- {
- _adapters = null;
- _dbEnvs = null;
- _services = null;
- }
- else
- {
- if(_templateDescriptor.descriptor instanceof IceBoxDescriptor)
- {
- IceBoxDescriptor iceBoxDescriptor =
- (IceBoxDescriptor)_templateDescriptor.descriptor;
-
- _services = new Services(iceBoxDescriptor.services, true, null,
- application);
- addChild(_services);
-
- assert _templateDescriptor.descriptor.dbEnvs.size() == 0;
- _dbEnvs = null;
- }
- else
- {
- _services = null;
-
- _dbEnvs = new DbEnvs(_templateDescriptor.descriptor.dbEnvs, true,
- null, _model);
- addChild(_dbEnvs);
- }
-
- _adapters = new Adapters(_templateDescriptor.descriptor.adapters, true,
- _services != null, null, _model);
- addChild(_adapters);
- }
- }
-
- void rebuild()
- throws UpdateFailedException
- {
- rebuild(_templateDescriptor, getApplication());
- }
-
- void removeServiceInstances(String template)
- {
- if(_services != null)
- {
- _services.removeServiceInstances(template);
- }
- }
-
- private TemplateDescriptor _templateDescriptor;
-
- private Services _services;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-
- private PropertiesHolder _propertiesHolder;
- private final boolean _ephemeral;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private Icon _plainIcon;
- static private Icon _iceboxIcon;
- static private ServerTemplateEditor _editor;
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/Service.java b/java/src/IceGrid/TreeNode/Service.java
deleted file mode 100755
index 5ad5051f929..00000000000
--- a/java/src/IceGrid/TreeNode/Service.java
+++ /dev/null
@@ -1,397 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import IceGrid.SimpleInternalFrame;
-
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-class Service extends Parent
-{
- static public ServiceInstanceDescriptor
- copyDescriptor(ServiceInstanceDescriptor instanceDescriptor)
- {
- ServiceInstanceDescriptor copy = (ServiceInstanceDescriptor)
- instanceDescriptor.clone();
-
- if(copy.descriptor != null)
- {
- copy.descriptor = copyDescriptor((ServiceDescriptor)copy.descriptor);
- }
- return copy;
- }
-
- static public ServiceDescriptor
- copyDescriptor(ServiceDescriptor sd)
- {
- ServiceDescriptor copy = (ServiceDescriptor)sd.clone();
- copy.adapters = Adapters.copyDescriptors(copy.adapters);
- copy.dbEnvs = DbEnvs.copyDescriptors(copy.dbEnvs);
-
- //
- // Update to properties is not atomic because of Adapter endpoints
- // (and possibly other properties set through a PropertiesHolder)
- //
- copy.properties = (java.util.LinkedList)copy.properties.clone();
- return copy;
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- _cellRenderer = new DefaultTreeCellRenderer();
- _cellRenderer.setOpenIcon(
- Utils.getIcon("/icons/16x16/service.png"));
-
- _cellRenderer.setClosedIcon(
- Utils.getIcon("/icons/16x16/service.png"));
- }
-
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
-
- //
- // Actions
- //
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
- actions[COPY] = true;
-
- if(_parent.getAvailableActions()[PASTE])
- {
- actions[PASTE] = true;
- }
- if(isEditable())
- {
- actions[DELETE] = true;
-
- if(_instanceDescriptor.template.equals(""))
- {
- actions[NEW_ADAPTER] = (_adapters != null);
- actions[NEW_DBENV] = (_dbEnvs != null);
- }
- }
-
- if(_resolver != null && !_ephemeral)
- {
- actions[SHOW_VARS] = true;
- actions[SUBSTITUTE_VARS] = true;
- }
-
- actions[MOVE_UP] = canMoveUp();
- actions[MOVE_DOWN] = canMoveDown();
- return actions;
- }
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_ADAPTER]);
- item.setText("New adapter");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_DBENV]);
- item.setText("New DbEnv");
- _popup.add(item);
-
- _popup.addSeparator();
- _popup.add(_model.getActions()[MOVE_UP]);
- _popup.add(_model.getActions()[MOVE_DOWN]);
- }
- return _popup;
- }
- public void copy()
- {
- _model.setClipboard(copyDescriptor(_instanceDescriptor));
- _model.getActions()[PASTE].setEnabled(true);
- }
- public void paste()
- {
- _parent.paste();
- }
- public void moveUp()
- {
- assert canMoveUp();
- ((Services)_parent).move(this, true);
- }
- public void moveDown()
- {
- assert canMoveDown();
- ((Services)_parent).move(this, false);
- }
- public void newAdapter()
- {
- _adapters.newAdapter();
- }
- public void newDbEnv()
- {
- _dbEnvs.newDbEnv();
- }
-
- public Object getDescriptor()
- {
- return _instanceDescriptor;
- }
-
- public Object saveDescriptor()
- {
- //
- // Must be a shallow copy
- //
- ServiceInstanceDescriptor saved =
- (ServiceInstanceDescriptor)_instanceDescriptor.clone();
-
- if(saved.descriptor != null)
- {
- saved.descriptor = (ServiceDescriptor)saved.descriptor.clone();
- }
- return saved;
- }
-
- public void restoreDescriptor(Object savedDescriptor)
- {
- ServiceInstanceDescriptor sd = (ServiceInstanceDescriptor)savedDescriptor;
- _instanceDescriptor.template = sd.template;
- _instanceDescriptor.parameterValues = sd.parameterValues;
- if(_instanceDescriptor.descriptor != null)
- {
- _instanceDescriptor.descriptor.properties = sd.descriptor.properties;
- _instanceDescriptor.descriptor.description = sd.descriptor.description;
-
- _instanceDescriptor.descriptor.name = sd.descriptor.name;
- _instanceDescriptor.descriptor.entry = sd.descriptor.entry;
- }
- }
-
- public boolean destroy()
- {
- return _parent == null ? false :
- ((ListParent)_parent).destroyChild(this);
- }
-
- public Editor getEditor()
- {
- if(_instanceDescriptor.template.length() > 0)
- {
- if(_instanceEditor == null)
- {
- _instanceEditor = new ServiceInstanceEditor(_model.getMainFrame());
- }
- _instanceEditor.show(this);
- return _instanceEditor;
- }
- else
- {
- if(_editor == null)
- {
- _editor = new ServiceEditor(_model.getMainFrame());
- }
- _editor.show(this);
- return _editor;
- }
- }
-
- public String toString()
- {
- if(_displayString != null)
- {
- return _displayString;
- }
- else
- {
- return super.toString();
- }
- }
-
- public PropertiesHolder getPropertiesHolder()
- {
- return _propertiesHolder;
- }
-
-
- boolean canMoveUp()
- {
- if(_ephemeral)
- {
- return false;
- }
- else
- {
- return ((Services)_parent).canMove(this, true);
- }
- }
-
- boolean canMoveDown()
- {
- if(_ephemeral)
- {
- return false;
- }
- else
- {
- return ((Services)_parent).canMove(this, false);
- }
- }
-
-
- //
- // child == _adapters or _dbEnvs
- //
- public java.util.List findAllInstances(CommonBase child)
- {
- //
- // Find all instances of this service (in server instances)
- // and return the list of their adapters or dbEnvs
- //
- assert getIndex(child) != -1;
-
- java.util.List result = new java.util.LinkedList();
-
- //
- // First find all instances of the enclosing Services
- //
- java.util.List servicesList = _parent.getParent().findAllInstances(_parent);
-
- java.util.Iterator p = servicesList.iterator();
- while(p.hasNext())
- {
- Services services = (Services)p.next();
- Service service = (Service)services.findChildWithDescriptor(_instanceDescriptor);
- assert service != null;
- result.addAll(service.findChildrenWithType(child.getClass()));
- }
- return result;
- }
-
-
- Service(String name,
- String displayString,
- ServiceInstanceDescriptor instanceDescriptor,
- ServiceDescriptor serviceDescriptor,
- boolean isEditable,
- Utils.Resolver resolver,
- Model model)
- throws UpdateFailedException
- {
- super(name, model);
- _displayString = displayString;
- _instanceDescriptor = instanceDescriptor;
- _serviceDescriptor = serviceDescriptor;
- _propertiesHolder = new PropertiesHolder(serviceDescriptor);
- _ephemeral = false;
-
- _resolver = resolver;
-
- boolean areChildrenEditable = _instanceDescriptor.template.length() == 0
- && isEditable;
-
- try
- {
- _adapters = new Adapters(serviceDescriptor.adapters,
- areChildrenEditable, false, resolver,
- _model);
- addChild(_adapters);
-
- _dbEnvs = new DbEnvs(serviceDescriptor.dbEnvs,
- areChildrenEditable, resolver, _model);
- addChild(_dbEnvs);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
- //
- // New temporary object
- //
- Service(String name,
- ServiceInstanceDescriptor instanceDescriptor,
- Model model)
- {
- super(name, model);
- _instanceDescriptor = instanceDescriptor;
- _serviceDescriptor = instanceDescriptor.descriptor;
- _ephemeral = true;
- }
-
-
- ServiceDescriptor getServiceDescriptor()
- {
- return _serviceDescriptor;
- }
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- Utils.Resolver getParentResolver()
- {
- return ((Services)_parent).getResolver();
- }
-
- boolean isEditable()
- {
- if(_parent == null)
- {
- return false;
- }
- else
- {
- return ((Services)_parent).isEditable();
- }
- }
-
- public boolean isEphemeral()
- {
- return _ephemeral;
- }
-
- private ServiceInstanceDescriptor _instanceDescriptor;
- private ServiceDescriptor _serviceDescriptor;
-
- private String _displayString;
- private final boolean _ephemeral;
- private Utils.Resolver _resolver;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-
- private PropertiesHolder _propertiesHolder;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private ServiceEditor _editor;
- static private ServiceInstanceEditor _instanceEditor;
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/Services.java b/java/src/IceGrid/TreeNode/Services.java
deleted file mode 100755
index 61c1e32fe88..00000000000
--- a/java/src/IceGrid/TreeNode/Services.java
+++ /dev/null
@@ -1,472 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPopupMenu;
-
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-class Services extends ListParent
-{
- static public java.util.LinkedList
- copyDescriptors(java.util.LinkedList descriptors)
- {
- java.util.LinkedList copy = new java.util.LinkedList();
- java.util.Iterator p = descriptors.iterator();
- while(p.hasNext())
- {
- copy.add(Service.copyDescriptor(
- (ServiceInstanceDescriptor)p.next()));
- }
- return copy;
- }
-
- public boolean[] getAvailableActions()
- {
- boolean[] actions = new boolean[ACTION_COUNT];
-
- Object descriptor = _model.getClipboard();
- if(descriptor != null)
- {
- actions[PASTE] = isEditable() &&
- descriptor instanceof ServiceInstanceDescriptor;
- }
- actions[NEW_SERVICE] = isEditable();
- actions[NEW_SERVICE_FROM_TEMPLATE] = isEditable();
- return actions;
- }
-
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu(_model);
- JMenuItem newServiceItem = new JMenuItem(_model.getActions()[NEW_SERVICE]);
- newServiceItem.setText("New service");
- _popup.add(newServiceItem);
- JMenuItem newServiceFromTemplateItem =
- new JMenuItem(_model.getActions()[NEW_SERVICE_FROM_TEMPLATE]);
- newServiceFromTemplateItem.setText("New service from template");
- _popup.add(newServiceFromTemplateItem);
- }
- return _popup;
- }
-
- public void paste()
- {
- Object descriptor = _model.getClipboard();
- ServiceInstanceDescriptor d = (ServiceInstanceDescriptor)descriptor;
- newService(Service.copyDescriptor(d));
- }
-
- public void newService()
- {
- ServiceDescriptor sd =
- new ServiceDescriptor(new java.util.LinkedList(),
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- "",
- "NewService",
- "");
-
- ServiceInstanceDescriptor descriptor =
- new ServiceInstanceDescriptor("",
- new java.util.TreeMap(),
- sd);
- newService(descriptor);
- }
-
- public void newServiceFromTemplate()
- {
- ServiceInstanceDescriptor descriptor =
- new ServiceInstanceDescriptor("",
- new java.util.HashMap(),
- null);
- newService(descriptor);
- }
-
-
- private Service createService(ServiceInstanceDescriptor descriptor,
- Application application) throws UpdateFailedException
- {
- ServiceDescriptor serviceDescriptor = null;
- String serviceName = null;
- String displayString = null;
- Utils.Resolver serviceResolver = null;
-
- if(descriptor.template.length() > 0)
- {
- TemplateDescriptor templateDescriptor
- = application.findServiceTemplateDescriptor(descriptor.template);
-
- assert templateDescriptor != null;
-
- serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor;
- assert serviceDescriptor != null;
-
- if(_resolver != null)
- {
- serviceResolver = new Utils.Resolver(_resolver,
- descriptor.parameterValues,
- templateDescriptor.parameterDefaults);
- serviceName = serviceResolver.substitute(serviceDescriptor.name);
- serviceResolver.put("service", serviceName);
- displayString = serviceName + ": " + descriptor.template + "<>";
- }
- else
- {
- //
- // serviceName = TemplateName<unsubstituted param 1, ....>
- //
- serviceName = templateLabel(descriptor.template,
- templateDescriptor.parameters,
- descriptor.parameterValues,
- templateDescriptor.parameterDefaults);
-
- }
- }
- else
- {
- serviceDescriptor = descriptor.descriptor;
- assert serviceDescriptor != null;
-
- if(_resolver != null)
- {
- serviceResolver = new Utils.Resolver(_resolver);
- serviceName = _resolver.substitute(serviceDescriptor.name);
- serviceResolver.put("service", serviceName);
- }
- else
- {
- serviceName = serviceDescriptor.name;
- }
- }
-
- return new Service(serviceName,
- displayString,
- descriptor,
- serviceDescriptor,
- _isEditable,
- serviceResolver,
- _model);
- }
-
- Services(java.util.List descriptors,
- boolean isEditable,
- Utils.Resolver resolver, // Null within template
- Application application)
- throws UpdateFailedException
- {
- super("Services", application.getModel());
- _descriptors = descriptors;
- _isEditable = isEditable;
- _resolver = resolver;
-
- sortChildren(false);
-
- java.util.Iterator p = _descriptors.iterator();
- while(p.hasNext())
- {
- ServiceInstanceDescriptor descriptor =
- (ServiceInstanceDescriptor)p.next();
-
- try
- {
- addChild(createService(descriptor, application));
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
- }
-
- private void newService(ServiceInstanceDescriptor descriptor)
- {
- String baseName = descriptor.descriptor == null ? "NewService" :
- descriptor.descriptor.name;
- String name = makeNewChildId(baseName);
-
- if(descriptor.descriptor != null)
- {
- descriptor.descriptor.name = name;
- }
- else
- {
- //
- // Make sure descriptor.template points to a real template
- //
- ServiceTemplate t = getApplication().findServiceTemplate(descriptor.template);
-
- if(t == null)
- {
- t = (ServiceTemplate)getApplication().getServiceTemplates().getChildAt(0);
-
- if(t == null)
- {
- JOptionPane.showMessageDialog(
- _model.getMainFrame(),
- "You need to create a service template before you can create a service from a template.",
- "No Service Template",
- JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- else
- {
- descriptor.template = t.getId();
- descriptor.parameterValues = new java.util.HashMap();
- }
- }
-
- //
- // Validate/update parameterValues
- //
- TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor();
- descriptor.parameterValues = Editor.makeParameterValues(descriptor.parameterValues,
- td.parameters);
-
- }
-
- Service service = new Service(name, descriptor, _model);
- try
- {
- addChild(service, true);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- _model.setSelectionPath(service.getPath());
- }
-
- boolean isEditable()
- {
- return _isEditable;
- }
-
- java.util.List findServiceInstances(String template)
- {
- java.util.List result = new java.util.LinkedList();
-
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Service service = (Service)p.next();
- ServiceInstanceDescriptor d =
- (ServiceInstanceDescriptor)service.getDescriptor();
- if(d.template.equals(template))
- {
- result.add(service);
- }
- }
- return result;
- }
-
-
- void removeServiceInstances(String template)
- {
- java.util.List toRemove = new java.util.LinkedList();
-
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Service service = (Service)p.next();
- ServiceInstanceDescriptor d =
- (ServiceInstanceDescriptor)service.getDescriptor();
- if(d.template.equals(template))
- {
- removeDescriptor(d);
- toRemove.add(service.getId());
- }
- }
-
- if(toRemove.size() > 0)
- {
- getEditable().markModified();
- removeChildren((String[])toRemove.toArray(new String[0]));
- }
- }
-
- Utils.Resolver getResolver()
- {
- return _resolver;
- }
-
- boolean canMove(Service service, boolean up)
- {
- if(_isEditable)
- {
- int index = _descriptors.indexOf(service.getDescriptor());
- assert index != -1;
- if(up && index == 0 || !up && (index == _descriptors.size() - 1))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- return false;
- }
-
- void move(Service service, boolean up)
- {
- int index = _descriptors.indexOf(service.getDescriptor());
-
- if(_model.canUpdate())
- {
- getEditable().markModified();
-
- Object descriptor = _descriptors.remove(index);
- if(up)
- {
- _descriptors.add(index - 1, descriptor);
- }
- else
- {
- _descriptors.add(index + 1, descriptor);
- }
- moveChild(index, up, true);
-
- //
- // Propagate to instances
- //
- if(_parent instanceof ServerTemplate)
- {
- java.util.List instances =
- getApplication().findServerInstances(_parent.getId());
- java.util.Iterator p = instances.iterator();
- while(p.hasNext())
- {
- Server server = (Server)p.next();
-
- //
- // The descriptors are the same as `this` descriptors
- //
- server.getServices().moveChild(index, up, true);
- }
- }
- }
- //
- // Recompute actions
- //
- _model.showActions(_model.getSelectedNode());
- }
-
-
- CommonBase addNewChild(Object d) throws UpdateFailedException
- {
- ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)d;
-
- try
- {
- Service service = createService(descriptor, getApplication());
- addChild(service, true);
- return service;
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
-
- Object rebuildChild(CommonBase child, java.util.List editables)
- throws UpdateFailedException
- {
- int index = getIndex(child);
- assert index != -1;
- removeChild(child, true);
- ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)child.getDescriptor();
-
- java.util.Map savedParameterValues = null;
-
- if(descriptor.template.length() > 0)
- {
- TemplateDescriptor templateDescriptor
- = getApplication().findServiceTemplateDescriptor(descriptor.template);
-
- java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters);
- if(!parameters.equals(descriptor.parameterValues.keySet()))
- {
- savedParameterValues = descriptor.parameterValues;
- descriptor.parameterValues = Editor.makeParameterValues(
- descriptor.parameterValues, templateDescriptor.parameters);
- editables.add(getEditable());
- }
- }
-
- try
- {
- Service newChild = createService(descriptor, getApplication());
- addChild(index, newChild, true);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- //
- // Restore
- //
- if(savedParameterValues != null)
- {
- descriptor.parameterValues = savedParameterValues;
- }
- addChild(index, child, true);
-
- throw e;
- }
-
- return savedParameterValues;
- }
-
- void restoreChild(CommonBase child, Object backup)
- {
- java.util.Map savedParameterValues = (java.util.Map)backup;
-
- ServiceInstanceDescriptor descriptor =
- (ServiceInstanceDescriptor)child.getDescriptor();
-
- if(savedParameterValues != null)
- {
- descriptor.parameterValues = savedParameterValues;
- }
-
- CommonBase badChild = findChildWithDescriptor(descriptor);
- int index = getIndex(badChild);
- assert index != -1;
- removeChild(badChild, true);
-
- try
- {
- addChild(index, child, true);
- }
- catch(UpdateFailedException e)
- {
- assert false; // impossible
- }
- }
-
- private final boolean _isEditable;
- private final Utils.Resolver _resolver;
-
- static private JPopupMenu _popup;
-}
diff --git a/java/src/IceGrid/TreeNode/UpdateFailedException.java b/java/src/IceGrid/TreeNode/UpdateFailedException.java
deleted file mode 100755
index 0027f7a1b26..00000000000
--- a/java/src/IceGrid/TreeNode/UpdateFailedException.java
+++ /dev/null
@@ -1,87 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import javax.swing.tree.TreePath;
-
-class UpdateFailedException extends Exception
-{
- UpdateFailedException(Parent parent, String duplicateName)
- {
- _duplicateName = duplicateName;
- _parentList = new java.util.LinkedList();
- _parentList.addFirst(parent);
- }
-
- UpdateFailedException(String message)
- {
- _message = message;
- }
-
- void addParent(Parent parent)
- {
- if(_message == null)
- {
- Parent firstParent = (Parent)_parentList.get(0);
- if(firstParent != parent && firstParent.getParent() == null)
- {
- _parentList.addFirst(parent);
- }
- }
- }
-
- public String toString()
- {
- if(_message == null)
- {
- _message = "";
- if(_parentList != null)
- {
- TreePath path = null;
-
- java.util.Iterator p = _parentList.iterator();
- while(p.hasNext())
- {
- Parent parent = (Parent)p.next();
- if(path == null)
- {
- path = parent.getPath();
- if(path == null)
- {
- path = new TreePath(parent);
- }
- }
- else
- {
- path = path.pathByAddingChild(parent);
- }
- }
-
- for(int i = 1; i < path.getPathCount(); ++i)
- {
- if(!_message.equals(""))
- {
- _message += "/";
- }
- _message += ((CommonBase)path.getPathComponent(i)).getId();
- }
- }
- else
- {
- _message = "???";
- }
- _message += " cannot have two children named " + _duplicateName;
- }
- return _message;
- }
-
- private String _message;
- private String _duplicateName;
- private java.util.LinkedList _parentList;
-}
diff --git a/java/src/IceGridGUI/Application/AbstractServerEditor.java b/java/src/IceGridGUI/Application/AbstractServerEditor.java
new file mode 100755
index 00000000000..2a57502f978
--- /dev/null
+++ b/java/src/IceGridGUI/Application/AbstractServerEditor.java
@@ -0,0 +1,176 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+import javax.swing.JToolBar;
+
+import com.jgoodies.looks.Options;
+import com.jgoodies.looks.HeaderStyle;
+import com.jgoodies.looks.BorderStyle;
+import com.jgoodies.looks.plastic.PlasticLookAndFeel;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// Base class for ServerEditor and ServerInstanceEditor
+//
+
+abstract class AbstractServerEditor extends Editor
+{
+ abstract protected void writeDescriptor();
+ abstract protected boolean isSimpleUpdate();
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Server Properties");
+ }
+
+ protected void applyUpdate()
+ {
+ Root root = _target.getRoot();
+ Server server = (Server)_target;
+
+ root.disableSelectionListener();
+ try
+ {
+ if(_target.isEphemeral())
+ {
+ Node node = (Node)_target.getParent();
+ writeDescriptor();
+ ServerInstanceDescriptor instanceDescriptor =
+ server.getInstanceDescriptor();
+ ServerDescriptor serverDescriptor =
+ server.getServerDescriptor();
+
+ _target.destroy(); // just removes the child
+
+ try
+ {
+ node.tryAdd(instanceDescriptor, serverDescriptor, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Add back ephemeral child
+ //
+ try
+ {
+ node.insertChild(_target, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+ root.setSelectedNode(_target);
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ if(instanceDescriptor != null)
+ {
+ _target = (Server)node.findChildWithDescriptor(instanceDescriptor);
+ }
+ else
+ {
+ _target = (Server)node.findChildWithDescriptor(serverDescriptor);
+ }
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+ else if(isSimpleUpdate())
+ {
+ writeDescriptor();
+ root.updated();
+ server.getEditable().markModified();
+ }
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ Object savedDescriptor = ((Communicator)_target).saveDescriptor();
+ Node node = (Node)_target.getParent();
+ writeDescriptor();
+
+ ServerInstanceDescriptor instanceDescriptor =
+ server.getInstanceDescriptor();
+ ServerDescriptor serverDescriptor =
+ server.getServerDescriptor();
+
+ node.removeChild(_target);
+
+ try
+ {
+ node.tryAdd(instanceDescriptor, serverDescriptor, false);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Restore
+ //
+ try
+ {
+ node.insertChild(_target, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+ ((Communicator)_target).restoreDescriptor(savedDescriptor);
+ root.setSelectedNode(_target);
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ node.getEditable().removeElement(_target.getId()); // replaced by brand new Server
+
+ if(instanceDescriptor != null)
+ {
+ _target = node.findChildWithDescriptor(instanceDescriptor);
+ }
+ else
+ {
+ _target = node.findChildWithDescriptor(serverDescriptor);
+ }
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+
+ root.getCoordinator().getCurrentTab().showNode(_target);
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
+ }
+ finally
+ {
+ root.enableSelectionListener();
+ }
+ }
+}
diff --git a/java/src/IceGridGUI/Application/Adapter.java b/java/src/IceGridGUI/Application/Adapter.java
new file mode 100755
index 00000000000..c55398dfa5f
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Adapter.java
@@ -0,0 +1,226 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Adapter extends TreeNode implements CommunicatorChild, DescriptorHolder
+{
+ static public AdapterDescriptor copyDescriptor(AdapterDescriptor d)
+ {
+ return (AdapterDescriptor)d.clone();
+ }
+
+ static public java.util.LinkedList
+ copyDescriptors(java.util.LinkedList descriptors)
+ {
+ java.util.LinkedList copy = new java.util.LinkedList();
+ java.util.Iterator p = descriptors.iterator();
+ while(p.hasNext())
+ {
+ copy.add(copyDescriptor((AdapterDescriptor)p.next()));
+ }
+ return copy;
+ }
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+
+ boolean[] parentActions = ((TreeNode)_parent).getAvailableActions();
+
+ actions[PASTE] = parentActions[PASTE];
+
+ if(isEditable())
+ {
+ actions[DELETE] = true;
+ }
+
+ if(!_ephemeral)
+ {
+ actions[SHOW_VARS] = parentActions[SHOW_VARS];
+ actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS];
+ }
+ return actions;
+ }
+
+ public void copy()
+ {
+ getCoordinator().setClipboard(copyDescriptor(_descriptor));
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+ }
+ public void paste()
+ {
+ ((TreeNode)_parent).paste();
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/adapter_inactive.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (AdapterEditor)getRoot().getEditor(AdapterEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new AdapterEditor(getCoordinator().getMainFrame());
+ }
+
+
+ public void destroy()
+ {
+ ((Communicator)_parent).getAdapters().destroyChild(this);
+ }
+
+ Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ public Object saveDescriptor()
+ {
+ return copyDescriptor(_descriptor);
+ }
+
+ public void restoreDescriptor(Object savedDescriptor)
+ {
+ AdapterDescriptor ad = (AdapterDescriptor)savedDescriptor;
+
+ _descriptor.name = ad.name;
+ _descriptor.id = ad.id;
+ _descriptor.replicaGroupId = ad.replicaGroupId;
+ _descriptor.description = ad.description;
+ _descriptor.registerProcess = ad.registerProcess;
+ _descriptor.waitForActivation = ad.waitForActivation;
+ _descriptor.objects = ad.objects;
+ }
+
+ Adapter(Communicator parent, String adapterName, AdapterDescriptor descriptor,
+ boolean ephemeral)
+ {
+ super(parent, adapterName);
+ _descriptor = descriptor;
+ _ephemeral = ephemeral;
+ }
+
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", _descriptor.name));
+ attributes.add(createAttribute("endpoints", getProperty("Endpoints")));
+ attributes.add(createAttribute("id", _descriptor.id));
+ if(_descriptor.registerProcess)
+ {
+ attributes.add(createAttribute("register-process", "true"));
+ }
+ if(_descriptor.replicaGroupId.length() > 0)
+ {
+ attributes.add(createAttribute("replica-group", _descriptor.replicaGroupId));
+ }
+ if(!_descriptor.waitForActivation)
+ {
+ attributes.add(createAttribute("wait-for-activation", "false"));
+ }
+
+ if(_descriptor.description.length() == 0 && _descriptor.objects.isEmpty())
+ {
+ writer.writeElement("adapter", attributes);
+ }
+ else
+ {
+ writer.writeStartTag("adapter", attributes);
+
+ if(_descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _descriptor.description);
+ }
+ writeObjects(writer, _descriptor.objects);
+ writer.writeEndTag("adapter");
+ }
+ }
+ }
+
+ boolean inIceBox()
+ {
+ return ((Communicator)_parent).isIceBox();
+ }
+
+ String getProperty(String property)
+ {
+ return ((Communicator)_parent).getProperty(_descriptor.name + "." + property);
+ }
+ void setProperty(String name, String property, String newValue)
+ {
+ ((Communicator)_parent).setProperty(name + "." + property, newValue);
+ }
+ void removeProperty(String name, String property)
+ {
+ ((Communicator)_parent).removeProperty(name + "." + property);
+ }
+
+ String getDefaultAdapterId()
+ {
+ return getDefaultAdapterId(_id);
+ }
+
+ String getDefaultAdapterId(String name)
+ {
+ return (_parent instanceof Service ||
+ _parent instanceof ServiceTemplate) ?
+ "${server}.${service}." + name: "${server}." + name;
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ private final boolean _ephemeral;
+ private AdapterDescriptor _descriptor;
+ private AdapterEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+}
diff --git a/java/src/IceGrid/TreeNode/AdapterEditor.java b/java/src/IceGridGUI/Application/AdapterEditor.java
index cd341385ce7..d4059a79d06 100755
--- a/java/src/IceGrid/TreeNode/AdapterEditor.java
+++ b/java/src/IceGridGUI/Application/AdapterEditor.java
@@ -1,671 +1,615 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-
-import IceGrid.AdapterDescriptor;
-import IceGrid.Model;
-import IceGrid.ObjectDescriptor;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
-
-class AdapterEditor extends ListElementEditor
-{
- public JComponent getCurrentStatus(Ice.StringHolder title)
- {
- JComponent panel = super.getCurrentStatus(title);
-
- if(panel != null)
- {
- Adapter adapter = getAdapter();
- if(adapter == null || adapter.getResolver() == null)
- {
- panel = null;
- }
- }
- return panel;
- }
-
- AdapterEditor(JFrame parentFrame)
- {
- super(true);
-
- _objects.setEditable(false);
-
- _currentStatus.setEditable(false);
- _currentEndpoints.setEditable(false);
- _currentEndpoints.setToolTipText(
- "Endpoints registered with the IceGrid Registry during the activation of this adapter");
-
- //
- // Create buttons
- //
-
- //
- // _replicaGroupButton
- //
- Action gotoReplicaGroup = new AbstractAction(
- "", Utils.getIcon("/icons/16x16/goto.png"))
- {
- public void actionPerformed(ActionEvent e)
- {
- Object obj = _replicaGroupId.getSelectedItem();
- Adapter adapter = getAdapter();
-
- ReplicaGroup rg = null;
- if(obj instanceof ReplicaGroup)
- {
- rg = (ReplicaGroup)obj;
- }
- else
- {
- String replicaGroupId =
- Utils.substitute(obj.toString(), adapter.getResolver());
-
- rg = adapter.getApplication().
- findReplicaGroup(replicaGroupId);
- }
-
- //
- // The button is enabled therefore rg should be != null
- //
- if(rg != null)
- {
- adapter.getModel().setSelectionPath(rg.getPath());
- }
- }
- };
- gotoReplicaGroup.putValue(Action.SHORT_DESCRIPTION,
- "Goto the definition of this replica group");
- _replicaGroupButton = new JButton(gotoReplicaGroup);
-
- //
- // _objectsButton
- //
- _objectsDialog = new TableDialog(parentFrame,
- "Registered Objects",
- "Object Identity",
- "Type", true);
-
- Action openObjectsDialog = new AbstractAction("...")
- {
- public void actionPerformed(ActionEvent e)
- {
- java.util.Map result = _objectsDialog.show(_objectsMap,
- getProperties());
- if(result != null)
- {
- updated();
- _objectsMap = result;
- setObjectsField();
- }
- }
- };
- openObjectsDialog.putValue(Action.SHORT_DESCRIPTION,
- "Edit registered objects");
- _objectsButton = new JButton(openObjectsDialog);
-
-
- Action checkRegisterProcess = new AbstractAction("Register Process")
- {
- public void actionPerformed(ActionEvent e)
- {
- updated();
- }
- };
- _registerProcess = new JCheckBox(checkRegisterProcess);
- _registerProcess.setToolTipText(
- "<html>During activation, create a Process object<br>"
- + "in this adapter and register it with IceGrid<br>"
- + "to enable clean shutdown; you should register<br>"
- + "exactly one Process object per server.</html>");
-
- Action checkWaitForActivation =
- new AbstractAction("Wait for Activation")
- {
- public void actionPerformed(ActionEvent e)
- {
- updated();
- }
- };
- _waitForActivation = new JCheckBox(checkWaitForActivation);
- _waitForActivation.setToolTipText(
- "<html>When starting the enclosing server, "
- + "does IceGrid<br>wait for this adapter to become active?</html>");
- //
- // Associate updateListener with various fields
- //
- _name.getDocument().addDocumentListener(
- new DocumentListener()
- {
- public void changedUpdate(DocumentEvent e)
- {
- update();
- }
-
- public void insertUpdate(DocumentEvent e)
- {
- update();
- }
-
- public void removeUpdate(DocumentEvent e)
- {
- update();
- }
-
- private void update()
- {
- updated();
- //
- // Recompute default id
- //
- _defaultAdapterId = getAdapter().getDefaultAdapterId(_name.getText());
- refreshId();
- }
- });
-
- _name.setToolTipText(
- "Identifies this object adapter within an Ice communicator");
-
- _endpoints.getDocument().addDocumentListener(_updateListener);
- _endpoints.setToolTipText(
- "<html>The network interfaces on which this adapter receives requests;<br>"
- + "for example:<br>"
- + " tcp (listen on all local interfaces using a random port)<br>"
- + " tcp -h venus.foo.com (listen on just one interface)<br>"
- + " tcp -t 10000 (sets a timeout of 10,000 milliseconds)<br>"
- + " ssl -h venus.foo.com (accepts SSL connections instead of plain TCP)"
- + "</html>");
-
- _description.getDocument().addDocumentListener(_updateListener);
- _description.setToolTipText(
- "An optional description for this object adapter");
-
- JTextField idTextField = (JTextField)
- _id.getEditor().getEditorComponent();
- idTextField.getDocument().addDocumentListener(_updateListener);
- _id.setToolTipText("If set, must be unique within this IceGrid deployment");
-
- JTextField replicaGroupIdTextField = (JTextField)
- _replicaGroupId.getEditor().getEditorComponent();
- replicaGroupIdTextField.getDocument().addDocumentListener(_updateListener);
- _replicaGroupId.setToolTipText("Select a replica group");
-
- JTextField publishedEndpointsTextField = (JTextField)
- _publishedEndpoints.getEditor().getEditorComponent();
- publishedEndpointsTextField.getDocument().addDocumentListener(_updateListener);
- _publishedEndpoints.setToolTipText(
- "<html>Direct adapter: endpoints included in proxies created using this adapter.<br>"
- + "Indirect adapter: endpoints registered with the IceGrid Registry during the activation of this adapter."
- + "</html>");
- }
-
-
- //
- // From Editor:
- //
-
- void writeDescriptor()
- {
- AdapterDescriptor descriptor =
- (AdapterDescriptor)getAdapter().getDescriptor();
- descriptor.name = _name.getText();
- descriptor.description = _description.getText();
- descriptor.id = getIdAsString();
- descriptor.replicaGroupId = getReplicaGroupIdAsString();
- descriptor.registerProcess = _registerProcess.isSelected();
- descriptor.waitForActivation = _waitForActivation.isSelected();
- descriptor.objects = mapToObjectDescriptorSeq(_objectsMap);
- }
-
- boolean isSimpleUpdate()
- {
- AdapterDescriptor descriptor =
- (AdapterDescriptor)getAdapter().getDescriptor();
-
- //
- // When id change, we need to re-register for updates
- //
- return descriptor.name.equals(_name.getText())
- && descriptor.id.equals(getIdAsString());
- }
-
- void appendCurrentStatus(DefaultFormBuilder builder)
- {
- builder.append("Status" );
- builder.append(_currentStatus, 3);
- builder.nextLine();
-
- builder.append("Published Endpoints" );
- builder.append(_currentEndpoints, 3);
- builder.nextLine();
- }
-
- void appendProperties(DefaultFormBuilder builder)
- {
- builder.append("Adapter Name" );
- builder.append(_name, 3);
- builder.nextLine();
-
- builder.append("Description");
- builder.nextLine();
- builder.append("");
- builder.nextRow(-2);
- CellConstraints cc = new CellConstraints();
- JScrollPane scrollPane = new JScrollPane(_description);
- builder.add(scrollPane,
- cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
- builder.nextRow(2);
- builder.nextLine();
-
- builder.append("Adapter ID");
- builder.append(_id, 3);
- builder.nextLine();
-
- builder.append("Replica Group", _replicaGroupId);
- builder.append(_replicaGroupButton);
- builder.nextLine();
-
- builder.append("Registered Objects");
- builder.append(_objects, _objectsButton);
- builder.nextLine();
-
- builder.append("", _registerProcess);
- builder.nextLine();
- builder.append("", _waitForActivation);
- builder.nextLine();
-
- builder.append("Endpoints" );
- builder.append(_endpoints, 3);
- builder.nextLine();
-
- builder.append("Published Endpoints" );
- builder.append(_publishedEndpoints, 3);
- builder.nextLine();
- }
-
- void postUpdate()
- {
- //
- // Change enclosing properties after successful update
- //
- String name = _name.getText();
- Adapter adapter = getAdapter();
- if(!name.equals(_oldName))
- {
- adapter.removeProperty(_oldName, "Endpoints");
- adapter.removeProperty(_oldName, "PublishedEndpoints");
- }
-
- adapter.setProperty(name, "Endpoints", _endpoints.getText());
-
- Object published = _publishedEndpoints.getSelectedItem();
- if(published == PUBLISH_ACTUAL)
- {
- adapter.removeProperty(name, "PublishedEndpoints");
- }
- else
- {
- adapter.setProperty(name, "PublishedEndpoints",
- published.toString());
-
- }
- }
-
- private void setObjectsField()
- {
- Adapter adapter = getAdapter();
-
- final Utils.Resolver resolver = adapter.getModel().substitute() ?
- adapter.getResolver() : null;
-
- Ice.StringHolder toolTipHolder = new Ice.StringHolder();
- Utils.Stringifier stringifier = new Utils.Stringifier()
- {
- public String toString(Object obj)
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)obj;
-
- return Utils.substitute((String)entry.getKey(), resolver)
- + " as '"
- + Utils.substitute((String)entry.getValue(), resolver)
- + "'";
- }
- };
-
- _objects.setText(
- Utils.stringify(_objectsMap.entrySet(), stringifier,
- ", ", toolTipHolder));
-
- _objects.setToolTipText(toolTipHolder.value);
- }
-
- private void setId(String id)
- {
- if(id.equals(""))
- {
- _id.setSelectedItem(DIRECT_ADAPTER);
- }
- else if(id.equals(_defaultAdapterId))
- {
- _id.setSelectedItem(DEFAULT_ADAPTER_ID);
- }
- else
- {
- _id.setSelectedItem(id);
- }
- }
-
- private void refreshId()
- {
- Object id = _id.getSelectedItem();
- _id.setModel(new DefaultComboBoxModel(new Object[]
- {DIRECT_ADAPTER, DEFAULT_ADAPTER_ID}));
- _id.setSelectedItem(id);
- }
-
- private String getIdAsString()
- {
- Object obj = _id.getSelectedItem();
- if(obj == DIRECT_ADAPTER)
- {
- return "";
- }
- else
- {
- return obj.toString();
- }
- }
-
- private void setReplicaGroupId(String replicaGroupId)
- {
- if(replicaGroupId.equals(""))
- {
- _replicaGroupId.setSelectedItem(NOT_REPLICATED);
- }
- else
- {
- ReplicaGroups replicaGroups =
- getAdapter().getApplication().getReplicaGroups();
-
- ReplicaGroup replicaGroup =
- (ReplicaGroup)replicaGroups.findChild(replicaGroupId);
-
- if(replicaGroup != null)
- {
- _replicaGroupId.setSelectedItem(replicaGroup);
- }
- else
- {
- _replicaGroupId.setSelectedItem(replicaGroupId);
- }
- }
- }
-
-
- private String getReplicaGroupIdAsString()
- {
- Object obj = _replicaGroupId.getSelectedItem();
- if(obj == NOT_REPLICATED)
- {
- return "";
- }
- else
- {
- return obj.toString();
- }
- }
-
- void show(Adapter adapter)
- {
- detectUpdates(false);
- setTarget(adapter);
-
- AdapterDescriptor descriptor = (AdapterDescriptor)adapter.getDescriptor();
-
- final Utils.Resolver resolver = adapter.getModel().substitute() ?
- adapter.getResolver() : null;
-
- boolean isEditable = adapter.isEditable() && resolver == null;
- boolean inIceBox = adapter.inIceBox();
-
- _oldName = descriptor.name;
-
- _name.setText(Utils.substitute(descriptor.name, resolver));
- _name.setEditable(isEditable && !inIceBox);
-
- _description.setText(
- Utils.substitute(descriptor.description, resolver));
- _description.setEditable(isEditable);
- _description.setOpaque(isEditable);
-
- //
- // Need to make control editable & enabled before changing it
- //
- _id.setEnabled(true);
- _id.setEditable(true);
- _defaultAdapterId = adapter.getDefaultAdapterId();
- refreshId();
- if(descriptor.id == null)
- {
- descriptor.id = _defaultAdapterId;
- }
-
- setId(Utils.substitute(descriptor.id, resolver));
- _id.setEnabled(isEditable);
- _id.setEditable(isEditable);
-
- _replicaGroupId.setEnabled(true);
- _replicaGroupId.setEditable(true);
-
- final ReplicaGroups replicaGroups =
- adapter.getApplication().getReplicaGroups();
- _replicaGroupId.setModel(replicaGroups.createComboBoxModel(NOT_REPLICATED));
-
- _replicaGroupId.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent e)
- {
- if(e.getStateChange() == ItemEvent.SELECTED)
- {
- Object item = e.getItem();
- boolean enabled = (item instanceof ReplicaGroup);
- if(!enabled && item != NOT_REPLICATED)
- {
- if(resolver != null)
- {
- String replicaGroupId =
- resolver.substitute(item.toString());
- enabled = (replicaGroups.findChild(replicaGroupId) != null);
- }
- }
- _replicaGroupButton.setEnabled(enabled);
- }
- }
- });
-
- setReplicaGroupId(Utils.substitute(descriptor.replicaGroupId, resolver));
- _replicaGroupId.setEnabled(isEditable);
- _replicaGroupId.setEditable(isEditable);
-
- _endpoints.setText(
- Utils.substitute(adapter.getProperty("Endpoints"), resolver));
- _endpoints.setEditable(isEditable);
-
- _publishedEndpoints.setEnabled(true);
- _publishedEndpoints.setEditable(true);
- String published =
- Utils.substitute(adapter.getProperty("PublishedEndpoints"), resolver);
- if(published == null || published.equals(""))
- {
- _publishedEndpoints.setSelectedItem(PUBLISH_ACTUAL);
- }
- else
- {
- _publishedEndpoints.setSelectedItem(published);
- }
- _publishedEndpoints.setEnabled(isEditable);
- _publishedEndpoints.setEditable(isEditable);
-
- //
- // Objects
- //
- _objectsMap = objectDescriptorSeqToMap(descriptor.objects);
- setObjectsField();
- _objectsButton.setEnabled(isEditable);
-
- _registerProcess.setSelected(descriptor.registerProcess);
- _registerProcess.setEnabled(isEditable);
-
- _waitForActivation.setSelected(descriptor.waitForActivation);
- _waitForActivation.setEnabled(isEditable);
-
- refreshCurrentStatus();
-
- _applyButton.setEnabled(adapter.isEphemeral());
- _discardButton.setEnabled(adapter.isEphemeral());
- detectUpdates(true);
- }
-
- public void refreshCurrentStatus()
- {
- Adapter adapter = getAdapter();
-
- //
- // Only when not in a template
- //
- if(adapter.getResolver() != null)
- {
- String currentEndpoints = adapter.getCurrentEndpoints();
- boolean active = (currentEndpoints != null);
-
- if(currentEndpoints == null)
- {
- _currentStatus.setText("Inactive");
- _currentEndpoints.setText("");
- }
- else
- {
- _currentStatus.setText("Active");
- _currentEndpoints.setText(currentEndpoints);
- }
- }
- }
-
- Adapter getAdapter()
- {
- return (Adapter)_target;
- }
-
- static java.util.Map objectDescriptorSeqToMap(java.util.List objects)
- {
- java.util.Map result = new java.util.HashMap(objects.size());
- java.util.Iterator p = objects.iterator();
- while(p.hasNext())
- {
- ObjectDescriptor od = (ObjectDescriptor)p.next();
- result.put(Ice.Util.identityToString(od.id), od.type);
- }
- return result;
- }
-
- static java.util.LinkedList mapToObjectDescriptorSeq(java.util.Map map)
- {
- java.util.LinkedList result = new java.util.LinkedList();
- java.util.Iterator p = map.entrySet().iterator();
- while(p.hasNext())
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- Ice.Identity id =
- Ice.Util.stringToIdentity((String)entry.getKey());
- String type = (String)entry.getValue();
- result.add(new ObjectDescriptor(id, type));
- }
- return result;
- }
-
- private String _defaultAdapterId = "";
-
- private final Object DEFAULT_ADAPTER_ID = new Object()
- {
- public String toString()
- {
- return _defaultAdapterId;
- }
- };
-
- private String _oldName;
-
- private JTextField _name = new JTextField(20);
- private JTextArea _description = new JTextArea(3, 20);
-
- private JComboBox _id = new JComboBox(new Object[]
- {DIRECT_ADAPTER, DEFAULT_ADAPTER_ID});
- private JComboBox _replicaGroupId = new JComboBox();
- private JButton _replicaGroupButton;
-
- private JTextField _endpoints = new JTextField(20);
- private JComboBox _publishedEndpoints = new JComboBox(
- new Object[]{PUBLISH_ACTUAL});
-
- private JTextField _currentStatus = new JTextField(20);
- private JTextField _currentEndpoints = new JTextField(20);
-
- private JCheckBox _registerProcess;
- private JCheckBox _waitForActivation;
-
- private JTextField _objects = new JTextField(20);
- private java.util.Map _objectsMap;
- private TableDialog _objectsDialog;
- private JButton _objectsButton;
-
- static private final Object PUBLISH_ACTUAL = new Object()
- {
- public String toString()
- {
- return "Actual endpoints";
- }
- };
-
- static private final Object DIRECT_ADAPTER = new Object()
- {
- public String toString()
- {
- return "No ID (a direct adapter)";
- }
- };
-
- static private final Object NOT_REPLICATED = new Object()
- {
- public String toString()
- {
- return "Does not belong to a replica group";
- }
- };
-}
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class AdapterEditor extends CommunicatorChildEditor
+{
+ AdapterEditor(JFrame parentFrame)
+ {
+ _objects.setEditable(false);
+
+ //
+ // Create buttons
+ //
+
+ //
+ // _replicaGroupButton
+ //
+ Action gotoReplicaGroup = new AbstractAction(
+ "", Utils.getIcon("/icons/16x16/goto.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Object obj = _replicaGroupId.getSelectedItem();
+ Adapter adapter = getAdapter();
+
+ ReplicaGroup rg = null;
+ if(obj instanceof ReplicaGroup)
+ {
+ rg = (ReplicaGroup)obj;
+ }
+ else
+ {
+ String replicaGroupId =
+ adapter.getResolver().substitute(obj.toString());
+
+ rg = adapter.getRoot().findReplicaGroup(replicaGroupId);
+ }
+
+ //
+ // The button is enabled therefore rg should be != null
+ //
+ if(rg != null)
+ {
+ adapter.getRoot().setSelectedNode(rg);
+ }
+ }
+ };
+ gotoReplicaGroup.putValue(Action.SHORT_DESCRIPTION,
+ "Goto the definition of this replica group");
+ _replicaGroupButton = new JButton(gotoReplicaGroup);
+
+ //
+ // _objectsButton
+ //
+ _objectsDialog = new TableDialog(parentFrame,
+ "Registered Objects",
+ "Object Identity",
+ "Type", true);
+
+ Action openObjectsDialog = new AbstractAction("...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ java.util.Map result = _objectsDialog.show(_objectsMap,
+ getProperties());
+ if(result != null)
+ {
+ updated();
+ _objectsMap = result;
+ setObjectsField();
+ }
+ }
+ };
+ openObjectsDialog.putValue(Action.SHORT_DESCRIPTION,
+ "Edit registered objects");
+ _objectsButton = new JButton(openObjectsDialog);
+
+
+ Action checkRegisterProcess = new AbstractAction("Register Process")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ updated();
+ }
+ };
+ _registerProcess = new JCheckBox(checkRegisterProcess);
+ _registerProcess.setToolTipText(
+ "<html>During activation, create a Process object<br>"
+ + "in this adapter and register it with IceGrid<br>"
+ + "to enable clean shutdown; you should register<br>"
+ + "exactly one Process object per server.</html>");
+
+ Action checkWaitForActivation =
+ new AbstractAction("Wait for Activation")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ updated();
+ }
+ };
+ _waitForActivation = new JCheckBox(checkWaitForActivation);
+ _waitForActivation.setToolTipText(
+ "<html>When starting the enclosing server, "
+ + "does IceGrid<br>wait for this adapter to become active?</html>");
+ //
+ // Associate updateListener with various fields
+ //
+ _name.getDocument().addDocumentListener(
+ new DocumentListener()
+ {
+ public void changedUpdate(DocumentEvent e)
+ {
+ update();
+ }
+
+ public void insertUpdate(DocumentEvent e)
+ {
+ update();
+ }
+
+ public void removeUpdate(DocumentEvent e)
+ {
+ update();
+ }
+
+ private void update()
+ {
+ updated();
+ //
+ // Recompute default id
+ //
+ _defaultAdapterId = getAdapter().getDefaultAdapterId(_name.getText());
+ refreshId();
+ }
+ });
+
+ _name.setToolTipText(
+ "Identifies this object adapter within an Ice communicator");
+
+ _endpoints.getDocument().addDocumentListener(_updateListener);
+ _endpoints.setToolTipText(
+ "<html>The network interfaces on which this adapter receives requests;<br>"
+ + "for example:<br>"
+ + " tcp (listen on all local interfaces using a random port)<br>"
+ + " tcp -h venus.foo.com (listen on just one interface)<br>"
+ + " tcp -t 10000 (sets a timeout of 10,000 milliseconds)<br>"
+ + " ssl -h venus.foo.com (accepts SSL connections instead of plain TCP)"
+ + "</html>");
+
+ _description.getDocument().addDocumentListener(_updateListener);
+ _description.setToolTipText(
+ "An optional description for this object adapter");
+
+ JTextField idTextField = (JTextField)
+ _id.getEditor().getEditorComponent();
+ idTextField.getDocument().addDocumentListener(_updateListener);
+ _id.setToolTipText("If set, must be unique within this IceGrid deployment");
+
+ JTextField replicaGroupIdTextField = (JTextField)
+ _replicaGroupId.getEditor().getEditorComponent();
+ replicaGroupIdTextField.getDocument().addDocumentListener(_updateListener);
+ _replicaGroupId.setToolTipText("Select a replica group");
+
+ JTextField publishedEndpointsTextField = (JTextField)
+ _publishedEndpoints.getEditor().getEditorComponent();
+ publishedEndpointsTextField.getDocument().addDocumentListener(_updateListener);
+ _publishedEndpoints.setToolTipText(
+ "<html>Direct adapter: endpoints included in proxies created using this adapter.<br>"
+ + "Indirect adapter: endpoints registered with the IceGrid Registry during the activation of this adapter."
+ + "</html>");
+ }
+
+
+ //
+ // From CommunicatorChildEditor
+ //
+
+ void writeDescriptor()
+ {
+ AdapterDescriptor descriptor =
+ (AdapterDescriptor)getAdapter().getDescriptor();
+ descriptor.name = _name.getText();
+ descriptor.description = _description.getText();
+ descriptor.id = getIdAsString();
+ descriptor.replicaGroupId = getReplicaGroupIdAsString();
+ descriptor.registerProcess = _registerProcess.isSelected();
+ descriptor.waitForActivation = _waitForActivation.isSelected();
+ descriptor.objects = mapToObjectDescriptorSeq(_objectsMap);
+ }
+
+ boolean isSimpleUpdate()
+ {
+ AdapterDescriptor descriptor =
+ (AdapterDescriptor)getAdapter().getDescriptor();
+
+ return descriptor.name.equals(_name.getText());
+ }
+
+ Communicator.ChildList getChildList()
+ {
+ return ((Communicator)_target.getParent()).getAdapters();
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Adapter Name" );
+ builder.append(_name, 3);
+ builder.nextLine();
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("Adapter ID");
+ builder.append(_id, 3);
+ builder.nextLine();
+
+ builder.append("Replica Group", _replicaGroupId);
+ builder.append(_replicaGroupButton);
+ builder.nextLine();
+
+ builder.append("Registered Objects");
+ builder.append(_objects, _objectsButton);
+ builder.nextLine();
+
+ builder.append("", _registerProcess);
+ builder.nextLine();
+ builder.append("", _waitForActivation);
+ builder.nextLine();
+
+ builder.append("Endpoints" );
+ builder.append(_endpoints, 3);
+ builder.nextLine();
+
+ builder.append("Published Endpoints" );
+ builder.append(_publishedEndpoints, 3);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Adapter Properties");
+ }
+
+
+ void postUpdate()
+ {
+ //
+ // Change enclosing properties after successful update
+ //
+ String name = _name.getText();
+ Adapter adapter = getAdapter();
+ if(!name.equals(_oldName))
+ {
+ adapter.removeProperty(_oldName, "Endpoints");
+ adapter.removeProperty(_oldName, "PublishedEndpoints");
+ _oldName = name;
+ }
+
+ adapter.setProperty(name, "Endpoints", _endpoints.getText());
+
+ Object published = _publishedEndpoints.getSelectedItem();
+ if(published == PUBLISH_ACTUAL)
+ {
+ adapter.removeProperty(name, "PublishedEndpoints");
+ }
+ else
+ {
+ adapter.setProperty(name, "PublishedEndpoints",
+ published.toString());
+
+ }
+ }
+
+ private void setObjectsField()
+ {
+ Adapter adapter = getAdapter();
+
+ final Utils.Resolver resolver = adapter.getCoordinator().substitute() ?
+ adapter.getResolver() : null;
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)obj;
+
+ return Utils.substitute((String)entry.getKey(), resolver)
+ + " as '"
+ + Utils.substitute((String)entry.getValue(), resolver)
+ + "'";
+ }
+ };
+
+ _objects.setText(
+ Utils.stringify(_objectsMap.entrySet(), stringifier,
+ ", ", toolTipHolder));
+
+ _objects.setToolTipText(toolTipHolder.value);
+ }
+
+ private void setId(String id)
+ {
+ if(id.equals(""))
+ {
+ _id.setSelectedItem(DIRECT_ADAPTER);
+ }
+ else if(id.equals(_defaultAdapterId))
+ {
+ _id.setSelectedItem(DEFAULT_ADAPTER_ID);
+ }
+ else
+ {
+ _id.setSelectedItem(id);
+ }
+ }
+
+ private void refreshId()
+ {
+ Object id = _id.getSelectedItem();
+ _id.setModel(new DefaultComboBoxModel(new Object[]
+ {DIRECT_ADAPTER, DEFAULT_ADAPTER_ID}));
+ _id.setSelectedItem(id);
+ }
+
+ private String getIdAsString()
+ {
+ Object obj = _id.getSelectedItem();
+ if(obj == DIRECT_ADAPTER)
+ {
+ return "";
+ }
+ else
+ {
+ return obj.toString();
+ }
+ }
+
+ private void setReplicaGroupId(String replicaGroupId)
+ {
+ if(replicaGroupId.equals(""))
+ {
+ _replicaGroupId.setSelectedItem(NOT_REPLICATED);
+ }
+ else
+ {
+ ReplicaGroups replicaGroups =
+ getAdapter().getRoot().getReplicaGroups();
+
+ ReplicaGroup replicaGroup =
+ (ReplicaGroup)replicaGroups.findChild(replicaGroupId);
+
+ if(replicaGroup != null)
+ {
+ _replicaGroupId.setSelectedItem(replicaGroup);
+ }
+ else
+ {
+ _replicaGroupId.setSelectedItem(replicaGroupId);
+ }
+ }
+ }
+
+ private String getReplicaGroupIdAsString()
+ {
+ Object obj = _replicaGroupId.getSelectedItem();
+ if(obj == NOT_REPLICATED)
+ {
+ return "";
+ }
+ else
+ {
+ return obj.toString();
+ }
+ }
+
+ void show(Adapter adapter)
+ {
+ detectUpdates(false);
+ _target = adapter;
+
+ AdapterDescriptor descriptor = (AdapterDescriptor)adapter.getDescriptor();
+
+ final Utils.Resolver resolver = adapter.getCoordinator().substitute() ?
+ adapter.getResolver() : null;
+
+ boolean isEditable = adapter.isEditable() && resolver == null;
+ boolean inIceBox = adapter.inIceBox();
+
+ _oldName = descriptor.name;
+
+ _name.setText(Utils.substitute(descriptor.name, resolver));
+ _name.setEditable(isEditable && !inIceBox);
+
+ _description.setText(
+ Utils.substitute(descriptor.description, resolver));
+ _description.setEditable(isEditable);
+ _description.setOpaque(isEditable);
+
+ //
+ // Need to make control editable & enabled before changing it
+ //
+ _id.setEnabled(true);
+ _id.setEditable(true);
+ _defaultAdapterId = adapter.getDefaultAdapterId();
+ refreshId();
+ if(descriptor.id == null)
+ {
+ descriptor.id = _defaultAdapterId;
+ }
+
+ setId(Utils.substitute(descriptor.id, resolver));
+ _id.setEnabled(isEditable);
+ _id.setEditable(isEditable);
+
+ _replicaGroupId.setEnabled(true);
+ _replicaGroupId.setEditable(true);
+
+ final ReplicaGroups replicaGroups =
+ adapter.getRoot().getReplicaGroups();
+ _replicaGroupId.setModel(replicaGroups.createComboBoxModel(NOT_REPLICATED));
+
+ _replicaGroupId.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent e)
+ {
+ if(e.getStateChange() == ItemEvent.SELECTED)
+ {
+ Object item = e.getItem();
+ boolean enabled = (item instanceof ReplicaGroup);
+ if(!enabled && item != NOT_REPLICATED)
+ {
+ if(resolver != null)
+ {
+ String replicaGroupId =
+ resolver.substitute(item.toString());
+ enabled = (replicaGroups.findChild(replicaGroupId) != null);
+ }
+ }
+ _replicaGroupButton.setEnabled(enabled);
+ }
+ }
+ });
+
+ setReplicaGroupId(Utils.substitute(descriptor.replicaGroupId, resolver));
+ _replicaGroupId.setEnabled(isEditable);
+ _replicaGroupId.setEditable(isEditable);
+
+ _endpoints.setText(
+ Utils.substitute(adapter.getProperty("Endpoints"), resolver));
+ _endpoints.setEditable(isEditable);
+
+ _publishedEndpoints.setEnabled(true);
+ _publishedEndpoints.setEditable(true);
+ String published =
+ Utils.substitute(adapter.getProperty("PublishedEndpoints"), resolver);
+ if(published == null || published.equals(""))
+ {
+ _publishedEndpoints.setSelectedItem(PUBLISH_ACTUAL);
+ }
+ else
+ {
+ _publishedEndpoints.setSelectedItem(published);
+ }
+ _publishedEndpoints.setEnabled(isEditable);
+ _publishedEndpoints.setEditable(isEditable);
+
+ //
+ // Objects
+ //
+ _objectsMap = objectDescriptorSeqToMap(descriptor.objects);
+ setObjectsField();
+ _objectsButton.setEnabled(isEditable);
+
+ _registerProcess.setSelected(descriptor.registerProcess);
+ _registerProcess.setEnabled(isEditable);
+
+ _waitForActivation.setSelected(descriptor.waitForActivation);
+ _waitForActivation.setEnabled(isEditable);
+
+ _applyButton.setEnabled(adapter.isEphemeral());
+ _discardButton.setEnabled(adapter.isEphemeral());
+ detectUpdates(true);
+ }
+
+ Adapter getAdapter()
+ {
+ return (Adapter)_target;
+ }
+
+ static java.util.Map objectDescriptorSeqToMap(java.util.List objects)
+ {
+ java.util.Map result = new java.util.HashMap(objects.size());
+ java.util.Iterator p = objects.iterator();
+ while(p.hasNext())
+ {
+ ObjectDescriptor od = (ObjectDescriptor)p.next();
+ result.put(Ice.Util.identityToString(od.id), od.type);
+ }
+ return result;
+ }
+
+ static java.util.LinkedList mapToObjectDescriptorSeq(java.util.Map map)
+ {
+ java.util.LinkedList result = new java.util.LinkedList();
+ java.util.Iterator p = map.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ Ice.Identity id =
+ Ice.Util.stringToIdentity((String)entry.getKey());
+ String type = (String)entry.getValue();
+ result.add(new ObjectDescriptor(id, type));
+ }
+ return result;
+ }
+
+ private String _defaultAdapterId = "";
+
+ private final Object DEFAULT_ADAPTER_ID = new Object()
+ {
+ public String toString()
+ {
+ return _defaultAdapterId;
+ }
+ };
+
+ private String _oldName;
+
+ private JTextField _name = new JTextField(20);
+ private JTextArea _description = new JTextArea(3, 20);
+
+ private JComboBox _id = new JComboBox(new Object[]
+ {DIRECT_ADAPTER, DEFAULT_ADAPTER_ID});
+ private JComboBox _replicaGroupId = new JComboBox();
+ private JButton _replicaGroupButton;
+
+ private JTextField _endpoints = new JTextField(20);
+ private JComboBox _publishedEndpoints = new JComboBox(
+ new Object[]{PUBLISH_ACTUAL});
+
+ private JTextField _currentStatus = new JTextField(20);
+ private JTextField _currentEndpoints = new JTextField(20);
+
+ private JCheckBox _registerProcess;
+ private JCheckBox _waitForActivation;
+
+ private JTextField _objects = new JTextField(20);
+ private java.util.Map _objectsMap;
+ private TableDialog _objectsDialog;
+ private JButton _objectsButton;
+
+ static private final Object PUBLISH_ACTUAL = new Object()
+ {
+ public String toString()
+ {
+ return "Actual endpoints";
+ }
+ };
+
+ static private final Object DIRECT_ADAPTER = new Object()
+ {
+ public String toString()
+ {
+ return "No ID (a direct adapter)";
+ }
+ };
+
+ static private final Object NOT_REPLICATED = new Object()
+ {
+ public String toString()
+ {
+ return "Does not belong to a replica group";
+ }
+ };
+}
diff --git a/java/src/IceGrid/TreeNode/ApplicationEditor.java b/java/src/IceGridGUI/Application/ApplicationEditor.java
index 26d70760711..94bc39bdaa4 100755
--- a/java/src/IceGrid/TreeNode/ApplicationEditor.java
+++ b/java/src/IceGridGUI/Application/ApplicationEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -24,126 +24,98 @@ import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.CellConstraints;
-import IceGrid.ApplicationDescriptor;
-import IceGrid.DistributionDescriptor;
-import IceGrid.ListDialog;
-import IceGrid.Model;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class ApplicationEditor extends Editor
{
protected void applyUpdate()
{
- Application application = (Application)_target;
- Model model = application.getModel();
+ Root root = (Root)_target;
+ MainPane mainPane = _target.getCoordinator().getMainPane();
- if(model.canUpdate())
- {
- model.disableDisplay();
-
- try
+ root.disableSelectionListener();
+ try
+ {
+ if(root.isEphemeral())
{
- if(application.isEphemeral())
+ writeDescriptor();
+ ApplicationDescriptor descriptor =
+ (ApplicationDescriptor)root.getDescriptor();
+ try
{
- Root root = (Root)application.getParent();
- writeDescriptor();
- ApplicationDescriptor descriptor =
- (ApplicationDescriptor)application.getDescriptor();
- application.destroy(); // just removes the child
- try
- {
- root.tryAdd(descriptor);
- }
- catch(UpdateFailedException e)
+ Root newRoot = new Root(root);
+ ApplicationPane app = mainPane.findApplication(root);
+ app.setRoot(newRoot);
+ newRoot.setSelectedNode(newRoot);
+ app.showNode(newRoot);
+
+ _target = newRoot;
+ if(!root.getId().equals(newRoot.getId()))
{
- //
- // Add back ephemeral child
- //
- try
- {
- root.addChild(application, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- model.setSelectionPath(application.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- _target = root.findChildWithDescriptor(descriptor);
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
+ mainPane.resetTitle(newRoot);
+ }
}
- else if(isSimpleUpdate())
+ catch(UpdateFailedException e)
{
- writeDescriptor();
- application.markModified();
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
}
- else
- {
- //
- // Save to be able to rollback
- //
- Object savedDescriptor = application.saveDescriptor();
- writeDescriptor();
- try
- {
- application.rebuild();
- }
- catch(UpdateFailedException e)
- {
- application.restoreDescriptor(savedDescriptor);
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- //
- // Success
- //
- application.markModified();
- model.showActions(_target);
- }
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
}
- finally
+ else if(isSimpleUpdate())
{
- model.enableDisplay();
+ writeDescriptor();
+ root.updated();
+ root.getEditable().markModified();
}
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ ApplicationDescriptor savedDescriptor = root.saveDescriptor();
+ writeDescriptor();
+ try
+ {
+ root.rebuild();
+ }
+ catch(UpdateFailedException e)
+ {
+ root.restoreDescriptor(savedDescriptor);
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ //
+ // Success
+ //
+ root.updated();
+ root.getEditable().markModified();
+
+ if(!savedDescriptor.name.equals(root.getId()))
+ {
+ mainPane.resetTitle(root);
+ }
+ }
+
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
}
- }
-
- Utils.Resolver getDetailResolver()
- {
- Application application = (Application)_target;
- if(application.getModel().substitute())
- {
- return application.getResolver();
- }
- else
+ finally
{
- return null;
+ root.enableSelectionListener();
}
}
-
ApplicationEditor(JFrame parentFrame)
{
- super(false, true);
_name.getDocument().addDocumentListener(_updateListener);
_description.getDocument().addDocumentListener(_updateListener);
_variables.setEditable(false);
@@ -208,7 +180,7 @@ class ApplicationEditor extends Editor
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
builder.append("Name");
builder.append(_name, 3);
@@ -238,10 +210,16 @@ class ApplicationEditor extends Editor
builder.nextLine();
}
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Application Properties");
+ }
+
boolean isSimpleUpdate()
{
ApplicationDescriptor descriptor = (ApplicationDescriptor)_target.getDescriptor();
- return (_variablesMap.equals(descriptor.variables));
+ return descriptor.name.equals(_name.getText()) && _variablesMap.equals(descriptor.variables);
}
void writeDescriptor()
@@ -263,19 +241,19 @@ class ApplicationEditor extends Editor
}
- void show(Application application)
+ void show(Root root)
{
detectUpdates(false);
- setTarget(application);
+ _target = root;
Utils.Resolver resolver = getDetailResolver();
boolean isEditable = (resolver == null);
-
- _name.setText(application.getId());
- _name.setEditable(application.isEphemeral());
ApplicationDescriptor descriptor =
- (ApplicationDescriptor)application.getDescriptor();
+ (ApplicationDescriptor)root.getDescriptor();
+
+ _name.setText(descriptor.name);
+ _name.setEditable(root.isEphemeral() || !root.isLive());
_description.setText(
Utils.substitute(descriptor.description, resolver));
@@ -306,8 +284,8 @@ class ApplicationEditor extends Editor
setDistribDirsField();
_distribDirsButton.setEnabled(isEditable);
- _applyButton.setEnabled(application.isEphemeral());
- _discardButton.setEnabled(application.isEphemeral());
+ _applyButton.setEnabled(root.isEphemeral());
+ _discardButton.setEnabled(root.isEphemeral());
detectUpdates(true);
}
diff --git a/java/src/IceGridGUI/Application/Communicator.java b/java/src/IceGridGUI/Application/Communicator.java
new file mode 100755
index 00000000000..741cc63d487
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Communicator.java
@@ -0,0 +1,1036 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.util.Enumeration;
+
+import javax.swing.JOptionPane;
+import javax.swing.tree.DefaultTreeModel;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// The base class for Server, Service, ServerTemplate and ServiceTemplate
+//
+abstract class Communicator extends TreeNode implements DescriptorHolder
+{
+ public Enumeration children()
+ {
+ return new Enumeration()
+ {
+ public boolean hasMoreElements()
+ {
+ if(_p.hasNext())
+ {
+ return true;
+ }
+
+ while(++_index < _childListArray.length)
+ {
+ _p = _childListArray[_index].iterator();
+ if(_p.hasNext())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Object nextElement()
+ {
+ try
+ {
+ return _p.next();
+ }
+ catch(java.util.NoSuchElementException nse)
+ {
+ if(hasMoreElements())
+ {
+ return _p.next();
+ }
+ else
+ {
+ throw nse;
+ }
+ }
+ }
+
+ private int _index = 0;
+ private java.util.Iterator _p = _childListArray[0].iterator();
+ };
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return true;
+ }
+
+ public javax.swing.tree.TreeNode getChildAt(int childIndex)
+ {
+ if(childIndex < 0)
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ int offset = 0;
+ for(int i = 0; i < _childListArray.length; ++i)
+ {
+ if(childIndex < offset + _childListArray[i].size())
+ {
+ return _childListArray[i].get(childIndex - offset);
+ }
+ else
+ {
+ offset += _childListArray[i].size();
+ }
+ }
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+
+ public int getChildCount()
+ {
+ int result = 0;
+ for(int i = 0; i < _childListArray.length; ++i)
+ {
+ result += _childListArray[i].size();
+ }
+ return result;
+ }
+
+ public int getIndex(javax.swing.tree.TreeNode node)
+ {
+ int offset = 0;
+ for(int i = 0; i < _childListArray.length; ++i)
+ {
+ int index = _childListArray[i].indexOf(node);
+ if(index == -1)
+ {
+ offset += _childListArray[i].size();
+ }
+ else
+ {
+ return offset + index;
+ }
+ }
+ return -1;
+ }
+
+ public boolean isLeaf()
+ {
+ for(int i = 0; i < _childListArray.length; ++i)
+ {
+ if(!_childListArray[i].isEmpty())
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ //
+ // Actions
+ //
+
+ public void newAdapter()
+ {
+ _adapters.newChild();
+ }
+ public void newDbEnv()
+ {
+ _dbEnvs.newChild();
+ }
+ public void newService()
+ {
+ _services.newChild();
+ }
+ public void newServiceFromTemplate()
+ {
+ _services.newServiceFromTemplate();
+ }
+
+ public void paste()
+ {
+ Object descriptor = getCoordinator().getClipboard();
+
+ if(descriptor instanceof AdapterDescriptor)
+ {
+ AdapterDescriptor d = (AdapterDescriptor)descriptor;
+ _adapters.newAdapter(Adapter.copyDescriptor(d));
+ }
+ else if(descriptor instanceof DbEnvDescriptor)
+ {
+ DbEnvDescriptor d = (DbEnvDescriptor)descriptor;
+ _dbEnvs.newDbEnv(DbEnv.copyDescriptor(d));
+ }
+ else if(descriptor instanceof ServiceInstanceDescriptor && _services.initialized())
+ {
+ ServiceInstanceDescriptor d = (ServiceInstanceDescriptor)descriptor;
+ _services.newService(Service.copyDescriptor(d));
+ }
+ else
+ {
+ ((TreeNode)_parent).paste();
+ }
+ }
+
+ abstract CommunicatorDescriptor getCommunicatorDescriptor();
+ abstract Editable getEnclosingEditable();
+
+ //
+ // Returns all instances of 'this'. When 'this' is a template,
+ // includeTemplate determines whether the template itself is or is not
+ // included in the list. Otherwise, the list contain 'this' instance
+ // in any number of enclosing instances ... often simply 'this'.
+ //
+ abstract java.util.List findInstances(boolean includeTemplate);
+
+
+ TreeNode findChildLike(TreeNode other)
+ {
+ if(other instanceof Adapter)
+ {
+ return _adapters.findChildById(other.getId());
+ }
+ else if(other instanceof DbEnv)
+ {
+ return _dbEnvs.findChildById(other.getId());
+ }
+ else if(other instanceof Service)
+ {
+ return _dbEnvs.findChildById(other.getId());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ boolean isIceBox()
+ {
+ return false;
+ }
+
+ protected Communicator(TreeNode parent, String id)
+ {
+ super(parent, id);
+ }
+
+ abstract class ChildList
+ {
+ abstract TreeNode createChild(Object descriptor) throws UpdateFailedException;
+ abstract ChildList getMyChildList(Communicator communicator);
+ abstract void newChild();
+
+ protected ChildList(boolean sorted)
+ {
+ _sorted = sorted;
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ TreeNode child = (TreeNode)p.next();
+ child.write(writer);
+ }
+ }
+
+ //
+ // Some list-like methods
+ //
+ java.util.Iterator iterator()
+ {
+ return _children.iterator();
+ }
+
+ TreeNode get(int index)
+ {
+ return (TreeNode)_children.get(index);
+ }
+
+ int indexOf(Object obj)
+ {
+ return _children.indexOf(obj);
+ }
+
+ int size()
+ {
+ return _children.size();
+ }
+
+ boolean isEmpty()
+ {
+ return _children.isEmpty();
+ }
+
+ //
+ // Non-list methods
+ //
+
+ void init(java.util.List descriptors) throws UpdateFailedException
+ {
+ assert _descriptors == null;
+ assert _children.isEmpty();
+
+ _descriptors = descriptors;
+ java.util.Iterator p = _descriptors.iterator();
+
+ while(p.hasNext())
+ {
+ Object descriptor = p.next();
+ TreeNode child = createChild(descriptor);
+ addChild(child, false);
+ }
+ }
+
+ boolean initialized()
+ {
+ return _descriptors != null;
+ }
+
+ void clear()
+ {
+ _descriptors = null;
+ _children.clear();
+ }
+
+ TreeNode addNewChild(Object descriptor) throws UpdateFailedException
+ {
+ TreeNode child = createChild(descriptor);
+ addChild(child, true);
+
+ return child;
+ }
+
+ TreeNode findChildWithDescriptor(Object descriptor)
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ TreeNode child = (TreeNode)p.next();
+ if(child.getDescriptor() == descriptor)
+ {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ TreeNode findChildById(String id)
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ TreeNode child = (TreeNode)p.next();
+ if(child.getId().equals(id))
+ {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ void addChild(TreeNode child, boolean fireEvent) throws UpdateFailedException
+ {
+ if(_sorted)
+ {
+ DefaultTreeModel treeModel = fireEvent ?
+ getRoot().getTreeModel() : null;
+
+ if(!insertSortedChild(child, _children, treeModel))
+ {
+ throw new UpdateFailedException(Communicator.this, child.getId());
+ }
+ }
+ else
+ {
+ //
+ // Just add the child at the end of the list
+ //
+ _children.add(child);
+ if(fireEvent)
+ {
+ getRoot().getTreeModel().nodesWereInserted(Communicator.this, new int[]{getIndex(child)});
+ }
+ }
+ }
+
+ int removeChild(TreeNode child)
+ {
+ int index = getIndex(child);
+
+ _children.remove(child);
+
+ getRoot().getTreeModel().nodesWereRemoved(Communicator.this,
+ new int[]{index},
+ new Object[]{child});
+ return index;
+ }
+
+ void destroyChild(TreeNode child)
+ {
+ if(child.isEphemeral())
+ {
+ removeChild(child);
+ }
+ else
+ {
+ Object descriptor = child.getDescriptor();
+ removeDescriptor(descriptor);
+ getEnclosingEditable().markModified();
+
+ java.util.List list = findInstances(true);
+ java.util.Iterator p = list.iterator();
+ while(p.hasNext())
+ {
+ Communicator communicator = (Communicator)p.next();
+ ChildList container = getMyChildList(communicator);
+ container.removeChild(container.findChildWithDescriptor(descriptor));
+ }
+ }
+ }
+
+ void addDescriptor(Object descriptor)
+ {
+ _children.add(descriptor);
+ }
+
+ void removeDescriptor(Object descriptor)
+ {
+ //
+ // A straight remove uses equals(), which is not the desired behavior
+ //
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext())
+ {
+ if(descriptor == p.next())
+ {
+ p.remove();
+ break;
+ }
+ }
+ }
+
+ boolean canMove(TreeNode child, boolean up)
+ {
+ if(!isEditable())
+ {
+ return false;
+ }
+ else
+ {
+ int i = _children.indexOf(child);
+ assert i != -1;
+ return (up && i > 0) || (!up && i < _children.size() - 1);
+ }
+ }
+
+ void move(int listIndex, int index, boolean up)
+ {
+ Object child = _children.remove(listIndex);
+ assert child != null;
+
+ getRoot().getTreeModel().nodesWereRemoved(Communicator.this,
+ new int[]{index},
+ new Object[]{child});
+ if(up)
+ {
+ _children.add(listIndex - 1, child);
+ getRoot().getTreeModel().nodesWereInserted(Communicator.this,
+ new int[]{index - 1});
+
+ }
+ else
+ {
+ _children.add(listIndex + 1, child);
+ getRoot().getTreeModel().nodesWereInserted(Communicator.this,
+ new int[]{index + 1});
+
+ }
+ }
+
+ void tryAdd(Object descriptor) throws UpdateFailedException
+ {
+ addDescriptor(descriptor);
+
+ java.util.List newChildren = new java.util.LinkedList();
+ java.util.List list = findInstances(true);
+
+ java.util.Iterator p = list.iterator();
+ while(p.hasNext())
+ {
+ Communicator communicator = (Communicator)p.next();
+ ChildList container = getMyChildList(communicator);
+
+ try
+ {
+ newChildren.add(container.addNewChild(descriptor));
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Rollback
+ //
+ java.util.Iterator q = newChildren.iterator();
+ p = list.iterator();
+ while(q.hasNext())
+ {
+ communicator = (Communicator)p.next();
+ container = getMyChildList(communicator);
+ container.removeChild((TreeNode)q.next());
+ }
+ removeDescriptor(descriptor);
+ throw e;
+ }
+ }
+ getEnclosingEditable().markModified();
+ }
+
+ void tryUpdate(TreeNode child) throws UpdateFailedException
+ {
+ //
+ // Child is an Adapter or DbEnv
+ //
+ assert _sorted;
+
+ java.util.List list = findInstances(true);
+ Object descriptor = child.getDescriptor();
+
+ java.util.List children = new java.util.Vector();
+
+ java.util.Iterator p = list.iterator();
+ while(p.hasNext())
+ {
+ Communicator communicator = (Communicator)p.next();
+ ChildList container = getMyChildList(communicator);
+
+ try
+ {
+ child = container.findChildWithDescriptor(descriptor);
+ removeChild(child);
+ try
+ {
+ container.addNewChild(descriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ addChild(child, true);
+ throw e;
+ }
+ children.add(child);
+ }
+ catch(UpdateFailedException e)
+ {
+ for(int i = children.size() - 1; i >= 0; --i)
+ {
+ communicator = (Communicator)list.get(i);
+ container = getMyChildList(communicator);
+ child = (TreeNode)children.get(i);
+ TreeNode badChild = container.findChildWithDescriptor(descriptor);
+ container.removeChild(badChild);
+ try
+ {
+ container.addChild(child, true);
+ }
+ catch(UpdateFailedException ufe)
+ {
+ assert false; // impossible
+ }
+ }
+ throw e;
+ }
+ }
+ getEnclosingEditable().markModified();
+ }
+
+ protected String makeNewChildId(String base)
+ {
+ String id = base;
+ int i = 0;
+ while(findChildById(id) != null)
+ {
+ id = base + "-" + (++i);
+ }
+ return id;
+ }
+
+ protected java.util.List _children = new java.util.LinkedList();
+ protected java.util.List _descriptors;
+ protected boolean _sorted;
+ }
+
+ class Adapters extends ChildList
+ {
+ Adapters()
+ {
+ super(true);
+ }
+
+ void newChild()
+ {
+ AdapterDescriptor descriptor = new AdapterDescriptor(
+ "NewAdapter",
+ "",
+ null,
+ "",
+ false,
+ true,
+ new java.util.LinkedList());
+
+ newAdapter(descriptor);
+ }
+
+ TreeNode createChild(Object descriptor)
+ {
+ AdapterDescriptor ad = (AdapterDescriptor)descriptor;
+ String name = getResolver().substitute(ad.name);
+ return new Adapter(Communicator.this, name, ad, false);
+ }
+
+ ChildList getMyChildList(Communicator communicator)
+ {
+ return communicator.getAdapters();
+ }
+
+ private void newAdapter(AdapterDescriptor descriptor)
+ {
+ descriptor.name = makeNewChildId(descriptor.name);
+ Adapter adapter = new Adapter(Communicator.this, descriptor.name, descriptor, true);
+ try
+ {
+ addChild(adapter, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
+ getRoot().setSelectedNode(adapter);
+ }
+
+ }
+
+ class DbEnvs extends ChildList
+ {
+ DbEnvs()
+ {
+ super(true);
+ }
+
+ void newChild()
+ {
+ DbEnvDescriptor descriptor = new DbEnvDescriptor(
+ "NewDbEnv",
+ "",
+ "",
+ new java.util.LinkedList());
+
+ newDbEnv(descriptor);
+ }
+
+ TreeNode createChild(Object descriptor)
+ {
+ DbEnvDescriptor dd = (DbEnvDescriptor)descriptor;
+ String name = getResolver().substitute(dd.name);
+ return new DbEnv(Communicator.this, name, dd, false);
+ }
+
+ ChildList getMyChildList(Communicator communicator)
+ {
+ return communicator.getDbEnvs();
+ }
+
+ private void newDbEnv(DbEnvDescriptor descriptor)
+ {
+ descriptor.name = makeNewChildId(descriptor.name);
+ DbEnv dbEnv = new DbEnv(Communicator.this, descriptor.name, descriptor, true);
+ try
+ {
+ addChild(dbEnv, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
+ getRoot().setSelectedNode(dbEnv);
+ }
+
+ }
+
+ class Services extends ChildList
+ {
+ Services()
+ {
+ super(false);
+ }
+
+ void newChild()
+ {
+ ServiceDescriptor sd =
+ new ServiceDescriptor(new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ "",
+ "NewService",
+ "");
+
+ ServiceInstanceDescriptor descriptor =
+ new ServiceInstanceDescriptor("",
+ new java.util.TreeMap(),
+ sd);
+ newService(descriptor);
+ }
+
+ void newServiceFromTemplate()
+ {
+ ServiceInstanceDescriptor descriptor =
+ new ServiceInstanceDescriptor("",
+ new java.util.HashMap(),
+ null);
+ newService(descriptor);
+ }
+
+ void move(Service child, boolean up)
+ {
+ int index = getIndex(child);
+ int listIndex = _children.indexOf(child);
+
+ Object descriptor = child.getDescriptor();
+
+ getEnclosingEditable().markModified();
+
+ _descriptors.remove(listIndex);
+ if(up)
+ {
+ _descriptors.add(listIndex - 1, descriptor);
+ }
+ else
+ {
+ _descriptors.add(listIndex + 1, descriptor);
+ }
+
+ java.util.List servers = ((Communicator)_parent).findInstances(true);
+ java.util.Iterator p = servers.iterator();
+
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+
+ //
+ // The descriptors are the same as `this` descriptor
+ //
+ server.getServices().move(listIndex, index, up);
+ }
+
+ getCoordinator().showActions(child);
+ }
+
+ TreeNode createChild(Object o) throws UpdateFailedException
+ {
+ ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)o;
+ ServiceDescriptor serviceDescriptor = null;
+ String serviceName = null;
+ String displayString = null;
+ Utils.Resolver serviceResolver = null;
+
+ if(descriptor.template.length() > 0)
+ {
+ TemplateDescriptor templateDescriptor
+ = getRoot().findServiceTemplateDescriptor(descriptor.template);
+
+ assert templateDescriptor != null;
+
+ serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ if(Communicator.this instanceof Server)
+ {
+ serviceResolver = new Utils.Resolver(getResolver(),
+ descriptor.parameterValues,
+ templateDescriptor.parameterDefaults);
+ serviceName = serviceResolver.substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ displayString = serviceName + ": " + descriptor.template + "<>";
+ }
+ else
+ {
+ //
+ // serviceName = TemplateName<unsubstituted param 1, ....>
+ //
+ serviceName = templateLabel(descriptor.template,
+ templateDescriptor.parameters,
+ descriptor.parameterValues,
+ templateDescriptor.parameterDefaults);
+ }
+ }
+ else
+ {
+ serviceDescriptor = descriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ if(Communicator.this instanceof Server)
+ {
+ serviceResolver = new Utils.Resolver(getResolver());
+ serviceName = getResolver().substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ }
+ else
+ {
+ serviceName = serviceDescriptor.name;
+ }
+ }
+
+ return new Service(Communicator.this,
+ serviceName,
+ displayString,
+ descriptor,
+ serviceDescriptor,
+ serviceResolver);
+ }
+
+ void tryUpdate(TreeNode child) throws UpdateFailedException
+ {
+ //
+ // Rebuilding a Service if quite different since the creation of a service can
+ // trigger an UpdateFailedException
+ //
+ Object descriptor = child.getDescriptor();
+
+ java.util.List list = findInstances(true);
+ java.util.List children = new java.util.Vector();
+ int listIndex = _children.indexOf(child);
+ assert listIndex != -1;
+
+ java.util.Iterator p = list.iterator();
+ while(p.hasNext())
+ {
+ Communicator communicator = (Communicator)p.next();
+ ChildList container = getMyChildList(communicator);
+
+ try
+ {
+ TreeNode newChild = container.createChild(descriptor);
+ children.add(container._children.set(listIndex, newChild));
+ getRoot().getTreeModel().nodeChanged(newChild);
+ }
+ catch(UpdateFailedException e)
+ {
+ for(int i = children.size() - 1; i >= 0; --i)
+ {
+ communicator = (Communicator)list.get(i);
+ container = getMyChildList(communicator);
+ container._children.set(listIndex, children.get(i));
+ getRoot().getTreeModel().nodeChanged(child);
+ }
+ throw e;
+ }
+ }
+ getEnclosingEditable().markModified();
+ }
+
+ ChildList getMyChildList(Communicator communicator)
+ {
+ return communicator.getServices();
+ }
+
+ private void newService(ServiceInstanceDescriptor descriptor)
+ {
+ String baseName = descriptor.descriptor == null ? "NewService" :
+ descriptor.descriptor.name;
+ String name = makeNewChildId(baseName);
+
+ if(descriptor.descriptor != null)
+ {
+ descriptor.descriptor.name = name;
+ }
+ else
+ {
+ //
+ // Make sure descriptor.template points to a real template
+ //
+ ServiceTemplate t = getRoot().findServiceTemplate(descriptor.template);
+
+ if(t == null)
+ {
+ t = (ServiceTemplate)getRoot().getServiceTemplates().getChildAt(0);
+
+ if(t == null)
+ {
+ JOptionPane.showMessageDialog(
+ getCoordinator().getMainFrame(),
+ "You need to create a service template before you can create a service from a template.",
+ "No Service Template",
+ JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ else
+ {
+ descriptor.template = t.getId();
+ descriptor.parameterValues = new java.util.HashMap();
+ }
+ }
+
+ //
+ // Validate/update parameterValues
+ //
+ TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor();
+ descriptor.parameterValues = Editor.makeParameterValues(descriptor.parameterValues,
+ td.parameters);
+
+ }
+
+ Service service = new Service(Communicator.this, name, descriptor);
+ try
+ {
+ addChild(service, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
+ getRoot().setSelectedNode(service);
+ }
+ }
+
+ Adapters getAdapters()
+ {
+ return _adapters;
+ }
+
+ DbEnvs getDbEnvs()
+ {
+ return _dbEnvs;
+ }
+
+ Services getServices()
+ {
+ return _services;
+ }
+
+ java.util.List findServiceInstances(String template)
+ {
+ java.util.List result = new java.util.LinkedList();
+ java.util.Iterator p = _services.iterator();
+ while(p.hasNext())
+ {
+ Service service = (Service)p.next();
+ ServiceInstanceDescriptor d =
+ (ServiceInstanceDescriptor)service.getDescriptor();
+ if(d.template.equals(template))
+ {
+ result.add(service);
+ }
+ }
+ return result;
+ }
+
+ void removeServiceInstances(String template)
+ {
+ java.util.Iterator p = _services.iterator();
+ while(p.hasNext())
+ {
+ Service service = (Service)p.next();
+ ServiceInstanceDescriptor d =
+ (ServiceInstanceDescriptor)service.getDescriptor();
+ if(d.template.equals(template))
+ {
+ _services.removeChild(service);
+ _services.removeDescriptor(d);
+ getEnclosingEditable().markModified();
+ }
+ }
+ }
+
+ void removeSortedChildren(String[] childIds, java.util.List fromChildren)
+ {
+ removeSortedChildren(childIds, fromChildren, getRoot().getTreeModel());
+ }
+ void childrenChanged(java.util.List children)
+ {
+ childrenChanged(children, getRoot().getTreeModel());
+ }
+
+ String getProperty(String key)
+ {
+ CommunicatorDescriptor descriptor = getCommunicatorDescriptor();
+ java.util.Iterator p = descriptor.properties.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ if(pd.name.equals(key))
+ {
+ return pd.value;
+ }
+ }
+ return null;
+ }
+
+ void setProperty(String key, String newValue)
+ {
+ CommunicatorDescriptor descriptor = getCommunicatorDescriptor();
+ removeProperty(key);
+ descriptor.properties.add(new PropertyDescriptor(key, newValue));
+ }
+
+ void removeProperty(String key)
+ {
+ CommunicatorDescriptor descriptor = getCommunicatorDescriptor();
+ java.util.Iterator p = descriptor.properties.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ if(pd.name.equals(key))
+ {
+ p.remove();
+ }
+ }
+ }
+
+ static String templateLabel(String templateName,
+ java.util.List parameters,
+ final java.util.Map parameterValues,
+ final java.util.Map parameterDefaults)
+ {
+ String result = templateName + "<";
+
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ String name = (String)obj;
+ String val = (String)parameterValues.get(name);
+ if(val == null)
+ {
+ val = (String)parameterDefaults.get(name);
+ }
+ if(val != null)
+ {
+ return val;
+ }
+ else
+ {
+ return "";
+ }
+ }
+ };
+
+ result += Utils.stringify(parameters, stringifier, ", ", null);
+ result += ">";
+ return result;
+ }
+
+
+ //
+ // Children
+ //
+ protected Adapters _adapters = new Adapters();
+ protected DbEnvs _dbEnvs = new DbEnvs();
+ protected Services _services = new Services();
+ protected ChildList[] _childListArray = new ChildList[]{_adapters, _dbEnvs, _services};
+}
diff --git a/java/src/IceGridGUI/Application/CommunicatorChildEditor.java b/java/src/IceGridGUI/Application/CommunicatorChildEditor.java
new file mode 100755
index 00000000000..48212b64936
--- /dev/null
+++ b/java/src/IceGridGUI/Application/CommunicatorChildEditor.java
@@ -0,0 +1,121 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import javax.swing.JOptionPane;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+abstract class CommunicatorChildEditor extends Editor
+{
+ abstract void writeDescriptor();
+ abstract boolean isSimpleUpdate();
+ abstract Communicator.ChildList getChildList();
+
+ void postUpdate() {}
+
+ protected void applyUpdate()
+ {
+ Root root = _target.getRoot();
+ root.disableSelectionListener();
+ try
+ {
+ if(_target.isEphemeral())
+ {
+ Communicator.ChildList childList = getChildList();
+
+ writeDescriptor();
+ Object descriptor = _target.getDescriptor();
+ _target.destroy(); // just removes the child
+
+ try
+ {
+ childList.tryAdd(descriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Restore ephemeral
+ //
+ try
+ {
+ childList.addChild(_target, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+
+ root.setSelectedNode(_target);
+ return;
+ }
+
+ //
+ // Success
+ //
+ _target = childList.findChildWithDescriptor(descriptor);
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+ else if(isSimpleUpdate())
+ {
+ writeDescriptor();
+ root.updated();
+ ((Communicator)_target.getParent()).getEnclosingEditable().markModified();
+ }
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ Object savedDescriptor = ((DescriptorHolder)_target).saveDescriptor();
+ Communicator.ChildList childList = getChildList();
+ writeDescriptor();
+ try
+ {
+ childList.tryUpdate(_target);
+ }
+ catch(UpdateFailedException e)
+ {
+ ((DescriptorHolder)_target).restoreDescriptor(savedDescriptor);
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ _target = childList.findChildWithDescriptor(_target.getDescriptor());
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+
+ postUpdate();
+
+ root.getCoordinator().getCurrentTab().showNode(_target);
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
+ }
+ finally
+ {
+ root.enableSelectionListener();
+ }
+ }
+}
diff --git a/java/src/IceGrid/TreeNode/CommunicatorSubEditor.java b/java/src/IceGridGUI/Application/CommunicatorSubEditor.java
index e5951bfc26c..74506ad0f16 100755
--- a/java/src/IceGrid/TreeNode/CommunicatorSubEditor.java
+++ b/java/src/IceGridGUI/Application/CommunicatorSubEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -22,10 +22,8 @@ import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.CellConstraints;
-import IceGrid.CommunicatorDescriptor;
-import IceGrid.Model;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class CommunicatorSubEditor
{
@@ -96,7 +94,7 @@ class CommunicatorSubEditor
Utils.Resolver detailResolver = _mainEditor.getDetailResolver();
isEditable = isEditable && (detailResolver == null);
- _propertiesMap = Editor.propertiesToMap(descriptor.properties);
+ _propertiesMap = Editor.propertiesToMap(descriptor.properties, detailResolver);
setPropertiesField();
_propertiesButton.setEnabled(isEditable);
diff --git a/java/src/IceGridGUI/Application/DbEnv.java b/java/src/IceGridGUI/Application/DbEnv.java
new file mode 100755
index 00000000000..bd72d1b639c
--- /dev/null
+++ b/java/src/IceGridGUI/Application/DbEnv.java
@@ -0,0 +1,198 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class DbEnv extends TreeNode implements DescriptorHolder
+{
+ static public DbEnvDescriptor copyDescriptor(DbEnvDescriptor d)
+ {
+ return (DbEnvDescriptor)d.clone();
+ }
+
+ static public java.util.LinkedList copyDescriptors(java.util.LinkedList list)
+ {
+ java.util.LinkedList copy = new java.util.LinkedList();
+ java.util.Iterator p = list.iterator();
+ while(p.hasNext())
+ {
+ copy.add(copyDescriptor((DbEnvDescriptor)p.next()));
+ }
+ return copy;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/database.png"));
+ }
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+ boolean[] parentActions = ((TreeNode)_parent).getAvailableActions();
+
+ actions[PASTE] = parentActions[PASTE];
+
+ if(isEditable())
+ {
+ actions[DELETE] = true;
+ }
+
+ if(!_ephemeral)
+ {
+ actions[SHOW_VARS] = parentActions[SHOW_VARS];
+ actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS];
+ }
+ return actions;
+ }
+
+ public void copy()
+ {
+ getCoordinator().setClipboard(copyDescriptor(_descriptor));
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+ }
+ public void paste()
+ {
+ ((TreeNode)_parent).paste();
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (DbEnvEditor)getRoot().getEditor(DbEnvEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new DbEnvEditor(getCoordinator().getMainFrame());
+ }
+
+ public Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ public Object copyDescriptor()
+ {
+ return copyDescriptor(_descriptor);
+ }
+
+ public Object saveDescriptor()
+ {
+ return copyDescriptor(_descriptor);
+ }
+
+ public void restoreDescriptor(Object savedDescriptor)
+ {
+ DbEnvDescriptor clone = (DbEnvDescriptor)savedDescriptor;
+ _descriptor.name = clone.name;
+ _descriptor.dbHome = clone.dbHome;
+ _descriptor.description = clone.description;
+ _descriptor.properties = clone.properties;
+ }
+
+ public void destroy()
+ {
+ ((Communicator)_parent).getDbEnvs().destroyChild(this);
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ DbEnv(Communicator parent, String dbEnvName, DbEnvDescriptor descriptor,
+ boolean ephemeral)
+ {
+ super(parent, dbEnvName);
+ _descriptor = descriptor;
+ _ephemeral = ephemeral;
+ }
+
+ static void writeDbProperties(XMLWriter writer,
+ java.util.List properties)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = properties.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", pd.name));
+ attributes.add(createAttribute("value", pd.value));
+ writer.writeElement("dbproperty", attributes);
+ }
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", _descriptor.name));
+ if(_descriptor.dbHome.length() > 0)
+ {
+ attributes.add(createAttribute("home", _descriptor.dbHome));
+ }
+
+ if(_descriptor.description.length() == 0 &&
+ _descriptor.properties.isEmpty())
+ {
+ writer.writeElement("dbenv", attributes);
+ }
+ else
+ {
+ writer.writeStartTag("dbenv", attributes);
+ if(_descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _descriptor.description);
+ }
+ writeDbProperties(writer, _descriptor.properties);
+ writer.writeEndTag("dbenv");
+ }
+ }
+ }
+
+ private DbEnvDescriptor _descriptor;
+ private final boolean _ephemeral;
+ private DbEnvEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+}
diff --git a/java/src/IceGrid/TreeNode/DbEnvEditor.java b/java/src/IceGridGUI/Application/DbEnvEditor.java
index 5545bea2b0f..fc3db163a09 100755
--- a/java/src/IceGrid/TreeNode/DbEnvEditor.java
+++ b/java/src/IceGridGUI/Application/DbEnvEditor.java
@@ -1,243 +1,250 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JFrame;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-
-import IceGrid.DbEnvDescriptor;
-import IceGrid.Model;
-import IceGrid.ObjectDescriptor;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
-
-class DbEnvEditor extends ListElementEditor
-{
- DbEnvEditor(JFrame parentFrame)
- {
- super(false);
- _name.getDocument().addDocumentListener(_updateListener);
- _name.setToolTipText(
- "Identifies this Freeze database environment within an Ice communicator");
- _description.getDocument().addDocumentListener(_updateListener);
- _description.setToolTipText(
- "An optional description for this database environment");
-
- JTextField dbHomeTextField = (JTextField)
- _dbHome.getEditor().getEditorComponent();
- dbHomeTextField.getDocument().addDocumentListener(_updateListener);
- _dbHome.setToolTipText("<html><i>node data dir</i>/servers/<i>server id</i>"
- + "/dbs/<i>db env name</i> if created by the IceGrid Node;<br>"
- + "otherwise, IceGrid does not create this directory"
- + "</html>");
-
-
- _properties.setEditable(false);
-
- //
- // _propertiesButton
- //
- _propertiesDialog = new TableDialog(parentFrame,
- "Berkeley DB Configuration Properties",
- "Name",
- "Value", true);
-
- Action openPropertiesDialog = new AbstractAction("...")
- {
- public void actionPerformed(ActionEvent e)
- {
- java.util.Map result =
- _propertiesDialog.show(_propertiesMap,
- getProperties());
- if(result != null)
- {
- updated();
- _propertiesMap = result;
- setPropertiesField();
- }
- }
- };
- openPropertiesDialog.putValue(Action.SHORT_DESCRIPTION,
- "Edit properties");
- _propertiesButton = new JButton(openPropertiesDialog);
- }
-
- void writeDescriptor()
- {
- DbEnvDescriptor descriptor =
- (DbEnvDescriptor)getDbEnv().getDescriptor();
- descriptor.name = _name.getText();
- descriptor.description = _description.getText();
- descriptor.dbHome = getDbHomeAsString();
- descriptor.properties = Editor.mapToProperties(_propertiesMap);
- }
-
- boolean isSimpleUpdate()
- {
- DbEnvDescriptor descriptor =
- (DbEnvDescriptor)getDbEnv().getDescriptor();
- return descriptor.name.equals(_name.getText());
- }
-
- void appendProperties(DefaultFormBuilder builder)
- {
- builder.append("Name" );
- builder.append(_name, 3);
- builder.nextLine();
-
- builder.append("Description");
- builder.nextLine();
- builder.append("");
- builder.nextRow(-2);
- CellConstraints cc = new CellConstraints();
- JScrollPane scrollPane = new JScrollPane(_description);
- builder.add(scrollPane,
- cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
- builder.nextRow(2);
- builder.nextLine();
-
- builder.append("DB Home" );
- builder.append(_dbHome, 3);
- builder.nextLine();
-
- builder.append("Properties");
- builder.append(_properties, _propertiesButton);
- builder.nextLine();
- }
-
- void show(DbEnv dbEnv)
- {
- detectUpdates(false);
- setTarget(dbEnv);
-
- DbEnvDescriptor descriptor = (DbEnvDescriptor)dbEnv.getDescriptor();
-
- Utils.Resolver resolver = null;
- if(dbEnv.getModel().substitute())
- {
- resolver = dbEnv.getResolver();
- }
- boolean isEditable = dbEnv.isEditable() && resolver == null;
-
- _name.setText(
- Utils.substitute(descriptor.name, resolver));
- _name.setEditable(isEditable);
-
- _description.setText(
- Utils.substitute(descriptor.description, resolver));
- _description.setEditable(isEditable);
- _description.setOpaque(isEditable);
-
- _dbHome.setEnabled(true);
- _dbHome.setEditable(true);
- setDbHome(Utils.substitute(descriptor.dbHome, resolver));
- _dbHome.setEnabled(isEditable);
- _dbHome.setEditable(isEditable);
-
- _propertiesMap = Editor.propertiesToMap(descriptor.properties);
- setPropertiesField();
- _propertiesButton.setEnabled(isEditable);
-
- _applyButton.setEnabled(dbEnv.isEphemeral());
- _discardButton.setEnabled(dbEnv.isEphemeral());
- detectUpdates(true);
- }
-
- private DbEnv getDbEnv()
- {
- return (DbEnv)_target;
- }
-
- private void setDbHome(String dbHome)
- {
- if(dbHome.equals(""))
- {
- _dbHome.setSelectedItem(NO_DB_HOME);
- }
- else
- {
- _dbHome.setSelectedItem(dbHome);
- }
- }
-
- private String getDbHomeAsString()
- {
- Object obj = _dbHome.getSelectedItem();
- if(obj == NO_DB_HOME)
- {
- return "";
- }
- else
- {
- return obj.toString();
- }
- }
-
-
- private void setPropertiesField()
- {
- final Utils.Resolver resolver = getDbEnv().getResolver();
-
- Ice.StringHolder toolTipHolder = new Ice.StringHolder();
- Utils.Stringifier stringifier = new Utils.Stringifier()
- {
- public String toString(Object obj)
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)obj;
-
- return Utils.substitute((String)entry.getKey(), resolver)
- + "="
- + Utils.substitute((String)entry.getValue(), resolver);
- }
- };
-
- _properties.setText(
- Utils.stringify(_propertiesMap.entrySet(), stringifier,
- ", ", toolTipHolder));
-
- String toolTip = "<html>Properties used to generate a"
- + " DB_CONFIG file in the DB home directory";
- if(toolTipHolder.value != null)
- {
- toolTip += ":<br>" + toolTipHolder.value;
- }
- toolTip += "</html>";
-
- _properties.setToolTipText(toolTip);
- }
-
- private JTextField _name = new JTextField(20);
- private JTextArea _description = new JTextArea(3, 20);
-
- private JComboBox _dbHome = new JComboBox(new Object[]{NO_DB_HOME});
-
- private JTextField _properties = new JTextField(20);
- private java.util.Map _propertiesMap;
- private TableDialog _propertiesDialog;
- private JButton _propertiesButton = new JButton("...");
-
- static private final Object NO_DB_HOME = new Object()
- {
- public String toString()
- {
- return "Created by the IceGrid Node";
- }
- };
-}
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class DbEnvEditor extends CommunicatorChildEditor
+{
+ DbEnvEditor(JFrame parentFrame)
+ {
+ _name.getDocument().addDocumentListener(_updateListener);
+ _name.setToolTipText(
+ "Identifies this Freeze database environment within an Ice communicator");
+ _description.getDocument().addDocumentListener(_updateListener);
+ _description.setToolTipText(
+ "An optional description for this database environment");
+
+ JTextField dbHomeTextField = (JTextField)
+ _dbHome.getEditor().getEditorComponent();
+ dbHomeTextField.getDocument().addDocumentListener(_updateListener);
+ _dbHome.setToolTipText("<html><i>node data dir</i>/servers/<i>server id</i>"
+ + "/dbs/<i>db env name</i> if created by the IceGrid Node;<br>"
+ + "otherwise, IceGrid does not create this directory"
+ + "</html>");
+
+
+ _properties.setEditable(false);
+
+ //
+ // _propertiesButton
+ //
+ _propertiesDialog = new TableDialog(parentFrame,
+ "Berkeley DB Configuration Properties",
+ "Name",
+ "Value", true);
+
+ Action openPropertiesDialog = new AbstractAction("...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ java.util.Map result =
+ _propertiesDialog.show(_propertiesMap,
+ getProperties());
+ if(result != null)
+ {
+ updated();
+ _propertiesMap = result;
+ setPropertiesField();
+ }
+ }
+ };
+ openPropertiesDialog.putValue(Action.SHORT_DESCRIPTION,
+ "Edit properties");
+ _propertiesButton = new JButton(openPropertiesDialog);
+ }
+
+ void writeDescriptor()
+ {
+ DbEnvDescriptor descriptor =
+ (DbEnvDescriptor)getDbEnv().getDescriptor();
+ descriptor.name = _name.getText();
+ descriptor.description = _description.getText();
+ descriptor.dbHome = getDbHomeAsString();
+ descriptor.properties = Editor.mapToProperties(_propertiesMap);
+ }
+
+ boolean isSimpleUpdate()
+ {
+ DbEnvDescriptor descriptor =
+ (DbEnvDescriptor)getDbEnv().getDescriptor();
+ return descriptor.name.equals(_name.getText());
+ }
+
+ Communicator.ChildList getChildList()
+ {
+ return ((Communicator)_target.getParent()).getDbEnvs();
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Name" );
+ builder.append(_name, 3);
+ builder.nextLine();
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("DB Home" );
+ builder.append(_dbHome, 3);
+ builder.nextLine();
+
+ builder.append("Properties");
+ builder.append(_properties, _propertiesButton);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Database Environment Properties");
+ }
+
+ void show(DbEnv dbEnv)
+ {
+ detectUpdates(false);
+ _target = dbEnv;
+
+ DbEnvDescriptor descriptor = (DbEnvDescriptor)dbEnv.getDescriptor();
+
+ Utils.Resolver resolver = null;
+ if(dbEnv.getCoordinator().substitute())
+ {
+ resolver = dbEnv.getResolver();
+ }
+ boolean isEditable = dbEnv.isEditable() && resolver == null;
+
+ _name.setText(
+ Utils.substitute(descriptor.name, resolver));
+ _name.setEditable(isEditable);
+
+ _description.setText(
+ Utils.substitute(descriptor.description, resolver));
+ _description.setEditable(isEditable);
+ _description.setOpaque(isEditable);
+
+ _dbHome.setEnabled(true);
+ _dbHome.setEditable(true);
+ setDbHome(Utils.substitute(descriptor.dbHome, resolver));
+ _dbHome.setEnabled(isEditable);
+ _dbHome.setEditable(isEditable);
+
+ _propertiesMap = Editor.propertiesToMap(descriptor.properties, resolver);
+ setPropertiesField();
+ _propertiesButton.setEnabled(isEditable);
+
+ _applyButton.setEnabled(dbEnv.isEphemeral());
+ _discardButton.setEnabled(dbEnv.isEphemeral());
+ detectUpdates(true);
+ }
+
+ private DbEnv getDbEnv()
+ {
+ return (DbEnv)_target;
+ }
+
+ private void setDbHome(String dbHome)
+ {
+ if(dbHome.equals(""))
+ {
+ _dbHome.setSelectedItem(NO_DB_HOME);
+ }
+ else
+ {
+ _dbHome.setSelectedItem(dbHome);
+ }
+ }
+
+ private String getDbHomeAsString()
+ {
+ Object obj = _dbHome.getSelectedItem();
+ if(obj == NO_DB_HOME)
+ {
+ return "";
+ }
+ else
+ {
+ return obj.toString();
+ }
+ }
+
+
+ private void setPropertiesField()
+ {
+ final Utils.Resolver resolver = getDbEnv().getResolver();
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)obj;
+
+ return Utils.substitute((String)entry.getKey(), resolver)
+ + "="
+ + Utils.substitute((String)entry.getValue(), resolver);
+ }
+ };
+
+ _properties.setText(
+ Utils.stringify(_propertiesMap.entrySet(), stringifier,
+ ", ", toolTipHolder));
+
+ String toolTip = "<html>Properties used to generate a"
+ + " DB_CONFIG file in the DB home directory";
+ if(toolTipHolder.value != null)
+ {
+ toolTip += ":<br>" + toolTipHolder.value;
+ }
+ toolTip += "</html>";
+
+ _properties.setToolTipText(toolTip);
+ }
+
+ private JTextField _name = new JTextField(20);
+ private JTextArea _description = new JTextArea(3, 20);
+
+ private JComboBox _dbHome = new JComboBox(new Object[]{NO_DB_HOME});
+
+ private JTextField _properties = new JTextField(20);
+ private java.util.Map _propertiesMap;
+ private TableDialog _propertiesDialog;
+ private JButton _propertiesButton = new JButton("...");
+
+ static private final Object NO_DB_HOME = new Object()
+ {
+ public String toString()
+ {
+ return "Created by the IceGrid Node";
+ }
+ };
+}
diff --git a/java/src/IceGrid/TreeNode/Editable.java b/java/src/IceGridGUI/Application/DescriptorHolder.java
index 9d727f8343c..0009fd5acde 100755
--- a/java/src/IceGrid/TreeNode/Editable.java
+++ b/java/src/IceGridGUI/Application/DescriptorHolder.java
@@ -1,22 +1,15 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.Model;
-
-
-interface Editable
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+interface DescriptorHolder
{
- boolean isNew();
- boolean isModified();
- void markModified();
- void commit();
+ Object saveDescriptor();
+ void restoreDescriptor(Object descriptor);
}
-
-
diff --git a/java/src/IceGridGUI/Application/Editable.java b/java/src/IceGridGUI/Application/Editable.java
new file mode 100755
index 00000000000..79254f75634
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Editable.java
@@ -0,0 +1,80 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+class Editable implements Cloneable
+{
+ Editable(boolean brandNew)
+ {
+ _isNew = brandNew;
+ }
+
+ boolean isNew()
+ {
+ return _isNew;
+ }
+
+ boolean isModified()
+ {
+ return _modified;
+ }
+
+ void markModified()
+ {
+ _modified = true;
+ }
+
+ void commit()
+ {
+ _isNew = false;
+ _modified = false;
+ _removedElements.clear();
+ }
+
+ void markNew()
+ {
+ _isNew = true;
+ }
+
+ void removeElement(String id)
+ {
+ _removedElements.add(id);
+ }
+
+ String[] removedElements()
+ {
+ return (String[])_removedElements.toArray(new String[0]);
+ }
+
+ Editable save()
+ {
+ try
+ {
+ Editable result = (Editable)clone();
+ result._removedElements = (java.util.TreeSet)result._removedElements.clone();
+ return result;
+ }
+ catch(CloneNotSupportedException e)
+ {
+ assert false;
+ return null;
+ }
+ }
+
+ void restore(Editable clone)
+ {
+ _isNew = clone._isNew;
+ _modified = clone._modified;
+ _removedElements = clone._removedElements;
+ }
+
+ private boolean _isNew = false;
+ private boolean _modified = false;
+ private java.util.TreeSet _removedElements = new java.util.TreeSet();
+}
diff --git a/java/src/IceGridGUI/Application/Editor.java b/java/src/IceGridGUI/Application/Editor.java
new file mode 100755
index 00000000000..0e4040eeab4
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Editor.java
@@ -0,0 +1,163 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JToolBar;
+
+import javax.swing.tree.TreePath;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.factories.Borders;
+import com.jgoodies.forms.factories.ButtonBarFactory;
+import com.jgoodies.forms.factories.DefaultComponentFactory;
+import com.jgoodies.forms.layout.FormLayout;
+import com.jgoodies.forms.util.LayoutStyle;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+public class Editor extends EditorBase
+{
+ protected void applyUpdate()
+ {
+ assert false;
+ }
+
+ protected void detectUpdates(boolean val)
+ {
+ _detectUpdates = val;
+ }
+
+ protected void discardUpdate()
+ {
+ if(_target.isEphemeral())
+ {
+ _target.delete();
+ }
+ else
+ {
+ _target.getCoordinator().getCurrentTab().showNode(_target);
+ }
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {}
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ JComponent buttonBar =
+ ButtonBarFactory.buildRightAlignedBar(_applyButton,
+ _discardButton);
+ buttonBar.setBorder(Borders.DIALOG_BORDER);
+ _propertiesPanel.add(buttonBar, BorderLayout.SOUTH);
+ }
+
+
+ Editor()
+ {
+ //
+ // _applyButton
+ //
+ AbstractAction apply = new AbstractAction("Apply")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ applyUpdate();
+ }
+ };
+ _applyButton = new JButton(apply);
+ _applyButton.setEnabled(false);
+
+ //
+ // _discardButton
+ //
+ AbstractAction discard = new AbstractAction("Discard")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ discardUpdate();
+ }
+ };
+ _discardButton = new JButton(discard);
+ _discardButton.setEnabled(false);
+
+ _updateListener = new DocumentListener()
+ {
+ public void changedUpdate(DocumentEvent e)
+ {
+ updated();
+ }
+
+ public void insertUpdate(DocumentEvent e)
+ {
+ updated();
+ }
+
+ public void removeUpdate(DocumentEvent e)
+ {
+ updated();
+ }
+ };
+ }
+
+ //
+ // Used by the sub-editor (when there is one)
+ //
+ Object getSubDescriptor()
+ {
+ return null;
+ }
+
+ Utils.Resolver getDetailResolver()
+ {
+ return null;
+ }
+
+ TreeNode getTarget()
+ {
+ return _target;
+ }
+
+ void updated()
+ {
+ if(_detectUpdates)
+ {
+ _target.getRoot().disableRegistryUpdates();
+ _applyButton.setEnabled(true);
+ _discardButton.setEnabled(true);
+ }
+ }
+
+ DocumentListener getUpdateListener()
+ {
+ return _updateListener;
+ }
+
+
+ protected JButton _applyButton;
+ protected JButton _discardButton;
+ protected DocumentListener _updateListener;
+
+ protected TreeNode _target;
+ private boolean _detectUpdates = true;
+}
diff --git a/java/src/IceGridGUI/Application/ListTreeNode.java b/java/src/IceGridGUI/Application/ListTreeNode.java
new file mode 100755
index 00000000000..7be67779ee1
--- /dev/null
+++ b/java/src/IceGridGUI/Application/ListTreeNode.java
@@ -0,0 +1,296 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import javax.swing.tree.DefaultTreeModel;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// An editable TreeNode that holds a list of children
+//
+abstract class ListTreeNode extends TreeNode
+{
+ public Enumeration children()
+ {
+ return new Enumeration()
+ {
+ public boolean hasMoreElements()
+ {
+ return _p.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ return _p.next();
+ }
+
+ private java.util.Iterator _p = _children.iterator();
+ };
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return true;
+ }
+
+ public javax.swing.tree.TreeNode getChildAt(int childIndex)
+ {
+ if(childIndex < 0)
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ else if(childIndex < _children.size())
+ {
+ return (javax.swing.tree.TreeNode)_children.get(childIndex);
+ }
+ else
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ }
+
+ public int getChildCount()
+ {
+ return _children.size();
+ }
+
+ public int getIndex(javax.swing.tree.TreeNode node)
+ {
+ return _children.indexOf(node);
+ }
+
+ public boolean isLeaf()
+ {
+ return _children.isEmpty();
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new Editor();
+ }
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ assert false;
+ return null;
+ }
+
+ protected ListTreeNode(boolean brandNew, TreeNode parent, String id)
+ {
+ super(parent, id);
+ _editable = new Editable(brandNew);
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ TreeNode node = (TreeNode)p.next();
+ node.write(writer);
+ }
+ }
+
+ void insertChild(TreeNode child, boolean fireEvent)
+ throws UpdateFailedException
+ {
+ DefaultTreeModel treeModel = fireEvent ?
+ getRoot().getTreeModel() : null;
+
+ if(!insertSortedChild(child, _children, treeModel))
+ {
+ throw new UpdateFailedException(this, child.getId());
+ }
+ }
+
+ void insertChildren(java.util.List newChildren, boolean fireEvent)
+ throws UpdateFailedException
+ {
+ TreeNodeBase[] children = (TreeNodeBase[])newChildren.toArray(new TreeNodeBase[0]);
+ java.util.Arrays.sort(children, _childComparator);
+
+ int[] indices = new int[children.length];
+
+ int i = 0;
+ boolean checkInsert = true;
+ for(int j = 0; j < children.length; ++j)
+ {
+ String id = children[j].getId();
+
+ if(checkInsert)
+ {
+ while(i < _children.size())
+ {
+ TreeNodeBase existingChild = (TreeNodeBase)_children.get(i);
+ int cmp = id.compareTo(existingChild.getId());
+ if(cmp == 0)
+ {
+ throw new UpdateFailedException(this, id);
+ }
+ if(cmp < 0)
+ {
+ break; // while
+ }
+ i++;
+ }
+
+ if(i < _children.size())
+ {
+ // Insert here, and increment i (since children is sorted)
+ _children.add(i, children[j]);
+ indices[j] = i;
+ i++;
+ continue; // for
+ }
+ else
+ {
+ checkInsert = false;
+ }
+ }
+
+ //
+ // Append
+ //
+ _children.add(children[j]);
+ indices[j] = i;
+ i++;
+ }
+
+ if(fireEvent)
+ {
+ getRoot().getTreeModel().nodesWereInserted(this, indices);
+ }
+ }
+
+ int removeChild(TreeNode child)
+ {
+ int index = getIndex(child);
+ _children.remove(child);
+
+ getRoot().getTreeModel().nodesWereRemoved(this,
+ new int[]{index},
+ new Object[]{child});
+ return index;
+ }
+
+ void removeChildren(String[] childIds)
+ {
+ removeSortedChildren(childIds, _children, getRoot().getTreeModel());
+ }
+
+ void childrenChanged(java.util.List children)
+ {
+ childrenChanged(children, getRoot().getTreeModel());
+ }
+
+ Editable getEditable()
+ {
+ return _editable;
+ }
+
+ protected String makeNewChildId(String base)
+ {
+ String id = base;
+ int i = 0;
+ while(findChild(id) != null)
+ {
+ id = base + "-" + (++i);
+ }
+ return id;
+ }
+
+
+ javax.swing.ComboBoxModel createComboBoxModel()
+ {
+ return new ComboBoxModel();
+ }
+
+ javax.swing.ComboBoxModel createComboBoxModel(Object item)
+ {
+ return new ComboBoxModel(item);
+ }
+
+ //
+ // Adapts ListTreeNode to a ComboBoxModel
+ //
+ class ComboBoxModel extends javax.swing.AbstractListModel
+ implements javax.swing.ComboBoxModel
+ {
+ public Object getElementAt(int index)
+ {
+ if(_firstItem != null)
+ {
+ if(index == 0)
+ {
+ return _firstItem;
+ }
+ else
+ {
+ return getChildAt(index - 1);
+ }
+ }
+ else
+ {
+ return getChildAt(index);
+ }
+ }
+
+ public int getSize()
+ {
+ if(_firstItem != null)
+ {
+ return getChildCount() + 1;
+ }
+ else
+ {
+ return getChildCount();
+ }
+ }
+
+ public Object getSelectedItem()
+ {
+ return _selectedItem;
+ }
+
+ public void setSelectedItem(Object obj)
+ {
+ if(obj != _selectedItem)
+ {
+ _selectedItem = obj;
+ fireContentsChanged(this, -1, -1);
+ }
+ }
+
+ ComboBoxModel(Object firstItem)
+ {
+ _firstItem = firstItem;
+ }
+
+ ComboBoxModel()
+ {
+ _firstItem = null;
+ }
+
+ private final Object _firstItem;
+ private Object _selectedItem;
+ }
+
+ protected final java.util.LinkedList _children = new java.util.LinkedList();
+ protected Editable _editable;
+
+ static private Editor _editor;
+}
diff --git a/java/src/IceGrid/TreeNode/Node.java b/java/src/IceGridGUI/Application/Node.java
index db8045af8a4..9af689a0279 100755
--- a/java/src/IceGrid/TreeNode/Node.java
+++ b/java/src/IceGridGUI/Application/Node.java
@@ -1,15 +1,14 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.Component;
-import java.awt.Cursor;
import javax.swing.Icon;
import javax.swing.JMenuItem;
@@ -17,33 +16,14 @@ import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.JTree;
-import javax.swing.SwingUtilities;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.DefaultTreeCellRenderer;
-import java.text.NumberFormat;
-
-import IceGrid.AMI_Admin_getNodeLoad;
-import IceGrid.AMI_Admin_shutdownNode;
-
-import IceGrid.LoadInfo;
-import IceGrid.NodeDescriptor;
-import IceGrid.NodeInfo;
-import IceGrid.Model;
-import IceGrid.NodeInfo;
-import IceGrid.NodeDynamicInfo;
-import IceGrid.NodeUpdateDescriptor;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.AdapterDynamicInfo;
-import IceGrid.ServerDescriptor;
-import IceGrid.ServerInstanceDescriptor;
-import IceGrid.ServerState;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-class Node extends EditableParent
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Node extends ListTreeNode
{
static public NodeDescriptor
copyDescriptor(NodeDescriptor nd)
@@ -76,7 +56,7 @@ class Node extends EditableParent
actions[COPY] = true;
actions[DELETE] = true;
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
if(descriptor != null)
{
actions[PASTE] = descriptor instanceof NodeDescriptor ||
@@ -91,46 +71,34 @@ class Node extends EditableParent
actions[NEW_SERVER] = true;
actions[NEW_SERVER_ICEBOX] = true;
actions[NEW_SERVER_FROM_TEMPLATE] = true;
- actions[SHUTDOWN_NODE] = _up && _model.getAdmin() != null;
}
return actions;
}
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
-
- JMenuItem newServerItem = new JMenuItem(_model.getActions()[NEW_SERVER]);
- newServerItem.setText("New server");
- _popup.add(newServerItem);
-
- JMenuItem newIceBoxItem = new JMenuItem(_model.getActions()[NEW_SERVER_ICEBOX]);
- newIceBoxItem.setText("New IceBox server");
- _popup.add(newIceBoxItem);
-
- JMenuItem newServerFromTemplateItem =
- new JMenuItem(_model.getActions()[NEW_SERVER_FROM_TEMPLATE]);
- newServerFromTemplateItem.setText("New server from template");
- _popup.add(newServerFromTemplateItem);
-
- _popup.addSeparator();
- _popup.add(_model.getActions()[SHUTDOWN_NODE]);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_SERVER));
+ _popup.add(actions.get(NEW_SERVER_ICEBOX));
+ _popup.add(actions.get(NEW_SERVER_FROM_TEMPLATE));
}
+ actions.setTarget(this);
return _popup;
}
public void copy()
{
- _model.setClipboard(copyDescriptor(_descriptor));
- _model.getActions()[PASTE].setEnabled(true);
+ getCoordinator().setClipboard(copyDescriptor(_descriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
}
public void paste()
{
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
if(descriptor instanceof NodeDescriptor)
{
- _parent.paste();
+ ((TreeNode)_parent).paste();
}
else if(descriptor instanceof ServerInstanceDescriptor)
{
@@ -157,106 +125,23 @@ class Node extends EditableParent
newServer(descriptor);
}
- public void shutdownNode()
- {
- final String prefix = "Shutting down node '" + _id + "'...";
- _model.getStatusBar().setText(prefix);
-
- AMI_Admin_shutdownNode cb = new AMI_Admin_shutdownNode()
- {
- //
- // Called by another thread!
- //
- public void ice_response()
- {
- amiSuccess(prefix);
- }
-
- public void ice_exception(Ice.UserException e)
- {
- amiFailure(prefix, "Failed to shutdown " + _id, e);
- }
-
- public void ice_exception(Ice.LocalException e)
- {
- amiFailure(prefix, "Failed to shutdown " + _id,
- e.toString());
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- _model.getAdmin().shutdownNode_async(cb, _id);
- }
- catch(Ice.LocalException e)
- {
- failure(prefix, "Failed to shutdown " + _id, e.toString());
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
-
-
- //
- // Recompute actions in case this comes from popup menu
- //
- _model.showActions(_model.getSelectedNode());
- }
-
- public boolean destroy()
+ public void destroy()
{
- if(_parent == null)
- {
- return false;
- }
Nodes nodes = (Nodes)_parent;
-
if(_ephemeral)
{
- nodes.removeChild(this, true);
- return true;
- }
- else if(!_inRegistry)
- {
- JOptionPane.showMessageDialog(
- _model.getMainFrame(),
- "There is no definition for this node in application '"
- + getApplication().getId()
- + "'; this node only appears here because it's up and running.",
- "Nothing to destroy",
- JOptionPane.INFORMATION_MESSAGE);
- return false;
+ nodes.removeChild(this);
}
- else if(_model.canUpdate())
+ else
{
- Application application = getApplication();
-
+ nodes.removeChild(this);
nodes.removeDescriptor(_id);
- nodes.removeElement(this, true);
- if(_up)
- {
- try
- {
- Node cleanNode = new Node(false, _id, null, application, _staticInfo);
- nodes.addChild(cleanNode, true);
- }
- catch(UpdateFailedException e)
- {
- assert false;
- }
- }
- return true;
+ nodes.getEditable().removeElement(_id);
+ getRoot().updated();
}
- return false;
}
-
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
@@ -272,33 +157,9 @@ class Node extends EditableParent
// Initialization
//
_cellRenderer = new DefaultTreeCellRenderer();
- _nodeUp = Utils.getIcon("/icons/16x16/node_up.png");
- _nodeDown = Utils.getIcon("/icons/16x16/node_down.png");
- }
-
- if(_up)
- {
- _cellRenderer.setToolTipText("Up and running");
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_nodeUp);
- }
- else
- {
- _cellRenderer.setClosedIcon(_nodeUp);
- }
- }
- else
- {
- _cellRenderer.setToolTipText("Not running");
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_nodeDown);
- }
- else
- {
- _cellRenderer.setClosedIcon(_nodeDown);
- }
+ Icon nodeIcon = Utils.getIcon("/icons/16x16/node.png");
+ _cellRenderer.setOpenIcon(nodeIcon);
+ _cellRenderer.setClosedIcon(nodeIcon);
}
return _cellRenderer.getTreeCellRendererComponent(
@@ -309,161 +170,66 @@ class Node extends EditableParent
{
if(_editor == null)
{
- _editor = new NodeEditor(_model.getMainFrame());
+ _editor = (NodeEditor)getRoot().getEditor(NodeEditor.class, this);
}
_editor.show(this);
return _editor;
}
- public Object getDescriptor()
+ protected Editor createEditor()
{
- return _descriptor;
+ return new NodeEditor(getCoordinator().getMainFrame());
}
+
public boolean isEphemeral()
{
return _ephemeral;
}
+
- public Object saveDescriptor()
+ Object getDescriptor()
{
- return _descriptor.clone();
+ return _descriptor;
}
- public void restoreDescriptor(Object savedCopy)
+
+ NodeDescriptor saveDescriptor()
{
- NodeDescriptor copy = (NodeDescriptor)savedCopy;
- _descriptor.description = copy.description;
- _descriptor.loadFactor = copy.loadFactor;
- _descriptor.variables = copy.variables;
+ return (NodeDescriptor)_descriptor.clone();
}
- static private class ServerBackup
+ void restoreDescriptor(NodeDescriptor copy)
{
- java.util.TreeSet removedElements;
- java.util.Map parameterValues;
+ _descriptor.description = copy.description;
+ _descriptor.loadFactor = copy.loadFactor;
+ _descriptor.variables = copy.variables;
}
- Object rebuildChild(CommonBase child, java.util.List editables)
- throws UpdateFailedException
+ void write(XMLWriter writer) throws java.io.IOException
{
- ServerBackup backup = new ServerBackup();
-
- Server newServer = null;
- Server server = (Server)child;
- ServerInstanceDescriptor instanceDescriptor = server.getInstanceDescriptor();
-
- if(instanceDescriptor != null)
- {
- TemplateDescriptor templateDescriptor
- = getApplication().findServerTemplateDescriptor(instanceDescriptor.template);
-
- java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters);
- if(!parameters.equals(instanceDescriptor.parameterValues.keySet()))
- {
- backup.parameterValues = instanceDescriptor.parameterValues;
- instanceDescriptor.parameterValues = Editor.makeParameterValues(
- instanceDescriptor.parameterValues, templateDescriptor.parameters);
- }
- try
- {
- newServer = createServer(false, instanceDescriptor, getApplication());
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
- else
- {
- try
- {
- newServer = createServer(false, server.getServerDescriptor(), getApplication());
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
- }
-
- if(server.getId().equals(newServer.getId()))
+ if(!_ephemeral)
{
- //
- // A simple update. We can't simply rebuild server because
- // we need to keep a backup
- //
- if(server.isModified())
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", _id));
+ if(_descriptor.loadFactor.length() > 0)
{
- newServer.markModified();
- }
-
- removeChild(server, true);
- try
- {
- addChild(newServer, true);
- }
- catch(UpdateFailedException e)
- {
- assert false; // impossible, we just removed a child with
- // this id
+ attributes.add(createAttribute("load-factor",
+ _descriptor.loadFactor));
}
+
+ writer.writeStartTag("node", attributes);
+ writeVariables(writer, _descriptor.variables);
- if(backup.parameterValues != null)
- {
- editables.add(newServer);
- }
- }
- else
- {
- newServer.markNew();
- backup.removedElements = (java.util.TreeSet)_removedElements.clone();
- removeElement(server, true);
- try
- {
- addChild(newServer, true);
- }
- catch(UpdateFailedException e)
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
{
- e.addParent(this);
- restoreChild(server, backup);
- throw e;
+ Server server = (Server)p.next();
+ server.write(writer);
}
+ writer.writeEndTag("node");
}
-
- return backup;
}
- void restoreChild(CommonBase child, Object backupObject)
- {
- ServerBackup backup = (ServerBackup)backupObject;
- if(backup.removedElements != null)
- {
- _removedElements = backup.removedElements;
- }
-
- Server goodServer = (Server)child;
- ServerInstanceDescriptor instanceDescriptor = goodServer.getInstanceDescriptor();
- if(instanceDescriptor != null && backup.parameterValues != null)
- {
- instanceDescriptor.parameterValues = backup.parameterValues;
- }
-
- CommonBase badServer = findChildWithDescriptor(goodServer.getDescriptor());
- if(badServer != null)
- {
- removeChild(badServer, true);
- }
-
- try
- {
- addChild(child, true);
- }
- catch(UpdateFailedException e)
- {
- assert false; // impossible
- }
- }
static class Backup
{
@@ -479,15 +245,15 @@ class Node extends EditableParent
Backup rebuild(java.util.List editables)
throws UpdateFailedException
{
- Application application = getApplication();
+ Root root = getRoot();
Backup backup = new Backup();
backup.resolver = _resolver;
_resolver = new Utils.Resolver(new java.util.Map[]
- {_descriptor.variables, application.getVariables()});
+ {_descriptor.variables, root.getVariables()});
- _resolver.put("application", application.getId());
- _resolver.put("node", getId());
+ _resolver.put("application", root.getId());
+ _resolver.put("node", _id);
backup.backupList = new java.util.Vector();
backup.servers = (java.util.LinkedList)_children.clone();
@@ -498,7 +264,7 @@ class Node extends EditableParent
Server server = (Server)p.next();
try
{
- backup.backupList.add(rebuildChild(server, editables));
+ backup.backupList.add(server.rebuild(editables));
}
catch(UpdateFailedException e)
{
@@ -508,24 +274,42 @@ class Node extends EditableParent
}
return backup;
}
+
+ void commit()
+ {
+ _editable.commit();
+ _origVariables = _descriptor.variables;
+ _origDescription = _descriptor.description;
+ _origLoadFactor = _descriptor.loadFactor;
+
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+ server.commit();
+ }
+ }
+
void restore(Backup backup)
{
for(int i = backup.backupList.size() - 1; i >= 0; --i)
{
- restoreChild((Server)backup.servers.get(i), backup.backupList.get(i));
+ ((Server)backup.servers.get(i)).restore(backup.backupList.get(i));
}
_resolver = backup.resolver;
}
- private Server createServer(boolean brandNew, ServerInstanceDescriptor instanceDescriptor,
- Application application) throws UpdateFailedException
+ Server createServer(boolean brandNew, ServerInstanceDescriptor instanceDescriptor)
+ throws UpdateFailedException
{
+ Root root = getRoot();
+
//
// Find template
//
TemplateDescriptor templateDescriptor =
- application.findServerTemplateDescriptor(instanceDescriptor.template);
+ root.findServerTemplateDescriptor(instanceDescriptor.template);
assert templateDescriptor != null;
@@ -548,12 +332,12 @@ class Node extends EditableParent
//
// Create server
//
- return new Server(brandNew, serverId, instanceResolver, instanceDescriptor,
- serverDescriptor, application);
+ return new Server(brandNew, this, serverId, instanceResolver, instanceDescriptor,
+ serverDescriptor);
}
- private Server createServer(boolean brandNew, ServerDescriptor serverDescriptor,
- Application application) throws UpdateFailedException
+ Server createServer(boolean brandNew, ServerDescriptor serverDescriptor)
+ throws UpdateFailedException
{
//
// Build resolver
@@ -565,131 +349,10 @@ class Node extends EditableParent
//
// Create server
//
- return new Server(brandNew, serverId, instanceResolver, null, serverDescriptor,
- application);
+ return new Server(brandNew, this, serverId, instanceResolver, null, serverDescriptor);
}
- void up(NodeInfo staticInfo)
- {
- _up = true;
- _staticInfo = staticInfo;
- _windows = _staticInfo.os.toLowerCase().startsWith("windows");
- fireNodeChangedEvent(this);
- }
-
- boolean down()
- {
- _up = false;
-
- if(_inRegistry)
- {
- fireNodeChangedEvent(this);
- return false;
- }
- else
- {
- return true;
- }
- }
-
- void getLoad()
- {
- AMI_Admin_getNodeLoad cb = new AMI_Admin_getNodeLoad()
- {
- public void ice_response(LoadInfo loadInfo)
- {
- NumberFormat format;
- if(_windows)
- {
- format = NumberFormat.getPercentInstance();
- format.setMaximumFractionDigits(1);
- format.setMinimumFractionDigits(1);
- }
- else
- {
- format = NumberFormat.getNumberInstance();
- format.setMaximumFractionDigits(2);
- format.setMinimumFractionDigits(2);
- }
-
- final String load =
- format.format(loadInfo.avg1) + " " +
- format.format(loadInfo.avg5) + " " +
- format.format(loadInfo.avg15);
-
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _editor.setLoad(load, Node.this);
- }
- });
- }
-
- public void ice_exception(final Ice.UserException e)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- if(e instanceof IceGrid.NodeNotExistException)
- {
- _editor.setLoad(
- "Error: this node is not known to the IceGrid Registry",
- Node.this);
- }
- else if(e instanceof IceGrid.NodeUnreachableException)
- {
- _editor.setLoad("Error: cannot reach this node", Node.this);
- }
- else
- {
- _editor.setLoad("Error: " + e.toString(), Node.this);
- }
- }
- });
- }
-
- public void ice_exception(final Ice.LocalException e)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- _editor.setLoad("Error: " + e.toString(), Node.this);
- }
- });
- }
- };
-
- try
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- IceGrid.AdminPrx admin = _model.getAdmin();
- if(admin == null)
- {
- _editor.setLoad("Unknown", this);
- }
- else
- {
- admin.getNodeLoad_async(cb, _id);
- }
- }
- catch(Ice.LocalException e)
- {
- _editor.setLoad("Error: " + e.toString(), this);
- }
- finally
- {
- _model.getMainFrame().setCursor(
- Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
-
NodeUpdateDescriptor getUpdate()
{
NodeUpdateDescriptor update = new NodeUpdateDescriptor();
@@ -698,13 +361,13 @@ class Node extends EditableParent
//
// First: servers
//
- if(isNew())
+ if(_editable.isNew())
{
update.removeServers = new String[0];
}
else
{
- update.removeServers = removedElements();
+ update.removeServers = _editable.removedElements();
}
update.serverInstances = new java.util.LinkedList();
@@ -714,7 +377,8 @@ class Node extends EditableParent
while(p.hasNext())
{
Server server = (Server)p.next();
- if(isNew() || server.isModified() || server.isNew())
+ if(_editable.isNew() || server.getEditable().isModified()
+ || server.getEditable().isNew())
{
ServerInstanceDescriptor instanceDescriptor = server.getInstanceDescriptor();
if(instanceDescriptor != null)
@@ -731,14 +395,14 @@ class Node extends EditableParent
//
// Anything in this update?
//
- if(!isNew() && !isModified() && update.removeServers.length == 0
+ if(!_editable.isNew() && !_editable.isModified() && update.removeServers.length == 0
&& update.servers.size() == 0
&& update.serverInstances.size() == 0)
{
return null;
}
- if(isNew())
+ if(_editable.isNew())
{
update.variables = _descriptor.variables;
update.removeVariables = new String[0];
@@ -757,7 +421,7 @@ class Node extends EditableParent
}
//
- // Diff variables (TODO: avoid duplication with same code in Application)
+ // Diff variables (TODO: avoid duplication with same code in Root)
//
update.variables = (java.util.TreeMap)_descriptor.variables.clone();
java.util.List removeVariables = new java.util.LinkedList();
@@ -783,7 +447,6 @@ class Node extends EditableParent
}
update.removeVariables = (String[])removeVariables.toArray(new String[0]);
}
-
return update;
}
@@ -793,7 +456,7 @@ class Node extends EditableParent
java.util.Set serverTemplates, java.util.Set serviceTemplates)
throws UpdateFailedException
{
- Application application = getApplication();
+ Root root = getRoot();
java.util.Vector newChildren = new java.util.Vector();
java.util.Vector updatedChildren = new java.util.Vector();
@@ -855,7 +518,7 @@ class Node extends EditableParent
// Find template
//
TemplateDescriptor templateDescriptor =
- application.findServerTemplateDescriptor(instanceDescriptor.template);
+ root.findServerTemplateDescriptor(instanceDescriptor.template);
assert templateDescriptor != null;
@@ -881,14 +544,13 @@ class Node extends EditableParent
Server server = (Server)findChild(serverId);
if(server != null)
{
- server.rebuild(instanceResolver, instanceDescriptor, serverDescriptor,
- application);
+ server.rebuild(instanceResolver, instanceDescriptor, serverDescriptor);
updatedChildren.add(server);
}
else
{
- server = new Server(false, serverId, instanceResolver, instanceDescriptor,
- serverDescriptor, application);
+ server = new Server(false, this, serverId, instanceResolver, instanceDescriptor,
+ serverDescriptor);
newChildren.add(server);
_descriptor.serverInstances.add(instanceDescriptor);
}
@@ -917,14 +579,13 @@ class Node extends EditableParent
if(server != null)
{
- server.rebuild(instanceResolver, null, serverDescriptor,
- application);
+ server.rebuild(instanceResolver, null, serverDescriptor);
updatedChildren.add(server);
}
else
{
- server = new Server(false, serverId, instanceResolver, null,
- serverDescriptor, application);
+ server = new Server(false, this, serverId, instanceResolver, null,
+ serverDescriptor);
newChildren.add(server);
_descriptor.servers.add(serverDescriptor);
}
@@ -992,7 +653,7 @@ class Node extends EditableParent
else
{
TemplateDescriptor templateDescriptor =
- application.findServerTemplateDescriptor(instanceDescriptor.template);
+ root.findServerTemplateDescriptor(instanceDescriptor.template);
assert templateDescriptor != null;
serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor;
@@ -1007,71 +668,30 @@ class Node extends EditableParent
String serverId = instanceResolver.substitute(serverDescriptor.id);
assert serverId.equals(server.getId());
- server.rebuild(instanceResolver, instanceDescriptor, serverDescriptor,
- application);
+ server.rebuild(instanceResolver, instanceDescriptor, serverDescriptor);
updatedChildren.add(server);
}
- updateChildren((CommonBaseI[])updatedChildren.toArray(new CommonBaseI[0]));
- addChildren((CommonBaseI[])newChildren.toArray(new CommonBaseI[0]));
-
- if(!_inRegistry)
- {
- ((Nodes)_parent).addDescriptor(_id, _descriptor);
- _inRegistry = true;
- }
- }
-
- public void commit()
- {
- super.commit();
-
- _origVariables = _descriptor.variables;
- _origDescription = _descriptor.description;
- _origLoadFactor = _descriptor.loadFactor;
+ childrenChanged(updatedChildren);
+ insertChildren(newChildren, true);
}
- Node(boolean brandNew, String nodeName, NodeDescriptor descriptor,
- Application application, NodeInfo staticInfo)
+ Node(boolean brandNew, TreeNode parent, String nodeName, NodeDescriptor descriptor)
throws UpdateFailedException
{
- super(brandNew, nodeName, application.getModel());
+ super(brandNew, parent, nodeName);
_ephemeral = false;
- _inRegistry = (descriptor != null);
- _staticInfo = staticInfo;
- _up = staticInfo != null;
- if(_up)
- {
- _windows = _staticInfo.os.toLowerCase().startsWith("windows");
- }
-
- if(!_inRegistry)
- {
- assert !brandNew;
- descriptor = new NodeDescriptor(new java.util.TreeMap(),
- new java.util.LinkedList(),
- new java.util.LinkedList(),
- "",
- "");
- }
-
_descriptor = descriptor;
+
_origVariables = _descriptor.variables;
_origDescription = _descriptor.description;
_origLoadFactor = _descriptor.loadFactor;
-
- java.util.Map[] maps = new java.util.Map[]
- {_descriptor.variables, application.getVariables()};
-
- assert maps[0] == _descriptor.variables;
- assert maps[1] == application.getVariables();
-
-
- _resolver = new Utils.Resolver(maps);
+ _resolver = new Utils.Resolver(new java.util.Map[]
+ {_descriptor.variables, getRoot().getVariables()});
- _resolver.put("application", application.getId());
- _resolver.put("node", getId());
+ _resolver.put("application", getRoot().getId());
+ _resolver.put("node", _id);
//
// Template instances
@@ -1082,7 +702,7 @@ class Node extends EditableParent
ServerInstanceDescriptor instanceDescriptor =
(ServerInstanceDescriptor)p.next();
- addChild(createServer(false, instanceDescriptor, application));
+ insertChild(createServer(false, instanceDescriptor), false);
}
//
@@ -1092,15 +712,14 @@ class Node extends EditableParent
while(p.hasNext())
{
ServerDescriptor serverDescriptor = (ServerDescriptor)p.next();
- addChild(createServer(false, serverDescriptor, application));
+ insertChild(createServer(false, serverDescriptor), false);
}
}
- Node(String nodeName, NodeDescriptor descriptor, Model model)
+ Node(TreeNode parent, String nodeName, NodeDescriptor descriptor)
{
- super(false, nodeName, model);
+ super(false, parent, nodeName);
_ephemeral = true;
- _inRegistry = false;
_descriptor = descriptor;
}
@@ -1158,7 +777,7 @@ class Node extends EditableParent
// Remove instance
//
removeInstanceDescriptor(instanceDescriptor);
- _removedElements.add(server.getId());
+ _editable.removeElement(server.getId());
toRemove.add(server.getId());
}
}
@@ -1197,39 +816,22 @@ class Node extends EditableParent
return _resolver;
}
- NodeInfo getStaticInfo()
- {
- return _staticInfo;
- }
-
- boolean isRunningWindows()
- {
- return _windows;
- }
void tryAdd(ServerInstanceDescriptor instanceDescriptor,
ServerDescriptor serverDescriptor,
boolean addDescriptor) throws UpdateFailedException
{
- try
+ if(instanceDescriptor != null)
{
- if(instanceDescriptor != null)
- {
- addChild(createServer(true, instanceDescriptor, getApplication()),
- true);
- }
- else
- {
- addChild(createServer(true, serverDescriptor, getApplication()),
- true);
- }
+ insertChild(createServer(true, instanceDescriptor),
+ true);
}
- catch(UpdateFailedException e)
+ else
{
- e.addParent(this);
- throw e;
+ insertChild(createServer(true, serverDescriptor),
+ true);
}
-
+
if(addDescriptor)
{
if(instanceDescriptor != null)
@@ -1241,11 +843,6 @@ class Node extends EditableParent
_descriptor.servers.add(serverDescriptor);
}
}
-
- if(!_inRegistry)
- {
- moveToRegistry();
- }
}
void removeDescriptor(ServerDescriptor sd)
@@ -1279,54 +876,40 @@ class Node extends EditableParent
}
}
- boolean inRegistry()
- {
- return _inRegistry;
- }
-
- void moveToRegistry()
- {
- assert !_inRegistry;
- assert !_ephemeral;
-
- ((Nodes)_parent).addDescriptor(_id, _descriptor);
- _inRegistry = true;
- markNew();
- }
-
private void newServer(ServerDescriptor descriptor)
{
descriptor.id = makeNewChildId(descriptor.id);
- Server server = new Server(descriptor.id, null, descriptor, _model);
+ Server server = new Server(this, descriptor.id, null, descriptor);
try
{
- addChild(server, true);
+ insertChild(server, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(server.getPath());
+ getRoot().setSelectedNode(server);
}
private void newServer(ServerInstanceDescriptor descriptor)
{
String id = makeNewChildId("NewServer");
-
+ Root root = getRoot();
+
//
// Make sure descriptor.template points to a real template
//
- ServerTemplate t = getApplication().findServerTemplate(descriptor.template);
+ ServerTemplate t = root.findServerTemplate(descriptor.template);
if(t == null)
{
- t = (ServerTemplate)getApplication().getServerTemplates().getChildAt(0);
+ t = (ServerTemplate)root.getServerTemplates().getChildAt(0);
if(t == null)
{
JOptionPane.showMessageDialog(
- _model.getMainFrame(),
+ getCoordinator().getMainFrame(),
"You need to create a server template before you can create a server from a template.",
"No Server Template",
JOptionPane.INFORMATION_MESSAGE);
@@ -1342,16 +925,16 @@ class Node extends EditableParent
ServerDescriptor sd = (ServerDescriptor)
((TemplateDescriptor)t.getDescriptor()).descriptor;
- Server server = new Server(id, descriptor, sd, _model);
+ Server server = new Server(this, id, descriptor, sd);
try
{
- addChild(server, true);
+ insertChild(server, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(server.getPath());
+ root.setSelectedNode(server);
}
private NodeDescriptor _descriptor;
@@ -1361,18 +944,9 @@ class Node extends EditableParent
private String _origDescription;
private String _origLoadFactor;
- private boolean _up = false;
private final boolean _ephemeral;
+ private NodeEditor _editor;
- private boolean _inRegistry;
-
- private NodeInfo _staticInfo;
- private boolean _windows;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private Icon _nodeUp;
- static private Icon _nodeDown;
-
- static private NodeEditor _editor;
+ static private DefaultTreeCellRenderer _cellRenderer;
static private JPopupMenu _popup;
}
diff --git a/java/src/IceGridGUI/Application/NodeEditor.java b/java/src/IceGridGUI/Application/NodeEditor.java
new file mode 100755
index 00000000000..3de6710fb94
--- /dev/null
+++ b/java/src/IceGridGUI/Application/NodeEditor.java
@@ -0,0 +1,293 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.KeyStroke;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class NodeEditor extends Editor
+{
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Node Properties");
+ }
+
+ protected void applyUpdate()
+ {
+ Root root = _target.getRoot();
+
+ root.disableSelectionListener();
+ try
+ {
+ if(_target.isEphemeral())
+ {
+ Nodes nodes = (Nodes)_target.getParent();
+ writeDescriptor();
+ NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
+ _target.destroy(); // just removes the child
+ try
+ {
+ nodes.tryAdd(_name.getText(), descriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Add back ephemeral child
+ //
+ try
+ {
+ nodes.insertChild(_target, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+ root.setSelectedNode(_target);
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ _target = nodes.findChildWithDescriptor(descriptor);
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+ else if(isSimpleUpdate())
+ {
+ writeDescriptor();
+ root.updated();
+ ((Node)_target).getEditable().markModified();
+ }
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ NodeDescriptor savedDescriptor = ((Node)_target).saveDescriptor();
+ writeDescriptor();
+
+ //
+ // Rebuild node; don't need the backup
+ // since it's just one node
+ //
+ java.util.List editables = new java.util.LinkedList();
+
+ try
+ {
+ ((Node)_target).rebuild(editables);
+ }
+ catch(UpdateFailedException e)
+ {
+ ((Node)_target) .restoreDescriptor(savedDescriptor);
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ java.util.Iterator p = editables.iterator();
+ while(p.hasNext())
+ {
+ Editable editable = (Editable)p.next();
+ editable.markModified();
+ }
+
+ ((Node)_target).getEditable().markModified();
+ root.updated();
+ }
+
+ root.getCoordinator().getCurrentTab().showNode(_target);
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
+ }
+ finally
+ {
+ root.enableSelectionListener();
+ }
+ }
+
+ Utils.Resolver getDetailResolver()
+ {
+ if(_target.getCoordinator().substitute())
+ {
+ return _target.getResolver();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ NodeEditor(JFrame parentFrame)
+ {
+ _name.getDocument().addDocumentListener(_updateListener);
+ _name.setToolTipText("Must match the IceGrid.Node.Name property of the desired icegridnode process");
+ _description.getDocument().addDocumentListener(_updateListener);
+ _description.setToolTipText("An optional description for this node");
+ _variables.setEditable(false);
+
+
+ //
+ // Variables
+ //
+ _variablesDialog = new TableDialog(parentFrame,
+ "Variables", "Name", "Value", true);
+
+ Action openVariablesDialog = new AbstractAction("...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ java.util.TreeMap result = _variablesDialog.show(_variablesMap,
+ getProperties());
+ if(result != null)
+ {
+ updated();
+ _variablesMap = result;
+ setVariablesField();
+ }
+ }
+ };
+ openVariablesDialog.putValue(Action.SHORT_DESCRIPTION,
+ "Edit variables");
+ _variablesButton = new JButton(openVariablesDialog);
+
+ _loadFactor.getDocument().addDocumentListener(_updateListener);
+ _loadFactor.setToolTipText("<html>A floating point value.<br>"
+ + "When not specified, IceGrid uses 1.0 on all platforms<br>"
+ + "except Windows where it uses 1.0 divided by <i>number of processors</i>.<html>");
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Name");
+ builder.append(_name, 3);
+ builder.nextLine();
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("Variables", _variables);
+ builder.append(_variablesButton);
+ builder.nextLine();
+ builder.append("Load Factor");
+ builder.append(_loadFactor, 3);
+ builder.nextLine();
+ }
+
+ boolean isSimpleUpdate()
+ {
+ NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
+ return (_variablesMap.equals(descriptor.variables));
+ }
+
+ void writeDescriptor()
+ {
+ NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
+ descriptor.description = _description.getText();
+ descriptor.variables = _variablesMap;
+ descriptor.loadFactor = _loadFactor.getText();
+ }
+
+ void show(Node node)
+ {
+ detectUpdates(false);
+ _target = node;
+
+ Utils.Resolver resolver = getDetailResolver();
+ boolean isEditable = (resolver == null);
+
+ _name.setText(_target.getId());
+ _name.setEditable(_target.isEphemeral());
+
+ NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor();
+
+ _description.setText(
+ Utils.substitute(descriptor.description, resolver));
+ _description.setEditable(isEditable);
+ _description.setOpaque(isEditable);
+
+ _variablesMap = descriptor.variables;
+ setVariablesField();
+ _variablesButton.setEnabled(isEditable);
+
+ _loadFactor.setText(
+ Utils.substitute(descriptor.loadFactor, resolver));
+ _loadFactor.setEditable(isEditable);
+
+ _applyButton.setEnabled(node.isEphemeral());
+ _discardButton.setEnabled(node.isEphemeral());
+ detectUpdates(true);
+ }
+
+ private void setVariablesField()
+ {
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ final Utils.Resolver resolver = getDetailResolver();
+
+ public String toString(Object obj)
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)obj;
+
+ return (String)entry.getKey() + "="
+ + Utils.substitute((String)entry.getValue(), resolver);
+ }
+ };
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ _variables.setText(
+ Utils.stringify(_variablesMap.entrySet(), stringifier,
+ ", ", toolTipHolder));
+ _variables.setToolTipText(toolTipHolder.value);
+ }
+
+ private JTextField _name = new JTextField(20);
+ private JTextArea _description = new JTextArea(3, 20);
+ private JTextField _variables = new JTextField(20);
+ private JButton _variablesButton;
+ private TableDialog _variablesDialog;
+ private java.util.TreeMap _variablesMap;
+ private JTextField _loadFactor = new JTextField(20);
+}
diff --git a/java/src/IceGrid/TreeNode/Nodes.java b/java/src/IceGridGUI/Application/Nodes.java
index 196582c05b1..51e2fa2c410 100755
--- a/java/src/IceGrid/TreeNode/Nodes.java
+++ b/java/src/IceGridGUI/Application/Nodes.java
@@ -1,29 +1,23 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
+import javax.swing.JTree;
-import IceGrid.ApplicationDescriptor;
-import IceGrid.NodeDescriptor;
-import IceGrid.TreeModelI;
-import IceGrid.Model;
-import IceGrid.NodeDescriptor;
-import IceGrid.NodeDynamicInfo;
-import IceGrid.NodeInfo;
-import IceGrid.NodeUpdateDescriptor;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.AdapterDynamicInfo;
-import IceGrid.ServerState;
+import IceGrid.*;
+import IceGridGUI.*;
-public class Nodes extends EditableParent
+class Nodes extends ListTreeNode
{
static public java.util.HashMap
copyDescriptors(java.util.Map descriptors)
@@ -45,7 +39,7 @@ public class Nodes extends EditableParent
{
boolean[] actions = new boolean[ACTION_COUNT];
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
if(descriptor != null)
{
actions[PASTE] = descriptor instanceof NodeDescriptor;
@@ -56,23 +50,22 @@ public class Nodes extends EditableParent
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
-
- JMenuItem newNodeItem =
- new JMenuItem(_model.getActions()[NEW_NODE]);
- newNodeItem.setText("New node");
- _popup.add(newNodeItem);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_NODE));
}
+ actions.setTarget(this);
return _popup;
}
public void paste()
{
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
newNode(Node.copyDescriptor((NodeDescriptor)descriptor));
}
+
public void newNode()
{
newNode(new NodeDescriptor(
@@ -84,35 +77,19 @@ public class Nodes extends EditableParent
));
}
- public Nodes(java.util.Map nodeMap, Application application)
+ Nodes(TreeNode parent, java.util.Map descriptors)
throws UpdateFailedException
{
- super(false, "Nodes", application.getModel());
- _descriptors = nodeMap;
+ super(false, parent, "Nodes");
+ _descriptors = descriptors;
- java.util.Iterator p = nodeMap.entrySet().iterator();
+ java.util.Iterator p = _descriptors.entrySet().iterator();
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
String nodeName = (String)entry.getKey();
NodeDescriptor nodeDescriptor = (NodeDescriptor)entry.getValue();
- addChild(new Node(false, nodeName, nodeDescriptor,
- application,
- _model.getRoot().getStaticNodeInfo(nodeName)));
- }
-
- //
- // Also create a Node for each node that is up
- //
- p = _model.getRoot().getNodesUp().iterator();
- while(p.hasNext())
- {
- String nodeName = (String)p.next();
- if(findChild(nodeName) == null)
- {
- addChild(new Node(false, nodeName, null, application,
- _model.getRoot().getStaticNodeInfo(nodeName)));
- }
+ insertChild(new Node(false, this, nodeName, nodeDescriptor), false);
}
}
@@ -154,6 +131,17 @@ public class Nodes extends EditableParent
}
}
+ void commit()
+ {
+ _editable.commit();
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ Node node = (Node)p.next();
+ node.commit();
+ }
+ }
+
java.util.LinkedList getUpdates()
{
java.util.LinkedList updates = new java.util.LinkedList();
@@ -207,7 +195,7 @@ public class Nodes extends EditableParent
java.util.Set serverTemplates, java.util.Set serviceTemplates)
throws UpdateFailedException
{
- Application application = (Application)getParent();
+ Root root = getRoot();
//
// Note: _descriptors has already the nodes removed but
@@ -239,7 +227,7 @@ public class Nodes extends EditableParent
update.loadFactor.value,
update.description.value);
_descriptors.put(update.name, nodeDescriptor);
- node = new Node(false, update.name, nodeDescriptor, application, null);
+ node = new Node(false, this, update.name, nodeDescriptor);
newChildren.add(node);
}
else
@@ -262,49 +250,10 @@ public class Nodes extends EditableParent
}
}
- addChildren((CommonBaseI[])newChildren.toArray(new CommonBaseI[0]));
- }
-
- void nodeUp(String nodeName, NodeInfo staticInfo)
- {
- Node node = findNode(nodeName);
- if(node == null)
- {
- try
- {
- node = new Node(false, nodeName, null, getApplication(),
- staticInfo);
- addChild(node, true);
- }
- catch(UpdateFailedException e)
- {
- // Impossible
- assert false;
- }
- }
- else
- {
- node.up(staticInfo);
- }
+ insertChildren(newChildren, true);
}
- void nodeDown(String nodeName)
- {
- //
- // We remove nodes that are down and without descriptor
- //
- Node node = findNode(nodeName);
- if(node != null)
- {
- if(node.down())
- {
- removeChild(nodeName, true);
- }
- }
- //
- // Else log a warning?
- //
- }
+
Node findNode(String nodeName)
{
@@ -332,19 +281,16 @@ public class Nodes extends EditableParent
_descriptors.remove(nodeName);
}
+ Object getDescriptor()
+ {
+ return _descriptors;
+ }
+
void tryAdd(String nodeName, NodeDescriptor descriptor)
throws UpdateFailedException
{
- try
- {
- Node node = new Node(true, nodeName, descriptor, getApplication(), null);
- addChild(node, true);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
+ Node node = new Node(true, this, nodeName, descriptor);
+ insertChild(node, true);
_descriptors.put(nodeName, descriptor);
}
@@ -352,18 +298,19 @@ public class Nodes extends EditableParent
{
String name = makeNewChildId("NewNode");
- Node node = new Node(name, descriptor, _model);
+ Node node = new Node(this, name, descriptor);
try
{
- addChild(node, true);
+ insertChild(node, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(node.getPath());
+ getRoot().setSelectedNode(node);
}
+
private java.util.Map _descriptors;
static private JPopupMenu _popup;
diff --git a/java/src/IceGridGUI/Application/ReplicaGroup.java b/java/src/IceGridGUI/Application/ReplicaGroup.java
new file mode 100755
index 00000000000..e360ec41bc2
--- /dev/null
+++ b/java/src/IceGridGUI/Application/ReplicaGroup.java
@@ -0,0 +1,222 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class ReplicaGroup extends TreeNode
+{
+ static public ReplicaGroupDescriptor
+ copyDescriptor(ReplicaGroupDescriptor d)
+ {
+ return (ReplicaGroupDescriptor)d.clone();
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setLeafIcon(
+ Utils.getIcon("/icons/16x16/replica_group.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ actions[PASTE] = true;
+ }
+ actions[DELETE] = true;
+
+ if(!_ephemeral)
+ {
+ actions[SHOW_VARS] = true;
+ actions[SUBSTITUTE_VARS] = true;
+ }
+ return actions;
+ }
+
+ public void copy()
+ {
+ getCoordinator().setClipboard(copyDescriptor(_descriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+
+ }
+ public void paste()
+ {
+ ((TreeNode)_parent).paste();
+ }
+
+ public void destroy()
+ {
+ ReplicaGroups replicaGroups = (ReplicaGroups)_parent;
+ replicaGroups.removeChild(this);
+
+ if(!_ephemeral)
+ {
+ replicaGroups.removeDescriptor(_descriptor);
+ replicaGroups.getEditable().removeElement(_id);
+ getRoot().updated();
+ }
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (ReplicaGroupEditor)getRoot().getEditor(ReplicaGroupEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new ReplicaGroupEditor(getCoordinator().getMainFrame());
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ Object saveDescriptor()
+ {
+ return _descriptor.clone();
+ }
+ void restoreDescriptor(Object savedDescriptor)
+ {
+ ReplicaGroupDescriptor clone = (ReplicaGroupDescriptor)savedDescriptor;
+ _descriptor.id = clone.id;
+ _descriptor.description = clone.description;
+ _descriptor.objects = clone.objects;
+ _descriptor.loadBalancing = clone.loadBalancing;
+ }
+
+ void commit()
+ {
+ _editable.commit();
+ }
+
+ Editable getEditable()
+ {
+ return _editable;
+ }
+
+ ReplicaGroup(boolean brandNew,
+ TreeNode parent,
+ ReplicaGroupDescriptor descriptor)
+ {
+ super(parent, descriptor.id);
+ _ephemeral = false;
+ _editable = new Editable(brandNew);
+ rebuild(descriptor);
+ }
+
+ ReplicaGroup(TreeNode parent, ReplicaGroupDescriptor descriptor)
+ {
+ super(parent, descriptor.id);
+ _ephemeral = true;
+ _editable = null;
+ rebuild(descriptor);
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("id", _descriptor.id));
+
+ if(_descriptor.loadBalancing == null &&
+ _descriptor.description.length() == 0 && _descriptor.objects.isEmpty())
+ {
+ writer.writeElement("replica-group", attributes);
+ }
+ else
+ {
+ writer.writeStartTag("replica-group", attributes);
+
+ if(_descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _descriptor.description);
+ }
+ if(_descriptor.loadBalancing != null)
+ {
+ attributes.clear();
+ if(_descriptor.loadBalancing instanceof RandomLoadBalancingPolicy)
+ {
+ attributes.add(createAttribute("type", "random"));
+ }
+ else if(_descriptor.loadBalancing instanceof RoundRobinLoadBalancingPolicy)
+ {
+ attributes.add(createAttribute("type", "round-robin"));
+ }
+ else if(_descriptor.loadBalancing instanceof AdaptiveLoadBalancingPolicy)
+ {
+ attributes.add(createAttribute("type", "adaptive"));
+ AdaptiveLoadBalancingPolicy policy =
+ (AdaptiveLoadBalancingPolicy)_descriptor.loadBalancing;
+ attributes.add(createAttribute("load-sample", policy.loadSample));
+ }
+ attributes.add(createAttribute("n-replicas",
+ _descriptor.loadBalancing.nReplicas));
+ writer.writeElement("load-balancing", attributes);
+ }
+
+ writeObjects(writer, _descriptor.objects);
+ writer.writeEndTag("replica-group");
+ }
+ }
+ }
+
+
+ void rebuild(ReplicaGroupDescriptor descriptor)
+ {
+ _descriptor = descriptor;
+ //
+ // And that's it since there is no children
+ //
+ }
+
+ private ReplicaGroupDescriptor _descriptor;
+ private final boolean _ephemeral;
+ private final Editable _editable;
+ private ReplicaGroupEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+}
diff --git a/java/src/IceGrid/TreeNode/ReplicaGroupEditor.java b/java/src/IceGridGUI/Application/ReplicaGroupEditor.java
index f9dda6d0a0e..0926dc07d8c 100755
--- a/java/src/IceGrid/TreeNode/ReplicaGroupEditor.java
+++ b/java/src/IceGridGUI/Application/ReplicaGroupEditor.java
@@ -1,453 +1,449 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.CellConstraints;
-
-import IceGrid.AdaptiveLoadBalancingPolicy;
-import IceGrid.RandomLoadBalancingPolicy;
-import IceGrid.RoundRobinLoadBalancingPolicy;
-
-import IceGrid.Model;
-import IceGrid.ObjectDescriptor;
-import IceGrid.ReplicaGroupDescriptor;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
-
-class ReplicaGroupEditor extends Editor
-{
- protected void applyUpdate()
- {
- ReplicaGroup replicaGroup = getReplicaGroup();
- Model model = replicaGroup.getModel();
-
- if(model.canUpdate())
- {
- model.disableDisplay();
-
- try
- {
- if(replicaGroup.isEphemeral())
- {
- ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
- writeDescriptor();
- ReplicaGroupDescriptor descriptor =
- (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
- replicaGroup.destroy(); // just removes the child
-
- try
- {
- replicaGroups.tryAdd(descriptor, true);
- }
- catch(UpdateFailedException e)
- {
- //
- // Add back ephemeral child
- //
- try
- {
- replicaGroups.addChild(replicaGroup, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- model.setSelectionPath(replicaGroup.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- _target = replicaGroups.findChildWithDescriptor(descriptor);
- }
- else if(isSimpleUpdate())
- {
- writeDescriptor();
- _target.getEditable().markModified();
- }
- else
- {
- //
- // Save to be able to rollback
- //
- Object savedDescriptor = replicaGroup.saveDescriptor();
- ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
- writeDescriptor();
- ReplicaGroupDescriptor descriptor =
- (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
-
- replicaGroups.removeChild(replicaGroup, true);
- try
- {
- replicaGroups.tryAdd(descriptor, false);
- }
- catch(UpdateFailedException e)
- {
- //
- // Restore all
- //
- try
- {
- replicaGroups.addChild(replicaGroup, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- replicaGroup.restoreDescriptor(savedDescriptor);
- model.setSelectionPath(replicaGroup.getPath());
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- replicaGroups.removeElement(replicaGroup.getId()); // replaced by brand new ReplicaGroup
-
- _target = replicaGroups.findChildWithDescriptor(descriptor);
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- }
-
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
- }
- finally
- {
- model.enableDisplay();
- }
- }
- }
-
- Utils.Resolver getDetailResolver()
- {
- Application application = _target.getApplication();
- if(application.getModel().substitute())
- {
- return application.getResolver();
- }
- else
- {
- return null;
- }
- }
-
- ReplicaGroupEditor(JFrame parentFrame)
- {
- super(false, true);
-
- _objects.setEditable(false);
-
- //
- // _objectsButton
- //
- _objectsDialog = new TableDialog(parentFrame,
- "Registered Objects",
- "Object Identity",
- "Type", true);
-
- Action openObjectsDialog = new AbstractAction("...")
- {
- public void actionPerformed(ActionEvent e)
- {
- java.util.Map result = _objectsDialog.show(_objectsMap,
- getProperties());
- if(result != null)
- {
- updated();
- _objectsMap = result;
- setObjectsField();
- }
- }
- };
- openObjectsDialog.putValue(Action.SHORT_DESCRIPTION,
- "Edit registered objects");
- _objectsButton = new JButton(openObjectsDialog);
-
- //
- // load balancing
- //
- _loadBalancing.addItemListener(new ItemListener()
- {
- public void itemStateChanged(ItemEvent e)
- {
- if(e.getStateChange() == ItemEvent.SELECTED)
- {
- updated();
-
- Object item = e.getItem();
- _nReplicasLabel.setVisible(item != RETURN_ALL);
- _nReplicas.setVisible(item != RETURN_ALL);
-
- _loadSampleLabel.setVisible(item == ADAPTIVE);
- _loadSample.setVisible(item == ADAPTIVE);
- }
- }
- });
- _loadBalancing.setToolTipText(
- "Specifies how IceGrid selects adapters when resolving a replica group ID");
-
- //
- // Associate updateListener with various fields
- //
- _id.getDocument().addDocumentListener(_updateListener);
- _id.setToolTipText("Must be unique within this IceGrid deployment");
-
- _description.getDocument().addDocumentListener(_updateListener);
- _description.setToolTipText(
- "An optional description for this replica group");
-
- _nReplicas.getDocument().addDocumentListener(_updateListener);
- _nReplicas.setToolTipText("<html>IceGrid returns the endpoints of "
- + "up to <i>number</i> adapters<br>"
- + "when resolving a replica group ID</html>");
-
- _loadSample.setEditable(true);
- JTextField loadSampleTextField = (JTextField)
- _loadSample.getEditor().getEditorComponent();
- loadSampleTextField.getDocument().addDocumentListener(_updateListener);
- _loadSample.setToolTipText(
- "Use the load average or CPU usage over the last 1, 5 or 15 minutes?");
-
- }
-
- void writeDescriptor()
- {
- ReplicaGroupDescriptor descriptor =
- (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
-
- descriptor.id = _id.getText();
- descriptor.description = _description.getText();
- descriptor.objects = AdapterEditor.mapToObjectDescriptorSeq(_objectsMap);
-
- Object loadBalancing = _loadBalancing.getSelectedItem();
- if(loadBalancing == RETURN_ALL)
- {
- descriptor.loadBalancing = null;
- }
- else if(loadBalancing == RANDOM)
- {
- descriptor.loadBalancing = new RandomLoadBalancingPolicy(
- _nReplicas.getText());
- }
- else if(loadBalancing == ROUND_ROBIN)
- {
- descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(
- _nReplicas.getText());
- }
- else if(loadBalancing == ADAPTIVE)
- {
- descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy(
- _nReplicas.getText(),
- _loadSample.getSelectedItem().toString());
- }
- else
- {
- assert false;
- }
- }
-
- boolean isSimpleUpdate()
- {
- ReplicaGroupDescriptor descriptor =
- (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
- return descriptor.id.equals(_id.getText());
- }
-
- void appendProperties(DefaultFormBuilder builder)
- {
- builder.append("Replica Group ID" );
- builder.append(_id, 3);
- builder.nextLine();
-
- builder.append("Description");
- builder.nextLine();
- builder.append("");
- builder.nextRow(-2);
- CellConstraints cc = new CellConstraints();
- JScrollPane scrollPane = new JScrollPane(_description);
- builder.add(scrollPane,
- cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
- builder.nextRow(2);
- builder.nextLine();
-
- builder.append("Registered Objects");
- builder.append(_objects, _objectsButton);
- builder.nextLine();
-
- builder.append("Load Balancing Policy");
- builder.append(_loadBalancing, 3);
- builder.nextLine();
- _nReplicasLabel = builder.append("How many Adapters?");
- builder.append(_nReplicas, 3);
- builder.nextLine();
- _loadSampleLabel = builder.append("Load Sample");
- builder.append(_loadSample, 3);
- builder.nextLine();
- }
-
- void setObjectsField()
- {
- final Utils.Resolver resolver = getDetailResolver();
-
- Ice.StringHolder toolTipHolder = new Ice.StringHolder();
- Utils.Stringifier stringifier = new Utils.Stringifier()
- {
- public String toString(Object obj)
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)obj;
-
- return Utils.substitute((String)entry.getKey(), resolver)
- + " as '"
- + Utils.substitute((String)entry.getValue(), resolver)
- + "'";
- }
- };
-
- _objects.setText(
- Utils.stringify(_objectsMap.entrySet(), stringifier,
- ", ", toolTipHolder));
- _objects.setToolTipText(toolTipHolder.value);
- }
-
-
- void show(ReplicaGroup replicaGroup)
- {
- //
- // Make sure everything is built
- //
- getProperties();
-
-
- detectUpdates(false);
- setTarget(replicaGroup);
-
- Utils.Resolver resolver = getDetailResolver();
- boolean isEditable = (resolver == null);
-
- ReplicaGroupDescriptor descriptor =
- (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
-
- _id.setText(descriptor.id);
- _id.setEditable(isEditable);
-
- _description.setText(
- Utils.substitute(descriptor.description, resolver));
- _description.setEditable(isEditable);
- _description.setOpaque(isEditable);
-
- _objectsMap = AdapterEditor.objectDescriptorSeqToMap(descriptor.objects);
- setObjectsField();
- _objectsButton.setEnabled(isEditable);
-
- _loadBalancing.setEnabled(true);
-
- if(descriptor.loadBalancing == null)
- {
- _loadBalancing.setSelectedItem(RETURN_ALL);
- _nReplicas.setText("1");
- _loadSample.setSelectedItem("1");
- }
- else if(descriptor.loadBalancing instanceof RandomLoadBalancingPolicy)
- {
- _loadBalancing.setSelectedItem(RANDOM);
- _nReplicas.setText(
- Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
- _loadSample.setSelectedItem("1");
- }
- else if(descriptor.loadBalancing instanceof RoundRobinLoadBalancingPolicy)
- {
- _loadBalancing.setSelectedItem(ROUND_ROBIN);
- _nReplicas.setText(
- Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
- _loadSample.setSelectedItem("1");
- }
- else if(descriptor.loadBalancing instanceof AdaptiveLoadBalancingPolicy)
- {
- _loadBalancing.setSelectedItem(ADAPTIVE);
- _nReplicas.setText(
- Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
-
- _loadSample.setSelectedItem(
- Utils.substitute(
- ((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample,
- resolver));
- }
- else
- {
- assert false;
- }
- _nReplicas.setEditable(isEditable);
- _loadSample.setEditable(isEditable);
- _loadBalancing.setEnabled(isEditable);
-
- _applyButton.setEnabled(replicaGroup.isEphemeral());
- _discardButton.setEnabled(replicaGroup.isEphemeral());
- detectUpdates(true);
- }
-
- private ReplicaGroup getReplicaGroup()
- {
- return (ReplicaGroup)_target;
- }
-
- static private String RETURN_ALL = "Return all";
- static private String RANDOM = "Random";
- static private String ROUND_ROBIN = "Round-robin";
- static private String ADAPTIVE = "Adaptive";
-
- private JTextField _id = new JTextField(20);
- private JTextArea _description = new JTextArea(3, 20);
-
- private JComboBox _loadBalancing = new JComboBox(new Object[]
- {ADAPTIVE, RANDOM, RETURN_ALL, ROUND_ROBIN});
-
- private JLabel _nReplicasLabel;
- private JTextField _nReplicas = new JTextField(20);
-
- private JLabel _loadSampleLabel;
- private JComboBox _loadSample = new JComboBox(new Object[]
- {"1", "5", "15"});
-
- private JTextField _objects = new JTextField(20);
- private java.util.Map _objectsMap;
- private TableDialog _objectsDialog;
- private JButton _objectsButton;
-}
+
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class ReplicaGroupEditor extends Editor
+{
+ protected void applyUpdate()
+ {
+ ReplicaGroup replicaGroup = (ReplicaGroup)_target;
+ Root root = replicaGroup.getRoot();
+
+ root.disableSelectionListener();
+ try
+ {
+ if(replicaGroup.isEphemeral())
+ {
+ ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
+ writeDescriptor();
+ ReplicaGroupDescriptor descriptor =
+ (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
+ replicaGroup.destroy(); // just removes the child
+
+ try
+ {
+ replicaGroups.tryAdd(descriptor, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Add back ephemeral child
+ //
+ try
+ {
+ replicaGroups.insertChild(replicaGroup, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+ root.setSelectedNode(replicaGroup);
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ _target = replicaGroups.findChildWithDescriptor(descriptor);
+ root.updated();
+ }
+ else if(isSimpleUpdate())
+ {
+ writeDescriptor();
+ root.updated();
+ replicaGroup.getEditable().markModified();
+ }
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ Object savedDescriptor = replicaGroup.saveDescriptor();
+ ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
+ writeDescriptor();
+ ReplicaGroupDescriptor descriptor =
+ (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
+
+ replicaGroups.removeChild(replicaGroup);
+ try
+ {
+ replicaGroups.tryAdd(descriptor, false);
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Restore all
+ //
+ try
+ {
+ replicaGroups.insertChild(replicaGroup, true);
+ }
+ catch(UpdateFailedException die)
+ {
+ assert false;
+ }
+ replicaGroup.restoreDescriptor(savedDescriptor);
+ root.setSelectedNode(_target);
+
+ JOptionPane.showMessageDialog(
+ root.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ replicaGroups.getEditable().removeElement(replicaGroup.getId()); // replaced by brand new ReplicaGroup
+ _target = replicaGroups.findChildWithDescriptor(descriptor);
+ root.updated();
+ root.setSelectedNode(_target);
+ }
+
+ root.getCoordinator().getCurrentTab().showNode(_target);
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
+ }
+ finally
+ {
+ root.enableSelectionListener();
+ }
+ }
+
+ Utils.Resolver getDetailResolver()
+ {
+ Root root = _target.getRoot();
+
+ if(root.getCoordinator().substitute())
+ {
+ return root.getResolver();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ ReplicaGroupEditor(JFrame parentFrame)
+ {
+ _objects.setEditable(false);
+
+ //
+ // _objectsButton
+ //
+ _objectsDialog = new TableDialog(parentFrame,
+ "Registered Objects",
+ "Object Identity",
+ "Type", true);
+
+ Action openObjectsDialog = new AbstractAction("...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ java.util.Map result = _objectsDialog.show(_objectsMap,
+ getProperties());
+ if(result != null)
+ {
+ updated();
+ _objectsMap = result;
+ setObjectsField();
+ }
+ }
+ };
+ openObjectsDialog.putValue(Action.SHORT_DESCRIPTION,
+ "Edit registered objects");
+ _objectsButton = new JButton(openObjectsDialog);
+
+ //
+ // load balancing
+ //
+ _loadBalancing.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent e)
+ {
+ if(e.getStateChange() == ItemEvent.SELECTED)
+ {
+ updated();
+
+ Object item = e.getItem();
+ _nReplicasLabel.setVisible(item != RETURN_ALL);
+ _nReplicas.setVisible(item != RETURN_ALL);
+
+ _loadSampleLabel.setVisible(item == ADAPTIVE);
+ _loadSample.setVisible(item == ADAPTIVE);
+ }
+ }
+ });
+ _loadBalancing.setToolTipText(
+ "Specifies how IceGrid selects adapters when resolving a replica group ID");
+
+ //
+ // Associate updateListener with various fields
+ //
+ _id.getDocument().addDocumentListener(_updateListener);
+ _id.setToolTipText("Must be unique within this IceGrid deployment");
+
+ _description.getDocument().addDocumentListener(_updateListener);
+ _description.setToolTipText(
+ "An optional description for this replica group");
+
+ _nReplicas.getDocument().addDocumentListener(_updateListener);
+ _nReplicas.setToolTipText("<html>IceGrid returns the endpoints of "
+ + "up to <i>number</i> adapters<br>"
+ + "when resolving a replica group ID</html>");
+
+ _loadSample.setEditable(true);
+ JTextField loadSampleTextField = (JTextField)
+ _loadSample.getEditor().getEditorComponent();
+ loadSampleTextField.getDocument().addDocumentListener(_updateListener);
+ _loadSample.setToolTipText(
+ "Use the load average or CPU usage over the last 1, 5 or 15 minutes?");
+
+ }
+
+ void writeDescriptor()
+ {
+ ReplicaGroupDescriptor descriptor =
+ (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
+
+ descriptor.id = _id.getText();
+ descriptor.description = _description.getText();
+ descriptor.objects = AdapterEditor.mapToObjectDescriptorSeq(_objectsMap);
+
+ Object loadBalancing = _loadBalancing.getSelectedItem();
+ if(loadBalancing == RETURN_ALL)
+ {
+ descriptor.loadBalancing = null;
+ }
+ else if(loadBalancing == RANDOM)
+ {
+ descriptor.loadBalancing = new RandomLoadBalancingPolicy(
+ _nReplicas.getText());
+ }
+ else if(loadBalancing == ROUND_ROBIN)
+ {
+ descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(
+ _nReplicas.getText());
+ }
+ else if(loadBalancing == ADAPTIVE)
+ {
+ descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy(
+ _nReplicas.getText(),
+ _loadSample.getSelectedItem().toString());
+ }
+ else
+ {
+ assert false;
+ }
+ }
+
+ boolean isSimpleUpdate()
+ {
+ ReplicaGroupDescriptor descriptor =
+ (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
+ return descriptor.id.equals(_id.getText());
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Replica Group ID" );
+ builder.append(_id, 3);
+ builder.nextLine();
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("Registered Objects");
+ builder.append(_objects, _objectsButton);
+ builder.nextLine();
+
+ builder.append("Load Balancing Policy");
+ builder.append(_loadBalancing, 3);
+ builder.nextLine();
+ _nReplicasLabel = builder.append("How many Adapters?");
+ builder.append(_nReplicas, 3);
+ builder.nextLine();
+ _loadSampleLabel = builder.append("Load Sample");
+ builder.append(_loadSample, 3);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Replica Group Properties");
+ }
+
+ void setObjectsField()
+ {
+ final Utils.Resolver resolver = getDetailResolver();
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)obj;
+
+ return Utils.substitute((String)entry.getKey(), resolver)
+ + " as '"
+ + Utils.substitute((String)entry.getValue(), resolver)
+ + "'";
+ }
+ };
+
+ _objects.setText(
+ Utils.stringify(_objectsMap.entrySet(), stringifier,
+ ", ", toolTipHolder));
+ _objects.setToolTipText(toolTipHolder.value);
+ }
+
+
+ void show(ReplicaGroup replicaGroup)
+ {
+ //
+ // Make sure everything is built
+ //
+ getProperties();
+
+ detectUpdates(false);
+ _target = replicaGroup;
+
+ Utils.Resolver resolver = getDetailResolver();
+ boolean isEditable = (resolver == null);
+
+ ReplicaGroupDescriptor descriptor =
+ (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
+
+ _id.setText(descriptor.id);
+ _id.setEditable(isEditable);
+
+ _description.setText(
+ Utils.substitute(descriptor.description, resolver));
+ _description.setEditable(isEditable);
+ _description.setOpaque(isEditable);
+
+ _objectsMap = AdapterEditor.objectDescriptorSeqToMap(descriptor.objects);
+ setObjectsField();
+ _objectsButton.setEnabled(isEditable);
+
+ _loadBalancing.setEnabled(true);
+
+ if(descriptor.loadBalancing == null)
+ {
+ _loadBalancing.setSelectedItem(RETURN_ALL);
+ _nReplicas.setText("1");
+ _loadSample.setSelectedItem("1");
+ }
+ else if(descriptor.loadBalancing instanceof RandomLoadBalancingPolicy)
+ {
+ _loadBalancing.setSelectedItem(RANDOM);
+ _nReplicas.setText(
+ Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
+ _loadSample.setSelectedItem("1");
+ }
+ else if(descriptor.loadBalancing instanceof RoundRobinLoadBalancingPolicy)
+ {
+ _loadBalancing.setSelectedItem(ROUND_ROBIN);
+ _nReplicas.setText(
+ Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
+ _loadSample.setSelectedItem("1");
+ }
+ else if(descriptor.loadBalancing instanceof AdaptiveLoadBalancingPolicy)
+ {
+ _loadBalancing.setSelectedItem(ADAPTIVE);
+ _nReplicas.setText(
+ Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
+
+ _loadSample.setSelectedItem(
+ Utils.substitute(
+ ((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample,
+ resolver));
+ }
+ else
+ {
+ assert false;
+ }
+ _nReplicas.setEditable(isEditable);
+ _loadSample.setEditable(isEditable);
+ _loadBalancing.setEnabled(isEditable);
+
+ _applyButton.setEnabled(replicaGroup.isEphemeral());
+ _discardButton.setEnabled(replicaGroup.isEphemeral());
+ detectUpdates(true);
+ }
+
+ private ReplicaGroup getReplicaGroup()
+ {
+ return (ReplicaGroup)_target;
+ }
+
+ static private String RETURN_ALL = "Return all";
+ static private String RANDOM = "Random";
+ static private String ROUND_ROBIN = "Round-robin";
+ static private String ADAPTIVE = "Adaptive";
+
+ private JTextField _id = new JTextField(20);
+ private JTextArea _description = new JTextArea(3, 20);
+
+ private JComboBox _loadBalancing = new JComboBox(new Object[]
+ {ADAPTIVE, RANDOM, RETURN_ALL, ROUND_ROBIN});
+
+ private JLabel _nReplicasLabel;
+ private JTextField _nReplicas = new JTextField(20);
+
+ private JLabel _loadSampleLabel;
+ private JComboBox _loadSample = new JComboBox(new Object[]
+ {"1", "5", "15"});
+
+ private JTextField _objects = new JTextField(20);
+ private java.util.Map _objectsMap;
+ private TableDialog _objectsDialog;
+ private JButton _objectsButton;
+}
diff --git a/java/src/IceGrid/TreeNode/ReplicaGroups.java b/java/src/IceGridGUI/Application/ReplicaGroups.java
index 1e581add4f8..6250574e0d9 100755
--- a/java/src/IceGrid/TreeNode/ReplicaGroups.java
+++ b/java/src/IceGridGUI/Application/ReplicaGroups.java
@@ -1,22 +1,21 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.AbstractListModel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
-import IceGrid.ReplicaGroupDescriptor;
-import IceGrid.Model;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
-class ReplicaGroups extends EditableParent
+class ReplicaGroups extends ListTreeNode
{
static public java.util.LinkedList
copyDescriptors(java.util.List descriptors)
@@ -38,7 +37,7 @@ class ReplicaGroups extends EditableParent
{
boolean[] actions = new boolean[ACTION_COUNT];
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
if(descriptor != null)
{
actions[PASTE] = descriptor instanceof ReplicaGroupDescriptor;
@@ -50,13 +49,13 @@ class ReplicaGroups extends EditableParent
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_REPLICA_GROUP]);
- item.setText("New replica group");
- _popup.add(item);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_REPLICA_GROUP));
}
+ actions.setTarget(this);
return _popup;
}
@@ -74,7 +73,7 @@ class ReplicaGroups extends EditableParent
public void paste()
{
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
ReplicaGroupDescriptor d = ReplicaGroup.copyDescriptor(
(ReplicaGroupDescriptor)descriptor);
@@ -82,19 +81,19 @@ class ReplicaGroups extends EditableParent
newReplicaGroup(d);
}
- ReplicaGroups(java.util.List descriptors, Model model)
- throws UpdateFailedException
+
+ ReplicaGroups(TreeNode parent, java.util.List desc) throws UpdateFailedException
{
- super(false, "Replica Groups", model);
- _descriptors = descriptors;
-
+ super(false, parent, "Replica Groups");
+ _descriptors = desc;
+
java.util.Iterator p = _descriptors.iterator();
while(p.hasNext())
{
ReplicaGroupDescriptor descriptor
= (ReplicaGroupDescriptor)p.next();
- addChild(new ReplicaGroup(false, descriptor, _model));
+ insertChild(new ReplicaGroup(false, this, descriptor), false);
}
}
@@ -105,7 +104,7 @@ class ReplicaGroups extends EditableParent
while(p.hasNext())
{
ReplicaGroup ra = (ReplicaGroup)p.next();
- if(ra.isNew() || ra.isModified())
+ if(ra.getEditable().isNew() || ra.getEditable().isModified())
{
updates.add(ra.getDescriptor());
}
@@ -113,8 +112,18 @@ class ReplicaGroups extends EditableParent
return updates;
}
+ void commit()
+ {
+ _editable.commit();
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ ReplicaGroup rg = (ReplicaGroup)p.next();
+ rg.commit();
+ }
+ }
+
void update(java.util.List descriptors, String[] removeAdapters)
- throws UpdateFailedException
{
_descriptors = descriptors;
@@ -124,11 +133,9 @@ class ReplicaGroups extends EditableParent
removeChildren(removeAdapters);
//
- // One big set of updates, followed by inserts
+ // Updates and inserts
//
- java.util.Vector newChildren = new java.util.Vector();
- java.util.Vector updatedChildren = new java.util.Vector();
-
+ java.util.List updatedChildren = new java.util.LinkedList();
java.util.Iterator p = descriptors.iterator();
while(p.hasNext())
{
@@ -137,10 +144,19 @@ class ReplicaGroups extends EditableParent
ReplicaGroup child
= (ReplicaGroup)findChild(descriptor.id);
+
if(child == null)
{
- newChildren.add(new ReplicaGroup(false, descriptor,
- _model));
+ try
+ {
+ insertChild(
+ new ReplicaGroup(false, this, descriptor),
+ true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
}
else
{
@@ -148,13 +164,23 @@ class ReplicaGroups extends EditableParent
updatedChildren.add(child);
}
}
-
- updateChildren((CommonBaseI[])updatedChildren.toArray
- (new CommonBaseI[0]));
- addChildren((CommonBaseI[])newChildren.toArray(new CommonBaseI[0]));
+ childrenChanged(updatedChildren);
}
-
+
+ Object getDescriptor()
+ {
+ return _descriptors;
+ }
+ Object saveDescriptor()
+ {
+ assert false;
+ return null;
+ }
+ void restoreDescriptor(Object savedDescriptor)
+ {
+ assert false;
+ }
void removeDescriptor(Object descriptor)
{
@@ -175,15 +201,9 @@ class ReplicaGroups extends EditableParent
void tryAdd(ReplicaGroupDescriptor descriptor, boolean addDescriptor)
throws UpdateFailedException
{
- try
- {
- addChild(createReplicaGroup(true, descriptor), true);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
+ insertChild(
+ new ReplicaGroup(true, this, descriptor),
+ true);
if(addDescriptor)
{
@@ -191,25 +211,20 @@ class ReplicaGroups extends EditableParent
}
}
-
- private ReplicaGroup createReplicaGroup(boolean brandNew,
- ReplicaGroupDescriptor descriptor)
- {
- return new ReplicaGroup(brandNew, descriptor, _model);
- }
-
private void newReplicaGroup(ReplicaGroupDescriptor descriptor)
{
- ReplicaGroup replicaGroup = new ReplicaGroup(descriptor, _model);
+ ReplicaGroup replicaGroup =
+ new ReplicaGroup(this, descriptor);
+
try
{
- addChild(replicaGroup, true);
+ insertChild(replicaGroup, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(replicaGroup.getPath());
+ getRoot().setSelectedNode(replicaGroup);
}
private java.util.List _descriptors;
diff --git a/java/src/IceGridGUI/Application/Root.java b/java/src/IceGridGUI/Application/Root.java
new file mode 100755
index 00000000000..8926b302cd3
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Root.java
@@ -0,0 +1,1186 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import java.awt.Cursor;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+
+import java.io.File;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+public class Root extends ListTreeNode
+{
+ //
+ // Construct a normal, existing Application
+ //
+ public Root(Coordinator coordinator, ApplicationDescriptor desc,
+ boolean live, File file)
+ {
+ super(false, null, desc.name);
+ _ephemeral = false;
+ _coordinator = coordinator;
+ _descriptor = desc;
+
+ _file = file;
+ _live = live;
+
+ try
+ {
+ init();
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Impossible
+ //
+ assert false;
+ }
+ }
+
+ //
+ // Construct a new, ephemeral Application
+ //
+ public Root(Coordinator coordinator, ApplicationDescriptor desc)
+ {
+ super(false, null, desc.name);
+ _ephemeral = true;
+ _coordinator = coordinator;
+ _descriptor = desc;
+
+ _tree = new JTree(this, true);
+ _treeModel = (DefaultTreeModel)_tree.getModel();
+ }
+
+ //
+ // Contruct a brand-new Application from an ephemeral Application
+ //
+ Root(Root root) throws UpdateFailedException
+ {
+ super(true, null, root._descriptor.name);
+ _ephemeral = false;
+ _coordinator = root._coordinator;
+ _descriptor = root._descriptor;
+
+ assert root._ephemeral;
+ init();
+ }
+
+ private void init() throws UpdateFailedException
+ {
+ _resolver = new Utils.Resolver(_descriptor.variables);
+ _resolver.put("application", _descriptor.name);
+
+ _origVariables = _descriptor.variables;
+ _origDescription = _descriptor.description;
+ _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
+
+ _replicaGroups = new ReplicaGroups(this, _descriptor.replicaGroups);
+ _serviceTemplates = new ServiceTemplates(this, _descriptor.serviceTemplates);
+ _serverTemplates = new ServerTemplates(this, _descriptor.serverTemplates);
+ _nodes = new Nodes(this, _descriptor.nodes);
+
+ _children.add(_nodes);
+ _children.add(_replicaGroups);
+ _children.add(_serverTemplates);
+ _children.add(_serviceTemplates);
+
+ _tree = new JTree(this, true);
+ _treeModel = (DefaultTreeModel)_tree.getModel();
+ }
+
+
+ static public ApplicationDescriptor
+ copyDescriptor(ApplicationDescriptor ad)
+ {
+ ApplicationDescriptor copy = (ApplicationDescriptor)ad.clone();
+
+ copy.replicaGroups =
+ ReplicaGroups.copyDescriptors(copy.replicaGroups);
+
+ copy.serverTemplates =
+ ServerTemplates.copyDescriptors(copy.serverTemplates);
+
+ copy.serviceTemplates =
+ ServiceTemplates.copyDescriptors(copy.serviceTemplates);
+
+ copy.nodes = Nodes.copyDescriptors(copy.nodes);
+
+ copy.distrib = (DistributionDescriptor)copy.distrib.clone();
+ return copy;
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (ApplicationEditor)
+ getEditor(ApplicationEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new ApplicationEditor(_coordinator.getMainFrame());
+ }
+
+ public TreeNode findNodeLike(TreePath path, boolean exactMatch)
+ {
+ TreeNode result = null;
+ if(path == null)
+ {
+ return null;
+ }
+
+ for(int i = 0; i < path.getPathCount(); ++i)
+ {
+ TreeNode node = (TreeNode)path.getPathComponent(i);
+
+ if(result == null)
+ {
+ if(node.getId().equals(_id))
+ {
+ result = this;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ TreeNode newNode = result.findChildLike(node);
+ if(newNode == null)
+ {
+ if(exactMatch)
+ {
+ return null;
+ }
+ else
+ {
+ return result;
+ }
+ }
+ else
+ {
+ result = newNode;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ //
+ // Check that this node is attached to the tree
+ //
+ public boolean hasNode(TreeNode node)
+ {
+ while(node != this)
+ {
+ TreeNode parent = (TreeNode)node.getParent();
+ if(parent == null || parent.getIndex(node) == -1)
+ {
+ return false;
+ }
+ else
+ {
+ node = parent;
+ }
+ }
+ return true;
+ }
+
+ public void setSelectedNode(TreeNode node)
+ {
+ _tree.setSelectionPath(node.getPath());
+ }
+
+ public TreeNode getSelectedNode()
+ {
+ TreePath path = _tree.getSelectionPath();
+ if(path == null)
+ {
+ return null;
+ }
+ else
+ {
+ return (TreeNode)path.getLastPathComponent();
+ }
+ }
+
+ public void selectServer(String nodeName, String serverId)
+ {
+ TreeNode target = _nodes;
+ if(target != null)
+ {
+ Node node = (Node)target.findChild(nodeName);
+ if(node != null)
+ {
+ target = node;
+ Server server = (Server)target.findChild(serverId);
+ if(server != null)
+ {
+ target = server;
+ }
+ }
+ setSelectedNode(target);
+ }
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setOpenIcon(
+ Utils.getIcon("/icons/16x16/application_open.png"));
+ _cellRenderer.setClosedIcon(
+ Utils.getIcon("/icons/16x16/application_closed.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+
+ actions[COPY] = true;
+ actions[DELETE] = true;
+
+ Object descriptor = _coordinator.getClipboard();
+ if(descriptor != null)
+ {
+ actions[PASTE] = descriptor instanceof ApplicationDescriptor;
+ }
+ if(!_ephemeral)
+ {
+ actions[SHOW_VARS] = true;
+ actions[SUBSTITUTE_VARS] = true;
+ actions[NEW_NODE] = true;
+ actions[NEW_REPLICA_GROUP] = true;
+ actions[NEW_TEMPLATE_SERVER] = true;
+ actions[NEW_TEMPLATE_SERVER_ICEBOX] = true;
+ actions[NEW_TEMPLATE_SERVICE] = true;
+ }
+ return actions;
+ }
+
+ public JPopupMenu getPopupMenu()
+ {
+ ApplicationActions actions = _coordinator.getActionsForPopup();
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_NODE));
+ _popup.add(actions.get(NEW_REPLICA_GROUP));
+ _popup.addSeparator();
+ _popup.add(actions.get(NEW_TEMPLATE_SERVER));
+ _popup.add(actions.get(NEW_TEMPLATE_SERVER_ICEBOX));
+ _popup.addSeparator();
+ _popup.add(actions.get(NEW_TEMPLATE_SERVICE));
+ }
+ actions.setTarget(this);
+ return _popup;
+ }
+
+ public void copy()
+ {
+ _coordinator.setClipboard(copyDescriptor(_descriptor));
+ _coordinator.getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+ public void paste()
+ {
+ _coordinator.pasteApplication();
+ }
+ public void newNode()
+ {
+ _nodes.newNode();
+ }
+ public void newReplicaGroup()
+ {
+ _replicaGroups.newReplicaGroup();
+ }
+ public void newTemplateServer()
+ {
+ _serverTemplates.newTemplateServer();
+ }
+ public void newTemplateServerIceBox()
+ {
+ _serverTemplates.newTemplateServerIceBox();
+ }
+ public void newTemplateService()
+ {
+ _serviceTemplates.newTemplateService();
+ }
+
+ public void save()
+ {
+ if(_live)
+ {
+ saveToRegistry();
+ }
+ else if(_file != null)
+ {
+ File file = _coordinator.saveToFile(false, this, _file);
+ if(file != null)
+ {
+ _file = file;
+ commit();
+ _coordinator.getSaveAction().setEnabled(false);
+ _coordinator.getDiscardUpdatesAction().setEnabled(false);
+ }
+ }
+ else
+ {
+ assert false;
+ }
+ }
+
+ public void saveToRegistry()
+ {
+ //
+ // To be run in GUI thread when exclusive write access is acquired
+ //
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ try
+ {
+ if(_live && _canUseUpdateDescriptor)
+ {
+ ApplicationUpdateDescriptor updateDescriptor = createUpdateDescriptor();
+ if(updateDescriptor != null)
+ {
+ _coordinator.getSession().updateApplication(updateDescriptor);
+ commit();
+ _skipUpdates++;
+ }
+ }
+ else
+ {
+ //
+ // Add or sync application
+ //
+ if(_coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id) == null)
+ {
+ assert _live == false;
+ _coordinator.getSession().addApplication(_descriptor);
+ commit();
+ liveReset();
+ _coordinator.addLiveApplication(Root.this);
+ }
+ else
+ {
+ _coordinator.getSession().syncApplication(_descriptor);
+ commit();
+
+ if(_live)
+ {
+ liveReset();
+ _skipUpdates++;
+ }
+ else
+ {
+ //
+ // Make this tab live or close it if there is one already open
+ //
+ ApplicationPane app = _coordinator.getLiveApplication(_id);
+ if(app == null)
+ {
+ liveReset();
+ _coordinator.addLiveApplication(Root.this);
+ }
+ else
+ {
+ boolean selected = isSelected();
+ _coordinator.getMainPane().removeApplication(Root.this);
+ if(selected)
+ {
+ _coordinator.getMainPane().setSelectedComponent(app);
+ }
+ }
+ }
+ }
+ }
+ if(isSelected())
+ {
+ _coordinator.getSaveAction().setEnabled(false);
+ _coordinator.getDiscardUpdatesAction().setEnabled(false);
+ }
+ }
+ catch(DeploymentException e)
+ {
+ JOptionPane.showMessageDialog(
+ _coordinator.getMainFrame(),
+ "Application '" + _id + "': "+ e.reason,
+ "Deployment Exception",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ catch(ApplicationNotExistException e)
+ {
+ //
+ // Should never happen
+ //
+ JOptionPane.showMessageDialog(
+ _coordinator.getMainFrame(),
+ "Application '" + _id + "' was not found in the IceGrid registry",
+ "Deployment Exception",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ catch(AccessDeniedException e)
+ {
+ //
+ // Should never happen
+ //
+ _coordinator.accessDenied(e);
+ }
+ finally
+ {
+ _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ _coordinator.releaseExclusiveWriteAccess();
+ }
+ }
+ };
+
+ try
+ {
+ _coordinator.acquireExclusiveWriteAccess(runnable);
+ }
+ catch(AccessDeniedException e)
+ {
+ _coordinator.accessDenied(e);
+ }
+ }
+
+ public void saveToFile()
+ {
+ File file = _coordinator.saveToFile(true, this, _file);
+ if(file != null)
+ {
+ _file = file;
+ _live = false;
+
+ _coordinator.removeLiveApplication(_id);
+ _coordinator.getMainPane().resetIcon(this);
+
+ commit();
+ _coordinator.getSaveAction().setEnabled(false);
+ _coordinator.getDiscardUpdatesAction().setEnabled(false);
+ }
+ }
+
+ public void discardUpdates()
+ {
+ if(_live)
+ {
+ ApplicationDescriptor desc = _coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id);
+ assert desc != null;
+ desc = IceGridGUI.Application.Root.copyDescriptor(desc);
+
+ Root newRoot = new Root(_coordinator, desc, true, null);
+ ApplicationPane app = _coordinator.getMainPane().findApplication(this);
+ assert app != null;
+ app.setRoot(newRoot);
+
+ TreeNode node = newRoot.findNodeLike(_tree.getSelectionPath(), false);
+ if(node == null)
+ {
+ newRoot.setSelectedNode(newRoot);
+ }
+ else
+ {
+ newRoot.setSelectedNode(node);
+ }
+ }
+ else if(_file != null)
+ {
+ //
+ // TODO: re-read file
+ //
+ }
+ else
+ {
+ assert false;
+ }
+ _coordinator.getCurrentTab().selected();
+ }
+
+ private void liveReset()
+ {
+ _live = true;
+ _file = null;
+ _coordinator.getMainPane().resetIcon(this);
+ }
+
+
+ private ApplicationUpdateDescriptor createUpdateDescriptor()
+ {
+ ApplicationUpdateDescriptor update = new ApplicationUpdateDescriptor();
+ update.name = _descriptor.name;
+ if(_editable.isModified())
+ {
+ //
+ // Diff description
+ //
+ if(!_descriptor.description.equals(_origDescription))
+ {
+ update.description =
+ new IceGrid.BoxedString(_descriptor.description);
+ }
+
+ //
+ // Diff variables
+ //
+ update.variables = (java.util.TreeMap)_descriptor.variables.clone();
+ java.util.List removeVariables = new java.util.LinkedList();
+
+ java.util.Iterator p = _origVariables.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ Object key = entry.getKey();
+ Object newValue = update.variables.get(key);
+ if(newValue == null)
+ {
+ removeVariables.add(key);
+ }
+ else
+ {
+ Object value = entry.getValue();
+ if(newValue.equals(value))
+ {
+ update.variables.remove(key);
+ }
+ }
+ }
+ update.removeVariables = (String[])removeVariables.toArray(new String[0]);
+
+ //
+ // Diff distribution
+ //
+ if(!_descriptor.distrib.equals(_origDistrib))
+ {
+ update.distrib = new IceGrid.BoxedDistributionDescriptor(
+ _descriptor.distrib);
+ }
+ }
+ else
+ {
+ update.variables = new java.util.TreeMap();
+ update.removeVariables = new String[0];
+ }
+
+ //
+ // Replica Groups
+ //
+ update.removeReplicaGroups = _replicaGroups.getEditable().removedElements();
+ update.replicaGroups = _replicaGroups.getUpdates();
+
+ //
+ // Server Templates
+ //
+ update.removeServerTemplates = _serverTemplates.getEditable().removedElements();
+ update.serverTemplates = _serverTemplates.getUpdates();
+
+ //
+ // Service Templates
+ //
+ update.removeServiceTemplates = _serviceTemplates.getEditable().removedElements();
+ update.serviceTemplates =_serviceTemplates.getUpdates();
+
+ //
+ // Nodes
+ //
+ update.removeNodes = _nodes.getEditable().removedElements();
+ update.nodes = _nodes.getUpdates();
+
+
+ //
+ // Return null if nothing changed
+ //
+ if(!_editable.isModified() &&
+ update.removeReplicaGroups.length == 0 &&
+ update.replicaGroups.size() == 0 &&
+ update.removeServerTemplates.length == 0 &&
+ update.serverTemplates.size() == 0 &&
+ update.removeServiceTemplates.length == 0 &&
+ update.serviceTemplates.size() == 0 &&
+ update.removeNodes.length == 0 &&
+ update.nodes.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+ return update;
+ }
+ }
+
+ private void commit()
+ {
+ _updated = false;
+ _registryUpdatesEnabled = true;
+ _canUseUpdateDescriptor = true;
+
+ assert _concurrentUpdates.size() == 0;
+
+ _editable.commit();
+ _origVariables = _descriptor.variables;
+ _origDescription = _descriptor.description;
+ _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
+
+ _nodes.commit();
+ _replicaGroups.commit();
+ _serverTemplates.commit();
+ _serviceTemplates.commit();
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ public void destroy()
+ {
+ if(_ephemeral || (!_live && _file == null))
+ {
+ _coordinator.getMainPane().removeApplication(this);
+ }
+ else if(_live)
+ {
+ int confirm = JOptionPane.showConfirmDialog(
+ _coordinator.getMainFrame(),
+ "You are about to remove application '" + _id + "' from the IceGrid registry. "
+ + "Do you want to proceed?",
+ "Remove Confirmation",
+ JOptionPane.YES_NO_OPTION);
+
+ if(confirm == JOptionPane.YES_OPTION)
+ {
+ if(_coordinator.removeApplicationFromRegistry(_id))
+ {
+ _coordinator.getMainPane().removeApplication(this);
+ }
+ }
+ }
+ else
+ {
+ assert _file != null;
+
+ int confirm = JOptionPane.showConfirmDialog(
+ _coordinator.getMainFrame(),
+ "You are about to remove application '" + _id + "' and its associated file. "
+ + "Do you want to proceed?",
+ "Remove Confirmation",
+ JOptionPane.YES_NO_OPTION);
+
+ if(confirm == JOptionPane.YES_OPTION)
+ {
+ if(_file.delete())
+ {
+ _coordinator.getMainPane().removeApplication(this);
+ }
+ }
+ }
+ }
+
+ public boolean update(ApplicationUpdateDescriptor desc)
+ {
+ assert _live == true;
+
+ if(_skipUpdates > 0)
+ {
+ _skipUpdates--;
+ return false;
+ }
+
+ if(!_registryUpdatesEnabled)
+ {
+ if(_updated)
+ {
+ _canUseUpdateDescriptor = false;
+ }
+ else
+ {
+ _concurrentUpdates.add(desc);
+ }
+ return false;
+ }
+
+ try
+ {
+ //
+ // Description
+ //
+ if(desc.description != null)
+ {
+ _descriptor.description = desc.description.value;
+ _origDescription = _descriptor.description;
+ }
+
+ //
+ // Variables
+ //
+ for(int i = 0; i < desc.removeVariables.length; ++i)
+ {
+ _descriptor.variables.remove(desc.removeVariables[i]);
+ }
+ _descriptor.variables.putAll(desc.variables);
+
+ //
+ // Distrib
+ //
+ if(desc.distrib != null)
+ {
+ _descriptor.distrib = desc.distrib.value;
+ _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone();
+ }
+
+ //
+ // Replica groups
+ //
+ for(int i = 0; i < desc.removeReplicaGroups.length; ++i)
+ {
+ _descriptor.replicaGroups.remove(desc.
+ removeReplicaGroups[i]);
+ }
+ _descriptor.replicaGroups.addAll(desc.replicaGroups);
+ _replicaGroups.update(desc.replicaGroups,
+ desc.removeReplicaGroups);
+
+
+ //
+ // Service templates
+ //
+ for(int i = 0; i < desc.removeServiceTemplates.length; ++i)
+ {
+ _descriptor.serviceTemplates.remove(desc.
+ removeServiceTemplates[i]);
+ }
+ _descriptor.serviceTemplates.putAll(desc.serviceTemplates);
+ _serviceTemplates.update(desc.serviceTemplates,
+ desc.removeServiceTemplates);
+
+ //
+ // Server templates
+ //
+ for(int i = 0; i < desc.removeServerTemplates.length; ++i)
+ {
+ _descriptor.serverTemplates.remove(desc.removeServerTemplates[i]);
+ }
+ _descriptor.serverTemplates.putAll(desc.serverTemplates);
+ _serverTemplates.update(desc.serverTemplates,
+ desc.removeServerTemplates,
+ desc.serviceTemplates.keySet());
+
+ //
+ // Nodes
+ //
+ for(int i = 0; i < desc.removeNodes.length; ++i)
+ {
+ _descriptor.nodes.remove(desc.removeNodes[i]);
+ }
+
+ //
+ // Updates also _descriptor.nodes
+ //
+ _nodes.update(desc.nodes, desc.removeNodes,
+ desc.serverTemplates.keySet(),
+ desc.serviceTemplates.keySet());
+ }
+ catch(UpdateFailedException e)
+ {
+ //
+ // Received invalid update from IceGrid registry: a bug!
+ //
+ assert false;
+ }
+
+ return true;
+ }
+
+ public JTree getTree()
+ {
+ return _tree;
+ }
+
+ public DefaultTreeModel getTreeModel()
+ {
+ return _treeModel;
+ }
+
+ public Coordinator getCoordinator()
+ {
+ return _coordinator;
+ }
+
+ public boolean isSelectionListenerEnabled()
+ {
+ return _selectionListenerEnabled;
+ }
+
+ public void enableSelectionListener()
+ {
+ _selectionListenerEnabled = true;
+ }
+
+ public void disableSelectionListener()
+ {
+ _selectionListenerEnabled = false;
+ }
+
+ public void cancelEdit()
+ {
+ if(!_updated)
+ {
+ _registryUpdatesEnabled = true;
+
+ //
+ // Apply now any delayed concurrent update
+ //
+ java.util.Iterator p = _concurrentUpdates.iterator();
+ while(p.hasNext())
+ {
+ ApplicationUpdateDescriptor d = (ApplicationUpdateDescriptor)p.next();
+ boolean ok = update(d);
+ assert ok;
+ }
+ _concurrentUpdates.clear();
+ }
+ }
+
+ public boolean kill()
+ {
+ _live = false;
+
+ if(_registryUpdatesEnabled)
+ {
+ return true;
+ }
+ else
+ {
+ _coordinator.getMainPane().resetIcon(this);
+ return false;
+ }
+ }
+
+ public boolean isLive()
+ {
+ return _live;
+ }
+
+ public boolean hasFile()
+ {
+ return _file != null;
+ }
+
+ public boolean needsSaving()
+ {
+ return _updated;
+ }
+
+ Editor getEditor(Class c, TreeNode node)
+ {
+ Editor result = (Editor)_editorMap.get(c);
+ if(result == null)
+ {
+ result = node.createEditor();
+ _editorMap.put(c, result);
+ }
+ return result;
+ }
+
+ Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ ApplicationDescriptor saveDescriptor()
+ {
+ ApplicationDescriptor clone = (ApplicationDescriptor)_descriptor.clone();
+ clone.distrib = (IceGrid.DistributionDescriptor)clone.distrib.clone();
+ return clone;
+ }
+
+ void restoreDescriptor(ApplicationDescriptor clone)
+ {
+ _descriptor.name = clone.name;
+ _descriptor.variables = clone.variables;
+ _descriptor.distrib.icepatch = clone.distrib.icepatch;
+ _descriptor.distrib.directories = clone.distrib.directories;
+ _descriptor.description = clone.description;
+ }
+
+ public void write(XMLWriter writer) throws java.io.IOException
+ {
+ writer.writeStartTag("icegrid");
+
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", _id));
+
+ writer.writeStartTag("application", attributes);
+
+ writeVariables(writer, _descriptor.variables);
+
+ _serviceTemplates.write(writer);
+ _serverTemplates.write(writer);
+ _replicaGroups.write(writer);
+ _nodes.write(writer);
+
+ writer.writeEndTag("application");
+ writer.writeEndTag("icegrid");
+ }
+
+ //
+ // Methods called by editors; see also cancelEdit() above
+ //
+ void disableRegistryUpdates()
+ {
+ _registryUpdatesEnabled = false;
+ }
+
+ void updated()
+ {
+ _updated = true;
+ _concurrentUpdates.clear();
+
+ _coordinator.getSaveAction().setEnabled(_live || _file != null);
+ _coordinator.getDiscardUpdatesAction().setEnabled(_live || _file != null);
+
+ _coordinator.getSaveToRegistryAction().setEnabled(_coordinator.getSession() != null);
+ _coordinator.getSaveToFileAction().setEnabled(true);
+ }
+
+ void rebuild() throws UpdateFailedException
+ {
+ Utils.Resolver oldResolver = _resolver;
+ String oldId = _id;
+ _id = _descriptor.name;
+ _resolver = new Utils.Resolver(_descriptor.variables);
+ _resolver.put("application", _id);
+
+ try
+ {
+ _nodes.rebuild();
+ }
+ catch(UpdateFailedException e)
+ {
+ _id = oldId;
+ _resolver = oldResolver;
+ throw e;
+ }
+ }
+
+ //
+ // Called when a server-template is deleted, to remove all
+ // corresponding instances.
+ //
+ void removeServerInstances(String templateId)
+ {
+ _nodes.removeServerInstances(templateId);
+ }
+
+ //
+ // Called when a service-template is deleted, to remove all
+ // corresponding instances
+ //
+ void removeServiceInstances(String templateId)
+ {
+ _nodes.removeServiceInstances(templateId);
+ _serverTemplates.removeServiceInstances(templateId);
+ }
+
+
+ ServerTemplate findServerTemplate(String id)
+ {
+ return (ServerTemplate)_serverTemplates.findChild(id);
+ }
+
+ ServiceTemplate findServiceTemplate(String id)
+ {
+ return (ServiceTemplate)_serviceTemplates.findChild(id);
+ }
+
+ ReplicaGroup findReplicaGroup(String id)
+ {
+ return (ReplicaGroup)_replicaGroups.findChild(id);
+ }
+
+ Node findNode(String id)
+ {
+ return (Node)_nodes.findChild(id);
+ }
+
+ java.util.List findServerInstances(String template)
+ {
+ return _nodes.findServerInstances(template);
+ }
+
+ java.util.List findServiceInstances(String template)
+ {
+ java.util.List result = _serverTemplates.findServiceInstances(template);
+ result.addAll(_nodes.findServiceInstances(template));
+ return result;
+ }
+
+ TemplateDescriptor findServerTemplateDescriptor(String templateName)
+ {
+ return (TemplateDescriptor)
+ _descriptor.serverTemplates.get(templateName);
+ }
+
+ TemplateDescriptor findServiceTemplateDescriptor(String templateName)
+ {
+ return (TemplateDescriptor)
+ _descriptor.serviceTemplates.get(templateName);
+ }
+
+ ServerTemplates getServerTemplates()
+ {
+ return _serverTemplates;
+ }
+
+ ServiceTemplates getServiceTemplates()
+ {
+ return _serviceTemplates;
+ }
+
+ ReplicaGroups getReplicaGroups()
+ {
+ return _replicaGroups;
+ }
+
+ Root getRoot()
+ {
+ return this;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ //
+ // Should only be used for reading
+ //
+ java.util.Map getVariables()
+ {
+ return _descriptor.variables;
+ }
+
+ private boolean isSelected()
+ {
+ if(_coordinator.getCurrentTab() instanceof ApplicationPane)
+ {
+ return ((ApplicationPane)_coordinator.getCurrentTab()).getRoot() == Root.this;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ private Coordinator _coordinator;
+
+ //
+ // 'this' is the root of the tree
+ //
+ private JTree _tree;
+ private DefaultTreeModel _treeModel;
+ private final boolean _ephemeral;
+ private Utils.Resolver _resolver;
+
+ private boolean _live;
+
+ //
+ // null when this application is not tied to a file
+ //
+ private File _file;
+
+ private ApplicationDescriptor _descriptor;
+
+ //
+ // Keeps original version (as shallow copies) to be able to build
+ // ApplicationUpdateDescriptor. Only used when _live == true
+ //
+ private java.util.TreeMap _origVariables;
+ private String _origDescription;
+ private DistributionDescriptor _origDistrib;
+
+ //
+ // When this application (and children) is being updated, we
+ // no longer apply updates from the Registry. Only meaningful when
+ // _live == true
+ //
+ private boolean _registryUpdatesEnabled = true;
+
+ //
+ // True when any update was applies to this application
+ // (including children)
+ //
+ private boolean _updated = false;
+
+ //
+ // Updates saved when _updated == false and
+ // _registryUpdatesEnabled == false
+ //
+ private java.util.List _concurrentUpdates = new java.util.LinkedList();
+
+ //
+ // When _live is true and _canUseUpdateDescriptor is true, we can
+ // save the updates using an ApplicationUpdateDescriptor
+ //
+ private boolean _canUseUpdateDescriptor = true;
+ //
+ // Updates to skip (because already applied locally)
+ //
+ private int _skipUpdates = 0;
+
+
+ private Nodes _nodes;
+ private ReplicaGroups _replicaGroups;
+ private ServerTemplates _serverTemplates;
+ private ServiceTemplates _serviceTemplates;
+
+ private boolean _selectionListenerEnabled = true;
+
+ private ApplicationEditor _editor;
+
+ //
+ // Map editor-class to Editor object
+ //
+ private java.util.Map _editorMap = new java.util.HashMap();
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGridGUI/Application/Server.java b/java/src/IceGridGUI/Application/Server.java
new file mode 100755
index 00000000000..f327d8b41ef
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Server.java
@@ -0,0 +1,731 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+
+import javax.swing.Icon;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// We can have 4 kinds of servers:
+// - Plain server (no template)
+// - Icebox server (no template)
+// - Server instance
+// - Icebox instance
+//
+class Server extends Communicator implements TemplateInstance
+{
+ static public ServerDescriptor
+ copyDescriptor(ServerDescriptor sd)
+ {
+ ServerDescriptor copy = (ServerDescriptor)sd.clone();
+
+ copy.adapters = Adapter.copyDescriptors(copy.adapters);
+ copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs);
+
+ //
+ // Update to properties is not atomic because of Adapter endpoints
+ // (and possibly other properties set through a PropertiesHolder)
+ //
+ copy.properties = (java.util.LinkedList)copy.properties.clone();
+ copy.distrib = (DistributionDescriptor)copy.distrib.clone();
+
+ if(copy instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor ib = (IceBoxDescriptor)copy;
+ ib.services = Service.copyDescriptors(ib.services);
+ }
+ return copy;
+ }
+
+ static public ServerInstanceDescriptor
+ copyDescriptor(ServerInstanceDescriptor sid)
+ {
+ return (ServerInstanceDescriptor)sid.clone();
+ }
+
+ static public void shallowRestore(ServerDescriptor from, ServerDescriptor into)
+ {
+ //
+ // When editing a server or server template, if we update properties,
+ // we replace the entire field
+ into.properties = from.properties;
+
+ into.description = from.description;
+ into.id = from.id;
+ into.exe = from.exe;
+ into.options = from.options;
+ into.envs = from.envs;
+ into.activation = from.activation;
+ into.activationTimeout = from.activationTimeout;
+ into.deactivationTimeout = from.deactivationTimeout;
+ into.applicationDistrib = from.applicationDistrib;
+ into.distrib.icepatch = from.distrib.icepatch;
+ into.distrib.directories = from.distrib.directories;
+ }
+
+ static public ServerDescriptor newServerDescriptor()
+ {
+ return new ServerDescriptor(
+ new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ "",
+ "NewServer",
+ "",
+ "",
+ new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ "manual",
+ "",
+ "",
+ true,
+ new DistributionDescriptor("", new java.util.LinkedList()));
+ }
+
+ static public IceBoxDescriptor newIceBoxDescriptor()
+ {
+ AdapterDescriptor serviceManager = new AdapterDescriptor(
+ "IceBox.ServiceManager",
+ "",
+ "", // direct-adapter by default
+ "",
+ true,
+ true,
+ new java.util.LinkedList()
+ );
+
+ java.util.LinkedList adapterList = new java.util.LinkedList();
+ adapterList.add(serviceManager);
+
+ PropertyDescriptor pd =
+ new PropertyDescriptor("IceBox.ServiceManager.Endpoints",
+ "tcp -h 127.0.0.1");
+ java.util.LinkedList properties = new java.util.LinkedList();
+ properties.add(pd);
+
+ return new IceBoxDescriptor(
+ adapterList,
+ properties,
+ new java.util.LinkedList(),
+ "",
+ "NewIceBox",
+ "",
+ "",
+ new java.util.LinkedList(),
+ new java.util.LinkedList(),
+ "manual",
+ "",
+ "",
+ true,
+ new DistributionDescriptor("", new java.util.LinkedList()),
+ new java.util.LinkedList()
+ );
+ }
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+
+ Object clipboard = getCoordinator().getClipboard();
+ if(clipboard != null &&
+ (clipboard instanceof ServerDescriptor
+ || clipboard instanceof ServerInstanceDescriptor))
+ {
+ actions[PASTE] = true;
+ }
+
+ actions[DELETE] = true;
+ if(!_ephemeral)
+ {
+ actions[SHOW_VARS] = true;
+ actions[SUBSTITUTE_VARS] = true;
+ }
+
+ if(_instanceDescriptor == null)
+ {
+ actions[NEW_ADAPTER] = !_services.initialized();
+ actions[NEW_SERVICE] = _services.initialized();
+ actions[NEW_DBENV] = !_services.initialized();
+ }
+
+ return actions;
+ }
+ public JPopupMenu getPopupMenu()
+ {
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_ADAPTER));
+ _popup.add(actions.get(NEW_DBENV));
+ _popup.add(actions.get(NEW_SERVICE));
+ _popup.add(actions.get(NEW_SERVICE_FROM_TEMPLATE));
+ }
+ actions.setTarget(this);
+ return _popup;
+ }
+ public void copy()
+ {
+ if(_instanceDescriptor != null)
+ {
+ getCoordinator().setClipboard(copyDescriptor(_instanceDescriptor));
+ }
+ else
+ {
+ getCoordinator().setClipboard(copyDescriptor(_serverDescriptor));
+ }
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+
+ public Editor getEditor()
+ {
+ //
+ // Pick the appropriate editor
+ //
+ Editor editor = null;
+ if(_instanceDescriptor == null)
+ {
+ if(_serverEditor == null)
+ {
+ _serverEditor = (ServerEditor)getRoot().getEditor(ServerEditor.class, this);
+ }
+ _serverEditor.show(this);
+ return _serverEditor;
+ }
+ else
+ {
+ if(_serverInstanceEditor == null)
+ {
+ _serverInstanceEditor = (ServerInstanceEditor)
+ getRoot().getEditor(ServerInstanceEditor.class, this);
+ }
+ _serverInstanceEditor.show(this);
+ return _serverInstanceEditor;
+ }
+ }
+
+ protected Editor createEditor()
+ {
+ if(_instanceDescriptor == null)
+ {
+ return new ServerEditor(getCoordinator().getMainFrame());
+ }
+ else
+ {
+ return new ServerInstanceEditor(getCoordinator().getMainFrame());
+ }
+ }
+
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ //
+ // Initialization
+ //
+ _cellRenderer = new DefaultTreeCellRenderer();
+
+ _serverIcon = Utils.getIcon("/icons/16x16/server_inactive.png");
+ _iceboxServerIcon = Utils.getIcon("/icons/16x16/icebox_server_inactive.png");
+ }
+
+ boolean icebox = _serverDescriptor instanceof IceBoxDescriptor;
+
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(icebox ? _iceboxServerIcon : _serverIcon);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(icebox ? _iceboxServerIcon : _serverIcon);
+ }
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ public void destroy()
+ {
+ Node node = (Node)_parent;
+
+ if(_ephemeral)
+ {
+ node.removeChild(this);
+ }
+ else
+ {
+ if(_instanceDescriptor != null)
+ {
+ node.removeDescriptor(_instanceDescriptor);
+ }
+ else
+ {
+ node.removeDescriptor(_serverDescriptor);
+ }
+ node.removeChild(this);
+ node.getEditable().removeElement(_id);
+ getRoot().updated();
+ }
+ }
+
+
+ public Object getDescriptor()
+ {
+ if(_instanceDescriptor != null)
+ {
+ return _instanceDescriptor;
+ }
+ else
+ {
+ return _serverDescriptor;
+ }
+ }
+
+ public Object saveDescriptor()
+ {
+ if(_instanceDescriptor != null)
+ {
+ return _instanceDescriptor.clone();
+ }
+ else
+ {
+ ServerDescriptor clone = (ServerDescriptor)_serverDescriptor.clone();
+ clone.distrib = (DistributionDescriptor)clone.distrib.clone();
+ return clone;
+ }
+ }
+
+ public void restoreDescriptor(Object savedDescriptor)
+ {
+ if(_instanceDescriptor != null)
+ {
+ ServerInstanceDescriptor copy = (ServerInstanceDescriptor)savedDescriptor;
+
+ _instanceDescriptor.template = copy.template;
+ _instanceDescriptor.parameterValues = copy.parameterValues;
+
+ ServerTemplate t = getRoot().findServerTemplate(_instanceDescriptor.template);
+ _serverDescriptor = (ServerDescriptor)
+ ((TemplateDescriptor)t.getDescriptor()).descriptor;
+ }
+ else
+ {
+ shallowRestore((ServerDescriptor)savedDescriptor, _serverDescriptor);
+ }
+ }
+
+ //
+ // Builds the server and all its sub-tree
+ //
+ Server(boolean brandNew, TreeNode parent, String serverId,
+ Utils.Resolver resolver, ServerInstanceDescriptor instanceDescriptor,
+ ServerDescriptor serverDescriptor) throws UpdateFailedException
+ {
+ super(parent, serverId);
+ _ephemeral = false;
+ _editable = new Editable(brandNew);
+ rebuild(resolver, instanceDescriptor, serverDescriptor);
+ }
+
+ Server(TreeNode parent, String serverId, ServerInstanceDescriptor instanceDescriptor,
+ ServerDescriptor serverDescriptor)
+ {
+ super(parent, serverId);
+ _ephemeral = true;
+ _editable = null;
+ try
+ {
+ rebuild(null, instanceDescriptor, serverDescriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
+ }
+
+
+ static java.util.List createAttributes(ServerDescriptor descriptor)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("id", descriptor.id));
+ if(descriptor.activation.length() > 0)
+ {
+ attributes.add(createAttribute("activation",
+ descriptor.activation));
+ }
+ if(descriptor.activationTimeout.length() > 0)
+ {
+ attributes.add(createAttribute("activation-timeout",
+ descriptor.activationTimeout));
+ }
+ if(!descriptor.applicationDistrib)
+ {
+ attributes.add(createAttribute("application-distrib", "false"));
+ }
+ if(descriptor.deactivationTimeout.length() > 0)
+ {
+ attributes.add(createAttribute("deactivation-timeout",
+ descriptor.deactivationTimeout));
+ }
+ if(descriptor.exe.length() > 0)
+ {
+ attributes.add(createAttribute("exe", descriptor.exe));
+ }
+ if(descriptor.pwd.length() > 0)
+ {
+ attributes.add(createAttribute("pwd", descriptor.pwd));
+ }
+
+ return attributes;
+ }
+
+ static void writeOptions(XMLWriter writer, java.util.List options)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = options.iterator();
+ while(p.hasNext())
+ {
+ writer.writeElement("option", (String)p.next());
+ }
+ }
+
+ static void writeEnvs(XMLWriter writer, java.util.List envs)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = envs.iterator();
+ while(p.hasNext())
+ {
+ writer.writeElement("env", (String)p.next());
+ }
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ if(_instanceDescriptor != null)
+ {
+ TemplateDescriptor templateDescriptor
+ = getRoot().findServerTemplateDescriptor(_instanceDescriptor.template);
+
+ java.util.LinkedList attributes = parameterValuesToAttributes(
+ _instanceDescriptor.parameterValues, templateDescriptor.parameters);
+ attributes.addFirst(createAttribute("template", _instanceDescriptor.template));
+
+
+ writer.writeElement("server-instance", attributes);
+ }
+ else if(isIceBox())
+ {
+ writer.writeStartTag("icebox",
+ createAttributes(_serverDescriptor));
+
+ if(_serverDescriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _serverDescriptor.description);
+ }
+ writeOptions(writer, _serverDescriptor.options);
+ writeEnvs(writer, _serverDescriptor.envs);
+ writeProperties(writer, _serverDescriptor.properties);
+ writeDistribution(writer, _serverDescriptor.distrib);
+
+ _adapters.write(writer);
+ _services.write(writer);
+ writer.writeEndTag("icebox");
+ }
+ else
+ {
+ writer.writeStartTag("server", createAttributes(_serverDescriptor));
+
+ if(_serverDescriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _serverDescriptor.description);
+ }
+
+ writeOptions(writer, _serverDescriptor.options);
+ writeEnvs(writer, _serverDescriptor.envs);
+ writeProperties(writer, _serverDescriptor.properties);
+ writeDistribution(writer, _serverDescriptor.distrib);
+
+ _adapters.write(writer);
+ _dbEnvs.write(writer);
+ writer.writeEndTag("server");
+ }
+ }
+ }
+
+
+ boolean isIceBox()
+ {
+ return _serverDescriptor instanceof IceBoxDescriptor;
+ }
+
+ static private class Backup
+ {
+ Backup(Editable ne)
+ {
+ nodeEditable = ne;
+ }
+
+ Editable nodeEditable;
+ java.util.Map parameterValues;
+ }
+
+ public Object rebuild(java.util.List editables) throws UpdateFailedException
+ {
+ Backup backup = new Backup(((Node)_parent).getEditable());
+ Node node = (Node)_parent;
+ Server newServer = null;
+
+ if(_instanceDescriptor != null)
+ {
+ TemplateDescriptor templateDescriptor
+ = getRoot().findServerTemplateDescriptor(_instanceDescriptor.template);
+
+ java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters);
+ if(!parameters.equals(_instanceDescriptor.parameterValues.keySet()))
+ {
+ backup.parameterValues = _instanceDescriptor.parameterValues;
+ _instanceDescriptor.parameterValues = EditorBase.makeParameterValues(
+ _instanceDescriptor.parameterValues, templateDescriptor.parameters);
+ }
+ newServer = node.createServer(false, _instanceDescriptor);
+ }
+ else
+ {
+ newServer = node.createServer(false, _serverDescriptor);
+ }
+
+ if(_id.equals(newServer.getId()))
+ {
+ //
+ // A simple update. We can't simply rebuild server because
+ // we need to keep a backup
+ //
+ if(_editable.isModified())
+ {
+ newServer.getEditable().markModified();
+ }
+
+ node.removeChild(this);
+ try
+ {
+ node.insertChild(newServer, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false; // impossible, we just removed a child with
+ // this id
+ }
+
+ if(backup.parameterValues != null)
+ {
+ editables.add(newServer.getEditable());
+ }
+ }
+ else
+ {
+ newServer.getEditable().markNew();
+ node.removeChild(this);
+ node.getEditable().removeElement(_id);
+ try
+ {
+ node.insertChild(newServer, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ restore(backup);
+ throw e;
+ }
+ }
+
+ return backup;
+ }
+
+ public void restore(Object backupObj)
+ {
+ Backup backup = (Backup)backupObj;
+ Node node = (Node)_parent;
+
+ node.getEditable().restore(backup.nodeEditable);
+
+ if(_instanceDescriptor != null && backup.parameterValues != null)
+ {
+ _instanceDescriptor.parameterValues = backup.parameterValues;
+ }
+
+ TreeNode badServer = null;
+
+ if(_instanceDescriptor != null)
+ {
+ badServer = node.findChildWithDescriptor(_instanceDescriptor);
+ }
+ else
+ {
+ badServer = node.findChildWithDescriptor(_serverDescriptor);
+ }
+
+ if(badServer != null)
+ {
+ node.removeChild(badServer);
+ }
+
+ try
+ {
+ node.insertChild(this, true);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false; // impossible
+ }
+ }
+
+ void commit()
+ {
+ _editable.commit();
+ }
+
+
+ void setServerDescriptor(ServerDescriptor descriptor)
+ {
+ _serverDescriptor = descriptor;
+ }
+
+ //
+ // Update the server and all its subtree
+ //
+ void rebuild(Utils.Resolver resolver,
+ ServerInstanceDescriptor instanceDescriptor,
+ ServerDescriptor serverDescriptor) throws UpdateFailedException
+ {
+ assert serverDescriptor != null;
+ _resolver = resolver;
+ _instanceDescriptor = instanceDescriptor;
+ _serverDescriptor = serverDescriptor;
+
+ _adapters.clear();
+ _dbEnvs.clear();
+ _services.clear();
+
+ if(!_ephemeral)
+ {
+ _adapters.init(_serverDescriptor.adapters);
+ if(_serverDescriptor instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)_serverDescriptor;
+ _services.init(iceBoxDescriptor.services);
+
+ //
+ // IceBox has not dbEnv
+ //
+ assert _serverDescriptor.dbEnvs.size() == 0;
+ }
+ else
+ {
+ _dbEnvs.init(_serverDescriptor.dbEnvs);
+ }
+ }
+ }
+
+
+ ServerInstanceDescriptor getInstanceDescriptor()
+ {
+ return _instanceDescriptor;
+ }
+
+ ServerDescriptor getServerDescriptor()
+ {
+ return _serverDescriptor;
+ }
+
+ CommunicatorDescriptor getCommunicatorDescriptor()
+ {
+ return _serverDescriptor;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ boolean isEditable()
+ {
+ return _instanceDescriptor == null;
+ }
+
+ Editable getEditable()
+ {
+ return _editable;
+ }
+
+ Editable getEnclosingEditable()
+ {
+ return _editable;
+ }
+
+ java.util.List findInstances(boolean includeTemplate)
+ {
+ java.util.List result = new java.util.LinkedList();
+ result.add(this);
+ return result;
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ public String toString()
+ {
+ if(_instanceDescriptor == null || _ephemeral)
+ {
+ return super.toString();
+ }
+ else
+ {
+ return _id + ": " + _instanceDescriptor.template + "<>";
+ }
+ }
+
+ private ServerInstanceDescriptor _instanceDescriptor;
+ private ServerDescriptor _serverDescriptor;
+ private final boolean _ephemeral;
+
+ private ServerEditor _serverEditor;
+ private ServerInstanceEditor _serverInstanceEditor;
+
+ private Utils.Resolver _resolver;
+ private Editable _editable;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private Icon _serverIcon;
+ static private Icon _iceboxServerIcon;
+
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGrid/TreeNode/ServerEditor.java b/java/src/IceGridGUI/Application/ServerEditor.java
index ef22901e457..b2499da21e2 100755
--- a/java/src/IceGrid/TreeNode/ServerEditor.java
+++ b/java/src/IceGridGUI/Application/ServerEditor.java
@@ -1,20 +1,19 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JFrame;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.Model;
-import IceGrid.ServerDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class ServerEditor extends AbstractServerEditor
{
@@ -28,9 +27,8 @@ class ServerEditor extends AbstractServerEditor
return _subEditor.isSimpleUpdate();
}
- ServerEditor(Model model, JFrame parentFrame)
+ ServerEditor(JFrame parentFrame)
{
- super(model);
_subEditor = new ServerSubEditor(this, parentFrame);
}
@@ -39,10 +37,9 @@ class ServerEditor extends AbstractServerEditor
//
Utils.Resolver getDetailResolver()
{
- Server server = (Server)_target;
- if(server.getModel().substitute())
+ if(_target.getCoordinator().substitute())
{
- return server.getResolver();
+ return _target.getResolver();
}
else
{
@@ -50,12 +47,11 @@ class ServerEditor extends AbstractServerEditor
}
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
_subEditor.appendProperties(builder);
}
-
Object getSubDescriptor()
{
return ((Server)_target).getServerDescriptor();
@@ -64,15 +60,13 @@ class ServerEditor extends AbstractServerEditor
void show(Server server)
{
detectUpdates(false);
- setTarget(server);
+ _target = server;
_subEditor.show(true);
_applyButton.setEnabled(server.isEphemeral());
_discardButton.setEnabled(server.isEphemeral());
detectUpdates(true);
-
- refreshCurrentStatus();
}
private ServerSubEditor _subEditor;
diff --git a/java/src/IceGrid/TreeNode/ServerInstanceEditor.java b/java/src/IceGridGUI/Application/ServerInstanceEditor.java
index 8da92a72ec0..ebb83010249 100755
--- a/java/src/IceGrid/TreeNode/ServerInstanceEditor.java
+++ b/java/src/IceGridGUI/Application/ServerInstanceEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -22,12 +22,8 @@ import javax.swing.event.ListDataListener;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.Model;
-import IceGrid.ParametersDialog;
-import IceGrid.ServerDescriptor;
-import IceGrid.ServerInstanceDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class ServerInstanceEditor extends AbstractServerEditor
{
@@ -47,9 +43,8 @@ class ServerInstanceEditor extends AbstractServerEditor
return false;
}
- ServerInstanceEditor(Model model, JFrame parentFrame)
+ ServerInstanceEditor(JFrame parentFrame)
{
- super(model);
_subEditor = new ServerSubEditor(this, parentFrame);
_template.setToolTipText("Server template");
@@ -63,10 +58,10 @@ class ServerInstanceEditor extends AbstractServerEditor
{
public void actionPerformed(ActionEvent e)
{
- CommonBase t = (CommonBase)_template.getSelectedItem();
+ TreeNode t = (TreeNode)_template.getSelectedItem();
if(t != null)
{
- t.getModel().setSelectionPath(t.getPath());
+ t.getRoot().setSelectedNode(t);
}
}
};
@@ -114,10 +109,9 @@ class ServerInstanceEditor extends AbstractServerEditor
Utils.Resolver getDetailResolver()
{
- Server server = (Server)_target;
- if(server.getModel().substitute())
+ if(_target.getCoordinator().substitute())
{
- return server.getResolver();
+ return _target.getResolver();
}
else
{
@@ -125,7 +119,7 @@ class ServerInstanceEditor extends AbstractServerEditor
}
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
builder.append("Template", _template);
builder.append(_templateButton);
@@ -152,19 +146,18 @@ class ServerInstanceEditor extends AbstractServerEditor
void show(Server server)
{
detectUpdates(false);
- setTarget(server);
+ _target = server;
ServerInstanceDescriptor descriptor = getDescriptor();
- Model model = server.getModel();
- boolean isEditable = !model.substitute();
+ Root root = server.getRoot();
+ boolean isEditable = !root.getCoordinator().substitute();
//
// Need to make control enabled before changing it
//
_template.setEnabled(true);
- ServerTemplates serverTemplates =
- server.getApplication().getServerTemplates();
+ ServerTemplates serverTemplates = root.getServerTemplates();
_template.setModel(serverTemplates.createComboBoxModel());
ServerTemplate t = (ServerTemplate)
@@ -217,16 +210,12 @@ class ServerInstanceEditor extends AbstractServerEditor
_applyButton.setEnabled(server.isEphemeral());
_discardButton.setEnabled(server.isEphemeral());
detectUpdates(true);
-
- refreshCurrentStatus();
}
void setParameterValuesField()
{
- Server server = (Server)_target;
-
- final Utils.Resolver resolver = server.getModel().substitute() ?
- server.getParentResolver() : null;
+ final Utils.Resolver resolver = _target.getCoordinator().substitute() ?
+ ((Node)_target.getParent()).getResolver() : null;
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
Utils.Stringifier stringifier = new Utils.Stringifier()
diff --git a/java/src/IceGrid/TreeNode/ServerSubEditor.java b/java/src/IceGridGUI/Application/ServerSubEditor.java
index 591b1a15201..95e37c4a8da 100755
--- a/java/src/IceGrid/TreeNode/ServerSubEditor.java
+++ b/java/src/IceGridGUI/Application/ServerSubEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -22,11 +22,8 @@ import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.CellConstraints;
-import IceGrid.ListDialog;
-import IceGrid.Model;
-import IceGrid.ServerDescriptor;
-import IceGrid.TableDialog;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class ServerSubEditor extends CommunicatorSubEditor
{
diff --git a/java/src/IceGridGUI/Application/ServerTemplate.java b/java/src/IceGridGUI/Application/ServerTemplate.java
new file mode 100755
index 00000000000..580bf8f77f1
--- /dev/null
+++ b/java/src/IceGridGUI/Application/ServerTemplate.java
@@ -0,0 +1,360 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+
+class ServerTemplate extends Communicator
+{
+ static public TemplateDescriptor
+ copyDescriptor(TemplateDescriptor templateDescriptor)
+ {
+ TemplateDescriptor copy = (TemplateDescriptor)
+ templateDescriptor.clone();
+
+ copy.descriptor = Server.copyDescriptor(
+ (ServerDescriptor)copy.descriptor);
+ return copy;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _plainIcon =
+ Utils.getIcon("/icons/16x16/server_template.png");
+ _iceboxIcon =
+ Utils.getIcon("/icons/16x16/icebox_server_template.png");
+ }
+
+ if(_templateDescriptor.descriptor instanceof IceBoxDescriptor)
+ {
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(_iceboxIcon);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(_iceboxIcon);
+ }
+ }
+ else
+ {
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(_plainIcon);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(_plainIcon);
+ }
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ actions[PASTE] = true;
+ }
+
+ actions[DELETE] = true;
+
+ actions[NEW_ADAPTER] = !_services.initialized();
+ actions[NEW_SERVICE] = _services.initialized();
+ actions[NEW_SERVICE_FROM_TEMPLATE] = _services.initialized();
+ actions[NEW_DBENV] = _dbEnvs.initialized();
+
+ return actions;
+ }
+ public void copy()
+ {
+ getCoordinator().setClipboard(copyDescriptor(_templateDescriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+ public void paste()
+ {
+ ((TreeNode)_parent).paste();
+ }
+
+ public JPopupMenu getPopupMenu()
+ {
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_ADAPTER));
+ _popup.add(actions.get(NEW_DBENV));
+ _popup.add(actions.get(NEW_SERVICE));
+ _popup.add(actions.get(NEW_SERVICE_FROM_TEMPLATE));
+ }
+ actions.setTarget(this);
+ return _popup;
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (ServerTemplateEditor)getRoot().
+ getEditor(ServerTemplateEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new ServerTemplateEditor(getCoordinator().getMainFrame());
+ }
+
+ public void destroy()
+ {
+ ServerTemplates serverTemplates = (ServerTemplates)_parent;
+
+ if(_ephemeral)
+ {
+ serverTemplates.removeChild(this);
+ }
+ else
+ {
+ serverTemplates.removeDescriptor(_id);
+ getRoot().removeServerInstances(_id);
+ serverTemplates.removeChild(this);
+ serverTemplates.getEditable().removeElement(_id);
+ getRoot().updated();
+ }
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ public Object getDescriptor()
+ {
+ return _templateDescriptor;
+ }
+
+ CommunicatorDescriptor getCommunicatorDescriptor()
+ {
+ return _templateDescriptor.descriptor;
+ }
+
+
+ public Object saveDescriptor()
+ {
+ //
+ // Shallow copy
+ //
+ TemplateDescriptor clone = (TemplateDescriptor)_templateDescriptor.clone();
+ clone.descriptor = (ServerDescriptor)_templateDescriptor.descriptor.clone();
+ return clone;
+ }
+
+ public void restoreDescriptor(Object savedDescriptor)
+ {
+ TemplateDescriptor clone = (TemplateDescriptor)savedDescriptor;
+ //
+ // Keep the same object
+ //
+ _templateDescriptor.parameters = clone.parameters;
+
+ Server.shallowRestore((ServerDescriptor)clone.descriptor,
+ (ServerDescriptor)_templateDescriptor.descriptor);
+ }
+
+ //
+ // Application is needed to lookup service templates
+ //
+ ServerTemplate(boolean brandNew, ServerTemplates parent, String name, TemplateDescriptor descriptor)
+ throws UpdateFailedException
+ {
+ super(parent, name);
+ _editable = new Editable(brandNew);
+ _ephemeral = false;
+ rebuild(descriptor);
+ }
+
+ ServerTemplate(ServerTemplates parent, String name, TemplateDescriptor descriptor)
+ {
+ super(parent, name);
+ _ephemeral = true;
+ try
+ {
+ rebuild(descriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ assert false;
+ }
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("id", _id));
+ writer.writeStartTag("server-template", attributes);
+ writeParameters(writer, _templateDescriptor.parameters,
+ _templateDescriptor.parameterDefaults);
+
+ if(_templateDescriptor.descriptor instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor descriptor = (IceBoxDescriptor)_templateDescriptor.descriptor;
+
+ writer.writeStartTag("icebox",
+ Server.createAttributes(descriptor));
+
+ if(descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", descriptor.description);
+ }
+ Server.writeOptions(writer, descriptor.options);
+ Server.writeEnvs(writer, descriptor.envs);
+ writeProperties(writer, descriptor.properties);
+ writeDistribution(writer, descriptor.distrib);
+
+ _adapters.write(writer);
+ _services.write(writer);
+ writer.writeEndTag("icebox");
+ }
+ else
+ {
+ ServerDescriptor descriptor = (ServerDescriptor)_templateDescriptor.descriptor;
+
+ writer.writeStartTag("server",
+ Server.createAttributes(descriptor));
+
+ if(descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", descriptor.description);
+ }
+ Server.writeOptions(writer, descriptor.options);
+ Server.writeEnvs(writer, descriptor.envs);
+ writeProperties(writer, descriptor.properties);
+ writeDistribution(writer, descriptor.distrib);
+
+ _adapters.write(writer);
+ _dbEnvs.write(writer);
+ writer.writeEndTag("server");
+ }
+ writer.writeEndTag("server-template");
+ }
+ }
+
+
+ boolean isIceBox()
+ {
+ return _templateDescriptor.descriptor instanceof IceBoxDescriptor;
+ }
+
+ void rebuild(TemplateDescriptor descriptor) throws UpdateFailedException
+ {
+ _templateDescriptor = descriptor;
+
+ _adapters.clear();
+ _dbEnvs.clear();
+ _services.clear();
+
+ if(!_ephemeral)
+ {
+ _adapters.init(_templateDescriptor.descriptor.adapters);
+
+ if(_templateDescriptor.descriptor instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor iceBoxDescriptor =
+ (IceBoxDescriptor)_templateDescriptor.descriptor;
+
+ _services.init(iceBoxDescriptor.services);
+
+ assert _templateDescriptor.descriptor.dbEnvs.size() == 0;
+ }
+ else
+ {
+ _dbEnvs.init(_templateDescriptor.descriptor.dbEnvs);
+ }
+ }
+ }
+
+ void rebuild() throws UpdateFailedException
+ {
+ rebuild(_templateDescriptor);
+ }
+
+ void commit()
+ {
+ _editable.commit();
+ }
+
+ Editable getEditable()
+ {
+ return _editable;
+ }
+
+ Editable getEnclosingEditable()
+ {
+ return _editable;
+ }
+
+ java.util.List findInstances(boolean includeTemplate)
+ {
+ java.util.List result = getRoot().findServerInstances(_id);
+ if(includeTemplate)
+ {
+ result.add(0, this);
+ }
+ return result;
+ }
+
+ private TemplateDescriptor _templateDescriptor;
+ private final boolean _ephemeral;
+ private Editable _editable;
+ private ServerTemplateEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private Icon _plainIcon;
+ static private Icon _iceboxIcon;
+
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGrid/TreeNode/ServerTemplateEditor.java b/java/src/IceGridGUI/Application/ServerTemplateEditor.java
index e55b6fd7134..99ca4a48a93 100755
--- a/java/src/IceGrid/TreeNode/ServerTemplateEditor.java
+++ b/java/src/IceGridGUI/Application/ServerTemplateEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JFrame;
@@ -31,7 +31,7 @@ class ServerTemplateEditor extends TemplateEditor
return super.isSimpleUpdate() && _subEditor.isSimpleUpdate();
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
super.appendProperties(builder);
builder.appendSeparator();
@@ -39,10 +39,16 @@ class ServerTemplateEditor extends TemplateEditor
_subEditor.appendProperties(builder);
}
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Server Template Properties");
+ }
+
void show(ServerTemplate t)
{
detectUpdates(false);
- setTarget(t);
+ _target = t;
super.show();
_subEditor.show(true);
diff --git a/java/src/IceGrid/TreeNode/ServerTemplates.java b/java/src/IceGridGUI/Application/ServerTemplates.java
index 9925872a9fd..3056bc13002 100755
--- a/java/src/IceGrid/TreeNode/ServerTemplates.java
+++ b/java/src/IceGridGUI/Application/ServerTemplates.java
@@ -1,20 +1,18 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
-import IceGrid.IceBoxDescriptor;
-import IceGrid.Model;
-import IceGrid.ServerDescriptor;
-import IceGrid.TemplateDescriptor;
+import IceGrid.*;
+import IceGridGUI.*;
class ServerTemplates extends Templates
{
@@ -43,7 +41,7 @@ class ServerTemplates extends Templates
actions[NEW_TEMPLATE_SERVER] = true;
actions[NEW_TEMPLATE_SERVER_ICEBOX] = true;
- Object clipboard = _model.getClipboard();
+ Object clipboard = getCoordinator().getClipboard();
if(clipboard != null && clipboard instanceof TemplateDescriptor)
{
TemplateDescriptor d = (TemplateDescriptor)clipboard;
@@ -53,19 +51,17 @@ class ServerTemplates extends Templates
}
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
- JMenuItem newServerItem = new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVER]);
- newServerItem.setText("New server template");
- _popup.add(newServerItem);
- JMenuItem newIceBoxItem =
- new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVER_ICEBOX]);
- newIceBoxItem.setText("New IceBox server template");
- _popup.add(newIceBoxItem);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_TEMPLATE_SERVER));
+ _popup.add(actions.get(NEW_TEMPLATE_SERVER_ICEBOX));
}
+ actions.setTarget(this);
return _popup;
}
+
public void newTemplateServer()
{
newServerTemplate(new TemplateDescriptor(
@@ -82,17 +78,16 @@ class ServerTemplates extends Templates
}
public void paste()
{
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
TemplateDescriptor td = (TemplateDescriptor)descriptor;
newServerTemplate(td);
}
-
- ServerTemplates(java.util.Map descriptors, Application application)
+ ServerTemplates(Root parent, java.util.Map descriptors)
throws UpdateFailedException
{
- super("Server templates", application.getModel());
+ super(parent, "Server templates");
_descriptors = descriptors;
@@ -101,9 +96,10 @@ class ServerTemplates extends Templates
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- addChild(new ServerTemplate(false, (String)entry.getKey(),
- (TemplateDescriptor)entry.getValue(),
- application));
+ insertChild(new ServerTemplate(false, this,
+ (String)entry.getKey(),
+ (TemplateDescriptor)entry.getValue()),
+ false);
}
}
@@ -114,7 +110,7 @@ class ServerTemplates extends Templates
while(p.hasNext())
{
ServerTemplate t = (ServerTemplate)p.next();
- if(t.isNew() || t.isModified())
+ if(t.getEditable().isNew() || t.getEditable().isModified())
{
updates.put(t.getId(), t.getDescriptor());
}
@@ -122,6 +118,17 @@ class ServerTemplates extends Templates
return updates;
}
+ void commit()
+ {
+ _editable.commit();
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ ServerTemplate st = (ServerTemplate)p.next();
+ st.commit();
+ }
+ }
+
java.util.List findServiceInstances(String template)
{
java.util.List result = new java.util.LinkedList();
@@ -156,48 +163,35 @@ class ServerTemplates extends Templates
id = makeNewChildId("NewServerTemplate");
}
- ServerTemplate t = new ServerTemplate(id, descriptor, getApplication());
+ ServerTemplate t = new ServerTemplate(this, id, descriptor);
try
{
- addChild(t, true);
+ insertChild(t, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(t.getPath());
+ getRoot().setSelectedNode(t);
}
void tryAdd(String newId, TemplateDescriptor descriptor)
throws UpdateFailedException
{
- try
- {
- addChild(new ServerTemplate(true, newId, descriptor,
- getApplication()), true);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
+ insertChild(new ServerTemplate(true, this, newId, descriptor),
+ true);
_descriptors.put(newId, descriptor);
}
- protected java.util.List findAllTemplateInstances(String templateId)
- {
- return getApplication().findServerInstances(templateId);
- }
-
void update(java.util.Map updates, String[] removeTemplates,
java.util.Set serviceTemplates)
throws UpdateFailedException
{
//
- // Note: _descriptors is updated by Application
+ // Note: _descriptors is updated by Root
//
- Application application = getApplication();
+ Root root = getRoot();
//
// One big set of removes
@@ -220,12 +214,11 @@ class ServerTemplates extends Templates
ServerTemplate child = (ServerTemplate)findChild(name);
if(child == null)
{
- newChildren.add(new ServerTemplate(false, name, templateDescriptor,
- application));
+ newChildren.add(new ServerTemplate(false, this, name, templateDescriptor));
}
else
{
- child.rebuild(templateDescriptor, application);
+ child.rebuild(templateDescriptor);
updatedChildren.add(child);
}
}
@@ -243,7 +236,7 @@ class ServerTemplates extends Templates
{
Service service = (Service)q.next();
ServerTemplate serverTemplate =
- (ServerTemplate)service.getParent().getParent();
+ (ServerTemplate)service.getParent();
if(!updatedChildren.contains(serverTemplate) &&
!newChildren.contains(serverTemplate))
@@ -254,15 +247,19 @@ class ServerTemplates extends Templates
}
}
- updateChildren((CommonBaseI[])updatedChildren.toArray
- (new CommonBaseI[0]));
- addChildren((CommonBaseI[])newChildren.toArray(new CommonBaseI[0]));
+ childrenChanged(updatedChildren);
+ insertChildren(newChildren, true);
}
void removeDescriptor(String id)
{
_descriptors.remove(id);
}
+
+ Object getDescriptor()
+ {
+ return _descriptors;
+ }
private java.util.Map _descriptors;
static private JPopupMenu _popup;
diff --git a/java/src/IceGridGUI/Application/Service.java b/java/src/IceGridGUI/Application/Service.java
new file mode 100755
index 00000000000..b15c1c9ac0e
--- /dev/null
+++ b/java/src/IceGridGUI/Application/Service.java
@@ -0,0 +1,489 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Service extends Communicator implements Cloneable, TemplateInstance
+{
+ static public ServiceInstanceDescriptor
+ copyDescriptor(ServiceInstanceDescriptor instanceDescriptor)
+ {
+ ServiceInstanceDescriptor copy = (ServiceInstanceDescriptor)
+ instanceDescriptor.clone();
+
+ if(copy.descriptor != null)
+ {
+ copy.descriptor = copyDescriptor((ServiceDescriptor)copy.descriptor);
+ }
+ return copy;
+ }
+
+ static public ServiceDescriptor
+ copyDescriptor(ServiceDescriptor sd)
+ {
+ ServiceDescriptor copy = (ServiceDescriptor)sd.clone();
+ copy.adapters = Adapter.copyDescriptors(copy.adapters);
+ copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs);
+
+ //
+ // Update to properties is not atomic because of Adapter endpoints
+ // (and possibly other properties set through a PropertiesHolder)
+ //
+ copy.properties = (java.util.LinkedList)copy.properties.clone();
+ return copy;
+ }
+
+ static public java.util.LinkedList
+ copyDescriptors(java.util.LinkedList descriptors)
+ {
+ java.util.LinkedList copy = new java.util.LinkedList();
+ java.util.Iterator p = descriptors.iterator();
+ while(p.hasNext())
+ {
+ copy.add(copyDescriptor(
+ (ServiceInstanceDescriptor)p.next()));
+ }
+ return copy;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setOpenIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+
+ _cellRenderer.setClosedIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ actions[PASTE] = true;
+ }
+
+ if(_isEditable)
+ {
+ actions[DELETE] = true;
+
+ if(_instanceDescriptor.template.equals(""))
+ {
+ actions[NEW_ADAPTER] = !_ephemeral;
+ actions[NEW_DBENV] = !_ephemeral;
+ }
+ }
+
+ if(_parent instanceof Server && !_ephemeral)
+ {
+ actions[SHOW_VARS] = true;
+ actions[SUBSTITUTE_VARS] = true;
+ }
+
+ actions[MOVE_UP] = canMove(true);
+ actions[MOVE_DOWN] = canMove(false);
+ return actions;
+ }
+ public JPopupMenu getPopupMenu()
+ {
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_ADAPTER));
+ _popup.add(actions.get(NEW_DBENV));
+ _popup.addSeparator();
+ _popup.add(actions.get(MOVE_UP));
+ _popup.add(actions.get(MOVE_DOWN));
+ }
+ actions.setTarget(this);
+ return _popup;
+ }
+ public void copy()
+ {
+ getCoordinator().setClipboard(copyDescriptor(_instanceDescriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+
+ public void moveUp()
+ {
+ move(true);
+ }
+ public void moveDown()
+ {
+ move(false);
+ }
+
+ public Object getDescriptor()
+ {
+ return _instanceDescriptor;
+ }
+
+ public Object saveDescriptor()
+ {
+ //
+ // Must be a shallow copy
+ //
+ ServiceInstanceDescriptor saved =
+ (ServiceInstanceDescriptor)_instanceDescriptor.clone();
+
+ if(saved.descriptor != null)
+ {
+ saved.descriptor = (ServiceDescriptor)saved.descriptor.clone();
+ }
+ return saved;
+ }
+
+ public void restoreDescriptor(Object savedDescriptor)
+ {
+ ServiceInstanceDescriptor sd = (ServiceInstanceDescriptor)savedDescriptor;
+ _instanceDescriptor.template = sd.template;
+ _instanceDescriptor.parameterValues = sd.parameterValues;
+ if(_instanceDescriptor.descriptor != null)
+ {
+ _instanceDescriptor.descriptor.properties = sd.descriptor.properties;
+ _instanceDescriptor.descriptor.description = sd.descriptor.description;
+
+ _instanceDescriptor.descriptor.name = sd.descriptor.name;
+ _instanceDescriptor.descriptor.entry = sd.descriptor.entry;
+ }
+ }
+
+ public void destroy()
+ {
+ ((Communicator)_parent).getServices().destroyChild(this);
+ }
+
+ public Editor getEditor()
+ {
+ if(_instanceDescriptor.template.length() > 0)
+ {
+ if(_instanceEditor == null)
+ {
+ _instanceEditor = (ServiceInstanceEditor)getRoot().
+ getEditor(ServiceInstanceEditor.class, this);
+ }
+ _instanceEditor.show(this);
+ return _instanceEditor;
+ }
+ else
+ {
+ if(_editor == null)
+ {
+ _editor = (ServiceEditor)getRoot().getEditor(ServiceEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+ }
+
+ protected Editor createEditor()
+ {
+ if(_instanceDescriptor.template.length() > 0)
+ {
+ return new ServiceInstanceEditor(getCoordinator().getMainFrame());
+ }
+ else
+ {
+ return new ServiceEditor(getCoordinator().getMainFrame());
+ }
+ }
+
+ public String toString()
+ {
+ if(_displayString != null)
+ {
+ return _displayString;
+ }
+ else
+ {
+ return super.toString();
+ }
+ }
+
+ Editable getEnclosingEditable()
+ {
+ return ((Communicator)_parent).getEnclosingEditable();
+ }
+
+ private boolean canMove(boolean up)
+ {
+ if(_ephemeral)
+ {
+ return false;
+ }
+ else
+ {
+ return ((Communicator)_parent).getServices().canMove(this, up);
+ }
+ }
+
+ private void move(boolean up)
+ {
+ assert canMove(up);
+ ((Communicator)_parent).getServices().move(this, up);
+ }
+
+
+ java.util.List findInstances(boolean includeTemplate)
+ {
+ java.util.List result = new java.util.LinkedList();
+
+ //
+ // First find all instances of the enclosing Communicator, including
+ // the ServerTemplate itself (if that's my parent)
+ //
+ java.util.List communicatorList = ((Communicator)_parent).findInstances(true);
+
+ java.util.Iterator p = communicatorList.iterator();
+ while(p.hasNext())
+ {
+ Services services = ((Communicator)p.next()).getServices();
+ Service service = (Service)services.findChildWithDescriptor(_instanceDescriptor);
+ assert service != null;
+ result.add(service);
+ }
+ return result;
+ }
+
+ static private class Backup
+ {
+ java.util.Map parameterValues;
+ Service clone;
+ }
+
+ public Object rebuild(java.util.List editables)
+ throws UpdateFailedException
+ {
+ Backup backup = new Backup();
+
+ //
+ // Fix-up _instanceDescriptor if necessary
+ //
+ if(_instanceDescriptor.template.length() > 0)
+ {
+ TemplateDescriptor templateDescriptor
+ = getRoot().findServiceTemplateDescriptor(_instanceDescriptor.template);
+
+ java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters);
+ if(!parameters.equals(_instanceDescriptor.parameterValues.keySet()))
+ {
+ backup.parameterValues = _instanceDescriptor.parameterValues;
+ _instanceDescriptor.parameterValues = EditorBase.makeParameterValues(
+ _instanceDescriptor.parameterValues, templateDescriptor.parameters);
+ editables.add(getEnclosingEditable());
+ }
+ }
+
+ Communicator communicator = (Communicator)_parent;
+ Services services = communicator.getServices();
+ Service newService = null;
+
+ try
+ {
+ newService = (Service)services.createChild(_instanceDescriptor);
+ }
+ catch(UpdateFailedException e)
+ {
+ if(backup.parameterValues != null)
+ {
+ _instanceDescriptor.parameterValues = backup.parameterValues;
+ }
+ throw e;
+ }
+
+ try
+ {
+ backup.clone = (Service)clone();
+ }
+ catch(CloneNotSupportedException e)
+ {
+ assert false;
+ }
+
+ reset(newService);
+
+ if(backup.parameterValues != null)
+ {
+ editables.add(getEnclosingEditable());
+ }
+ getRoot().getTreeModel().nodeChanged(this);
+ return backup;
+ }
+
+ public void restore(Object backupObj)
+ {
+ Backup backup = (Backup)backupObj;
+
+ if(backup.parameterValues != null)
+ {
+ _instanceDescriptor.parameterValues = backup.parameterValues;
+ }
+
+ reset(backup.clone);
+ getRoot().getTreeModel().nodeChanged(this);
+ }
+
+ private void reset(Service from)
+ {
+ _id = from._id;
+ assert _parent == from._parent;
+
+ _adapters = from._adapters;
+ _dbEnvs = from._dbEnvs;
+ _services = from._services;
+ _childListArray = from._childListArray;
+
+ assert _instanceDescriptor == from._instanceDescriptor;
+ _serviceDescriptor = from._serviceDescriptor;
+
+ _displayString = from._displayString;
+ _isEditable = from._isEditable;
+ _resolver = from._resolver;
+ }
+
+ Service(Communicator parent,
+ String name,
+ String displayString,
+ ServiceInstanceDescriptor instanceDescriptor,
+ ServiceDescriptor serviceDescriptor,
+ Utils.Resolver resolver)
+ throws UpdateFailedException
+ {
+ super(parent, name);
+ _displayString = displayString;
+ _instanceDescriptor = instanceDescriptor;
+ _serviceDescriptor = serviceDescriptor;
+ _ephemeral = false;
+ _resolver = resolver;
+
+ _isEditable = _instanceDescriptor.template.length() == 0
+ && ((TreeNode)_parent).isEditable();
+
+ _adapters.init(_serviceDescriptor.adapters);
+ _dbEnvs.init(_serviceDescriptor.dbEnvs);
+ }
+
+ //
+ // New temporary object
+ //
+ Service(Communicator parent, String name,
+ ServiceInstanceDescriptor instanceDescriptor)
+ {
+ super(parent, name);
+ _instanceDescriptor = instanceDescriptor;
+ _serviceDescriptor = instanceDescriptor.descriptor;
+ _ephemeral = true;
+ _isEditable = true;
+ }
+
+ static java.util.List createAttributes(ServiceDescriptor descriptor)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", descriptor.name));
+ attributes.add(createAttribute("entry", descriptor.entry));
+ return attributes;
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
+ {
+ if(_instanceDescriptor.template.length() > 0)
+ {
+ TemplateDescriptor templateDescriptor
+ = getRoot().findServiceTemplateDescriptor(_instanceDescriptor.template);
+
+ java.util.LinkedList attributes = parameterValuesToAttributes(
+ _instanceDescriptor.parameterValues, templateDescriptor.parameters);
+ attributes.addFirst(createAttribute("template", _instanceDescriptor.template));
+
+ writer.writeElement("service-instance", attributes);
+ }
+ else
+ {
+ writer.writeStartTag("service", createAttributes(_serviceDescriptor));
+
+ if(_serviceDescriptor.description.length() > 0)
+ {
+ writer.writeElement("description", _serviceDescriptor.description);
+ }
+ writeProperties(writer, _serviceDescriptor.properties);
+ _adapters.write(writer);
+ _dbEnvs.write(writer);
+ writer.writeEndTag("service");
+ }
+ }
+ }
+
+ ServiceDescriptor getServiceDescriptor()
+ {
+ return _serviceDescriptor;
+ }
+
+ CommunicatorDescriptor getCommunicatorDescriptor()
+ {
+ return _serviceDescriptor;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ boolean isEditable()
+ {
+ return _isEditable;
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ private ServiceInstanceDescriptor _instanceDescriptor;
+ private ServiceDescriptor _serviceDescriptor;
+
+ private String _displayString;
+ private final boolean _ephemeral;
+ private boolean _isEditable;
+
+ private Utils.Resolver _resolver;
+ private ServiceEditor _editor;
+ private ServiceInstanceEditor _instanceEditor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGrid/TreeNode/ServiceEditor.java b/java/src/IceGridGUI/Application/ServiceEditor.java
index de4021b5306..3fec0c6c278 100755
--- a/java/src/IceGrid/TreeNode/ServiceEditor.java
+++ b/java/src/IceGridGUI/Application/ServiceEditor.java
@@ -1,26 +1,24 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JFrame;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.Model;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
-class ServiceEditor extends ListElementEditor
+class ServiceEditor extends CommunicatorChildEditor
{
ServiceEditor(JFrame parentFrame)
{
- super(false);
_subEditor = new ServiceSubEditor(this, parentFrame);
}
@@ -30,7 +28,7 @@ class ServiceEditor extends ListElementEditor
Utils.Resolver getDetailResolver()
{
Service service = (Service)_target;
- if(service.getModel().substitute())
+ if(service.getCoordinator().substitute())
{
return service.getResolver();
}
@@ -40,11 +38,18 @@ class ServiceEditor extends ListElementEditor
}
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
_subEditor.appendProperties(builder);
}
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Service Properties");
+ }
+
+
void writeDescriptor()
{
_subEditor.writeDescriptor();
@@ -55,6 +60,11 @@ class ServiceEditor extends ListElementEditor
return _subEditor.isSimpleUpdate();
}
+ Communicator.ChildList getChildList()
+ {
+ return ((Communicator)_target.getParent()).getServices();
+ }
+
Object getSubDescriptor()
{
return ((Service)_target).getServiceDescriptor();
@@ -70,7 +80,7 @@ class ServiceEditor extends ListElementEditor
!= null;
detectUpdates(false);
- setTarget(service);
+ _target = service;
_subEditor.show(service.isEditable());
diff --git a/java/src/IceGrid/TreeNode/ServiceInstanceEditor.java b/java/src/IceGridGUI/Application/ServiceInstanceEditor.java
index 6c70b951421..3ad638e3378 100755
--- a/java/src/IceGrid/TreeNode/ServiceInstanceEditor.java
+++ b/java/src/IceGridGUI/Application/ServiceInstanceEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -22,17 +22,13 @@ import javax.swing.event.ListDataListener;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.Model;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.ParametersDialog;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
-class ServiceInstanceEditor extends ListElementEditor
+class ServiceInstanceEditor extends CommunicatorChildEditor
{
ServiceInstanceEditor(JFrame parentFrame)
{
- super(false);
_subEditor = new ServiceSubEditor(this, parentFrame);
_parameterValues.setEditable(false);
@@ -45,10 +41,10 @@ class ServiceInstanceEditor extends ListElementEditor
{
public void actionPerformed(ActionEvent e)
{
- CommonBase t = (CommonBase)_template.getSelectedItem();
+ TreeNode t = (TreeNode)_template.getSelectedItem();
if(t != null)
{
- t.getModel().setSelectionPath(t.getPath());
+ t.getRoot().setSelectedNode(t);
}
}
};
@@ -95,7 +91,7 @@ class ServiceInstanceEditor extends ListElementEditor
Utils.Resolver getDetailResolver()
{
Service service = (Service)_target;
- if(service.getModel().substitute())
+ if(service.getCoordinator().substitute())
{
return service.getResolver();
}
@@ -117,7 +113,12 @@ class ServiceInstanceEditor extends ListElementEditor
return false;
}
- void appendProperties(DefaultFormBuilder builder)
+ Communicator.ChildList getChildList()
+ {
+ return ((Communicator)_target.getParent()).getServices();
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
{
builder.append("Template", _template);
builder.append(_templateButton);
@@ -133,6 +134,13 @@ class ServiceInstanceEditor extends ListElementEditor
_subEditor.appendProperties(builder);
}
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Service Properties");
+ }
+
+
Object getSubDescriptor()
{
ServiceTemplate template = (ServiceTemplate)_template.getSelectedItem();
@@ -144,7 +152,7 @@ class ServiceInstanceEditor extends ListElementEditor
void show(Service service)
{
detectUpdates(false);
- setTarget(service);
+ _target = service;
//
// If it's not a template instance, it's shown using
@@ -155,8 +163,8 @@ class ServiceInstanceEditor extends ListElementEditor
ServiceInstanceDescriptor descriptor =
(ServiceInstanceDescriptor)service.getDescriptor();
- Model model = service.getModel();
- boolean isEditable = service.isEditable() && !model.substitute();
+ Coordinator coordinator = service.getCoordinator();
+ boolean isEditable = service.isEditable() && !coordinator.substitute();
//
// Need to make control enabled before changing it
@@ -164,7 +172,7 @@ class ServiceInstanceEditor extends ListElementEditor
_template.setEnabled(true);
ServiceTemplates serviceTemplates =
- service.getApplication().getServiceTemplates();
+ service.getRoot().getServiceTemplates();
_template.setModel(serviceTemplates.createComboBoxModel());
ServiceTemplate t = (ServiceTemplate)
@@ -226,8 +234,8 @@ class ServiceInstanceEditor extends ListElementEditor
{
Service service = (Service)_target;
- final Utils.Resolver resolver = service.getModel().substitute() ?
- service.getParentResolver() : null;
+ final Utils.Resolver resolver = service.getCoordinator().substitute() ?
+ ((TreeNode)service.getParent()).getResolver() : null;
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
Utils.Stringifier stringifier = new Utils.Stringifier()
diff --git a/java/src/IceGrid/TreeNode/ServiceSubEditor.java b/java/src/IceGridGUI/Application/ServiceSubEditor.java
index fede11832bd..313194ebcd6 100755
--- a/java/src/IceGrid/TreeNode/ServiceSubEditor.java
+++ b/java/src/IceGridGUI/Application/ServiceSubEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -17,9 +17,8 @@ import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.ServiceDescriptor;
-import IceGrid.Model;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class ServiceSubEditor extends CommunicatorSubEditor
{
diff --git a/java/src/IceGrid/TreeNode/ServiceTemplate.java b/java/src/IceGridGUI/Application/ServiceTemplate.java
index aa6d259b851..2b17f26bec1 100755
--- a/java/src/IceGrid/TreeNode/ServiceTemplate.java
+++ b/java/src/IceGridGUI/Application/ServiceTemplate.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.Component;
import javax.swing.JMenuItem;
@@ -14,13 +14,10 @@ import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.SimpleInternalFrame;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
-class ServiceTemplate extends EditableParent
+class ServiceTemplate extends Communicator
{
static public TemplateDescriptor
copyDescriptor(TemplateDescriptor templateDescriptor)
@@ -64,48 +61,37 @@ class ServiceTemplate extends EditableParent
{
boolean[] actions = new boolean[ACTION_COUNT];
actions[COPY] = true;
- if(_parent.getAvailableActions()[PASTE])
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
{
actions[PASTE] = true;
}
actions[DELETE] = true;
- actions[NEW_ADAPTER] = (_adapters != null);
- actions[NEW_DBENV] = (_dbEnvs != null);
+ actions[NEW_ADAPTER] = !_ephemeral;
+ actions[NEW_DBENV] = !_ephemeral;
return actions;
}
public void copy()
{
- _model.setClipboard(copyDescriptor(_templateDescriptor));
- _model.getActions()[PASTE].setEnabled(true);
+ getCoordinator().setClipboard(copyDescriptor(_templateDescriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
}
public void paste()
{
- _parent.paste();
+ ((TreeNode)_parent).paste();
}
- public void newAdapter()
- {
- _adapters.newAdapter();
- }
- public void newDbEnv()
- {
- _dbEnvs.newDbEnv();
- }
-
+
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_ADAPTER]);
- item.setText("New adapter");
- _popup.add(item);
-
- item = new JMenuItem(_model.getActions()[NEW_DBENV]);
- item.setText("New DbEnv");
- _popup.add(item);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_ADAPTER));
+ _popup.add(actions.get(NEW_DBENV));
}
+ actions.setTarget(this);
return _popup;
}
@@ -113,32 +99,58 @@ class ServiceTemplate extends EditableParent
{
if(_editor == null)
{
- _editor = new ServiceTemplateEditor(_model.getMainFrame());
+ _editor = (ServiceTemplateEditor)getRoot().getEditor(ServiceTemplateEditor.class, this);
}
_editor.show(this);
return _editor;
}
- ServiceTemplate(boolean brandNew, String name,
- TemplateDescriptor descriptor, Model model)
+ protected Editor createEditor()
+ {
+ return new ServiceTemplateEditor(getCoordinator().getMainFrame());
+ }
+
+ ServiceTemplate(boolean brandNew, ServiceTemplates parent,
+ String name, TemplateDescriptor descriptor)
throws UpdateFailedException
{
- super(brandNew, name, model);
+ super(parent, name);
+ _editable = new Editable(brandNew);
_ephemeral = false;
rebuild(descriptor);
}
- ServiceTemplate(String name, TemplateDescriptor descriptor, Model model)
+ ServiceTemplate(ServiceTemplates parent, String name, TemplateDescriptor descriptor)
{
- super(false, name, model);
+ super(parent, name);
_ephemeral = true;
- try
- {
- rebuild(descriptor);
- }
- catch(UpdateFailedException e)
+ _editable = null;
+ _templateDescriptor = descriptor;
+ }
+
+ void write(XMLWriter writer) throws java.io.IOException
+ {
+ if(!_ephemeral)
{
- assert false;
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("id", _id));
+ writer.writeStartTag("service-template", attributes);
+ writeParameters(writer, _templateDescriptor.parameters,
+ _templateDescriptor.parameterDefaults);
+
+ ServiceDescriptor descriptor = (ServiceDescriptor)_templateDescriptor.descriptor;
+
+ writer.writeStartTag("service", Service.createAttributes(descriptor));
+
+ if(descriptor.description.length() > 0)
+ {
+ writer.writeElement("description", descriptor.description);
+ }
+ writeProperties(writer, descriptor.properties);
+ _adapters.write(writer);
+ _dbEnvs.write(writer);
+ writer.writeEndTag("service");
+ writer.writeEndTag("service-template");
}
}
@@ -146,29 +158,20 @@ class ServiceTemplate extends EditableParent
throws UpdateFailedException
{
_templateDescriptor = descriptor;
- _propertiesHolder = new PropertiesHolder(_templateDescriptor.descriptor);
-
- clearChildren();
- if(_ephemeral)
- {
- _adapters = null;
- _dbEnvs = null;
- }
- else
+
+ _adapters.clear();
+ _dbEnvs.clear();
+
+ if(!_ephemeral)
{
- _adapters = new Adapters(_templateDescriptor.descriptor.adapters, true,
- false, null, _model);
- addChild(_adapters);
-
- _dbEnvs = new DbEnvs(_templateDescriptor.descriptor.dbEnvs, true,
- null, _model);
- addChild(_dbEnvs);
+ _adapters.init(_templateDescriptor.descriptor.adapters);
+ _dbEnvs.init(_templateDescriptor.descriptor.dbEnvs);
}
}
- public PropertiesHolder getPropertiesHolder()
+ void commit()
{
- return _propertiesHolder;
+ _editable.commit();
}
public Object getDescriptor()
@@ -176,50 +179,54 @@ class ServiceTemplate extends EditableParent
return _templateDescriptor;
}
+ CommunicatorDescriptor getCommunicatorDescriptor()
+ {
+ return _templateDescriptor.descriptor;
+ }
+
public boolean isEphemeral()
{
return _ephemeral;
}
- public boolean destroy()
+ public void destroy()
{
ServiceTemplates serviceTemplates = (ServiceTemplates)_parent;
- if(serviceTemplates != null && _ephemeral)
- {
- serviceTemplates.removeChild(this, true);
- return true;
- }
- else if(serviceTemplates != null && _model.canUpdate())
+ if(_ephemeral)
{
- serviceTemplates.removeDescriptor(_id);
- getApplication().removeServiceInstances(_id);
- serviceTemplates.removeElement(this, true);
- return true;
+ serviceTemplates.removeChild(this);
}
else
{
- return false;
+ serviceTemplates.removeDescriptor(_id);
+ getRoot().removeServiceInstances(_id);
+ serviceTemplates.removeChild(this);
+ serviceTemplates.getEditable().removeElement(_id);
+ getRoot().updated();
}
}
- public java.util.List findAllInstances(CommonBase child)
+ java.util.List findInstances(boolean includeTemplate)
{
- java.util.List result = super.findAllInstances(child);
-
- java.util.List serviceInstances =
- getApplication().findServiceInstances(_id);
-
- java.util.Iterator p = serviceInstances.iterator();
- while(p.hasNext())
+ java.util.List result = getRoot().findServiceInstances(_id);
+ if(includeTemplate)
{
- Service service = (Service)p.next();
- result.addAll(service.findChildrenWithType(child.getClass()));
+ result.add(0, this);
}
-
return result;
}
+ Editable getEditable()
+ {
+ return _editable;
+ }
+
+ Editable getEnclosingEditable()
+ {
+ return _editable;
+ }
+
public Object saveDescriptor()
{
//
@@ -248,13 +255,10 @@ class ServiceTemplate extends EditableParent
}
private TemplateDescriptor _templateDescriptor;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-
- private PropertiesHolder _propertiesHolder;
private final boolean _ephemeral;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private ServiceTemplateEditor _editor;
+ private Editable _editable;
+ private ServiceTemplateEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
static private JPopupMenu _popup;
}
diff --git a/java/src/IceGrid/TreeNode/ServiceTemplateEditor.java b/java/src/IceGridGUI/Application/ServiceTemplateEditor.java
index 89b82be225b..ab5eb555d75 100755
--- a/java/src/IceGrid/TreeNode/ServiceTemplateEditor.java
+++ b/java/src/IceGridGUI/Application/ServiceTemplateEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JFrame;
@@ -31,7 +31,7 @@ class ServiceTemplateEditor extends TemplateEditor
return super.isSimpleUpdate() && _subEditor.isSimpleUpdate();
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
super.appendProperties(builder);
builder.appendSeparator();
@@ -39,10 +39,16 @@ class ServiceTemplateEditor extends TemplateEditor
_subEditor.appendProperties(builder);
}
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Service Template Properties");
+ }
+
void show(ServiceTemplate t)
{
detectUpdates(false);
- setTarget(t);
+ _target = t;
super.show();
_subEditor.show(true);
diff --git a/java/src/IceGrid/TreeNode/ServiceTemplates.java b/java/src/IceGridGUI/Application/ServiceTemplates.java
index a8bbe71d3db..b94ae2b920f 100755
--- a/java/src/IceGrid/TreeNode/ServiceTemplates.java
+++ b/java/src/IceGridGUI/Application/ServiceTemplates.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -15,9 +15,8 @@ import javax.swing.Action;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.TemplateDescriptor;
+import IceGrid.*;
+import IceGridGUI.*;
class ServiceTemplates extends Templates
{
@@ -46,7 +45,7 @@ class ServiceTemplates extends Templates
boolean[] actions = new boolean[ACTION_COUNT];
actions[NEW_TEMPLATE_SERVICE] = true;
- Object clipboard = _model.getClipboard();
+ Object clipboard = getCoordinator().getClipboard();
if(clipboard != null && clipboard instanceof TemplateDescriptor)
{
TemplateDescriptor d = (TemplateDescriptor)clipboard;
@@ -56,13 +55,13 @@ class ServiceTemplates extends Templates
}
public JPopupMenu getPopupMenu()
{
+ ApplicationActions actions = getCoordinator().getActionsForPopup();
if(_popup == null)
{
- _popup = new PopupMenu(_model);
- JMenuItem item = new JMenuItem(_model.getActions()[NEW_TEMPLATE_SERVICE]);
- item.setText("New service template");
- _popup.add(item);
+ _popup = new JPopupMenu();
+ _popup.add(actions.get(NEW_TEMPLATE_SERVICE));
}
+ actions.setTarget(this);
return _popup;
}
public void newTemplateService()
@@ -81,16 +80,16 @@ class ServiceTemplates extends Templates
}
public void paste()
{
- Object descriptor = _model.getClipboard();
+ Object descriptor = getCoordinator().getClipboard();
TemplateDescriptor td = (TemplateDescriptor)descriptor;
newServiceTemplate(td);
}
- ServiceTemplates(java.util.Map descriptors, Model model)
+ ServiceTemplates(Root parent, java.util.Map descriptors)
throws UpdateFailedException
{
- super("Service templates", model);
+ super(parent, "Service templates");
_descriptors = descriptors;
@@ -99,9 +98,10 @@ class ServiceTemplates extends Templates
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- addChild(new ServiceTemplate(false, (String)entry.getKey(),
- (TemplateDescriptor)entry.getValue(),
- _model));
+ insertChild(new ServiceTemplate(false, this,
+ (String)entry.getKey(),
+ (TemplateDescriptor)entry.getValue()),
+ false);
}
}
@@ -109,40 +109,26 @@ class ServiceTemplates extends Templates
{
String id = makeNewChildId("NewServiceTemplate");
- ServiceTemplate t = new ServiceTemplate(id, descriptor, _model);
+ ServiceTemplate t = new ServiceTemplate(this, id, descriptor);
try
{
- addChild(t, true);
+ insertChild(t, true);
}
catch(UpdateFailedException e)
{
assert false;
}
- _model.setSelectionPath(t.getPath());
+ getRoot().setSelectedNode(t);
}
void tryAdd(String newId, TemplateDescriptor descriptor)
throws UpdateFailedException
{
- try
- {
- addChild(new ServiceTemplate(true, newId, descriptor, _model),
- true);
- }
- catch(UpdateFailedException e)
- {
- e.addParent(this);
- throw e;
- }
+ insertChild(new ServiceTemplate(true, this, newId, descriptor),
+ true);
_descriptors.put(newId, descriptor);
}
- protected java.util.List findAllTemplateInstances(String templateId)
- {
- return getApplication().findServiceInstances(templateId);
- }
-
-
java.util.Map getUpdates()
{
java.util.Map updates = new java.util.HashMap();
@@ -150,7 +136,7 @@ class ServiceTemplates extends Templates
while(p.hasNext())
{
ServiceTemplate t = (ServiceTemplate)p.next();
- if(t.isNew() || t.isModified())
+ if(t.getEditable().isNew() || t.getEditable().isModified())
{
updates.put(t.getId(), t.getDescriptor());
}
@@ -158,6 +144,18 @@ class ServiceTemplates extends Templates
return updates;
}
+ void commit()
+ {
+ _editable.commit();
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ ServiceTemplate st = (ServiceTemplate)p.next();
+ st.commit();
+ }
+ }
+
+
void update(java.util.Map descriptors, String[] removeTemplates)
throws UpdateFailedException
{
@@ -186,8 +184,8 @@ class ServiceTemplates extends Templates
ServiceTemplate child = (ServiceTemplate)findChild(name);
if(child == null)
{
- newChildren.add(new ServiceTemplate(false, name,
- templateDescriptor, _model));
+ newChildren.add(new ServiceTemplate(false, this, name,
+ templateDescriptor));
}
else
{
@@ -196,17 +194,20 @@ class ServiceTemplates extends Templates
}
}
- updateChildren((CommonBaseI[])updatedChildren.toArray
- (new CommonBaseI[0]));
- addChildren((CommonBaseI[])newChildren.toArray(new CommonBaseI[0]));
-
+ childrenChanged(updatedChildren);
+ insertChildren(newChildren, true);
}
void removeDescriptor(String id)
{
_descriptors.remove(id);
}
-
+
+ Object getDescriptor()
+ {
+ return _descriptors;
+ }
+
private java.util.Map _descriptors;
static private JPopupMenu _popup;
diff --git a/java/src/IceGrid/TreeNode/TemplateEditor.java b/java/src/IceGridGUI/Application/TemplateEditor.java
index 92199e28ad8..2c90345f31f 100755
--- a/java/src/IceGrid/TreeNode/TemplateEditor.java
+++ b/java/src/IceGridGUI/Application/TemplateEditor.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import java.awt.event.ActionEvent;
@@ -19,16 +19,13 @@ import javax.swing.JTextField;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import IceGrid.Model;
-import IceGrid.ParametersDialog;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
+import IceGrid.*;
+import IceGridGUI.*;
class TemplateEditor extends Editor
{
TemplateEditor(JFrame parentFrame)
{
- super(false, true);
_template.getDocument().addDocumentListener(_updateListener);
_template.setToolTipText("Must be unique within the enclosing application");
_parameters.setEditable(false);
@@ -85,7 +82,7 @@ class TemplateEditor extends Editor
&& descriptor.parameterDefaults.equals(_parameterValuesMap);
}
- void appendProperties(DefaultFormBuilder builder)
+ protected void appendProperties(DefaultFormBuilder builder)
{
builder.append("Template ID");
builder.append(_template, 3);
@@ -109,103 +106,103 @@ class TemplateEditor extends Editor
protected void applyUpdate()
{
- Model model = _target.getModel();
+ Root root = _target.getRoot();
+ root.disableSelectionListener();
- if(model.canUpdate())
- {
- model.disableDisplay();
-
- try
+ try
+ {
+ if(_target.isEphemeral())
{
- if(_target.isEphemeral())
- {
- writeDescriptor();
- TemplateDescriptor descriptor = getDescriptor();
- Templates parent = (Templates)_target.getParent();
- _target.destroy(); // just removes the child
+ writeDescriptor();
+ TemplateDescriptor descriptor = getDescriptor();
+ Templates parent = (Templates)_target.getParent();
+ _target.destroy(); // just removes the child
- try
- {
- parent.tryAdd(_template.getText(), descriptor);
- }
- catch(UpdateFailedException e)
- {
- //
- // Re-add ephemeral child
- //
- try
- {
- parent.addChild(_target, true);
- }
- catch(UpdateFailedException die)
- {
- assert false;
- }
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- //
- // Success
- //
- _target = parent.findChildWithDescriptor(descriptor);
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
- _template.setEditable(false);
- }
- else if(isSimpleUpdate())
+ try
{
- writeDescriptor();
+ parent.tryAdd(_template.getText(), descriptor);
}
- else
+ catch(UpdateFailedException e)
{
//
- // Save to be able to rollback
+ // Re-add ephemeral child
//
- Object savedDescriptor = _target.saveDescriptor();
- Templates parent = (Templates)_target.getParent();
- writeDescriptor();
-
try
{
-
- parent.tryUpdate(_target);
+ parent.insertChild(_target, true);
}
- catch(UpdateFailedException e)
+ catch(UpdateFailedException die)
{
- _target.restoreDescriptor(savedDescriptor);
-
- JOptionPane.showMessageDialog(
- model.getMainFrame(),
- e.toString(),
- "Apply failed",
- JOptionPane.ERROR_MESSAGE);
- //
- // Everything was restored, user must deal with error
- //
- return;
+ assert false;
}
+ JOptionPane.showMessageDialog(
+ _target.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ //
+ // Success
+ //
+ _target = parent.findChildWithDescriptor(descriptor);
+ root.updated();
+ root.setSelectedNode(_target);
+ _template.setEditable(false);
+ }
+ else if(isSimpleUpdate())
+ {
+ writeDescriptor();
+ ((Communicator)_target).getEnclosingEditable().markModified();
+ root.updated();
+
+ }
+ else
+ {
+ //
+ // Save to be able to rollback
+ //
+ Object savedDescriptor = ((Communicator)_target).saveDescriptor();
+ Templates parent = (Templates)_target.getParent();
+ writeDescriptor();
+
+ try
+ {
+ parent.tryUpdate((Communicator)_target);
+ }
+ catch(UpdateFailedException e)
+ {
+ ((Communicator)_target).restoreDescriptor(savedDescriptor);
+ JOptionPane.showMessageDialog(
+ _target.getCoordinator().getMainFrame(),
+ e.toString(),
+ "Apply failed",
+ JOptionPane.ERROR_MESSAGE);
//
- // Success
+ // Everything was restored, user must deal with error
//
- _target = parent.findChildWithDescriptor(getDescriptor());
- model.setSelectionPath(_target.getPath());
- model.showActions(_target);
+ return;
}
-
- _target.getEditable().markModified();
- _applyButton.setEnabled(false);
- _discardButton.setEnabled(false);
- }
- finally
- {
- model.enableDisplay();
+
+ //
+ // Success
+ //
+ ((Communicator)_target).getEnclosingEditable().markModified();
+ root.updated();
+
+ _target = parent.findChildWithDescriptor(getDescriptor());
+ root.setSelectedNode(_target);
}
+
+ root.getCoordinator().getCurrentTab().showNode(_target);
+ _applyButton.setEnabled(false);
+ _discardButton.setEnabled(false);
+ }
+ finally
+ {
+ root.enableSelectionListener();
}
}
diff --git a/java/src/IceGridGUI/Application/TemplateInstance.java b/java/src/IceGridGUI/Application/TemplateInstance.java
new file mode 100755
index 00000000000..1e2b069cc7f
--- /dev/null
+++ b/java/src/IceGridGUI/Application/TemplateInstance.java
@@ -0,0 +1,16 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+interface TemplateInstance
+{
+ Object rebuild(java.util.List editables) throws UpdateFailedException;
+ void restore(Object backupObj);
+}
+
diff --git a/java/src/IceGrid/TreeNode/Templates.java b/java/src/IceGridGUI/Application/Templates.java
index 4ec8fef4b87..a7f86fdb776 100755
--- a/java/src/IceGrid/TreeNode/Templates.java
+++ b/java/src/IceGridGUI/Application/Templates.java
@@ -1,37 +1,32 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
import javax.swing.JOptionPane;
-import IceGrid.Model;
-import IceGrid.TemplateDescriptor;
+import IceGrid.*;
+import IceGridGUI.*;
-
-abstract class Templates extends EditableParent
+abstract class Templates extends ListTreeNode
{
abstract void tryAdd(String newId, TemplateDescriptor descriptor)
throws UpdateFailedException;
-
- abstract protected java.util.List findAllTemplateInstances(String templateId);
-
- protected Templates(String id, Model model)
+
+ protected Templates(Root parent, String id)
{
- super(false, id, model, false);
+ super(false, parent, id);
}
- void tryUpdate(CommonBase child)
+ void tryUpdate(Communicator child)
throws UpdateFailedException
{
- java.util.List instanceList = findAllTemplateInstances(child.getId());
-
- java.util.List parentList = new java.util.Vector();
+ java.util.List instanceList = child.findInstances(false);
java.util.List backupList = new java.util.Vector();
java.util.List editables = new java.util.LinkedList();
@@ -39,24 +34,21 @@ abstract class Templates extends EditableParent
java.util.Iterator p = instanceList.iterator();
while(p.hasNext())
{
- CommonBase instance = (CommonBase)p.next();
- Parent parent = (Parent)instance.getParent();
+ TemplateInstance instance = (TemplateInstance)p.next();
try
{
- backupList.add(parent.rebuildChild(instance, editables));
+ backupList.add(instance.rebuild(editables));
}
catch(UpdateFailedException e)
{
for(int i = backupList.size() - 1; i >= 0; --i)
{
- parent = (Parent)parentList.get(i);
- parent.restoreChild((CommonBase)instanceList.get(i), backupList.get(i));
+ instance = (TemplateInstance)instanceList.get(i);
+ instance.restore(backupList.get(i));
}
throw e;
}
-
- parentList.add(parent);
}
p = editables.iterator();
diff --git a/java/src/IceGridGUI/Application/TreeNode.java b/java/src/IceGridGUI/Application/TreeNode.java
new file mode 100755
index 00000000000..5f854f708f3
--- /dev/null
+++ b/java/src/IceGridGUI/Application/TreeNode.java
@@ -0,0 +1,328 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.SwingUtilities;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+public abstract class TreeNode extends TreeNodeBase
+{
+ abstract public Editor getEditor();
+ abstract protected Editor createEditor();
+ abstract Object getDescriptor();
+
+ abstract void write(XMLWriter writer) throws java.io.IOException;
+
+ //
+ // Ephemeral objects are destroyed when you switch selection
+ // without "apply"ing the changes.
+ //
+ public boolean isEphemeral()
+ {
+ return false;
+ }
+
+ //
+ // Destroys this node
+ //
+ public void destroy()
+ {
+ assert false;
+ }
+
+ TreeNode(TreeNode parent, String id)
+ {
+ super(parent, id);
+ }
+
+ Root getRoot()
+ {
+ assert _parent != null;
+ return ((TreeNode)_parent).getRoot();
+ }
+
+ TreeNode findChildLike(TreeNode other)
+ {
+ //
+ // Default implementation just use id; not always appropriate
+ //
+ return (TreeNode)findChild(other.getId());
+ }
+
+
+ boolean isEditable()
+ {
+ if(_parent == null)
+ {
+ return true;
+ }
+ else
+ {
+ return ((TreeNode)_parent).isEditable();
+ }
+ }
+
+ //
+ // Get variable-resolver
+ //
+ Utils.Resolver getResolver()
+ {
+ return ((TreeNode)_parent).getResolver();
+ }
+
+ //
+ // Find child whose descriptor == the given descriptor
+ //
+ TreeNode findChildWithDescriptor(Object descriptor)
+ {
+ Enumeration p = children();
+ while(p.hasMoreElements())
+ {
+ TreeNode node = (TreeNode)p.nextElement();
+ if(node.getDescriptor() == descriptor)
+ {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ static String[] createAttribute(String name, String value)
+ {
+ return new String[]{name, value};
+ }
+
+ static void writeVariables(XMLWriter writer,
+ java.util.SortedMap variables)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = variables.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", entry.getKey().toString()));
+ attributes.add(createAttribute("value", entry.getValue().toString()));
+
+ writer.writeElement("variable", attributes);
+ }
+ }
+
+ static void writeProperties(XMLWriter writer,
+ java.util.List properties)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = properties.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", pd.name));
+ attributes.add(createAttribute("value", pd.value));
+ writer.writeElement("property", attributes);
+ }
+ }
+
+ static void writeDistribution(XMLWriter writer,
+ DistributionDescriptor descriptor)
+ throws java.io.IOException
+ {
+ if(descriptor.icepatch.length() > 0)
+ {
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("icepatch", descriptor.icepatch));
+
+ if(descriptor.directories.isEmpty())
+ {
+ writer.writeElement("distrib", attributes);
+ }
+ else
+ {
+ writer.writeStartTag("distrib", attributes);
+ java.util.Iterator p = descriptor.directories.iterator();
+ while(p.hasNext())
+ {
+ writer.writeElement("directory", p.next().toString());
+ }
+ writer.writeEndTag("distrib");
+ }
+ }
+ }
+
+ static void writeObjects(XMLWriter writer, java.util.List objects)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = objects.iterator();
+ while(p.hasNext())
+ {
+ ObjectDescriptor od = (ObjectDescriptor)p.next();
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("identity", Ice.Util.identityToString(od.id)));
+ if(od.type.length() > 0)
+ {
+ attributes.add(createAttribute("type", od.type));
+ }
+ writer.writeElement("object", attributes);
+ }
+ }
+
+ static void writeParameters(XMLWriter writer, java.util.List parameters,
+ java.util.Map defaultValues)
+ throws java.io.IOException
+ {
+ java.util.Iterator p = parameters.iterator();
+ while(p.hasNext())
+ {
+ String parameter = (String)p.next();
+ String val = (String)defaultValues.get(parameter);
+ java.util.List attributes = new java.util.LinkedList();
+ attributes.add(createAttribute("name", parameter));
+ if(val != null)
+ {
+ attributes.add(createAttribute("default", val));
+ }
+ writer.writeElement("parameter", attributes);
+ }
+ }
+
+ static java.util.LinkedList
+ parameterValuesToAttributes(java.util.Map parameterValues,
+ java.util.List parameters)
+ {
+ java.util.LinkedList result = new java.util.LinkedList();
+
+ java.util.Iterator p = parameters.iterator();
+ while(p.hasNext())
+ {
+ String param = (String)p.next();
+ String val = (String)parameterValues.get(param);
+ if(val != null)
+ {
+ result.add(createAttribute(param, val));
+ }
+ }
+ return result;
+ }
+
+
+
+ //
+ // Actions
+ //
+ public static final int NEW_ADAPTER = 0;
+ public static final int NEW_DBENV = 1;
+ public static final int NEW_NODE = 2;
+ public static final int NEW_REPLICA_GROUP = 3;
+ public static final int NEW_SERVER = 4;
+ public static final int NEW_SERVER_ICEBOX = 5;
+ public static final int NEW_SERVER_FROM_TEMPLATE = 6;
+ public static final int NEW_SERVICE = 7;
+ public static final int NEW_SERVICE_FROM_TEMPLATE = 8;
+ public static final int NEW_TEMPLATE_SERVER = 9;
+ public static final int NEW_TEMPLATE_SERVER_ICEBOX = 10;
+ public static final int NEW_TEMPLATE_SERVICE = 11;
+
+ public static final int COPY = 12;
+ public static final int PASTE = 13;
+ public static final int DELETE = 14;
+
+ public static final int SHOW_VARS = 15;
+ public static final int SUBSTITUTE_VARS = 16;
+
+ public static final int MOVE_UP = 17;
+ public static final int MOVE_DOWN = 18;
+
+ static public final int ACTION_COUNT = 19;
+
+ public boolean[] getAvailableActions()
+ {
+ return new boolean[ACTION_COUNT];
+ }
+ public void newAdapter()
+ {
+ assert false;
+ }
+ public void newDbEnv()
+ {
+ assert false;
+ }
+ public void newNode()
+ {
+ assert false;
+ }
+ public void newReplicaGroup()
+ {
+ assert false;
+ }
+ public void newServer()
+ {
+ assert false;
+ }
+ public void newServerIceBox()
+ {
+ assert false;
+ }
+ public void newServerFromTemplate()
+ {
+ assert false;
+ }
+ public void newService()
+ {
+ assert false;
+ }
+ public void newServiceFromTemplate()
+ {
+ assert false;
+ }
+ public void newTemplateServer()
+ {
+ assert false;
+ }
+ public void newTemplateServerIceBox()
+ {
+ assert false;
+ }
+ public void newTemplateService()
+ {
+ assert false;
+ }
+ public void copy()
+ {
+ assert false;
+ }
+ public void paste()
+ {
+ assert false;
+ }
+ public void delete()
+ {
+ destroy();
+ if(_parent != null)
+ {
+ getRoot().setSelectedNode((TreeNode)_parent);
+ }
+ }
+ public void moveUp()
+ {
+ assert false;
+ }
+ public void moveDown()
+ {
+ assert false;
+ }
+
+
+}
diff --git a/java/src/IceGrid/TreeNode/DuplicateIdException.java b/java/src/IceGridGUI/Application/UpdateFailedException.java
index ba97363dadf..2e400c63eec 100755
--- a/java/src/IceGrid/TreeNode/DuplicateIdException.java
+++ b/java/src/IceGridGUI/Application/UpdateFailedException.java
@@ -1,27 +1,26 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
-class DuplicateIdException extends Exception
+class UpdateFailedException extends Exception
{
- DuplicateIdException(Parent parent, String id)
+ UpdateFailedException(TreeNode parent, String id)
{
_parent = parent;
_id = id;
}
-
+
public String toString()
{
- return _parent.getId() + " cannot have two children with '"
- + _id + "' as id";
+ return _parent.getFullId().toString() + " has already a child with '" + _id + "' as ID.";
}
-
- private Parent _parent;
+
+ private TreeNode _parent;
private String _id;
}
diff --git a/java/src/IceGridGUI/ApplicationActions.java b/java/src/IceGridGUI/ApplicationActions.java
new file mode 100755
index 00000000000..5501e9abef0
--- /dev/null
+++ b/java/src/IceGridGUI/ApplicationActions.java
@@ -0,0 +1,246 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.KeyStroke;
+
+import IceGrid.*;
+import IceGridGUI.Application.*;
+
+//
+// Holds all actions for the Application view
+//
+public class ApplicationActions
+{
+ public Action get(int index)
+ {
+ return _array[index];
+ }
+
+ public boolean[] setTarget(TreeNode target)
+ {
+ _target = target;
+
+ boolean[] availableActions;
+ if(_target == null)
+ {
+ availableActions = new boolean[TreeNode.ACTION_COUNT];
+ }
+ else
+ {
+ availableActions = _target.getAvailableActions();
+ }
+
+ for(int i = 0; i < _array.length; ++i)
+ {
+ _array[i].setEnabled(availableActions[i]);
+ }
+
+ return availableActions;
+ }
+
+ ApplicationActions(boolean popup)
+ {
+ final int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+
+ _array[TreeNode.NEW_ADAPTER] = new AbstractAction(
+ popup ? "New adapter" : "Adapter")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newAdapter();
+ }
+ };
+
+ _array[TreeNode.NEW_DBENV] = new AbstractAction(
+ popup ? "New database environment" : "Database environment")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newDbEnv();
+ }
+ };
+
+ _array[TreeNode.NEW_NODE] = new AbstractAction(
+ popup ? "New node" : "Node")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newNode();
+ }
+ };
+
+ _array[TreeNode.NEW_REPLICA_GROUP] = new AbstractAction(
+ popup ? "New replica group" : "Replica group" )
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newReplicaGroup();
+ }
+ };
+
+ _array[TreeNode.NEW_SERVER] = new AbstractAction(
+ popup ? "New server" : "Server")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newServer();
+ }
+ };
+
+ _array[TreeNode.NEW_SERVER_ICEBOX] = new AbstractAction(
+ popup ? "New IceBox server" : "IceBox server")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newServerIceBox();
+ }
+ };
+
+ _array[TreeNode.NEW_SERVER_FROM_TEMPLATE] = new AbstractAction(
+ popup ? "New server from template" : "Server from template")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newServerFromTemplate();
+ }
+ };
+
+
+ _array[TreeNode.NEW_SERVICE] = new AbstractAction(
+ popup ? "New service" : "Service")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newService();
+ }
+ };
+
+ _array[TreeNode.NEW_SERVICE_FROM_TEMPLATE] = new AbstractAction(
+ popup ? "New service from template" : "Service from template")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newServiceFromTemplate();
+ }
+ };
+
+ _array[TreeNode.NEW_TEMPLATE_SERVER] = new AbstractAction(
+ popup ? "New Server template" : "Server template")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newTemplateServer();
+ }
+ };
+
+ _array[TreeNode.NEW_TEMPLATE_SERVER_ICEBOX] = new AbstractAction(
+ popup ? "New IceBox server template" : "IceBox server template")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newTemplateServerIceBox();
+ }
+ };
+
+
+ _array[TreeNode.NEW_TEMPLATE_SERVICE] = new AbstractAction(
+ popup ? "New service template" : "Service template")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.newTemplateService();
+ }
+ };
+
+ _array[TreeNode.COPY] = new AbstractAction("Copy")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.copy();
+ }
+ };
+ _array[TreeNode.COPY].putValue(Action.ACCELERATOR_KEY,
+ KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK));
+ _array[TreeNode.COPY].putValue(Action.SHORT_DESCRIPTION, "Copy");
+
+ _array[TreeNode.PASTE] = new AbstractAction("Paste")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.paste();
+ }
+ };
+ _array[TreeNode.PASTE].putValue(Action.ACCELERATOR_KEY,
+ KeyStroke.getKeyStroke(KeyEvent.VK_V, MENU_MASK));
+ _array[TreeNode.PASTE].putValue(Action.SHORT_DESCRIPTION, "Paste");
+
+ _array[TreeNode.DELETE] = new AbstractAction("Delete")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.delete();
+ }
+ };
+ _array[TreeNode.DELETE].putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE"));
+ _array[TreeNode.DELETE].putValue(Action.SHORT_DESCRIPTION, "Delete");
+
+ _array[TreeNode.SHOW_VARS] = new
+ AbstractAction("Show variables")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.getCoordinator().showVars();
+ }
+ };
+ _array[TreeNode.SHOW_VARS].putValue(
+ Action.SHORT_DESCRIPTION,
+ "Show variables and parameters in the Properties pane");
+
+
+ _array[TreeNode.SUBSTITUTE_VARS] = new
+ AbstractAction("Substitute variables")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.getCoordinator().substituteVars();
+ }
+ };
+
+ _array[TreeNode.SUBSTITUTE_VARS].putValue(
+ Action.SHORT_DESCRIPTION,
+ "Substitute variables and parameters with their values in the Properties pane");
+
+
+ _array[TreeNode.MOVE_UP] = new AbstractAction("Move up")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.moveUp();
+ }
+ };
+
+ _array[TreeNode.MOVE_DOWN] = new AbstractAction("Move down")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.moveDown();
+ }
+ };
+ }
+
+ private TreeNode _target;
+ private Action[] _array = new Action[TreeNode.ACTION_COUNT];
+}
diff --git a/java/src/IceGridGUI/ApplicationPane.java b/java/src/IceGridGUI/ApplicationPane.java
new file mode 100755
index 00000000000..efd63957a9e
--- /dev/null
+++ b/java/src/IceGridGUI/ApplicationPane.java
@@ -0,0 +1,393 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.*;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.*;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.plaf.SplitPaneUI;
+import javax.swing.plaf.basic.BasicSplitPaneUI;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import com.jgoodies.looks.Options;
+import com.jgoodies.looks.plastic.PlasticLookAndFeel;
+import com.jgoodies.looks.windows.WindowsLookAndFeel;
+import com.jgoodies.forms.factories.Borders;
+
+import IceGrid.*;
+import IceGridGUI.Application.Editor;
+import IceGridGUI.Application.Root;
+import IceGridGUI.Application.TreeNode;
+
+public class ApplicationPane extends JSplitPane implements Tab
+{
+ public void updateUI()
+ {
+ super.updateUI();
+ setEmptyDividerBorder();
+ }
+
+ public void selected()
+ {
+ Coordinator c = _root.getCoordinator();
+
+ c.getCloseApplicationAction().setEnabled(true);
+
+ boolean enableSave = _root.needsSaving() && (_root.isLive() || _root.hasFile());
+ c.getSaveAction().setEnabled(enableSave);
+ c.getDiscardUpdatesAction().setEnabled(enableSave);
+
+ if(_root.isLive())
+ {
+ c.getSaveToRegistryAction().setEnabled(_root.needsSaving());
+ }
+ else
+ {
+ c.getSaveToRegistryAction().setEnabled(c.getSession() != null);
+ }
+ c.getSaveToFileAction().setEnabled(true);
+
+
+ c.getBackAction().setEnabled(_previousNodes.size() > 0);
+ c.getForwardAction().setEnabled(_nextNodes.size() > 0);
+ c.showActions(_currentNode);
+ }
+
+ public void showNode(TreeNodeBase node)
+ {
+ TreeNode newNode = (TreeNode)node;
+
+ if(newNode != _currentNode)
+ {
+ if(_currentNode != null
+ && _currentNode.isEphemeral() && _root.hasNode(_currentNode))
+ {
+ _currentNode.destroy();
+ _currentNode = null;
+ }
+
+ if(newNode == null)
+ {
+ _currentNode = null;
+ showCurrentNode();
+ }
+ else
+ {
+ if(_currentNode != null && _root.hasNode(_currentNode))
+ {
+ _previousNodes.add(_currentNode);
+ while(_previousNodes.size() >= HISTORY_MAX_SIZE)
+ {
+ _previousNodes.removeFirst();
+ }
+ _root.getCoordinator().getBackAction().setEnabled(true);
+ }
+ _nextNodes.clear();
+ _root.getCoordinator().getForwardAction().setEnabled(false);
+ _currentNode = newNode;
+ showCurrentNode();
+ }
+ }
+ else
+ {
+ refresh();
+ }
+ }
+
+ public void refresh()
+ {
+ _root.cancelEdit();
+
+ if(_currentNode != null)
+ {
+ _root.getCoordinator().showActions(_currentNode);
+ _currentNode.getEditor();
+ }
+ }
+
+ public void back()
+ {
+ TreeNode previousNode = null;
+ do
+ {
+ previousNode = (TreeNode)_previousNodes.removeLast();
+ } while(_previousNodes.size() > 0
+ && (previousNode == _currentNode || !_root.hasNode(previousNode)));
+
+ if(_previousNodes.size() == 0)
+ {
+ _root.getCoordinator().getBackAction().setEnabled(false);
+ }
+
+ if(previousNode != _currentNode)
+ {
+ if(_currentNode != null)
+ {
+ _nextNodes.addFirst(_currentNode);
+ _root.getCoordinator().getForwardAction().setEnabled(true);
+ }
+
+ _currentNode = previousNode;
+ _root.disableSelectionListener();
+ _root.setSelectedNode(_currentNode);
+ _root.enableSelectionListener();
+ showCurrentNode();
+ }
+ }
+
+ public void forward()
+ {
+ TreeNode nextNode = null;
+ do
+ {
+ nextNode = (TreeNode)_nextNodes.removeFirst();
+ } while(_nextNodes.size() > 0
+ && (nextNode == _currentNode || !_root.hasNode(nextNode)));
+
+ if(_nextNodes.size() == 0)
+ {
+ _root.getCoordinator().getForwardAction().setEnabled(false);
+ }
+
+ if(nextNode != _currentNode)
+ {
+ if(_currentNode != null)
+ {
+ _previousNodes.add(_currentNode);
+ _root.getCoordinator().getBackAction().setEnabled(true);
+ }
+
+ _currentNode = nextNode;
+ _root.disableSelectionListener();
+ _root.setSelectedNode(_currentNode);
+ _root.enableSelectionListener();
+ showCurrentNode();
+ }
+ }
+
+ public Root getRoot()
+ {
+ return _root;
+ }
+
+ //
+ // E.g. to replace an ephemeral root
+ //
+ public void setRoot(Root newRoot)
+ {
+ boolean reset = (_root != null);
+
+ if(reset)
+ {
+ ToolTipManager.sharedInstance().unregisterComponent(_root.getTree());
+ _currentNode = null;
+ _previousNodes.clear();
+ _nextNodes.clear();
+ }
+
+ _root = newRoot;
+
+ //
+ // Tree display
+ //
+ TreeCellRenderer renderer = new CellRenderer();
+ PopupListener popupListener = new PopupListener();
+
+ JTree tree = _root.getTree();
+
+ tree.setBorder(new EmptyBorder(5, 5, 5, 5));
+ tree.setCellRenderer(renderer);
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ tree.addMouseListener(popupListener);
+
+ tree.getSelectionModel().setSelectionMode
+ (TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+ tree.addTreeSelectionListener(new SelectionListener());
+
+ tree.setRootVisible(true);
+
+ JScrollPane leftScroll =
+ new JScrollPane(tree,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ leftScroll.setBorder(Borders.EMPTY_BORDER);
+
+ _leftPane.setContent(leftScroll);
+
+ if(reset)
+ {
+ _root.getCoordinator().getMainPane().resetIcon(_root);
+ _leftPane.validate();
+ _leftPane.repaint();
+ }
+ }
+
+ public void save()
+ {
+ _root.save();
+ }
+ public void saveToRegistry()
+ {
+ _root.saveToRegistry();
+ }
+ public void saveToFile()
+ {
+ _root.saveToFile();
+ }
+ public void discardUpdates()
+ {
+ _root.discardUpdates();
+ }
+ public boolean close()
+ {
+ _root.getCoordinator().getMainPane().remove(this);
+ return true;
+ }
+
+ ApplicationPane(Root root)
+ {
+ super(JSplitPane.HORIZONTAL_SPLIT, true);
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ _leftPane = new SimpleInternalFrame("Descriptors");
+ _leftPane.setPreferredSize(new Dimension(280, 350));
+
+ //
+ // Right pane
+ //
+ _propertiesFrame = new SimpleInternalFrame("Properties");
+
+ setLeftComponent(_leftPane);
+ setRightComponent(_propertiesFrame);
+
+ setRoot(root);
+ }
+
+ private void showCurrentNode()
+ {
+ _root.cancelEdit();
+ _root.getCoordinator().showActions(_currentNode);
+
+ if(_currentNode == null)
+ {
+ Component oldContent = _propertiesFrame.getContent();
+ if(oldContent != null)
+ {
+ _propertiesFrame.remove(oldContent);
+ }
+ _propertiesFrame.setTitle("Properties");
+ _propertiesFrame.setToolBar(null);
+ }
+ else
+ {
+ Editor editor = _currentNode.getEditor();
+ Component currentProperties = editor.getProperties();
+ _propertiesFrame.setContent(currentProperties);
+ _propertiesFrame.setTitle(currentProperties.getName());
+ _propertiesFrame.setToolBar(editor.getToolBar());
+ }
+ _propertiesFrame.validate();
+ _propertiesFrame.repaint();
+ }
+
+
+ private void setEmptyDividerBorder()
+ {
+ SplitPaneUI splitPaneUI = getUI();
+ if(splitPaneUI instanceof BasicSplitPaneUI)
+ {
+ BasicSplitPaneUI basicUI = (BasicSplitPaneUI)splitPaneUI;
+ basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder());
+ }
+ }
+
+ private class PopupListener extends MouseAdapter
+ {
+ public void mousePressed(MouseEvent e)
+ {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ maybeShowPopup(e);
+ }
+
+ private void maybeShowPopup(MouseEvent e)
+ {
+ if (e.isPopupTrigger())
+ {
+ JTree tree = (JTree)e.getComponent();
+
+ TreePath path = tree.getPathForLocation(e.getX(), e.getY());
+
+ if(path != null)
+ {
+ TreeNode node = (TreeNode)path.getLastPathComponent();
+ JPopupMenu popup = node.getPopupMenu();
+ if(popup != null)
+ {
+ popup.show(tree, e.getX(), e.getY());
+ }
+ }
+ }
+ }
+ }
+
+
+ private class SelectionListener implements TreeSelectionListener
+ {
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ if(_root.isSelectionListenerEnabled())
+ {
+ TreePath path = null;
+ if(e.isAddedPath())
+ {
+ path = e.getPath();
+ }
+
+ if(path == null)
+ {
+ showNode(null);
+ }
+ else
+ {
+ showNode((TreeNode)path.getLastPathComponent());
+ }
+ }
+ }
+ }
+
+
+ private Root _root;
+ private SimpleInternalFrame _leftPane;
+ private SimpleInternalFrame _propertiesFrame;
+
+ //
+ // back/forward navigation
+ //
+ private java.util.LinkedList _previousNodes = new java.util.LinkedList();
+ private java.util.LinkedList _nextNodes = new java.util.LinkedList();
+ private TreeNode _currentNode;
+
+ static private final int HISTORY_MAX_SIZE = 20;
+}
diff --git a/java/src/IceGrid/BareBonesBrowserLaunch.java b/java/src/IceGridGUI/BareBonesBrowserLaunch.java
index 223fb3fd74b..37a219a8dcf 100755
--- a/java/src/IceGrid/BareBonesBrowserLaunch.java
+++ b/java/src/IceGridGUI/BareBonesBrowserLaunch.java
@@ -13,7 +13,7 @@
// Public Domain Software -- Free to Use as You Like //
////////////////////////////////////////////////////////
-package IceGrid;
+package IceGridGUI;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
diff --git a/java/src/IceGrid/CellRenderer.java b/java/src/IceGridGUI/CellRenderer.java
index 51081b6c4a6..2eb4a3a5143 100755
--- a/java/src/IceGrid/CellRenderer.java
+++ b/java/src/IceGridGUI/CellRenderer.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import java.awt.Component;
import javax.swing.JTree;
diff --git a/java/src/IceGridGUI/Coordinator.java b/java/src/IceGridGUI/Coordinator.java
new file mode 100755
index 00000000000..da927772440
--- /dev/null
+++ b/java/src/IceGridGUI/Coordinator.java
@@ -0,0 +1,1797 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+
+import java.awt.BorderLayout;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Rectangle;
+import java.awt.Container;
+import java.awt.Component;
+import java.awt.Toolkit;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+
+import java.io.File;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JToggleButton;
+import javax.swing.JToolBar;
+import javax.swing.JTree;
+import javax.swing.KeyStroke;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+
+import javax.swing.border.EmptyBorder;
+import javax.swing.filechooser.FileFilter;
+
+import com.jgoodies.looks.Options;
+import com.jgoodies.looks.HeaderStyle;
+import com.jgoodies.looks.BorderStyle;
+import com.jgoodies.looks.plastic.PlasticLookAndFeel;
+
+import IceGrid.*;
+
+//
+// This class coordinates the communications between the various objects
+// that make up the IceGrid GUI.
+// It also provides both the menu bar and tool bar.
+//
+public class Coordinator
+{
+ private class StatusBarI extends JPanel implements StatusBar
+ {
+ StatusBarI()
+ {
+ super(new BorderLayout());
+ setBorder(new EmptyBorder(0, 13, 10, 13));
+
+ _text = new JLabel();
+ _text.setHorizontalAlignment(SwingConstants.LEFT);
+ add(_text, BorderLayout.LINE_START);
+
+ _connectedLabel = new JLabel("Working Offline");
+ _connectedLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+ add(_connectedLabel, BorderLayout.LINE_END);
+ }
+
+ public void setText(String text)
+ {
+ _text.setText(text);
+ }
+
+ public void setConnected(boolean connected)
+ {
+ if(connected)
+ {
+ _connectedLabel.setText("Working Online");
+ }
+ else
+ {
+ _connectedLabel.setText("Working Offline");
+ }
+ }
+
+ JLabel _connectedLabel;
+ JLabel _text;
+ }
+
+ private class MenuBar extends JMenuBar
+ {
+ private MenuBar()
+ {
+ putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
+ putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
+
+ //
+ // File menu
+ //
+ JMenu fileMenu = new JMenu("File");
+ fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F);
+ add(fileMenu);
+
+ //
+ // New sub-menu
+ //
+ _newMenu = new JMenu("New");
+ fileMenu.add(_newMenu);
+ _newMenu.add(_newApplication);
+ _newMenu.add(_newApplicationWithDefaultTemplates);
+ _newMenu.addSeparator();
+
+ _newMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_ADAPTER));
+ _newMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_DBENV));
+ _newMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_NODE));
+ _newMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_REPLICA_GROUP));
+
+
+ //
+ // Open sub-menu
+ //
+ JMenu openMenu = new JMenu("Open");
+ openMenu.add(_openApplicationFromFile);
+ openMenu.add(_openApplicationFromRegistry);
+
+
+ //
+ // New server sub-sub-menu
+ //
+ _newServerMenu = new JMenu("Server");
+ _newServerMenu.setEnabled(false);
+ _newMenu.add(_newServerMenu);
+ _newServerMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_SERVER));
+ _newServerMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_SERVER_ICEBOX));
+ _newServerMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_SERVER_FROM_TEMPLATE));
+
+ //
+ // New service sub-sub-menu
+ //
+ _newServiceMenu = new JMenu("Service");
+ _newServiceMenu.setEnabled(false);
+ _newMenu.add(_newServiceMenu);
+ _newServiceMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_SERVICE));
+ _newServiceMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_SERVICE_FROM_TEMPLATE));
+
+ //
+ // New template sub-sub-menu
+ //
+ _newTemplateMenu = new JMenu("Template");
+ _newTemplateMenu.setEnabled(false);
+ _newMenu.add(_newTemplateMenu);
+ _newTemplateMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVER));
+ _newTemplateMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVER_ICEBOX));
+ _newTemplateMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVICE));
+
+ fileMenu.addSeparator();
+ fileMenu.add(_login);
+ fileMenu.add(_logout);
+ fileMenu.addSeparator();
+ fileMenu.add(_acquireExclusiveWriteAccess);
+ fileMenu.add(_releaseExclusiveWriteAccess);
+ fileMenu.addSeparator();
+ fileMenu.add(openMenu);
+ fileMenu.add(_closeApplication);
+ fileMenu.add(_save);
+ fileMenu.add(_saveToFile);
+ fileMenu.add(_saveToRegistry);
+ fileMenu.addSeparator();
+ fileMenu.add(_discardUpdates);
+ fileMenu.addSeparator();
+ fileMenu.add(_exit);
+
+ //
+ // Edit menu
+ //
+ JMenu editMenu = new JMenu("Edit");
+ editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E);
+ add(editMenu);
+ editMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY));
+ editMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.PASTE));
+ editMenu.addSeparator();
+ editMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.DELETE));
+
+ //
+ // View menu
+ //
+ JMenu viewMenu = new JMenu("View");
+ viewMenu.setMnemonic(java.awt.event.KeyEvent.VK_V);
+ add(viewMenu);
+ viewMenu.add(_showVarsMenuItem);
+ viewMenu.add(_substituteMenuItem);
+ viewMenu.addSeparator();
+ viewMenu.add(_back);
+ viewMenu.add(_forward);
+
+ //
+ // Tools menu
+ //
+ JMenu toolsMenu = new JMenu("Tools");
+ toolsMenu.setMnemonic(java.awt.event.KeyEvent.VK_T);
+ add(toolsMenu);
+
+ //
+ // Application sub-menu
+ //
+ _appMenu = new JMenu("Application");
+ _appMenu.setEnabled(false);
+ toolsMenu.add(_appMenu);
+ _appMenu.add(_installDistribution);
+
+ //
+ // Node sub-menu
+ //
+ _nodeMenu = new JMenu("Node");
+ _nodeMenu.setEnabled(false);
+ toolsMenu.add(_nodeMenu);
+ _nodeMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_NODE));
+
+ //
+ // Server sub-menu
+ //
+ _serverMenu = new JMenu("Server");
+ _serverMenu.setEnabled(false);
+ toolsMenu.add(_serverMenu);
+ _serverMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.START));
+ _serverMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.STOP));
+ _serverMenu.addSeparator();
+ _serverMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.ENABLE));
+ _serverMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.DISABLE));
+ _serverMenu.addSeparator();
+ _serverMenu.add(_liveActionsForMenu.get(
+ IceGridGUI.LiveDeployment.TreeNode.SERVER_INSTALL_DISTRIBUTION));
+
+ //
+ // Service sub-menu
+ //
+ _serviceMenu = new JMenu("Service");
+ _serviceMenu.setEnabled(false);
+ toolsMenu.add(_serviceMenu);
+ _serviceMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_UP));
+ _serviceMenu.add(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_DOWN));
+
+ //
+ // Help menu
+ //
+ JMenu helpMenu = new JMenu("Help");
+ helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H);
+ add(helpMenu);
+
+ helpMenu.add(_helpContents);
+ if(GPL_BUILD)
+ {
+ helpMenu.addSeparator();
+ helpMenu.add(_copying);
+ helpMenu.add(_warranty);
+ }
+
+ helpMenu.addSeparator();
+ helpMenu.add(_about);
+ }
+ }
+
+ private class ToolBar extends JToolBar
+ {
+ private ToolBar()
+ {
+ putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
+ putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
+ setFloatable(false);
+ putClientProperty("JToolBar.isRollover", Boolean.TRUE);
+
+ JButton button = new JButton(_login);
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/login.png"));
+ add(button);
+
+ addSeparator();
+
+ button = new JButton(_back);
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/back.png"));
+ add(button);
+ button = new JButton(_forward);
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/forward.png"));
+ add(button);
+
+ addSeparator();
+
+ button = new JButton(_save);
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/save.png"));
+ add(button);
+ button = new JButton(_discardUpdates);
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/discard.png"));
+ add(button);
+
+ addSeparator();
+
+ button = new JButton(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY));
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/copy.png"));
+ add(button);
+ button = new JButton(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.PASTE));
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/paste.png"));
+ add(button);
+ button = new JButton(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.DELETE));
+ button.setText(null);
+ button.setIcon(Utils.getIcon("/icons/24x24/delete.png"));
+ add(button);
+
+ addSeparator();
+
+ add(_showVarsTool);
+ add(_substituteTool);
+ }
+ }
+
+ //
+ // All Coordinator's methods run in the UI thread
+ //
+ public Ice.Communicator getCommunicator()
+ {
+ return _communicator;
+ }
+
+ public Tab getCurrentTab()
+ {
+ return (Tab)_mainPane.getSelectedComponent();
+ }
+
+ public Action getBackAction()
+ {
+ return _back;
+ }
+
+ public Action getForwardAction()
+ {
+ return _forward;
+ }
+
+ public Action getCloseApplicationAction()
+ {
+ return _closeApplication;
+ }
+
+ public Action getSaveAction()
+ {
+ return _save;
+ }
+
+ public Action getSaveToRegistryAction()
+ {
+ return _saveToRegistry;
+ }
+
+ public Action getSaveToFileAction()
+ {
+ return _saveToFile;
+ }
+
+ public Action getDiscardUpdatesAction()
+ {
+ return _discardUpdates;
+ }
+
+
+
+ //
+ // Open live application and select application tab
+ //
+ public ApplicationPane openLiveApplication(String applicationName)
+ {
+ ApplicationPane app = (ApplicationPane)_liveApplications.get(applicationName);
+ if(app == null)
+ {
+ ApplicationDescriptor desc =
+ _liveDeploymentRoot.getApplicationDescriptor(applicationName);
+ if(desc == null)
+ {
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "The application '" + applicationName + "' was not found in the Registry.",
+ "No such application",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ //
+ // Essential: deep-copy desc!
+ //
+ desc = IceGridGUI.Application.Root.copyDescriptor(desc);
+
+ app = new ApplicationPane(new IceGridGUI.Application.Root(this, desc, true, null));
+ _mainPane.addApplication(app);
+ _liveApplications.put(applicationName, app);
+ }
+ _mainPane.setSelectedComponent(app);
+ return app;
+ }
+
+ public void removeLiveApplication(String name)
+ {
+ _liveApplications.remove(name);
+ }
+
+ public void addLiveApplication(IceGridGUI.Application.Root root)
+ {
+ ApplicationPane app = _mainPane.findApplication(root);
+ assert app != null;
+ _liveApplications.put(app.getRoot().getId(), app);
+ }
+
+ public ApplicationPane getLiveApplication(String name)
+ {
+ return (ApplicationPane)_liveApplications.get(name);
+ }
+
+
+ //
+ // From the Registry observer:
+ //
+ void registryInit(int serial, final java.util.List applications)
+ {
+ assert _latestSerial == -1;
+ _latestSerial = serial;
+
+ _liveDeploymentRoot.init(_admin.ice_getIdentity().category, applications);
+ //
+ // When we get this init, we can't have any live Application yet.
+ //
+ }
+
+ void applicationAdded(int serial, ApplicationDescriptor desc)
+ {
+ _liveDeploymentRoot.applicationAdded(desc);
+ _statusBar.setText(
+ "Last update: new application '" + desc.name + "'");
+ updateSerial(serial);
+ }
+
+ void applicationRemoved(int serial, String name)
+ {
+ _liveDeploymentRoot.applicationRemoved(name);
+ _statusBar.setText(
+ "Last update: application '" + name + "' was removed");
+
+ ApplicationPane app =
+ (ApplicationPane)_liveApplications.get(name);
+
+ if(app.getRoot().kill())
+ {
+ _mainPane.remove(app);
+ }
+ _liveApplications.remove(name);
+ updateSerial(serial);
+ }
+
+ void applicationUpdated(int serial, ApplicationUpdateDescriptor desc)
+ {
+ _liveDeploymentRoot.applicationUpdated(desc);
+ _liveDeploymentPane.refresh();
+
+ _statusBar.setText("Last update: application '" + desc.name + "' was updated");
+
+ ApplicationPane app =
+ (ApplicationPane)_liveApplications.get(desc.name);
+
+ if(app != null)
+ {
+ if(app.getRoot().update(desc))
+ {
+ app.refresh();
+ }
+ }
+ updateSerial(serial);
+ }
+
+ public void accessDenied(AccessDeniedException e)
+ {
+ assert false;
+
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "Another session (username = " + e.lockUserId
+ + ") has exclusive write access to the Registry",
+ "Access Denied",
+ JOptionPane.ERROR_MESSAGE);
+
+ }
+
+ public void pasteApplication()
+ {
+ Object descriptor = getClipboard();
+ ApplicationDescriptor desc =
+ IceGridGUI.Application.Root.copyDescriptor((ApplicationDescriptor)descriptor);
+
+ IceGridGUI.Application.Root root = new IceGridGUI.Application.Root(this, desc);
+ ApplicationPane app = new ApplicationPane(root);
+ _mainPane.addApplication(app);
+ _mainPane.setSelectedComponent(app);
+ root.setSelectedNode(root);
+ }
+
+ public boolean removeApplicationFromRegistry(String name)
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ try
+ {
+ _sessionKeeper.getSession().removeApplication(name);
+ }
+ catch(AccessDeniedException e)
+ {
+ accessDenied(e);
+ return false;
+ }
+ catch(ApplicationNotExistException e)
+ {
+ //
+ // Somebody else deleted this application at about the same time
+ //
+ }
+ finally
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+
+ _liveApplications.remove(name);
+ return true;
+ }
+
+ public void acquireExclusiveWriteAccess(Runnable runnable)
+ throws AccessDeniedException
+ {
+ if(_writeSerial == -1)
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ try
+ {
+ _writeSerial = _sessionKeeper.getSession().startUpdate();
+ System.err.println("Write serial is: " + _writeSerial);
+ }
+ finally
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ assert _onExclusiveWrite == null;
+
+ //
+ // Must increment now since run() can call releaseExclusiveWriteAccess()
+ //
+ _writeAccessCount++;
+
+ if(runnable != null)
+ {
+ if(_writeSerial <= _latestSerial)
+ {
+ runnable.run();
+ }
+ else
+ {
+ _onExclusiveWrite = runnable;
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ //
+ // TODO: start a thread to check we don't wait forever
+ //
+ }
+ }
+ }
+
+ public void releaseExclusiveWriteAccess()
+ {
+ if(--_writeAccessCount == 0)
+ {
+ System.err.println("finishUpdate");
+ try
+ {
+ _writeSerial = -1;
+ _sessionKeeper.getSession().finishUpdate();
+ }
+ catch(AccessDeniedException e)
+ {
+ accessDenied(e);
+ }
+ }
+ }
+
+ private void updateSerial(int serial)
+ {
+ assert serial == _latestSerial + 1;
+ _latestSerial = serial;
+
+ if(_writeAccessCount > 0 &&
+ _writeSerial <= _latestSerial &&
+ _onExclusiveWrite != null)
+ {
+ Runnable runnable = _onExclusiveWrite;
+ _onExclusiveWrite = null;
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ runnable.run();
+ }
+ }
+
+ //
+ // From the Node observer:
+ //
+ void nodeUp(NodeDynamicInfo updatedInfo)
+ {
+ _liveDeploymentRoot.nodeUp(updatedInfo);
+ _liveDeploymentPane.refresh();
+ }
+
+ void nodeDown(String node)
+ {
+ _liveDeploymentRoot.nodeDown(node);
+ _liveDeploymentPane.refresh();
+ }
+
+ void updateServer(String node, ServerDynamicInfo updatedInfo)
+ {
+ _liveDeploymentRoot.updateServer(node, updatedInfo);
+ _liveDeploymentPane.refresh();
+ }
+
+ void updateAdapter(String node, AdapterDynamicInfo updatedInfo)
+ {
+ _liveDeploymentRoot.updateAdapter(node, updatedInfo);
+ _liveDeploymentPane.refresh();
+ }
+
+ void sessionLost()
+ {
+ _latestSerial = -1;
+ _writeSerial = -1;
+ _writeAccessCount = 0;
+ _onExclusiveWrite = null;
+ _admin = null;
+ _liveDeploymentRoot.clear();
+
+ //
+ // Kill all live applications
+ //
+ java.util.Iterator p = _liveApplications.values().iterator();
+ while(p.hasNext())
+ {
+ ApplicationPane app = (ApplicationPane)p.next();
+ if(app.getRoot().kill())
+ {
+ _mainPane.remove(app);
+ }
+ }
+ _liveApplications.clear();
+
+ _logout.setEnabled(false);
+ _openApplicationFromRegistry.setEnabled(false);
+ _newApplicationWithDefaultTemplates.setEnabled(false);
+ _acquireExclusiveWriteAccess.setEnabled(false);
+ _releaseExclusiveWriteAccess.setEnabled(false);
+ _saveToRegistry.setEnabled(false);
+ }
+
+ SessionPrx login(SessionKeeper.LoginInfo info, Component parent)
+ {
+ _liveDeploymentRoot.clear();
+
+ SessionPrx session = null;
+
+ if(_routedAdapter != null)
+ {
+ //
+ // Clean it up!
+ //
+ _routedAdapter.removeRouter(_communicator.getDefaultRouter());
+ _routedAdapter.deactivate();
+ _routedAdapter.waitForDeactivate();
+ _routedAdapter = null;
+ }
+
+ _communicator.setDefaultRouter(null);
+ _communicator.setDefaultLocator(null);
+
+ if(info.routed)
+ {
+ //
+ // Router
+ //
+
+ String str = info.routerInstanceName + "/router";
+ if(!info.routerEndpoints.equals(""))
+ {
+ str += ":" + info.routerEndpoints;
+ }
+
+ try
+ {
+ Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.
+ uncheckedCast(_communicator.stringToProxy(str));
+
+ //
+ // The session must be routed through this router
+ //
+ _communicator.setDefaultRouter(router);
+
+ Glacier2.SessionPrx s =
+ router.createSession(
+ info.routerUsername, new String(info.routerPassword));
+
+ session = SessionPrxHelper.uncheckedCast(s);
+ }
+ catch(Glacier2.PermissionDeniedException e)
+ {
+ JOptionPane.showMessageDialog(parent,
+ "Permission denied: "
+ + e.reason,
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ catch(Glacier2.CannotCreateSessionException e)
+ {
+ JOptionPane.showMessageDialog(parent,
+ "Could not create session: "
+ + e.reason,
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ catch(Ice.LocalException e)
+ {
+ JOptionPane.showMessageDialog(parent,
+ "Could not create session: "
+ + e.toString(),
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ }
+ else
+ {
+ //
+ // The client uses the locator only without routing
+ //
+ String str = info.registryInstanceName + "/Locator";
+ if(!info.registryEndpoints.equals(""))
+ {
+ str += ":" + info.registryEndpoints;
+ }
+
+ try
+ {
+ Ice.LocatorPrx defaultLocator = Ice.LocatorPrxHelper.
+ checkedCast(_communicator.stringToProxy(str));
+ _communicator.setDefaultLocator(defaultLocator);
+ }
+ catch(Ice.LocalException e)
+ {
+ JOptionPane.showMessageDialog(
+ parent,
+ "Could not contact '" + str + "': " + e.toString(),
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+
+ //
+ // Local session
+ //
+ str = info.registryInstanceName + "/SessionManager";
+
+ SessionManagerPrx sessionManager = SessionManagerPrxHelper.
+ uncheckedCast(_communicator.stringToProxy(str));
+
+ try
+ {
+ session = sessionManager.createLocalSession(info.registryUsername);
+ }
+ catch(Ice.LocalException e)
+ {
+ JOptionPane.showMessageDialog(parent,
+ "Could not create session: "
+ + e.toString(),
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ }
+
+ //
+ // Admin
+ //
+ try
+ {
+ _admin = session.getAdmin();
+ }
+ catch(Ice.LocalException e)
+ {
+ JOptionPane.showMessageDialog(
+ parent,
+ "Could not retrieve Admin proxy: " + e.toString(),
+ "Login failed",
+ JOptionPane.ERROR_MESSAGE);
+ destroySession(session);
+ return null;
+ }
+
+ _logout.setEnabled(true);
+ _openApplicationFromRegistry.setEnabled(true);
+ _newApplicationWithDefaultTemplates.setEnabled(true);
+ _acquireExclusiveWriteAccess.setEnabled(true);
+
+ _mainPane.setSelectedComponent(_liveDeploymentPane);
+
+ return session;
+ }
+
+ Ice.ObjectAdapter getObjectAdapter()
+ {
+ Ice.RouterPrx router = _communicator.getDefaultRouter();
+
+ if(router == null)
+ {
+ if(_localAdapter == null)
+ {
+ _localAdapter =
+ _communicator.createObjectAdapter("IceGrid.AdminGUI");
+ _localAdapter.activate();
+ }
+ return _localAdapter;
+ }
+ else
+ {
+ if(_routedAdapter == null)
+ {
+ //
+ // Needs a unique name since we destroy this adapter at
+ // each new login
+ //
+ String name = "RoutedAdapter-" + Ice.Util.generateUUID();
+
+ _routedAdapter =
+ _communicator.createObjectAdapter(name);
+ _routedAdapter.addRouter(router);
+ _routedAdapter.activate();
+ }
+ return _routedAdapter;
+ }
+ }
+
+
+ void destroySession(SessionPrx session)
+ {
+ Ice.RouterPrx router = _communicator.getDefaultRouter();
+
+ try
+ {
+ if(router == null)
+ {
+ session.destroy();
+ }
+ else
+ {
+ Glacier2.RouterPrx gr
+ = Glacier2.RouterPrxHelper.uncheckedCast(router);
+ gr.destroySession();
+ }
+ }
+ catch(Glacier2.SessionNotExistException e)
+ {
+ // Ignored
+ }
+ catch(Ice.LocalException e)
+ {
+ // Ignored
+ }
+ }
+
+ void showVars()
+ {
+ substitute(false);
+ }
+
+ void substituteVars()
+ {
+ substitute(true);
+ }
+
+ private void substitute(boolean newValue)
+ {
+ if(_substitute != newValue)
+ {
+ _substitute = newValue;
+
+ if(_substitute)
+ {
+ _substituteMenuItem.setSelected(true);
+ _substituteTool.setSelected(true);
+ }
+ else
+ {
+ _showVarsMenuItem.setSelected(true);
+ _showVarsTool.setSelected(true);
+ }
+ getCurrentTab().refresh();
+ }
+ }
+
+ public boolean substitute()
+ {
+ return _substitute;
+ }
+
+ public AdminPrx getAdmin()
+ {
+ return _admin;
+ }
+
+ public StatusBar getStatusBar()
+ {
+ return _statusBar;
+ }
+
+ public JFrame getMainFrame()
+ {
+ return _mainFrame;
+ }
+
+ public MainPane getMainPane()
+ {
+ return _mainPane;
+ }
+
+ public File saveToFile(boolean ask, IceGridGUI.Application.Root root,
+ File file)
+ {
+ if(ask || file == null)
+ {
+ if(file != null)
+ {
+ _fileChooser.setSelectedFile(file);
+ }
+ int result = _fileChooser.showSaveDialog(_mainFrame);
+ if(result == JFileChooser.APPROVE_OPTION)
+ {
+ file = _fileChooser.getSelectedFile();
+ }
+ else
+ {
+ file = null;
+ }
+ }
+ if(file != null)
+ {
+ try
+ {
+ XMLWriter writer = new XMLWriter(file);
+ root.write(writer);
+ writer.close();
+ _statusBar.setText(
+ "Saved application '" + root.getId() + "' to "
+ + file.getAbsolutePath());
+ }
+ catch(java.io.FileNotFoundException e)
+ {
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "Cannot use the selected file for writing.",
+ "File Not Found",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ catch(java.io.IOException e)
+ {
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "IO Exception: " + e.toString(),
+ "IO Exception",
+ JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+ }
+ return file;
+ }
+
+ static private Ice.Communicator createCommunicator(String[] args)
+ {
+ Ice.StringSeqHolder argSeq = new Ice.StringSeqHolder(args);
+
+ Ice.Properties properties = Ice.Util.createProperties(argSeq);
+
+ //
+ // Set various default values
+ //
+ if(properties.getProperty("Ice.Override.ConnectTimeout").equals(""))
+ {
+ properties.setProperty("Ice.Override.ConnectTimeout", "5000");
+ }
+
+ if(properties.getProperty("IceGrid.AdminGUI.Endpoints").equals(""))
+ {
+ properties.setProperty("IceGrid.AdminGUI.Endpoints", "tcp -t 10000");
+ }
+
+ //
+ // For SSL
+ //
+ if(properties.getProperty("Ice.ThreadPerConnection").equals(""))
+ {
+ properties.setProperty("Ice.ThreadPerConnection", "1");
+ }
+
+ //
+ // For Glacier
+ //
+ if(properties.getProperty("Ice.ACM.Client").equals(""))
+ {
+ properties.setProperty("Ice.ACM.Client", "0");
+ }
+ if(properties.getProperty("Ice.MonitorConnections").equals(""))
+ {
+ properties.setProperty("Ice.MonitorConnections", "5");
+ }
+
+ //
+ // Retries are not useful when using Glacier2, however
+ // they are not harmful either.
+ //
+ // For now we retry to work-around bug #574:
+ // properties.setProperty("Ice.RetryIntervals", "-1");
+
+ return Ice.Util.initializeWithProperties(argSeq, properties);
+ }
+
+ Coordinator(JFrame mainFrame, String[] args, Preferences prefs)
+ {
+ _mainFrame = mainFrame;
+ _prefs = prefs;
+ _communicator = createCommunicator(args);
+
+ _liveDeploymentRoot = new IceGridGUI.LiveDeployment.Root(this);
+
+ _licenseDialog = new LicenseDialog(_mainFrame);
+
+ _sessionKeeper = new SessionKeeper(this);
+
+ _shutdownHook = new Thread("Shutdown hook")
+ {
+ public void run()
+ {
+ destroyCommunicator();
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(_shutdownHook);
+
+ _fileChooser = new JFileChooser();
+ _fileChooser.addChoosableFileFilter(new FileFilter()
+ {
+ public boolean accept(File f)
+ {
+ return f.isDirectory() || f.getName().endsWith(".xml");
+ }
+
+ public String getDescription()
+ {
+ return ".xml files";
+ }
+ });
+
+
+ final int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+
+ //
+ // Common actions (nodes not involved)
+ //
+ _newApplication = new AbstractAction("Application")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ newApplication();
+ }
+ };
+
+ _newApplicationWithDefaultTemplates =
+ new AbstractAction("Application with default templates from Registry")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ newApplicationWithDefaultTemplates();
+ }
+ };
+ _newApplicationWithDefaultTemplates.setEnabled(false);
+
+ _login = new AbstractAction("Login...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ login();
+ }
+ };
+ _login.putValue(Action.SHORT_DESCRIPTION,
+ "Log into an IceGrid Registry");
+
+ _logout = new AbstractAction("Logout")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ logout();
+ }
+ };
+ _logout.putValue(Action.SHORT_DESCRIPTION, "Logout");
+ _logout.setEnabled(false);
+
+ _acquireExclusiveWriteAccess = new AbstractAction("Acquire exclusive write access")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
+ acquireExclusiveWriteAccess(null);
+ _releaseExclusiveWriteAccess.setEnabled(true);
+ _acquireExclusiveWriteAccess.setEnabled(false);
+ }
+ catch(AccessDeniedException ade)
+ {
+ accessDenied(ade);
+ }
+ }
+ };
+ _acquireExclusiveWriteAccess.putValue(Action.SHORT_DESCRIPTION,
+ "Acquire exclusive write access on the Registry");
+ _acquireExclusiveWriteAccess.setEnabled(false);
+
+
+ _releaseExclusiveWriteAccess = new AbstractAction("Release exclusive write access")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ releaseExclusiveWriteAccess();
+ _acquireExclusiveWriteAccess.setEnabled(true);
+ _releaseExclusiveWriteAccess.setEnabled(false);
+ }
+ };
+ _releaseExclusiveWriteAccess.putValue(Action.SHORT_DESCRIPTION,
+ "Release exclusive write access on the Registry");
+ _releaseExclusiveWriteAccess.setEnabled(false);
+
+ _openApplicationFromFile = new AbstractAction("Application from file")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ int result = _fileChooser.showOpenDialog(_mainFrame);
+ if(result == JFileChooser.APPROVE_OPTION)
+ {
+ System.err.println("Opening file: " + _fileChooser.getSelectedFile().getAbsolutePath());
+ }
+ }
+ };
+ _openApplicationFromFile.putValue(Action.SHORT_DESCRIPTION, "Open application from file");
+ _openApplicationFromFile.setEnabled(true);
+
+ _openApplicationFromRegistry = new AbstractAction("Application from Registry")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Object[] applicationNames = _liveDeploymentRoot.getApplicationNames();
+
+ String appName = (String)JOptionPane.showInputDialog(
+ _mainFrame, "Which Application do you want to open?", "Open Application from Registry",
+ JOptionPane.QUESTION_MESSAGE, null,
+ applicationNames, applicationNames[0]);
+
+ if(appName != null)
+ {
+ openLiveApplication(appName);
+ }
+ }
+ };
+ _openApplicationFromRegistry.putValue(Action.SHORT_DESCRIPTION, "Open application from Registry");
+ _openApplicationFromRegistry.setEnabled(false);
+
+ _closeApplication = new AbstractAction("Close application")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Tab tab = getCurrentTab();
+ if(tab.close())
+ {
+ String id = ((ApplicationPane)tab).getRoot().getId();
+ _liveApplications.remove(id);
+ }
+ }
+ };
+ _closeApplication.putValue(Action.SHORT_DESCRIPTION, "Close application");
+ _closeApplication.setEnabled(false);
+
+ _save = new AbstractAction("Save")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().save();
+ }
+ };
+ _save.setEnabled(false);
+ _save.putValue(Action.ACCELERATOR_KEY,
+ KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK));
+ _save.putValue(Action.SHORT_DESCRIPTION, "Save");
+
+
+ _saveToRegistry = new AbstractAction("Save to Registry")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().saveToRegistry();
+ }
+ };
+ _saveToRegistry.setEnabled(false);
+ _saveToRegistry.putValue(Action.SHORT_DESCRIPTION, "Save to Registry");
+
+
+ _saveToFile = new AbstractAction("Save to file")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().saveToFile();
+ }
+ };
+ _saveToFile.setEnabled(false);
+ _saveToFile.putValue(Action.SHORT_DESCRIPTION, "Save to file");
+
+
+ _discardUpdates = new AbstractAction("Discard updates...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().discardUpdates();
+ }
+ };
+ _discardUpdates.setEnabled(false);
+ _discardUpdates.putValue(Action.SHORT_DESCRIPTION, "Discard updates");
+
+
+ _exit = new AbstractAction("Exit")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ exit(0);
+ }
+ };
+ _exit.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt F4"));
+
+
+ _back = new AbstractAction("Go back to the previous node")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().back();
+ }
+ };
+ _back.setEnabled(false);
+ _back.putValue(Action.SHORT_DESCRIPTION, "Go back to the previous node");
+
+ _forward = new AbstractAction("Go to the next node")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ getCurrentTab().forward();
+ }
+ };
+ _forward.setEnabled(false);
+ _forward.putValue(Action.SHORT_DESCRIPTION, "Go to the next node");
+
+ _helpContents = new AbstractAction("Contents")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ helpContents();
+ }
+ };
+
+ _copying = new AbstractAction("Copying conditions")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _licenseDialog.show("TOP");
+ }
+ };
+
+ _warranty = new AbstractAction("(Non)Warranty")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _licenseDialog.show("WARRANTY");
+ }
+ };
+
+ _about = new AbstractAction("About")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ about();
+ }
+ };
+
+ _installDistribution = new AbstractAction("Install distribution")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ //
+ // TODO: select a live application
+ //
+ }
+ };
+ _installDistribution.setEnabled(false);
+
+
+ _showVarsMenuItem = new
+ JCheckBoxMenuItem(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.SHOW_VARS));
+ _showVarsTool = new
+ JToggleButton(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.SHOW_VARS));
+ _showVarsTool.setIcon(Utils.getIcon("/icons/24x24/show_vars.png"));
+ _showVarsTool.setText("");
+
+ _substituteMenuItem = new
+ JCheckBoxMenuItem(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.SUBSTITUTE_VARS));
+ _substituteTool = new
+ JToggleButton(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.SUBSTITUTE_VARS));
+ _substituteTool.setIcon(Utils.getIcon("/icons/24x24/substitute.png"));
+ _substituteTool.setText("");
+
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(_showVarsMenuItem);
+ group.add(_substituteMenuItem);
+ group = new ButtonGroup();
+ group.add(_showVarsTool);
+ group.add(_substituteTool);
+
+ _showVarsMenuItem.setSelected(true);
+ _showVarsTool.setSelected(true);
+
+ _mainFrame.setJMenuBar(new MenuBar());
+
+ _mainFrame.getContentPane().add(new ToolBar(),
+ BorderLayout.PAGE_START);
+
+ _mainFrame.getContentPane().add((StatusBarI)_statusBar,
+ BorderLayout.PAGE_END);
+
+ _liveDeploymentPane = new LiveDeploymentPane(_liveDeploymentRoot);
+ _mainPane = new MainPane(this);
+ _mainFrame.getContentPane().add(_mainPane, BorderLayout.CENTER);
+ }
+
+ JComponent getLiveDeploymentPane()
+ {
+ return _liveDeploymentPane;
+ }
+
+ public IceGridGUI.LiveDeployment.Root getLiveDeploymentRoot()
+ {
+ return _liveDeploymentRoot;
+ }
+
+ private void newApplication()
+ {
+ ApplicationDescriptor desc = new ApplicationDescriptor("NewApplication",
+ new java.util.TreeMap(),
+ new java.util.LinkedList(),
+ new java.util.HashMap(),
+ new java.util.HashMap(),
+ new java.util.HashMap(),
+ new IceGrid.DistributionDescriptor(
+ "", new java.util.LinkedList()),
+ "");
+ IceGridGUI.Application.Root root = new IceGridGUI.Application.Root(this, desc);
+ ApplicationPane app = new ApplicationPane(root);
+ _mainPane.addApplication(app);
+ _mainPane.setSelectedComponent(app);
+ root.setSelectedNode(root);
+ }
+
+ private void newApplicationWithDefaultTemplates()
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ try
+ {
+ ApplicationDescriptor descriptor = _admin.getDefaultApplicationDescriptor();
+ descriptor.name = "NewApplication";
+ IceGridGUI.Application.Root root = new IceGridGUI.Application.Root(this, descriptor);
+ ApplicationPane app = new ApplicationPane(root);
+ _mainPane.addApplication(app);
+ _mainPane.setSelectedComponent(app);
+ root.setSelectedNode(root);
+ }
+ catch(DeploymentException e)
+ {
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "The default application descriptor from the IceGrid Registry is invalid:\n"
+ + e.reason,
+ "Deployment Exception",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ catch(Ice.LocalException e)
+ {
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ "Could not retrieve the default application descriptor from the IceGrid Registry: \n"
+ + e.toString(),
+ "Trouble with IceGrid Registry",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ finally
+ {
+ _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ //
+ // Login and logout action
+ //
+ private void login()
+ {
+ if(_latestSerial != -1 && _latestSerial == _writeSerial)
+ {
+ int saveFirst = JOptionPane.showConfirmDialog(
+ _mainFrame,
+ "Do you want to save your updates?",
+ "Save Confirmation",
+ JOptionPane.YES_NO_CANCEL_OPTION);
+
+ switch(saveFirst)
+ {
+ case JOptionPane.YES_OPTION:
+ /*if(saveUpdates())
+ {
+ _sessionKeeper.relog(true);
+ }*/
+ break;
+ case JOptionPane.NO_OPTION:
+ _sessionKeeper.relog(true);
+ break;
+ case JOptionPane.CANCEL_OPTION:
+ break;
+ default:
+ assert false;
+ }
+ }
+ else
+ {
+ _sessionKeeper.relog(true);
+ }
+ }
+
+ private void logout()
+ {
+ if(_latestSerial != -1 && _latestSerial == _writeSerial)
+ {
+ int saveFirst = JOptionPane.showConfirmDialog(
+ _mainFrame,
+ "Do you want to save your updates?",
+ "Save Confirmation",
+ JOptionPane.YES_NO_CANCEL_OPTION);
+
+ switch(saveFirst)
+ {
+ case JOptionPane.YES_OPTION:
+ /* if(saveUpdates())
+ {
+ _sessionKeeper.logout(true);
+ }*/
+ break;
+ case JOptionPane.NO_OPTION:
+ _sessionKeeper.logout(true);
+ break;
+ case JOptionPane.CANCEL_OPTION:
+ break;
+ default:
+ assert false;
+ }
+ }
+ else
+ {
+ _sessionKeeper.logout(true);
+ }
+ }
+
+
+ private void helpContents()
+ {
+ BareBonesBrowserLaunch.openURL(
+ "http://www.zeroc.com/help/IceGridAdmin/");
+ }
+
+ private void about()
+ {
+ String text = "IceGrid Admin version "
+ + IceUtil.Version.ICE_STRING_VERSION + "\n"
+ + "Copyright \u00A9 2005 ZeroC, Inc. All rights reserved.\n";
+
+ JOptionPane.showMessageDialog(
+ _mainFrame,
+ text,
+ "About - IceGrid Admin",
+ JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ public void setClipboard(Object copy)
+ {
+ _clipboard = copy;
+ }
+
+ public Object getClipboard()
+ {
+ return _clipboard;
+ }
+
+ void showMainFrame()
+ {
+ if(!loadWindowPrefs())
+ {
+ _mainFrame.setLocation(100, 100);
+ _mainFrame.pack();
+ }
+ _mainFrame.setVisible(true);
+ }
+
+ void exit(int status)
+ {
+ storeWindowPrefs();
+ destroyCommunicator();
+ _mainFrame.dispose();
+ Runtime.getRuntime().removeShutdownHook(_shutdownHook);
+ Runtime.getRuntime().exit(status);
+ }
+
+ //
+ // Can be called by the shutdown hook thread
+ //
+ private void destroyCommunicator()
+ {
+ try
+ {
+ _communicator.destroy();
+ }
+ catch(Ice.LocalException e)
+ {
+ System.err.println("_communicator.destroy() raised "
+ + e.toString());
+ }
+ }
+
+ private boolean loadWindowPrefs()
+ {
+ try
+ {
+ if(!_prefs.nodeExists("Window"))
+ {
+ return false;
+ }
+ }
+ catch(BackingStoreException e)
+ {
+ return false;
+ }
+
+ Preferences windowPrefs = _prefs.node("Window");
+ int x = windowPrefs.getInt("x", 0);
+ int y = windowPrefs.getInt("y", 0);
+ int width = windowPrefs.getInt("width", 0);
+ int height = windowPrefs.getInt("height", 0);
+ _mainFrame.setBounds(new Rectangle(x, y, width, height));
+ if(windowPrefs.getBoolean("maximized", false))
+ {
+ _mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
+ }
+ return true;
+ }
+
+ private void storeWindowPrefs()
+ {
+ Preferences windowPrefs = _prefs.node("Window");
+ Rectangle rect = _mainFrame.getBounds();
+ windowPrefs.putInt("x", rect.x);
+ windowPrefs.putInt("y", rect.y);
+ windowPrefs.putInt("width", rect.width);
+ windowPrefs.putInt("height", rect.height);
+ windowPrefs.putBoolean("maximized",
+ _mainFrame.getExtendedState() == Frame.MAXIMIZED_BOTH);
+ }
+
+
+ public SessionPrx getSession()
+ {
+ return _sessionKeeper.getSession();
+ }
+
+ SessionKeeper getSessionKeeper()
+ {
+ return _sessionKeeper;
+ }
+
+ Preferences getPrefs()
+ {
+ return _prefs;
+ }
+
+ public LiveActions getLiveActionsForPopup()
+ {
+ return _liveActionsForPopup;
+ }
+
+ public LiveActions getLiveActionsForMenu()
+ {
+ return _liveActionsForMenu;
+ }
+
+ public ApplicationActions getActionsForMenu()
+ {
+ return _appActionsForMenu;
+ }
+
+ public ApplicationActions getActionsForPopup()
+ {
+ return _appActionsForPopup;
+ }
+
+ public void showActions(IceGridGUI.LiveDeployment.TreeNode node)
+ {
+ boolean[] availableActions = _liveActionsForMenu.setTarget(node);
+ _appActionsForMenu.setTarget(null);
+
+ _newServerMenu.setEnabled(false);
+ _newServiceMenu.setEnabled(false);
+ _newTemplateMenu.setEnabled(false);
+
+ _appMenu.setEnabled(true);
+
+ _nodeMenu.setEnabled(
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_NODE]);
+
+ _serverMenu.setEnabled(
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.START] ||
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.STOP] ||
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.ENABLE] ||
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.DISABLE] ||
+ availableActions[IceGridGUI.LiveDeployment.TreeNode.SERVER_INSTALL_DISTRIBUTION]);
+
+ _serviceMenu.setEnabled(false);
+ }
+
+ public void showActions(IceGridGUI.Application.TreeNode node)
+ {
+ boolean[] availableActions = _appActionsForMenu.setTarget(node);
+ _liveActionsForMenu.setTarget(null);
+
+ _newServerMenu.setEnabled(
+ availableActions[IceGridGUI.Application.TreeNode.NEW_SERVER] ||
+ availableActions[IceGridGUI.Application.TreeNode.NEW_SERVER_ICEBOX] ||
+ availableActions[IceGridGUI.Application.TreeNode.NEW_SERVER_FROM_TEMPLATE]);
+
+ _newServiceMenu.setEnabled(
+ availableActions[IceGridGUI.Application.TreeNode.NEW_SERVICE] ||
+ availableActions[IceGridGUI.Application.TreeNode.NEW_SERVICE_FROM_TEMPLATE]);
+
+ _newTemplateMenu.setEnabled(
+ availableActions[IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVER] ||
+ availableActions[IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVER_ICEBOX] ||
+ availableActions[IceGridGUI.Application.TreeNode.NEW_TEMPLATE_SERVICE]);
+
+ _appMenu.setEnabled(false);
+ _nodeMenu.setEnabled(false);
+ _serverMenu.setEnabled(false);
+ _serviceMenu.setEnabled(
+ availableActions[IceGridGUI.Application.TreeNode.MOVE_UP] ||
+ availableActions[IceGridGUI.Application.TreeNode.MOVE_DOWN]);
+ }
+
+
+ private final Ice.Communicator _communicator;
+ private Preferences _prefs;
+ private StatusBarI _statusBar = new StatusBarI();
+ private AdminPrx _admin;
+
+ private Ice.ObjectAdapter _localAdapter;
+ private Ice.ObjectAdapter _routedAdapter;
+
+ private IceGridGUI.LiveDeployment.Root _liveDeploymentRoot;
+ private LiveDeploymentPane _liveDeploymentPane;
+
+ //
+ // Maps application-name to ApplicationPane (only for 'live' applications)
+ //
+ private java.util.Map _liveApplications = new java.util.HashMap();
+
+ private MainPane _mainPane;
+
+ //
+ // Keep tracks of serial number when viewing/editing application definitions
+ // (not used for displaying live deployment)
+ //
+ private int _latestSerial = -1;
+ private int _writeSerial = -1;
+
+ private Runnable _onExclusiveWrite;
+ private int _writeAccessCount = 0;
+
+ private boolean _substitute = false;
+
+ private JFrame _mainFrame;
+ private SessionKeeper _sessionKeeper;
+
+ private Object _clipboard;
+
+ private LicenseDialog _licenseDialog;
+
+ //
+ // Actions
+ //
+ private Action _newApplication;
+ private Action _newApplicationWithDefaultTemplates;
+ private Action _login;
+ private Action _logout;
+ private Action _acquireExclusiveWriteAccess;
+ private Action _releaseExclusiveWriteAccess;
+
+ private Action _openApplicationFromFile;
+ private Action _openApplicationFromRegistry;
+ private Action _closeApplication;
+ private Action _save;
+ private Action _saveToRegistry;
+ private Action _saveToFile;
+ private Action _discardUpdates;
+ private Action _exit;
+ private Action _back;
+ private Action _forward;
+ private Action _helpContents;
+ private Action _copying;
+ private Action _warranty;
+ private Action _about;
+ private Action _installDistribution;
+
+ //
+ // Two sets of actions because the popup's target and the menu/toolbar's target
+ // can be different.
+ //
+ private LiveActions _liveActionsForMenu = new LiveActions();
+ private LiveActions _liveActionsForPopup = new LiveActions();
+ private ApplicationActions _appActionsForMenu = new ApplicationActions(false);
+ private ApplicationActions _appActionsForPopup = new ApplicationActions(true);
+
+
+ private JToggleButton _showVarsTool;
+ private JToggleButton _substituteTool;
+ private JCheckBoxMenuItem _substituteMenuItem;
+ private JCheckBoxMenuItem _showVarsMenuItem;
+
+
+ private JMenu _newMenu;
+ private JMenu _newServerMenu;
+ private JMenu _newServiceMenu;
+ private JMenu _newTemplateMenu;
+ private JMenu _appMenu;
+ private JMenu _nodeMenu;
+ private JMenu _serverMenu;
+ private JMenu _serviceMenu;
+
+ private final Thread _shutdownHook;
+
+ private JFileChooser _fileChooser;
+
+ static private final int HISTORY_MAX_SIZE = 20;
+
+ //
+ // TODO: should come from build system
+ //
+ static private final boolean GPL_BUILD = true;
+}
diff --git a/java/src/IceGridGUI/EditorBase.java b/java/src/IceGridGUI/EditorBase.java
new file mode 100755
index 00000000000..1e11340f891
--- /dev/null
+++ b/java/src/IceGridGUI/EditorBase.java
@@ -0,0 +1,139 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JToolBar;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.factories.Borders;
+import com.jgoodies.forms.layout.FormLayout;
+import com.jgoodies.forms.util.LayoutStyle;
+
+import IceGrid.*;
+
+//
+// Base class for all editors
+//
+public abstract class EditorBase
+{
+ public JComponent getProperties()
+ {
+ if(_propertiesPanel == null)
+ {
+ buildPropertiesPanel();
+ }
+ return _propertiesPanel;
+ }
+
+ public JToolBar getToolBar()
+ {
+ return null;
+ }
+
+ static public java.util.SortedMap propertiesToMap(java.util.List props,
+ Utils.Resolver resolver)
+ {
+ java.util.SortedMap result = new java.util.TreeMap();
+ java.util.Iterator p = props.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ String name = (String)pd.name;
+ String val = (String)pd.value;
+ if(resolver != null)
+ {
+ name = resolver.substitute(pd.name);
+ val = resolver.substitute(pd.value);
+ }
+ result.put(name, val);
+ }
+ return result;
+ }
+
+ static public java.util.Vector mapToVector(java.util.Map map)
+ {
+ java.util.Vector result = new java.util.Vector(map.size());
+ java.util.Iterator p = map.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ java.util.Vector row = new java.util.Vector(2);
+ row.add(entry.getKey());
+ row.add(entry.getValue());
+ result.add(row);
+ }
+ return result;
+ }
+
+ static public java.util.LinkedList mapToProperties(java.util.Map map)
+ {
+ java.util.LinkedList result = new java.util.LinkedList();
+ java.util.Iterator p = map.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ String name = (String)entry.getKey();
+ String value = (String)entry.getValue();
+ result.add(new PropertyDescriptor(name, value));
+ }
+ return result;
+ }
+
+ static public java.util.Map makeParameterValues(
+ java.util.Map oldParameterValues,
+ java.util.List newParameters)
+ {
+ java.util.Map result = new java.util.HashMap();
+
+ java.util.Iterator p = newParameters.iterator();
+ while(p.hasNext())
+ {
+ Object name = p.next();
+ Object value = oldParameterValues.get(name);
+ if(value != null)
+ {
+ result.put(name, value);
+ }
+ }
+ return result;
+ }
+
+ protected abstract void appendProperties(DefaultFormBuilder builder);
+
+ protected void buildPropertiesPanel()
+ {
+ 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.setLineGapSize(LayoutStyle.getCurrent().getLinePad());
+
+ appendProperties(builder);
+
+ JScrollPane scrollPane =
+ new JScrollPane(builder.getPanel(),
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
+ scrollPane.setBorder(Borders.DIALOG_BORDER);
+
+ _propertiesPanel = new JPanel(new BorderLayout());
+ _propertiesPanel.add(scrollPane, BorderLayout.CENTER);
+ _propertiesPanel.setBorder(Borders.EMPTY_BORDER);
+ }
+
+ protected JPanel _propertiesPanel;
+}
diff --git a/java/src/IceGrid/LicenseDialog.java b/java/src/IceGridGUI/LicenseDialog.java
index 93d02ca379e..9505befc0c4 100755
--- a/java/src/IceGrid/LicenseDialog.java
+++ b/java/src/IceGridGUI/LicenseDialog.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import java.awt.BorderLayout;
import java.awt.Dimension;
diff --git a/java/src/IceGrid/ListDialog.java b/java/src/IceGridGUI/ListDialog.java
index 1aea43117e5..88125cfc0d0 100755
--- a/java/src/IceGrid/ListDialog.java
+++ b/java/src/IceGridGUI/ListDialog.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import java.awt.BorderLayout;
import java.awt.Dimension;
diff --git a/java/src/IceGridGUI/LiveActions.java b/java/src/IceGridGUI/LiveActions.java
new file mode 100755
index 00000000000..1ed640b794e
--- /dev/null
+++ b/java/src/IceGridGUI/LiveActions.java
@@ -0,0 +1,118 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+
+import IceGrid.*;
+import IceGridGUI.LiveDeployment.*;
+
+//
+// Holds all actions for the "Live Deployment" view
+//
+public class LiveActions
+{
+ public Action get(int index)
+ {
+ return _array[index];
+ }
+
+ public boolean[] setTarget(TreeNode target)
+ {
+ _target = target;
+
+ boolean[] availableActions;
+ if(_target == null)
+ {
+ availableActions = new boolean[TreeNode.ACTION_COUNT];
+ }
+ else
+ {
+ availableActions = _target.getAvailableActions();
+ }
+
+ for(int i = 0; i < _array.length; ++i)
+ {
+ _array[i].setEnabled(availableActions[i]);
+ }
+
+ return availableActions;
+ }
+
+ LiveActions()
+ {
+ _array[TreeNode.START] = new AbstractAction(
+ "Start", Utils.getIcon("/icons/16x16/start.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.start();
+ }
+ };
+ _array[TreeNode.START].putValue(Action.SHORT_DESCRIPTION,
+ "Start this server");
+
+ _array[TreeNode.STOP] = new AbstractAction(
+ "Stop", Utils.getIcon("/icons/16x16/stop.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.stop();
+ }
+ };
+ _array[TreeNode.STOP].putValue(Action.SHORT_DESCRIPTION,
+ "Stop this server");
+
+
+ _array[TreeNode.ENABLE] = new AbstractAction(
+ "Enable", Utils.getIcon("/icons/16x16/enable.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.enable();
+ }
+ };
+ _array[TreeNode.ENABLE].putValue(Action.SHORT_DESCRIPTION,
+ "Enable this server");
+
+ _array[TreeNode.DISABLE] = new AbstractAction(
+ "Disable", Utils.getIcon("/icons/16x16/disable.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.disable();
+ }
+ };
+ _array[TreeNode.DISABLE].putValue(Action.SHORT_DESCRIPTION,
+ "Disable this server");
+
+
+ _array[TreeNode.SHUTDOWN_NODE] = new AbstractAction("Shutdown")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.shutdownNode();
+ }
+ };
+
+ _array[TreeNode.SERVER_INSTALL_DISTRIBUTION] =
+ new AbstractAction("Patch")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.serverInstallDistribution();
+ }
+ };
+ }
+
+ private TreeNode _target;
+ private Action[] _array = new Action[TreeNode.ACTION_COUNT];
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/Adapter.java b/java/src/IceGridGUI/LiveDeployment/Adapter.java
new file mode 100755
index 00000000000..5add2303c42
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Adapter.java
@@ -0,0 +1,169 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.Component;
+
+import javax.swing.Icon;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+
+class Adapter extends TreeNode
+{
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new AdapterEditor();
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _activeIcon = Utils.getIcon("/icons/16x16/adapter_active.png");
+ _inactiveIcon = Utils.getIcon("/icons/16x16/adapter_inactive.png");
+ }
+
+ if(_currentEndpoints == null || _currentEndpoints.length() == 0)
+ {
+ _cellRenderer.setLeafIcon(_inactiveIcon);
+ }
+ else
+ {
+ _cellRenderer.setLeafIcon(_activeIcon);
+ }
+
+ _cellRenderer.setToolTipText(_toolTip);
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ Adapter(TreeNode parent, String adapterName, Utils.Resolver resolver,
+ String adapterId, AdapterDescriptor descriptor, Ice.ObjectPrx proxy)
+ {
+ super(parent, adapterName);
+ _resolver = resolver;
+ _adapterId = adapterId;
+ _descriptor = descriptor;
+
+ setCurrentEndpoints(proxy);
+ }
+
+ AdapterDescriptor getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ String getCurrentEndpoints()
+ {
+ return _currentEndpoints;
+ }
+
+ String getProperty(String name)
+ {
+ Server server = (Server)_parent;
+ return server.getProperty(_descriptor.name + "." + name);
+ }
+
+ boolean update(AdapterDynamicInfo info)
+ {
+ if(info == null)
+ {
+ setCurrentEndpoints(null);
+ getRoot().getTreeModel().nodeChanged(this);
+ return true;
+ }
+ else if(info.id.equals(_adapterId))
+ {
+ setCurrentEndpoints(info.proxy);
+ getRoot().getTreeModel().nodeChanged(this);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ boolean update(java.util.List infoList)
+ {
+ java.util.Iterator p = infoList.iterator();
+ while(p.hasNext())
+ {
+ AdapterDynamicInfo info = (AdapterDynamicInfo)p.next();
+ if(update(info))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void setCurrentEndpoints(Ice.ObjectPrx proxy)
+ {
+ if(proxy == null)
+ {
+ _currentEndpoints = null;
+ _toolTip = "Inactive";
+ }
+ else
+ {
+ String str = getCoordinator().getCommunicator().proxyToString(proxy);
+ int index = str.indexOf(':');
+ if(index == -1 || index == str.length() - 1)
+ {
+ _currentEndpoints = "";
+ }
+ else
+ {
+ _currentEndpoints = str.substring(index + 1);
+ }
+ _toolTip = "Published endpoints: " + _currentEndpoints;
+ }
+ }
+
+
+ private AdapterDescriptor _descriptor;
+ private Utils.Resolver _resolver;
+ private String _adapterId;
+
+ private String _currentEndpoints;
+ private String _toolTip;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private Icon _activeIcon;
+ static private Icon _inactiveIcon;
+
+ static private AdapterEditor _editor;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java b/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java
new file mode 100755
index 00000000000..5726c1ab316
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java
@@ -0,0 +1,140 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class AdapterEditor extends Editor
+{
+ AdapterEditor()
+ {
+ _currentStatus.setEditable(false);
+ _currentEndpoints.setEditable(false);
+ _description.setEditable(false);
+ _description.setOpaque(false);
+ _id.setEditable(false);
+ _replicaGroupId.setEditable(false);
+ _endpoints.setEditable(false);
+ _publishedEndpoints.setEditable(false);
+ _registerProcess.setEnabled(false);
+ _waitForActivation.setEnabled(false);
+ }
+
+
+ void show(Adapter adapter)
+ {
+ AdapterDescriptor descriptor = adapter.getDescriptor();
+ Utils.Resolver resolver = adapter.getResolver();
+
+ String currentEndpoints = adapter.getCurrentEndpoints();
+ boolean active = (currentEndpoints != null);
+
+ if(currentEndpoints == null)
+ {
+ _currentStatus.setText("Inactive");
+ _currentEndpoints.setText("");
+ }
+ else
+ {
+ _currentStatus.setText("Active");
+ _currentEndpoints.setText(currentEndpoints);
+ }
+
+ _description.setText(resolver.substitute(descriptor.description));
+ _id.setText(resolver.substitute(descriptor.id));
+ _replicaGroupId.setText(resolver.substitute(descriptor.replicaGroupId));
+ _endpoints.setText(resolver.substitute(adapter.getProperty("Endpoints")));
+ _publishedEndpoints.setText(
+ resolver.substitute(adapter.getProperty("PublishedEndpoints")));
+
+ _registerProcess.setSelected(descriptor.registerProcess);
+ _waitForActivation.setSelected(descriptor.waitForActivation);
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.appendSeparator("Runtime Status");
+
+ builder.append("Status" );
+ builder.append(_currentStatus, 3);
+ builder.nextLine();
+
+ builder.append("Published Endpoints" );
+ builder.append(_currentEndpoints, 3);
+ builder.nextLine();
+
+ builder.appendSeparator("Configuration");
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("Adapter ID");
+ builder.append(_id, 3);
+ builder.nextLine();
+
+ builder.append("Replica Group");
+ builder.append(_replicaGroupId, 3);
+ builder.nextLine();
+
+ builder.append("", _registerProcess);
+ builder.nextLine();
+ builder.append("", _waitForActivation);
+ builder.nextLine();
+
+ builder.append("Endpoints");
+ builder.append(_endpoints, 3);
+ builder.nextLine();
+
+ builder.append("Published Endpoints");
+ builder.append(_publishedEndpoints, 3);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Adapter Properties");
+ }
+
+ private JTextField _currentStatus = new JTextField(20);
+ private JTextField _currentEndpoints = new JTextField(20);
+
+ private JTextArea _description = new JTextArea(3, 20);
+ private JTextField _id = new JTextField(20);
+ private JTextField _replicaGroupId = new JTextField(20);
+ private JTextField _endpoints = new JTextField(20);
+ private JTextField _publishedEndpoints = new JTextField(20);
+
+ private JCheckBox _registerProcess = new JCheckBox("Register Process");
+ private JCheckBox _waitForActivation = new JCheckBox("Wait for Activation");
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java b/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java
new file mode 100755
index 00000000000..529df24c3ae
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java
@@ -0,0 +1,98 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.DefaultTableCellRenderer;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class CommunicatorEditor extends Editor
+{
+ protected CommunicatorEditor()
+ {
+ _description.setEditable(false);
+ _description.setOpaque(false);
+
+ _propertiesModel = new DefaultTableModel()
+ {
+ public boolean isCellEditable(int row, int column)
+ {
+ return false;
+ }
+ };
+
+ _properties = new JTable(_propertiesModel);
+ _properties.setCellSelectionEnabled(false);
+ _properties.setOpaque(false);
+ _properties.setPreferredScrollableViewportSize(_properties.getPreferredSize());
+
+ _columnNames.add("Name");
+ _columnNames.add("Value");
+ }
+
+ protected void show(CommunicatorDescriptor descriptor, Utils.Resolver resolver)
+ {
+ _description.setText(resolver.substitute(descriptor.description));
+ _propertiesModel.setDataVector(
+ mapToVector(propertiesToMap(descriptor.properties, resolver)),
+ _columnNames);
+
+ DefaultTableCellRenderer cr = (DefaultTableCellRenderer)
+ _properties.getDefaultRenderer(String.class);
+ cr.setOpaque(false);
+
+ // _properties.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ // _properties.doLayout();
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("Properties");
+ builder.nextLine();
+ builder.append("");
+ builder.nextLine();
+ builder.append("");
+
+ builder.nextLine();
+ builder.append("");
+
+ builder.nextRow(-6);
+ scrollPane = new JScrollPane(_properties);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
+ builder.nextRow(6);
+ builder.nextLine();
+ }
+
+ private JTextArea _description = new JTextArea(3, 20);
+ private JTable _properties;
+ private DefaultTableModel _propertiesModel;
+ private java.util.Vector _columnNames = new java.util.Vector(2);
+}
+
diff --git a/java/src/IceGridGUI/LiveDeployment/DbEnv.java b/java/src/IceGridGUI/LiveDeployment/DbEnv.java
new file mode 100755
index 00000000000..88e89222c5e
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/DbEnv.java
@@ -0,0 +1,75 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class DbEnv extends TreeNode
+{
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/database.png"));
+ }
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new DbEnvEditor();
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ DbEnv(TreeNode parent, String dbEnvName, Utils.Resolver resolver,
+ DbEnvDescriptor descriptor)
+ {
+ super(parent, dbEnvName);
+ _resolver = resolver;
+ _descriptor = descriptor;
+
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ DbEnvDescriptor getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ private Utils.Resolver _resolver;
+ private DbEnvDescriptor _descriptor;
+
+ static private DbEnvEditor _editor;
+ static private DefaultTreeCellRenderer _cellRenderer;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java b/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java
new file mode 100755
index 00000000000..65b03f8c967
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java
@@ -0,0 +1,121 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.DefaultTableCellRenderer;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class DbEnvEditor extends Editor
+{
+ DbEnvEditor()
+ {
+ _description.setEditable(false);
+ _description.setOpaque(false);
+ _dbHome.setEditable(false);
+
+ _propertiesModel = new DefaultTableModel()
+ {
+ public boolean isCellEditable(int row, int column)
+ {
+ return false;
+ }
+ };
+
+ _properties = new JTable(_propertiesModel);
+ _properties.setCellSelectionEnabled(false);
+ _properties.setOpaque(false);
+ _properties.setPreferredScrollableViewportSize(_properties.getPreferredSize());
+
+ _columnNames.add("Name");
+ _columnNames.add("Value");
+ }
+
+ void show(DbEnv dbEnv)
+ {
+ DbEnvDescriptor descriptor = dbEnv.getDescriptor();
+ Utils.Resolver resolver = dbEnv.getResolver();
+ _description.setText(resolver.substitute(descriptor.description));
+
+ if(descriptor.dbHome.length() == 0)
+ {
+ _dbHome.setText("Created by the IceGrid Node");
+ }
+ else
+ {
+ _dbHome.setText(resolver.substitute(descriptor.dbHome));
+ }
+
+ _propertiesModel.setDataVector(
+ mapToVector(propertiesToMap(descriptor.properties, resolver)),
+ _columnNames);
+
+ DefaultTableCellRenderer cr = (DefaultTableCellRenderer)
+ _properties.getDefaultRenderer(String.class);
+ cr.setOpaque(false);
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("DB Home" );
+ builder.append(_dbHome, 3);
+ builder.nextLine();
+
+ builder.append("Properties");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextRow(-6);
+ scrollPane = new JScrollPane(_properties);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
+ builder.nextRow(6);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("DbEnv Properties");
+ }
+
+ private JTextArea _description = new JTextArea(3, 20);
+ private JTextField _dbHome = new JTextField(20);
+
+ private JTable _properties;
+ private DefaultTableModel _propertiesModel;
+ private java.util.Vector _columnNames = new java.util.Vector(2);
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/Editor.java b/java/src/IceGridGUI/LiveDeployment/Editor.java
new file mode 100755
index 00000000000..957c55c2018
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Editor.java
@@ -0,0 +1,16 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import IceGridGUI.*;
+
+public abstract class Editor extends EditorBase
+{}
+
+
diff --git a/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java b/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java
new file mode 100755
index 00000000000..d8a7d452dae
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java
@@ -0,0 +1,140 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// A TreeNode that holds an array of list of children
+//
+abstract class ListArrayTreeNode extends TreeNode
+{
+ public Enumeration children()
+ {
+ return new Enumeration()
+ {
+ public boolean hasMoreElements()
+ {
+ if(_p.hasNext())
+ {
+ return true;
+ }
+
+ while(++_index < _childrenArray.length)
+ {
+ _p = _childrenArray[_index].iterator();
+ if(_p.hasNext())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Object nextElement()
+ {
+ try
+ {
+ return _p.next();
+ }
+ catch(java.util.NoSuchElementException nse)
+ {
+ if(hasMoreElements())
+ {
+ return _p.next();
+ }
+ else
+ {
+ throw nse;
+ }
+ }
+ }
+
+ private int _index = 0;
+ private java.util.Iterator _p = _childrenArray[0].iterator();
+ };
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return true;
+ }
+
+ public javax.swing.tree.TreeNode getChildAt(int childIndex)
+ {
+ if(childIndex < 0)
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ int offset = 0;
+ for(int i = 0; i < _childrenArray.length; ++i)
+ {
+ if(childIndex < offset + _childrenArray[i].size())
+ {
+ return (javax.swing.tree.TreeNode)_childrenArray[i].get(childIndex - offset);
+ }
+ else
+ {
+ offset += _childrenArray[i].size();
+ }
+ }
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+
+ public int getChildCount()
+ {
+ int result = 0;
+ for(int i = 0; i < _childrenArray.length; ++i)
+ {
+ result += _childrenArray[i].size();
+ }
+ return result;
+ }
+
+ public int getIndex(javax.swing.tree.TreeNode node)
+ {
+ int offset = 0;
+ for(int i = 0; i < _childrenArray.length; ++i)
+ {
+ int index = _childrenArray[i].indexOf(node);
+ if(index == -1)
+ {
+ offset += _childrenArray[i].size();
+ }
+ else
+ {
+ return offset + index;
+ }
+ }
+ return -1;
+ }
+
+ public boolean isLeaf()
+ {
+ for(int i = 0; i < _childrenArray.length; ++i)
+ {
+ if(!_childrenArray[i].isEmpty())
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ protected ListArrayTreeNode(TreeNode parent, String id, int arraySize)
+ {
+ super(parent, id);
+ _childrenArray = new java.util.List[arraySize];
+ }
+
+ protected final java.util.List[] _childrenArray;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/ListTreeNode.java b/java/src/IceGridGUI/LiveDeployment/ListTreeNode.java
new file mode 100755
index 00000000000..bea3d9463dc
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/ListTreeNode.java
@@ -0,0 +1,81 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// An TreeNode that holds a list of children
+//
+abstract class ListTreeNode extends TreeNode
+{
+ public Enumeration children()
+ {
+ return new Enumeration()
+ {
+ public boolean hasMoreElements()
+ {
+ return _p.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ return _p.next();
+ }
+
+ private java.util.Iterator _p = _children.iterator();
+ };
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return true;
+ }
+
+ public javax.swing.tree.TreeNode getChildAt(int childIndex)
+ {
+ if(childIndex < 0)
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ else if(childIndex < _children.size())
+ {
+ return (javax.swing.tree.TreeNode)_children.get(childIndex);
+ }
+ else
+ {
+ throw new ArrayIndexOutOfBoundsException(childIndex);
+ }
+ }
+
+ public int getChildCount()
+ {
+ return _children.size();
+ }
+
+ public int getIndex(javax.swing.tree.TreeNode node)
+ {
+ return _children.indexOf(node);
+ }
+
+ public boolean isLeaf()
+ {
+ return _children.isEmpty();
+ }
+
+ protected ListTreeNode(TreeNode parent, String id)
+ {
+ super(parent, id);
+ }
+
+ protected final java.util.List _children = new java.util.LinkedList();
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/Node.java b/java/src/IceGridGUI/LiveDeployment/Node.java
new file mode 100755
index 00000000000..dbd8d2a3114
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Node.java
@@ -0,0 +1,767 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.Component;
+import java.awt.Cursor;
+
+import javax.swing.Icon;
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+
+import java.text.NumberFormat;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Node extends ListTreeNode
+{
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[SHUTDOWN_NODE] = _up;
+ return actions;
+ }
+
+ public void shutdownNode()
+ {
+ final String prefix = "Shutting down node '" + _id + "'...";
+ getCoordinator().getStatusBar().setText(prefix);
+
+ AMI_Admin_shutdownNode cb = new AMI_Admin_shutdownNode()
+ {
+ //
+ // Called by another thread!
+ //
+ public void ice_response()
+ {
+ amiSuccess(prefix);
+ }
+
+ public void ice_exception(Ice.UserException e)
+ {
+ amiFailure(prefix, "Failed to shutdown " + _id, e);
+ }
+
+ public void ice_exception(Ice.LocalException e)
+ {
+ amiFailure(prefix, "Failed to shutdown " + _id,
+ e.toString());
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ getCoordinator().getAdmin().shutdownNode_async(cb, _id);
+ }
+ catch(Ice.LocalException e)
+ {
+ failure(prefix, "Failed to shutdown " + _id, e.toString());
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ public JPopupMenu getPopupMenu()
+ {
+ LiveActions la = getCoordinator().getLiveActionsForPopup();
+
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+ _popup.add(la.get(SHUTDOWN_NODE));
+ }
+
+ la.setTarget(this);
+ return _popup;
+ }
+
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new NodeEditor();
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ //
+ // Initialization
+ //
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _nodeUp = Utils.getIcon("/icons/16x16/node_up.png");
+ _nodeDown = Utils.getIcon("/icons/16x16/node_down.png");
+ }
+
+ if(_up)
+ {
+ _cellRenderer.setToolTipText("Up and running");
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(_nodeUp);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(_nodeUp);
+ }
+ }
+ else
+ {
+ _cellRenderer.setToolTipText("Not running");
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(_nodeDown);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(_nodeDown);
+ }
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ Node(Root parent, NodeDynamicInfo info)
+ {
+ super(parent, info.name);
+ up(info, false);
+ }
+
+
+ Node(Root parent, ApplicationDescriptor appDesc,
+ String nodeName, NodeDescriptor nodeDesc)
+ {
+ super(parent, nodeName);
+ add(appDesc, nodeDesc);
+ }
+
+ Node(Root parent, ApplicationDescriptor appDesc, NodeUpdateDescriptor update)
+ {
+ super(parent, update.name);
+
+ NodeDescriptor nodeDesc = new NodeDescriptor(
+ update.variables,
+ update.serverInstances,
+ update.servers,
+ update.loadFactor.value,
+ update.description.value);
+
+ appDesc.nodes.put(_id, nodeDesc);
+ add(appDesc, nodeDesc);
+ }
+
+
+ void add(ApplicationDescriptor appDesc, NodeDescriptor nodeDesc)
+ {
+ ApplicationData data = new ApplicationData();
+ data.descriptor = nodeDesc;
+ data.resolver = new Utils.Resolver(new java.util.Map[]{appDesc.variables, nodeDesc.variables});
+ data.resolver.put("application", appDesc.name);
+ data.resolver.put("node", _id);
+
+ _map.put(appDesc.name, data);
+
+ java.util.Iterator p = nodeDesc.serverInstances.iterator();
+ while(p.hasNext())
+ {
+ ServerInstanceDescriptor desc = (ServerInstanceDescriptor)p.next();
+ insertServer(createServer(appDesc, data.resolver, desc));
+ }
+
+ p = nodeDesc.servers.iterator();
+ while(p.hasNext())
+ {
+ ServerDescriptor desc = (ServerDescriptor)p.next();
+ insertServer(createServer(appDesc, data.resolver, desc));
+ }
+ }
+
+
+
+ boolean remove(String appName)
+ {
+ _map.remove(appName);
+ if(_map.isEmpty() && !_up)
+ {
+ return true;
+ }
+
+ java.util.List toRemove = new java.util.LinkedList();
+ int[] toRemoveIndices = new int[_children.size()];
+ int i = 0;
+
+ for(int index = 0; index < _children.size(); ++index)
+ {
+ Server server = (Server)_children.get(i);
+ if(server.getApplication().name.equals(appName))
+ {
+ toRemove.add(server);
+ toRemoveIndices[i++] = index;
+ }
+ }
+ toRemoveIndices = resize(toRemoveIndices, toRemove.size());
+ _children.removeAll(toRemove);
+ getRoot().getTreeModel().nodesWereRemoved(this, toRemoveIndices, toRemove.toArray());
+
+ return false;
+ }
+
+ void update(ApplicationDescriptor appDesc, NodeUpdateDescriptor update,
+ boolean variablesChanged, java.util.Set serviceTemplates,
+ java.util.Set serverTemplates)
+ {
+ ApplicationData data = (ApplicationData)_map.get(appDesc.name);
+ NodeDescriptor nodeDesc = data.descriptor;
+ java.util.Set freshServers = new java.util.HashSet();
+
+ if(update != null)
+ {
+ //
+ // Update various fields of nodeDesc
+ //
+ if(update.description != null)
+ {
+ nodeDesc.description = update.description.value;
+ }
+ if(update.loadFactor != null)
+ {
+ nodeDesc.loadFactor = update.loadFactor.value;
+ }
+
+ nodeDesc.variables.keySet().removeAll(java.util.Arrays.asList(update.removeVariables));
+ nodeDesc.variables.putAll(update.variables);
+
+ if(!variablesChanged)
+ {
+ variablesChanged = update.removeVariables.length > 0 ||
+ !update.variables.isEmpty();
+ }
+
+ //
+ // Remove servers
+ //
+ for(int i = 0; i < update.removeServers.length; ++i)
+ {
+ Server server = findServer(update.removeServers[i]);
+
+ ServerInstanceDescriptor sid =
+ server.getInstanceDescriptor();
+ if(sid != null)
+ {
+ nodeDesc.serverInstances.remove(sid);
+ }
+ else
+ {
+ nodeDesc.servers.remove(server.getServerDescriptor());
+ }
+
+ int index = getIndex(server);
+ _children.remove(server);
+ getRoot().getTreeModel().nodesWereRemoved(this, new int[]{index}, new Object[]{server});
+ }
+
+ //
+ // Add/update servers
+ //
+ java.util.Iterator p = update.serverInstances.iterator();
+ while(p.hasNext())
+ {
+ ServerInstanceDescriptor desc = (ServerInstanceDescriptor)p.next();
+ Server server = createServer(appDesc, data.resolver, desc);
+
+ Server oldServer = findServer(server.getId());
+ if(oldServer == null)
+ {
+ insertServer(server);
+ freshServers.add(server);
+ }
+ else
+ {
+ oldServer.rebuild(server);
+ freshServers.add(oldServer);
+ }
+ nodeDesc.serverInstances.add(desc);
+ }
+
+ p = update.servers.iterator();
+ while(p.hasNext())
+ {
+ ServerDescriptor desc = (ServerDescriptor)p.next();
+ Server server = createServer(appDesc, data.resolver, desc);
+
+ Server oldServer = findServer(server.getId());
+ if(oldServer == null)
+ {
+ insertServer(server);
+ freshServers.add(server);
+ }
+ else
+ {
+ oldServer.rebuild(server);
+ freshServers.add(oldServer);
+ }
+ nodeDesc.servers.add(desc);
+ }
+ }
+
+ if(variablesChanged || !serviceTemplates.isEmpty() || !serverTemplates.isEmpty())
+ {
+ //
+ // Rebuild every other server
+ //
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+ if(!freshServers.contains(server))
+ {
+ server.rebuild(data.resolver,
+ variablesChanged,
+ serviceTemplates, serverTemplates);
+ }
+ }
+ }
+ }
+
+ NodeInfo getStaticInfo()
+ {
+ if(_info == null)
+ {
+ return null;
+ }
+ else
+ {
+ return _info.info;
+ }
+ }
+
+ boolean isRunningWindows()
+ {
+ return _windows;
+ }
+
+ void up(NodeDynamicInfo info, boolean fireEvent)
+ {
+ _up = true;
+ _info = info;
+ _windows = info.info.os.toLowerCase().startsWith("windows");
+
+ //
+ // Tell every server on this node
+ //
+ java.util.Set updatedServers = new java.util.HashSet();
+ java.util.Iterator p = _info.servers.iterator();
+ while(p.hasNext())
+ {
+ ServerDynamicInfo sinfo = (ServerDynamicInfo)p.next();
+ Server server = findServer(sinfo.id);
+ if(server != null)
+ {
+ server.update(sinfo.state, sinfo.pid, sinfo.enabled, true);
+ updatedServers.add(server);
+ }
+ }
+ p = _children.iterator();
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+ if(!updatedServers.contains(server))
+ {
+ server.update(ServerState.Inactive, 0, true, true);
+ }
+ }
+
+ //
+ // Tell adapters
+ //
+ p = _children.iterator();
+ int updateCount = 0;
+ while(p.hasNext() && updateCount < _info.adapters.size())
+ {
+ Server server = (Server)p.next();
+ updateCount += server.updateAdapters(_info.adapters);
+ }
+
+ if(fireEvent)
+ {
+ getRoot().getTreeModel().nodeChanged(this);
+ }
+ }
+
+ boolean down()
+ {
+ _up = false;
+ _info.servers.clear();
+ _info.adapters.clear();
+
+ if(_children.isEmpty())
+ {
+ return true;
+ }
+ else
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+ server.nodeDown();
+ }
+
+ getRoot().getTreeModel().nodeChanged(this);
+ return false;
+ }
+ }
+
+ void updateServer(ServerDynamicInfo updatedInfo)
+ {
+ if(_info != null)
+ {
+ java.util.ListIterator p = _info.servers.listIterator();
+ while(p.hasNext())
+ {
+ ServerDynamicInfo sinfo = (ServerDynamicInfo)p.next();
+ if(sinfo.id.equals(updatedInfo.id))
+ {
+ p.set(updatedInfo);
+ break;
+ }
+ }
+ }
+
+ Server server = findServer(updatedInfo.id);
+ if(server != null)
+ {
+ server.update(updatedInfo.state, updatedInfo.pid,
+ updatedInfo.enabled, true);
+ }
+ }
+
+ void updateAdapter(AdapterDynamicInfo updatedInfo)
+ {
+ if(_info != null)
+ {
+ java.util.ListIterator p = _info.adapters.listIterator();
+ while(p.hasNext())
+ {
+ AdapterDynamicInfo ainfo = (AdapterDynamicInfo)p.next();
+ if(ainfo.id.equals(updatedInfo.id))
+ {
+ p.set(updatedInfo);
+ break;
+ }
+ }
+ }
+
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ Server server = (Server)p.next();
+ if(server.updateAdapter(updatedInfo))
+ {
+ break;
+ }
+ }
+ }
+
+ Ice.ObjectPrx getProxy(String adapterId)
+ {
+ if(_info != null)
+ {
+ java.util.ListIterator p = _info.adapters.listIterator();
+ while(p.hasNext())
+ {
+ AdapterDynamicInfo ainfo = (AdapterDynamicInfo)p.next();
+ if(ainfo.equals(adapterId))
+ {
+ return ainfo.proxy;
+ }
+ }
+ }
+ return null;
+ }
+
+ java.util.SortedMap getLoadFactors()
+ {
+ java.util.SortedMap result = new java.util.TreeMap();
+
+ java.util.Iterator p = _map.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+
+ ApplicationData ad = (ApplicationData)entry.getValue();
+
+ String val = ad.resolver.substitute(ad.descriptor.loadFactor);
+ if(val.length() == 0)
+ {
+ val = "Default";
+ }
+
+ result.put(entry.getKey(), val);
+ }
+ return result;
+ }
+
+
+ void showLoad()
+ {
+ AMI_Admin_getNodeLoad cb = new AMI_Admin_getNodeLoad()
+ {
+ public void ice_response(LoadInfo loadInfo)
+ {
+ NumberFormat format;
+ if(_windows)
+ {
+ format = NumberFormat.getPercentInstance();
+ format.setMaximumFractionDigits(1);
+ format.setMinimumFractionDigits(1);
+ }
+ else
+ {
+ format = NumberFormat.getNumberInstance();
+ format.setMaximumFractionDigits(2);
+ format.setMinimumFractionDigits(2);
+ }
+
+ final String load =
+ format.format(loadInfo.avg1) + " " +
+ format.format(loadInfo.avg5) + " " +
+ format.format(loadInfo.avg15);
+
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ _editor.setLoad(load, Node.this);
+ }
+ });
+ }
+
+ public void ice_exception(final Ice.UserException e)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ if(e instanceof IceGrid.NodeNotExistException)
+ {
+ _editor.setLoad(
+ "Error: this node is not known to this IceGrid Registry",
+ Node.this);
+ }
+ else if(e instanceof IceGrid.NodeUnreachableException)
+ {
+ _editor.setLoad("Error: cannot reach this node", Node.this);
+ }
+ else
+ {
+ _editor.setLoad("Error: " + e.toString(), Node.this);
+ }
+ }
+ });
+ }
+
+ public void ice_exception(final Ice.LocalException e)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ _editor.setLoad("Error: " + e.toString(), Node.this);
+ }
+ });
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ IceGrid.AdminPrx admin = getCoordinator().getAdmin();
+ if(admin == null)
+ {
+ _editor.setLoad("Unknown", this);
+ }
+ else
+ {
+ admin.getNodeLoad_async(cb, _id);
+ }
+ }
+ catch(Ice.LocalException e)
+ {
+ _editor.setLoad("Error: " + e.toString(), this);
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+
+ private Server createServer(ApplicationDescriptor application,
+ Utils.Resolver resolver, ServerInstanceDescriptor instanceDescriptor)
+ {
+ //
+ // Find template
+ //
+ TemplateDescriptor templateDescriptor =
+ (TemplateDescriptor)application.serverTemplates.get(instanceDescriptor.template);
+ assert templateDescriptor != null;
+
+ ServerDescriptor serverDescriptor =
+ (ServerDescriptor)templateDescriptor.descriptor;
+
+ assert serverDescriptor != null;
+
+ //
+ // Build resolver
+ //
+ Utils.Resolver instanceResolver =
+ new Utils.Resolver(resolver,
+ instanceDescriptor.parameterValues,
+ templateDescriptor.parameterDefaults);
+
+ String serverId = instanceResolver.substitute(serverDescriptor.id);
+ instanceResolver.put("server", serverId);
+
+ //
+ // Lookup dynamic info
+ //
+ ServerState serverState = _up ? ServerState.Inactive : null;
+ int pid = 0;
+ boolean enabled = true;
+ if(_info != null)
+ {
+ java.util.Iterator p = _info.servers.iterator();
+ while(p.hasNext())
+ {
+ ServerDynamicInfo sinfo = (ServerDynamicInfo)p.next();
+ if(sinfo.id.equals(serverId))
+ {
+ serverState = sinfo.state;
+ pid = sinfo.pid;
+ enabled = sinfo.enabled;
+ break;
+ }
+ }
+ }
+
+ //
+ // Create server
+ //
+ return new Server(this, serverId, instanceResolver, instanceDescriptor,
+ serverDescriptor, application,
+ serverState, pid, enabled);
+
+ }
+
+ private Server createServer(ApplicationDescriptor application,
+ Utils.Resolver resolver, ServerDescriptor serverDescriptor)
+ {
+ //
+ // Build resolver
+ //
+ Utils.Resolver instanceResolver = new Utils.Resolver(resolver);
+ String serverId = instanceResolver.substitute(serverDescriptor.id);
+ instanceResolver.put("server", serverId);
+
+ //
+ // Lookup dynamic info
+ //
+ ServerState serverState = _up ? ServerState.Inactive : null;
+ int pid = 0;
+ boolean enabled = true;
+ if(_info != null)
+ {
+ java.util.Iterator p = _info.servers.iterator();
+ while(p.hasNext())
+ {
+ ServerDynamicInfo sinfo = (ServerDynamicInfo)p.next();
+ if(sinfo.id.equals(serverId))
+ {
+ serverState = sinfo.state;
+ pid = sinfo.pid;
+ enabled = sinfo.enabled;
+ break;
+ }
+ }
+ }
+
+ //
+ // Create server
+ //
+ return new Server(this, serverId, instanceResolver, null, serverDescriptor,
+ application, serverState, pid, enabled);
+
+ }
+
+ private void insertServer(Server server)
+ {
+ insertSortedChild(server, _children, getRoot().getTreeModel());
+ }
+
+ private Server findServer(String id)
+ {
+ return (Server)find(id, _children);
+ }
+
+ static class ApplicationData
+ {
+ NodeDescriptor descriptor;
+ Utils.Resolver resolver;
+ }
+
+ //
+ // Application name to ApplicationData
+ //
+ private final java.util.SortedMap _map = new java.util.TreeMap();
+
+ private boolean _up = false;
+ private NodeDynamicInfo _info;
+ private boolean _windows = false;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private Icon _nodeUp;
+ static private Icon _nodeDown;
+
+ static private NodeEditor _editor;
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/NodeEditor.java b/java/src/IceGridGUI/LiveDeployment/NodeEditor.java
new file mode 100755
index 00000000000..087c7cd53b2
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/NodeEditor.java
@@ -0,0 +1,185 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.event.ActionEvent;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.DefaultTableCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class NodeEditor extends Editor
+{
+ NodeEditor()
+ {
+ _hostname.setEditable(false);
+ _os.setEditable(false);
+ _machineType.setEditable(false);
+ _loadAverage.setEditable(false);
+
+ Action refresh = new AbstractAction("Refresh")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _target.showLoad();
+ }
+ };
+ refresh.putValue(Action.SHORT_DESCRIPTION,
+ "Fetch the latest values from this IceGrid Node");
+ _refreshButton = new JButton(refresh);
+
+ _loadFactorModel = new DefaultTableModel()
+ {
+ public boolean isCellEditable(int row, int column)
+ {
+ return false;
+ }
+ };
+
+ _loadFactorTable = new JTable(_loadFactorModel);
+ _loadFactorTable.setCellSelectionEnabled(false);
+ _loadFactorTable.setOpaque(false);
+ _loadFactorTable.setPreferredScrollableViewportSize(
+ _loadFactorTable.getPreferredSize());
+
+ _columnNames.add("Application");
+ _columnNames.add("Value");
+
+ }
+
+ void show(Node node)
+ {
+ _target = node;
+
+ NodeInfo info = node.getStaticInfo();
+
+ if(info == null)
+ {
+ _hostname.setText("Unknown");
+ _os.setText("Unknown");
+ _machineType.setText("Unknown");
+ _loadAverageLabel.setText("Load Average");
+ _loadAverage.setText("Unknown");
+ }
+ else
+ {
+ _hostname.setText(info.hostname);
+ _os.setText(info.os + " " + info.release + " " + info.version);
+ _machineType.setText(info.machine + " with " +
+ info.nProcessors
+ + " CPU"
+ + (info.nProcessors >= 2 ? "s" : ""));
+
+ if(node.isRunningWindows())
+ {
+ _loadAverageLabel.setText("CPU Usage");
+ _loadAverage.setToolTipText(
+ "CPU usage in the past 1 min, 5 min and 15 min period");
+ }
+ else
+ {
+ _loadAverageLabel.setText("Load Average");
+ _loadAverage.setToolTipText(
+ "Load average in the past 1 min, 5 min and 15 min period");
+ }
+ _loadAverage.setText("Refreshing...");
+ node.showLoad();
+ }
+
+ _loadFactorModel.setDataVector(
+ mapToVector(node.getLoadFactors()),
+ _columnNames);
+
+ DefaultTableCellRenderer cr = (DefaultTableCellRenderer)
+ _loadFactorTable.getDefaultRenderer(String.class);
+ cr.setOpaque(false);
+
+ }
+
+ void setLoad(String load, Node node)
+ {
+ if(node == _target)
+ {
+ _loadAverage.setText(load);
+ }
+ //
+ // Otherwise, we've already moved to another node
+ //
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.appendSeparator("System Information");
+
+ builder.append("Hostname");
+ builder.append(_hostname, 3);
+ builder.nextLine();
+ builder.append("Operating System");
+ builder.append(_os, 3);
+ builder.nextLine();
+ builder.append("Machine Type");
+ builder.append(_machineType, 3);
+ builder.append(_loadAverageLabel, _loadAverage);
+ builder.append(_refreshButton);
+ builder.nextLine();
+
+ builder.appendSeparator("Configuration");
+
+ builder.append("Load Factor");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextLine();
+
+ builder.append("");
+ builder.nextRow(-6);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_loadFactorTable);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
+ builder.nextRow(6);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Node Properties");
+ }
+
+ private JTextField _hostname = new JTextField(20);
+ private JTextField _os = new JTextField(20);
+ private JTextField _machineType = new JTextField(20);
+ private JLabel _loadAverageLabel = new JLabel();
+ private JTextField _loadAverage = new JTextField(20);
+ private JButton _refreshButton;
+
+ private JTable _loadFactorTable;
+ private DefaultTableModel _loadFactorModel;
+ private java.util.Vector _columnNames = new java.util.Vector(2);
+
+ private Node _target;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java b/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java
new file mode 100755
index 00000000000..42f3820204c
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class RegistryEditor extends Editor
+{
+ protected void appendProperties(DefaultFormBuilder builder)
+ {}
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Registry Properties");
+ }
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/Root.java b/java/src/IceGridGUI/LiveDeployment/Root.java
new file mode 100755
index 00000000000..d50fc0af7eb
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Root.java
@@ -0,0 +1,377 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+//
+// The Root node of the Live Deployment view
+//
+public class Root extends ListTreeNode
+{
+ public Root(Coordinator coordinator)
+ {
+ super(null, "Root");
+ _coordinator = coordinator;
+
+ _tree = new JTree(this, true);
+ _treeModel = (DefaultTreeModel)_tree.getModel();
+ }
+
+ public ApplicationDescriptor getApplicationDescriptor(String name)
+ {
+ return (ApplicationDescriptor)_descriptorMap.get(name);
+ }
+
+ public Object[] getApplicationNames()
+ {
+ return _descriptorMap.keySet().toArray();
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new RegistryEditor();
+ }
+ return _editor;
+ }
+
+ public void init(String instanceName, java.util.List applications)
+ {
+ _label = instanceName;
+ _tree.setRootVisible(true);
+
+ java.util.Iterator p = applications.iterator();
+ while(p.hasNext())
+ {
+ applicationAdded((ApplicationDescriptor)p.next());
+ }
+ }
+
+ //
+ // Called when the session to the IceGrid Registry is closed
+ //
+ public void clear()
+ {
+ _descriptorMap.clear();
+ _children.clear();
+ _treeModel.nodeStructureChanged(this);
+ _tree.setRootVisible(false);
+ }
+
+ //
+ // From the Registry Observer:
+ //
+ public void applicationAdded(ApplicationDescriptor desc)
+ {
+ _descriptorMap.put(desc.name, desc);
+
+ java.util.Iterator p = desc.nodes.entrySet().iterator();
+ while(p.hasNext())
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ String nodeName = (String)entry.getKey();
+ NodeDescriptor nodeDesc = (NodeDescriptor)entry.getValue();
+
+ Node node = findNode(nodeName);
+ if(node == null)
+ {
+ insertNode(new Node(this, desc, nodeName, nodeDesc));
+ }
+ else
+ {
+ node.add(desc, nodeDesc);
+ }
+ }
+ }
+
+ public void applicationRemoved(String name)
+ {
+ _descriptorMap.remove(name);
+
+ java.util.List toRemove = new java.util.LinkedList();
+ int[] toRemoveIndices = new int[_children.size()];
+
+ int i = 0;
+ for(int index = 0; index < _children.size(); ++index)
+ {
+ Node node = (Node)_children.get(index);
+ if(node.remove(name))
+ {
+ toRemove.add(node);
+ toRemoveIndices[i++] = index;
+ }
+ }
+
+ removeNodes(resize(toRemoveIndices, toRemove.size()), toRemove);
+ }
+
+ public void applicationUpdated(ApplicationUpdateDescriptor update)
+ {
+ ApplicationDescriptor appDesc = (ApplicationDescriptor)_descriptorMap.get(update.name);
+
+ //
+ // Update various fields of appDesc
+ //
+ if(update.description != null)
+ {
+ appDesc.description = update.description.value;
+ }
+ if(update.distrib != null)
+ {
+ appDesc.distrib = update.distrib.value;
+ }
+
+ appDesc.variables.keySet().removeAll(java.util.Arrays.asList(update.removeVariables));
+ appDesc.variables.putAll(update.variables);
+ boolean variablesChanged = update.removeVariables.length > 0 || !update.variables.isEmpty();
+
+ //
+ // Update only descriptors (no tree node shown in this view)
+ //
+ for(int i = 0; i < update.removeReplicaGroups.length; ++i)
+ {
+ for(int j = 0; j < appDesc.replicaGroups.size(); ++j)
+ {
+ ReplicaGroupDescriptor rgd = (ReplicaGroupDescriptor)appDesc.replicaGroups.get(j);
+ if(rgd.id.equals(update.removeReplicaGroups[i]))
+ {
+ appDesc.replicaGroups.remove(j);
+ }
+ }
+ }
+ appDesc.replicaGroups.addAll(update.replicaGroups);
+
+ appDesc.serviceTemplates.keySet().
+ removeAll(java.util.Arrays.asList(update.removeServiceTemplates));
+ appDesc.serviceTemplates.putAll(update.serviceTemplates);
+
+ appDesc.serverTemplates.keySet().
+ removeAll(java.util.Arrays.asList(update.removeServerTemplates));
+ appDesc.serverTemplates.putAll(update.serverTemplates);
+
+
+ //
+ // Nodes
+ //
+
+ //
+ // Removal
+ //
+ appDesc.nodes.keySet().removeAll(java.util.Arrays.asList(update.removeNodes));
+
+ for(int i = 0; i < update.removeNodes.length; ++i)
+ {
+ Node node = findNode(update.removeNodes[i]);
+ if(node.remove(update.name))
+ {
+ int index = getIndex(node);
+ _children.remove(node);
+ _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node});
+ }
+ }
+
+ //
+ // Add/update
+ //
+ java.util.Iterator p = update.nodes.iterator();
+ java.util.Set freshNodes = new java.util.HashSet();
+ while(p.hasNext())
+ {
+ NodeUpdateDescriptor nodeUpdateDesc = (NodeUpdateDescriptor)p.next();
+
+ String nodeName = nodeUpdateDesc.name;
+
+ Node node = findNode(nodeName);
+ if(node == null)
+ {
+ node = new Node(this, appDesc, nodeUpdateDesc);
+ insertNode(node);
+ }
+ else
+ {
+ node.update(appDesc, nodeUpdateDesc, variablesChanged,
+ update.serviceTemplates.keySet(), update.serverTemplates.keySet());
+ }
+ freshNodes.add(node);
+ }
+
+ //
+ // Notify non-fresh nodes if needed
+ //
+ if(variablesChanged || !update.serviceTemplates.isEmpty() || !update.serverTemplates.isEmpty())
+ {
+ p = _children.iterator();
+ while(p.hasNext())
+ {
+ Node node = (Node)p.next();
+ if(!freshNodes.contains(node))
+ {
+ node.update(appDesc, null, variablesChanged,
+ update.serviceTemplates.keySet(), update.serverTemplates.keySet());
+ }
+ }
+ }
+ }
+
+ //
+ // From the Node Observer:
+ //
+ public void nodeUp(NodeDynamicInfo updatedInfo)
+ {
+ Node node = findNode(updatedInfo.name);
+ if(node != null)
+ {
+ node.up(updatedInfo, true);
+ }
+ else
+ {
+ insertNode(new Node(this, updatedInfo));
+ }
+ }
+
+ public void nodeDown(String nodeName)
+ {
+ Node node = findNode(nodeName);
+ if(node != null)
+ {
+ if(node.down())
+ {
+ int index = getIndex(node);
+ _children.remove(node);
+ _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node});
+ }
+ }
+ }
+
+ public void updateServer(String nodeName, ServerDynamicInfo updatedInfo)
+ {
+ Node node = findNode(nodeName);
+ if(node != null)
+ {
+ node.updateServer(updatedInfo);
+ }
+ }
+
+ public void updateAdapter(String nodeName, AdapterDynamicInfo updatedInfo)
+ {
+ Node node = findNode(nodeName);
+ if(node != null)
+ {
+ node.updateAdapter(updatedInfo);
+ }
+ }
+
+ public void setSelectedNode(TreeNode node)
+ {
+ _tree.setSelectionPath(node.getPath());
+ }
+
+ public JTree getTree()
+ {
+ return _tree;
+ }
+
+ public DefaultTreeModel getTreeModel()
+ {
+ return _treeModel;
+ }
+
+ public Coordinator getCoordinator()
+ {
+ return _coordinator;
+ }
+
+ public String toString()
+ {
+ return _label;
+ }
+
+ //
+ // Check that this node is attached to the tree
+ //
+ public boolean hasNode(TreeNode node)
+ {
+ while(node != this)
+ {
+ TreeNode parent = (TreeNode)node.getParent();
+ if(parent.getIndex(node) == -1)
+ {
+ return false;
+ }
+ else
+ {
+ node = parent;
+ }
+ }
+ return true;
+ }
+
+
+ Root getRoot()
+ {
+ return this;
+ }
+
+ private Node findNode(String nodeName)
+ {
+ return (Node)find(nodeName, _children);
+ }
+
+ private void insertNode(Node node)
+ {
+ String nodeName = node.toString();
+ int i;
+ for(i = 0; i < _children.size(); ++i)
+ {
+ String otherNodeName = _children.get(i).toString();
+ if(nodeName.compareTo(otherNodeName) > 0)
+ {
+ i++;
+ break;
+ }
+ }
+ _children.add(i, node);
+ _treeModel.nodesWereInserted(this, new int[]{i});
+ }
+
+ private void removeNodes(int[] toRemoveIndices, java.util.List toRemove)
+ {
+ if(toRemove.size() > 0)
+ {
+ _children.removeAll(toRemove);
+ _treeModel.nodesWereRemoved(this, toRemoveIndices, toRemove.toArray());
+ }
+ }
+
+ private final Coordinator _coordinator;
+
+ //
+ // Maps application name to current application descriptor
+ //
+ private final java.util.Map _descriptorMap = new java.util.TreeMap();
+
+ //
+ // 'this' is the root of the tree
+ //
+ private final JTree _tree;
+ private final DefaultTreeModel _treeModel;
+
+ private String _label;
+
+ static private RegistryEditor _editor;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/Server.java b/java/src/IceGridGUI/LiveDeployment/Server.java
new file mode 100755
index 00000000000..96a509a9351
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Server.java
@@ -0,0 +1,721 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.Component;
+import java.awt.Cursor;
+
+import javax.swing.Icon;
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Server extends ListArrayTreeNode
+{
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+
+ if(_state != null)
+ {
+ actions[START] = _state == ServerState.Inactive && _enabled;
+ actions[STOP] = _state != ServerState.Inactive;
+ actions[ENABLE] = !_enabled;
+ actions[DISABLE] = _enabled;
+ actions[SERVER_INSTALL_DISTRIBUTION] =
+ !_serverDescriptor.distrib.icepatch.equals("");
+ }
+
+ return actions;
+ }
+
+ public void start()
+ {
+ final String prefix = "Starting server '" + _id + "'...";
+ getCoordinator().getStatusBar().setText(prefix);
+
+ AMI_Admin_startServer cb = new AMI_Admin_startServer()
+ {
+ //
+ // Called by another thread!
+ //
+ public void ice_response()
+ {
+ amiSuccess(prefix);
+ }
+
+ public void ice_exception(Ice.UserException e)
+ {
+ amiFailure(prefix, "Failed to start " + _id, e);
+ }
+
+ public void ice_exception(Ice.LocalException e)
+ {
+ amiFailure(prefix, "Failed to start " + _id, e.toString());
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ getCoordinator().getAdmin().startServer_async(cb, _id);
+ }
+ catch(Ice.LocalException e)
+ {
+ failure(prefix, "Failed to start " + _id, e.toString());
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ public void stop()
+ {
+ final String prefix = "Stopping server '" + _id + "'...";
+ getCoordinator().getStatusBar().setText(prefix);
+
+ AMI_Admin_stopServer cb = new AMI_Admin_stopServer()
+ {
+ //
+ // Called by another thread!
+ //
+ public void ice_response()
+ {
+ amiSuccess(prefix);
+ }
+
+ public void ice_exception(Ice.UserException e)
+ {
+ amiFailure(prefix, "Failed to stop " + _id, e);
+ }
+
+ public void ice_exception(Ice.LocalException e)
+ {
+ amiFailure(prefix, "Failed to stop " + _id, e.toString());
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ getCoordinator().getAdmin().stopServer_async(cb, _id);
+ }
+ catch(Ice.LocalException e)
+ {
+ failure(prefix, "Failed to stop " + _id, e.toString());
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ public void enable()
+ {
+ enableServer(true);
+ }
+
+ public void disable()
+ {
+ enableServer(false);
+ }
+
+ public void serverInstallDistribution()
+ {
+ int shutdown = JOptionPane.showConfirmDialog(
+ getCoordinator().getMainFrame(),
+ "You are about to install or refresh your"
+ + " server distribution and your application distribution onto this node.\n"
+ + " Do you want shut down all servers affected by this update?",
+ "Patch Confirmation",
+ JOptionPane.YES_NO_CANCEL_OPTION);
+
+ if(shutdown == JOptionPane.CANCEL_OPTION)
+ {
+ return;
+ }
+
+ final String prefix = "Patching server '" + _id + "'...";
+ getCoordinator().getStatusBar().setText(prefix);
+
+ AMI_Admin_patchServer cb = new AMI_Admin_patchServer()
+ {
+ //
+ // Called by another thread!
+ //
+ public void ice_response()
+ {
+ amiSuccess(prefix);
+ }
+
+ public void ice_exception(Ice.UserException e)
+ {
+ amiFailure(prefix, "Failed to patch " + _id, e);
+ }
+
+ public void ice_exception(Ice.LocalException e)
+ {
+ amiFailure(prefix, "Failed to patch " + _id, e.toString());
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ getCoordinator().getAdmin().patchServer_async(cb, _id,
+ shutdown == JOptionPane.YES_OPTION);
+ }
+ catch(Ice.LocalException e)
+ {
+ failure(prefix, "Failed to patch " + _id, e.toString());
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ private void enableServer(boolean enable)
+ {
+ final String prefix = (enable ?
+ "Enabling" : "Disabling") + " server '" + _id + "'...";
+
+ final String action = enable ? "enable" : "disable";
+
+ getCoordinator().getStatusBar().setText(prefix);
+
+ AMI_Admin_enableServer cb = new AMI_Admin_enableServer()
+ {
+ //
+ // Called by another thread!
+ //
+ public void ice_response()
+ {
+ amiSuccess(prefix);
+ }
+
+ public void ice_exception(Ice.UserException e)
+ {
+ amiFailure(prefix, "Failed to " + action + " " + _id, e);
+ }
+
+ public void ice_exception(Ice.LocalException e)
+ {
+ amiFailure(prefix, "Failed to " + action + " " + _id, e.toString());
+ }
+ };
+
+ try
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ getCoordinator().getAdmin().enableServer_async(cb, _id, enable);
+ }
+ catch(Ice.LocalException e)
+ {
+ failure(prefix, "Failed to " + action + " " + _id, e.toString());
+ }
+ finally
+ {
+ getCoordinator().getMainFrame().setCursor(
+ Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ public JPopupMenu getPopupMenu()
+ {
+ LiveActions la = getCoordinator().getLiveActionsForPopup();
+
+ if(_popup == null)
+ {
+ _popup = new JPopupMenu();
+
+ _popup.add(la.get(START));
+ _popup.add(la.get(STOP));
+ _popup.addSeparator();
+ _popup.add(la.get(ENABLE));
+ _popup.add(la.get(DISABLE));
+ _popup.addSeparator();
+ _popup.add(la.get(SERVER_INSTALL_DISTRIBUTION));
+ }
+
+ la.setTarget(this);
+ return _popup;
+ }
+
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new ServerEditor(getCoordinator());
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ //
+ // Initialization
+ //
+ _cellRenderer = new DefaultTreeCellRenderer();
+
+ //
+ // Regular servers
+ //
+ _icons = new Icon[7][2][2];
+ _icons[0][0][0] = Utils.getIcon("/icons/16x16/server_unknown.png");
+ _icons[ServerState.Inactive.value() + 1][0][0]
+ = Utils.getIcon("/icons/16x16/server_inactive.png");
+ _icons[ServerState.Activating.value() + 1][0][0] =
+ Utils.getIcon("/icons/16x16/server_activating.png");
+ _icons[ServerState.Active.value() + 1][0][0] =
+ Utils.getIcon("/icons/16x16/server_active.png");
+ _icons[ServerState.Deactivating.value() + 1][0][0] =
+ Utils.getIcon("/icons/16x16/server_deactivating.png");
+ _icons[ServerState.Destroying.value() + 1][0][0] =
+ Utils.getIcon("/icons/16x16/server_destroying.png");
+ _icons[ServerState.Destroyed.value() + 1][0][0] =
+ Utils.getIcon("/icons/16x16/server_destroyed.png");
+
+ //
+ // IceBox servers
+ //
+ _icons[0][1][0] = Utils.getIcon("/icons/16x16/icebox_server_unknown.png");
+ _icons[ServerState.Inactive.value() + 1][1][0]
+ = Utils.getIcon("/icons/16x16/icebox_server_inactive.png");
+ _icons[ServerState.Activating.value() + 1][1][0] =
+ Utils.getIcon("/icons/16x16/icebox_server_activating.png");
+ _icons[ServerState.Active.value() + 1][1][0] =
+ Utils.getIcon("/icons/16x16/icebox_server_active.png");
+ _icons[ServerState.Deactivating.value() + 1][1][0] =
+ Utils.getIcon("/icons/16x16/icebox_server_deactivating.png");
+ _icons[ServerState.Destroying.value() + 1][1][0] =
+ Utils.getIcon("/icons/16x16/icebox_server_destroying.png");
+ _icons[ServerState.Destroyed.value() + 1][1][0] =
+ Utils.getIcon("/icons/16x16/icebox_server_destroyed.png");
+
+ //
+ // Regular servers (disabled)
+ //
+ _icons[0][0][1] = Utils.getIcon("/icons/16x16/server_unknown.png");
+ _icons[ServerState.Inactive.value() + 1][0][1]
+ = Utils.getIcon("/icons/16x16/server_disabled_inactive.png");
+ _icons[ServerState.Activating.value() + 1][0][1] =
+ Utils.getIcon("/icons/16x16/server_disabled_activating.png");
+ _icons[ServerState.Active.value() + 1][0][1] =
+ Utils.getIcon("/icons/16x16/server_disabled_active.png");
+ _icons[ServerState.Deactivating.value() + 1][0][1] =
+ Utils.getIcon("/icons/16x16/server_disabled_deactivating.png");
+ _icons[ServerState.Destroying.value() + 1][0][1] =
+ Utils.getIcon("/icons/16x16/server_disabled_destroying.png");
+ _icons[ServerState.Destroyed.value() + 1][0][1] =
+ Utils.getIcon("/icons/16x16/server_disabled_destroyed.png");
+
+ //
+ // IceBox servers (disabled)
+ //
+ _icons[0][1][1] = Utils.getIcon("/icons/16x16/icebox_server_unknown.png");
+ _icons[ServerState.Inactive.value() + 1][1][1]
+ = Utils.getIcon("/icons/16x16/icebox_server_disabled_inactive.png");
+ _icons[ServerState.Activating.value() + 1][1][1] =
+ Utils.getIcon("/icons/16x16/icebox_server_disabled_activating.png");
+ _icons[ServerState.Active.value() + 1][1][1] =
+ Utils.getIcon("/icons/16x16/icebox_server_disabled_active.png");
+ _icons[ServerState.Deactivating.value() + 1][1][1] =
+ Utils.getIcon("/icons/16x16/icebox_server_disabled_deactivating.png");
+ _icons[ServerState.Destroying.value() + 1][1][1] =
+ Utils.getIcon("/icons/16x16/icebox_server_disabled_destroying.png");
+ _icons[ServerState.Destroyed.value() + 1][1][1] =
+ Utils.getIcon("/icons/16x16/icebox_server_disabled_destroyed.png");
+
+ }
+
+ int icebox = _serverDescriptor instanceof IceBoxDescriptor ? 1 : 0;
+ int disabled = _enabled ? 0 : 1;
+
+ if(expanded)
+ {
+ _cellRenderer.setOpenIcon(_icons[_stateIconIndex][icebox][disabled]);
+ }
+ else
+ {
+ _cellRenderer.setClosedIcon(_icons[_stateIconIndex][icebox][disabled]);
+ }
+
+ _cellRenderer.setToolTipText(_toolTip);
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+
+ Server(Node parent, String serverId, Utils.Resolver resolver,
+ ServerInstanceDescriptor instanceDescriptor,
+ ServerDescriptor serverDescriptor, ApplicationDescriptor application,
+ ServerState state, int pid, boolean enabled)
+ {
+ super(parent, serverId, 3);
+ _resolver = resolver;
+
+ _instanceDescriptor = instanceDescriptor;
+ _serverDescriptor = serverDescriptor;
+ _application = application;
+
+ _childrenArray[0] = _adapters;
+ _childrenArray[1] = _dbEnvs;
+ _childrenArray[2] = _services;
+
+ update(state, pid, enabled, false);
+
+ createAdapters();
+ createDbEnvs();
+ createServices();
+ }
+
+ ApplicationDescriptor getApplication()
+ {
+ return _application;
+ }
+
+ ServerInstanceDescriptor getInstanceDescriptor()
+ {
+ return _instanceDescriptor;
+ }
+
+ ServerDescriptor getServerDescriptor()
+ {
+ return _serverDescriptor;
+ }
+
+ ServerState getState()
+ {
+ return _state;
+ }
+
+ int getPid()
+ {
+ return _pid;
+ }
+
+ boolean isEnabled()
+ {
+ return _enabled;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ void rebuild(Server server)
+ {
+ _resolver = server._resolver;
+ _instanceDescriptor = server._instanceDescriptor;
+ _serverDescriptor = server._serverDescriptor;
+ _application = server._application;
+ _adapters = server._adapters;
+ _dbEnvs = server._dbEnvs;
+ _services = server._services;
+
+ getRoot().getTreeModel().nodeStructureChanged(this);
+ }
+
+ void rebuild(Utils.Resolver resolver, boolean variablesChanged, java.util.Set serviceTemplates,
+ java.util.Set serverTemplates)
+ {
+ if(variablesChanged ||
+ (_instanceDescriptor != null && serverTemplates.contains(_instanceDescriptor.template)))
+ {
+ if(_instanceDescriptor != null)
+ {
+ TemplateDescriptor templateDescriptor =
+ (TemplateDescriptor)_application.serverTemplates.get(_instanceDescriptor.template);
+ assert templateDescriptor != null;
+
+ _resolver.reset(resolver, _instanceDescriptor.parameterValues,
+ templateDescriptor.parameterDefaults);
+ _resolver.put("server", _id);
+ }
+
+ _adapters.clear();
+ createAdapters();
+ _dbEnvs.clear();
+ createDbEnvs();
+ _services.clear();
+ createServices();
+
+ getRoot().getTreeModel().nodeStructureChanged(this);
+ }
+ else if(serviceTemplates.size() > 0 && _serverDescriptor instanceof IceBoxDescriptor)
+ {
+ _services.clear();
+ createServices();
+ getRoot().getTreeModel().nodeStructureChanged(this);
+ }
+ }
+
+ void update(ServerState state, int pid, boolean enabled, boolean fireEvent)
+ {
+ if(state != _state || pid != _pid || enabled != _enabled)
+ {
+ _state = state;
+ _pid = pid;
+ _enabled = enabled;
+
+ _toolTip = toolTip(_state, _pid, _enabled);
+ if(_state == null)
+ {
+ _stateIconIndex = 0;
+ }
+ else
+ {
+ _stateIconIndex = _state.value() + 1;
+ }
+
+ if(fireEvent)
+ {
+ getRoot().getTreeModel().nodeChanged(this);
+ }
+ }
+ }
+
+ boolean updateAdapter(AdapterDynamicInfo info)
+ {
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext())
+ {
+ Adapter adapter = (Adapter)p.next();
+ if(adapter.update(info))
+ {
+ return true;
+ }
+ }
+
+ //
+ // Could be in one of the services as well
+ //
+ p = _services.iterator();
+ while(p.hasNext())
+ {
+ Service service = (Service)p.next();
+ if(service.updateAdapter(info))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ int updateAdapters(java.util.List infoList)
+ {
+ int result = 0;
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext() && result < infoList.size())
+ {
+ Adapter adapter = (Adapter)p.next();
+ if(adapter.update(infoList))
+ {
+ result++;
+ }
+ }
+
+ //
+ // Could be in one of the services as well
+ //
+ p = _services.iterator();
+ while(p.hasNext() && result < infoList.size())
+ {
+ Service service = (Service)p.next();
+ result += service.updateAdapters(infoList);
+ }
+ return result;
+ }
+
+ void nodeDown()
+ {
+ update(null, 0, true, true);
+
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext())
+ {
+ Adapter adapter = (Adapter)p.next();
+ adapter.update((AdapterDynamicInfo)null);
+ }
+
+ p = _services.iterator();
+ while(p.hasNext())
+ {
+ Service service = (Service)p.next();
+ service.nodeDown();
+ }
+ }
+
+ String getProperty(String name)
+ {
+ java.util.Iterator p = _serverDescriptor.properties.iterator();
+ while(p.hasNext())
+ {
+ PropertyDescriptor pd = (PropertyDescriptor)p.next();
+ if(pd.name.equals(name))
+ {
+ return pd.value;
+ }
+ }
+ return "";
+ }
+
+ private void createAdapters()
+ {
+ java.util.Iterator p = _serverDescriptor.adapters.iterator();
+ while(p.hasNext())
+ {
+ AdapterDescriptor descriptor = (AdapterDescriptor)p.next();
+ String adapterName = Utils.substitute(descriptor.name, _resolver);
+ String adapterId = Utils.substitute(descriptor.id, _resolver);
+ Ice.ObjectPrx proxy = null;
+ if(adapterId.length() > 0)
+ {
+ proxy = ((Node)_parent).getProxy(adapterId);
+ }
+
+ insertSortedChild(new Adapter(this, adapterName,
+ _resolver, adapterId, descriptor, proxy),
+ _adapters, null);
+ }
+ }
+
+ private void createDbEnvs()
+ {
+ java.util.Iterator p = _serverDescriptor.dbEnvs.iterator();
+ while(p.hasNext())
+ {
+ DbEnvDescriptor descriptor = (DbEnvDescriptor)p.next();
+ String dbEnvName = Utils.substitute(descriptor.name, _resolver);
+
+ insertSortedChild(new DbEnv(this, dbEnvName, _resolver, descriptor),
+ _dbEnvs, null);
+ }
+ }
+
+ private void createServices()
+ {
+ if(_serverDescriptor instanceof IceBoxDescriptor)
+ {
+ IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)_serverDescriptor;
+
+ java.util.Iterator p = iceBoxDescriptor.services.iterator();
+ while(p.hasNext())
+ {
+ ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)p.next();
+ createService(descriptor);
+ }
+ }
+ }
+
+ private void createService(ServiceInstanceDescriptor descriptor)
+ {
+ ServiceDescriptor serviceDescriptor = null;
+ String serviceName = null;
+ Utils.Resolver serviceResolver = null;
+
+ if(descriptor.template.length() > 0)
+ {
+ TemplateDescriptor templateDescriptor
+ = (TemplateDescriptor)_application.serviceTemplates.get(descriptor.template);
+
+ assert templateDescriptor != null;
+
+ serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ serviceResolver = new Utils.Resolver(_resolver,
+ descriptor.parameterValues,
+ templateDescriptor.parameterDefaults);
+ serviceName = serviceResolver.substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ }
+ else
+ {
+ serviceDescriptor = descriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ serviceResolver = new Utils.Resolver(_resolver);
+ serviceName = _resolver.substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ }
+
+ _services.add(new Service(this, serviceName, serviceResolver,
+ descriptor, serviceDescriptor));
+ }
+
+ static private String toolTip(ServerState state, int pid, boolean enabled)
+ {
+ String result = (state == null ? "Unknown" : state.toString());
+
+ if(!enabled)
+ {
+ result += ", disabled";
+ }
+
+ if(pid != 0)
+ {
+ result += ", pid: " + pid;
+ }
+ return result;
+ }
+
+
+ private ServerInstanceDescriptor _instanceDescriptor;
+ private ServerDescriptor _serverDescriptor;
+ private ApplicationDescriptor _application;
+
+ private Utils.Resolver _resolver;
+ private java.util.List _adapters = new java.util.LinkedList();
+ private java.util.List _dbEnvs = new java.util.LinkedList();
+ private java.util.List _services = new java.util.LinkedList();
+
+ private ServerState _state;
+ private boolean _enabled;
+ private int _stateIconIndex;
+ private int _pid;
+ private String _toolTip;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private Icon[][][] _icons;
+
+ static private ServerEditor _editor;
+ static private JPopupMenu _popup;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/ServerEditor.java b/java/src/IceGridGUI/LiveDeployment/ServerEditor.java
new file mode 100755
index 00000000000..fad35395110
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/ServerEditor.java
@@ -0,0 +1,271 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+import javax.swing.JToolBar;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+
+import com.jgoodies.looks.Options;
+import com.jgoodies.looks.HeaderStyle;
+import com.jgoodies.looks.BorderStyle;
+import com.jgoodies.looks.plastic.PlasticLookAndFeel;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class ServerEditor extends CommunicatorEditor
+{
+ public JToolBar getToolBar()
+ {
+ if(_toolBar == null)
+ {
+ _toolBar = new ToolBar();
+ }
+ return _toolBar;
+ }
+
+
+ ServerEditor(Coordinator c)
+ {
+ _coordinator = c;
+ _currentState.setEditable(false);
+ _currentPid.setEditable(false);
+ _enabled.setEnabled(false);
+
+ _application.setEditable(false);
+ _exe.setEditable(false);
+ _pwd.setEditable(false);
+
+ _activation.setEditable(false);
+ _activationTimeout.setEditable(false);
+ _deactivationTimeout.setEditable(false);
+
+ _options.setEditable(false);
+
+ _applicationDistrib.setEnabled(false);
+ _icepatch.setEditable(false);
+ _directories.setEditable(false);
+
+ Action gotoApplication = new AbstractAction(
+ "", Utils.getIcon("/icons/16x16/goto.png"))
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _coordinator.openLiveApplication(_application.getText()).getRoot().
+ selectServer(((Node)_target.getParent()).getId(), _target.getId());
+ }
+ };
+ gotoApplication.putValue(Action.SHORT_DESCRIPTION,
+ "View/Edit this application");
+ _gotoApplication = new JButton(gotoApplication);
+ }
+
+
+ void show(Server server)
+ {
+ _target = server;
+
+ ServerState state = server.getState();
+ if(state == null)
+ {
+ _currentState.setText("Unknown");
+ _currentPid.setText("");
+ _enabled.setSelected(false);
+ }
+ else
+ {
+ _currentState.setText(state.toString());
+ int pid = server.getPid();
+ if(pid == 0)
+ {
+ _currentPid.setText("");
+ }
+ else
+ {
+ _currentPid.setText(Integer.toString(pid));
+ }
+ _enabled.setSelected(server.isEnabled());
+ }
+
+ ServerDescriptor descriptor = server.getServerDescriptor();
+ final Utils.Resolver resolver = server.getResolver();
+
+ _application.setText(resolver.find("application"));
+
+ super.show(descriptor, resolver);
+
+ _exe.setText(resolver.substitute(descriptor.exe));
+ _pwd.setText(resolver.substitute(descriptor.pwd));
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ return resolver.substitute((String)obj);
+ }
+ };
+
+ _options.setText(
+ Utils.stringify(descriptor.options, stringifier, " ", toolTipHolder));
+ _options.setToolTipText(toolTipHolder.value);
+
+ _activation.setText(resolver.substitute(descriptor.activation));
+ _activationTimeout.setText(resolver.substitute(descriptor.activationTimeout));
+ _deactivationTimeout.setText(resolver.substitute(descriptor.deactivationTimeout));
+
+ _applicationDistrib.setSelected(descriptor.applicationDistrib);
+ _icepatch.setText(resolver.substitute(resolver.substitute(descriptor.distrib.icepatch)));
+
+ toolTipHolder = new Ice.StringHolder();
+
+ _directories.setText(
+ Utils.stringify(descriptor.distrib.directories, stringifier, ", ",
+ toolTipHolder));
+
+ String toolTip = "<html>Include only these directories";
+
+ if(toolTipHolder.value != null)
+ {
+ toolTip += ":<br>" + toolTipHolder.value;
+ }
+ toolTip += "</html>";
+ _directories.setToolTipText(toolTip);
+ }
+
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.appendSeparator("Runtime Status");
+
+ builder.append("State");
+ builder.append(_currentState, 3);
+ builder.nextLine();
+
+ builder.append("Process ID");
+ builder.append(_currentPid, 3);
+ builder.nextLine();
+
+ builder.append("", _enabled);
+ builder.nextLine();
+
+ builder.appendSeparator("Configuration");
+
+ builder.append("Application");
+ builder.append(_application);
+ builder.append(_gotoApplication);
+ builder.nextLine();
+
+ //
+ // Add Communicator fields
+ //
+ super.appendProperties(builder);
+
+ builder.appendSeparator("Activation");
+ builder.append("Path to Executable");
+ builder.append(_exe, 3);
+ builder.nextLine();
+ builder.append("Working Directory");
+ builder.append(_pwd, 3);
+ builder.nextLine();
+ builder.append("Command Arguments");
+ builder.append(_options, 3);
+ builder.nextLine();
+// builder.append("Environment Variables");
+// builder.append(_envs, _envButton);
+// builder.nextLine();
+ builder.append("Activation Mode");
+ builder.append(_activation, 3);
+ builder.nextLine();
+ builder.append("Activation Timeout");
+ builder.append(_activationTimeout, 3);
+ builder.nextLine();
+ builder.append("Deactivation Timeout");
+ builder.append(_deactivationTimeout, 3);
+ builder.nextLine();
+
+ JComponent c = builder.appendSeparator("Distribution");
+ c.setToolTipText("Files specific to this server");
+
+ builder.append("", _applicationDistrib);
+ builder.nextLine();
+ builder.append("IcePatch2 Proxy");
+ builder.append(_icepatch, 3);
+ builder.nextLine();
+ builder.append("Directories");
+ builder.append(_directories, 3);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Server Properties");
+ }
+
+
+ private class ToolBar extends JToolBar
+ {
+ private ToolBar()
+ {
+ putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.SINGLE);
+ putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
+ setFloatable(false);
+ putClientProperty("JToolBar.isRollover", Boolean.TRUE);
+
+ LiveActions la = _coordinator.getLiveActionsForMenu();
+
+ add(la.get(TreeNode.START));
+ add(la.get(TreeNode.STOP));
+ addSeparator();
+ add(la.get(TreeNode.ENABLE));
+ add(la.get(TreeNode.DISABLE));
+ }
+ }
+
+
+ private Coordinator _coordinator;
+ private Server _target;
+
+ private JTextField _currentState = new JTextField(20);
+ private JTextField _currentPid = new JTextField(20);
+ private JCheckBox _enabled = new JCheckBox("Enabled");
+
+ private JTextField _application = new JTextField(20);
+ private JButton _gotoApplication;
+
+ private JTextField _exe = new JTextField(20);
+ private JTextField _pwd = new JTextField(20);
+
+ private JTextField _activation = new JTextField(20);
+ private JTextField _activationTimeout = new JTextField(20);
+ private JTextField _deactivationTimeout = new JTextField(20);
+
+ // private JTextField _envs = new JTextField(20);
+
+ private JTextField _options = new JTextField(20);
+ private JCheckBox _applicationDistrib = new JCheckBox("Depends on the application distribution");
+
+ private JTextField _icepatch = new JTextField(20);
+ private JTextField _directories = new JTextField(20);
+
+ private JToolBar _toolBar;
+}
+
diff --git a/java/src/IceGridGUI/LiveDeployment/Service.java b/java/src/IceGridGUI/LiveDeployment/Service.java
new file mode 100755
index 00000000000..b7d3f8cbb54
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/Service.java
@@ -0,0 +1,166 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+import java.util.Enumeration;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class Service extends ListArrayTreeNode
+{
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setOpenIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+
+ _cellRenderer.setClosedIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = new ServiceEditor();
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+
+ Service(Server parent, String serviceName, Utils.Resolver resolver,
+ ServiceInstanceDescriptor descriptor,
+ ServiceDescriptor serviceDescriptor)
+ {
+ super(parent, serviceName, 2);
+ _resolver = resolver;
+
+ _instanceDescriptor = descriptor;
+ _serviceDescriptor = serviceDescriptor;
+
+ _childrenArray[0] = _adapters;
+ _childrenArray[1] = _dbEnvs;
+
+ createAdapters();
+ createDbEnvs();
+ }
+
+ boolean updateAdapter(AdapterDynamicInfo info)
+ {
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext())
+ {
+ Adapter adapter = (Adapter)p.next();
+ if(adapter.update(info))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ int updateAdapters(java.util.List infoList)
+ {
+ int result = 0;
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext() && result < infoList.size())
+ {
+ Adapter adapter = (Adapter)p.next();
+ if(adapter.update(infoList))
+ {
+ result++;
+ }
+ }
+ return result;
+ }
+
+ void nodeDown()
+ {
+ java.util.Iterator p = _adapters.iterator();
+ while(p.hasNext())
+ {
+ Adapter adapter = (Adapter)p.next();
+ adapter.update((AdapterDynamicInfo)null);
+ }
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ ServiceDescriptor getServiceDescriptor()
+ {
+ return _serviceDescriptor;
+ }
+
+ private void createAdapters()
+ {
+ java.util.Iterator p = _serviceDescriptor.adapters.iterator();
+ while(p.hasNext())
+ {
+ AdapterDescriptor descriptor = (AdapterDescriptor)p.next();
+ String adapterName = Utils.substitute(descriptor.name, _resolver);
+
+ String adapterId = Utils.substitute(descriptor.id, _resolver);
+ Ice.ObjectPrx proxy = null;
+ if(adapterId.length() > 0)
+ {
+ proxy = ((Node)_parent.getParent()).getProxy(adapterId);
+ }
+
+ insertSortedChild(
+ new Adapter(this, adapterName,
+ _resolver, adapterId, descriptor, proxy),
+ _adapters, null);
+ }
+ }
+
+ private void createDbEnvs()
+ {
+ java.util.Iterator p = _serviceDescriptor.dbEnvs.iterator();
+ while(p.hasNext())
+ {
+ DbEnvDescriptor descriptor = (DbEnvDescriptor)p.next();
+ String dbEnvName = Utils.substitute(descriptor.name, _resolver);
+ insertSortedChild(
+ new DbEnv(this, dbEnvName, _resolver, descriptor), _dbEnvs, null);
+ }
+ }
+
+ private ServiceInstanceDescriptor _instanceDescriptor;
+ private ServiceDescriptor _serviceDescriptor;
+ private Utils.Resolver _resolver;
+
+ private java.util.List _adapters = new java.util.LinkedList();
+ private java.util.List _dbEnvs = new java.util.LinkedList();
+
+ static private ServiceEditor _editor;
+ static private DefaultTreeCellRenderer _cellRenderer;
+}
diff --git a/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java b/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java
new file mode 100755
index 00000000000..1164338ef28
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java
@@ -0,0 +1,51 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.JTextField;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class ServiceEditor extends CommunicatorEditor
+{
+ ServiceEditor()
+ {
+ _entry.setEditable(false);
+ }
+
+ void show(Service service)
+ {
+ ServiceDescriptor descriptor = service.getServiceDescriptor();
+ Utils.Resolver resolver = service.getResolver();
+
+ show(descriptor, resolver);
+ _entry.setText(resolver.substitute(descriptor.entry));
+ }
+
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ super.appendProperties(builder);
+
+ builder.append("Entry Point");
+ builder.append(_entry, 3);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Service Properties");
+ }
+
+ private JTextField _entry = new JTextField(20);
+}
+
diff --git a/java/src/IceGridGUI/LiveDeployment/TreeNode.java b/java/src/IceGridGUI/LiveDeployment/TreeNode.java
new file mode 100755
index 00000000000..912f5d0c29f
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeployment/TreeNode.java
@@ -0,0 +1,160 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.LiveDeployment;
+
+import javax.swing.SwingUtilities;
+import javax.swing.JOptionPane;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+public abstract class TreeNode extends TreeNodeBase
+{
+ public abstract Editor getEditor();
+
+ TreeNode(TreeNode parent, String id)
+ {
+ super(parent, id);
+ }
+
+ Root getRoot()
+ {
+ assert _parent != null;
+ return ((TreeNode)_parent).getRoot();
+ }
+
+ //
+ // Actions
+ //
+ public static final int START = 0;
+ public static final int STOP = 1;
+ public static final int ENABLE = 2;
+ public static final int DISABLE = 3;
+
+ public static final int SHUTDOWN_NODE = 4;
+ public static final int SERVER_INSTALL_DISTRIBUTION = 5;
+
+ static public final int ACTION_COUNT = 6;
+
+ public boolean[] getAvailableActions()
+ {
+ return new boolean[ACTION_COUNT];
+ }
+
+ public void start()
+ {
+ assert false;
+ }
+ public void stop()
+ {
+ assert false;
+ }
+ public void enable()
+ {
+ assert false;
+ }
+ public void disable()
+ {
+ assert false;
+ }
+ public void shutdownNode()
+ {
+ assert false;
+ }
+ public void serverInstallDistribution()
+ {
+ assert false;
+ }
+
+ //
+ // Helpers
+ //
+ protected void amiSuccess(final String prefix)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ getCoordinator().getStatusBar().setText(prefix + "done.");
+ }
+ });
+ }
+
+ protected void amiFailure(String prefix, String title, Ice.UserException e)
+ {
+ if(e instanceof IceGrid.ServerNotExistException)
+ {
+ IceGrid.ServerNotExistException sne =
+ (IceGrid.ServerNotExistException)e;
+
+ amiFailure(prefix, title,
+ "Server '" + sne.id +
+ "' was not registered with the IceGrid Registry");
+ }
+ else if(e instanceof IceGrid.ServerStartException)
+ {
+ IceGrid.ServerStartException ste = (IceGrid.ServerStartException)e;
+ amiFailure(prefix, title, "Server '" +
+ ste.id + "' did not start: " + ste.reason);
+ }
+ else if(e instanceof IceGrid.ApplicationNotExistException)
+ {
+ amiFailure(prefix, title,
+ "This application was not registered with the IceGrid Registry");
+ }
+ else if(e instanceof IceGrid.PatchException)
+ {
+ IceGrid.PatchException pe = (IceGrid.PatchException)e;
+ amiFailure(prefix, title, pe.reason);
+ }
+ else if(e instanceof IceGrid.NodeNotExistException)
+ {
+ IceGrid.NodeNotExistException nnee =
+ (IceGrid.NodeNotExistException)e;
+
+ amiFailure(prefix, title,
+ "Node '" + nnee.name +
+ " 'was not registered with the IceGrid Registry.");
+ }
+ else if(e instanceof IceGrid.NodeUnreachableException)
+ {
+ IceGrid.NodeUnreachableException nue =
+ (IceGrid.NodeUnreachableException)e;
+ amiFailure(prefix, title, "Node '" +
+ nue.name + "' is unreachable: " + nue.reason);
+ }
+ else
+ {
+ amiFailure(prefix, title, e.toString());
+ }
+ }
+
+ protected void amiFailure(final String prefix,
+ final String title, final String message)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ failure(prefix, title, message);
+ }
+ });
+ }
+
+ protected void failure(String prefix, String title, String message)
+ {
+ getCoordinator().getStatusBar().setText(prefix + "failed!");
+
+ JOptionPane.showMessageDialog(
+ getCoordinator().getMainFrame(),
+ message,
+ title,
+ JOptionPane.ERROR_MESSAGE);
+ }
+}
diff --git a/java/src/IceGridGUI/LiveDeploymentPane.java b/java/src/IceGridGUI/LiveDeploymentPane.java
new file mode 100755
index 00000000000..69483d07be6
--- /dev/null
+++ b/java/src/IceGridGUI/LiveDeploymentPane.java
@@ -0,0 +1,342 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.*;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.*;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.plaf.SplitPaneUI;
+import javax.swing.plaf.basic.BasicSplitPaneUI;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreeSelectionModel;
+import javax.swing.tree.TreePath;
+
+import com.jgoodies.looks.Options;
+import com.jgoodies.looks.plastic.PlasticLookAndFeel;
+import com.jgoodies.looks.windows.WindowsLookAndFeel;
+import com.jgoodies.forms.factories.Borders;
+
+import IceGrid.*;
+import IceGridGUI.LiveDeployment.Editor;
+import IceGridGUI.LiveDeployment.Root;
+import IceGridGUI.LiveDeployment.TreeNode;
+
+public class LiveDeploymentPane extends JSplitPane implements Tab
+{
+ public void updateUI()
+ {
+ super.updateUI();
+ setEmptyDividerBorder();
+ }
+
+ public void selected()
+ {
+ Coordinator c = _root.getCoordinator();
+
+ c.getCloseApplicationAction().setEnabled(false);
+ c.getSaveAction().setEnabled(false);
+ c.getSaveToRegistryAction().setEnabled(false);
+ c.getSaveToFileAction().setEnabled(false);
+ c.getDiscardUpdatesAction().setEnabled(false);
+
+ c.getBackAction().setEnabled(_previousNodes.size() > 0);
+ c.getForwardAction().setEnabled(_nextNodes.size() > 0);
+ c.showActions(_currentNode);
+ }
+
+ public void showNode(TreeNodeBase node)
+ {
+ TreeNode newNode = (TreeNode)node;
+
+ if(newNode != _currentNode)
+ {
+ if(newNode == null)
+ {
+ _currentNode = null;
+ showCurrentNode();
+ }
+ else
+ {
+ if(_currentNode != null && _root.hasNode(_currentNode))
+ {
+ _previousNodes.add(_currentNode);
+ while(_previousNodes.size() >= HISTORY_MAX_SIZE)
+ {
+ _previousNodes.removeFirst();
+ }
+ _root.getCoordinator().getBackAction().setEnabled(true);
+ }
+ _nextNodes.clear();
+ _root.getCoordinator().getForwardAction().setEnabled(false);
+ _currentNode = newNode;
+ showCurrentNode();
+ }
+ }
+ else
+ {
+ refresh();
+ }
+
+ }
+
+ public void refresh()
+ {
+ if(_currentNode != null)
+ {
+ _root.getCoordinator().showActions(_currentNode);
+ _currentNode.getEditor();
+ }
+ }
+
+ public void back()
+ {
+ TreeNode previousNode = null;
+ do
+ {
+ previousNode = (TreeNode)_previousNodes.removeLast();
+ } while(_previousNodes.size() > 0
+ && (previousNode == _currentNode || !_root.hasNode(previousNode)));
+
+ if(_previousNodes.size() == 0)
+ {
+ _root.getCoordinator().getBackAction().setEnabled(false);
+ }
+
+ if(previousNode != _currentNode)
+ {
+ if(_currentNode != null)
+ {
+ _nextNodes.addFirst(_currentNode);
+ _root.getCoordinator().getForwardAction().setEnabled(true);
+ }
+
+ _currentNode = previousNode;
+ _selectionListenerEnabled = false;
+ _root.setSelectedNode(_currentNode);
+ _selectionListenerEnabled = true;
+ showCurrentNode();
+ }
+ }
+
+ public void forward()
+ {
+ TreeNode nextNode = null;
+ do
+ {
+ nextNode = (TreeNode)_nextNodes.removeFirst();
+ } while(_nextNodes.size() > 0
+ && (nextNode == _currentNode || !_root.hasNode(nextNode)));
+
+ if(_nextNodes.size() == 0)
+ {
+ _root.getCoordinator().getForwardAction().setEnabled(false);
+ }
+
+ if(nextNode != _currentNode)
+ {
+ if(_currentNode != null)
+ {
+ _previousNodes.add(_currentNode);
+ _root.getCoordinator().getBackAction().setEnabled(true);
+ }
+
+ _currentNode = nextNode;
+ _selectionListenerEnabled = false;
+ _root.setSelectedNode(_currentNode);
+ _selectionListenerEnabled = true;
+ showCurrentNode();
+ }
+ }
+
+
+ public void save()
+ {
+ assert false;
+ }
+ public void saveToRegistry()
+ {
+ assert false;
+ }
+ public void saveToFile()
+ {
+ assert false;
+ }
+ public void discardUpdates()
+ {
+ assert false;
+ }
+ public boolean close()
+ {
+ return false;
+ }
+
+ LiveDeploymentPane(Root root)
+ {
+ super(JSplitPane.HORIZONTAL_SPLIT, true);
+ _root = root;
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ //
+ // Tree display
+ //
+ TreeCellRenderer renderer = new CellRenderer();
+ PopupListener popupListener = new PopupListener();
+
+ JTree tree = _root.getTree();
+
+ tree.setBorder(new EmptyBorder(5, 5, 5, 5));
+ tree.setCellRenderer(renderer);
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ tree.addMouseListener(popupListener);
+
+ tree.getSelectionModel().setSelectionMode
+ (TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+ tree.addTreeSelectionListener(new SelectionListener());
+
+ tree.setRootVisible(false);
+
+ JScrollPane leftScroll =
+ new JScrollPane(tree,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ leftScroll.setBorder(Borders.EMPTY_BORDER);
+
+ _leftPane = new SimpleInternalFrame("Runtime Components");
+ _leftPane.setContent(leftScroll);
+ _leftPane.setPreferredSize(new Dimension(280, 350));
+
+ //
+ // Right pane
+ //
+ _propertiesFrame = new SimpleInternalFrame("Properties");
+
+ setLeftComponent(_leftPane);
+ setRightComponent(_propertiesFrame);
+ }
+
+ private void showCurrentNode()
+ {
+ _root.getCoordinator().showActions(_currentNode);
+ if(_currentNode == null)
+ {
+ Component oldContent = _propertiesFrame.getContent();
+ if(oldContent != null)
+ {
+ _propertiesFrame.remove(oldContent);
+ }
+ _propertiesFrame.setTitle("Properties");
+ _propertiesFrame.setToolBar(null);
+ }
+ else
+ {
+ Editor editor = _currentNode.getEditor();
+ Component currentProperties = editor.getProperties();
+ _propertiesFrame.setContent(currentProperties);
+ _propertiesFrame.setTitle(currentProperties.getName());
+ _propertiesFrame.setToolBar(editor.getToolBar());
+ }
+ _propertiesFrame.validate();
+ _propertiesFrame.repaint();
+ }
+
+ private void setEmptyDividerBorder()
+ {
+ SplitPaneUI splitPaneUI = getUI();
+ if(splitPaneUI instanceof BasicSplitPaneUI)
+ {
+ BasicSplitPaneUI basicUI = (BasicSplitPaneUI)splitPaneUI;
+ basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder());
+ }
+ }
+
+
+ private class SelectionListener implements TreeSelectionListener
+ {
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ if(_selectionListenerEnabled)
+ {
+ TreePath path = null;
+ if(e.isAddedPath())
+ {
+ path = e.getPath();
+ }
+
+ if(path == null)
+ {
+ showNode(null);
+ }
+ else
+ {
+ showNode((TreeNode)path.getLastPathComponent());
+ }
+ }
+ }
+ }
+
+
+ private class PopupListener extends MouseAdapter
+ {
+ public void mousePressed(MouseEvent e)
+ {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ maybeShowPopup(e);
+ }
+
+ private void maybeShowPopup(MouseEvent e)
+ {
+ if (e.isPopupTrigger())
+ {
+ JTree tree = (JTree)e.getComponent();
+
+ TreePath path = tree.getPathForLocation(e.getX(), e.getY());
+
+ if(path != null)
+ {
+ TreeNode node = (TreeNode)path.getLastPathComponent();
+ JPopupMenu popup = node.getPopupMenu();
+ if(popup != null)
+ {
+ popup.show(tree, e.getX(), e.getY());
+ }
+ }
+ }
+ }
+ }
+
+ private Root _root;
+ private SimpleInternalFrame _leftPane;
+ private SimpleInternalFrame _propertiesFrame;
+
+
+ //
+ // back/forward navigation
+ //
+ private java.util.LinkedList _previousNodes = new java.util.LinkedList();
+ private java.util.LinkedList _nextNodes = new java.util.LinkedList();
+ private TreeNode _currentNode;
+
+ private boolean _selectionListenerEnabled = true;
+
+ static private final int HISTORY_MAX_SIZE = 20;
+}
diff --git a/java/src/IceGridGUI/Main.java b/java/src/IceGridGUI/Main.java
new file mode 100755
index 00000000000..f7b73c4d325
--- /dev/null
+++ b/java/src/IceGridGUI/Main.java
@@ -0,0 +1,93 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.Icon;
+import javax.swing.JFrame;
+
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+
+import java.util.prefs.Preferences;
+
+public class Main extends JFrame
+{
+ public static void main(final String[] args)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ createAndShowGUI(args);
+ }
+ });
+ }
+
+ Main(String[] args)
+ {
+ super("IceGrid Admin");
+ javax.swing.ImageIcon icon = Utils.getIcon("/icons/16x16/grid.png");
+ if(icon != null)
+ {
+ setIconImage(icon.getImage());
+ }
+
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+ addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ if(_coordinator != null)
+ {
+ _coordinator.exit(0);
+ }
+ }
+ });
+
+ _coordinator =
+ new Coordinator(this, args, Preferences.userNodeForPackage(getClass()));
+
+ _coordinator.showMainFrame();
+ }
+
+ private static void createAndShowGUI(String[] args)
+ {
+ try
+ {
+ if(UIManager.getSystemLookAndFeelClassName().equals("apple.laf.AquaLookAndFeel"))
+ {
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+ UIManager.setLookAndFeel("apple.laf.AquaLookAndFeel");
+ }
+ else // JGoodies L&F
+ {
+ UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
+ }
+ }
+ catch(Exception e)
+ {
+ System.err.println(e.toString());
+ }
+
+ //
+ // Create and set up the window.
+ //
+ new Main(args);
+
+ }
+
+ private Coordinator _coordinator;
+}
+
+
diff --git a/java/src/IceGridGUI/MainPane.java b/java/src/IceGridGUI/MainPane.java
new file mode 100755
index 00000000000..0384fe3f92c
--- /dev/null
+++ b/java/src/IceGridGUI/MainPane.java
@@ -0,0 +1,156 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.Component;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.border.EmptyBorder;
+
+public class MainPane extends JTabbedPane
+{
+ public void addApplication(ApplicationPane application)
+ {
+ IceGridGUI.Application.Root root = application.getRoot();
+ super.addTab(computeTitle(root.getId()),
+ getIcon(root), application);
+ }
+
+ public void setTitleAt(int index, String title)
+ {
+ super.setTitleAt(index, computeTitle(title));
+ }
+
+ public void resetTitle(IceGridGUI.Application.Root root)
+ {
+ System.err.println("Reset title");
+ int i = findIndex(root);
+ if(i > 0)
+ {
+ System.err.println("New title:" + root.getId());
+ setTitleAt(i, root.getId());
+ }
+ }
+
+ public void resetIcon(IceGridGUI.Application.Root root)
+ {
+ int i = findIndex(root);
+ if(i > 0)
+ {
+ setIconAt(i, getIcon(root));
+ }
+ }
+
+ public int findIndex(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public ApplicationPane findApplication(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ return pane;
+ }
+ }
+ return null;
+ }
+
+ public void removeApplication(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ removeTabAt(i);
+ break;
+ }
+ }
+ }
+
+ MainPane(Coordinator coordinator)
+ {
+ _coordinator = coordinator;
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ addChangeListener(new ChangeListener()
+ {
+ public void stateChanged(ChangeEvent evt)
+ {
+ Tab tab = (Tab)getSelectedComponent();
+ tab.selected();
+ }
+ });
+
+ _liveIcon = Utils.getIcon("/icons/16x16/grid.png");
+ _fileIcon = Utils.getIcon("/icons/16x16/folder_open.png");
+
+ addTab("Live Deployment", _liveIcon, _coordinator.getLiveDeploymentPane());
+ }
+
+
+ private String computeTitle(String name)
+ {
+ String title = name;
+ int i = 0;
+ while(hasTitle(title))
+ {
+ title = name + " (" + Integer.toString(++i) + ")";
+ }
+ return title;
+ }
+
+ private boolean hasTitle(String title)
+ {
+ int tabCount = getTabCount();
+ for(int i = 0; i < tabCount; ++i)
+ {
+ if(title.equals(getTitleAt(i)))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private ImageIcon getIcon(IceGridGUI.Application.Root root)
+ {
+ if(root.isLive())
+ {
+ return _liveIcon;
+ }
+ else if(root.hasFile())
+ {
+ return _fileIcon;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ private Coordinator _coordinator;
+ private ImageIcon _liveIcon;
+ private ImageIcon _fileIcon;
+}
diff --git a/java/src/IceGrid/NodeObserverI.java b/java/src/IceGridGUI/NodeObserverI.java
index 3bb9511d2fe..2755eca8cc6 100755
--- a/java/src/IceGrid/NodeObserverI.java
+++ b/java/src/IceGridGUI/NodeObserverI.java
@@ -1,20 +1,21 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import javax.swing.SwingUtilities;
+import IceGrid.*;
class NodeObserverI extends _NodeObserverDisp
{
- NodeObserverI(Model model)
+ NodeObserverI(Coordinator coordinator)
{
- _model = model;
+ _coordinator = coordinator;
}
public void init(final NodeDynamicInfo[] nodes, Ice.Current current)
@@ -25,7 +26,7 @@ class NodeObserverI extends _NodeObserverDisp
{
for(int i = 0; i < nodes.length; ++i)
{
- _model.nodeUp(nodes[i]);
+ _coordinator.nodeUp(nodes[i]);
}
}
});
@@ -37,7 +38,7 @@ class NodeObserverI extends _NodeObserverDisp
{
public void run()
{
- _model.nodeUp(nodeInfo);
+ _coordinator.nodeUp(nodeInfo);
}
});
}
@@ -48,7 +49,7 @@ class NodeObserverI extends _NodeObserverDisp
{
public void run()
{
- _model.nodeDown(nodeName);
+ _coordinator.nodeDown(nodeName);
}
});
}
@@ -60,7 +61,7 @@ class NodeObserverI extends _NodeObserverDisp
{
public void run()
{
- _model.updateServer(node, updatedInfo);
+ _coordinator.updateServer(node, updatedInfo);
}
});
}
@@ -72,10 +73,10 @@ class NodeObserverI extends _NodeObserverDisp
{
public void run()
{
- _model.updateAdapter(node, updatedInfo);
+ _coordinator.updateAdapter(node, updatedInfo);
}
});
}
- private Model _model;
+ private Coordinator _coordinator;
};
diff --git a/java/src/IceGrid/ParametersDialog.java b/java/src/IceGridGUI/ParametersDialog.java
index 027159e76c3..2bfcb282cff 100755
--- a/java/src/IceGrid/ParametersDialog.java
+++ b/java/src/IceGridGUI/ParametersDialog.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import java.awt.BorderLayout;
import java.awt.Dimension;
diff --git a/java/src/IceGrid/RegistryObserverI.java b/java/src/IceGridGUI/RegistryObserverI.java
index 67453a13d16..808cc306c9a 100755
--- a/java/src/IceGrid/RegistryObserverI.java
+++ b/java/src/IceGridGUI/RegistryObserverI.java
@@ -1,21 +1,22 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import javax.swing.SwingUtilities;
+import IceGrid.*;
class RegistryObserverI extends _RegistryObserverDisp
{
- RegistryObserverI(Model model)
+ RegistryObserverI(Coordinator coordinator)
{
- _model = model;
+ _coordinator = coordinator;
}
//
@@ -48,7 +49,7 @@ class RegistryObserverI extends _RegistryObserverDisp
if(_initialized)
{
- _model.registryInit(_serial, _applications);
+ _coordinator.registryInit(_serial, _applications);
}
else
{
@@ -73,7 +74,7 @@ class RegistryObserverI extends _RegistryObserverDisp
{
public void run()
{
- _model.applicationAdded(serial, desc);
+ _coordinator.applicationAdded(serial, desc);
}
});
}
@@ -85,7 +86,7 @@ class RegistryObserverI extends _RegistryObserverDisp
{
public void run()
{
- _model.applicationRemoved(serial, name);
+ _coordinator.applicationRemoved(serial, name);
}
});
}
@@ -97,13 +98,13 @@ class RegistryObserverI extends _RegistryObserverDisp
{
public void run()
{
- _model.applicationUpdated(serial, desc);
+ _coordinator.applicationUpdated(serial, desc);
}
});
}
- private Model _model;
+ private Coordinator _coordinator;
private boolean _initialized = false;
diff --git a/java/src/IceGrid/SessionKeeper.java b/java/src/IceGridGUI/SessionKeeper.java
index d41c2094de9..ce0393eb293 100755
--- a/java/src/IceGrid/SessionKeeper.java
+++ b/java/src/IceGridGUI/SessionKeeper.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import javax.swing.*;
@@ -29,6 +29,8 @@ import com.jgoodies.forms.util.LayoutStyle;
import java.util.prefs.Preferences;
+import IceGrid.*;
+
//
// The SessionKeeper is responsible for establishing sessions (one at a time)
// and keeping them alive.
@@ -129,9 +131,6 @@ class SessionKeeper
registryUsername = _connectionPrefs.get("registry.username", registryUsername);
routerUsername = _connectionPrefs.get("router.username", routerUsername);
- registryAutoconnect = _connectionPrefs.
- getBoolean("registry.autoconnect", registryAutoconnect);
-
routed = _connectionPrefs.getBoolean("routed", routed);
}
@@ -148,7 +147,6 @@ class SessionKeeper
else
{
_connectionPrefs.put("registry.username", registryUsername);
- _connectionPrefs.putBoolean("registry.autoconnect", registryAutoconnect);
_connectionPrefs.put("registry.instanceName", registryInstanceName);
_connectionPrefs.put("registry.endpoints", registryEndpoints);
}
@@ -157,7 +155,6 @@ class SessionKeeper
boolean routed = false;
String registryUsername = System.getProperty("user.name");
- boolean registryAutoconnect = false;
String registryInstanceName = "IceGrid";
String registryEndpoints = "";
@@ -176,7 +173,7 @@ class SessionKeeper
{
LoginDialog()
{
- super(_model.getMainFrame(), "Login - IceGrid Admin", true);
+ super(_coordinator.getMainFrame(), "Login - IceGrid Admin", true);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
@@ -220,8 +217,6 @@ class SessionKeeper
builder.append("Username", _registryUsername);
builder.nextLine();
- builder.append("", _registryAutoconnect);
- builder.nextLine();
builder.append("IceGrid Instance Name", _registryInstanceName);
builder.nextLine();
builder.append("IceGrid Registry Endpoint(s)", _registryEndpoints);
@@ -277,7 +272,6 @@ class SessionKeeper
_tabbedPane.setSelectedIndex(_loginInfo.routed ? 1 : 0);
_registryUsername.setText(_loginInfo.registryUsername);
- _registryAutoconnect.setSelected(_loginInfo.registryAutoconnect);
_registryInstanceName.setText(_loginInfo.registryInstanceName);
_registryEndpoints.setText(_loginInfo.registryEndpoints);
@@ -285,7 +279,7 @@ class SessionKeeper
_routerInstanceName.setText(_loginInfo.routerInstanceName);
_routerEndpoints.setText(_loginInfo.routerEndpoints);
- setLocationRelativeTo(_model.getMainFrame());
+ setLocationRelativeTo(_coordinator.getMainFrame());
setVisible(true);
}
@@ -299,7 +293,6 @@ class SessionKeeper
_loginInfo.routed = (_tabbedPane.getSelectedIndex() == 1);
_loginInfo.registryUsername = _registryUsername.getText();
- _loginInfo.registryAutoconnect = _registryAutoconnect.isSelected();
_loginInfo.registryInstanceName = _registryInstanceName.getText();
_loginInfo.registryEndpoints = _registryEndpoints.getText();
@@ -311,8 +304,6 @@ class SessionKeeper
private JTabbedPane _tabbedPane = new JTabbedPane();
private JTextField _registryUsername = new JTextField(30);
- private JCheckBox _registryAutoconnect
- = new JCheckBox("Automatically log in at startup");
private JTextField _registryInstanceName = new JTextField(30);
private JTextField _registryEndpoints = new JTextField(30);
@@ -384,42 +375,33 @@ class SessionKeeper
}
- SessionKeeper(Model model)
+ SessionKeeper(Coordinator coordinator)
{
- _model = model;
+ _coordinator = coordinator;
_loginDialog = new LoginDialog();
- _loginPrefs = model.getPrefs().node("Connection");
+ _loginPrefs = coordinator.getPrefs().node("Connection");
}
//
// Runs in UI thread
//
- void createSession(boolean autoconnectEnabled)
+ void createSession()
{
_loginInfo = new LoginInfo(_loginPrefs,
- _model.getCommunicator());
- boolean openDialog = true;
- if(autoconnectEnabled && !_loginInfo.routed &&
- _loginInfo.registryAutoconnect)
- {
- openDialog = !login(_model.getMainFrame());
- }
+ _coordinator.getCommunicator());
+ _loginDialog.showDialog();
- if(openDialog)
- {
- _loginDialog.showDialog();
- }
}
void relog(boolean showDialog)
{
if(_loginInfo == null)
{
- createSession(!showDialog);
+ createSession();
}
else
{
- if(showDialog || !login(_model.getMainFrame()))
+ if(showDialog || !login(_coordinator.getMainFrame()))
{
_loginDialog.showDialog();
}
@@ -430,7 +412,7 @@ class SessionKeeper
{
destroyObservers();
releaseSession(destroySession);
- _model.sessionLost();
+ _coordinator.sessionLost();
}
private boolean login(Component parent)
@@ -446,13 +428,13 @@ class SessionKeeper
{
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- _session = _model.login(_loginInfo, parent);
+ _session = _coordinator.login(_loginInfo, parent);
if(_session == null)
{
return false;
}
- _model.getStatusBar().setConnected(true);
+ _coordinator.getStatusBar().setConnected(true);
//
// Start thread
@@ -495,7 +477,7 @@ class SessionKeeper
void sessionLost(String message)
{
JOptionPane.showMessageDialog(
- _model.getMainFrame(),
+ _coordinator.getMainFrame(),
message,
"Session lost",
JOptionPane.ERROR_MESSAGE);
@@ -525,11 +507,10 @@ class SessionKeeper
if(destroySession)
{
- _model.destroySession(_session);
+ _coordinator.destroySession(_session);
}
-
_session = null;
- _model.getStatusBar().setConnected(false);
+ _coordinator.getStatusBar().setConnected(false);
}
}
@@ -542,7 +523,7 @@ class SessionKeeper
String category;
Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast(
- _model.getCommunicator().getDefaultRouter());
+ _coordinator.getCommunicator().getDefaultRouter());
if(router == null)
{
category = "observer";
@@ -561,9 +542,9 @@ class SessionKeeper
_nodeObserverIdentity.name = "node-" + uuid;
_nodeObserverIdentity.category = category;
- Ice.ObjectAdapter adapter = _model.getObjectAdapter();
+ Ice.ObjectAdapter adapter = _coordinator.getObjectAdapter();
- RegistryObserverI registryObserverServant = new RegistryObserverI(_model);
+ RegistryObserverI registryObserverServant = new RegistryObserverI(_coordinator);
RegistryObserverPrx registryObserver =
RegistryObserverPrxHelper.uncheckedCast(
@@ -573,7 +554,7 @@ class SessionKeeper
NodeObserverPrx nodeObserver =
NodeObserverPrxHelper.uncheckedCast(
adapter.add(
- new NodeObserverI(_model), _nodeObserverIdentity));
+ new NodeObserverI(_coordinator), _nodeObserverIdentity));
_session.setObservers(registryObserver, nodeObserver);
@@ -585,7 +566,7 @@ class SessionKeeper
//
private void destroyObservers()
{
- Ice.ObjectAdapter adapter = _model.getObjectAdapter();
+ Ice.ObjectAdapter adapter = _coordinator.getObjectAdapter();
try
{
@@ -613,7 +594,7 @@ class SessionKeeper
private LoginDialog _loginDialog;
private LoginInfo _loginInfo;
- private Model _model;
+ private Coordinator _coordinator;
private Preferences _loginPrefs;
private Pinger _thread;
diff --git a/java/src/IceGrid/SimpleInternalFrame.java b/java/src/IceGridGUI/SimpleInternalFrame.java
index 456507c67ba..8743464048c 100755
--- a/java/src/IceGrid/SimpleInternalFrame.java
+++ b/java/src/IceGridGUI/SimpleInternalFrame.java
@@ -28,7 +28,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package IceGrid;
+package IceGridGUI;
import java.awt.*;
diff --git a/java/src/IceGrid/StatusBar.java b/java/src/IceGridGUI/StatusBar.java
index 99ecef8f122..85e13507cd4 100755
--- a/java/src/IceGrid/StatusBar.java
+++ b/java/src/IceGridGUI/StatusBar.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
public interface StatusBar
{
diff --git a/java/src/IceGridGUI/Tab.java b/java/src/IceGridGUI/Tab.java
new file mode 100755
index 00000000000..0c4e14c1fbe
--- /dev/null
+++ b/java/src/IceGridGUI/Tab.java
@@ -0,0 +1,27 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+public interface Tab
+{
+ void selected();
+
+ void showNode(TreeNodeBase node);
+ void refresh();
+
+ void back();
+ void forward();
+
+ boolean close();
+
+ void save();
+ void saveToRegistry();
+ void saveToFile();
+ void discardUpdates();
+}
diff --git a/java/src/IceGrid/TableDialog.java b/java/src/IceGridGUI/TableDialog.java
index 3a1f8788ce6..da0b7e9cac3 100755
--- a/java/src/IceGrid/TableDialog.java
+++ b/java/src/IceGridGUI/TableDialog.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import java.awt.BorderLayout;
import java.awt.Dimension;
diff --git a/java/src/IceGridGUI/TreeNodeBase.java b/java/src/IceGridGUI/TreeNodeBase.java
new file mode 100755
index 00000000000..5dbed38db6a
--- /dev/null
+++ b/java/src/IceGridGUI/TreeNodeBase.java
@@ -0,0 +1,268 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.util.Enumeration;
+
+import java.awt.Component;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.JPopupMenu;
+
+//
+// This class behaves like a leaf; derived class that represent non-leaf nodes must
+// override various methods.
+//
+public class TreeNodeBase implements javax.swing.tree.TreeNode, TreeCellRenderer
+{
+ public Coordinator getCoordinator()
+ {
+ return _parent.getCoordinator();
+ }
+
+ public Enumeration children()
+ {
+ return new Enumeration()
+ {
+ public boolean hasMoreElements()
+ {
+ return false;
+ }
+
+ public Object nextElement()
+ {
+ throw new java.util.NoSuchElementException();
+ }
+ };
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return false;
+ }
+
+ public javax.swing.tree.TreeNode getChildAt(int childIndex)
+ {
+ return null;
+ }
+
+ public int getChildCount()
+ {
+ return 0;
+ }
+
+ public int getIndex(javax.swing.tree.TreeNode node)
+ {
+ return -1;
+ }
+
+ public javax.swing.tree.TreeNode getParent()
+ {
+ return _parent;
+ }
+
+ public boolean isLeaf()
+ {
+ return true;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ return null;
+ }
+
+ public String toString()
+ {
+ return _id;
+ }
+
+ public JPopupMenu getPopupMenu()
+ {
+ return null;
+ }
+
+ public String getId()
+ {
+ return _id;
+ }
+
+ public TreePath getPath()
+ {
+ if(_parent == null)
+ {
+ return new TreePath(this);
+ }
+ else
+ {
+ return _parent.getPath().pathByAddingChild(this);
+ }
+ }
+
+ public java.util.LinkedList getFullId()
+ {
+ java.util.LinkedList result = _parent == null ?
+ new java.util.LinkedList() :
+ _parent.getFullId();
+
+ result.add(_id);
+ return result;
+ }
+
+ public TreeNodeBase findChild(String id)
+ {
+ Enumeration p = children();
+ while(p.hasMoreElements())
+ {
+ TreeNodeBase child = (TreeNodeBase)p.nextElement();
+ if(child.getId().equals(id))
+ {
+ return child;
+ }
+ }
+ return null;
+ }
+
+ protected TreeNodeBase(TreeNodeBase parent, String id)
+ {
+ _parent = parent;
+ _id = id;
+ }
+
+ //
+ // Helper functions
+ //
+ protected boolean insertSortedChild(TreeNodeBase newChild, java.util.List children,
+ DefaultTreeModel treeModel)
+ {
+ String id = newChild.getId();
+ int i;
+ for(i = 0; i < children.size(); ++i)
+ {
+ String otherId = ((TreeNodeBase)children.get(i)).getId();
+ int cmp = id.compareTo(otherId);
+
+ if(cmp == 0)
+ {
+ return false;
+ }
+ else if(cmp < 0)
+ {
+ break;
+ }
+ }
+ children.add(i, newChild);
+
+ if(treeModel != null)
+ {
+ treeModel.nodesWereInserted(this, new int[]{getIndex(newChild)});
+ }
+ return true;
+ }
+
+
+ protected void removeSortedChildren(String[] childIds,
+ java.util.List fromChildren,
+ DefaultTreeModel treeModel)
+ {
+ if(childIds.length == 0)
+ {
+ return; // nothing to do
+ }
+ assert fromChildren.size() > 0;
+
+ String[] ids = (String[])childIds.clone();
+ java.util.Arrays.sort(ids);
+
+ Object[] childrenToRemove = new Object[ids.length];
+ int[] indices = new int[ids.length];
+
+ int i = getIndex((TreeNodeBase)fromChildren.get(0));
+ int j = 0;
+ java.util.Iterator p = fromChildren.iterator();
+
+ while(p.hasNext() && j < ids.length)
+ {
+ TreeNodeBase child = (TreeNodeBase)p.next();
+ if(ids[j].equals(child.getId()))
+ {
+ childrenToRemove[j] = child;
+ indices[j] = i;
+ p.remove();
+ ++j;
+ }
+ ++i;
+ }
+
+ //
+ // Should be all removed
+ //
+ assert(j == ids.length);
+
+ if(treeModel != null)
+ {
+ treeModel.nodesWereRemoved(this, indices, childrenToRemove);
+ }
+ }
+
+ protected void childrenChanged(java.util.List children, DefaultTreeModel treeModel)
+ {
+ int[] indices = new int[children.size()];
+ int i = 0;
+ java.util.Iterator p = children.iterator();
+ while(p.hasNext())
+ {
+ TreeNodeBase child = (TreeNodeBase)p.next();
+ indices[i++] = getIndex(child);
+ }
+ treeModel.nodesChanged(this, indices);
+ }
+
+ public int[] resize(int[] array, int size)
+ {
+ int[] result = new int[size];
+ System.arraycopy(array, 0, result, 0, size);
+ return result;
+ }
+
+ protected TreeNodeBase find(String id, java.util.List inList)
+ {
+ java.util.Iterator p = inList.iterator();
+ while(p.hasNext())
+ {
+ TreeNodeBase node = (TreeNodeBase)p.next();
+ if(node.getId().equals(id))
+ {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ protected TreeNodeBase _parent;
+ protected String _id;
+
+ protected java.util.Comparator _childComparator = new java.util.Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ TreeNodeBase child1 = (TreeNodeBase)o1;
+ TreeNodeBase child2 = (TreeNodeBase)o2;
+ return child1.getId().compareTo(child2.getId());
+ }
+ };
+}
diff --git a/java/src/IceGrid/Utils.java b/java/src/IceGridGUI/Utils.java
index 0a981532298..b85a54fed22 100755
--- a/java/src/IceGrid/Utils.java
+++ b/java/src/IceGridGUI/Utils.java
@@ -1,12 +1,12 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid;
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
import javax.swing.ImageIcon;
@@ -125,182 +125,47 @@ public class Utils
return stringify(stringMap.entrySet(), stringifier, separator, toolTipHolder);
}
-
- //
- // Same algorithm as DescriptorVariables::substituteImpl (see IceGrid C++)
- //
- static public String substituteVariables(String input, java.util.Map[] stringMaps)
- {
- if(stringMaps == null)
- {
- return input;
- }
-
- int beg = 0;
- int end = 0;
-
- while((beg = input.indexOf("${", beg)) != -1)
- {
- if(beg > 0 && input.charAt(beg - 1) == '$')
- {
- int escape = beg - 1;
- while(escape > 0 && input.charAt(escape = 1) == '$')
- {
- --escape;
- }
-
- input = input.substring(0, escape) + input.substring(beg - (beg - escape) / 2);
- if((beg - escape) % 2 != 0)
- {
- ++beg;
- continue;
- }
- else
- {
- beg -= (beg - escape) / 2;
- }
- }
-
- end = input.indexOf('}', beg);
- if(end == -1)
- {
- //
- // Malformed variable, can't subsitute anything else
- //
- return input;
- }
-
- String name = input.substring(beg + 2, end);
-
- //
- // Lookup name's value
- //
- String val = null;
- for(int i = 0; i < stringMaps.length; ++i)
- {
- if(stringMaps[i] != null)
- {
- val = (String)stringMaps[i].get(name);
- if(val != null)
- {
- break; // for
- }
- }
- }
-
- if(val != null)
- {
- input = input.substring(0, beg) + val + input.substring(end + 1);
- beg += val.length();
- }
- else
- {
- //
- // No substitution, keep ${name} in the result
- //
- ++beg;
- }
- }
- return input;
- }
-
- static public String substituteVariables(String input, java.util.Map m1)
- {
- return substituteVariables(input,
- new java.util.Map[]{m1});
- }
-
- static public String substituteVariables(String input, java.util.Map m1,
- java.util.Map m2)
- {
- return substituteVariables(input,
- new java.util.Map[]{m1, m2});
- }
-
- static public String substituteVariables(String input, java.util.Map m1,
- java.util.Map m2, java.util.Map m3)
- {
- return substituteVariables(input,
- new java.util.Map[]{m1, m2, m3});
- }
-
- static public java.util.Map substituteVariables(java.util.Map input,
- java.util.Map[] stringMaps)
- {
- java.util.Map result = new java.util.HashMap();
-
- java.util.Iterator p = input.entrySet().iterator();
- while(p.hasNext())
- {
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- result.put(entry.getKey(),
- substituteVariables((String)entry.getValue(), stringMaps));
- }
-
- return result;
- }
-
-
- static public java.util.Map substituteVariables(java.util.Map input,
- java.util.Map m1,
- java.util.Map m2)
- {
- return substituteVariables(input,
- new java.util.Map[]{m1, m2});
- }
-
- static public java.util.Map substituteVariables(java.util.Map input,
- java.util.Map m1,
- java.util.Map m2,
- java.util.Map m3)
- {
- return substituteVariables(input,
- new java.util.Map[]{m1, m2, m3});
- }
-
-
static public class Resolver
{
//
- // Simple resolver
+ // Application-level resolver
//
public Resolver(java.util.Map variables)
{
this(new java.util.Map[]{variables});
}
-
+
public Resolver(java.util.Map[] variables)
{
_variables = variables;
- _resolvedVariableCache = new java.util.HashMap();
+ _predefinedVariables = new java.util.HashMap();
+
_parameters = null;
_subResolver = this;
}
//
- // Resolver for instance; parameters is not yet substituted
+ // Resolver for instance; in-parameters are not yet substituted
//
public Resolver(Resolver parent, java.util.Map parameters,
java.util.Map defaults)
{
- java.util.Map substitutedParameters =
- parent.substituteParameterValues(parameters, defaults);
-
_variables = parent._variables;
- _resolvedVariableCache =
- new java.util.HashMap(parent._resolvedVariableCache);
- _parameters = substitutedParameters;
- _subResolver = new Resolver(_variables, _resolvedVariableCache);
+
+ //
+ // Whenever the parent's predefined variables change, the resolver
+ // must be recreated
+ //
+ reset(parent, parameters, defaults);
}
//
- // Resolver for plain server
+ // Resolver for plain server or service
//
public Resolver(Resolver parent)
{
_variables = parent._variables;
- _resolvedVariableCache =
- new java.util.HashMap(parent._resolvedVariableCache);
+ _predefinedVariables = new java.util.HashMap(parent._predefinedVariables);
_parameters = parent._parameters;
if(_parameters == null)
{
@@ -308,18 +173,19 @@ public class Utils
}
else
{
- _subResolver = new Resolver(_variables, _resolvedVariableCache);
+ _subResolver = new Resolver(_variables, _predefinedVariables);
}
}
private Resolver(java.util.Map[] variables,
- java.util.Map resolvedVariableCache)
+ java.util.Map predefinedVariables)
{
_variables = variables;
- _resolvedVariableCache = resolvedVariableCache;
+ _predefinedVariables = _predefinedVariables;
+
_parameters = null;
_subResolver = this;
- }
+ }
public String find(String name)
{
@@ -331,52 +197,43 @@ public class Utils
return (String)obj;
}
}
-
- Object obj = _resolvedVariableCache.get(name);
+
+ Object obj = _predefinedVariables.get(name);
if(obj != null)
{
return (String)obj;
}
- else
+
+ for(int i = 0; i < _variables.length; ++i)
{
- for(int i = 0; i < _variables.length; ++i)
- {
- obj = _variables[i].get(name);
- if(obj != null)
- {
- break;
- }
- }
+ obj = _variables[i].get(name);
if(obj != null)
{
- //
- // If I lookup myself, replace xxx${myself}xxx by xxx<error msg>xxx
- //
- _resolvedVariableCache.put(name, _recursiveDefError);
- String result = _subResolver.substitute((String)obj);
- if(obj.equals(result))
- {
- _resolvedVariableCache.remove(name);
- }
- else
- {
- _resolvedVariableCache.put(name, result);
- }
- return result;
- }
- else
- {
- return null;
+ return _subResolver.substitute((String)obj);
}
}
+ return null;
}
//
- // Put this entry; particularly useful for predefined variables
+ // Set a pre-defined variable
//
public void put(String name, String value)
{
- _resolvedVariableCache.put(name, value);
+ _predefinedVariables.put(name, value);
+ }
+
+ //
+ // Reset parameters and pre-defined variables
+ //
+ public void reset(Resolver parent, java.util.Map parameters,
+ java.util.Map defaults)
+ {
+ assert _variables == parent._variables;
+ _predefinedVariables = new java.util.HashMap(parent._predefinedVariables);
+
+ _parameters = parent.substituteParameterValues(parameters, defaults);
+ _subResolver = new Resolver(_variables, _predefinedVariables);
}
//
@@ -467,7 +324,7 @@ public class Utils
while(p.hasNext())
{
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- if(result.get(entry.getKey()) == null)
+ if(!result.containsKey(entry.getKey()))
{
result.put(entry.getKey(), substitute((String)entry.getValue()));
}
@@ -476,10 +333,10 @@ public class Utils
}
private java.util.Map[] _variables;
- private java.util.Map _resolvedVariableCache;
private java.util.Map _parameters;
+ private java.util.Map _predefinedVariables;
+
private Resolver _subResolver;
- static private String _recursiveDefError = "<recursive def error>";
}
diff --git a/java/src/IceGridGUI/XMLWriter.java b/java/src/IceGridGUI/XMLWriter.java
new file mode 100755
index 00000000000..d3e44aa2681
--- /dev/null
+++ b/java/src/IceGridGUI/XMLWriter.java
@@ -0,0 +1,117 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.io.*;
+
+//
+// Helper class to write XML files
+//
+public class XMLWriter
+{
+ public XMLWriter(File file) throws FileNotFoundException, IOException
+ {
+ try
+ {
+ _writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
+ }
+ catch(UnsupportedEncodingException e)
+ {
+ assert false;
+ }
+ _writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + _newline);
+ _writer.write("<!-- This file was written by IceGrid Admin -->" + _newline);
+ }
+
+ public void writeElement(String name, java.util.List attributes)
+ throws IOException
+ {
+ _writer.write(_indent);
+ _writer.write("<" + name);
+ writeAttributes(attributes);
+ _writer.write("/>" + _newline);
+ }
+
+ public void writeElement(String name) throws IOException
+ {
+ writeElement(name, (java.util.List)null);
+ }
+
+ public void writeElement(String name, String content) throws IOException
+ {
+ //
+ // TODO: deal with ]]> content
+ //
+ _writer.write(_indent);
+ _writer.write("<" + name + "><![CDATA[" + content
+ + "]]></" + name + ">" + _newline);
+ }
+
+ public void writeStartTag(String name, java.util.List attributes)
+ throws IOException
+ {
+ _writer.write(_indent);
+ _writer.write("<" + name);
+ writeAttributes(attributes);
+ _writer.write(">");
+ _writer.write(_newline);
+ increaseIndent();
+ }
+
+ public void writeStartTag(String name) throws IOException
+ {
+ writeStartTag(name, null);
+ }
+
+ public void writeEndTag(String name) throws IOException
+ {
+ decreaseIndent();
+ _writer.write(_indent);
+ _writer.write("</" + name + ">" + _newline);
+ }
+
+ public void close() throws IOException
+ {
+ _writer.close();
+ }
+
+ public void flush() throws IOException
+ {
+ _writer.flush();
+ }
+
+ private void writeAttributes(java.util.List attributes)
+ throws IOException
+ {
+ if(attributes != null)
+ {
+ java.util.Iterator p = attributes.iterator();
+ while(p.hasNext())
+ {
+ String[] pair = (String[])p.next();
+ _writer.write(" " + pair[0] + "=\"" + pair[1] + "\"");
+ }
+ }
+ }
+
+ private void increaseIndent()
+ {
+ _indent += " ";
+ }
+
+ private void decreaseIndent()
+ {
+ _indent = _indent.substring(3);
+ }
+
+ private Writer _writer;
+ private String _indent = "";
+ private static String _newline = System.getProperty("line.separator");
+}