diff options
Diffstat (limited to 'java/src/IceGridGUI')
95 files changed, 20118 insertions, 20118 deletions
diff --git a/java/src/IceGridGUI/AdapterObserverI.java b/java/src/IceGridGUI/AdapterObserverI.java index 929139bcde9..717a9d777fc 100644 --- a/java/src/IceGridGUI/AdapterObserverI.java +++ b/java/src/IceGridGUI/AdapterObserverI.java @@ -15,85 +15,85 @@ class AdapterObserverI extends _AdapterObserverDisp { AdapterObserverI(Coordinator coordinator) { - _coordinator = coordinator; - _trace = coordinator.traceObservers(); + _coordinator = coordinator; + _trace = coordinator.traceObservers(); } public synchronized void adapterInit(final AdapterInfo[] adapters, Ice.Current current) { - if(_trace) - { - if(adapters.length == 0) - { - _coordinator.traceObserver("adapterInit (no adapter)"); - } - else - { - String names = ""; - for(int i = 0; i < adapters.length; ++i) - { - names += " " + adapters[i].id; - } - - _coordinator.traceObserver("adapterInit for adapters" + names); - } - } + if(_trace) + { + if(adapters.length == 0) + { + _coordinator.traceObserver("adapterInit (no adapter)"); + } + else + { + String names = ""; + for(int i = 0; i < adapters.length; ++i) + { + names += " " + adapters[i].id; + } + + _coordinator.traceObserver("adapterInit for adapters" + names); + } + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.adapterInit(adapters); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.adapterInit(adapters); + } + }); } public void adapterAdded(final AdapterInfo info, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("adapterAdded for adapter " + info.id); - } + if(_trace) + { + _coordinator.traceObserver("adapterAdded for adapter " + info.id); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.adapterAdded(info); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.adapterAdded(info); + } + }); } public void adapterUpdated(final AdapterInfo info, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("adapterUpdated for adapter " + info.id); - } + if(_trace) + { + _coordinator.traceObserver("adapterUpdated for adapter " + info.id); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.adapterUpdated(info); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.adapterUpdated(info); + } + }); } public void adapterRemoved(final String id, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("adapterRemoved for adapter " + id); - } + if(_trace) + { + _coordinator.traceObserver("adapterRemoved for adapter " + id); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.adapterRemoved(id); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.adapterRemoved(id); + } + }); } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/AdminRouter.java b/java/src/IceGridGUI/AdminRouter.java index a163d742bbc..8e436b76e2d 100755 --- a/java/src/IceGridGUI/AdminRouter.java +++ b/java/src/IceGridGUI/AdminRouter.java @@ -13,42 +13,42 @@ import IceGrid.*; class AdminRouter extends Ice.Blobject { public boolean ice_invoke(byte[] inParams, - Ice.ByteSeqHolder outParams, - Ice.Current current) + Ice.ByteSeqHolder outParams, + Ice.Current current) { - if(_admin == null) - { - throw new Ice.ObjectNotExistException(current.id, - current.facet, - current.operation); - } - else if(current.operation.equals("ice_id") || - current.operation.equals("ice_ids") || - current.operation.equals("ice_isA") || - current.operation.equals("ice_ping") || - current.operation.equals("getDefaultApplicationDescriptor")) - { - - return _admin.ice_invoke(current.operation, - current.mode, - inParams, outParams, - current.ctx); - } - else - { - // - // Routing other operations could be a security risk - // - throw new Ice.OperationNotExistException(current.id, - current.facet, - current.operation); - } + if(_admin == null) + { + throw new Ice.ObjectNotExistException(current.id, + current.facet, + current.operation); + } + else if(current.operation.equals("ice_id") || + current.operation.equals("ice_ids") || + current.operation.equals("ice_isA") || + current.operation.equals("ice_ping") || + current.operation.equals("getDefaultApplicationDescriptor")) + { + + return _admin.ice_invoke(current.operation, + current.mode, + inParams, outParams, + current.ctx); + } + else + { + // + // Routing other operations could be a security risk + // + throw new Ice.OperationNotExistException(current.id, + current.facet, + current.operation); + } } AdminRouter(AdminPrx admin) { - _admin = admin; + _admin = admin; } private final AdminPrx _admin; diff --git a/java/src/IceGridGUI/Application/AbstractServerEditor.java b/java/src/IceGridGUI/Application/AbstractServerEditor.java index 2bead3feac9..f46a40838c3 100755 --- a/java/src/IceGridGUI/Application/AbstractServerEditor.java +++ b/java/src/IceGridGUI/Application/AbstractServerEditor.java @@ -33,148 +33,148 @@ abstract class AbstractServerEditor extends Editor protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Server Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Server Properties"); } protected boolean applyUpdate(boolean refresh) { - Root root = _target.getRoot(); - Server server = (Server)_target; + Root root = _target.getRoot(); + Server server = (Server)_target; - root.disableSelectionListener(); - try - { - if(_target.isEphemeral()) - { - Node node = (Node)_target.getParent(); - writeDescriptor(); + root.disableSelectionListener(); + try + { + if(_target.isEphemeral()) + { + Node node = (Node)_target.getParent(); + writeDescriptor(); - _target.destroy(); // just removes the child + _target.destroy(); // just removes the child - try - { - if(server instanceof PlainServer) - { - node.tryAdd((ServerDescriptor)server.getDescriptor(), true); - } - else - { - node.tryAdd((ServerInstanceDescriptor)server.getDescriptor(), true); - } - } - catch(UpdateFailedException e) - { - // - // Add back ephemeral child - // - try - { - node.insertServer(_target, true); - } - catch(UpdateFailedException die) - { - assert false; - } - root.setSelectedNode(_target); + try + { + if(server instanceof PlainServer) + { + node.tryAdd((ServerDescriptor)server.getDescriptor(), true); + } + else + { + node.tryAdd((ServerInstanceDescriptor)server.getDescriptor(), true); + } + } + catch(UpdateFailedException e) + { + // + // Add back ephemeral child + // + try + { + node.insertServer(_target, true); + } + catch(UpdateFailedException die) + { + assert false; + } + root.setSelectedNode(_target); - JOptionPane.showMessageDialog( - root.getCoordinator().getMainFrame(), - e.toString(), - "Apply failed", - JOptionPane.ERROR_MESSAGE); - return false; - } + JOptionPane.showMessageDialog( + root.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } - // - // Success - // - _target = (TreeNode)node.findChildWithDescriptor(server.getDescriptor()); - root.updated(); - - if(refresh) - { - root.setSelectedNode(_target); - } - - } - else if(isSimpleUpdate()) - { - writeDescriptor(); - root.updated(); - server.getEditable().markModified(); - } - else - { - // - // Save to be able to rollback - // - Object savedDescriptor = server.saveDescriptor(); - Node node = (Node)_target.getParent(); - writeDescriptor(); - - node.removeServer(_target); - - try - { - if(server instanceof PlainServer) - { - node.tryAdd((ServerDescriptor)server.getDescriptor(), false); - } - else - { - node.tryAdd((ServerInstanceDescriptor)server.getDescriptor(), false); - } - } - catch(UpdateFailedException e) - { - // - // Restore - // - try - { - node.insertServer(_target, true); - } - catch(UpdateFailedException die) - { - assert false; - } - server.restoreDescriptor(savedDescriptor); - root.setSelectedNode(_target); - - JOptionPane.showMessageDialog( - root.getCoordinator().getMainFrame(), - e.toString(), - "Apply failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - // - // Success - // - node.getEditable().removeElement(_target.getId(), server.getEditable(), - Server.class); // replaced by brand new Server - - _target = node.findChildWithDescriptor(server.getDescriptor()); - root.updated(); - if(refresh) - { - root.setSelectedNode(_target); - } - } - - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + // + // Success + // + _target = (TreeNode)node.findChildWithDescriptor(server.getDescriptor()); + root.updated(); + + if(refresh) + { + root.setSelectedNode(_target); + } + + } + else if(isSimpleUpdate()) + { + writeDescriptor(); + root.updated(); + server.getEditable().markModified(); + } + else + { + // + // Save to be able to rollback + // + Object savedDescriptor = server.saveDescriptor(); + Node node = (Node)_target.getParent(); + writeDescriptor(); + + node.removeServer(_target); + + try + { + if(server instanceof PlainServer) + { + node.tryAdd((ServerDescriptor)server.getDescriptor(), false); + } + else + { + node.tryAdd((ServerInstanceDescriptor)server.getDescriptor(), false); + } + } + catch(UpdateFailedException e) + { + // + // Restore + // + try + { + node.insertServer(_target, true); + } + catch(UpdateFailedException die) + { + assert false; + } + server.restoreDescriptor(savedDescriptor); + root.setSelectedNode(_target); + + JOptionPane.showMessageDialog( + root.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + // + // Success + // + node.getEditable().removeElement(_target.getId(), server.getEditable(), + Server.class); // replaced by brand new Server + + _target = node.findChildWithDescriptor(server.getDescriptor()); + root.updated(); + if(refresh) + { + root.setSelectedNode(_target); + } + } + + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } } diff --git a/java/src/IceGridGUI/Application/Adapter.java b/java/src/IceGridGUI/Application/Adapter.java index 9c3adc738ef..f12b90d139b 100755 --- a/java/src/IceGridGUI/Application/Adapter.java +++ b/java/src/IceGridGUI/Application/Adapter.java @@ -19,19 +19,19 @@ class Adapter extends TreeNode implements DescriptorHolder { static public AdapterDescriptor copyDescriptor(AdapterDescriptor d) { - return (AdapterDescriptor)d.clone(); + return (AdapterDescriptor)d.clone(); } static public java.util.List copyDescriptors(java.util.List descriptors) { - java.util.List copy = new java.util.LinkedList(); - java.util.Iterator p = descriptors.iterator(); - while(p.hasNext()) - { - copy.add(copyDescriptor((AdapterDescriptor)p.next())); - } - return copy; + java.util.List copy = new java.util.LinkedList(); + java.util.Iterator p = descriptors.iterator(); + while(p.hasNext()) + { + copy.add(copyDescriptor((AdapterDescriptor)p.next())); + } + return copy; } // @@ -39,194 +39,194 @@ class Adapter extends TreeNode implements DescriptorHolder // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - Object clipboard = getCoordinator().getClipboard(); - actions[PASTE] = clipboard != null && - (clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor); - - actions[DELETE] = true; - - if(!_ephemeral) - { - boolean[] parentActions = ((TreeNode)_parent).getAvailableActions(); - actions[SHOW_VARS] = parentActions[SHOW_VARS]; - actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS]; - } - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + Object clipboard = getCoordinator().getClipboard(); + actions[PASTE] = clipboard != null && + (clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor); + + actions[DELETE] = true; + + if(!_ephemeral) + { + boolean[] parentActions = ((TreeNode)_parent).getAvailableActions(); + actions[SHOW_VARS] = parentActions[SHOW_VARS]; + actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS]; + } + return actions; } public void copy() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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")); - } + 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); + 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; + if(_editor == null) + { + _editor = (AdapterEditor)getRoot().getEditor(AdapterEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new AdapterEditor(); + return new AdapterEditor(); } public void destroy() { - removeProperty("Ice.OA." + _descriptor.name + ".Endpoints"); - removeProperty("Ice.OA." + _descriptor.name + ".PublishedEndpoints"); + removeProperty("Ice.OA." + _descriptor.name + ".Endpoints"); + removeProperty("Ice.OA." + _descriptor.name + ".PublishedEndpoints"); - ((Communicator)_parent).getAdapters().destroyChild(this); + ((Communicator)_parent).getAdapters().destroyChild(this); } Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object saveDescriptor() { - return copyDescriptor(_descriptor); + 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.serverLifetime = ad.serverLifetime; - _descriptor.objects = ad.objects; + 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.serverLifetime = ad.serverLifetime; + _descriptor.objects = ad.objects; } Adapter(Communicator parent, String adapterName, AdapterDescriptor descriptor, - boolean ephemeral) + boolean ephemeral) { - super(parent, adapterName); - _descriptor = descriptor; - _ephemeral = ephemeral; + super(parent, adapterName); + _descriptor = descriptor; + _ephemeral = ephemeral; } void write(XMLWriter writer) throws java.io.IOException { - assert false; + assert false; } void write(XMLWriter writer, java.util.List properties) throws java.io.IOException { - if(!_ephemeral) - { - java.util.List attributes = new java.util.LinkedList(); - attributes.add(createAttribute("name", _descriptor.name)); - String oaPrefix = "Ice.OA." + _descriptor.name + "."; - - attributes.add(createAttribute("endpoints", getProperty(oaPrefix + "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.priority != null && _descriptor.priority.length() > 0) - { - attributes.add(createAttribute("priority", _descriptor.priority)); - } - if(!_descriptor.serverLifetime) - { - attributes.add(createAttribute("server-lifetime", "false")); - } - - if(_descriptor.description.length() == 0 - && _descriptor.objects.isEmpty() - && _descriptor.allocatables.isEmpty()) - { - writer.writeElement("adapter", attributes); - } - else - { - writer.writeStartTag("adapter", attributes); - - if(_descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.description); - } - writeObjects("object", writer, _descriptor.objects, properties); - writeObjects("allocatable", writer, _descriptor.allocatables, properties); - writer.writeEndTag("adapter"); - } - } + if(!_ephemeral) + { + java.util.List attributes = new java.util.LinkedList(); + attributes.add(createAttribute("name", _descriptor.name)); + String oaPrefix = "Ice.OA." + _descriptor.name + "."; + + attributes.add(createAttribute("endpoints", getProperty(oaPrefix + "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.priority != null && _descriptor.priority.length() > 0) + { + attributes.add(createAttribute("priority", _descriptor.priority)); + } + if(!_descriptor.serverLifetime) + { + attributes.add(createAttribute("server-lifetime", "false")); + } + + if(_descriptor.description.length() == 0 + && _descriptor.objects.isEmpty() + && _descriptor.allocatables.isEmpty()) + { + writer.writeElement("adapter", attributes); + } + else + { + writer.writeStartTag("adapter", attributes); + + if(_descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.description); + } + writeObjects("object", writer, _descriptor.objects, properties); + writeObjects("allocatable", writer, _descriptor.allocatables, properties); + writer.writeEndTag("adapter"); + } + } } String getProperty(String property) { - return ((Communicator)_parent).getProperty(property); + return ((Communicator)_parent).getProperty(property); } String lookupPropertyValue(String val) { - return ((Communicator)_parent).lookupPropertyValue(val); + return ((Communicator)_parent).lookupPropertyValue(val); } void setProperty(String property, String newValue) { - ((Communicator)_parent).setProperty(property, newValue); + ((Communicator)_parent).setProperty(property, newValue); } void removeProperty(String property) { - ((Communicator)_parent).removeProperty(property); + ((Communicator)_parent).removeProperty(property); } String getDefaultAdapterId() { - return getDefaultAdapterId(_id); + return getDefaultAdapterId(_id); } String getDefaultAdapterId(String name) - { - return (_parent instanceof Service || - _parent instanceof ServiceTemplate) ? - "${server}.${service}." + name: "${server}." + name; + { + return (_parent instanceof Service || + _parent instanceof ServiceTemplate) ? + "${server}.${service}." + name: "${server}." + name; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } private final boolean _ephemeral; diff --git a/java/src/IceGridGUI/Application/AdapterEditor.java b/java/src/IceGridGUI/Application/AdapterEditor.java index 97c6ba17bd1..5b8f8f85647 100755 --- a/java/src/IceGridGUI/Application/AdapterEditor.java +++ b/java/src/IceGridGUI/Application/AdapterEditor.java @@ -35,147 +35,147 @@ class AdapterEditor extends CommunicatorChildEditor { AdapterEditor() { - _objects = new MapField(this, "Identity", new String[]{"Type", "Property"}, true); - _allocatables = new MapField(this, "Identity", new String[]{"Type", "Property"}, true); - - // - // 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.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); - - 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 checkServerLifetime = - new AbstractAction("Server Lifetime") - { - public void actionPerformed(ActionEvent e) - { - updated(); - } - }; - _serverLifetime = new JCheckBox(checkServerLifetime); - _serverLifetime.setToolTipText( - "<html>Is the adapter lifetime the same as the server<br>" + + _objects = new MapField(this, "Identity", new String[]{"Type", "Property"}, true); + _allocatables = new MapField(this, "Identity", new String[]{"Type", "Property"}, true); + + // + // 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.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); + + 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 checkServerLifetime = + new AbstractAction("Server Lifetime") + { + public void actionPerformed(ActionEvent e) + { + updated(); + } + }; + _serverLifetime = new JCheckBox(checkServerLifetime); + _serverLifetime.setToolTipText( + "<html>Is the adapter lifetime the same as the server<br>" + "lifetime? The server is considered to be active<br>" + - "only if all the adapters with this attribute set<br>" + - "to true are 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().trim()); - refreshId(); - } - }); - - _name.setToolTipText( - "Identifies this object adapter within an Ice communicator"); - - _endpoints.getDocument().addDocumentListener(_updateListener); - _endpoints.setToolTipText( - "<html>The network interface(s) on which this object 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("Identities this object adapter within an IceGrid deployment"); - - JTextField replicaGroupIdTextField = (JTextField) - _replicaGroupId.getEditor().getEditorComponent(); - replicaGroupIdTextField.getDocument().addDocumentListener(_updateListener); - _replicaGroupId.setToolTipText("Select a replica group"); - - _priority.getDocument().addDocumentListener(_updateListener); - _priority.setToolTipText("The priority of this adapter; see the Ordered load-balancing " - + "policy in Replica Groups"); - - - JTextField publishedEndpointsTextField = (JTextField) - _publishedEndpoints.getEditor().getEditorComponent(); - publishedEndpointsTextField.getDocument().addDocumentListener(_updateListener); - _publishedEndpoints.setToolTipText( - "Endpoints registered with the IceGrid Registry during the activation of this adapter."); + "only if all the adapters with this attribute set<br>" + + "to true are 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().trim()); + refreshId(); + } + }); + + _name.setToolTipText( + "Identifies this object adapter within an Ice communicator"); + + _endpoints.getDocument().addDocumentListener(_updateListener); + _endpoints.setToolTipText( + "<html>The network interface(s) on which this object 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("Identities this object adapter within an IceGrid deployment"); + + JTextField replicaGroupIdTextField = (JTextField) + _replicaGroupId.getEditor().getEditorComponent(); + replicaGroupIdTextField.getDocument().addDocumentListener(_updateListener); + _replicaGroupId.setToolTipText("Select a replica group"); + + _priority.getDocument().addDocumentListener(_updateListener); + _priority.setToolTipText("The priority of this adapter; see the Ordered load-balancing " + + "policy in Replica Groups"); + + + JTextField publishedEndpointsTextField = (JTextField) + _publishedEndpoints.getEditor().getEditorComponent(); + publishedEndpointsTextField.getDocument().addDocumentListener(_updateListener); + _publishedEndpoints.setToolTipText( + "Endpoints registered with the IceGrid Registry during the activation of this adapter."); } @@ -185,403 +185,403 @@ class AdapterEditor extends CommunicatorChildEditor void writeDescriptor() { - AdapterDescriptor descriptor = - (AdapterDescriptor)getAdapter().getDescriptor(); - descriptor.name = _name.getText().trim(); - descriptor.description = _description.getText(); - descriptor.id = getIdAsString(); - descriptor.replicaGroupId = getReplicaGroupIdAsString(); - descriptor.priority = _priority.getText().trim(); - descriptor.registerProcess = _registerProcess.isSelected(); - descriptor.serverLifetime = _serverLifetime.isSelected(); - descriptor.objects = mapToObjectDescriptorSeq(_objects.get()); - descriptor.allocatables = mapToObjectDescriptorSeq(_allocatables.get()); - } + AdapterDescriptor descriptor = + (AdapterDescriptor)getAdapter().getDescriptor(); + descriptor.name = _name.getText().trim(); + descriptor.description = _description.getText(); + descriptor.id = getIdAsString(); + descriptor.replicaGroupId = getReplicaGroupIdAsString(); + descriptor.priority = _priority.getText().trim(); + descriptor.registerProcess = _registerProcess.isSelected(); + descriptor.serverLifetime = _serverLifetime.isSelected(); + descriptor.objects = mapToObjectDescriptorSeq(_objects.get()); + descriptor.allocatables = mapToObjectDescriptorSeq(_allocatables.get()); + } boolean isSimpleUpdate() { - AdapterDescriptor descriptor = - (AdapterDescriptor)getAdapter().getDescriptor(); + AdapterDescriptor descriptor = + (AdapterDescriptor)getAdapter().getDescriptor(); - return descriptor.name.equals(_name.getText().trim()); + return descriptor.name.equals(_name.getText().trim()); } Communicator.ChildList getChildList() { - return ((Communicator)_target.getParent()).getAdapters(); + 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("Priority"); - builder.append(_priority, 3); - builder.nextLine(); - - builder.append("Endpoints" ); - builder.append(_endpoints, 3); - builder.nextLine(); - - builder.append("Published Endpoints"); - builder.append(_publishedEndpoints, 3); - builder.nextLine(); - - builder.append("", _registerProcess); - builder.nextLine(); - builder.append("", _serverLifetime); - builder.nextLine(); - - builder.append("Well-known Objects"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_objects); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); - - builder.append("Allocatable Objects"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_allocatables); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + 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("Priority"); + builder.append(_priority, 3); + builder.nextLine(); + + builder.append("Endpoints" ); + builder.append(_endpoints, 3); + builder.nextLine(); + + builder.append("Published Endpoints"); + builder.append(_publishedEndpoints, 3); + builder.nextLine(); + + builder.append("", _registerProcess); + builder.nextLine(); + builder.append("", _serverLifetime); + builder.nextLine(); + + builder.append("Well-known Objects"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_objects); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); + + builder.append("Allocatable Objects"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_allocatables); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Adapter Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Adapter Properties"); } void postUpdate() { - // - // Change enclosing properties after successful update - // - String name = _name.getText().trim(); - Adapter adapter = getAdapter(); - if(!name.equals(_oldName)) - { - adapter.removeProperty("Ice.OA." + _oldName + ".Endpoints"); - adapter.removeProperty("Ice.OA." + _oldName + ".PublishedEndpoints"); - _oldName = name; - } - - adapter.setProperty("Ice.OA." + name + ".Endpoints", _endpoints.getText().trim()); - - Object published = _publishedEndpoints.getSelectedItem(); - if(published == PUBLISH_ACTUAL) - { - adapter.removeProperty("Ice.OA." + name + ".PublishedEndpoints"); - } - else - { - adapter.setProperty("Ice.OA." + name + ".PublishedEndpoints", - published.toString().trim()); - - } - - // - // Set all objects and allocatables properties - // - java.util.Map map = _objects.get(); - java.util.Iterator p = map.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String key = (String)entry.getKey(); - String[] value = (String[]) entry.getValue(); - if(!value[1].equals("")) - { - adapter.setProperty(value[1], key); - } - } - - map = _allocatables.get(); - p = map.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String key = (String)entry.getKey(); - String[] value = (String[]) entry.getValue(); - if(!value[1].equals("")) - { - adapter.setProperty(value[1], key); - } - } + // + // Change enclosing properties after successful update + // + String name = _name.getText().trim(); + Adapter adapter = getAdapter(); + if(!name.equals(_oldName)) + { + adapter.removeProperty("Ice.OA." + _oldName + ".Endpoints"); + adapter.removeProperty("Ice.OA." + _oldName + ".PublishedEndpoints"); + _oldName = name; + } + + adapter.setProperty("Ice.OA." + name + ".Endpoints", _endpoints.getText().trim()); + + Object published = _publishedEndpoints.getSelectedItem(); + if(published == PUBLISH_ACTUAL) + { + adapter.removeProperty("Ice.OA." + name + ".PublishedEndpoints"); + } + else + { + adapter.setProperty("Ice.OA." + name + ".PublishedEndpoints", + published.toString().trim()); + + } + + // + // Set all objects and allocatables properties + // + java.util.Map map = _objects.get(); + java.util.Iterator p = map.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String key = (String)entry.getKey(); + String[] value = (String[]) entry.getValue(); + if(!value[1].equals("")) + { + adapter.setProperty(value[1], key); + } + } + + map = _allocatables.get(); + p = map.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String key = (String)entry.getKey(); + String[] value = (String[]) entry.getValue(); + if(!value[1].equals("")) + { + adapter.setProperty(value[1], key); + } + } } private void setId(String id) { - if(id.equals(_defaultAdapterId)) - { - _id.setSelectedItem(DEFAULT_ADAPTER_ID); - } - else - { - _id.setSelectedItem(id); - } + 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[] - {DEFAULT_ADAPTER_ID})); - _id.setSelectedItem(id); + Object id = _id.getSelectedItem(); + _id.setModel(new DefaultComboBoxModel(new Object[] + {DEFAULT_ADAPTER_ID})); + _id.setSelectedItem(id); } private String getIdAsString() { - Object obj = _id.getSelectedItem(); - return obj.toString().trim(); + Object obj = _id.getSelectedItem(); + return obj.toString().trim(); } 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); - } - } + 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().trim(); - } + Object obj = _replicaGroupId.getSelectedItem(); + if(obj == NOT_REPLICATED) + { + return ""; + } + else + { + return obj.toString().trim(); + } } protected boolean validate() { - return check(new String[]{ - "Adapter Name", _name.getText().trim(), - "Adapter ID", getIdAsString(), - "Endpoints", _endpoints.getText().trim() - }); + return check(new String[]{ + "Adapter Name", _name.getText().trim(), + "Adapter ID", getIdAsString(), + "Endpoints", _endpoints.getText().trim() + }); } 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 = resolver == null; - - _oldName = descriptor.name; - - _name.setText(Utils.substitute(descriptor.name, resolver)); - _name.setEditable(isEditable); - - String oaPrefix = "Ice.OA." + descriptor.name + "."; - - _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().trim()); - enabled = (replicaGroups.findChild(replicaGroupId) != null); - } - } - _replicaGroupButton.setEnabled(enabled); - } - } - }); - - setReplicaGroupId(Utils.substitute(descriptor.replicaGroupId, resolver)); - - _replicaGroupId.setEnabled(isEditable); - _replicaGroupId.setEditable(isEditable); - - _priority.setText(Utils.substitute(descriptor.priority, resolver)); - _priority.setEditable(isEditable); - - if(adapter.isEphemeral()) - { - _endpoints.setText("default"); - } - else - { - _endpoints.setText(Utils.substitute(adapter.getProperty(oaPrefix + "Endpoints"), resolver)); - } - _endpoints.setEditable(isEditable); - - _publishedEndpoints.setEnabled(true); - _publishedEndpoints.setEditable(true); - String published = - Utils.substitute(adapter.getProperty(oaPrefix + "PublishedEndpoints"), resolver); - if(published == null || published.equals("")) - { - _publishedEndpoints.setSelectedItem(PUBLISH_ACTUAL); - } - else - { - _publishedEndpoints.setSelectedItem(published); - } - _publishedEndpoints.setEnabled(isEditable); - _publishedEndpoints.setEditable(isEditable); - - // - // Objects - // - _objects.set(objectDescriptorSeqToMap(descriptor.objects), resolver, isEditable); - _allocatables.set(objectDescriptorSeqToMap(descriptor.allocatables), resolver, isEditable); - - _registerProcess.setSelected(descriptor.registerProcess); - _registerProcess.setEnabled(isEditable); - - _serverLifetime.setSelected(descriptor.serverLifetime); - _serverLifetime.setEnabled(isEditable); - - _applyButton.setEnabled(adapter.isEphemeral()); - _discardButton.setEnabled(adapter.isEphemeral()); - detectUpdates(true); + detectUpdates(false); + _target = adapter; + + AdapterDescriptor descriptor = (AdapterDescriptor)adapter.getDescriptor(); + + final Utils.Resolver resolver = adapter.getCoordinator().substitute() ? + adapter.getResolver() : null; + + boolean isEditable = resolver == null; + + _oldName = descriptor.name; + + _name.setText(Utils.substitute(descriptor.name, resolver)); + _name.setEditable(isEditable); + + String oaPrefix = "Ice.OA." + descriptor.name + "."; + + _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().trim()); + enabled = (replicaGroups.findChild(replicaGroupId) != null); + } + } + _replicaGroupButton.setEnabled(enabled); + } + } + }); + + setReplicaGroupId(Utils.substitute(descriptor.replicaGroupId, resolver)); + + _replicaGroupId.setEnabled(isEditable); + _replicaGroupId.setEditable(isEditable); + + _priority.setText(Utils.substitute(descriptor.priority, resolver)); + _priority.setEditable(isEditable); + + if(adapter.isEphemeral()) + { + _endpoints.setText("default"); + } + else + { + _endpoints.setText(Utils.substitute(adapter.getProperty(oaPrefix + "Endpoints"), resolver)); + } + _endpoints.setEditable(isEditable); + + _publishedEndpoints.setEnabled(true); + _publishedEndpoints.setEditable(true); + String published = + Utils.substitute(adapter.getProperty(oaPrefix + "PublishedEndpoints"), resolver); + if(published == null || published.equals("")) + { + _publishedEndpoints.setSelectedItem(PUBLISH_ACTUAL); + } + else + { + _publishedEndpoints.setSelectedItem(published); + } + _publishedEndpoints.setEnabled(isEditable); + _publishedEndpoints.setEditable(isEditable); + + // + // Objects + // + _objects.set(objectDescriptorSeqToMap(descriptor.objects), resolver, isEditable); + _allocatables.set(objectDescriptorSeqToMap(descriptor.allocatables), resolver, isEditable); + + _registerProcess.setSelected(descriptor.registerProcess); + _registerProcess.setEnabled(isEditable); + + _serverLifetime.setSelected(descriptor.serverLifetime); + _serverLifetime.setEnabled(isEditable); + + _applyButton.setEnabled(adapter.isEphemeral()); + _discardButton.setEnabled(adapter.isEphemeral()); + detectUpdates(true); } Adapter getAdapter() { - return (Adapter)_target; + return (Adapter)_target; } private java.util.Map objectDescriptorSeqToMap(java.util.List objects) { - java.util.Map result = new java.util.TreeMap(); - java.util.Iterator p = objects.iterator(); - while(p.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)p.next(); - String k = Ice.Util.identityToString(od.id); - - result.put(k, new String[]{od.type, getAdapter().lookupPropertyValue(k)}); - } - return result; + java.util.Map result = new java.util.TreeMap(); + java.util.Iterator p = objects.iterator(); + while(p.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)p.next(); + String k = Ice.Util.identityToString(od.id); + + result.put(k, new String[]{od.type, getAdapter().lookupPropertyValue(k)}); + } + return result; } private 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[] val = (String[])entry.getValue(); - result.add(new ObjectDescriptor(id, val[0])); - } - return result; + 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[] val = (String[])entry.getValue(); + result.add(new ObjectDescriptor(id, val[0])); + } + return result; } private String _defaultAdapterId = ""; private final Object DEFAULT_ADAPTER_ID = new Object() - { - public String toString() - { - return _defaultAdapterId; - } - }; + { + public String toString() + { + return _defaultAdapterId; + } + }; private String _oldName; @@ -596,7 +596,7 @@ class AdapterEditor extends CommunicatorChildEditor private JTextField _endpoints = new JTextField(20); private JComboBox _publishedEndpoints = new JComboBox( - new Object[]{PUBLISH_ACTUAL}); + new Object[]{PUBLISH_ACTUAL}); private JTextField _currentStatus = new JTextField(20); private JTextField _currentEndpoints = new JTextField(20); @@ -608,18 +608,18 @@ class AdapterEditor extends CommunicatorChildEditor private MapField _allocatables; static private final Object PUBLISH_ACTUAL = new Object() - { - public String toString() - { - return "Actual endpoints"; - } - }; + { + public String toString() + { + return "Actual endpoints"; + } + }; static private final Object NOT_REPLICATED = new Object() - { - public String toString() - { - return "Does not belong to a replica group"; - } - }; + { + public String toString() + { + return "Does not belong to a replica group"; + } + }; } diff --git a/java/src/IceGridGUI/Application/ApplicationEditor.java b/java/src/IceGridGUI/Application/ApplicationEditor.java index 6a7c9858767..006cbad1270 100755 --- a/java/src/IceGridGUI/Application/ApplicationEditor.java +++ b/java/src/IceGridGUI/Application/ApplicationEditor.java @@ -30,231 +30,231 @@ class ApplicationEditor extends Editor { protected boolean applyUpdate(boolean refresh) { - Root root = (Root)_target; - MainPane mainPane = _target.getCoordinator().getMainPane(); + Root root = (Root)_target; + MainPane mainPane = _target.getCoordinator().getMainPane(); - root.disableSelectionListener(); - try - { - if(isSimpleUpdate()) - { - 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 false; - } - // - // Success - // - root.updated(); - root.getEditable().markModified(); - - if(!savedDescriptor.name.equals(root.getId())) - { - mainPane.resetTitle(root); - root.getTreeModel().nodeChanged(root); - } - } - - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + root.disableSelectionListener(); + try + { + if(isSimpleUpdate()) + { + 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 false; + } + // + // Success + // + root.updated(); + root.getEditable().markModified(); + + if(!savedDescriptor.name.equals(root.getId())) + { + mainPane.resetTitle(root); + root.getTreeModel().nodeChanged(root); + } + } + + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } ApplicationEditor() { - _name.getDocument().addDocumentListener(_updateListener); - _description.getDocument().addDocumentListener(_updateListener); - - // - // Variables - // - _variables = new MapField(this, "Name", "Value", false); + _name.getDocument().addDocumentListener(_updateListener); + _description.getDocument().addDocumentListener(_updateListener); + + // + // Variables + // + _variables = new MapField(this, "Name", "Value", false); - // - // Distrib - // - _distrib = new JComboBox(new Object[]{NO_DISTRIB, DEFAULT_DISTRIB}); - _distrib.setEditable(true); - _distrib.setToolTipText("The proxy to the IcePatch2 server holding your files"); + // + // Distrib + // + _distrib = new JComboBox(new Object[]{NO_DISTRIB, DEFAULT_DISTRIB}); + _distrib.setEditable(true); + _distrib.setToolTipText("The proxy to the IcePatch2 server holding your files"); - JTextField distribTextField = (JTextField) - _distrib.getEditor().getEditorComponent(); - distribTextField.getDocument().addDocumentListener( - _updateListener); + JTextField distribTextField = (JTextField) + _distrib.getEditor().getEditorComponent(); + distribTextField.getDocument().addDocumentListener( + _updateListener); - _distribDirs.getDocument().addDocumentListener(_updateListener); - _distribDirs.setToolTipText( - "<html>Include only these directories when patching.<br>" - + "Use whitespace as separator; use double-quotes around directories containing whitespaces</html>"); + _distribDirs.getDocument().addDocumentListener(_updateListener); + _distribDirs.setToolTipText( + "<html>Include only these directories when patching.<br>" + + "Use whitespace as separator; use double-quotes around directories containing whitespaces</html>"); } protected void appendProperties(DefaultFormBuilder builder) { - builder.append("Name"); - builder.append(_name, 3); + builder.append("Name"); + builder.append(_name, 3); - 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("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"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_variables); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + builder.append("Variables"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_variables); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); - JComponent c = builder.appendSeparator("Distribution"); - c.setToolTipText("Files shared by all servers in your application"); - builder.append("IcePatch2 Proxy"); - builder.append(_distrib, 3); - builder.nextLine(); - builder.append("Directories"); - builder.append(_distribDirs, 3); - builder.nextLine(); + JComponent c = builder.appendSeparator("Distribution"); + c.setToolTipText("Files shared by all servers in your application"); + builder.append("IcePatch2 Proxy"); + builder.append(_distrib, 3); + builder.nextLine(); + builder.append("Directories"); + builder.append(_distribDirs, 3); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Application Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Application Properties"); } boolean isSimpleUpdate() { - ApplicationDescriptor descriptor = (ApplicationDescriptor)_target.getDescriptor(); - return descriptor.name.equals(_name.getText().trim()) - && _variables.get().equals(descriptor.variables); + ApplicationDescriptor descriptor = (ApplicationDescriptor)_target.getDescriptor(); + return descriptor.name.equals(_name.getText().trim()) + && _variables.get().equals(descriptor.variables); } void writeDescriptor() { - ApplicationDescriptor descriptor = (ApplicationDescriptor)_target.getDescriptor(); - descriptor.name = _name.getText().trim(); - descriptor.variables = _variables.get(); - descriptor.description = _description.getText(); + ApplicationDescriptor descriptor = (ApplicationDescriptor)_target.getDescriptor(); + descriptor.name = _name.getText().trim(); + descriptor.variables = _variables.get(); + descriptor.description = _description.getText(); - if(_distrib.getSelectedItem() == NO_DISTRIB) - { - descriptor.distrib.icepatch = ""; - } - else - { - descriptor.distrib.icepatch = _distrib.getSelectedItem().toString().trim(); - } - descriptor.distrib.directories = _distribDirs.getList(); - } + if(_distrib.getSelectedItem() == NO_DISTRIB) + { + descriptor.distrib.icepatch = ""; + } + else + { + descriptor.distrib.icepatch = _distrib.getSelectedItem().toString().trim(); + } + descriptor.distrib.directories = _distribDirs.getList(); + } protected boolean validate() { - return check(new String[]{"Name", _name.getText().trim()}); + return check(new String[]{"Name", _name.getText().trim()}); } void show(Root root) { - detectUpdates(false); - _target = root; - - Utils.Resolver resolver = getDetailResolver(); - boolean isEditable = (resolver == null); + detectUpdates(false); + _target = root; + + Utils.Resolver resolver = getDetailResolver(); + boolean isEditable = (resolver == null); - ApplicationDescriptor descriptor = - (ApplicationDescriptor)root.getDescriptor(); + ApplicationDescriptor descriptor = + (ApplicationDescriptor)root.getDescriptor(); - _name.setText(descriptor.name); - _name.setEditable(!root.isLive() && isEditable); + _name.setText(descriptor.name); + _name.setEditable(!root.isLive() && isEditable); - _description.setText( - Utils.substitute(descriptor.description, resolver)); - _description.setEditable(isEditable); - _description.setOpaque(isEditable); - _description.setToolTipText("An optional description for this application"); - - _variables.set(descriptor.variables, resolver, isEditable); - - _distrib.setEnabled(true); - _distrib.setEditable(true); - String icepatch = - Utils.substitute(descriptor.distrib.icepatch, resolver); - if(icepatch.equals("")) - { - _distrib.setSelectedItem(NO_DISTRIB); - } - else - { - _distrib.setSelectedItem(icepatch); - } - _distrib.setEnabled(isEditable); - _distrib.setEditable(isEditable); + _description.setText( + Utils.substitute(descriptor.description, resolver)); + _description.setEditable(isEditable); + _description.setOpaque(isEditable); + _description.setToolTipText("An optional description for this application"); + + _variables.set(descriptor.variables, resolver, isEditable); + + _distrib.setEnabled(true); + _distrib.setEditable(true); + String icepatch = + Utils.substitute(descriptor.distrib.icepatch, resolver); + if(icepatch.equals("")) + { + _distrib.setSelectedItem(NO_DISTRIB); + } + else + { + _distrib.setSelectedItem(icepatch); + } + _distrib.setEnabled(isEditable); + _distrib.setEditable(isEditable); - _distribDirs.setList(descriptor.distrib.directories, resolver); - _distribDirs.setEditable(isEditable); + _distribDirs.setList(descriptor.distrib.directories, resolver); + _distribDirs.setEditable(isEditable); - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - detectUpdates(true); + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + detectUpdates(true); } Utils.Resolver getDetailResolver() { - if(_target.getCoordinator().substitute()) - { - return _target.getResolver(); - } - else - { - return null; - } + if(_target.getCoordinator().substitute()) + { + return _target.getResolver(); + } + else + { + return null; + } } static private final Object NO_DISTRIB = new Object() - { - public String toString() - { - return "None selected"; - } - }; + { + public String toString() + { + return "None selected"; + } + }; static private final String DEFAULT_DISTRIB = "${application}.IcePatch2/server"; private JTextField _name = new JTextField(20); diff --git a/java/src/IceGridGUI/Application/Communicator.java b/java/src/IceGridGUI/Application/Communicator.java index 4669e7385e4..dd13244ebf3 100755 --- a/java/src/IceGridGUI/Application/Communicator.java +++ b/java/src/IceGridGUI/Application/Communicator.java @@ -23,114 +23,114 @@ 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(); - }; + 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; + 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); + 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; + 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; + 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; + for(int i = 0; i < _childListArray.length; ++i) + { + if(!_childListArray[i].isEmpty()) + { + return false; + } + } + return true; } // @@ -139,44 +139,44 @@ abstract class Communicator extends TreeNode implements DescriptorHolder public void newAdapter() { - _adapters.newChild(); + _adapters.newChild(); } public void newDbEnv() { - _dbEnvs.newChild(); + _dbEnvs.newChild(); } public void newService() { - _services.newChild(); + _services.newChild(); } public void newServiceFromTemplate() { - _services.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(ServiceInstance.copyDescriptor(d)); - } - else - { - ((TreeNode)_parent).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(ServiceInstance.copyDescriptor(d)); + } + else + { + ((TreeNode)_parent).paste(); + } } abstract CommunicatorDescriptor getCommunicatorDescriptor(); @@ -188,736 +188,736 @@ abstract class Communicator extends TreeNode implements DescriptorHolder // java.util.List findInstances() { - java.util.List result = new java.util.LinkedList(); - result.add(this); - return result; + java.util.List result = new java.util.LinkedList(); + result.add(this); + return result; } 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; - } + 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; + return false; } protected Communicator(TreeNode parent, String id) { - super(parent, id); + super(parent, id); } abstract class ChildList { - abstract TreeNode createChild(Object descriptor) throws UpdateFailedException; - 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(); - getRoot().updated(); - removeChild(child); - } - } - - void addDescriptor(Object descriptor) - { - _descriptors.add(descriptor); - } - - 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; - } - } - } - - boolean canMove(TreeNode child, boolean up) - { - int i = _children.indexOf(child); - assert i != -1; - return (up && i > 0) || (!up && i < _children.size() - 1); - } - - void tryAdd(Object descriptor) throws UpdateFailedException - { - addDescriptor(descriptor); - try - { - addNewChild(descriptor); - } - catch(UpdateFailedException e) - { - removeDescriptor(descriptor); - throw e; - } - getEnclosingEditable().markModified(); - } - - void tryUpdate(TreeNode child) throws UpdateFailedException - { - // - // Child is an Adapter or DbEnv - // - assert _sorted; - - Object descriptor = child.getDescriptor(); - removeChild(child); - try - { - addNewChild(descriptor); - } - catch(UpdateFailedException e) - { - addChild(child, true); - 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; + abstract TreeNode createChild(Object descriptor) throws UpdateFailedException; + 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(); + getRoot().updated(); + removeChild(child); + } + } + + void addDescriptor(Object descriptor) + { + _descriptors.add(descriptor); + } + + 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; + } + } + } + + boolean canMove(TreeNode child, boolean up) + { + int i = _children.indexOf(child); + assert i != -1; + return (up && i > 0) || (!up && i < _children.size() - 1); + } + + void tryAdd(Object descriptor) throws UpdateFailedException + { + addDescriptor(descriptor); + try + { + addNewChild(descriptor); + } + catch(UpdateFailedException e) + { + removeDescriptor(descriptor); + throw e; + } + getEnclosingEditable().markModified(); + } + + void tryUpdate(TreeNode child) throws UpdateFailedException + { + // + // Child is an Adapter or DbEnv + // + assert _sorted; + + Object descriptor = child.getDescriptor(); + removeChild(child); + try + { + addNewChild(descriptor); + } + catch(UpdateFailedException e) + { + addChild(child, true); + 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 write(XMLWriter writer, java.util.List props) throws java.io.IOException - { - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Adapter child = (Adapter)p.next(); - child.write(writer, props); - } - } - - void newChild() - { - AdapterDescriptor descriptor = new AdapterDescriptor( - "NewAdapter", - "", - null, - "", - "", - false, - true, - new java.util.LinkedList(), - new java.util.LinkedList() - ); + Adapters() + { + super(true); + } + + void write(XMLWriter writer, java.util.List props) throws java.io.IOException + { + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Adapter child = (Adapter)p.next(); + child.write(writer, props); + } + } + + void newChild() + { + AdapterDescriptor descriptor = new AdapterDescriptor( + "NewAdapter", + "", + null, + "", + "", + false, + true, + new java.util.LinkedList(), + new java.util.LinkedList() + ); - newAdapter(descriptor); - } - - TreeNode createChild(Object descriptor) - { - AdapterDescriptor ad = (AdapterDescriptor)descriptor; - String name = Utils.substitute(ad.name, getResolver()); - return new Adapter(Communicator.this, name, ad, false); - } - - 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); - } + newAdapter(descriptor); + } + + TreeNode createChild(Object descriptor) + { + AdapterDescriptor ad = (AdapterDescriptor)descriptor; + String name = Utils.substitute(ad.name, getResolver()); + return new Adapter(Communicator.this, name, ad, false); + } + + 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 = Utils.substitute(dd.name, getResolver()); - return new DbEnv(Communicator.this, name, dd, false); - } - - 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); - } + 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 = Utils.substitute(dd.name, getResolver()); + return new DbEnv(Communicator.this, name, dd, false); + } + + 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 serviceDescriptor = - new ServiceDescriptor(new java.util.LinkedList(), - new PropertySetDescriptor(new String[0], new java.util.LinkedList()), - new java.util.LinkedList(), - new String[0], - "", - "NewService", - ""); - - ServiceInstanceDescriptor descriptor = - new ServiceInstanceDescriptor("", - new java.util.HashMap(), - serviceDescriptor, - new PropertySetDescriptor(new String[0], new java.util.LinkedList())); - - newService(descriptor); - } - - void newServiceFromTemplate() - { - ServiceInstanceDescriptor descriptor = - new ServiceInstanceDescriptor("", - new java.util.HashMap(), - null, - new PropertySetDescriptor(new String[0], new java.util.LinkedList())); - newService(descriptor); - } - - void move(TreeNode child, boolean up) - { - int index = getIndex(child); - int listIndex = _children.indexOf(child); - - Object descriptor = child.getDescriptor(); - - getEnclosingEditable().markModified(); - getRoot().updated(); - - _descriptors.remove(listIndex); - if(up) - { - _descriptors.add(listIndex - 1, descriptor); - } - else - { - _descriptors.add(listIndex + 1, descriptor); - } - - _children.remove(listIndex); - 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}); - - } - getRoot().setSelectedNode(child); - getCoordinator().showActions(child); - } - - TreeNode createChild(Object o) throws UpdateFailedException - { - ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)o; - - if(descriptor.descriptor == null) - { - TemplateDescriptor templateDescriptor - = getRoot().findServiceTemplateDescriptor(descriptor.template); - - assert templateDescriptor != null; - - String serviceName = null; - String displayString = null; - Utils.Resolver serviceResolver = null; - - if(Communicator.this instanceof PlainServer) - { - serviceResolver = new Utils.Resolver(getResolver(), - descriptor.parameterValues, - templateDescriptor.parameterDefaults); - - ServiceDescriptor serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor; - assert serviceDescriptor != null; - - serviceName = serviceResolver.substitute(serviceDescriptor.name); - serviceResolver.put("service", serviceName); - displayString = serviceName + ": " + descriptor.template + "<>"; - } - else - { - // - // Note: service names don't have to be unique - // - serviceName = descriptor.template + "<>"; - } - - return new ServiceInstance(Communicator.this, - serviceName, - displayString, - descriptor, - serviceResolver); - } - else - { - ServiceDescriptor serviceDescriptor = descriptor.descriptor; - - String serviceName = null; - Utils.Resolver serviceResolver = null; - - if(Communicator.this instanceof PlainServer) - { - serviceResolver = new Utils.Resolver(getResolver()); - serviceName = serviceResolver.substitute(serviceDescriptor.name); - serviceResolver.put("service", serviceName); - } - else - { - serviceName = serviceDescriptor.name; - } - - return new PlainService(Communicator.this, - serviceName, - descriptor, - serviceResolver); - } - } - - void tryUpdate(TreeNode child) throws UpdateFailedException - { - // - // Rebuilding a Service is quite different since the creation of a service can - // trigger an UpdateFailedException - // - Object descriptor = child.getDescriptor(); - int listIndex = _children.indexOf(child); - assert listIndex != -1; - - TreeNode newChild = createChild(descriptor); - _children.set(listIndex, newChild); - getRoot().getTreeModel().nodeChanged(newChild); - - getEnclosingEditable().markModified(); - } - - private void newService(ServiceInstanceDescriptor descriptor) - { - if(descriptor.descriptor == null) - { - String name = makeNewChildId("NewService"); - - // - // Make sure descriptor.template points to a real template - // - ServiceTemplate t = getRoot().findServiceTemplate(descriptor.template); - - if(t == null) - { - if(getRoot().getServiceTemplates().getChildCount() == 0) - { - 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 - { - t = (ServiceTemplate)getRoot().getServiceTemplates().getChildAt(0); - 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); - - - ServiceInstance service = new ServiceInstance(Communicator.this, name, descriptor); - try - { - addChild(service, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(service); - } - else - { - descriptor.descriptor.name = makeNewChildId(descriptor.descriptor.name); - - PlainService service = new PlainService(Communicator.this, descriptor); - try - { - addChild(service, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(service); - } - } + Services() + { + super(false); + } + + void newChild() + { + ServiceDescriptor serviceDescriptor = + new ServiceDescriptor(new java.util.LinkedList(), + new PropertySetDescriptor(new String[0], new java.util.LinkedList()), + new java.util.LinkedList(), + new String[0], + "", + "NewService", + ""); + + ServiceInstanceDescriptor descriptor = + new ServiceInstanceDescriptor("", + new java.util.HashMap(), + serviceDescriptor, + new PropertySetDescriptor(new String[0], new java.util.LinkedList())); + + newService(descriptor); + } + + void newServiceFromTemplate() + { + ServiceInstanceDescriptor descriptor = + new ServiceInstanceDescriptor("", + new java.util.HashMap(), + null, + new PropertySetDescriptor(new String[0], new java.util.LinkedList())); + newService(descriptor); + } + + void move(TreeNode child, boolean up) + { + int index = getIndex(child); + int listIndex = _children.indexOf(child); + + Object descriptor = child.getDescriptor(); + + getEnclosingEditable().markModified(); + getRoot().updated(); + + _descriptors.remove(listIndex); + if(up) + { + _descriptors.add(listIndex - 1, descriptor); + } + else + { + _descriptors.add(listIndex + 1, descriptor); + } + + _children.remove(listIndex); + 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}); + + } + getRoot().setSelectedNode(child); + getCoordinator().showActions(child); + } + + TreeNode createChild(Object o) throws UpdateFailedException + { + ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)o; + + if(descriptor.descriptor == null) + { + TemplateDescriptor templateDescriptor + = getRoot().findServiceTemplateDescriptor(descriptor.template); + + assert templateDescriptor != null; + + String serviceName = null; + String displayString = null; + Utils.Resolver serviceResolver = null; + + if(Communicator.this instanceof PlainServer) + { + serviceResolver = new Utils.Resolver(getResolver(), + descriptor.parameterValues, + templateDescriptor.parameterDefaults); + + ServiceDescriptor serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor; + assert serviceDescriptor != null; + + serviceName = serviceResolver.substitute(serviceDescriptor.name); + serviceResolver.put("service", serviceName); + displayString = serviceName + ": " + descriptor.template + "<>"; + } + else + { + // + // Note: service names don't have to be unique + // + serviceName = descriptor.template + "<>"; + } + + return new ServiceInstance(Communicator.this, + serviceName, + displayString, + descriptor, + serviceResolver); + } + else + { + ServiceDescriptor serviceDescriptor = descriptor.descriptor; + + String serviceName = null; + Utils.Resolver serviceResolver = null; + + if(Communicator.this instanceof PlainServer) + { + serviceResolver = new Utils.Resolver(getResolver()); + serviceName = serviceResolver.substitute(serviceDescriptor.name); + serviceResolver.put("service", serviceName); + } + else + { + serviceName = serviceDescriptor.name; + } + + return new PlainService(Communicator.this, + serviceName, + descriptor, + serviceResolver); + } + } + + void tryUpdate(TreeNode child) throws UpdateFailedException + { + // + // Rebuilding a Service is quite different since the creation of a service can + // trigger an UpdateFailedException + // + Object descriptor = child.getDescriptor(); + int listIndex = _children.indexOf(child); + assert listIndex != -1; + + TreeNode newChild = createChild(descriptor); + _children.set(listIndex, newChild); + getRoot().getTreeModel().nodeChanged(newChild); + + getEnclosingEditable().markModified(); + } + + private void newService(ServiceInstanceDescriptor descriptor) + { + if(descriptor.descriptor == null) + { + String name = makeNewChildId("NewService"); + + // + // Make sure descriptor.template points to a real template + // + ServiceTemplate t = getRoot().findServiceTemplate(descriptor.template); + + if(t == null) + { + if(getRoot().getServiceTemplates().getChildCount() == 0) + { + 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 + { + t = (ServiceTemplate)getRoot().getServiceTemplates().getChildAt(0); + 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); + + + ServiceInstance service = new ServiceInstance(Communicator.this, name, descriptor); + try + { + addChild(service, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(service); + } + else + { + descriptor.descriptor.name = makeNewChildId(descriptor.descriptor.name); + + PlainService service = new PlainService(Communicator.this, descriptor); + try + { + addChild(service, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(service); + } + } } Adapters getAdapters() { - return _adapters; + return _adapters; } DbEnvs getDbEnvs() { - return _dbEnvs; + return _dbEnvs; } Services getServices() { - return _services; + 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()) - { - Object obj = p.next(); - if(obj instanceof ServiceInstance) - { - ServiceInstance service = (ServiceInstance)obj; - ServiceInstanceDescriptor d = - (ServiceInstanceDescriptor)service.getDescriptor(); - if(d.template.equals(template)) - { - result.add(service); - } - } - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _services.iterator(); + while(p.hasNext()) + { + Object obj = p.next(); + if(obj instanceof ServiceInstance) + { + ServiceInstance service = (ServiceInstance)obj; + 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()) - { - Object obj = p.next(); - if(obj instanceof ServiceInstance) - { - ServiceInstance service = (ServiceInstance)obj; - ServiceInstanceDescriptor d = - (ServiceInstanceDescriptor)service.getDescriptor(); - if(d.template.equals(template)) - { - p.remove(); - _services.removeDescriptor(d); - getEnclosingEditable().markModified(); - } - } - } + { + java.util.Iterator p = _services.iterator(); + while(p.hasNext()) + { + Object obj = p.next(); + if(obj instanceof ServiceInstance) + { + ServiceInstance service = (ServiceInstance)obj; + ServiceInstanceDescriptor d = + (ServiceInstanceDescriptor)service.getDescriptor(); + if(d.template.equals(template)) + { + p.remove(); + _services.removeDescriptor(d); + getEnclosingEditable().markModified(); + } + } + } } void removeSortedChildren(String[] childIds, java.util.List fromChildren) { - removeSortedChildren(childIds, fromChildren, getRoot().getTreeModel()); + removeSortedChildren(childIds, fromChildren, getRoot().getTreeModel()); } void childrenChanged(java.util.List children) { - childrenChanged(children, getRoot().getTreeModel()); + childrenChanged(children, getRoot().getTreeModel()); } String getProperty(String key) { - CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); - java.util.Iterator p = descriptor.propertySet.properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.name.equals(key)) - { - return pd.value; - } - } - return null; + CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); + java.util.Iterator p = descriptor.propertySet.properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.name.equals(key)) + { + return pd.value; + } + } + return null; } String lookupPropertyValue(String val) { - CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); - java.util.Iterator p = descriptor.propertySet.properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.value.equals(val)) - { - return pd.name; - } - } - return ""; + CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); + java.util.Iterator p = descriptor.propertySet.properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.value.equals(val)) + { + return pd.name; + } + } + return ""; } void setProperty(String key, String newValue) { - CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); - removeProperty(key); - ((java.util.LinkedList)descriptor.propertySet.properties).addFirst(new PropertyDescriptor(key, newValue)); + CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); + removeProperty(key); + ((java.util.LinkedList)descriptor.propertySet.properties).addFirst(new PropertyDescriptor(key, newValue)); } void removeProperty(String key) { - CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); - java.util.Iterator p = descriptor.propertySet.properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.name.equals(key)) - { - p.remove(); - } - } + CommunicatorDescriptor descriptor = getCommunicatorDescriptor(); + java.util.Iterator p = descriptor.propertySet.properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.name.equals(key)) + { + p.remove(); + } + } } // diff --git a/java/src/IceGridGUI/Application/CommunicatorChildEditor.java b/java/src/IceGridGUI/Application/CommunicatorChildEditor.java index ee3ffe13935..041a9a72826 100755 --- a/java/src/IceGridGUI/Application/CommunicatorChildEditor.java +++ b/java/src/IceGridGUI/Application/CommunicatorChildEditor.java @@ -23,109 +23,109 @@ abstract class CommunicatorChildEditor extends Editor protected boolean applyUpdate(boolean refresh) { - 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 false; - } - - // - // Success - // - _target = childList.findChildWithDescriptor(descriptor); - root.updated(); - if(refresh) - { - 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 false; - } - - // - // Success - // - _target = childList.findChildWithDescriptor(_target.getDescriptor()); - root.updated(); - if(refresh) - { - root.setSelectedNode(_target); - } - } - - postUpdate(); + 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 false; + } + + // + // Success + // + _target = childList.findChildWithDescriptor(descriptor); + root.updated(); + if(refresh) + { + 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 false; + } + + // + // Success + // + _target = childList.findChildWithDescriptor(_target.getDescriptor()); + root.updated(); + if(refresh) + { + root.setSelectedNode(_target); + } + } + + postUpdate(); - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } } diff --git a/java/src/IceGridGUI/Application/CommunicatorSubEditor.java b/java/src/IceGridGUI/Application/CommunicatorSubEditor.java index 68a7200b179..5286e57b059 100755 --- a/java/src/IceGridGUI/Application/CommunicatorSubEditor.java +++ b/java/src/IceGridGUI/Application/CommunicatorSubEditor.java @@ -27,123 +27,123 @@ class CommunicatorSubEditor { CommunicatorSubEditor(Editor mainEditor) { - _mainEditor = mainEditor; - - _description.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _description.setToolTipText("An optional description"); - - _propertySets.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _propertySets.setToolTipText("Property Set References"); - - _properties = new PropertiesField(mainEditor); - _logFiles = new MapField(mainEditor, "Path", "Property", - true); - _logFiles.setToolTipText("Log files used by this server or service"); + _mainEditor = mainEditor; + + _description.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _description.setToolTipText("An optional description"); + + _propertySets.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _propertySets.setToolTipText("Property Set References"); + + _properties = new PropertiesField(mainEditor); + _logFiles = new MapField(mainEditor, "Path", "Property", + true); + _logFiles.setToolTipText("Log files used by this server or service"); } 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("Property Sets"); - builder.append(_propertySets, 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(); - - builder.append("Log files"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-4); - scrollPane = new JScrollPane(_logFiles); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 5)); - builder.nextRow(4); - 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("Property Sets"); + builder.append(_propertySets, 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(); + + builder.append("Log files"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-4); + scrollPane = new JScrollPane(_logFiles); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 5)); + builder.nextRow(4); + builder.nextLine(); } void writeDescriptor(CommunicatorDescriptor descriptor) { - descriptor.propertySet.references = - (String[])_propertySets.getList().toArray(new String[0]); - descriptor.propertySet.properties = _properties.getProperties(); - descriptor.description = _description.getText(); - - java.util.TreeMap tm = _logFiles.get(); - java.util.Iterator p = tm.entrySet().iterator(); - descriptor.logs = new String[tm.size()]; - int i = 0; - - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String path = (String)entry.getKey(); - String prop = ((String)entry.getValue()).trim(); - - descriptor.logs[i++] = path; - if(!prop.equals("")) - { - setProperty((java.util.LinkedList)descriptor.propertySet.properties, prop, path); - } - } + descriptor.propertySet.references = + (String[])_propertySets.getList().toArray(new String[0]); + descriptor.propertySet.properties = _properties.getProperties(); + descriptor.description = _description.getText(); + + java.util.TreeMap tm = _logFiles.get(); + java.util.Iterator p = tm.entrySet().iterator(); + descriptor.logs = new String[tm.size()]; + int i = 0; + + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String path = (String)entry.getKey(); + String prop = ((String)entry.getValue()).trim(); + + descriptor.logs[i++] = path; + if(!prop.equals("")) + { + setProperty((java.util.LinkedList)descriptor.propertySet.properties, prop, path); + } + } } void show(CommunicatorDescriptor descriptor, boolean isEditable) { - Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); - isEditable = isEditable && (detailResolver == null); - - // - // Note that we don't substitute in the lookup - // - java.util.Map map = new java.util.TreeMap(); - for(int i = 0; i < descriptor.logs.length; ++i) - { - String prop = lookupKey(descriptor.propertySet.properties, - descriptor.logs[i]); - map.put(descriptor.logs[i], prop); - } - _logFiles.set(map, detailResolver, isEditable); - - _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), - detailResolver); - _propertySets.setEditable(isEditable); - _properties.setProperties(descriptor.propertySet.properties, - descriptor.adapters, - descriptor.logs, - detailResolver, isEditable); - - _description.setText( - Utils.substitute(descriptor.description, detailResolver)); - _description.setEditable(isEditable); - _description.setOpaque(isEditable); + Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); + isEditable = isEditable && (detailResolver == null); + + // + // Note that we don't substitute in the lookup + // + java.util.Map map = new java.util.TreeMap(); + for(int i = 0; i < descriptor.logs.length; ++i) + { + String prop = lookupKey(descriptor.propertySet.properties, + descriptor.logs[i]); + map.put(descriptor.logs[i], prop); + } + _logFiles.set(map, detailResolver, isEditable); + + _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), + detailResolver); + _propertySets.setEditable(isEditable); + _properties.setProperties(descriptor.propertySet.properties, + descriptor.adapters, + descriptor.logs, + detailResolver, isEditable); + + _description.setText( + Utils.substitute(descriptor.description, detailResolver)); + _description.setEditable(isEditable); + _description.setOpaque(isEditable); } @@ -152,35 +152,35 @@ class CommunicatorSubEditor // private String lookupKey(java.util.List props, String value) { - java.util.Iterator p = props.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.value.equals(value)) - { - return pd.name; - } - } - return ""; + java.util.Iterator p = props.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.value.equals(value)) + { + return pd.name; + } + } + return ""; } private void setProperty(java.util.LinkedList props, String key, String newValue) { - removeProperty(props, key); - props.addFirst(new PropertyDescriptor(key, newValue)); + removeProperty(props, key); + props.addFirst(new PropertyDescriptor(key, newValue)); } private void removeProperty(java.util.List props, String key) { - java.util.Iterator p = props.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.name.equals(key)) - { - p.remove(); - } - } + java.util.Iterator p = props.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.name.equals(key)) + { + p.remove(); + } + } } diff --git a/java/src/IceGridGUI/Application/DbEnv.java b/java/src/IceGridGUI/Application/DbEnv.java index b2e89d668c9..790dcd83d89 100755 --- a/java/src/IceGridGUI/Application/DbEnv.java +++ b/java/src/IceGridGUI/Application/DbEnv.java @@ -19,36 +19,36 @@ class DbEnv extends TreeNode implements DescriptorHolder { static public DbEnvDescriptor copyDescriptor(DbEnvDescriptor d) { - return (DbEnvDescriptor)d.clone(); + return (DbEnvDescriptor)d.clone(); } static public java.util.List copyDescriptors(java.util.List list) { - java.util.List copy = new java.util.LinkedList(); - java.util.Iterator p = list.iterator(); - while(p.hasNext()) - { - copy.add(copyDescriptor((DbEnvDescriptor)p.next())); - } - return copy; + java.util.List 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); + 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); } // @@ -56,134 +56,134 @@ class DbEnv extends TreeNode implements DescriptorHolder // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; - Object clipboard = getCoordinator().getClipboard(); - actions[PASTE] = clipboard != null && - (clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor); - actions[DELETE] = true; - - if(!_ephemeral) - { - boolean[] parentActions = ((TreeNode)_parent).getAvailableActions(); - actions[SHOW_VARS] = parentActions[SHOW_VARS]; - actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS]; - } - return actions; + Object clipboard = getCoordinator().getClipboard(); + actions[PASTE] = clipboard != null && + (clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor); + actions[DELETE] = true; + + if(!_ephemeral) + { + boolean[] parentActions = ((TreeNode)_parent).getAvailableActions(); + actions[SHOW_VARS] = parentActions[SHOW_VARS]; + actions[SUBSTITUTE_VARS] = parentActions[SUBSTITUTE_VARS]; + } + return actions; } public void copy() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public Editor getEditor() { - if(_editor == null) - { - _editor = (DbEnvEditor)getRoot().getEditor(DbEnvEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (DbEnvEditor)getRoot().getEditor(DbEnvEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new DbEnvEditor(); + return new DbEnvEditor(); } public Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object copyDescriptor() { - return copyDescriptor(_descriptor); + return copyDescriptor(_descriptor); } public Object saveDescriptor() { - return copyDescriptor(_descriptor); + 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; + 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); + ((Communicator)_parent).getDbEnvs().destroyChild(this); } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } DbEnv(Communicator parent, String dbEnvName, DbEnvDescriptor descriptor, - boolean ephemeral) + boolean ephemeral) { - super(parent, dbEnvName); - _descriptor = descriptor; - _ephemeral = ephemeral; + super(parent, dbEnvName); + _descriptor = descriptor; + _ephemeral = ephemeral; } static void writeDbProperties(XMLWriter writer, - java.util.List properties) - throws java.io.IOException + 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); - } + 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"); - } - } + 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; diff --git a/java/src/IceGridGUI/Application/DbEnvEditor.java b/java/src/IceGridGUI/Application/DbEnvEditor.java index 9ff7b6a47bb..b937cd96ba8 100755 --- a/java/src/IceGridGUI/Application/DbEnvEditor.java +++ b/java/src/IceGridGUI/Application/DbEnvEditor.java @@ -28,160 +28,160 @@ class DbEnvEditor extends CommunicatorChildEditor { DbEnvEditor() { - _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 = new PropertiesField(this); + _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 = new PropertiesField(this); } void writeDescriptor() { - DbEnvDescriptor descriptor = - (DbEnvDescriptor)getDbEnv().getDescriptor(); - descriptor.name = _name.getText().trim(); - descriptor.description = _description.getText(); - descriptor.dbHome = getDbHomeAsString(); - descriptor.properties = _properties.getProperties(); - } + DbEnvDescriptor descriptor = + (DbEnvDescriptor)getDbEnv().getDescriptor(); + descriptor.name = _name.getText().trim(); + descriptor.description = _description.getText(); + descriptor.dbHome = getDbHomeAsString(); + descriptor.properties = _properties.getProperties(); + } boolean isSimpleUpdate() { - DbEnvDescriptor descriptor = - (DbEnvDescriptor)getDbEnv().getDescriptor(); - return descriptor.name.equals(_name.getText().trim()); + DbEnvDescriptor descriptor = + (DbEnvDescriptor)getDbEnv().getDescriptor(); + return descriptor.name.equals(_name.getText().trim()); } Communicator.ChildList getChildList() { - return ((Communicator)_target.getParent()).getDbEnvs(); + 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.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(); + 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.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("Database Environment Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Database Environment Properties"); } protected boolean validate() { - return check(new String[]{"Name", _name.getText().trim()}); + return check(new String[]{"Name", _name.getText().trim()}); } 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 = 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); - - _properties.setProperties(descriptor.properties, null, null, - resolver, isEditable); - - _applyButton.setEnabled(dbEnv.isEphemeral()); - _discardButton.setEnabled(dbEnv.isEphemeral()); - detectUpdates(true); + detectUpdates(false); + _target = dbEnv; + + DbEnvDescriptor descriptor = (DbEnvDescriptor)dbEnv.getDescriptor(); + + Utils.Resolver resolver = null; + if(dbEnv.getCoordinator().substitute()) + { + resolver = dbEnv.getResolver(); + } + boolean 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); + + _properties.setProperties(descriptor.properties, null, null, + resolver, isEditable); + + _applyButton.setEnabled(dbEnv.isEphemeral()); + _discardButton.setEnabled(dbEnv.isEphemeral()); + detectUpdates(true); } private DbEnv getDbEnv() { - return (DbEnv)_target; + return (DbEnv)_target; } private void setDbHome(String dbHome) { - if(dbHome.equals("")) - { - _dbHome.setSelectedItem(NO_DB_HOME); - } - else - { - _dbHome.setSelectedItem(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().trim(); - } + Object obj = _dbHome.getSelectedItem(); + if(obj == NO_DB_HOME) + { + return ""; + } + else + { + return obj.toString().trim(); + } } private JTextField _name = new JTextField(20); @@ -191,10 +191,10 @@ class DbEnvEditor extends CommunicatorChildEditor private PropertiesField _properties; static private final Object NO_DB_HOME = new Object() - { - public String toString() - { - return "Created by the IceGrid Node"; - } - }; + { + public String toString() + { + return "Created by the IceGrid Node"; + } + }; } diff --git a/java/src/IceGridGUI/Application/Editable.java b/java/src/IceGridGUI/Application/Editable.java index 487a7fecdc1..5972ea4d57e 100755 --- a/java/src/IceGridGUI/Application/Editable.java +++ b/java/src/IceGridGUI/Application/Editable.java @@ -12,91 +12,91 @@ class Editable implements Cloneable { Editable(boolean brandNew) { - _isNew = brandNew; + _isNew = brandNew; } boolean isNew() { - return _isNew; + return _isNew; } boolean isModified() { - return _modified; + return _modified; } void markModified() { - _modified = true; + _modified = true; } void commit() { - _isNew = false; - _modified = false; - _removedElements.clear(); + _isNew = false; + _modified = false; + _removedElements.clear(); } void markNew() { - _isNew = true; + _isNew = true; } void removeElement(String id, Editable editable, Class forClass) { - if(!editable.isNew()) - { - java.util.TreeSet set = (java.util.TreeSet)_removedElements.get(forClass); - if(set == null) - { - set = new java.util.TreeSet(); - _removedElements.put(forClass, set); - } - set.add(id); - } + if(!editable.isNew()) + { + java.util.TreeSet set = (java.util.TreeSet)_removedElements.get(forClass); + if(set == null) + { + set = new java.util.TreeSet(); + _removedElements.put(forClass, set); + } + set.add(id); + } } String[] removedElements(Class forClass) { - java.util.TreeSet set = (java.util.TreeSet)_removedElements.get(forClass); - if(set == null) - { - return new String[0]; - } - else - { - return (String[])set.toArray(new String[0]); - } + java.util.TreeSet set = (java.util.TreeSet)_removedElements.get(forClass); + if(set == null) + { + return new String[0]; + } + else + { + return (String[])set.toArray(new String[0]); + } } Editable save() { - try - { - Editable result = (Editable)clone(); - java.util.HashMap removedElements = new java.util.HashMap(); - java.util.Iterator p = result._removedElements.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - Object val = ((java.util.TreeSet)entry.getValue()).clone(); - removedElements.put(entry.getKey(), val); - } - result._removedElements = removedElements; - return result; - } - catch(CloneNotSupportedException e) - { - assert false; - return null; - } + try + { + Editable result = (Editable)clone(); + java.util.HashMap removedElements = new java.util.HashMap(); + java.util.Iterator p = result._removedElements.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + Object val = ((java.util.TreeSet)entry.getValue()).clone(); + removedElements.put(entry.getKey(), val); + } + result._removedElements = removedElements; + return result; + } + catch(CloneNotSupportedException e) + { + assert false; + return null; + } } void restore(Editable clone) { - _isNew = clone._isNew; - _modified = clone._modified; - _removedElements = clone._removedElements; + _isNew = clone._isNew; + _modified = clone._modified; + _removedElements = clone._removedElements; } private boolean _isNew = false; diff --git a/java/src/IceGridGUI/Application/Editor.java b/java/src/IceGridGUI/Application/Editor.java index dd8cf663e00..cb3308c0111 100755 --- a/java/src/IceGridGUI/Application/Editor.java +++ b/java/src/IceGridGUI/Application/Editor.java @@ -39,62 +39,62 @@ import IceGridGUI.*; public class Editor extends EditorBase { static public java.util.Map makeParameterValues( - java.util.Map oldParameterValues, - java.util.List newParameters) + 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; + 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; } public boolean save(boolean refresh) { - if(_applyButton.isEnabled()) - { - return validate() && applyUpdate(refresh); - } - else - { - return true; - } + if(_applyButton.isEnabled()) + { + return validate() && applyUpdate(refresh); + } + else + { + return true; + } } protected boolean validate() { - return true; + return true; } protected boolean applyUpdate(boolean refresh) { - assert false; - return false; + assert false; + return false; } protected void detectUpdates(boolean val) { - _detectUpdates = val; + _detectUpdates = val; } protected void discardUpdate() { - if(_target.isEphemeral()) - { - _target.delete(); - } - else - { - _target.getCoordinator().getCurrentTab().showNode(_target); - } + if(_target.isEphemeral()) + { + _target.delete(); + } + else + { + _target.getCoordinator().getCurrentTab().showNode(_target); + } } protected void appendProperties(DefaultFormBuilder builder) @@ -102,67 +102,67 @@ public class Editor extends EditorBase protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - JComponent buttonBar = - ButtonBarFactory.buildRightAlignedBar(_applyButton, - _discardButton); - buttonBar.setBorder(Borders.DIALOG_BORDER); - _propertiesPanel.add(buttonBar, BorderLayout.SOUTH); + 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) - { - if(validate()) - { - if(applyUpdate(true)) - { - _target.getRoot().getTree().grabFocus(); - } - } - } - }; - _applyButton = new JButton(apply); - _applyButton.setEnabled(false); - - // - // _discardButton - // - AbstractAction discard = new AbstractAction("Discard") - { - public void actionPerformed(ActionEvent e) - { - discardUpdate(); - _target.getRoot().getTree().grabFocus(); - } - }; - _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(); - } - }; + // + // _applyButton + // + AbstractAction apply = new AbstractAction("Apply") + { + public void actionPerformed(ActionEvent e) + { + if(validate()) + { + if(applyUpdate(true)) + { + _target.getRoot().getTree().grabFocus(); + } + } + } + }; + _applyButton = new JButton(apply); + _applyButton.setEnabled(false); + + // + // _discardButton + // + AbstractAction discard = new AbstractAction("Discard") + { + public void actionPerformed(ActionEvent e) + { + discardUpdate(); + _target.getRoot().getTree().grabFocus(); + } + }; + _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(); + } + }; } // @@ -170,32 +170,32 @@ public class Editor extends EditorBase // Object getSubDescriptor() { - return null; + return null; } Utils.Resolver getDetailResolver() { - return null; + return null; } public TreeNode getTarget() { - return _target; + return _target; } void updated() { - if(_detectUpdates) - { - _target.getRoot().disableRegistryUpdates(); - _applyButton.setEnabled(true); - _discardButton.setEnabled(true); - } + if(_detectUpdates) + { + _target.getRoot().disableRegistryUpdates(); + _applyButton.setEnabled(true); + _discardButton.setEnabled(true); + } } DocumentListener getUpdateListener() { - return _updateListener; + return _updateListener; } // @@ -203,36 +203,36 @@ public class Editor extends EditorBase // boolean check(String[] nameValArray) { - String emptyFields = ""; - int errorCount = 0; - - for(int i = 1; i < nameValArray.length; i += 2) - { - if(nameValArray[i] == null || nameValArray[i].length() == 0) - { - errorCount++; - if(emptyFields.length() > 0) - { - emptyFields += "\n"; - } - emptyFields += "'" + nameValArray[i - 1] + "'"; - } - } - - if(errorCount > 0) - { - String message = errorCount == 1 ? - emptyFields + " cannot be empty" : - "The following fields cannot be empty:\n" + emptyFields; - - JOptionPane.showMessageDialog( - _target.getCoordinator().getMainFrame(), - message, - "Validation failed", - JOptionPane.ERROR_MESSAGE); - } - - return errorCount == 0; + String emptyFields = ""; + int errorCount = 0; + + for(int i = 1; i < nameValArray.length; i += 2) + { + if(nameValArray[i] == null || nameValArray[i].length() == 0) + { + errorCount++; + if(emptyFields.length() > 0) + { + emptyFields += "\n"; + } + emptyFields += "'" + nameValArray[i - 1] + "'"; + } + } + + if(errorCount > 0) + { + String message = errorCount == 1 ? + emptyFields + " cannot be empty" : + "The following fields cannot be empty:\n" + emptyFields; + + JOptionPane.showMessageDialog( + _target.getCoordinator().getMainFrame(), + message, + "Validation failed", + JOptionPane.ERROR_MESSAGE); + } + + return errorCount == 0; } protected JButton _applyButton; diff --git a/java/src/IceGridGUI/Application/ListTextField.java b/java/src/IceGridGUI/Application/ListTextField.java index 86efdd6ef99..e82a6564cf8 100755 --- a/java/src/IceGridGUI/Application/ListTextField.java +++ b/java/src/IceGridGUI/Application/ListTextField.java @@ -22,58 +22,58 @@ public class ListTextField extends JTextField { public ListTextField(int columns) { - super(columns); + super(columns); } public void setList(java.util.List list, final Utils.Resolver resolver) { - Utils.Stringifier stringifier = new Utils.Stringifier() - { - public String toString(Object obj) - { - return Utils.substitute((String)obj, resolver); - } - }; - - setText(Utils.stringify(list, stringifier, " ", null)); + Utils.Stringifier stringifier = new Utils.Stringifier() + { + public String toString(Object obj) + { + return Utils.substitute((String)obj, resolver); + } + }; + + setText(Utils.stringify(list, stringifier, " ", null)); } public java.util.LinkedList getList() { - String text = getText().trim(); - java.util.LinkedList result = new java.util.LinkedList(); + String text = getText().trim(); + java.util.LinkedList result = new java.util.LinkedList(); - while(text.length() > 0) - { - if(text.startsWith("\"")) - { - int last = text.indexOf("\"", 1); - if(last == -1) - { - result.add(text.substring(1)); - text = ""; - } - else - { - result.add(text.substring(1, last)); - text = text.substring(last + 1).trim(); - } - } - else - { - String[] strings = text.split("\\s", 2); - if(strings.length == 1) - { - result.add(strings[0]); - text = ""; - } - else - { - result.add(strings[0]); - text = strings[1].trim(); - } - } - } - return result; + while(text.length() > 0) + { + if(text.startsWith("\"")) + { + int last = text.indexOf("\"", 1); + if(last == -1) + { + result.add(text.substring(1)); + text = ""; + } + else + { + result.add(text.substring(1, last)); + text = text.substring(last + 1).trim(); + } + } + else + { + String[] strings = text.split("\\s", 2); + if(strings.length == 1) + { + result.add(strings[0]); + text = ""; + } + else + { + result.add(strings[0]); + text = strings[1].trim(); + } + } + } + return result; } } diff --git a/java/src/IceGridGUI/Application/ListTreeNode.java b/java/src/IceGridGUI/Application/ListTreeNode.java index 90fec250fc8..4b5fa7f5370 100755 --- a/java/src/IceGridGUI/Application/ListTreeNode.java +++ b/java/src/IceGridGUI/Application/ListTreeNode.java @@ -22,214 +22,214 @@ 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(); - }; + 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; + 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); - } + 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(); + return _children.size(); } public int getIndex(javax.swing.tree.TreeNode node) { - return _children.indexOf(node); + return _children.indexOf(node); } public boolean isLeaf() { - return _children.isEmpty(); + return _children.isEmpty(); } public Editor getEditor() { - if(_editor == null) - { - _editor = new Editor(); - } - return _editor; + if(_editor == null) + { + _editor = new Editor(); + } + return _editor; } protected Editor createEditor() { - assert false; - return null; + assert false; + return null; } protected ListTreeNode(boolean brandNew, TreeNode parent, String id) { - super(parent, id); - _editable = new Editable(brandNew); + 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); - } + 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 + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - if(!insertSortedChild(child, _children, treeModel)) - { - throw new UpdateFailedException(this, child.getId()); - } + 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 + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - String badChildId = insertSortedChildren(newChildren, _children, treeModel); - - if(badChildId != null) - { - throw new UpdateFailedException(this, badChildId); - } + DefaultTreeModel treeModel = fireEvent ? + getRoot().getTreeModel() : null; + + String badChildId = insertSortedChildren(newChildren, _children, treeModel); + + if(badChildId != null) + { + throw new UpdateFailedException(this, badChildId); + } } int removeChild(TreeNode child) { - int index = getIndex(child); - _children.remove(child); - - getRoot().getTreeModel().nodesWereRemoved(this, - new int[]{index}, - new Object[]{child}); - return index; + 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()); + removeSortedChildren(childIds, _children, getRoot().getTreeModel()); } void childrenChanged(java.util.List children) { - childrenChanged(children, getRoot().getTreeModel()); + childrenChanged(children, getRoot().getTreeModel()); } Editable getEditable() { - return _editable; + return _editable; } javax.swing.ComboBoxModel createComboBoxModel() { - return new ComboBoxModel(); + return new ComboBoxModel(); } javax.swing.ComboBoxModel createComboBoxModel(Object item) { - return new ComboBoxModel(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; + 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(); diff --git a/java/src/IceGridGUI/Application/MapField.java b/java/src/IceGridGUI/Application/MapField.java index f5bc7cf7f2d..0966b6f6e83 100755 --- a/java/src/IceGridGUI/Application/MapField.java +++ b/java/src/IceGridGUI/Application/MapField.java @@ -32,198 +32,198 @@ public class MapField extends JTable { public MapField(Editor editor, String headKey, String[] headValues, boolean substituteKey) { - _editor = editor; - _substituteKey = substituteKey; - _vectorSize = headValues.length + 1; - - _columnNames = new java.util.Vector(_vectorSize); - _columnNames.add(headKey); - for(int i = 0; i < headValues.length; ++i) - { - _columnNames.add(headValues[i]); - } - - assert _vectorSize >= 2; - - Action deleteRow = new AbstractAction("Delete selected row(s)") - { - public void actionPerformed(ActionEvent e) - { - if(_editable) - { - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - - for(;;) - { - int selectedRow = getSelectedRow(); - if(selectedRow == -1) - { - break; - } - else - { - _model.removeRow(selectedRow); - } - } - } - } - }; - getActionMap().put("delete", deleteRow); - getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); + _editor = editor; + _substituteKey = substituteKey; + _vectorSize = headValues.length + 1; + + _columnNames = new java.util.Vector(_vectorSize); + _columnNames.add(headKey); + for(int i = 0; i < headValues.length; ++i) + { + _columnNames.add(headValues[i]); + } + + assert _vectorSize >= 2; + + Action deleteRow = new AbstractAction("Delete selected row(s)") + { + public void actionPerformed(ActionEvent e) + { + if(_editable) + { + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + + for(;;) + { + int selectedRow = getSelectedRow(); + if(selectedRow == -1) + { + break; + } + else + { + _model.removeRow(selectedRow); + } + } + } + } + }; + getActionMap().put("delete", deleteRow); + getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); } public MapField(Editor editor, String headKey, String headValue, boolean substituteKey) { - this(editor, headKey, new String[]{headValue}, substituteKey); + this(editor, headKey, new String[]{headValue}, substituteKey); } public void set(java.util.Map map, Utils.Resolver resolver, - boolean editable) + boolean editable) { - _editable = editable; - - // - // Transform map into vector of vectors - // - java.util.Vector vector = new java.util.Vector(map.size()); - java.util.Iterator p = map.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Vector row = new java.util.Vector(_vectorSize); - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - if(_substituteKey) - { - row.add(Utils.substitute((String)entry.getKey(), resolver)); - } - else - { - row.add((String)entry.getKey()); - } - - if(_vectorSize == 2) - { - row.add(Utils.substitute((String)entry.getValue(), resolver)); - } - else - { - String[] val = (String[])entry.getValue(); - - for(int i = 0; i < val.length; ++i) - { - row.add(Utils.substitute(val[i], resolver)); - } - } - vector.add(row); - } - - if(_editable) - { - java.util.Vector newRow = new java.util.Vector(_vectorSize); - for(int i = 0; i < _vectorSize; ++i) - { - newRow.add(""); - } - vector.add(newRow); - } - - _model = new DefaultTableModel(vector, _columnNames) - { - public boolean isCellEditable(int row, int column) - { - return _editable; - } - }; - - _model.addTableModelListener(new TableModelListener() - { - public void tableChanged(TableModelEvent e) - { - if(_editable) - { - Object lastKey = _model.getValueAt( - _model.getRowCount() - 1 , 0); - if(lastKey != null && !lastKey.equals("")) - { - Object[] emptyRow = new Object[_vectorSize]; - for(int i = 0; i < _vectorSize; ++i) - { - emptyRow[i] = ""; - } - _model.addRow(emptyRow); - } - _editor.updated(); - } - } - }); - setModel(_model); - - setCellSelectionEnabled(_editable); - setOpaque(_editable); - setPreferredScrollableViewportSize(getPreferredSize()); - - DefaultTableCellRenderer cr = (DefaultTableCellRenderer) - getDefaultRenderer(String.class); - cr.setOpaque(_editable); + _editable = editable; + + // + // Transform map into vector of vectors + // + java.util.Vector vector = new java.util.Vector(map.size()); + java.util.Iterator p = map.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Vector row = new java.util.Vector(_vectorSize); + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + if(_substituteKey) + { + row.add(Utils.substitute((String)entry.getKey(), resolver)); + } + else + { + row.add((String)entry.getKey()); + } + + if(_vectorSize == 2) + { + row.add(Utils.substitute((String)entry.getValue(), resolver)); + } + else + { + String[] val = (String[])entry.getValue(); + + for(int i = 0; i < val.length; ++i) + { + row.add(Utils.substitute(val[i], resolver)); + } + } + vector.add(row); + } + + if(_editable) + { + java.util.Vector newRow = new java.util.Vector(_vectorSize); + for(int i = 0; i < _vectorSize; ++i) + { + newRow.add(""); + } + vector.add(newRow); + } + + _model = new DefaultTableModel(vector, _columnNames) + { + public boolean isCellEditable(int row, int column) + { + return _editable; + } + }; + + _model.addTableModelListener(new TableModelListener() + { + public void tableChanged(TableModelEvent e) + { + if(_editable) + { + Object lastKey = _model.getValueAt( + _model.getRowCount() - 1 , 0); + if(lastKey != null && !lastKey.equals("")) + { + Object[] emptyRow = new Object[_vectorSize]; + for(int i = 0; i < _vectorSize; ++i) + { + emptyRow[i] = ""; + } + _model.addRow(emptyRow); + } + _editor.updated(); + } + } + }); + setModel(_model); + + setCellSelectionEnabled(_editable); + setOpaque(_editable); + setPreferredScrollableViewportSize(getPreferredSize()); + + DefaultTableCellRenderer cr = (DefaultTableCellRenderer) + getDefaultRenderer(String.class); + cr.setOpaque(_editable); } public java.util.TreeMap get() { - assert _editable; - - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - java.util.Vector vector = _model.getDataVector(); - - java.util.TreeMap result = new java.util.TreeMap(); - - java.util.Iterator p = vector.iterator(); - while(p.hasNext()) - { - java.util.Vector row = (java.util.Vector)p.next(); - - // - // Eliminate rows with null or empty keys - // - String key = (String)row.elementAt(0); - if(key != null) - { - key = key.trim(); - if(!key.equals("")) - { - if(_vectorSize == 2) - { - String val = (String)row.elementAt(1); - if(val == null) - { - val = ""; - } - result.put(key, val); - } - else - { - String[] val = new String[_vectorSize - 1]; - for(int i = 1; i < _vectorSize; ++i) - { - val[i - 1] = (String)row.elementAt(i); - if(val[i - 1] == null) - { - val[i - 1] = ""; - } - } - result.put(key, val); - } - } - } - } - return result; + assert _editable; + + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + java.util.Vector vector = _model.getDataVector(); + + java.util.TreeMap result = new java.util.TreeMap(); + + java.util.Iterator p = vector.iterator(); + while(p.hasNext()) + { + java.util.Vector row = (java.util.Vector)p.next(); + + // + // Eliminate rows with null or empty keys + // + String key = (String)row.elementAt(0); + if(key != null) + { + key = key.trim(); + if(!key.equals("")) + { + if(_vectorSize == 2) + { + String val = (String)row.elementAt(1); + if(val == null) + { + val = ""; + } + result.put(key, val); + } + else + { + String[] val = new String[_vectorSize - 1]; + for(int i = 1; i < _vectorSize; ++i) + { + val[i - 1] = (String)row.elementAt(i); + if(val[i - 1] == null) + { + val[i - 1] = ""; + } + } + result.put(key, val); + } + } + } + } + return result; } private final int _vectorSize; diff --git a/java/src/IceGridGUI/Application/Node.java b/java/src/IceGridGUI/Application/Node.java index 6d82d32731a..1260456a360 100755 --- a/java/src/IceGridGUI/Application/Node.java +++ b/java/src/IceGridGUI/Application/Node.java @@ -30,437 +30,437 @@ class Node extends TreeNode implements PropertySetParent static public NodeDescriptor copyDescriptor(NodeDescriptor nd) { - NodeDescriptor copy = (NodeDescriptor)nd.clone(); - - copy.propertySets = PropertySets.copyDescriptors(copy.propertySets); - - - copy.serverInstances = new java.util.LinkedList(); - java.util.Iterator p = nd.serverInstances.iterator(); - while(p.hasNext()) - { - copy.serverInstances.add(ServerInstance.copyDescriptor( - (ServerInstanceDescriptor)p.next())); - } + NodeDescriptor copy = (NodeDescriptor)nd.clone(); + + copy.propertySets = PropertySets.copyDescriptors(copy.propertySets); + + + copy.serverInstances = new java.util.LinkedList(); + java.util.Iterator p = nd.serverInstances.iterator(); + while(p.hasNext()) + { + copy.serverInstances.add(ServerInstance.copyDescriptor( + (ServerInstanceDescriptor)p.next())); + } - copy.servers = new java.util.LinkedList(); - p = nd.servers.iterator(); - while(p.hasNext()) - { - copy.servers.add(PlainServer.copyDescriptor( - (ServerDescriptor)p.next())); - } - - return copy; + copy.servers = new java.util.LinkedList(); + p = nd.servers.iterator(); + while(p.hasNext()) + { + copy.servers.add(PlainServer.copyDescriptor( + (ServerDescriptor)p.next())); + } + + return copy; } public Enumeration children() { - return new Enumeration() - { - public boolean hasMoreElements() - { - if(!_p.hasNext()) - { - if(!_iteratingOverServers) - { - _p = _servers.iterator(); - _iteratingOverServers = true; - return _p.hasNext(); - } - return false; - } - return true; - } - - public Object nextElement() - { - return _p.next(); - } - - private java.util.Iterator _p = _propertySets.iterator(); - private boolean _iteratingOverServers = false; - }; + return new Enumeration() + { + public boolean hasMoreElements() + { + if(!_p.hasNext()) + { + if(!_iteratingOverServers) + { + _p = _servers.iterator(); + _iteratingOverServers = true; + return _p.hasNext(); + } + return false; + } + return true; + } + + public Object nextElement() + { + return _p.next(); + } + + private java.util.Iterator _p = _propertySets.iterator(); + private boolean _iteratingOverServers = false; + }; } public boolean getAllowsChildren() { - return true; + return true; } public javax.swing.tree.TreeNode getChildAt(int childIndex) { - if(childIndex < 0) - { - throw new ArrayIndexOutOfBoundsException(childIndex); - } - else if(childIndex < _propertySets.size()) - { - return (javax.swing.tree.TreeNode)_propertySets.get(childIndex); - } - else if(childIndex < (_propertySets.size() + _servers.size())) - { - return (javax.swing.tree.TreeNode)_servers.get( - childIndex - _propertySets.size()); - } - else - { - throw new ArrayIndexOutOfBoundsException(childIndex); - } + if(childIndex < 0) + { + throw new ArrayIndexOutOfBoundsException(childIndex); + } + else if(childIndex < _propertySets.size()) + { + return (javax.swing.tree.TreeNode)_propertySets.get(childIndex); + } + else if(childIndex < (_propertySets.size() + _servers.size())) + { + return (javax.swing.tree.TreeNode)_servers.get( + childIndex - _propertySets.size()); + } + else + { + throw new ArrayIndexOutOfBoundsException(childIndex); + } } public int getChildCount() { - return _propertySets.size() + _servers.size(); + return _propertySets.size() + _servers.size(); } public int getIndex(javax.swing.tree.TreeNode node) { - if(node instanceof PropertySet) - { - return _propertySets.indexOf(node); - } - else - { - int index = _servers.indexOf(node); - if(index != -1) - { - index += _propertySets.size(); - } - return index; - } + if(node instanceof PropertySet) + { + return _propertySets.indexOf(node); + } + else + { + int index = _servers.indexOf(node); + if(index != -1) + { + index += _propertySets.size(); + } + return index; + } } public boolean isLeaf() { - return _propertySets.isEmpty() && _servers.isEmpty(); + return _propertySets.isEmpty() && _servers.isEmpty(); } void removeServers(String[] childIds) { - removeSortedChildren(childIds, _servers, getRoot().getTreeModel()); + removeSortedChildren(childIds, _servers, getRoot().getTreeModel()); } void removePropertySets(String[] childIds) { - removeSortedChildren(childIds, _propertySets, getRoot().getTreeModel()); + removeSortedChildren(childIds, _propertySets, getRoot().getTreeModel()); } void childrenChanged(java.util.List children) { - childrenChanged(children, getRoot().getTreeModel()); + childrenChanged(children, getRoot().getTreeModel()); } Server findServer(String id) { - return (Server)find(id, _servers); + return (Server)find(id, _servers); } PropertySet findPropertySet(String id) { - return (PropertySet)find(id, _propertySets); + return (PropertySet)find(id, _propertySets); } void insertPropertySets(java.util.List newChildren, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - String badChildId = insertSortedChildren(newChildren, _propertySets, treeModel); - - if(badChildId != null) - { - throw new UpdateFailedException(this, badChildId); - } + DefaultTreeModel treeModel = fireEvent ? + getRoot().getTreeModel() : null; + + String badChildId = insertSortedChildren(newChildren, _propertySets, treeModel); + + if(badChildId != null) + { + throw new UpdateFailedException(this, badChildId); + } } void insertServer(TreeNode child, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - if(!insertSortedChild(child, _servers, treeModel)) - { - throw new UpdateFailedException(this, child.getId()); - } + DefaultTreeModel treeModel = fireEvent ? + getRoot().getTreeModel() : null; + + if(!insertSortedChild(child, _servers, treeModel)) + { + throw new UpdateFailedException(this, child.getId()); + } } void insertServers(java.util.List newChildren, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - String badChildId = insertSortedChildren(newChildren, _servers, treeModel); - - if(badChildId != null) - { - throw new UpdateFailedException(this, badChildId); - } + DefaultTreeModel treeModel = fireEvent ? + getRoot().getTreeModel() : null; + + String badChildId = insertSortedChildren(newChildren, _servers, treeModel); + + if(badChildId != null) + { + throw new UpdateFailedException(this, badChildId); + } } void removeServer(TreeNode child) { - int index = getIndex(child); - _servers.remove(child); - - getRoot().getTreeModel().nodesWereRemoved(this, - new int[]{index}, - new Object[]{child}); + int index = getIndex(child); + _servers.remove(child); + + getRoot().getTreeModel().nodesWereRemoved(this, + new int[]{index}, + new Object[]{child}); } public void insertPropertySet(PropertySet child, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - DefaultTreeModel treeModel = fireEvent ? - getRoot().getTreeModel() : null; - - if(!insertSortedChild(child, _propertySets, treeModel)) - { - throw new UpdateFailedException(this, child.getId()); - } + DefaultTreeModel treeModel = fireEvent ? + getRoot().getTreeModel() : null; + + if(!insertSortedChild(child, _propertySets, treeModel)) + { + throw new UpdateFailedException(this, child.getId()); + } } public void removePropertySet(PropertySet child) { - int index = getIndex(child); - _propertySets.remove(child); - - getRoot().getTreeModel().nodesWereRemoved(this, - new int[]{index}, - new Object[]{child}); + int index = getIndex(child); + _propertySets.remove(child); + + getRoot().getTreeModel().nodesWereRemoved(this, + new int[]{index}, + new Object[]{child}); } public void removeDescriptor(String id) { - _descriptor.propertySets.remove(id); + _descriptor.propertySets.remove(id); } public Editable getEditable() { - return _editable; + return _editable; } public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - - actions[COPY] = !_ephemeral; - actions[DELETE] = true; - - Object descriptor = getCoordinator().getClipboard(); - if(descriptor != null) - { - actions[PASTE] = descriptor instanceof NodeDescriptor || - descriptor instanceof ServerInstanceDescriptor || - descriptor instanceof ServerDescriptor || - descriptor instanceof PropertySetDescriptor; - } - - if(!_ephemeral) - { - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - actions[NEW_PROPERTY_SET] = true; - actions[NEW_SERVER] = true; - actions[NEW_SERVER_ICEBOX] = true; - actions[NEW_SERVER_FROM_TEMPLATE] = true; - } - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + + actions[COPY] = !_ephemeral; + actions[DELETE] = true; + + Object descriptor = getCoordinator().getClipboard(); + if(descriptor != null) + { + actions[PASTE] = descriptor instanceof NodeDescriptor || + descriptor instanceof ServerInstanceDescriptor || + descriptor instanceof ServerDescriptor || + descriptor instanceof PropertySetDescriptor; + } + + if(!_ephemeral) + { + actions[SHOW_VARS] = true; + actions[SUBSTITUTE_VARS] = true; + actions[NEW_PROPERTY_SET] = true; + actions[NEW_SERVER] = true; + actions[NEW_SERVER_ICEBOX] = true; + actions[NEW_SERVER_FROM_TEMPLATE] = true; + } + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_PROPERTY_SET)); - _popup.addSeparator(); - _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; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_PROPERTY_SET)); + _popup.addSeparator(); + _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() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - if(descriptor instanceof NodeDescriptor) - { - ((TreeNode)_parent).paste(); - } - else if(descriptor instanceof PropertySetDescriptor) - { - newPropertySet(PropertySet.copyDescriptor((PropertySetDescriptor)descriptor)); - } - else if(descriptor instanceof ServerInstanceDescriptor) - { - newServer(ServerInstance.copyDescriptor((ServerInstanceDescriptor)descriptor)); - } - else - { - newServer(PlainServer.copyDescriptor(((ServerDescriptor)descriptor))); - } + Object descriptor = getCoordinator().getClipboard(); + if(descriptor instanceof NodeDescriptor) + { + ((TreeNode)_parent).paste(); + } + else if(descriptor instanceof PropertySetDescriptor) + { + newPropertySet(PropertySet.copyDescriptor((PropertySetDescriptor)descriptor)); + } + else if(descriptor instanceof ServerInstanceDescriptor) + { + newServer(ServerInstance.copyDescriptor((ServerInstanceDescriptor)descriptor)); + } + else + { + newServer(PlainServer.copyDescriptor(((ServerDescriptor)descriptor))); + } } public void newPropertySet() { - newPropertySet(new PropertySetDescriptor( - new String[0], new java.util.LinkedList())); + newPropertySet(new PropertySetDescriptor( + new String[0], new java.util.LinkedList())); } public void newServer() { - newServer(PlainServer.newServerDescriptor()); + newServer(PlainServer.newServerDescriptor()); } public void newServerIceBox() { - newServer(PlainServer.newIceBoxDescriptor()); + newServer(PlainServer.newIceBoxDescriptor()); } public void newServerFromTemplate() { - ServerInstanceDescriptor descriptor = - new ServerInstanceDescriptor("", - new java.util.HashMap(), - new PropertySetDescriptor(new String[0], new java.util.LinkedList()), - new java.util.HashMap()); + ServerInstanceDescriptor descriptor = + new ServerInstanceDescriptor("", + new java.util.HashMap(), + new PropertySetDescriptor(new String[0], new java.util.LinkedList()), + new java.util.HashMap()); - newServer(descriptor); + newServer(descriptor); } public void destroy() { - Nodes nodes = (Nodes)_parent; - if(_ephemeral) - { - nodes.removeChild(this); - } - else - { - nodes.removeChild(this); - nodes.removeDescriptor(_id); - nodes.getEditable().removeElement(_id, _editable, Node.class); - getRoot().updated(); - } + Nodes nodes = (Nodes)_parent; + if(_ephemeral) + { + nodes.removeChild(this); + } + else + { + nodes.removeChild(this); + nodes.removeDescriptor(_id); + nodes.getEditable().removeElement(_id, _editable, Node.class); + getRoot().updated(); + } } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { - if(_cellRenderer == null) - { - // - // Initialization - // - _cellRenderer = new DefaultTreeCellRenderer(); - Icon nodeIcon = Utils.getIcon("/icons/16x16/node.png"); - _cellRenderer.setOpenIcon(nodeIcon); - _cellRenderer.setClosedIcon(nodeIcon); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + if(_cellRenderer == null) + { + // + // Initialization + // + _cellRenderer = new DefaultTreeCellRenderer(); + Icon nodeIcon = Utils.getIcon("/icons/16x16/node.png"); + _cellRenderer.setOpenIcon(nodeIcon); + _cellRenderer.setClosedIcon(nodeIcon); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } public Editor getEditor() { - if(_editor == null) - { - _editor = (NodeEditor)getRoot().getEditor(NodeEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (NodeEditor)getRoot().getEditor(NodeEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new NodeEditor(); + return new NodeEditor(); } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } Object getDescriptor() { - return _descriptor; + return _descriptor; } NodeDescriptor saveDescriptor() { - return (NodeDescriptor)_descriptor.clone(); + return (NodeDescriptor)_descriptor.clone(); } void restoreDescriptor(NodeDescriptor copy) { - _descriptor.description = copy.description; - _descriptor.loadFactor = copy.loadFactor; - _descriptor.variables = copy.variables; + _descriptor.description = copy.description; + _descriptor.loadFactor = copy.loadFactor; + _descriptor.variables = copy.variables; } void write(XMLWriter writer) throws java.io.IOException { - if(!_ephemeral) - { - java.util.List attributes = new java.util.LinkedList(); - attributes.add(createAttribute("name", _id)); - if(_descriptor.loadFactor.length() > 0) - { - attributes.add(createAttribute("load-factor", - _descriptor.loadFactor)); - } - - writer.writeStartTag("node", attributes); - - if(_descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.description); - } - writeVariables(writer, _descriptor.variables); - - - java.util.Iterator p = _propertySets.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - ps.write(writer); - } - - p = _servers.iterator(); - while(p.hasNext()) - { - TreeNode server = (TreeNode)p.next(); - server.write(writer); - } - writer.writeEndTag("node"); - } + if(!_ephemeral) + { + java.util.List attributes = new java.util.LinkedList(); + attributes.add(createAttribute("name", _id)); + if(_descriptor.loadFactor.length() > 0) + { + attributes.add(createAttribute("load-factor", + _descriptor.loadFactor)); + } + + writer.writeStartTag("node", attributes); + + if(_descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.description); + } + writeVariables(writer, _descriptor.variables); + + + java.util.Iterator p = _propertySets.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + ps.write(writer); + } + + p = _servers.iterator(); + while(p.hasNext()) + { + TreeNode server = (TreeNode)p.next(); + server.write(writer); + } + writer.writeEndTag("node"); + } } static class Backup { - Utils.Resolver resolver; - java.util.List backupList; - java.util.List servers; + Utils.Resolver resolver; + java.util.List backupList; + java.util.List servers; } // @@ -471,854 +471,854 @@ class Node extends TreeNode implements PropertySetParent // Backup rebuild(java.util.List editables) - throws UpdateFailedException + throws UpdateFailedException { - Root root = getRoot(); - Backup backup = new Backup(); - backup.resolver = _resolver; - - _resolver = new Utils.Resolver(new java.util.Map[] - {_descriptor.variables, root.getVariables()}); - - _resolver.put("application", root.getId()); - _resolver.put("node", _id); - - backup.backupList = new java.util.Vector(); - backup.servers = (java.util.LinkedList)_servers.clone(); - - java.util.Iterator p = backup.servers.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - try - { - backup.backupList.add(server.rebuild(editables)); - } - catch(UpdateFailedException e) - { - restore(backup); - throw e; - } - } - return backup; + Root root = getRoot(); + Backup backup = new Backup(); + backup.resolver = _resolver; + + _resolver = new Utils.Resolver(new java.util.Map[] + {_descriptor.variables, root.getVariables()}); + + _resolver.put("application", root.getId()); + _resolver.put("node", _id); + + backup.backupList = new java.util.Vector(); + backup.servers = (java.util.LinkedList)_servers.clone(); + + java.util.Iterator p = backup.servers.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + try + { + backup.backupList.add(server.rebuild(editables)); + } + catch(UpdateFailedException e) + { + restore(backup); + throw e; + } + } + return backup; } void commit() { - _editable.commit(); - _origVariables = _descriptor.variables; - _origDescription = _descriptor.description; - _origLoadFactor = _descriptor.loadFactor; - - java.util.Iterator p = _propertySets.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - ps.commit(); - } - - p = _servers.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - server.getEditable().commit(); - } + _editable.commit(); + _origVariables = _descriptor.variables; + _origDescription = _descriptor.description; + _origLoadFactor = _descriptor.loadFactor; + + java.util.Iterator p = _propertySets.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + ps.commit(); + } + + p = _servers.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + server.getEditable().commit(); + } } void restore(Backup backup) - { - for(int i = backup.backupList.size() - 1; i >= 0; --i) - { - ((Server)backup.servers.get(i)).restore(backup.backupList.get(i)); - } - _resolver = backup.resolver; + { + for(int i = backup.backupList.size() - 1; i >= 0; --i) + { + ((Server)backup.servers.get(i)).restore(backup.backupList.get(i)); + } + _resolver = backup.resolver; } ServerInstance createServer(boolean brandNew, - ServerInstanceDescriptor instanceDescriptor) - throws UpdateFailedException + ServerInstanceDescriptor instanceDescriptor) + throws UpdateFailedException { - Root root = getRoot(); - - // - // Find template - // - TemplateDescriptor templateDescriptor = - root.findServerTemplateDescriptor(instanceDescriptor.template); - - assert templateDescriptor != null; - - ServerDescriptor serverDescriptor = - (ServerDescriptor)templateDescriptor.descriptor; - - assert serverDescriptor != null; - boolean isIceBox = serverDescriptor instanceof IceBoxDescriptor; - - // - // Build resolver - // - Utils.Resolver instanceResolver = - new Utils.Resolver(_resolver, - instanceDescriptor.parameterValues, - templateDescriptor.parameterDefaults); - - String serverId = instanceResolver.substitute(serverDescriptor.id); - instanceResolver.put("server", serverId); - - // - // Create server - // - return new ServerInstance(brandNew, this, serverId, - instanceResolver, instanceDescriptor, isIceBox); + Root root = getRoot(); + + // + // Find template + // + TemplateDescriptor templateDescriptor = + root.findServerTemplateDescriptor(instanceDescriptor.template); + + assert templateDescriptor != null; + + ServerDescriptor serverDescriptor = + (ServerDescriptor)templateDescriptor.descriptor; + + assert serverDescriptor != null; + boolean isIceBox = serverDescriptor instanceof IceBoxDescriptor; + + // + // Build resolver + // + Utils.Resolver instanceResolver = + new Utils.Resolver(_resolver, + instanceDescriptor.parameterValues, + templateDescriptor.parameterDefaults); + + String serverId = instanceResolver.substitute(serverDescriptor.id); + instanceResolver.put("server", serverId); + + // + // Create server + // + return new ServerInstance(brandNew, this, serverId, + instanceResolver, instanceDescriptor, isIceBox); } PlainServer createServer(boolean brandNew, ServerDescriptor serverDescriptor) - throws UpdateFailedException + throws UpdateFailedException { - // - // Build resolver - // - Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); - String serverId = instanceResolver.substitute(serverDescriptor.id); - instanceResolver.put("server", serverId); - - // - // Create server - // - return new PlainServer(brandNew, this, serverId, - instanceResolver, serverDescriptor); + // + // Build resolver + // + Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); + String serverId = instanceResolver.substitute(serverDescriptor.id); + instanceResolver.put("server", serverId); + + // + // Create server + // + return new PlainServer(brandNew, this, serverId, + instanceResolver, serverDescriptor); } NodeUpdateDescriptor getUpdate() { - NodeUpdateDescriptor update = new NodeUpdateDescriptor(); - update.name = _id; - - // - // First: property sets - // - if(_editable.isNew()) - { - update.removePropertySets = new String[0]; - update.propertySets = _descriptor.propertySets; - } - else - { - update.removePropertySets = _editable.removedElements(PropertySet.class); - update.propertySets = new java.util.HashMap(); - - java.util.Iterator p = _propertySets.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - if(ps.getEditable().isNew() || ps.getEditable().isModified()) - { - update.propertySets.put(ps.getId(), ps.getDescriptor()); - } - } - } - - // - // Then: servers - // - if(_editable.isNew()) - { - update.removeServers = new String[0]; - } - else - { - update.removeServers = _editable.removedElements(Server.class); - } - - update.serverInstances = new java.util.LinkedList(); - update.servers = new java.util.LinkedList(); - - java.util.Iterator p = _servers.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - if(_editable.isNew() || server.getEditable().isModified() - || server.getEditable().isNew()) - { - if(server instanceof PlainServer) - { - update.servers.add(server.getDescriptor()); - } - else - { - update.serverInstances.add(server.getDescriptor()); - } - } - } - - // - // Anything in this update? - // - if(!_editable.isNew() && !_editable.isModified() - && update.removePropertySets.length == 0 - && update.propertySets.size() == 0 - && update.removeServers.length == 0 - && update.servers.size() == 0 - && update.serverInstances.size() == 0) - { - return null; - } - - if(_editable.isNew()) - { - update.variables = _descriptor.variables; - update.removeVariables = new String[0]; - update.loadFactor = new IceGrid.BoxedString(_descriptor.loadFactor); - } - else - { - if(!_descriptor.description.equals(_origDescription)) - { - update.description = new IceGrid.BoxedString(_descriptor.description); - } - - if(!_descriptor.loadFactor.equals(_origLoadFactor)) - { - update.loadFactor = new IceGrid.BoxedString(_descriptor.loadFactor); - } - - // - // Diff variables (TODO: avoid duplication with same code in Root) - // - update.variables = new java.util.TreeMap(_descriptor.variables); - java.util.List removeVariables = new java.util.LinkedList(); - - 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]); - } - - return update; + NodeUpdateDescriptor update = new NodeUpdateDescriptor(); + update.name = _id; + + // + // First: property sets + // + if(_editable.isNew()) + { + update.removePropertySets = new String[0]; + update.propertySets = _descriptor.propertySets; + } + else + { + update.removePropertySets = _editable.removedElements(PropertySet.class); + update.propertySets = new java.util.HashMap(); + + java.util.Iterator p = _propertySets.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + if(ps.getEditable().isNew() || ps.getEditable().isModified()) + { + update.propertySets.put(ps.getId(), ps.getDescriptor()); + } + } + } + + // + // Then: servers + // + if(_editable.isNew()) + { + update.removeServers = new String[0]; + } + else + { + update.removeServers = _editable.removedElements(Server.class); + } + + update.serverInstances = new java.util.LinkedList(); + update.servers = new java.util.LinkedList(); + + java.util.Iterator p = _servers.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + if(_editable.isNew() || server.getEditable().isModified() + || server.getEditable().isNew()) + { + if(server instanceof PlainServer) + { + update.servers.add(server.getDescriptor()); + } + else + { + update.serverInstances.add(server.getDescriptor()); + } + } + } + + // + // Anything in this update? + // + if(!_editable.isNew() && !_editable.isModified() + && update.removePropertySets.length == 0 + && update.propertySets.size() == 0 + && update.removeServers.length == 0 + && update.servers.size() == 0 + && update.serverInstances.size() == 0) + { + return null; + } + + if(_editable.isNew()) + { + update.variables = _descriptor.variables; + update.removeVariables = new String[0]; + update.loadFactor = new IceGrid.BoxedString(_descriptor.loadFactor); + } + else + { + if(!_descriptor.description.equals(_origDescription)) + { + update.description = new IceGrid.BoxedString(_descriptor.description); + } + + if(!_descriptor.loadFactor.equals(_origLoadFactor)) + { + update.loadFactor = new IceGrid.BoxedString(_descriptor.loadFactor); + } + + // + // Diff variables (TODO: avoid duplication with same code in Root) + // + update.variables = new java.util.TreeMap(_descriptor.variables); + java.util.List removeVariables = new java.util.LinkedList(); + + 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]); + } + + return update; } void update(NodeUpdateDescriptor update, - java.util.Set serverTemplates, java.util.Set serviceTemplates) - throws UpdateFailedException + java.util.Set serverTemplates, java.util.Set serviceTemplates) + throws UpdateFailedException { - Root root = getRoot(); - - java.util.Vector newServers = new java.util.Vector(); - java.util.Vector updatedServers = new java.util.Vector(); - - if(update != null) - { - // - // Description - // - if(update.description != null) - { - _descriptor.description = update.description.value; - _origDescription = _descriptor.description; - } - - // - // Load factor - // - if(update.loadFactor != null) - { - _descriptor.loadFactor = update.loadFactor.value; - _origLoadFactor = _descriptor.loadFactor; - } - - // - // Variables - // - for(int i = 0; i < update.removeVariables.length; ++i) - { - _descriptor.variables.remove(update.removeVariables[i]); - } - _descriptor.variables.putAll(update.variables); - - - // - // Property Sets - // - removePropertySets(update.removePropertySets); - for(int i = 0; i < update.removePropertySets.length; ++i) - { - _descriptor.propertySets.remove(update.removePropertySets[i]); - } - - java.util.Vector newPropertySets = new java.util.Vector(); - java.util.Vector updatedPropertySets = new java.util.Vector(); - - java.util.Iterator p = update.propertySets.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - String id = (String)entry.getKey(); - PropertySetDescriptor psd = (PropertySetDescriptor)entry.getValue(); - - // - // Lookup named property set - // - PropertySet ps = findPropertySet(id); - if(ps != null) - { - ps.rebuild(psd); - updatedPropertySets.add(ps); - } - else - { - ps = new PropertySet(false, this, id, id, psd); - newPropertySets.add(ps); - _descriptor.propertySets.put(id, psd); - } - } - childrenChanged(updatedPropertySets); - insertPropertySets(newPropertySets, true); - - - // - // Update _descriptor - // - for(int i = 0; i < update.removeServers.length; ++i) - { - Server server = findServer(update.removeServers[i]); - removeDescriptor(server); - } - - // - // One big set of removes - // - removeServers(update.removeServers); - - // - // One big set of updates, followed by inserts - // - p = update.serverInstances.iterator(); - while(p.hasNext()) - { - ServerInstanceDescriptor instanceDescriptor = - (ServerInstanceDescriptor)p.next(); - - // - // Find template - // - TemplateDescriptor templateDescriptor = - root.findServerTemplateDescriptor(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 servers - // - ServerInstance server = (ServerInstance)findServer(serverId); - if(server != null) - { - removeDescriptor(server); - server.rebuild(instanceResolver, instanceDescriptor, - serverDescriptor instanceof IceBoxDescriptor); - updatedServers.add(server); - _descriptor.serverInstances.add(instanceDescriptor); - } - else - { - server = new ServerInstance(false, this, serverId, instanceResolver, - instanceDescriptor, - serverDescriptor instanceof IceBoxDescriptor); - newServers.add(server); - _descriptor.serverInstances.add(instanceDescriptor); - } - } - - // - // Plain servers - // - p = update.servers.iterator(); - while(p.hasNext()) - { - ServerDescriptor serverDescriptor = (ServerDescriptor)p.next(); - - // - // Build resolver - // - Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); - String serverId = instanceResolver.substitute(serverDescriptor.id); - instanceResolver.put("server", serverId); - - // - // Lookup server - // - PlainServer server = (PlainServer)findServer(serverId); - - if(server != null) - { - removeDescriptor(server); - server.rebuild(instanceResolver, serverDescriptor); - updatedServers.add(server); - _descriptor.servers.add(serverDescriptor); - } - else - { - server = new PlainServer(false, this, serverId, instanceResolver, - serverDescriptor); - newServers.add(server); - _descriptor.servers.add(serverDescriptor); - } - } - } - - // - // Find servers affected by template updates - // - java.util.Set serverSet = new java.util.HashSet(); - - java.util.Iterator p = serverTemplates.iterator(); - while(p.hasNext()) - { - String template = (String)p.next(); - java.util.List serverInstances = findServerInstances(template); - java.util.Iterator q = serverInstances.iterator(); - while(q.hasNext()) - { - ServerInstance server = (ServerInstance)q.next(); - if(!updatedServers.contains(server) && !newServers.contains(server)) - { - serverSet.add(server); - } - } - } - - // - // Servers affected by service-template updates - // - p = serviceTemplates.iterator(); - while(p.hasNext()) - { - java.util.List serviceInstances = - findServiceInstances((String)p.next()); - java.util.Iterator q = serviceInstances.iterator(); - while(q.hasNext()) - { - ServiceInstance service = (ServiceInstance)q.next(); - Server server = (Server)service.getParent().getParent(); - if(!updatedServers.contains(server) && !newServers.contains(server)) - { - serverSet.add(server); - } - } - } - - // - // Rebuild these servers - // - p = serverSet.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - - if(server instanceof PlainServer) - { - PlainServer ps = (PlainServer)server; - ServerDescriptor serverDescriptor = (ServerDescriptor)ps.getDescriptor(); - Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); - - String serverId = instanceResolver.substitute(serverDescriptor.id); - assert serverId.equals(ps.getId()); - - ps.rebuild(instanceResolver, serverDescriptor); - } - else - { - ServerInstance si = (ServerInstance)server; - ServerInstanceDescriptor instanceDescriptor = (ServerInstanceDescriptor)si.getDescriptor(); - - TemplateDescriptor templateDescriptor = - root.findServerTemplateDescriptor(instanceDescriptor.template); - assert templateDescriptor != null; - - ServerDescriptor serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor; - assert serverDescriptor != null; - - Utils.Resolver instanceResolver = - new Utils.Resolver(_resolver, - instanceDescriptor.parameterValues, - templateDescriptor.parameterDefaults); - - String serverId = instanceResolver.substitute(serverDescriptor.id); - assert serverId.equals(si.getId()); - - si.rebuild(instanceResolver, instanceDescriptor, - serverDescriptor instanceof IceBoxDescriptor); - } - updatedServers.add(server); - } - - childrenChanged(updatedServers); - insertServers(newServers, true); + Root root = getRoot(); + + java.util.Vector newServers = new java.util.Vector(); + java.util.Vector updatedServers = new java.util.Vector(); + + if(update != null) + { + // + // Description + // + if(update.description != null) + { + _descriptor.description = update.description.value; + _origDescription = _descriptor.description; + } + + // + // Load factor + // + if(update.loadFactor != null) + { + _descriptor.loadFactor = update.loadFactor.value; + _origLoadFactor = _descriptor.loadFactor; + } + + // + // Variables + // + for(int i = 0; i < update.removeVariables.length; ++i) + { + _descriptor.variables.remove(update.removeVariables[i]); + } + _descriptor.variables.putAll(update.variables); + + + // + // Property Sets + // + removePropertySets(update.removePropertySets); + for(int i = 0; i < update.removePropertySets.length; ++i) + { + _descriptor.propertySets.remove(update.removePropertySets[i]); + } + + java.util.Vector newPropertySets = new java.util.Vector(); + java.util.Vector updatedPropertySets = new java.util.Vector(); + + java.util.Iterator p = update.propertySets.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + String id = (String)entry.getKey(); + PropertySetDescriptor psd = (PropertySetDescriptor)entry.getValue(); + + // + // Lookup named property set + // + PropertySet ps = findPropertySet(id); + if(ps != null) + { + ps.rebuild(psd); + updatedPropertySets.add(ps); + } + else + { + ps = new PropertySet(false, this, id, id, psd); + newPropertySets.add(ps); + _descriptor.propertySets.put(id, psd); + } + } + childrenChanged(updatedPropertySets); + insertPropertySets(newPropertySets, true); + + + // + // Update _descriptor + // + for(int i = 0; i < update.removeServers.length; ++i) + { + Server server = findServer(update.removeServers[i]); + removeDescriptor(server); + } + + // + // One big set of removes + // + removeServers(update.removeServers); + + // + // One big set of updates, followed by inserts + // + p = update.serverInstances.iterator(); + while(p.hasNext()) + { + ServerInstanceDescriptor instanceDescriptor = + (ServerInstanceDescriptor)p.next(); + + // + // Find template + // + TemplateDescriptor templateDescriptor = + root.findServerTemplateDescriptor(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 servers + // + ServerInstance server = (ServerInstance)findServer(serverId); + if(server != null) + { + removeDescriptor(server); + server.rebuild(instanceResolver, instanceDescriptor, + serverDescriptor instanceof IceBoxDescriptor); + updatedServers.add(server); + _descriptor.serverInstances.add(instanceDescriptor); + } + else + { + server = new ServerInstance(false, this, serverId, instanceResolver, + instanceDescriptor, + serverDescriptor instanceof IceBoxDescriptor); + newServers.add(server); + _descriptor.serverInstances.add(instanceDescriptor); + } + } + + // + // Plain servers + // + p = update.servers.iterator(); + while(p.hasNext()) + { + ServerDescriptor serverDescriptor = (ServerDescriptor)p.next(); + + // + // Build resolver + // + Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); + String serverId = instanceResolver.substitute(serverDescriptor.id); + instanceResolver.put("server", serverId); + + // + // Lookup server + // + PlainServer server = (PlainServer)findServer(serverId); + + if(server != null) + { + removeDescriptor(server); + server.rebuild(instanceResolver, serverDescriptor); + updatedServers.add(server); + _descriptor.servers.add(serverDescriptor); + } + else + { + server = new PlainServer(false, this, serverId, instanceResolver, + serverDescriptor); + newServers.add(server); + _descriptor.servers.add(serverDescriptor); + } + } + } + + // + // Find servers affected by template updates + // + java.util.Set serverSet = new java.util.HashSet(); + + java.util.Iterator p = serverTemplates.iterator(); + while(p.hasNext()) + { + String template = (String)p.next(); + java.util.List serverInstances = findServerInstances(template); + java.util.Iterator q = serverInstances.iterator(); + while(q.hasNext()) + { + ServerInstance server = (ServerInstance)q.next(); + if(!updatedServers.contains(server) && !newServers.contains(server)) + { + serverSet.add(server); + } + } + } + + // + // Servers affected by service-template updates + // + p = serviceTemplates.iterator(); + while(p.hasNext()) + { + java.util.List serviceInstances = + findServiceInstances((String)p.next()); + java.util.Iterator q = serviceInstances.iterator(); + while(q.hasNext()) + { + ServiceInstance service = (ServiceInstance)q.next(); + Server server = (Server)service.getParent().getParent(); + if(!updatedServers.contains(server) && !newServers.contains(server)) + { + serverSet.add(server); + } + } + } + + // + // Rebuild these servers + // + p = serverSet.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + + if(server instanceof PlainServer) + { + PlainServer ps = (PlainServer)server; + ServerDescriptor serverDescriptor = (ServerDescriptor)ps.getDescriptor(); + Utils.Resolver instanceResolver = new Utils.Resolver(_resolver); + + String serverId = instanceResolver.substitute(serverDescriptor.id); + assert serverId.equals(ps.getId()); + + ps.rebuild(instanceResolver, serverDescriptor); + } + else + { + ServerInstance si = (ServerInstance)server; + ServerInstanceDescriptor instanceDescriptor = (ServerInstanceDescriptor)si.getDescriptor(); + + TemplateDescriptor templateDescriptor = + root.findServerTemplateDescriptor(instanceDescriptor.template); + assert templateDescriptor != null; + + ServerDescriptor serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor; + assert serverDescriptor != null; + + Utils.Resolver instanceResolver = + new Utils.Resolver(_resolver, + instanceDescriptor.parameterValues, + templateDescriptor.parameterDefaults); + + String serverId = instanceResolver.substitute(serverDescriptor.id); + assert serverId.equals(si.getId()); + + si.rebuild(instanceResolver, instanceDescriptor, + serverDescriptor instanceof IceBoxDescriptor); + } + updatedServers.add(server); + } + + childrenChanged(updatedServers); + insertServers(newServers, true); } Node(boolean brandNew, TreeNode parent, String nodeName, NodeDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - super(parent, nodeName); - _editable = new Editable(brandNew); - - _ephemeral = false; - _descriptor = descriptor; - - _origVariables = _descriptor.variables; - _origDescription = _descriptor.description; - _origLoadFactor = _descriptor.loadFactor; - - _resolver = new Utils.Resolver(new java.util.Map[] - {_descriptor.variables, getRoot().getVariables()}); - - _resolver.put("application", getRoot().getId()); - _resolver.put("node", _id); - - // - // Property Sets - // - java.util.Iterator p = _descriptor.propertySets.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String id = (String)entry.getKey(); - insertPropertySet(new PropertySet(false, this, - id, id, - (PropertySetDescriptor)entry.getValue()), - false); - } - - // - // Template instances - // - p = _descriptor.serverInstances.iterator(); - while(p.hasNext()) - { - ServerInstanceDescriptor instanceDescriptor = - (ServerInstanceDescriptor)p.next(); - - insertServer(createServer(false, instanceDescriptor), false); - } - - // - // Plain servers - // - p = _descriptor.servers.iterator(); - while(p.hasNext()) - { - ServerDescriptor serverDescriptor = (ServerDescriptor)p.next(); - insertServer(createServer(false, serverDescriptor), false); - } + super(parent, nodeName); + _editable = new Editable(brandNew); + + _ephemeral = false; + _descriptor = descriptor; + + _origVariables = _descriptor.variables; + _origDescription = _descriptor.description; + _origLoadFactor = _descriptor.loadFactor; + + _resolver = new Utils.Resolver(new java.util.Map[] + {_descriptor.variables, getRoot().getVariables()}); + + _resolver.put("application", getRoot().getId()); + _resolver.put("node", _id); + + // + // Property Sets + // + java.util.Iterator p = _descriptor.propertySets.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String id = (String)entry.getKey(); + insertPropertySet(new PropertySet(false, this, + id, id, + (PropertySetDescriptor)entry.getValue()), + false); + } + + // + // Template instances + // + p = _descriptor.serverInstances.iterator(); + while(p.hasNext()) + { + ServerInstanceDescriptor instanceDescriptor = + (ServerInstanceDescriptor)p.next(); + + insertServer(createServer(false, instanceDescriptor), false); + } + + // + // Plain servers + // + p = _descriptor.servers.iterator(); + while(p.hasNext()) + { + ServerDescriptor serverDescriptor = (ServerDescriptor)p.next(); + insertServer(createServer(false, serverDescriptor), false); + } } Node(TreeNode parent, String nodeName, NodeDescriptor descriptor) { - super(parent, nodeName); - _editable = new Editable(false); - _ephemeral = true; - _descriptor = descriptor; + super(parent, nodeName); + _editable = new Editable(false); + _ephemeral = true; + _descriptor = descriptor; } java.util.List findServerInstances(String template) { - java.util.List result = new java.util.LinkedList(); - java.util.Iterator p = _servers.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - - if(server instanceof ServerInstance) - { - ServerInstanceDescriptor instanceDescriptor - = (ServerInstanceDescriptor)server.getDescriptor(); - - if(instanceDescriptor.template.equals(template)) - { - result.add(server); - } - } - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _servers.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + + if(server instanceof ServerInstance) + { + ServerInstanceDescriptor instanceDescriptor + = (ServerInstanceDescriptor)server.getDescriptor(); + + if(instanceDescriptor.template.equals(template)) + { + result.add(server); + } + } + } + return result; } void removeServerInstances(String template) { - java.util.List toRemove = new java.util.LinkedList(); - - java.util.Iterator p = _servers.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - - if(server instanceof ServerInstance) - { - ServerInstanceDescriptor instanceDescriptor - = (ServerInstanceDescriptor)server.getDescriptor(); - - if(instanceDescriptor.template.equals(template)) - { - // - // Remove instance - // - removeDescriptor(instanceDescriptor); - String id = ((TreeNode)server).getId(); - _editable.removeElement(id, server.getEditable(), Server.class); - toRemove.add(id); - } - } - } - - if(toRemove.size() > 0) - { - removeServers((String[])toRemove.toArray(new String[0])); - } + java.util.List toRemove = new java.util.LinkedList(); + + java.util.Iterator p = _servers.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + + if(server instanceof ServerInstance) + { + ServerInstanceDescriptor instanceDescriptor + = (ServerInstanceDescriptor)server.getDescriptor(); + + if(instanceDescriptor.template.equals(template)) + { + // + // Remove instance + // + removeDescriptor(instanceDescriptor); + String id = ((TreeNode)server).getId(); + _editable.removeElement(id, server.getEditable(), Server.class); + toRemove.add(id); + } + } + } + + if(toRemove.size() > 0) + { + removeServers((String[])toRemove.toArray(new String[0])); + } } java.util.List findServiceInstances(String template) { - java.util.List result = new java.util.LinkedList(); - java.util.Iterator p = _servers.iterator(); - while(p.hasNext()) - { - Object o = p.next(); - if(o instanceof PlainServer) - { - result.addAll(((PlainServer)o).findServiceInstances(template)); - } - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _servers.iterator(); + while(p.hasNext()) + { + Object o = p.next(); + if(o instanceof PlainServer) + { + result.addAll(((PlainServer)o).findServiceInstances(template)); + } + } + return result; } void removeServiceInstances(String template) - { - java.util.Iterator p = _servers.iterator(); - while(p.hasNext()) - { - Object o = p.next(); - if(o instanceof PlainServer) - { - ((PlainServer)o).removeServiceInstances(template); - } - } + { + java.util.Iterator p = _servers.iterator(); + while(p.hasNext()) + { + Object o = p.next(); + if(o instanceof PlainServer) + { + ((PlainServer)o).removeServiceInstances(template); + } + } } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } public void tryAdd(String id, PropertySetDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertPropertySet(new PropertySet(true, this, id, id, descriptor), - true); - _descriptor.propertySets.put(id, descriptor); + insertPropertySet(new PropertySet(true, this, id, id, descriptor), + true); + _descriptor.propertySets.put(id, descriptor); } public void tryRename(String oldId, String oldId2, String newId) - throws UpdateFailedException + throws UpdateFailedException { - PropertySet oldChild = findPropertySet(oldId); - assert oldChild != null; - removePropertySet(oldChild); - PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); - - try - { - insertPropertySet( - new PropertySet(true, this, newId, newId, descriptor), - true); - } - catch(UpdateFailedException ex) - { - try - { - insertPropertySet(oldChild, true); - } - catch(UpdateFailedException ufe) - { - assert false; - } - throw ex; - } - - _editable.removeElement(oldId, oldChild.getEditable(), PropertySet.class); - _descriptor.propertySets.remove(oldId); - _descriptor.propertySets.put(newId, descriptor); + PropertySet oldChild = findPropertySet(oldId); + assert oldChild != null; + removePropertySet(oldChild); + PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); + + try + { + insertPropertySet( + new PropertySet(true, this, newId, newId, descriptor), + true); + } + catch(UpdateFailedException ex) + { + try + { + insertPropertySet(oldChild, true); + } + catch(UpdateFailedException ufe) + { + assert false; + } + throw ex; + } + + _editable.removeElement(oldId, oldChild.getEditable(), PropertySet.class); + _descriptor.propertySets.remove(oldId); + _descriptor.propertySets.put(newId, descriptor); } void tryAdd(ServerInstanceDescriptor instanceDescriptor, - boolean addDescriptor) throws UpdateFailedException + boolean addDescriptor) throws UpdateFailedException { - insertServer(createServer(true, instanceDescriptor), true); + insertServer(createServer(true, instanceDescriptor), true); - if(addDescriptor) - { - _descriptor.serverInstances.add(instanceDescriptor); - } + if(addDescriptor) + { + _descriptor.serverInstances.add(instanceDescriptor); + } } void tryAdd(ServerDescriptor serverDescriptor, - boolean addDescriptor) throws UpdateFailedException + boolean addDescriptor) throws UpdateFailedException { - insertServer(createServer(true, serverDescriptor), true); + insertServer(createServer(true, serverDescriptor), true); - if(addDescriptor) - { - _descriptor.servers.add(serverDescriptor); - } + if(addDescriptor) + { + _descriptor.servers.add(serverDescriptor); + } } void removeDescriptor(Server server) { - if(server instanceof ServerInstance) - { - removeDescriptor((ServerInstanceDescriptor)server.getDescriptor()); - } - else - { - removeDescriptor((ServerDescriptor)server.getDescriptor()); - } + if(server instanceof ServerInstance) + { + removeDescriptor((ServerInstanceDescriptor)server.getDescriptor()); + } + else + { + removeDescriptor((ServerDescriptor)server.getDescriptor()); + } } void removeDescriptor(ServerDescriptor sd) { - // - // A straight remove uses equals(), which is not the desired behavior - // - java.util.Iterator p = _descriptor.servers.iterator(); - while(p.hasNext()) - { - if(sd == p.next()) - { - p.remove(); - break; - } - } + // + // A straight remove uses equals(), which is not the desired behavior + // + java.util.Iterator p = _descriptor.servers.iterator(); + while(p.hasNext()) + { + if(sd == p.next()) + { + p.remove(); + break; + } + } } void removeDescriptor(ServerInstanceDescriptor sd) { - // - // A straight remove uses equals(), which is not the desired behavior - // - java.util.Iterator p = _descriptor.serverInstances.iterator(); - while(p.hasNext()) - { - if(sd == p.next()) - { - p.remove(); - break; - } - } + // + // A straight remove uses equals(), which is not the desired behavior + // + java.util.Iterator p = _descriptor.serverInstances.iterator(); + while(p.hasNext()) + { + if(sd == p.next()) + { + p.remove(); + break; + } + } } private void newPropertySet(PropertySetDescriptor descriptor) { - String id = makeNewChildId("PropertySet"); - - PropertySet ps = new PropertySet(this, id, descriptor); - try - { - insertPropertySet(ps, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(ps); + String id = makeNewChildId("PropertySet"); + + PropertySet ps = new PropertySet(this, id, descriptor); + try + { + insertPropertySet(ps, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(ps); } private void newServer(ServerDescriptor descriptor) { - descriptor.id = makeNewChildId(descriptor.id); - - PlainServer server = new PlainServer(this, descriptor.id, descriptor); - try - { - insertServer(server, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(server); + descriptor.id = makeNewChildId(descriptor.id); + + PlainServer server = new PlainServer(this, descriptor.id, descriptor); + try + { + insertServer(server, true); + } + catch(UpdateFailedException e) + { + assert false; + } + 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 = root.findServerTemplate(descriptor.template); - - if(t == null) - { - if(root.getServerTemplates().getChildCount() == 0) - { - JOptionPane.showMessageDialog( - getCoordinator().getMainFrame(), - "You need to create a server template before you can create a server from a template.", - "No Server Template", - JOptionPane.INFORMATION_MESSAGE); - return; - } - - t = (ServerTemplate)root.getServerTemplates().getChildAt(0); - descriptor.template = t.getId(); - descriptor.parameterValues = new java.util.HashMap(); - } - - ServerInstance server = new ServerInstance(this, id, descriptor); - try - { - insertServer(server, true); - } - catch(UpdateFailedException e) - { - assert false; - } - root.setSelectedNode(server); + String id = makeNewChildId("NewServer"); + Root root = getRoot(); + + // + // Make sure descriptor.template points to a real template + // + ServerTemplate t = root.findServerTemplate(descriptor.template); + + if(t == null) + { + if(root.getServerTemplates().getChildCount() == 0) + { + JOptionPane.showMessageDialog( + getCoordinator().getMainFrame(), + "You need to create a server template before you can create a server from a template.", + "No Server Template", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + t = (ServerTemplate)root.getServerTemplates().getChildAt(0); + descriptor.template = t.getId(); + descriptor.parameterValues = new java.util.HashMap(); + } + + ServerInstance server = new ServerInstance(this, id, descriptor); + try + { + insertServer(server, true); + } + catch(UpdateFailedException e) + { + assert false; + } + root.setSelectedNode(server); } private NodeDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/NodeEditor.java b/java/src/IceGridGUI/Application/NodeEditor.java index 78ecd6392b3..b8ca49a9302 100755 --- a/java/src/IceGridGUI/Application/NodeEditor.java +++ b/java/src/IceGridGUI/Application/NodeEditor.java @@ -32,232 +32,232 @@ class NodeEditor extends Editor { protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Node Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Node Properties"); } protected boolean applyUpdate(boolean refresh) { - Root root = _target.getRoot(); + 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().trim(), descriptor); - } - catch(UpdateFailedException e) - { - // - // Add back ephemeral child - // - try - { - nodes.insertChild(_target, true); - } - catch(UpdateFailedException die) - { - assert false; - } - root.setSelectedNode(_target); + 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().trim(), 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 false; - } - - // - // Success - // - _target = nodes.findChildWithDescriptor(descriptor); - root.updated(); - if(refresh) - { - 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 false; - } - - java.util.Iterator p = editables.iterator(); - while(p.hasNext()) - { - Editable editable = (Editable)p.next(); - editable.markModified(); - } + JOptionPane.showMessageDialog( + root.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + // + // Success + // + _target = nodes.findChildWithDescriptor(descriptor); + root.updated(); + if(refresh) + { + 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 false; + } + + java.util.Iterator p = editables.iterator(); + while(p.hasNext()) + { + Editable editable = (Editable)p.next(); + editable.markModified(); + } - ((Node)_target).getEditable().markModified(); - root.updated(); - } + ((Node)_target).getEditable().markModified(); + root.updated(); + } - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } Utils.Resolver getDetailResolver() { - if(_target.getCoordinator().substitute()) - { - return _target.getResolver(); - } - else - { - return null; - } + if(_target.getCoordinator().substitute()) + { + return _target.getResolver(); + } + else + { + return null; + } } NodeEditor() { - _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 - // - _variables = new MapField(this, "Name", "Value", false); + _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 + // + _variables = new MapField(this, "Name", "Value", false); - _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>"); + _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("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("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"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_variables); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + builder.append("Variables"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_variables); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); - builder.append("Load Factor"); - builder.append(_loadFactor, 3); - builder.nextLine(); + builder.append("Load Factor"); + builder.append(_loadFactor, 3); + builder.nextLine(); } boolean isSimpleUpdate() { - NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor(); - return (_variables.get().equals(descriptor.variables)); + NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor(); + return (_variables.get().equals(descriptor.variables)); } void writeDescriptor() { - NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor(); - descriptor.description = _description.getText(); - descriptor.variables = _variables.get(); - descriptor.loadFactor = _loadFactor.getText().trim(); - } + NodeDescriptor descriptor = (NodeDescriptor)_target.getDescriptor(); + descriptor.description = _description.getText(); + descriptor.variables = _variables.get(); + descriptor.loadFactor = _loadFactor.getText().trim(); + } protected boolean validate() { - return check(new String[]{"Name", _name.getText().trim()}); + return check(new String[]{"Name", _name.getText().trim()}); } void show(Node node) { - detectUpdates(false); - _target = node; - - Utils.Resolver resolver = getDetailResolver(); - boolean isEditable = (resolver == null); + 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(); + _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); + _description.setText( + Utils.substitute(descriptor.description, resolver)); + _description.setEditable(isEditable); + _description.setOpaque(isEditable); - _variables.set(descriptor.variables, resolver, isEditable); + _variables.set(descriptor.variables, resolver, isEditable); - _loadFactor.setText( - Utils.substitute(descriptor.loadFactor, resolver)); - _loadFactor.setEditable(isEditable); + _loadFactor.setText( + Utils.substitute(descriptor.loadFactor, resolver)); + _loadFactor.setEditable(isEditable); - _applyButton.setEnabled(node.isEphemeral()); - _discardButton.setEnabled(node.isEphemeral()); - detectUpdates(true); + _applyButton.setEnabled(node.isEphemeral()); + _discardButton.setEnabled(node.isEphemeral()); + detectUpdates(true); } private JTextField _name = new JTextField(20); diff --git a/java/src/IceGridGUI/Application/Nodes.java b/java/src/IceGridGUI/Application/Nodes.java index c8c021d5ce1..5da3acee87d 100755 --- a/java/src/IceGridGUI/Application/Nodes.java +++ b/java/src/IceGridGUI/Application/Nodes.java @@ -22,75 +22,75 @@ class Nodes extends ListTreeNode static public java.util.Map copyDescriptors(java.util.Map descriptors) { - java.util.Map copy = new java.util.HashMap(); - java.util.Iterator p = descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - copy.put(entry.getKey(), - Node.copyDescriptor( - (NodeDescriptor)entry.getValue())); - } - return copy; + java.util.Map copy = new java.util.HashMap(); + java.util.Iterator p = descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + copy.put(entry.getKey(), + Node.copyDescriptor( + (NodeDescriptor)entry.getValue())); + } + return copy; } public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; + boolean[] actions = new boolean[ACTION_COUNT]; - Object descriptor = getCoordinator().getClipboard(); - if(descriptor != null) - { - actions[PASTE] = descriptor instanceof NodeDescriptor; - } - actions[NEW_NODE] = true; - return actions; + Object descriptor = getCoordinator().getClipboard(); + if(descriptor != null) + { + actions[PASTE] = descriptor instanceof NodeDescriptor; + } + actions[NEW_NODE] = true; + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_NODE)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_NODE)); + } + actions.setTarget(this); + return _popup; } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - newNode(Node.copyDescriptor((NodeDescriptor)descriptor)); + Object descriptor = getCoordinator().getClipboard(); + newNode(Node.copyDescriptor((NodeDescriptor)descriptor)); } public void newNode() { - newNode(new NodeDescriptor( - new java.util.TreeMap(), - new java.util.LinkedList(), - new java.util.LinkedList(), - "", - "", - new java.util.HashMap())); + newNode(new NodeDescriptor( + new java.util.TreeMap(), + new java.util.LinkedList(), + new java.util.LinkedList(), + "", + "", + new java.util.HashMap())); } Nodes(TreeNode parent, java.util.Map descriptors) - throws UpdateFailedException + throws UpdateFailedException { - super(false, parent, "Nodes"); - _descriptors = descriptors; + super(false, parent, "Nodes"); + _descriptors = descriptors; - 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(); - insertChild(new Node(false, this, nodeName, nodeDescriptor), false); - } + 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(); + insertChild(new Node(false, this, nodeName, nodeDescriptor), false); + } } // @@ -99,216 +99,216 @@ class Nodes extends ListTreeNode // void rebuild() throws UpdateFailedException { - java.util.List backupList = new java.util.Vector(); - java.util.List editables = new java.util.LinkedList(); + java.util.List backupList = new java.util.Vector(); + java.util.List editables = new java.util.LinkedList(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - try - { - backupList.add(node.rebuild(editables)); - } - catch(UpdateFailedException e) - { - for(int i = backupList.size() - 1; i >= 0; --i) - { - ((Node)_children.get(i)).restore((Node.Backup)backupList.get(i)); - } - throw e; - } - } + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + try + { + backupList.add(node.rebuild(editables)); + } + catch(UpdateFailedException e) + { + for(int i = backupList.size() - 1; i >= 0; --i) + { + ((Node)_children.get(i)).restore((Node.Backup)backupList.get(i)); + } + throw e; + } + } - // - // Success - // - p = editables.iterator(); - while(p.hasNext()) - { - Editable editable = (Editable)p.next(); - editable.markModified(); - } + // + // Success + // + p = editables.iterator(); + while(p.hasNext()) + { + Editable editable = (Editable)p.next(); + editable.markModified(); + } } void commit() { - _editable.commit(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - node.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(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - NodeUpdateDescriptor d = node.getUpdate(); - if(d != null) - { - updates.add(d); - } - } - return updates; + java.util.LinkedList updates = new java.util.LinkedList(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + NodeUpdateDescriptor d = node.getUpdate(); + if(d != null) + { + updates.add(d); + } + } + return updates; } void removeServerInstances(String templateId) { - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - node.removeServerInstances(templateId); - } + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + node.removeServerInstances(templateId); + } } java.util.List findServiceInstances(String template) { - java.util.List result = new java.util.LinkedList(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - result.addAll(node.findServiceInstances(template)); - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + result.addAll(node.findServiceInstances(template)); + } + return result; } void removeServiceInstances(String templateId) { - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - node.removeServiceInstances(templateId); - } + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + node.removeServiceInstances(templateId); + } } void update(java.util.List updates, String[] removeNodes, - java.util.Set serverTemplates, java.util.Set serviceTemplates) - throws UpdateFailedException + java.util.Set serverTemplates, java.util.Set serviceTemplates) + throws UpdateFailedException { - Root root = getRoot(); + Root root = getRoot(); - // - // Note: _descriptors has already the nodes removed but - // needs to get the updated and new NodeDescriptors - // + // + // Note: _descriptors has already the nodes removed but + // needs to get the updated and new NodeDescriptors + // - // - // One big set of removes - // - removeChildren(removeNodes); - - // - // One big set of updates, followed by inserts - // - java.util.Vector newChildren = new java.util.Vector(); - java.util.Set updatedNodes = new java.util.HashSet(); - - java.util.Iterator p = updates.iterator(); - while(p.hasNext()) - { - NodeUpdateDescriptor update = (NodeUpdateDescriptor)p.next(); - Node node = findNode(update.name); + // + // One big set of removes + // + removeChildren(removeNodes); + + // + // One big set of updates, followed by inserts + // + java.util.Vector newChildren = new java.util.Vector(); + java.util.Set updatedNodes = new java.util.HashSet(); + + java.util.Iterator p = updates.iterator(); + while(p.hasNext()) + { + NodeUpdateDescriptor update = (NodeUpdateDescriptor)p.next(); + Node node = findNode(update.name); - if(node == null) - { - NodeDescriptor nodeDescriptor = new NodeDescriptor(update.variables, - update.serverInstances, - update.servers, - update.loadFactor.value, - update.description.value, - new java.util.HashMap()); - _descriptors.put(update.name, nodeDescriptor); - node = new Node(false, this, update.name, nodeDescriptor); - newChildren.add(node); - } - else - { - node.update(update, serverTemplates, serviceTemplates); - updatedNodes.add(node); - } - } + if(node == null) + { + NodeDescriptor nodeDescriptor = new NodeDescriptor(update.variables, + update.serverInstances, + update.servers, + update.loadFactor.value, + update.description.value, + new java.util.HashMap()); + _descriptors.put(update.name, nodeDescriptor); + node = new Node(false, this, update.name, nodeDescriptor); + newChildren.add(node); + } + else + { + node.update(update, serverTemplates, serviceTemplates); + updatedNodes.add(node); + } + } - // - // Some nodes are only affected by template updates - // - p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - if(!updatedNodes.contains(node)) - { - node.update(null, serverTemplates, serviceTemplates); - } - } - - insertChildren(newChildren, true); + // + // Some nodes are only affected by template updates + // + p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + if(!updatedNodes.contains(node)) + { + node.update(null, serverTemplates, serviceTemplates); + } + } + + insertChildren(newChildren, true); } Node findNode(String nodeName) { - return (Node)findChild(nodeName); + return (Node)findChild(nodeName); } java.util.List findServerInstances(String template) { - java.util.List result = new java.util.LinkedList(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - result.addAll(node.findServerInstances(template)); - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + result.addAll(node.findServerInstances(template)); + } + return result; } void addDescriptor(String nodeName, NodeDescriptor descriptor) { - _descriptors.put(nodeName, descriptor); + _descriptors.put(nodeName, descriptor); } void removeDescriptor(String nodeName) { - _descriptors.remove(nodeName); + _descriptors.remove(nodeName); } Object getDescriptor() { - return _descriptors; + return _descriptors; } void tryAdd(String nodeName, NodeDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - Node node = new Node(true, this, nodeName, descriptor); - insertChild(node, true); - _descriptors.put(nodeName, descriptor); + Node node = new Node(true, this, nodeName, descriptor); + insertChild(node, true); + _descriptors.put(nodeName, descriptor); } private void newNode(NodeDescriptor descriptor) { - String name = makeNewChildId("NewNode"); - - Node node = new Node(this, name, descriptor); - try - { - insertChild(node, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(node); + String name = makeNewChildId("NewNode"); + + Node node = new Node(this, name, descriptor); + try + { + insertChild(node, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(node); } diff --git a/java/src/IceGridGUI/Application/ParameterValuesField.java b/java/src/IceGridGUI/Application/ParameterValuesField.java index fbb4cc25b56..8976e461996 100755 --- a/java/src/IceGridGUI/Application/ParameterValuesField.java +++ b/java/src/IceGridGUI/Application/ParameterValuesField.java @@ -35,155 +35,155 @@ public class ParameterValuesField extends JTable { public ParameterValuesField(Editor editor) { - _editor = editor; + _editor = editor; - _columnNames = new java.util.Vector(2); - _columnNames.add("Name"); - _columnNames.add("Value"); + _columnNames = new java.util.Vector(2); + _columnNames.add("Name"); + _columnNames.add("Value"); - _useDefaultCombo.setEditable(true); - _notSetCombo.setEditable(true); + _useDefaultCombo.setEditable(true); + _notSetCombo.setEditable(true); } public void set(java.util.List names, - java.util.Map values, - java.util.Map defaultValues, - final Utils.Resolver resolver) + java.util.Map values, + java.util.Map defaultValues, + final Utils.Resolver resolver) { - // - // Transform map into vector of vectors - // - java.util.Vector vector = new java.util.Vector(names.size()); - java.util.Iterator p = names.iterator(); - - _hasDefault = new boolean[names.size()]; - int i = 0; - - while(p.hasNext()) - { - java.util.Vector row = new java.util.Vector(2); - String name = (String)p.next(); - row.add(name); - - _hasDefault[i] = (defaultValues.get(name) != null); - - Object val = values.get(name); - if(val == null) - { - row.add(_hasDefault[i] ? _useDefault : _notSet); - } - else - { - row.add(Utils.substitute((String)val, resolver)); - } - vector.add(row); - i++; - } - - _model = new DefaultTableModel(vector, _columnNames) - { - public boolean isCellEditable(int row, int column) - { - if(resolver == null) - { - return column > 0; - } - else - { - return false; - } - } - }; - - _model.addTableModelListener(new TableModelListener() - { - public void tableChanged(TableModelEvent e) - { - _editor.updated(); - } - }); - setModel(_model); - - setCellSelectionEnabled(resolver == null); - setOpaque(resolver == null); - setPreferredScrollableViewportSize(getPreferredSize()); - - DefaultTableCellRenderer cr = (DefaultTableCellRenderer) - getDefaultRenderer(String.class); - cr.setOpaque(resolver == null); + // + // Transform map into vector of vectors + // + java.util.Vector vector = new java.util.Vector(names.size()); + java.util.Iterator p = names.iterator(); + + _hasDefault = new boolean[names.size()]; + int i = 0; + + while(p.hasNext()) + { + java.util.Vector row = new java.util.Vector(2); + String name = (String)p.next(); + row.add(name); + + _hasDefault[i] = (defaultValues.get(name) != null); + + Object val = values.get(name); + if(val == null) + { + row.add(_hasDefault[i] ? _useDefault : _notSet); + } + else + { + row.add(Utils.substitute((String)val, resolver)); + } + vector.add(row); + i++; + } + + _model = new DefaultTableModel(vector, _columnNames) + { + public boolean isCellEditable(int row, int column) + { + if(resolver == null) + { + return column > 0; + } + else + { + return false; + } + } + }; + + _model.addTableModelListener(new TableModelListener() + { + public void tableChanged(TableModelEvent e) + { + _editor.updated(); + } + }); + setModel(_model); + + setCellSelectionEnabled(resolver == null); + setOpaque(resolver == null); + setPreferredScrollableViewportSize(getPreferredSize()); + + DefaultTableCellRenderer cr = (DefaultTableCellRenderer) + getDefaultRenderer(String.class); + cr.setOpaque(resolver == null); } public java.util.Map getValues() { - java.util.Map values = new java.util.HashMap(); - - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - java.util.Vector vector = _model.getDataVector(); - - java.util.Iterator p = vector.iterator(); - while(p.hasNext()) - { - java.util.Vector row = (java.util.Vector)p.next(); - - // - // Eliminate rows with null or empty names - // - String name = (String)row.elementAt(0); - assert name != null; - - Object val = row.elementAt(1); - - // - // Eliminate entries with default or not set value - // - if(val != _useDefault && val != _notSet) - { - assert val != null; - values.put(name, val); - } - } - return values; + java.util.Map values = new java.util.HashMap(); + + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + java.util.Vector vector = _model.getDataVector(); + + java.util.Iterator p = vector.iterator(); + while(p.hasNext()) + { + java.util.Vector row = (java.util.Vector)p.next(); + + // + // Eliminate rows with null or empty names + // + String name = (String)row.elementAt(0); + assert name != null; + + Object val = row.elementAt(1); + + // + // Eliminate entries with default or not set value + // + if(val != _useDefault && val != _notSet) + { + assert val != null; + values.put(name, val); + } + } + return values; } public TableCellEditor getCellEditor(int row, - int column) + int column) { - if(column == 1) - { - return _hasDefault[row] ? _useDefaultEditor : _notSetEditor; - } - else - { - return super.getCellEditor(row, column); - } + if(column == 1) + { + return _hasDefault[row] ? _useDefaultEditor : _notSetEditor; + } + else + { + return super.getCellEditor(row, column); + } } private static final Object _useDefault = new Object() - { - public String toString() - { - return "Use default"; - } - }; + { + public String toString() + { + return "Use default"; + } + }; private static final Object _notSet = new Object() - { - public String toString() - { - return "Not set"; - } - }; + { + public String toString() + { + return "Not set"; + } + }; private JComboBox _useDefaultCombo = new JComboBox( - new Object[]{_useDefault}); + new Object[]{_useDefault}); private JComboBox _notSetCombo = new JComboBox( - new Object[]{_notSet}); + new Object[]{_notSet}); private TableCellEditor _useDefaultEditor = new DefaultCellEditor(_useDefaultCombo); private TableCellEditor _notSetEditor = new DefaultCellEditor(_notSetCombo); diff --git a/java/src/IceGridGUI/Application/ParametersField.java b/java/src/IceGridGUI/Application/ParametersField.java index c491d28ddd4..aa82c146a81 100755 --- a/java/src/IceGridGUI/Application/ParametersField.java +++ b/java/src/IceGridGUI/Application/ParametersField.java @@ -35,155 +35,155 @@ public class ParametersField extends JTable { public ParametersField(Editor editor) { - _editor = editor; - - _columnNames = new java.util.Vector(2); - _columnNames.add("Name"); - _columnNames.add("Default value"); - - JComboBox comboBox = new JComboBox( - new Object[]{_noDefault}); - comboBox.setEditable(true); - _cellEditor = new DefaultCellEditor(comboBox); - - Action deleteRow = new AbstractAction("Delete selected row(s)") - { - public void actionPerformed(ActionEvent e) - { - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - - for(;;) - { - int selectedRow = getSelectedRow(); - if(selectedRow == -1) - { - break; - } - else - { - _model.removeRow(selectedRow); - } - } - } - }; - getActionMap().put("delete", deleteRow); - getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); + _editor = editor; + + _columnNames = new java.util.Vector(2); + _columnNames.add("Name"); + _columnNames.add("Default value"); + + JComboBox comboBox = new JComboBox( + new Object[]{_noDefault}); + comboBox.setEditable(true); + _cellEditor = new DefaultCellEditor(comboBox); + + Action deleteRow = new AbstractAction("Delete selected row(s)") + { + public void actionPerformed(ActionEvent e) + { + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + + for(;;) + { + int selectedRow = getSelectedRow(); + if(selectedRow == -1) + { + break; + } + else + { + _model.removeRow(selectedRow); + } + } + } + }; + getActionMap().put("delete", deleteRow); + getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); } public void set(java.util.List names, java.util.Map values) { - // - // Transform map into vector of vectors - // - java.util.Vector vector = new java.util.Vector(names.size()); - java.util.Iterator p = names.iterator(); - while(p.hasNext()) - { - java.util.Vector row = new java.util.Vector(2); - String name = (String)p.next(); - - row.add(name); - - Object val = values.get(name); - if(val == null) - { - row.add(_noDefault); - } - else - { - row.add(val); - } - vector.add(row); - } - - - java.util.Vector newRow = new java.util.Vector(2); - newRow.add(""); - newRow.add(_noDefault); - vector.add(newRow); - - _model = new DefaultTableModel(vector, _columnNames); - - _model.addTableModelListener(new TableModelListener() - { - public void tableChanged(TableModelEvent e) - { - Object lastKey = _model.getValueAt( - _model.getRowCount() - 1 , 0); - if(lastKey != null && !lastKey.equals("")) - { - _model.addRow(new Object[]{"", _noDefault}); - } - - _editor.updated(); - } - }); - setModel(_model); - - TableColumn valColumn = getColumnModel().getColumn(1); - valColumn.setCellEditor(_cellEditor); - - setPreferredScrollableViewportSize(getPreferredSize()); + // + // Transform map into vector of vectors + // + java.util.Vector vector = new java.util.Vector(names.size()); + java.util.Iterator p = names.iterator(); + while(p.hasNext()) + { + java.util.Vector row = new java.util.Vector(2); + String name = (String)p.next(); + + row.add(name); + + Object val = values.get(name); + if(val == null) + { + row.add(_noDefault); + } + else + { + row.add(val); + } + vector.add(row); + } + + + java.util.Vector newRow = new java.util.Vector(2); + newRow.add(""); + newRow.add(_noDefault); + vector.add(newRow); + + _model = new DefaultTableModel(vector, _columnNames); + + _model.addTableModelListener(new TableModelListener() + { + public void tableChanged(TableModelEvent e) + { + Object lastKey = _model.getValueAt( + _model.getRowCount() - 1 , 0); + if(lastKey != null && !lastKey.equals("")) + { + _model.addRow(new Object[]{"", _noDefault}); + } + + _editor.updated(); + } + }); + setModel(_model); + + TableColumn valColumn = getColumnModel().getColumn(1); + valColumn.setCellEditor(_cellEditor); + + setPreferredScrollableViewportSize(getPreferredSize()); } public java.util.Map get(java.util.List names) { - assert names != null; - - java.util.Map values = new java.util.HashMap(); - - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - java.util.Vector vector = _model.getDataVector(); - - java.util.Iterator p = vector.iterator(); - while(p.hasNext()) - { - java.util.Vector row = (java.util.Vector)p.next(); - - // - // Eliminate rows with null or empty names - // - String name = (String)row.elementAt(0); - if(name != null) - { - name = name.trim(); - - if(!name.equals("")) - { - names.add(name); - - Object val = row.elementAt(1); - - // - // Eliminate entries with "default" value - // - if(val != _noDefault) - { - assert val != null; - values.put(name, val); - } - } - } - } - return values; + assert names != null; + + java.util.Map values = new java.util.HashMap(); + + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + java.util.Vector vector = _model.getDataVector(); + + java.util.Iterator p = vector.iterator(); + while(p.hasNext()) + { + java.util.Vector row = (java.util.Vector)p.next(); + + // + // Eliminate rows with null or empty names + // + String name = (String)row.elementAt(0); + if(name != null) + { + name = name.trim(); + + if(!name.equals("")) + { + names.add(name); + + Object val = row.elementAt(1); + + // + // Eliminate entries with "default" value + // + if(val != _noDefault) + { + assert val != null; + values.put(name, val); + } + } + } + } + return values; } private final Object _noDefault = new Object() - { - public String toString() - { - return "No default"; - } - }; + { + public String toString() + { + return "No default"; + } + }; private DefaultTableModel _model; private java.util.Vector _columnNames; diff --git a/java/src/IceGridGUI/Application/PlainServer.java b/java/src/IceGridGUI/Application/PlainServer.java index fdf86d2ea0b..315d4212a5b 100755 --- a/java/src/IceGridGUI/Application/PlainServer.java +++ b/java/src/IceGridGUI/Application/PlainServer.java @@ -25,95 +25,95 @@ class PlainServer extends Communicator implements Server static public ServerDescriptor copyDescriptor(ServerDescriptor sd) { - ServerDescriptor copy = (ServerDescriptor)sd.clone(); + ServerDescriptor copy = (ServerDescriptor)sd.clone(); - copy.adapters = Adapter.copyDescriptors(copy.adapters); - copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs); + copy.adapters = Adapter.copyDescriptors(copy.adapters); + copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs); - copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); - - copy.distrib = (DistributionDescriptor)copy.distrib.clone(); + copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); + + copy.distrib = (DistributionDescriptor)copy.distrib.clone(); - if(copy instanceof IceBoxDescriptor) - { - IceBoxDescriptor ib = (IceBoxDescriptor)copy; - ib.services = ServiceInstance.copyDescriptors(ib.services); - } - return copy; + if(copy instanceof IceBoxDescriptor) + { + IceBoxDescriptor ib = (IceBoxDescriptor)copy; + ib.services = ServiceInstance.copyDescriptors(ib.services); + } + return copy; } 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.propertySet = from.propertySet; - 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; + // + // When editing a server or server template, if we update properties, + // we replace the entire field + // + into.propertySet = from.propertySet; + 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 PropertySetDescriptor(new String[0], new java.util.LinkedList()), - new java.util.LinkedList(), - new String[0], - "", - "NewServer", - "", - "", - new java.util.LinkedList(), - new java.util.LinkedList(), - "manual", - "", - "", - true, - new DistributionDescriptor("", new java.util.LinkedList()), - false, // Allocatable - "", - "" // Ice version - ); + return new ServerDescriptor( + new java.util.LinkedList(), + new PropertySetDescriptor(new String[0], new java.util.LinkedList()), + new java.util.LinkedList(), + new String[0], + "", + "NewServer", + "", + "", + new java.util.LinkedList(), + new java.util.LinkedList(), + "manual", + "", + "", + true, + new DistributionDescriptor("", new java.util.LinkedList()), + false, // Allocatable + "", + "" // Ice version + ); } static public IceBoxDescriptor newIceBoxDescriptor() { - java.util.LinkedList properties = new java.util.LinkedList(); - properties.add(new PropertyDescriptor("IceBox.InstanceName", "${server}")); - properties.add(new PropertyDescriptor("Ice.OA.IceBox.ServiceManager.Endpoints", "tcp -h 127.0.0.1")); - properties.add(new PropertyDescriptor("Ice.OA.IceBox.ServiceManager.RegisterProcess", "1")); - - return new IceBoxDescriptor( - new java.util.LinkedList(), - new PropertySetDescriptor(new String[0], properties), - new java.util.LinkedList(), - new String[0], - "", - "NewIceBox", - "", - "", - new java.util.LinkedList(), - new java.util.LinkedList(), - "manual", - "", - "", - true, - new DistributionDescriptor("", new java.util.LinkedList()), - false, // Allocatable - "", - "", // Ice version - new java.util.LinkedList() - ); + java.util.LinkedList properties = new java.util.LinkedList(); + properties.add(new PropertyDescriptor("IceBox.InstanceName", "${server}")); + properties.add(new PropertyDescriptor("Ice.OA.IceBox.ServiceManager.Endpoints", "tcp -h 127.0.0.1")); + properties.add(new PropertyDescriptor("Ice.OA.IceBox.ServiceManager.RegisterProcess", "1")); + + return new IceBoxDescriptor( + new java.util.LinkedList(), + new PropertySetDescriptor(new String[0], properties), + new java.util.LinkedList(), + new String[0], + "", + "NewIceBox", + "", + "", + new java.util.LinkedList(), + new java.util.LinkedList(), + "manual", + "", + "", + true, + new DistributionDescriptor("", new java.util.LinkedList()), + false, // Allocatable + "", + "", // Ice version + new java.util.LinkedList() + ); } // @@ -121,412 +121,412 @@ class PlainServer extends Communicator implements Server // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - - Object clipboard = getCoordinator().getClipboard(); - if(clipboard != null && - (clipboard instanceof ServerDescriptor - || clipboard instanceof ServerInstanceDescriptor - || (isIceBox() && (clipboard instanceof ServiceInstanceDescriptor)) - || (!isIceBox() && (clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor)))) - { - actions[PASTE] = true; - } - - actions[DELETE] = true; - if(!_ephemeral) - { - actions[COPY] = true; - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - - actions[NEW_ADAPTER] = !_services.initialized(); - actions[NEW_DBENV] = !_services.initialized(); - actions[NEW_SERVICE] = _services.initialized(); - actions[NEW_SERVICE_FROM_TEMPLATE] = _services.initialized(); - } - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + + Object clipboard = getCoordinator().getClipboard(); + if(clipboard != null && + (clipboard instanceof ServerDescriptor + || clipboard instanceof ServerInstanceDescriptor + || (isIceBox() && (clipboard instanceof ServiceInstanceDescriptor)) + || (!isIceBox() && (clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor)))) + { + actions[PASTE] = true; + } + + actions[DELETE] = true; + if(!_ephemeral) + { + actions[COPY] = true; + actions[SHOW_VARS] = true; + actions[SUBSTITUTE_VARS] = true; + + actions[NEW_ADAPTER] = !_services.initialized(); + actions[NEW_DBENV] = !_services.initialized(); + actions[NEW_SERVICE] = _services.initialized(); + actions[NEW_SERVICE_FROM_TEMPLATE] = _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; + 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() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public Editor getEditor() { - if(_editor == null) - { - _editor = (PlainServerEditor)getRoot().getEditor(PlainServerEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (PlainServerEditor)getRoot().getEditor(PlainServerEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new PlainServerEditor(); + return new PlainServerEditor(); } - + public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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"); - } - - if(expanded) - { - _cellRenderer.setOpenIcon(isIceBox() ? _iceboxServerIcon : _serverIcon); - } - else - { - _cellRenderer.setClosedIcon(isIceBox() ? _iceboxServerIcon : _serverIcon); - } - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, 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"); + } + + if(expanded) + { + _cellRenderer.setOpenIcon(isIceBox() ? _iceboxServerIcon : _serverIcon); + } + else + { + _cellRenderer.setClosedIcon(isIceBox() ? _iceboxServerIcon : _serverIcon); + } + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } public void destroy() { - Node node = (Node)_parent; - - if(_ephemeral) - { - node.removeServer(this); - } - else - { - node.removeDescriptor(_descriptor); - node.removeServer(this); - node.getEditable().removeElement(_id, _editable, Server.class); - getRoot().updated(); - } + Node node = (Node)_parent; + + if(_ephemeral) + { + node.removeServer(this); + } + else + { + node.removeDescriptor(_descriptor); + node.removeServer(this); + node.getEditable().removeElement(_id, _editable, Server.class); + getRoot().updated(); + } } public Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object saveDescriptor() { - ServerDescriptor clone = (ServerDescriptor)_descriptor.clone(); - clone.distrib = (DistributionDescriptor)clone.distrib.clone(); - return clone; + ServerDescriptor clone = (ServerDescriptor)_descriptor.clone(); + clone.distrib = (DistributionDescriptor)clone.distrib.clone(); + return clone; } public void restoreDescriptor(Object savedDescriptor) { - shallowRestore((ServerDescriptor)savedDescriptor, _descriptor); + shallowRestore((ServerDescriptor)savedDescriptor, _descriptor); } // // Builds the server and all its sub-tree // PlainServer(boolean brandNew, TreeNode parent, String serverId, - Utils.Resolver resolver, ServerDescriptor serverDescriptor) - throws UpdateFailedException + Utils.Resolver resolver, ServerDescriptor serverDescriptor) + throws UpdateFailedException { - super(parent, serverId); - _ephemeral = false; - _editable = new Editable(brandNew); - rebuild(resolver, serverDescriptor); + super(parent, serverId); + _ephemeral = false; + _editable = new Editable(brandNew); + rebuild(resolver, serverDescriptor); } PlainServer(TreeNode parent, String serverId, ServerDescriptor serverDescriptor) { - super(parent, serverId); - _ephemeral = true; - _editable = null; - try - { - rebuild(null, serverDescriptor); - } - catch(UpdateFailedException e) - { - assert false; - } + super(parent, serverId); + _ephemeral = true; + _editable = null; + try + { + rebuild(null, 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; + 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 + throws java.io.IOException { - java.util.Iterator p = options.iterator(); - while(p.hasNext()) - { - writer.writeElement("option", (String)p.next()); - } + 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 + throws java.io.IOException { - java.util.Iterator p = envs.iterator(); - while(p.hasNext()) - { - writer.writeElement("env", (String)p.next()); - } + 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(isIceBox()) - { - writer.writeStartTag("icebox", - createAttributes(_descriptor)); - - if(_descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.description); - } - writeOptions(writer, _descriptor.options); - writeEnvs(writer, _descriptor.envs); - - writePropertySet(writer, "", "", _descriptor.propertySet, - _descriptor.adapters, _descriptor.logs); - writeLogs(writer, _descriptor.logs, _descriptor.propertySet.properties); - writeDistribution(writer, _descriptor.distrib); - - _adapters.write(writer, _descriptor.propertySet.properties); - _services.write(writer); - writer.writeEndTag("icebox"); - } - else - { - writer.writeStartTag("server", createAttributes(_descriptor)); - - if(_descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.description); - } - - writeOptions(writer, _descriptor.options); - writeEnvs(writer, _descriptor.envs); - - writePropertySet(writer, _descriptor.propertySet, _descriptor.adapters, _descriptor.logs); - writeLogs(writer, _descriptor.logs, _descriptor.propertySet.properties); - writeDistribution(writer, _descriptor.distrib); - - _adapters.write(writer, _descriptor.propertySet.properties); - _dbEnvs.write(writer); - writer.writeEndTag("server"); - } - } + if(!_ephemeral) + { + if(isIceBox()) + { + writer.writeStartTag("icebox", + createAttributes(_descriptor)); + + if(_descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.description); + } + writeOptions(writer, _descriptor.options); + writeEnvs(writer, _descriptor.envs); + + writePropertySet(writer, "", "", _descriptor.propertySet, + _descriptor.adapters, _descriptor.logs); + writeLogs(writer, _descriptor.logs, _descriptor.propertySet.properties); + writeDistribution(writer, _descriptor.distrib); + + _adapters.write(writer, _descriptor.propertySet.properties); + _services.write(writer); + writer.writeEndTag("icebox"); + } + else + { + writer.writeStartTag("server", createAttributes(_descriptor)); + + if(_descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.description); + } + + writeOptions(writer, _descriptor.options); + writeEnvs(writer, _descriptor.envs); + + writePropertySet(writer, _descriptor.propertySet, _descriptor.adapters, _descriptor.logs); + writeLogs(writer, _descriptor.logs, _descriptor.propertySet.properties); + writeDistribution(writer, _descriptor.distrib); + + _adapters.write(writer, _descriptor.propertySet.properties); + _dbEnvs.write(writer); + writer.writeEndTag("server"); + } + } } boolean isIceBox() { - return _descriptor instanceof IceBoxDescriptor; + return _descriptor instanceof IceBoxDescriptor; } public Object rebuild(java.util.List editables) throws UpdateFailedException { - Node node = (Node)_parent; - PlainServer newServer = node.createServer(false, _descriptor); - - Object backup = null; - - 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.removeServer(this); - try - { - node.insertServer(newServer, true); - } - catch(UpdateFailedException e) - { - assert false; // impossible, we just removed a child with - // this id - } - } - else - { - // - // Typically, the id uses a variable whose definition changed - // - newServer.getEditable().markNew(); - node.removeServer(this); - backup = node.getEditable().save(); - node.getEditable().removeElement(_id, _editable, Server.class); - - try - { - node.insertServer(newServer, true); - } - catch(UpdateFailedException e) - { - restore(backup); - throw e; - } - } - - return backup; + Node node = (Node)_parent; + PlainServer newServer = node.createServer(false, _descriptor); + + Object backup = null; + + 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.removeServer(this); + try + { + node.insertServer(newServer, true); + } + catch(UpdateFailedException e) + { + assert false; // impossible, we just removed a child with + // this id + } + } + else + { + // + // Typically, the id uses a variable whose definition changed + // + newServer.getEditable().markNew(); + node.removeServer(this); + backup = node.getEditable().save(); + node.getEditable().removeElement(_id, _editable, Server.class); + + try + { + node.insertServer(newServer, true); + } + catch(UpdateFailedException e) + { + restore(backup); + throw e; + } + } + + return backup; } public void restore(Object backupObj) { - Editable backup = (Editable)backupObj; - Node node = (Node)_parent; - - if(backup != null) - { - node.getEditable().restore(backup); - } - - TreeNode badServer = node.findChildWithDescriptor(_descriptor); - - if(badServer != null) - { - node.removeServer(badServer); - } - try - { - node.insertServer(this, true); - } - catch(UpdateFailedException e) - { - assert false; // impossible - } + Editable backup = (Editable)backupObj; + Node node = (Node)_parent; + + if(backup != null) + { + node.getEditable().restore(backup); + } + + TreeNode badServer = node.findChildWithDescriptor(_descriptor); + + if(badServer != null) + { + node.removeServer(badServer); + } + try + { + node.insertServer(this, true); + } + catch(UpdateFailedException e) + { + assert false; // impossible + } } void setServerDescriptor(ServerDescriptor descriptor) { - _descriptor = descriptor; + _descriptor = descriptor; } // // Update the server and all its subtree // void rebuild(Utils.Resolver resolver, - ServerDescriptor serverDescriptor) throws UpdateFailedException + ServerDescriptor serverDescriptor) throws UpdateFailedException { - assert serverDescriptor != null; - _resolver = resolver; - _descriptor = serverDescriptor; - - _adapters.clear(); - _dbEnvs.clear(); - _services.clear(); - - if(!_ephemeral) - { - _adapters.init(_descriptor.adapters); - if(isIceBox()) - { - IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)_descriptor; - _services.init(iceBoxDescriptor.services); + assert serverDescriptor != null; + _resolver = resolver; + _descriptor = serverDescriptor; + + _adapters.clear(); + _dbEnvs.clear(); + _services.clear(); + + if(!_ephemeral) + { + _adapters.init(_descriptor.adapters); + if(isIceBox()) + { + IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)_descriptor; + _services.init(iceBoxDescriptor.services); - // - // IceBox has not dbEnv - // - assert _descriptor.dbEnvs.size() == 0; - } - else - { - _dbEnvs.init(_descriptor.dbEnvs); - } - } + // + // IceBox has not dbEnv + // + assert _descriptor.dbEnvs.size() == 0; + } + else + { + _dbEnvs.init(_descriptor.dbEnvs); + } + } } CommunicatorDescriptor getCommunicatorDescriptor() { - return _descriptor; + return _descriptor; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } public Editable getEditable() { - return _editable; + return _editable; } Editable getEnclosingEditable() { - return _editable; + return _editable; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } private ServerDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/PlainServerEditor.java b/java/src/IceGridGUI/Application/PlainServerEditor.java index d8bb19c4663..d2859d1339a 100755 --- a/java/src/IceGridGUI/Application/PlainServerEditor.java +++ b/java/src/IceGridGUI/Application/PlainServerEditor.java @@ -17,17 +17,17 @@ class PlainServerEditor extends AbstractServerEditor { protected void writeDescriptor() { - _subEditor.writeDescriptor(); - } + _subEditor.writeDescriptor(); + } protected boolean isSimpleUpdate() { - return _subEditor.isSimpleUpdate(); + return _subEditor.isSimpleUpdate(); } PlainServerEditor() { - _subEditor = new ServerSubEditor(this); + _subEditor = new ServerSubEditor(this); } // @@ -35,41 +35,41 @@ class PlainServerEditor extends AbstractServerEditor // Utils.Resolver getDetailResolver() { - if(_target.getCoordinator().substitute()) - { - return _target.getResolver(); - } - else - { - return null; - } + if(_target.getCoordinator().substitute()) + { + return _target.getResolver(); + } + else + { + return null; + } } protected void appendProperties(DefaultFormBuilder builder) { - _subEditor.appendProperties(builder); + _subEditor.appendProperties(builder); } Object getSubDescriptor() { - return _target.getDescriptor(); + return _target.getDescriptor(); } protected boolean validate() { - return _subEditor.validate(); + return _subEditor.validate(); } void show(PlainServer server) { - detectUpdates(false); - _target = server; + detectUpdates(false); + _target = server; - _subEditor.show(true); + _subEditor.show(true); - _applyButton.setEnabled(server.isEphemeral()); - _discardButton.setEnabled(server.isEphemeral()); - detectUpdates(true); + _applyButton.setEnabled(server.isEphemeral()); + _discardButton.setEnabled(server.isEphemeral()); + detectUpdates(true); } private ServerSubEditor _subEditor; diff --git a/java/src/IceGridGUI/Application/PlainService.java b/java/src/IceGridGUI/Application/PlainService.java index 01743f7bc90..f21b554a79b 100755 --- a/java/src/IceGridGUI/Application/PlainService.java +++ b/java/src/IceGridGUI/Application/PlainService.java @@ -21,34 +21,34 @@ class PlainService extends Communicator implements Service, Cloneable static public ServiceDescriptor copyDescriptor(ServiceDescriptor sd) { - ServiceDescriptor copy = (ServiceDescriptor)sd.clone(); - copy.adapters = Adapter.copyDescriptors(copy.adapters); - copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs); - copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); - return copy; + ServiceDescriptor copy = (ServiceDescriptor)sd.clone(); + copy.adapters = Adapter.copyDescriptors(copy.adapters); + copy.dbEnvs = DbEnv.copyDescriptors(copy.dbEnvs); + copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); + return copy; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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); + 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); } // @@ -56,183 +56,183 @@ class PlainService extends Communicator implements Service, Cloneable // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - Object clipboard = getCoordinator().getClipboard(); - if(clipboard != null && - (clipboard instanceof ServiceInstanceDescriptor - || clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor)) - { - actions[PASTE] = true; - } - - actions[DELETE] = true; - 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; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + Object clipboard = getCoordinator().getClipboard(); + if(clipboard != null && + (clipboard instanceof ServiceInstanceDescriptor + || clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor)) + { + actions[PASTE] = true; + } + + actions[DELETE] = true; + 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; + 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(ServiceInstance.copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(ServiceInstance.copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void moveUp() { - move(true); + move(true); } public void moveDown() { - move(false); + move(false); } public Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object saveDescriptor() { - return _descriptor.clone(); + return _descriptor.clone(); } public void restoreDescriptor(Object savedDescriptor) { - ServiceInstanceDescriptor sid = (ServiceInstanceDescriptor)savedDescriptor; + ServiceInstanceDescriptor sid = (ServiceInstanceDescriptor)savedDescriptor; - _descriptor.descriptor.propertySet = sid.descriptor.propertySet; - _descriptor.descriptor.description = sid.descriptor.description; - _descriptor.descriptor.name = sid.descriptor.name; - _descriptor.descriptor.entry = sid.descriptor.entry; + _descriptor.descriptor.propertySet = sid.descriptor.propertySet; + _descriptor.descriptor.description = sid.descriptor.description; + _descriptor.descriptor.name = sid.descriptor.name; + _descriptor.descriptor.entry = sid.descriptor.entry; } public void destroy() { - ((Communicator)_parent).getServices().destroyChild(this); + ((Communicator)_parent).getServices().destroyChild(this); } public Editor getEditor() { - if(_editor == null) - { - _editor = (PlainServiceEditor)getRoot().getEditor(PlainServiceEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (PlainServiceEditor)getRoot().getEditor(PlainServiceEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new PlainServiceEditor(); + return new PlainServiceEditor(); } Editable getEnclosingEditable() { - return ((Communicator)_parent).getEnclosingEditable(); + return ((Communicator)_parent).getEnclosingEditable(); } private boolean canMove(boolean up) { - if(_ephemeral) - { - return false; - } - else - { - return ((Communicator)_parent).getServices().canMove(this, 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); + assert canMove(up); + ((Communicator)_parent).getServices().move(this, up); } public Object rebuild(java.util.List editables) - throws UpdateFailedException + throws UpdateFailedException { - Communicator communicator = (Communicator)_parent; - Services services = communicator.getServices(); - PlainService newService = null; - - newService = (PlainService)services.createChild(_descriptor); - - Object backup = null; - - try - { - backup = (PlainService)clone(); - } - catch(CloneNotSupportedException e) - { - assert false; - } - - reset(newService); - getRoot().getTreeModel().nodeChanged(this); - return backup; + Communicator communicator = (Communicator)_parent; + Services services = communicator.getServices(); + PlainService newService = null; + + newService = (PlainService)services.createChild(_descriptor); + + Object backup = null; + + try + { + backup = (PlainService)clone(); + } + catch(CloneNotSupportedException e) + { + assert false; + } + + reset(newService); + getRoot().getTreeModel().nodeChanged(this); + return backup; } public void restore(Object backupObj) { - reset((PlainService)backupObj); - getRoot().getTreeModel().nodeChanged(this); + reset((PlainService)backupObj); + getRoot().getTreeModel().nodeChanged(this); } private void reset(PlainService from) { - _id = from._id; - assert _parent == from._parent; - - _adapters = from._adapters; - _dbEnvs = from._dbEnvs; - _services = from._services; - _childListArray = from._childListArray; - - _descriptor = from._descriptor; - _resolver = from._resolver; + _id = from._id; + assert _parent == from._parent; + + _adapters = from._adapters; + _dbEnvs = from._dbEnvs; + _services = from._services; + _childListArray = from._childListArray; + + _descriptor = from._descriptor; + _resolver = from._resolver; } PlainService(Communicator parent, - String name, - ServiceInstanceDescriptor descriptor, - Utils.Resolver resolver) - throws UpdateFailedException + String name, + ServiceInstanceDescriptor descriptor, + Utils.Resolver resolver) + throws UpdateFailedException { - super(parent, name); - _descriptor = descriptor; - _ephemeral = false; - _resolver = resolver; + super(parent, name); + _descriptor = descriptor; + _ephemeral = false; + _resolver = resolver; - _adapters.init(_descriptor.descriptor.adapters); - _dbEnvs.init(_descriptor.descriptor.dbEnvs); + _adapters.init(_descriptor.descriptor.adapters); + _dbEnvs.init(_descriptor.descriptor.dbEnvs); } // @@ -240,53 +240,53 @@ class PlainService extends Communicator implements Service, Cloneable // PlainService(Communicator parent, ServiceInstanceDescriptor descriptor) { - super(parent, descriptor.descriptor.name); - _descriptor = descriptor; - _ephemeral = true; + super(parent, descriptor.descriptor.name); + _descriptor = descriptor; + _ephemeral = 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; + 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) - { - writer.writeStartTag("service", createAttributes(_descriptor.descriptor)); - - if(_descriptor.descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.descriptor.description); - } - - writePropertySet(writer, _descriptor.descriptor.propertySet, - _descriptor.descriptor.adapters, _descriptor.descriptor.logs); - writeLogs(writer, _descriptor.descriptor.logs, _descriptor.descriptor.propertySet.properties); - - _adapters.write(writer, _descriptor.descriptor.propertySet.properties); - _dbEnvs.write(writer); - writer.writeEndTag("service"); - } + if(!_ephemeral) + { + writer.writeStartTag("service", createAttributes(_descriptor.descriptor)); + + if(_descriptor.descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.descriptor.description); + } + + writePropertySet(writer, _descriptor.descriptor.propertySet, + _descriptor.descriptor.adapters, _descriptor.descriptor.logs); + writeLogs(writer, _descriptor.descriptor.logs, _descriptor.descriptor.propertySet.properties); + + _adapters.write(writer, _descriptor.descriptor.propertySet.properties); + _dbEnvs.write(writer); + writer.writeEndTag("service"); + } } CommunicatorDescriptor getCommunicatorDescriptor() { - return _descriptor.descriptor; + return _descriptor.descriptor; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } private ServiceInstanceDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/PlainServiceEditor.java b/java/src/IceGridGUI/Application/PlainServiceEditor.java index c1de8d137e2..f2487413ba8 100755 --- a/java/src/IceGridGUI/Application/PlainServiceEditor.java +++ b/java/src/IceGridGUI/Application/PlainServiceEditor.java @@ -17,7 +17,7 @@ class PlainServiceEditor extends CommunicatorChildEditor { PlainServiceEditor() { - _subEditor = new ServiceSubEditor(this); + _subEditor = new ServiceSubEditor(this); } // @@ -25,65 +25,65 @@ class PlainServiceEditor extends CommunicatorChildEditor // Utils.Resolver getDetailResolver() { - PlainService service = (PlainService)_target; - if(service.getCoordinator().substitute()) - { - return service.getResolver(); - } - else - { - return null; - } + PlainService service = (PlainService)_target; + if(service.getCoordinator().substitute()) + { + return service.getResolver(); + } + else + { + return null; + } } protected void appendProperties(DefaultFormBuilder builder) { - _subEditor.appendProperties(builder); + _subEditor.appendProperties(builder); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Service Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Service Properties"); } protected boolean validate() { - return _subEditor.validate(); + return _subEditor.validate(); } void writeDescriptor() { - _subEditor.writeDescriptor(); - } + _subEditor.writeDescriptor(); + } boolean isSimpleUpdate() { - return _subEditor.isSimpleUpdate(); + return _subEditor.isSimpleUpdate(); } Communicator.ChildList getChildList() { - return ((Communicator)_target.getParent()).getServices(); + return ((Communicator)_target.getParent()).getServices(); } Object getSubDescriptor() { - ServiceInstanceDescriptor sid = (ServiceInstanceDescriptor)_target.getDescriptor(); - return sid.descriptor; + ServiceInstanceDescriptor sid = (ServiceInstanceDescriptor)_target.getDescriptor(); + return sid.descriptor; } void show(PlainService service) { - detectUpdates(false); - _target = service; + detectUpdates(false); + _target = service; - _subEditor.show(true); + _subEditor.show(true); - _applyButton.setEnabled(service.isEphemeral()); - _discardButton.setEnabled(service.isEphemeral()); - detectUpdates(true); + _applyButton.setEnabled(service.isEphemeral()); + _discardButton.setEnabled(service.isEphemeral()); + detectUpdates(true); } private ServiceSubEditor _subEditor; diff --git a/java/src/IceGridGUI/Application/PropertiesField.java b/java/src/IceGridGUI/Application/PropertiesField.java index e94ca2fda66..ed2035f56c9 100755 --- a/java/src/IceGridGUI/Application/PropertiesField.java +++ b/java/src/IceGridGUI/Application/PropertiesField.java @@ -33,231 +33,231 @@ public class PropertiesField extends JTable { public PropertiesField(Editor editor) { - _columnNames = new java.util.Vector(2); - _columnNames.add("Name"); - _columnNames.add("Value"); - - _editor = editor; - - Action deleteRow = new AbstractAction("Delete selected row(s)") - { - public void actionPerformed(ActionEvent e) - { - if(_editable) - { - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - - for(;;) - { - int selectedRow = getSelectedRow(); - if(selectedRow == -1) - { - break; - } - else - { - _model.removeRow(selectedRow); - } - } - } - } - }; - getActionMap().put("delete", deleteRow); - getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); - - - + _columnNames = new java.util.Vector(2); + _columnNames.add("Name"); + _columnNames.add("Value"); + + _editor = editor; + + Action deleteRow = new AbstractAction("Delete selected row(s)") + { + public void actionPerformed(ActionEvent e) + { + if(_editable) + { + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + + for(;;) + { + int selectedRow = getSelectedRow(); + if(selectedRow == -1) + { + break; + } + else + { + _model.removeRow(selectedRow); + } + } + } + } + }; + getActionMap().put("delete", deleteRow); + getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); + + + } public void setProperties(java.util.List properties, - java.util.List adapters, - String[] logs, - Utils.Resolver resolver, boolean editable) + java.util.List adapters, + String[] logs, + Utils.Resolver resolver, boolean editable) { - _editable = editable; - - // - // We don't show the .Endpoint and .PublishedEndpoints of adapters, - // since they already appear in the Adapter pages - // - java.util.Set hiddenPropertyNames = new java.util.HashSet(); - - // - // We also hide properties whose value match an object or allocatable - // - java.util.Set hiddenPropertyValues = new java.util.HashSet(); - - _hiddenProperties.clear(); - - if(adapters != null) - { - // - // Note that we don't substitute *on purpose*, i.e. the names or values - // must match before substitution. - // - java.util.Iterator p = adapters.iterator(); - while(p.hasNext()) - { - AdapterDescriptor ad = (AdapterDescriptor)p.next(); - hiddenPropertyNames.add("Ice.OA." + ad.name + ".Endpoints"); - hiddenPropertyNames.add("Ice.OA." + ad.name + ".PublishedEndpoints"); - - java.util.Iterator q = ad.objects.iterator(); - while(q.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)q.next(); - hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); - } - q = ad.allocatables.iterator(); - while(q.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)q.next(); - hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); - } - } - } - - if(logs != null) - { - for(int i = 0; i < logs.length; ++i) - { - hiddenPropertyValues.add(logs[i]); - } - } - - // - // Transform list into vector of vectors - // - java.util.Vector vector = new java.util.Vector(properties.size()); - java.util.Iterator p = properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(hiddenPropertyNames.contains(pd.name)) - { - // - // We keep them at the top of the list - // - if(_editable) - { - _hiddenProperties.add(pd); - } - - // - // We hide only the first occurence - // - hiddenPropertyNames.remove(pd.name); - } - else if(hiddenPropertyValues.contains(pd.value)) - { - // - // We keep them at the top of the list - // - if(_editable) - { - _hiddenProperties.add(pd); - } - - // - // We hide only the first occurence - // - hiddenPropertyValues.remove(pd.value); - } - else - { - java.util.Vector row = new java.util.Vector(2); - row.add(Utils.substitute(pd.name, resolver)); - row.add(Utils.substitute(pd.value, resolver)); - vector.add(row); - } - } - - if(_editable) - { - java.util.Vector newRow = new java.util.Vector(2); - newRow.add(""); - newRow.add(""); - vector.add(newRow); - } - - _model = new DefaultTableModel(vector, _columnNames) - { - public boolean isCellEditable(int row, int column) - { - return _editable; - } - }; - - _model.addTableModelListener(new TableModelListener() - { - public void tableChanged(TableModelEvent e) - { - if(_editable) - { - Object lastKey = _model.getValueAt( - _model.getRowCount() - 1 , 0); - if(lastKey != null && !lastKey.equals("")) - { - _model.addRow(new Object[]{"", ""}); - } - _editor.updated(); - } - } - }); - setModel(_model); - - setCellSelectionEnabled(_editable); - setOpaque(_editable); - setPreferredScrollableViewportSize(getPreferredSize()); - - DefaultTableCellRenderer cr = (DefaultTableCellRenderer) - getDefaultRenderer(String.class); - cr.setOpaque(_editable); + _editable = editable; + + // + // We don't show the .Endpoint and .PublishedEndpoints of adapters, + // since they already appear in the Adapter pages + // + java.util.Set hiddenPropertyNames = new java.util.HashSet(); + + // + // We also hide properties whose value match an object or allocatable + // + java.util.Set hiddenPropertyValues = new java.util.HashSet(); + + _hiddenProperties.clear(); + + if(adapters != null) + { + // + // Note that we don't substitute *on purpose*, i.e. the names or values + // must match before substitution. + // + java.util.Iterator p = adapters.iterator(); + while(p.hasNext()) + { + AdapterDescriptor ad = (AdapterDescriptor)p.next(); + hiddenPropertyNames.add("Ice.OA." + ad.name + ".Endpoints"); + hiddenPropertyNames.add("Ice.OA." + ad.name + ".PublishedEndpoints"); + + java.util.Iterator q = ad.objects.iterator(); + while(q.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)q.next(); + hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); + } + q = ad.allocatables.iterator(); + while(q.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)q.next(); + hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); + } + } + } + + if(logs != null) + { + for(int i = 0; i < logs.length; ++i) + { + hiddenPropertyValues.add(logs[i]); + } + } + + // + // Transform list into vector of vectors + // + java.util.Vector vector = new java.util.Vector(properties.size()); + java.util.Iterator p = properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(hiddenPropertyNames.contains(pd.name)) + { + // + // We keep them at the top of the list + // + if(_editable) + { + _hiddenProperties.add(pd); + } + + // + // We hide only the first occurence + // + hiddenPropertyNames.remove(pd.name); + } + else if(hiddenPropertyValues.contains(pd.value)) + { + // + // We keep them at the top of the list + // + if(_editable) + { + _hiddenProperties.add(pd); + } + + // + // We hide only the first occurence + // + hiddenPropertyValues.remove(pd.value); + } + else + { + java.util.Vector row = new java.util.Vector(2); + row.add(Utils.substitute(pd.name, resolver)); + row.add(Utils.substitute(pd.value, resolver)); + vector.add(row); + } + } + + if(_editable) + { + java.util.Vector newRow = new java.util.Vector(2); + newRow.add(""); + newRow.add(""); + vector.add(newRow); + } + + _model = new DefaultTableModel(vector, _columnNames) + { + public boolean isCellEditable(int row, int column) + { + return _editable; + } + }; + + _model.addTableModelListener(new TableModelListener() + { + public void tableChanged(TableModelEvent e) + { + if(_editable) + { + Object lastKey = _model.getValueAt( + _model.getRowCount() - 1 , 0); + if(lastKey != null && !lastKey.equals("")) + { + _model.addRow(new Object[]{"", ""}); + } + _editor.updated(); + } + } + }); + setModel(_model); + + setCellSelectionEnabled(_editable); + setOpaque(_editable); + setPreferredScrollableViewportSize(getPreferredSize()); + + DefaultTableCellRenderer cr = (DefaultTableCellRenderer) + getDefaultRenderer(String.class); + cr.setOpaque(_editable); } public java.util.LinkedList getProperties() { - assert _editable; - - if(isEditing()) - { - getCellEditor().stopCellEditing(); - } - java.util.Vector vector = _model.getDataVector(); - - java.util.LinkedList result = new java.util.LinkedList(_hiddenProperties); - - java.util.Iterator p = vector.iterator(); - while(p.hasNext()) - { - java.util.Vector row = (java.util.Vector)p.next(); - - // - // Eliminate rows with null or empty keys - // - String key = (String)row.elementAt(0); - if(key != null) - { - key = key.trim(); - if(!key.equals("")) - { - String val = (String) row.elementAt(1); - if(val == null) - { - val = ""; - } - - result.add(new PropertyDescriptor(key, val)); - } - } - } - return result; + assert _editable; + + if(isEditing()) + { + getCellEditor().stopCellEditing(); + } + java.util.Vector vector = _model.getDataVector(); + + java.util.LinkedList result = new java.util.LinkedList(_hiddenProperties); + + java.util.Iterator p = vector.iterator(); + while(p.hasNext()) + { + java.util.Vector row = (java.util.Vector)p.next(); + + // + // Eliminate rows with null or empty keys + // + String key = (String)row.elementAt(0); + if(key != null) + { + key = key.trim(); + if(!key.equals("")) + { + String val = (String) row.elementAt(1); + if(val == null) + { + val = ""; + } + + result.add(new PropertyDescriptor(key, val)); + } + } + } + return result; } private DefaultTableModel _model; diff --git a/java/src/IceGridGUI/Application/PropertySet.java b/java/src/IceGridGUI/Application/PropertySet.java index 745bc163aa3..8027977ef02 100755 --- a/java/src/IceGridGUI/Application/PropertySet.java +++ b/java/src/IceGridGUI/Application/PropertySet.java @@ -20,29 +20,29 @@ class PropertySet extends TreeNode static public PropertySetDescriptor copyDescriptor(PropertySetDescriptor d) { - PropertySetDescriptor psd = (PropertySetDescriptor)d.clone(); - psd.properties = new java.util.LinkedList(psd.properties); - return psd; + PropertySetDescriptor psd = (PropertySetDescriptor)d.clone(); + psd.properties = new java.util.LinkedList(psd.properties); + return psd; } 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/property_set.png")); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + 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/property_set.png")); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } // @@ -50,182 +50,182 @@ class PropertySet extends TreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - if(((TreeNode)_parent).getAvailableActions()[PASTE]) - { - actions[PASTE] = true; - } - actions[DELETE] = true; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + if(((TreeNode)_parent).getAvailableActions()[PASTE]) + { + actions[PASTE] = true; + } + actions[DELETE] = true; - if(!_ephemeral) - { - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - } - return actions; + 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); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public void destroy() { - PropertySetParent parent = (PropertySetParent)_parent; - parent.removePropertySet(this); + PropertySetParent parent = (PropertySetParent)_parent; + parent.removePropertySet(this); - if(!_ephemeral) - { - parent.removeDescriptor(_unsubstitutedId); - if(_editable != null) - { - parent.getEditable().removeElement(_unsubstitutedId, _editable, PropertySet.class); - } - else - { - parent.getEditable().markModified(); - } - getRoot().updated(); - } + if(!_ephemeral) + { + parent.removeDescriptor(_unsubstitutedId); + if(_editable != null) + { + parent.getEditable().removeElement(_unsubstitutedId, _editable, PropertySet.class); + } + else + { + parent.getEditable().markModified(); + } + getRoot().updated(); + } } public Editor getEditor() { - if(_editor == null) - { - if(_inServerInstance) - { - _editor = (PropertySetEditor)getRoot(). - getEditor(ServerInstancePropertySetEditor.class, this); - } - else - { - _editor = (PropertySetEditor)getRoot(). - getEditor(PropertySetEditor.class, this); - } - } - _editor.show(_unsubstitutedId, this); - return _editor; + if(_editor == null) + { + if(_inServerInstance) + { + _editor = (PropertySetEditor)getRoot(). + getEditor(ServerInstancePropertySetEditor.class, this); + } + else + { + _editor = (PropertySetEditor)getRoot(). + getEditor(PropertySetEditor.class, this); + } + } + _editor.show(_unsubstitutedId, this); + return _editor; } protected Editor createEditor() { - if(_inServerInstance) - { - return new ServerInstancePropertySetEditor(); - } - else - { - return new PropertySetEditor(); - } + if(_inServerInstance) + { + return new ServerInstancePropertySetEditor(); + } + else + { + return new PropertySetEditor(); + } } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } public String unsubstitutedId() { - return _unsubstitutedId; + return _unsubstitutedId; } Object getDescriptor() { - return _descriptor; + return _descriptor; } Object saveDescriptor() { - return _descriptor.clone(); + return _descriptor.clone(); } void restoreDescriptor(Object savedDescriptor) { - PropertySetDescriptor clone = (PropertySetDescriptor)savedDescriptor; - _descriptor.references = clone.references; - _descriptor.properties = clone.properties; + PropertySetDescriptor clone = (PropertySetDescriptor)savedDescriptor; + _descriptor.references = clone.references; + _descriptor.properties = clone.properties; } void commit() { - if(_editable != null) - { - _editable.commit(); - } + if(_editable != null) + { + _editable.commit(); + } } Editable getEditable() { - if(_editable != null) - { - return _editable; - } - else - { - return ((PropertySetParent)_parent).getEditable(); - } + if(_editable != null) + { + return _editable; + } + else + { + return ((PropertySetParent)_parent).getEditable(); + } } PropertySet(boolean brandNew, - TreeNode parent, - String id, - String unsubstitutedId, - PropertySetDescriptor descriptor) + TreeNode parent, + String id, + String unsubstitutedId, + PropertySetDescriptor descriptor) { - super(parent, id); - _unsubstitutedId = unsubstitutedId; - _inServerInstance = (parent instanceof ServerInstance); - _ephemeral = false; - _editable = new Editable(brandNew); - rebuild(descriptor); + super(parent, id); + _unsubstitutedId = unsubstitutedId; + _inServerInstance = (parent instanceof ServerInstance); + _ephemeral = false; + _editable = new Editable(brandNew); + rebuild(descriptor); } PropertySet(TreeNode parent, - String id, - String unsubstitutedId, - PropertySetDescriptor descriptor) + String id, + String unsubstitutedId, + PropertySetDescriptor descriptor) { - super(parent, id); - _unsubstitutedId = unsubstitutedId; - _inServerInstance = (parent instanceof ServerInstance); - _ephemeral = false; - _editable = null; - rebuild(descriptor); + super(parent, id); + _unsubstitutedId = unsubstitutedId; + _inServerInstance = (parent instanceof ServerInstance); + _ephemeral = false; + _editable = null; + rebuild(descriptor); } PropertySet(TreeNode parent, String id, PropertySetDescriptor descriptor) { - super(parent, id); - _unsubstitutedId = id; - _inServerInstance = (parent instanceof ServerInstance); - _ephemeral = true; - _editable = null; - rebuild(descriptor); + super(parent, id); + _unsubstitutedId = id; + _inServerInstance = (parent instanceof ServerInstance); + _ephemeral = true; + _editable = null; + rebuild(descriptor); } void write(XMLWriter writer) throws java.io.IOException { - if(!_ephemeral) - { - writePropertySet(writer, _unsubstitutedId, - _inServerInstance ? "service" : "id", - _descriptor, null, null); - } + if(!_ephemeral) + { + writePropertySet(writer, _unsubstitutedId, + _inServerInstance ? "service" : "id", + _descriptor, null, null); + } } void rebuild(PropertySetDescriptor descriptor) { - _descriptor = descriptor; + _descriptor = descriptor; } private PropertySetDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/PropertySetEditor.java b/java/src/IceGridGUI/Application/PropertySetEditor.java index dae73a2ab60..bad0ca590d2 100755 --- a/java/src/IceGridGUI/Application/PropertySetEditor.java +++ b/java/src/IceGridGUI/Application/PropertySetEditor.java @@ -34,240 +34,240 @@ class PropertySetEditor extends Editor { protected boolean applyUpdate(boolean refresh) { - PropertySet nps = (PropertySet)_target; - Root root = nps.getRoot(); - - root.disableSelectionListener(); - try - { - PropertySetParent parent = (PropertySetParent)nps.getParent(); - if(nps.isEphemeral()) - { - writeDescriptor(); - PropertySetDescriptor descriptor = - (PropertySetDescriptor)nps.getDescriptor(); - nps.destroy(); // just removes the child - - try - { - parent.tryAdd(getIdText(), descriptor); - } - catch(UpdateFailedException e) - { - // - // Add back ephemeral child - // - try - { - parent.insertPropertySet(nps, true); - } - catch(UpdateFailedException die) - { - assert false; - } - root.setSelectedNode(_target); - - JOptionPane.showMessageDialog( - root.getCoordinator().getMainFrame(), - e.toString(), - "Apply failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - // - // Success - // - _target = ((TreeNode)parent).findChildWithDescriptor(descriptor); - root.updated(); - if(refresh) - { - root.setSelectedNode(_target); - } - } - else if(!isSimpleUpdate()) - { - PropertySetDescriptor descriptor = - (PropertySetDescriptor)nps.getDescriptor(); - - try - { - parent.tryRename(_target.getId(), _oldId, getIdText()); - } - catch(UpdateFailedException e) - { - JOptionPane.showMessageDialog( - root.getCoordinator().getMainFrame(), - e.toString(), - "Apply failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - // - // Success - // - _target = ((TreeNode)parent).findChildWithDescriptor(descriptor); - writeDescriptor(); - root.updated(); - if(refresh) - { - root.setSelectedNode(_target); - } - } - else - { - writeDescriptor(); - root.updated(); - nps.getEditable().markModified(); - } - - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + PropertySet nps = (PropertySet)_target; + Root root = nps.getRoot(); + + root.disableSelectionListener(); + try + { + PropertySetParent parent = (PropertySetParent)nps.getParent(); + if(nps.isEphemeral()) + { + writeDescriptor(); + PropertySetDescriptor descriptor = + (PropertySetDescriptor)nps.getDescriptor(); + nps.destroy(); // just removes the child + + try + { + parent.tryAdd(getIdText(), descriptor); + } + catch(UpdateFailedException e) + { + // + // Add back ephemeral child + // + try + { + parent.insertPropertySet(nps, true); + } + catch(UpdateFailedException die) + { + assert false; + } + root.setSelectedNode(_target); + + JOptionPane.showMessageDialog( + root.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + // + // Success + // + _target = ((TreeNode)parent).findChildWithDescriptor(descriptor); + root.updated(); + if(refresh) + { + root.setSelectedNode(_target); + } + } + else if(!isSimpleUpdate()) + { + PropertySetDescriptor descriptor = + (PropertySetDescriptor)nps.getDescriptor(); + + try + { + parent.tryRename(_target.getId(), _oldId, getIdText()); + } + catch(UpdateFailedException e) + { + JOptionPane.showMessageDialog( + root.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + // + // Success + // + _target = ((TreeNode)parent).findChildWithDescriptor(descriptor); + writeDescriptor(); + root.updated(); + if(refresh) + { + root.setSelectedNode(_target); + } + } + else + { + writeDescriptor(); + root.updated(); + nps.getEditable().markModified(); + } + + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } Utils.Resolver getDetailResolver() { - Root root = _target.getRoot(); - - if(root.getCoordinator().substitute()) - { - return _target.getResolver(); - } - else - { - return null; - } + Root root = _target.getRoot(); + + if(root.getCoordinator().substitute()) + { + return _target.getResolver(); + } + else + { + return null; + } } PropertySetEditor() { - this("ID"); - _id.setToolTipText("The id of this Property Set"); - _id.getDocument().addDocumentListener(_updateListener); + this("ID"); + _id.setToolTipText("The id of this Property Set"); + _id.getDocument().addDocumentListener(_updateListener); } protected PropertySetEditor(String label) { - _idLabel = new JLabel(label); + _idLabel = new JLabel(label); - _propertySets.getDocument().addDocumentListener(_updateListener); - _propertySets.setToolTipText("Property Set References"); - _properties = new PropertiesField(this); + _propertySets.getDocument().addDocumentListener(_updateListener); + _propertySets.setToolTipText("Property Set References"); + _properties = new PropertiesField(this); } void writeDescriptor() { - PropertySetDescriptor descriptor = - (PropertySetDescriptor)getPropertySet().getDescriptor(); + PropertySetDescriptor descriptor = + (PropertySetDescriptor)getPropertySet().getDescriptor(); - descriptor.references = - (String[])_propertySets.getList().toArray(new String[0]); - descriptor.properties = _properties.getProperties(); - } + descriptor.references = + (String[])_propertySets.getList().toArray(new String[0]); + descriptor.properties = _properties.getProperties(); + } boolean isSimpleUpdate() { - return getIdText().equals(_oldId); + return getIdText().equals(_oldId); } protected void appendProperties(DefaultFormBuilder builder) { - builder.append(_idLabel); - builder.append(getIdComponent(), 3); - builder.nextLine(); - - builder.append("Property Sets"); - builder.append(_propertySets, 3); - builder.nextLine(); - - builder.append("Properties"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - - builder.nextRow(-6); - JScrollPane scrollPane = new JScrollPane(_properties); - CellConstraints cc = new CellConstraints(); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + builder.append(_idLabel); + builder.append(getIdComponent(), 3); + builder.nextLine(); + + builder.append("Property Sets"); + builder.append(_propertySets, 3); + builder.nextLine(); + + builder.append("Properties"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + + builder.nextRow(-6); + JScrollPane scrollPane = new JScrollPane(_properties); + CellConstraints cc = new CellConstraints(); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Named Property Set"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Named Property Set"); } protected boolean validate() { - return check(new String[]{_idLabel.getText(), getIdText()}); + return check(new String[]{_idLabel.getText(), getIdText()}); } void show(String unsubstitutedId, PropertySet nps) { - detectUpdates(false); - _target = nps; - - Utils.Resolver resolver = getDetailResolver(); - boolean isEditable = (resolver == null); - - PropertySetDescriptor descriptor = - (PropertySetDescriptor)nps.getDescriptor(); - - showId(unsubstitutedId, resolver); - _oldId = unsubstitutedId; - - _propertySets.setList(java.util.Arrays.asList(descriptor.references), - resolver); - _propertySets.setEditable(isEditable); - - _properties.setProperties(descriptor.properties, null, null, - getDetailResolver(), isEditable); - - _applyButton.setEnabled(nps.isEphemeral()); - _discardButton.setEnabled(nps.isEphemeral()); - detectUpdates(true); + detectUpdates(false); + _target = nps; + + Utils.Resolver resolver = getDetailResolver(); + boolean isEditable = (resolver == null); + + PropertySetDescriptor descriptor = + (PropertySetDescriptor)nps.getDescriptor(); + + showId(unsubstitutedId, resolver); + _oldId = unsubstitutedId; + + _propertySets.setList(java.util.Arrays.asList(descriptor.references), + resolver); + _propertySets.setEditable(isEditable); + + _properties.setProperties(descriptor.properties, null, null, + getDetailResolver(), isEditable); + + _applyButton.setEnabled(nps.isEphemeral()); + _discardButton.setEnabled(nps.isEphemeral()); + detectUpdates(true); } protected JComponent getIdComponent() { - return _id; + return _id; } protected String getIdText() { - return _id.getText().trim(); + return _id.getText().trim(); } protected void showId(String unsubstitutedId, Utils.Resolver resolver) { - // - // This version does NOT substitute the ID - // - _id.setText(unsubstitutedId); - _id.setEditable(resolver == null); + // + // This version does NOT substitute the ID + // + _id.setText(unsubstitutedId); + _id.setEditable(resolver == null); } private PropertySet getPropertySet() { - return (PropertySet)_target; + return (PropertySet)_target; } private String _oldId; diff --git a/java/src/IceGridGUI/Application/PropertySetParent.java b/java/src/IceGridGUI/Application/PropertySetParent.java index b7a285650ff..9d5f7a254e8 100755 --- a/java/src/IceGridGUI/Application/PropertySetParent.java +++ b/java/src/IceGridGUI/Application/PropertySetParent.java @@ -14,13 +14,13 @@ import IceGridGUI.*; interface PropertySetParent { void tryAdd(String id, PropertySetDescriptor descriptor) - throws UpdateFailedException; + throws UpdateFailedException; void tryRename(String oldId, String oldUnresolveId, String newUnresolvedId) - throws UpdateFailedException; + throws UpdateFailedException; void insertPropertySet(PropertySet nps, boolean fireEvent) - throws UpdateFailedException; + throws UpdateFailedException; void removePropertySet(PropertySet nps); diff --git a/java/src/IceGridGUI/Application/PropertySets.java b/java/src/IceGridGUI/Application/PropertySets.java index 2f090f2fb57..843d0f2cc59 100755 --- a/java/src/IceGridGUI/Application/PropertySets.java +++ b/java/src/IceGridGUI/Application/PropertySets.java @@ -20,17 +20,17 @@ class PropertySets extends ListTreeNode implements PropertySetParent static public java.util.Map copyDescriptors(java.util.Map descriptors) { - java.util.Map copy = new java.util.HashMap(); - java.util.Iterator p = descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + java.util.Map copy = new java.util.HashMap(); + java.util.Iterator p = descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - copy.put(entry.getKey(), - PropertySet.copyDescriptor( - (PropertySetDescriptor)entry.getValue())); - } - return copy; + copy.put(entry.getKey(), + PropertySet.copyDescriptor( + (PropertySetDescriptor)entry.getValue())); + } + return copy; } // @@ -38,215 +38,215 @@ class PropertySets extends ListTreeNode implements PropertySetParent // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; + boolean[] actions = new boolean[ACTION_COUNT]; - Object descriptor = getCoordinator().getClipboard(); - if(descriptor != null) - { - actions[PASTE] = descriptor instanceof PropertySetDescriptor; - } + Object descriptor = getCoordinator().getClipboard(); + if(descriptor != null) + { + actions[PASTE] = descriptor instanceof PropertySetDescriptor; + } - actions[NEW_PROPERTY_SET] = true; - return actions; + actions[NEW_PROPERTY_SET] = true; + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_PROPERTY_SET)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_PROPERTY_SET)); + } + actions.setTarget(this); + return _popup; } public void newPropertySet() { - PropertySetDescriptor descriptor = new - PropertySetDescriptor(new String[0], - new java.util.LinkedList()); + PropertySetDescriptor descriptor = new + PropertySetDescriptor(new String[0], + new java.util.LinkedList()); - newPropertySet(descriptor); + newPropertySet(descriptor); } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - - PropertySetDescriptor d = PropertySet.copyDescriptor( - (PropertySetDescriptor)descriptor); - newPropertySet(d); + Object descriptor = getCoordinator().getClipboard(); + + PropertySetDescriptor d = PropertySet.copyDescriptor( + (PropertySetDescriptor)descriptor); + newPropertySet(d); } PropertySets(TreeNode parent, java.util.Map desc) - throws UpdateFailedException + throws UpdateFailedException { - super(false, parent, "Property Sets"); - _descriptors = desc; - - java.util.Iterator p = _descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - String id = (String)entry.getKey(); + super(false, parent, "Property Sets"); + _descriptors = desc; + + java.util.Iterator p = _descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + String id = (String)entry.getKey(); - insertChild(new PropertySet(false, this, id, id, - (PropertySetDescriptor)entry.getValue()), false); - } + insertChild(new PropertySet(false, this, id, id, + (PropertySetDescriptor)entry.getValue()), false); + } } void update(java.util.Map updates, String[] removePropertySets) - throws UpdateFailedException - { - // - // Note: _descriptors is updated by Root - // - - // - // One big set of removes - // - removeChildren(removePropertySets); - - // - // One big set of updates, followed by inserts - // - java.util.Vector newChildren = new java.util.Vector(); - - java.util.Iterator p = updates.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String id = (String)entry.getKey(); - PropertySetDescriptor psd = (PropertySetDescriptor)entry.getValue(); - PropertySet child = (PropertySet)findChild(id); - if(child == null) - { - newChildren.add( - new PropertySet(false, this, id, id, psd)); - } - else - { - child.rebuild(psd); - } - } - insertChildren(newChildren, true); + throws UpdateFailedException + { + // + // Note: _descriptors is updated by Root + // + + // + // One big set of removes + // + removeChildren(removePropertySets); + + // + // One big set of updates, followed by inserts + // + java.util.Vector newChildren = new java.util.Vector(); + + java.util.Iterator p = updates.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String id = (String)entry.getKey(); + PropertySetDescriptor psd = (PropertySetDescriptor)entry.getValue(); + PropertySet child = (PropertySet)findChild(id); + if(child == null) + { + newChildren.add( + new PropertySet(false, this, id, id, psd)); + } + else + { + child.rebuild(psd); + } + } + insertChildren(newChildren, true); } java.util.Map getUpdates() { - java.util.Map updates = new java.util.HashMap(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - if(ps.getEditable().isNew() || ps.getEditable().isModified()) - { - updates.put(ps.getId(), ps.getDescriptor()); - } - } - return updates; + java.util.Map updates = new java.util.HashMap(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + if(ps.getEditable().isNew() || ps.getEditable().isModified()) + { + updates.put(ps.getId(), ps.getDescriptor()); + } + } + return updates; } void commit() { - _editable.commit(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - ps.commit(); - } + _editable.commit(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + ps.commit(); + } } Object getDescriptor() { - return _descriptors; + return _descriptors; } public void tryAdd(String id, PropertySetDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertChild( - new PropertySet(true, this, id, id, descriptor), - true); + insertChild( + new PropertySet(true, this, id, id, descriptor), + true); - _descriptors.put(id, descriptor); + _descriptors.put(id, descriptor); } public void tryRename(String oldId, String oldId2, String newId) - throws UpdateFailedException - { - PropertySet oldChild = (PropertySet)findChild(oldId); - assert oldChild != null; - removeChild(oldChild); - PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); - - try - { - insertChild( - new PropertySet(true, this, newId, newId, descriptor), - true); - } - catch(UpdateFailedException ex) - { - try - { - insertChild(oldChild, true); - } - catch(UpdateFailedException ufe) - { - assert false; - } - throw ex; - } - - _editable.removeElement(oldId, oldChild.getEditable(), PropertySet.class); - _descriptors.remove(oldId); - _descriptors.put(newId, descriptor); + throws UpdateFailedException + { + PropertySet oldChild = (PropertySet)findChild(oldId); + assert oldChild != null; + removeChild(oldChild); + PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); + + try + { + insertChild( + new PropertySet(true, this, newId, newId, descriptor), + true); + } + catch(UpdateFailedException ex) + { + try + { + insertChild(oldChild, true); + } + catch(UpdateFailedException ufe) + { + assert false; + } + throw ex; + } + + _editable.removeElement(oldId, oldChild.getEditable(), PropertySet.class); + _descriptors.remove(oldId); + _descriptors.put(newId, descriptor); } public void insertPropertySet(PropertySet nps, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - insertChild(nps, fireEvent); + insertChild(nps, fireEvent); } public void removePropertySet(PropertySet nps) { - removeChild(nps); + removeChild(nps); } public void removeDescriptor(String id) { - _descriptors.remove(id); + _descriptors.remove(id); } public Editable getEditable() { - return super.getEditable(); + return super.getEditable(); } private void newPropertySet(PropertySetDescriptor descriptor) { - String id = makeNewChildId("PropertySet"); + String id = makeNewChildId("PropertySet"); - PropertySet propertySet = - new PropertySet(this, id, descriptor); + PropertySet propertySet = + new PropertySet(this, id, descriptor); - try - { - insertChild(propertySet, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(propertySet); + try + { + insertChild(propertySet, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(propertySet); } private java.util.Map _descriptors; diff --git a/java/src/IceGridGUI/Application/ReplicaGroup.java b/java/src/IceGridGUI/Application/ReplicaGroup.java index a65a48b3989..50abc1dd7e2 100755 --- a/java/src/IceGridGUI/Application/ReplicaGroup.java +++ b/java/src/IceGridGUI/Application/ReplicaGroup.java @@ -20,27 +20,27 @@ class ReplicaGroup extends TreeNode static public ReplicaGroupDescriptor copyDescriptor(ReplicaGroupDescriptor d) { - return (ReplicaGroupDescriptor)d.clone(); + 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); + 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); } // @@ -48,173 +48,173 @@ class ReplicaGroup extends TreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - if(((TreeNode)_parent).getAvailableActions()[PASTE]) - { - actions[PASTE] = true; - } - actions[DELETE] = true; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + if(((TreeNode)_parent).getAvailableActions()[PASTE]) + { + actions[PASTE] = true; + } + actions[DELETE] = true; - if(!_ephemeral) - { - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - } - return actions; + 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); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public void destroy() { - ReplicaGroups replicaGroups = (ReplicaGroups)_parent; - replicaGroups.removeChild(this); + ReplicaGroups replicaGroups = (ReplicaGroups)_parent; + replicaGroups.removeChild(this); - if(!_ephemeral) - { - replicaGroups.removeDescriptor(_descriptor); - replicaGroups.getEditable(). - removeElement(_id, _editable, ReplicaGroup.class); - getRoot().updated(); - } + if(!_ephemeral) + { + replicaGroups.removeDescriptor(_descriptor); + replicaGroups.getEditable(). + removeElement(_id, _editable, ReplicaGroup.class); + getRoot().updated(); + } } public Editor getEditor() { - if(_editor == null) - { - _editor = (ReplicaGroupEditor)getRoot().getEditor(ReplicaGroupEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (ReplicaGroupEditor)getRoot().getEditor(ReplicaGroupEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ReplicaGroupEditor(); + return new ReplicaGroupEditor(); } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } Object getDescriptor() { - return _descriptor; + return _descriptor; } Object saveDescriptor() { - return _descriptor.clone(); + 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; + 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.commit(); } Editable getEditable() { - return _editable; + return _editable; } ReplicaGroup(boolean brandNew, - TreeNode parent, - ReplicaGroupDescriptor descriptor) + TreeNode parent, + ReplicaGroupDescriptor descriptor) { - super(parent, descriptor.id); - _ephemeral = false; - _editable = new Editable(brandNew); - rebuild(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); + 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); - } - assert _descriptor.loadBalancing != null; - - attributes.clear(); - if(_descriptor.loadBalancing instanceof RandomLoadBalancingPolicy) - { - attributes.add(createAttribute("type", "random")); - } - else if(_descriptor.loadBalancing instanceof OrderedLoadBalancingPolicy) - { - attributes.add(createAttribute("type", "ordered")); - } - 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("object", writer, _descriptor.objects, null); - writer.writeEndTag("replica-group"); - } - } + 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); + } + assert _descriptor.loadBalancing != null; + + attributes.clear(); + if(_descriptor.loadBalancing instanceof RandomLoadBalancingPolicy) + { + attributes.add(createAttribute("type", "random")); + } + else if(_descriptor.loadBalancing instanceof OrderedLoadBalancingPolicy) + { + attributes.add(createAttribute("type", "ordered")); + } + 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("object", writer, _descriptor.objects, null); + writer.writeEndTag("replica-group"); + } + } } void rebuild(ReplicaGroupDescriptor descriptor) { - _descriptor = descriptor; - // - // And that's it since there is no children - // + _descriptor = descriptor; + // + // And that's it since there is no children + // } private ReplicaGroupDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/ReplicaGroupEditor.java b/java/src/IceGridGUI/Application/ReplicaGroupEditor.java index a93852cd935..d0762ed687a 100755 --- a/java/src/IceGridGUI/Application/ReplicaGroupEditor.java +++ b/java/src/IceGridGUI/Application/ReplicaGroupEditor.java @@ -34,402 +34,402 @@ class ReplicaGroupEditor extends Editor { protected boolean applyUpdate(boolean refresh) { - 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 false; - } - - // - // 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 false; - } - - // - // Success - // - - // replaced by brand new ReplicaGroup - replicaGroups.getEditable(). - removeElement(replicaGroup.getId(), - replicaGroup.getEditable(), ReplicaGroup.class); - - _target = replicaGroups.findChildWithDescriptor(descriptor); - root.updated(); - - if(refresh) - { - root.setSelectedNode(_target); - } - } - - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + 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 false; + } + + // + // 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 false; + } + + // + // Success + // + + // replaced by brand new ReplicaGroup + replicaGroups.getEditable(). + removeElement(replicaGroup.getId(), + replicaGroup.getEditable(), ReplicaGroup.class); + + _target = replicaGroups.findChildWithDescriptor(descriptor); + root.updated(); + + if(refresh) + { + root.setSelectedNode(_target); + } + } + + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } Utils.Resolver getDetailResolver() { - Root root = _target.getRoot(); - - if(root.getCoordinator().substitute()) - { - return root.getResolver(); - } - else - { - return null; - } + Root root = _target.getRoot(); + + if(root.getCoordinator().substitute()) + { + return root.getResolver(); + } + else + { + return null; + } } ReplicaGroupEditor() { - _objects = new MapField(this, "Identity", "Type", true); - - // - // load balancing - // - _loadBalancing.addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - if(e.getStateChange() == ItemEvent.SELECTED) - { - updated(); - - Object item = e.getItem(); - _loadSampleLabel.setVisible(item == ADAPTIVE); - _loadSample.setVisible(item == ADAPTIVE); - } - } - }); - _loadBalancing.setToolTipText( - "<html>Specifies how IceGrid selects adapters and return<br>" - + "their endpoints when resolving a replica group ID</html>"); - - // - // 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.<br>" - + "Enter 0 to returns the endpoints of all adapters.</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?"); + _objects = new MapField(this, "Identity", "Type", true); + + // + // load balancing + // + _loadBalancing.addItemListener(new ItemListener() + { + public void itemStateChanged(ItemEvent e) + { + if(e.getStateChange() == ItemEvent.SELECTED) + { + updated(); + + Object item = e.getItem(); + _loadSampleLabel.setVisible(item == ADAPTIVE); + _loadSample.setVisible(item == ADAPTIVE); + } + } + }); + _loadBalancing.setToolTipText( + "<html>Specifies how IceGrid selects adapters and return<br>" + + "their endpoints when resolving a replica group ID</html>"); + + // + // 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.<br>" + + "Enter 0 to returns the endpoints of all adapters.</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().trim(); - descriptor.description = _description.getText(); - descriptor.objects = mapToObjectDescriptorSeq(_objects.get()); - - Object loadBalancing = _loadBalancing.getSelectedItem(); - if(loadBalancing == ORDERED) - { - descriptor.loadBalancing = new OrderedLoadBalancingPolicy( - _nReplicas.getText().trim()); - } - else if(loadBalancing == RANDOM) - { - descriptor.loadBalancing = new RandomLoadBalancingPolicy( - _nReplicas.getText().trim()); - } - else if(loadBalancing == ROUND_ROBIN) - { - descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy( - _nReplicas.getText().trim()); - } - else if(loadBalancing == ADAPTIVE) - { - descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy( - _nReplicas.getText().trim(), - _loadSample.getSelectedItem().toString().trim()); - } - else - { - assert false; - } - } + ReplicaGroupDescriptor descriptor = + (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor(); + + descriptor.id = _id.getText().trim(); + descriptor.description = _description.getText(); + descriptor.objects = mapToObjectDescriptorSeq(_objects.get()); + + Object loadBalancing = _loadBalancing.getSelectedItem(); + if(loadBalancing == ORDERED) + { + descriptor.loadBalancing = new OrderedLoadBalancingPolicy( + _nReplicas.getText().trim()); + } + else if(loadBalancing == RANDOM) + { + descriptor.loadBalancing = new RandomLoadBalancingPolicy( + _nReplicas.getText().trim()); + } + else if(loadBalancing == ROUND_ROBIN) + { + descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy( + _nReplicas.getText().trim()); + } + else if(loadBalancing == ADAPTIVE) + { + descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy( + _nReplicas.getText().trim(), + _loadSample.getSelectedItem().toString().trim()); + } + else + { + assert false; + } + } boolean isSimpleUpdate() { - ReplicaGroupDescriptor descriptor = - (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor(); - return descriptor.id.equals(_id.getText().trim()); + ReplicaGroupDescriptor descriptor = + (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor(); + return descriptor.id.equals(_id.getText().trim()); } 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("Well-known Objects"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_objects); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); - - builder.append("Load Balancing Policy"); - builder.append(_loadBalancing, 3); - builder.nextLine(); - builder.append("How many Adapters? (0 = all)"); - builder.append(_nReplicas, 3); - builder.nextLine(); - _loadSampleLabel = builder.append("Load Sample"); - builder.append(_loadSample, 3); - builder.nextLine(); + 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("Well-known Objects"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_objects); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); + + builder.append("Load Balancing Policy"); + builder.append(_loadBalancing, 3); + builder.nextLine(); + builder.append("How many Adapters? (0 = all)"); + 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"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Replica Group Properties"); } protected boolean validate() { - return check(new String[]{"Replica Group ID", _id.getText().trim()}); + return check(new String[]{"Replica Group ID", _id.getText().trim()}); } 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); - - _objects.set(objectDescriptorSeqToMap(descriptor.objects), resolver, isEditable); - - _loadBalancing.setEnabled(true); - - if(descriptor.loadBalancing == null) - { - _loadBalancing.setSelectedItem(RANDOM); - _nReplicas.setText("0"); - _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 OrderedLoadBalancingPolicy) - { - _loadBalancing.setSelectedItem(ORDERED); - _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); + // + // 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); + + _objects.set(objectDescriptorSeqToMap(descriptor.objects), resolver, isEditable); + + _loadBalancing.setEnabled(true); + + if(descriptor.loadBalancing == null) + { + _loadBalancing.setSelectedItem(RANDOM); + _nReplicas.setText("0"); + _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 OrderedLoadBalancingPolicy) + { + _loadBalancing.setSelectedItem(ORDERED); + _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; + return (ReplicaGroup)_target; } private java.util.Map objectDescriptorSeqToMap(java.util.List objects) { - java.util.Map result = new java.util.TreeMap(); - 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; + java.util.Map result = new java.util.TreeMap(); + 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; } private 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; + 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; } @@ -442,13 +442,13 @@ class ReplicaGroupEditor extends Editor private JTextArea _description = new JTextArea(3, 20); private JComboBox _loadBalancing = new JComboBox(new Object[] - {ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN}); + {ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN}); private JTextField _nReplicas = new JTextField(20); private JLabel _loadSampleLabel; private JComboBox _loadSample = new JComboBox(new Object[] - {"1", "5", "15"}); + {"1", "5", "15"}); private MapField _objects; } diff --git a/java/src/IceGridGUI/Application/ReplicaGroups.java b/java/src/IceGridGUI/Application/ReplicaGroups.java index 47960ef28bc..6ab770a779a 100755 --- a/java/src/IceGridGUI/Application/ReplicaGroups.java +++ b/java/src/IceGridGUI/Application/ReplicaGroups.java @@ -20,14 +20,14 @@ class ReplicaGroups extends ListTreeNode static public java.util.List copyDescriptors(java.util.List descriptors) { - java.util.List copy = new java.util.LinkedList(); - java.util.Iterator p = descriptors.iterator(); - while(p.hasNext()) - { - copy.add(ReplicaGroup.copyDescriptor( - (ReplicaGroupDescriptor)p.next())); - } - return copy; + java.util.List copy = new java.util.LinkedList(); + java.util.Iterator p = descriptors.iterator(); + while(p.hasNext()) + { + copy.add(ReplicaGroup.copyDescriptor( + (ReplicaGroupDescriptor)p.next())); + } + return copy; } // @@ -35,198 +35,198 @@ class ReplicaGroups extends ListTreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; + boolean[] actions = new boolean[ACTION_COUNT]; - Object descriptor = getCoordinator().getClipboard(); - if(descriptor != null) - { - actions[PASTE] = descriptor instanceof ReplicaGroupDescriptor; - } + Object descriptor = getCoordinator().getClipboard(); + if(descriptor != null) + { + actions[PASTE] = descriptor instanceof ReplicaGroupDescriptor; + } - actions[NEW_REPLICA_GROUP] = true; - return actions; + actions[NEW_REPLICA_GROUP] = true; + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_REPLICA_GROUP)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_REPLICA_GROUP)); + } + actions.setTarget(this); + return _popup; } public void newReplicaGroup() { - ReplicaGroupDescriptor descriptor = new - ReplicaGroupDescriptor( - makeNewChildId("NewReplicaGroup"), - null, - new java.util.LinkedList(), - ""); - - newReplicaGroup(descriptor); + ReplicaGroupDescriptor descriptor = new + ReplicaGroupDescriptor( + makeNewChildId("NewReplicaGroup"), + null, + new java.util.LinkedList(), + ""); + + newReplicaGroup(descriptor); } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - - ReplicaGroupDescriptor d = ReplicaGroup.copyDescriptor( - (ReplicaGroupDescriptor)descriptor); - d.id = makeNewChildId(d.id); - newReplicaGroup(d); + Object descriptor = getCoordinator().getClipboard(); + + ReplicaGroupDescriptor d = ReplicaGroup.copyDescriptor( + (ReplicaGroupDescriptor)descriptor); + d.id = makeNewChildId(d.id); + newReplicaGroup(d); } ReplicaGroups(TreeNode parent, java.util.List desc) throws UpdateFailedException { - super(false, parent, "Replica Groups"); - _descriptors = desc; - - java.util.Iterator p = _descriptors.iterator(); - while(p.hasNext()) - { - ReplicaGroupDescriptor descriptor - = (ReplicaGroupDescriptor)p.next(); - - insertChild(new ReplicaGroup(false, this, descriptor), false); - } + super(false, parent, "Replica Groups"); + _descriptors = desc; + + java.util.Iterator p = _descriptors.iterator(); + while(p.hasNext()) + { + ReplicaGroupDescriptor descriptor + = (ReplicaGroupDescriptor)p.next(); + + insertChild(new ReplicaGroup(false, this, descriptor), false); + } } java.util.LinkedList getUpdates() { - java.util.LinkedList updates = new java.util.LinkedList(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ReplicaGroup ra = (ReplicaGroup)p.next(); - if(ra.getEditable().isNew() || ra.getEditable().isModified()) - { - updates.add(ra.getDescriptor()); - } - } - return updates; + java.util.LinkedList updates = new java.util.LinkedList(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + ReplicaGroup ra = (ReplicaGroup)p.next(); + if(ra.getEditable().isNew() || ra.getEditable().isModified()) + { + updates.add(ra.getDescriptor()); + } + } + return updates; } void commit() { - _editable.commit(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ReplicaGroup rg = (ReplicaGroup)p.next(); - rg.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[] removeReplicaGroups) { - _descriptors = descriptors; - - // - // One big set of removes - // - removeChildren(removeReplicaGroups); - - // - // Updates and inserts - // - java.util.List updatedChildren = new java.util.LinkedList(); - java.util.Iterator p = descriptors.iterator(); - while(p.hasNext()) - { - ReplicaGroupDescriptor descriptor = - (ReplicaGroupDescriptor)p.next(); - - ReplicaGroup child - = (ReplicaGroup)findChild(descriptor.id); - - if(child == null) - { - try - { - insertChild( - new ReplicaGroup(false, this, descriptor), - true); - } - catch(UpdateFailedException e) - { - assert false; - } - } - else - { - child.rebuild(descriptor); - updatedChildren.add(child); - } - } - childrenChanged(updatedChildren); + _descriptors = descriptors; + + // + // One big set of removes + // + removeChildren(removeReplicaGroups); + + // + // Updates and inserts + // + java.util.List updatedChildren = new java.util.LinkedList(); + java.util.Iterator p = descriptors.iterator(); + while(p.hasNext()) + { + ReplicaGroupDescriptor descriptor = + (ReplicaGroupDescriptor)p.next(); + + ReplicaGroup child + = (ReplicaGroup)findChild(descriptor.id); + + if(child == null) + { + try + { + insertChild( + new ReplicaGroup(false, this, descriptor), + true); + } + catch(UpdateFailedException e) + { + assert false; + } + } + else + { + child.rebuild(descriptor); + updatedChildren.add(child); + } + } + childrenChanged(updatedChildren); } Object getDescriptor() { - return _descriptors; + return _descriptors; } /* Object saveDescriptor() { - assert false; - return null; + assert false; + return null; } void restoreDescriptor(Object savedDescriptor) { - assert false; + assert false; } */ 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; - } - } + // + // 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; + } + } } void tryAdd(ReplicaGroupDescriptor descriptor, boolean addDescriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertChild( - new ReplicaGroup(true, this, descriptor), - true); - - if(addDescriptor) - { - _descriptors.add(descriptor); - } + insertChild( + new ReplicaGroup(true, this, descriptor), + true); + + if(addDescriptor) + { + _descriptors.add(descriptor); + } } private void newReplicaGroup(ReplicaGroupDescriptor descriptor) { - ReplicaGroup replicaGroup = - new ReplicaGroup(this, descriptor); - - try - { - insertChild(replicaGroup, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(replicaGroup); + ReplicaGroup replicaGroup = + new ReplicaGroup(this, descriptor); + + try + { + insertChild(replicaGroup, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(replicaGroup); } private java.util.List _descriptors; diff --git a/java/src/IceGridGUI/Application/Root.java b/java/src/IceGridGUI/Application/Root.java index 80122504967..572f2e00897 100755 --- a/java/src/IceGridGUI/Application/Root.java +++ b/java/src/IceGridGUI/Application/Root.java @@ -32,19 +32,19 @@ public class Root extends ListTreeNode // Construct a normal, existing Application // public Root(Coordinator coordinator, ApplicationDescriptor desc, - boolean live, File file) throws UpdateFailedException + boolean live, File file) throws UpdateFailedException { - super(false, null, desc.name); - _coordinator = coordinator; - _traceSaveToRegistry = coordinator.traceSaveToRegistry(); + super(false, null, desc.name); + _coordinator = coordinator; + _traceSaveToRegistry = coordinator.traceSaveToRegistry(); - _descriptor = desc; + _descriptor = desc; - _file = file; - _live = live; + _file = file; + _live = live; - init(); + init(); } // @@ -52,144 +52,144 @@ public class Root extends ListTreeNode // public Root(Coordinator coordinator, ApplicationDescriptor desc) { - super(true, null, desc.name); - _coordinator = coordinator; - _traceSaveToRegistry = coordinator.traceSaveToRegistry(); - _descriptor = desc; - - _file = null; - _live = false; - - try - { - init(); - } - catch(UpdateFailedException e) - { - // - // Impossible - // - assert false; - } + super(true, null, desc.name); + _coordinator = coordinator; + _traceSaveToRegistry = coordinator.traceSaveToRegistry(); + _descriptor = desc; + + _file = null; + _live = false; + + try + { + init(); + } + catch(UpdateFailedException e) + { + // + // Impossible + // + assert false; + } } private void init() throws UpdateFailedException { - _resolver = new Utils.Resolver(_descriptor.variables); - _resolver.put("application", _descriptor.name); + _resolver = new Utils.Resolver(_descriptor.variables); + _resolver.put("application", _descriptor.name); - _origVariables = _descriptor.variables; - _origDescription = _descriptor.description; - _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone(); + _origVariables = _descriptor.variables; + _origDescription = _descriptor.description; + _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone(); - _propertySets = new PropertySets(this, _descriptor.propertySets); - _replicaGroups = new ReplicaGroups(this, _descriptor.replicaGroups); - _serviceTemplates = new ServiceTemplates(this, _descriptor.serviceTemplates); - _serverTemplates = new ServerTemplates(this, _descriptor.serverTemplates); - _nodes = new Nodes(this, _descriptor.nodes); + _propertySets = new PropertySets(this, _descriptor.propertySets); + _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(_propertySets); - _children.add(_replicaGroups); - _children.add(_serverTemplates); - _children.add(_serviceTemplates); + _children.add(_nodes); + _children.add(_propertySets); + _children.add(_replicaGroups); + _children.add(_serverTemplates); + _children.add(_serviceTemplates); - _tree = new JTree(this, true); - _treeModel = (DefaultTreeModel)_tree.getModel(); + _tree = new JTree(this, true); + _treeModel = (DefaultTreeModel)_tree.getModel(); - // - // Rebind "copy" and "paste" - // - javax.swing.ActionMap am = _tree.getActionMap(); - am.put("copy", _coordinator.getActionsForMenu().get(COPY)); - am.put("paste", _coordinator.getActionsForMenu().get(PASTE)); + // + // Rebind "copy" and "paste" + // + javax.swing.ActionMap am = _tree.getActionMap(); + am.put("copy", _coordinator.getActionsForMenu().get(COPY)); + am.put("paste", _coordinator.getActionsForMenu().get(PASTE)); } static public ApplicationDescriptor copyDescriptor(ApplicationDescriptor ad) { - ApplicationDescriptor copy = (ApplicationDescriptor)ad.clone(); - - copy.propertySets = PropertySets.copyDescriptors(copy.propertySets); + ApplicationDescriptor copy = (ApplicationDescriptor)ad.clone(); + + copy.propertySets = PropertySets.copyDescriptors(copy.propertySets); - 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.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; + 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; + if(_editor == null) + { + _editor = (ApplicationEditor) + getEditor(ApplicationEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ApplicationEditor(); + return new ApplicationEditor(); } 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; + 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; } // @@ -197,1091 +197,1091 @@ public class Root extends ListTreeNode // 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; + 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()); + _tree.setSelectionPath(node.getPath()); } public TreeNode getSelectedNode() { - TreePath path = _tree.getSelectionPath(); - if(path == null) - { - return null; - } - else - { - return (TreeNode)path.getLastPathComponent(); - } + 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 = node.findServer(serverId); - if(server != null) - { - target = (TreeNode)server; - } - } - setSelectedNode(target); - } + TreeNode target = _nodes; + if(target != null) + { + Node node = (Node)target.findChild(nodeName); + if(node != null) + { + target = node; + Server server = node.findServer(serverId); + if(server != null) + { + target = (TreeNode)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); + 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]; + boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = true; - actions[DELETE] = true; + actions[COPY] = true; + actions[DELETE] = true; - Object descriptor = _coordinator.getClipboard(); - if(descriptor != null) - { - actions[PASTE] = descriptor instanceof ApplicationDescriptor; - } + Object descriptor = _coordinator.getClipboard(); + if(descriptor != null) + { + actions[PASTE] = descriptor instanceof ApplicationDescriptor; + } - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - actions[NEW_NODE] = true; - actions[NEW_PROPERTY_SET] = true; - actions[NEW_REPLICA_GROUP] = true; - actions[NEW_TEMPLATE_SERVER] = true; - actions[NEW_TEMPLATE_SERVER_ICEBOX] = true; - actions[NEW_TEMPLATE_SERVICE] = true; + actions[SHOW_VARS] = true; + actions[SUBSTITUTE_VARS] = true; + actions[NEW_NODE] = true; + actions[NEW_PROPERTY_SET] = true; + actions[NEW_REPLICA_GROUP] = true; + actions[NEW_TEMPLATE_SERVER] = true; + actions[NEW_TEMPLATE_SERVER_ICEBOX] = true; + actions[NEW_TEMPLATE_SERVICE] = true; - return actions; + 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_PROPERTY_SET)); - _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; + ApplicationActions actions = _coordinator.getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_NODE)); + _popup.add(actions.get(NEW_PROPERTY_SET)); + _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); + _coordinator.setClipboard(copyDescriptor(_descriptor)); + _coordinator.getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - _coordinator.pasteApplication(); + _coordinator.pasteApplication(); } public void newNode() { - _nodes.newNode(); + _nodes.newNode(); } public void newPropertySet() { - _propertySets.newPropertySet(); + _propertySets.newPropertySet(); } public void newReplicaGroup() { - _replicaGroups.newReplicaGroup(); + _replicaGroups.newReplicaGroup(); } public void newTemplateServer() { - _serverTemplates.newTemplateServer(); + _serverTemplates.newTemplateServer(); } public void newTemplateServerIceBox() { - _serverTemplates.newTemplateServerIceBox(); + _serverTemplates.newTemplateServerIceBox(); } public void newTemplateService() { - _serviceTemplates.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; - } + 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() - { - private void release() - { - _coordinator.releaseExclusiveWriteAccess(); - _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - private void handleFailure(String prefix, String title, String message) - { - release(); - - if(isSelected()) - { - _coordinator.getSaveAction().setEnabled(isLive() && _coordinator.connectedToMaster() || hasFile()); - _coordinator.getSaveToRegistryAction().setEnabled(true); - _coordinator.getDiscardUpdatesAction().setEnabled(true); - } - - _coordinator.getStatusBar().setText(prefix + "failed!"); - - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - message, - title, - JOptionPane.ERROR_MESSAGE); - } - - - public void run() - { - _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - boolean asyncRelease = false; - - try - { - if(_live && _canUseUpdateDescriptor) - { - ApplicationUpdateDescriptor updateDescriptor = createUpdateDescriptor(); - if(updateDescriptor != null) - { - final String prefix = "Updating application '" + _id + "'..."; - _coordinator.getStatusBar().setText(prefix); - - AMI_Admin_updateApplication cb = new AMI_Admin_updateApplication() - { - public void ice_response() - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": success"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - commit(); - release(); - _coordinator.getStatusBar().setText(prefix + "done."); - } - }); - } - - public void ice_exception(final Ice.UserException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _skipUpdates--; - handleFailure(prefix, "Update failed", - "IceGrid exception: " + e.toString()); - } - - }); - } - - public void ice_exception(final Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _skipUpdates--; - handleFailure(prefix, "Update failed", - "Communication exception: " + e.toString()); - } - }); - } - - }; - - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("sending updateApplication for application " + _id); - } - - _coordinator.getAdmin().updateApplication_async(cb, updateDescriptor); - asyncRelease = true; - - // - // If updateApplication fails, we know we can't get other updates - // since we have exclusive write access - // - _skipUpdates++; - } - else - { - final String prefix = "Application '" + _id + "' is already up-to-date"; - _coordinator.getStatusBar().setText(prefix); - commit(); - } - } - else - { - // - // Add or sync application - // - if(_coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id) == null) - { - assert _live == false; - - - final String prefix = "Adding application '" + _id + "'..."; - _coordinator.getStatusBar().setText(prefix); - - AMI_Admin_addApplication cb = new AMI_Admin_addApplication() - { - public void ice_response() - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": success"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - commit(); - liveReset(); - _coordinator.addLiveApplication(Root.this); - release(); - _coordinator.getStatusBar().setText(prefix + "done."); - } - }); - } - - public void ice_exception(final Ice.UserException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure(prefix, "Add failed", - "IceGrid exception: " + e.toString()); - } - - }); - } - - public void ice_exception(final Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure(prefix, "Add failed", - "Communication exception: " + e.toString()); - } - }); - } - - }; - - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("sending addApplication for application " + _id); - } - - _coordinator.getAdmin().addApplication_async(cb, _descriptor); - asyncRelease = true; - } - else - { - final String prefix = "Synchronizing application '" + _id + "'..."; - _coordinator.getStatusBar().setText(prefix); - - AMI_Admin_syncApplication cb = new AMI_Admin_syncApplication() - { - public void ice_response() - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - commit(); - if(!_live) - { - // - // 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); - } - } - } - - release(); - _coordinator.getStatusBar().setText(prefix + "done."); - } - }); - } - - public void ice_exception(final Ice.UserException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - if(_live) - { - _skipUpdates--; - } - - handleFailure(prefix, "Sync failed", - "IceGrid exception: " + e.toString()); - } - - }); - } - - public void ice_exception(final Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - if(_live) - { - _skipUpdates--; - } - - handleFailure(prefix, "Sync failed", - "Communication exception: " + e.toString()); - } - }); - } - - }; - - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("sending syncApplication for application " + _id); - } - - _coordinator.getAdmin().syncApplication_async(cb, _descriptor); - asyncRelease = true; - if(_live) - { - _skipUpdates++; - } - } - } - if(isSelected()) - { - _coordinator.getSaveAction().setEnabled(false); - _coordinator.getSaveToRegistryAction().setEnabled(false); - _coordinator.getDiscardUpdatesAction().setEnabled(false); - } - } - catch(Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - _coordinator.traceSaveToRegistry("Ice communications exception while saving application " + _id); - } - - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - e.toString(), - "Communication Exception", - JOptionPane.ERROR_MESSAGE); - } - finally - { - if(!asyncRelease) - { - _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - _coordinator.releaseExclusiveWriteAccess(); - } - } - } - }; - - try - { - _coordinator.acquireExclusiveWriteAccess(runnable); - } - catch(AccessDeniedException e) - { - _coordinator.accessDenied(e); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - e.toString(), - "Communication Exception", - JOptionPane.ERROR_MESSAGE); - } + // + // To be run in GUI thread when exclusive write access is acquired + // + Runnable runnable = new Runnable() + { + private void release() + { + _coordinator.releaseExclusiveWriteAccess(); + _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + private void handleFailure(String prefix, String title, String message) + { + release(); + + if(isSelected()) + { + _coordinator.getSaveAction().setEnabled(isLive() && _coordinator.connectedToMaster() || hasFile()); + _coordinator.getSaveToRegistryAction().setEnabled(true); + _coordinator.getDiscardUpdatesAction().setEnabled(true); + } + + _coordinator.getStatusBar().setText(prefix + "failed!"); + + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + message, + title, + JOptionPane.ERROR_MESSAGE); + } + + + public void run() + { + _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + boolean asyncRelease = false; + + try + { + if(_live && _canUseUpdateDescriptor) + { + ApplicationUpdateDescriptor updateDescriptor = createUpdateDescriptor(); + if(updateDescriptor != null) + { + final String prefix = "Updating application '" + _id + "'..."; + _coordinator.getStatusBar().setText(prefix); + + AMI_Admin_updateApplication cb = new AMI_Admin_updateApplication() + { + public void ice_response() + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": success"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + commit(); + release(); + _coordinator.getStatusBar().setText(prefix + "done."); + } + }); + } + + public void ice_exception(final Ice.UserException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _skipUpdates--; + handleFailure(prefix, "Update failed", + "IceGrid exception: " + e.toString()); + } + + }); + } + + public void ice_exception(final Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("updateApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _skipUpdates--; + handleFailure(prefix, "Update failed", + "Communication exception: " + e.toString()); + } + }); + } + + }; + + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("sending updateApplication for application " + _id); + } + + _coordinator.getAdmin().updateApplication_async(cb, updateDescriptor); + asyncRelease = true; + + // + // If updateApplication fails, we know we can't get other updates + // since we have exclusive write access + // + _skipUpdates++; + } + else + { + final String prefix = "Application '" + _id + "' is already up-to-date"; + _coordinator.getStatusBar().setText(prefix); + commit(); + } + } + else + { + // + // Add or sync application + // + if(_coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id) == null) + { + assert _live == false; + + + final String prefix = "Adding application '" + _id + "'..."; + _coordinator.getStatusBar().setText(prefix); + + AMI_Admin_addApplication cb = new AMI_Admin_addApplication() + { + public void ice_response() + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": success"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + commit(); + liveReset(); + _coordinator.addLiveApplication(Root.this); + release(); + _coordinator.getStatusBar().setText(prefix + "done."); + } + }); + } + + public void ice_exception(final Ice.UserException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure(prefix, "Add failed", + "IceGrid exception: " + e.toString()); + } + + }); + } + + public void ice_exception(final Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("addApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure(prefix, "Add failed", + "Communication exception: " + e.toString()); + } + }); + } + + }; + + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("sending addApplication for application " + _id); + } + + _coordinator.getAdmin().addApplication_async(cb, _descriptor); + asyncRelease = true; + } + else + { + final String prefix = "Synchronizing application '" + _id + "'..."; + _coordinator.getStatusBar().setText(prefix); + + AMI_Admin_syncApplication cb = new AMI_Admin_syncApplication() + { + public void ice_response() + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + commit(); + if(!_live) + { + // + // 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); + } + } + } + + release(); + _coordinator.getStatusBar().setText(prefix + "done."); + } + }); + } + + public void ice_exception(final Ice.UserException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + if(_live) + { + _skipUpdates--; + } + + handleFailure(prefix, "Sync failed", + "IceGrid exception: " + e.toString()); + } + + }); + } + + public void ice_exception(final Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("syncApplication for application " + _id + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + if(_live) + { + _skipUpdates--; + } + + handleFailure(prefix, "Sync failed", + "Communication exception: " + e.toString()); + } + }); + } + + }; + + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("sending syncApplication for application " + _id); + } + + _coordinator.getAdmin().syncApplication_async(cb, _descriptor); + asyncRelease = true; + if(_live) + { + _skipUpdates++; + } + } + } + if(isSelected()) + { + _coordinator.getSaveAction().setEnabled(false); + _coordinator.getSaveToRegistryAction().setEnabled(false); + _coordinator.getDiscardUpdatesAction().setEnabled(false); + } + } + catch(Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + _coordinator.traceSaveToRegistry("Ice communications exception while saving application " + _id); + } + + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + e.toString(), + "Communication Exception", + JOptionPane.ERROR_MESSAGE); + } + finally + { + if(!asyncRelease) + { + _coordinator.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + _coordinator.releaseExclusiveWriteAccess(); + } + } + } + }; + + try + { + _coordinator.acquireExclusiveWriteAccess(runnable); + } + catch(AccessDeniedException e) + { + _coordinator.accessDenied(e); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + e.toString(), + "Communication Exception", + JOptionPane.ERROR_MESSAGE); + } } public void saveToFile() { - File file = _coordinator.saveToFile(true, this, _file); - if(file != null) - { - _file = file; - _live = false; + File file = _coordinator.saveToFile(true, this, _file); + if(file != null) + { + _file = file; + _live = false; - _coordinator.removeLiveApplication(_id); - _coordinator.getMainPane().resetIcon(this); + _coordinator.removeLiveApplication(_id); + _coordinator.getMainPane().resetIcon(this); - commit(); - _coordinator.getSaveAction().setEnabled(false); - _coordinator.getDiscardUpdatesAction().setEnabled(false); - _coordinator.getSaveToRegistryAction().setEnabled(_coordinator.connectedToMaster()); - } + commit(); + _coordinator.getSaveAction().setEnabled(false); + _coordinator.getDiscardUpdatesAction().setEnabled(false); + _coordinator.getSaveToRegistryAction().setEnabled(_coordinator.connectedToMaster()); + } } public void discardUpdates() { - ApplicationDescriptor desc = null; - - if(_live) - { - desc = _coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id); - assert desc != null; - desc = IceGridGUI.Application.Root.copyDescriptor(desc); - } - else if(_file != null) - { - desc = _coordinator.parseFile(_file); - if(desc == null) - { - return; - } - } - else - { - assert false; - } - - Root newRoot; - - try - { - newRoot = new Root(_coordinator, desc, _live, _file); - } - catch(UpdateFailedException e) - { - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - e.toString(), - "Bad Application Descriptor: Unable reload Application", - JOptionPane.ERROR_MESSAGE); - return; - } - - 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); - } - _coordinator.getCurrentTab().selected(); + ApplicationDescriptor desc = null; + + if(_live) + { + desc = _coordinator.getLiveDeploymentRoot().getApplicationDescriptor(_id); + assert desc != null; + desc = IceGridGUI.Application.Root.copyDescriptor(desc); + } + else if(_file != null) + { + desc = _coordinator.parseFile(_file); + if(desc == null) + { + return; + } + } + else + { + assert false; + } + + Root newRoot; + + try + { + newRoot = new Root(_coordinator, desc, _live, _file); + } + catch(UpdateFailedException e) + { + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + e.toString(), + "Bad Application Descriptor: Unable reload Application", + JOptionPane.ERROR_MESSAGE); + return; + } + + 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); + } + _coordinator.getCurrentTab().selected(); } private void liveReset() { - _live = true; - _skipUpdates = 0; - _file = null; - _coordinator.getMainPane().resetIcon(this); + _live = true; + _skipUpdates = 0; + _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 = new java.util.TreeMap(_descriptor.variables); - 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]; - } - - // - // Property sets - // - update.removePropertySets = _propertySets.getEditable(). - removedElements(PropertySet.class); - update.propertySets = _propertySets.getUpdates(); - - // - // Replica Groups - // - update.removeReplicaGroups = _replicaGroups.getEditable(). - removedElements(ReplicaGroup.class); - update.replicaGroups = _replicaGroups.getUpdates(); - - // - // Server Templates - // - update.removeServerTemplates = _serverTemplates.getEditable(). - removedElements(ServerTemplate.class); - update.serverTemplates = _serverTemplates.getUpdates(); - - // - // Service Templates - // - update.removeServiceTemplates = _serviceTemplates.getEditable(). - removedElements(ServiceTemplate.class); - update.serviceTemplates =_serviceTemplates.getUpdates(); - - // - // Nodes - // - update.removeNodes = _nodes.getEditable(). - removedElements(Node.class); - update.nodes = _nodes.getUpdates(); - - - // - // Return null if nothing changed - // - if(!_editable.isModified() && - update.removePropertySets.length == 0 && - update.propertySets.size() == 0 && - 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; - } + 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 = new java.util.TreeMap(_descriptor.variables); + 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]; + } + + // + // Property sets + // + update.removePropertySets = _propertySets.getEditable(). + removedElements(PropertySet.class); + update.propertySets = _propertySets.getUpdates(); + + // + // Replica Groups + // + update.removeReplicaGroups = _replicaGroups.getEditable(). + removedElements(ReplicaGroup.class); + update.replicaGroups = _replicaGroups.getUpdates(); + + // + // Server Templates + // + update.removeServerTemplates = _serverTemplates.getEditable(). + removedElements(ServerTemplate.class); + update.serverTemplates = _serverTemplates.getUpdates(); + + // + // Service Templates + // + update.removeServiceTemplates = _serviceTemplates.getEditable(). + removedElements(ServiceTemplate.class); + update.serviceTemplates =_serviceTemplates.getUpdates(); + + // + // Nodes + // + update.removeNodes = _nodes.getEditable(). + removedElements(Node.class); + update.nodes = _nodes.getUpdates(); + + + // + // Return null if nothing changed + // + if(!_editable.isModified() && + update.removePropertySets.length == 0 && + update.propertySets.size() == 0 && + 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; + _updated = false; + _registryUpdatesEnabled = true; + _canUseUpdateDescriptor = true; - assert _concurrentUpdates.size() == 0; + assert _concurrentUpdates.size() == 0; - _editable.commit(); - _origVariables = _descriptor.variables; - _origDescription = _descriptor.description; - _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone(); - - _nodes.commit(); - _propertySets.commit(); - _replicaGroups.commit(); - _serverTemplates.commit(); - _serviceTemplates.commit(); + _editable.commit(); + _origVariables = _descriptor.variables; + _origDescription = _descriptor.description; + _origDistrib = (DistributionDescriptor)_descriptor.distrib.clone(); + + _nodes.commit(); + _propertySets.commit(); + _replicaGroups.commit(); + _serverTemplates.commit(); + _serviceTemplates.commit(); } public boolean isEphemeral() { - return false; + return false; } public void destroy() { - if(!_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) - { - _coordinator.removeApplicationFromRegistry(_id); - _discardMe = true; - } - } - 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); - } - } - } + if(!_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) + { + _coordinator.removeApplicationFromRegistry(_id); + _discardMe = true; + } + } + 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(); - } - - // - // Property Sets - // - for(int i = 0; i < desc.removePropertySets.length; ++i) - { - _descriptor.propertySets.remove(desc.removePropertySets[i]); - } - _descriptor.propertySets.putAll(desc.propertySets); - _propertySets.update(desc.propertySets, - desc.removePropertySets); - - // - // 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; + 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(); + } + + // + // Property Sets + // + for(int i = 0; i < desc.removePropertySets.length; ++i) + { + _descriptor.propertySets.remove(desc.removePropertySets[i]); + } + _descriptor.propertySets.putAll(desc.propertySets); + _propertySets.update(desc.propertySets, + desc.removePropertySets); + + // + // 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; + return _tree; } public DefaultTreeModel getTreeModel() { - return _treeModel; + return _treeModel; } public Coordinator getCoordinator() { - return _coordinator; + return _coordinator; } public boolean isSelectionListenerEnabled() { - return _selectionListenerEnabled; + return _selectionListenerEnabled; } public void enableSelectionListener() { - _selectionListenerEnabled = true; + _selectionListenerEnabled = true; } public void disableSelectionListener() { - _selectionListenerEnabled = false; + _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(); - - _coordinator.getSaveAction().setEnabled(false); - _coordinator.getDiscardUpdatesAction().setEnabled(false); - _coordinator.getSaveToRegistryAction().setEnabled(hasFile() - && _coordinator.connectedToMaster()); - } + 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(); + + _coordinator.getSaveAction().setEnabled(false); + _coordinator.getDiscardUpdatesAction().setEnabled(false); + _coordinator.getSaveToRegistryAction().setEnabled(hasFile() + && _coordinator.connectedToMaster()); + } } public boolean kill() { - _live = false; + _live = false; - if(_registryUpdatesEnabled || _discardMe) - { - return true; - } - else - { - _coordinator.getMainPane().resetIcon(this); - _coordinator.getCurrentTab().selected(); // only needed when 'this' - // corresponds to the current tab - return false; - } + if(_registryUpdatesEnabled || _discardMe) + { + return true; + } + else + { + _coordinator.getMainPane().resetIcon(this); + _coordinator.getCurrentTab().selected(); // only needed when 'this' + // corresponds to the current tab + return false; + } } public boolean isLive() { - return _live; + return _live; } public boolean hasFile() { - return _file != null; + return _file != null; } public boolean needsSaving() { - return _updated || !_registryUpdatesEnabled; + return _updated || !_registryUpdatesEnabled; } public void setPane(ApplicationPane app) { - _applicationPane = app; + _applicationPane = app; } public ApplicationPane getPane() { - return _applicationPane; + return _applicationPane; } Editor getEditor(Class c, TreeNode node) { - Editor result = (Editor)_editorMap.get(c); - if(result == null) - { - result = node.createEditor(); - _editorMap.put(c, result); - } - return result; + Editor result = (Editor)_editorMap.get(c); + if(result == null) + { + result = node.createEditor(); + _editorMap.put(c, result); + } + return result; } Object getDescriptor() { - return _descriptor; + return _descriptor; } ApplicationDescriptor saveDescriptor() { - ApplicationDescriptor clone = (ApplicationDescriptor)_descriptor.clone(); - clone.distrib = (IceGrid.DistributionDescriptor)clone.distrib.clone(); - return clone; + 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; + _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"); + writer.writeStartTag("icegrid"); - java.util.List attributes = new java.util.LinkedList(); - attributes.add(createAttribute("name", _id)); + java.util.List attributes = new java.util.LinkedList(); + attributes.add(createAttribute("name", _id)); - writer.writeStartTag("application", attributes); + writer.writeStartTag("application", attributes); - if(_descriptor.description.length() > 0) - { - writer.writeElement("description", _descriptor.description); - } - writeVariables(writer, _descriptor.variables); - writeDistribution(writer, _descriptor.distrib); + if(_descriptor.description.length() > 0) + { + writer.writeElement("description", _descriptor.description); + } + writeVariables(writer, _descriptor.variables); + writeDistribution(writer, _descriptor.distrib); - _serviceTemplates.write(writer); - _serverTemplates.write(writer); - _replicaGroups.write(writer); - _propertySets.write(writer); - _nodes.write(writer); - - writer.writeEndTag("application"); - writer.writeEndTag("icegrid"); + _serviceTemplates.write(writer); + _serverTemplates.write(writer); + _replicaGroups.write(writer); + _propertySets.write(writer); + _nodes.write(writer); + + writer.writeEndTag("application"); + writer.writeEndTag("icegrid"); } // @@ -1289,41 +1289,41 @@ public class Root extends ListTreeNode // void disableRegistryUpdates() { - if(_registryUpdatesEnabled) - { - _registryUpdatesEnabled = false; - _coordinator.getSaveAction().setEnabled(_live && _coordinator.connectedToMaster() || _file != null); - _coordinator.getDiscardUpdatesAction().setEnabled(_live || _file != null); - _coordinator.getSaveToRegistryAction().setEnabled(_coordinator.connectedToMaster()); - } + if(_registryUpdatesEnabled) + { + _registryUpdatesEnabled = false; + _coordinator.getSaveAction().setEnabled(_live && _coordinator.connectedToMaster() || _file != null); + _coordinator.getDiscardUpdatesAction().setEnabled(_live || _file != null); + _coordinator.getSaveToRegistryAction().setEnabled(_coordinator.connectedToMaster()); + } } void updated() { - _updated = true; - disableRegistryUpdates(); // can be still enabled when updated() is called by destroy() + _updated = true; + disableRegistryUpdates(); // can be still enabled when updated() is called by destroy() - _concurrentUpdates.clear(); + _concurrentUpdates.clear(); } 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; - } + 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; + } } // @@ -1332,7 +1332,7 @@ public class Root extends ListTreeNode // void removeServerInstances(String templateId) { - _nodes.removeServerInstances(templateId); + _nodes.removeServerInstances(templateId); } // @@ -1341,78 +1341,78 @@ public class Root extends ListTreeNode // void removeServiceInstances(String templateId) { - _nodes.removeServiceInstances(templateId); - _serverTemplates.removeServiceInstances(templateId); + _nodes.removeServiceInstances(templateId); + _serverTemplates.removeServiceInstances(templateId); } ServerTemplate findServerTemplate(String id) { - return (ServerTemplate)_serverTemplates.findChild(id); + return (ServerTemplate)_serverTemplates.findChild(id); } ServiceTemplate findServiceTemplate(String id) { - return (ServiceTemplate)_serviceTemplates.findChild(id); + return (ServiceTemplate)_serviceTemplates.findChild(id); } ReplicaGroup findReplicaGroup(String id) { - return (ReplicaGroup)_replicaGroups.findChild(id); + return (ReplicaGroup)_replicaGroups.findChild(id); } Node findNode(String id) { - return (Node)_nodes.findChild(id); + return (Node)_nodes.findChild(id); } java.util.List findServerInstances(String template) { - return _nodes.findServerInstances(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; + java.util.List result = _serverTemplates.findServiceInstances(template); + result.addAll(_nodes.findServiceInstances(template)); + return result; } TemplateDescriptor findServerTemplateDescriptor(String templateName) { - return (TemplateDescriptor) - _descriptor.serverTemplates.get(templateName); + return (TemplateDescriptor) + _descriptor.serverTemplates.get(templateName); } TemplateDescriptor findServiceTemplateDescriptor(String templateName) { - return (TemplateDescriptor) - _descriptor.serviceTemplates.get(templateName); + return (TemplateDescriptor) + _descriptor.serviceTemplates.get(templateName); } ServerTemplates getServerTemplates() { - return _serverTemplates; + return _serverTemplates; } ServiceTemplates getServiceTemplates() { - return _serviceTemplates; + return _serviceTemplates; } ReplicaGroups getReplicaGroups() { - return _replicaGroups; + return _replicaGroups; } public Root getRoot() { - return this; + return this; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } // @@ -1420,19 +1420,19 @@ public class Root extends ListTreeNode // java.util.Map getVariables() { - return _descriptor.variables; + return _descriptor.variables; } private boolean isSelected() { - if(_coordinator.getCurrentTab() instanceof ApplicationPane) - { - return ((ApplicationPane)_coordinator.getCurrentTab()).getRoot() == Root.this; - } - else - { - return false; - } + if(_coordinator.getCurrentTab() instanceof ApplicationPane) + { + return ((ApplicationPane)_coordinator.getCurrentTab()).getRoot() == Root.this; + } + else + { + return false; + } } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/Application/ServerInstance.java b/java/src/IceGridGUI/Application/ServerInstance.java index 8e2d7388fc3..5d8fd9a23d9 100755 --- a/java/src/IceGridGUI/Application/ServerInstance.java +++ b/java/src/IceGridGUI/Application/ServerInstance.java @@ -26,8 +26,8 @@ class ServerInstance extends ListTreeNode implements Server, PropertySetParent copyDescriptor(ServerInstanceDescriptor sid) { ServerInstanceDescriptor copy = (ServerInstanceDescriptor)sid.clone(); - copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); - return copy; + copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); + return copy; } // @@ -35,7 +35,7 @@ class ServerInstance extends ListTreeNode implements Server, PropertySetParent // public boolean getAllowsChildren() { - return _isIceBox; + return _isIceBox; } // @@ -43,519 +43,519 @@ class ServerInstance extends ListTreeNode implements Server, PropertySetParent // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - Object clipboard = getCoordinator().getClipboard(); - if(clipboard != null && - (clipboard instanceof ServerDescriptor - || clipboard instanceof ServerInstanceDescriptor - || (_isIceBox && clipboard instanceof PropertySetDescriptor))) - { - actions[PASTE] = true; - } - - actions[DELETE] = true; - if(!_ephemeral) - { - actions[SHOW_VARS] = true; - actions[SUBSTITUTE_VARS] = true; - - if(_isIceBox) - { - actions[NEW_PROPERTY_SET] = true; - } - } - - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + Object clipboard = getCoordinator().getClipboard(); + if(clipboard != null && + (clipboard instanceof ServerDescriptor + || clipboard instanceof ServerInstanceDescriptor + || (_isIceBox && clipboard instanceof PropertySetDescriptor))) + { + actions[PASTE] = true; + } + + actions[DELETE] = true; + if(!_ephemeral) + { + actions[SHOW_VARS] = true; + actions[SUBSTITUTE_VARS] = true; + + if(_isIceBox) + { + actions[NEW_PROPERTY_SET] = true; + } + } + + return actions; } public void copy() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - if(_isIceBox) - { - Object descriptor = getCoordinator().getClipboard(); - if(descriptor instanceof PropertySetDescriptor) - { - newPropertySet(PropertySet.copyDescriptor((PropertySetDescriptor)descriptor)); - return; - } - } + if(_isIceBox) + { + Object descriptor = getCoordinator().getClipboard(); + if(descriptor instanceof PropertySetDescriptor) + { + newPropertySet(PropertySet.copyDescriptor((PropertySetDescriptor)descriptor)); + return; + } + } - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public void newPropertySet() { - newPropertySet(new PropertySetDescriptor( - new String[0], new java.util.LinkedList())); + newPropertySet(new PropertySetDescriptor( + new String[0], new java.util.LinkedList())); } public JPopupMenu getPopupMenu() { - if(_isIceBox) - { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_PROPERTY_SET)); - } - actions.setTarget(this); - return _popup; - } - else - { - return null; - } + if(_isIceBox) + { + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_PROPERTY_SET)); + } + actions.setTarget(this); + return _popup; + } + else + { + return null; + } } public Editor getEditor() { - if(_editor == null) - { - _editor = (ServerInstanceEditor) - getRoot().getEditor(ServerInstanceEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (ServerInstanceEditor) + getRoot().getEditor(ServerInstanceEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ServerInstanceEditor(); + return new 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(); - - _serverIcon = Utils.getIcon("/icons/16x16/server_inactive.png"); - _iceboxServerIcon = Utils.getIcon("/icons/16x16/icebox_server_inactive.png"); - - _cellRenderer.setLeafIcon(_serverIcon); - _cellRenderer.setOpenIcon(_iceboxServerIcon); - _cellRenderer.setClosedIcon(_iceboxServerIcon); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + 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"); + + _cellRenderer.setLeafIcon(_serverIcon); + _cellRenderer.setOpenIcon(_iceboxServerIcon); + _cellRenderer.setClosedIcon(_iceboxServerIcon); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } public void destroy() { - Node node = (Node)_parent; - - if(_ephemeral) - { - node.removeServer(this); - } - else - { - node.removeDescriptor(_descriptor); - node.removeServer(this); - node.getEditable().removeElement(_id, _editable, Server.class); - getRoot().updated(); - } + Node node = (Node)_parent; + + if(_ephemeral) + { + node.removeServer(this); + } + else + { + node.removeDescriptor(_descriptor); + node.removeServer(this); + node.getEditable().removeElement(_id, _editable, Server.class); + getRoot().updated(); + } } public Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object saveDescriptor() { - return _descriptor.clone(); + return _descriptor.clone(); } public void restoreDescriptor(Object savedDescriptor) { - ServerInstanceDescriptor copy = (ServerInstanceDescriptor)savedDescriptor; + ServerInstanceDescriptor copy = (ServerInstanceDescriptor)savedDescriptor; - _descriptor.template = copy.template; - _descriptor.parameterValues = copy.parameterValues; - _descriptor.propertySet = copy.propertySet; + _descriptor.template = copy.template; + _descriptor.parameterValues = copy.parameterValues; + _descriptor.propertySet = copy.propertySet; } // // Builds the server and all its sub-tree // ServerInstance(boolean brandNew, TreeNode parent, String serverId, - Utils.Resolver resolver, - ServerInstanceDescriptor instanceDescriptor, - boolean isIceBox) - throws UpdateFailedException + Utils.Resolver resolver, + ServerInstanceDescriptor instanceDescriptor, + boolean isIceBox) + throws UpdateFailedException { - super(brandNew, parent, serverId); - _ephemeral = false; - rebuild(resolver, instanceDescriptor, isIceBox); + super(brandNew, parent, serverId); + _ephemeral = false; + rebuild(resolver, instanceDescriptor, isIceBox); } ServerInstance(TreeNode parent, String serverId, - ServerInstanceDescriptor instanceDescriptor) + ServerInstanceDescriptor instanceDescriptor) { - super(false, parent, serverId); - _ephemeral = true; - try - { - rebuild(null, instanceDescriptor, false); - } - catch(UpdateFailedException e) - { - assert false; - } + super(false, parent, serverId); + _ephemeral = true; + try + { + rebuild(null, instanceDescriptor, false); + } + catch(UpdateFailedException e) + { + assert false; + } } void write(XMLWriter writer) throws java.io.IOException { - if(!_ephemeral) - { - TemplateDescriptor templateDescriptor - = getRoot().findServerTemplateDescriptor(_descriptor.template); - - java.util.LinkedList attributes = parameterValuesToAttributes( - _descriptor.parameterValues, templateDescriptor.parameters); - attributes.addFirst(createAttribute("template", _descriptor.template)); - - if(_descriptor.propertySet.references.length == 0 && - _descriptor.propertySet.properties.size() == 0 && - _children.size() == 0) - { - writer.writeElement("server-instance", attributes); - } - else - { - writer.writeStartTag("server-instance", attributes); - writePropertySet(writer, _descriptor.propertySet, null, null); - - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - PropertySet ps = (PropertySet)p.next(); - ps.write(writer); - } - - writer.writeEndTag("server-instance"); - } - } + if(!_ephemeral) + { + TemplateDescriptor templateDescriptor + = getRoot().findServerTemplateDescriptor(_descriptor.template); + + java.util.LinkedList attributes = parameterValuesToAttributes( + _descriptor.parameterValues, templateDescriptor.parameters); + attributes.addFirst(createAttribute("template", _descriptor.template)); + + if(_descriptor.propertySet.references.length == 0 && + _descriptor.propertySet.properties.size() == 0 && + _children.size() == 0) + { + writer.writeElement("server-instance", attributes); + } + else + { + writer.writeStartTag("server-instance", attributes); + writePropertySet(writer, _descriptor.propertySet, null, null); + + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + PropertySet ps = (PropertySet)p.next(); + ps.write(writer); + } + + writer.writeEndTag("server-instance"); + } + } } boolean isIceBox() { - return _isIceBox; + return _isIceBox; } void isIceBox(boolean newValue) { - if(newValue != _isIceBox) - { - _isIceBox = newValue; - _children.clear(); - getRoot().getTreeModel().nodeStructureChanged(this); - } + if(newValue != _isIceBox) + { + _isIceBox = newValue; + _children.clear(); + getRoot().getTreeModel().nodeStructureChanged(this); + } } static private class Backup { - Backup(Editable ne) - { - nodeEditable = ne; - } + Backup(Editable ne) + { + nodeEditable = ne; + } - Editable nodeEditable; - java.util.Map parameterValues; + Editable nodeEditable; + java.util.Map parameterValues; } public Object rebuild(java.util.List editables) throws UpdateFailedException { - Node node = (Node)_parent; - Backup backup = new Backup(node.getEditable().save()); - - TemplateDescriptor templateDescriptor - = getRoot().findServerTemplateDescriptor(_descriptor.template); - - java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters); - if(!parameters.equals(_descriptor.parameterValues.keySet())) - { - backup.parameterValues = _descriptor.parameterValues; - _descriptor.parameterValues = Editor.makeParameterValues( - _descriptor.parameterValues, templateDescriptor.parameters); - } - ServerInstance newServer = node.createServer(false, _descriptor); - - - 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.removeServer(this); - try - { - node.insertServer(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.removeServer(this); - node.getEditable().removeElement(_id, _editable, Server.class); - try - { - node.insertServer(newServer, true); - } - catch(UpdateFailedException e) - { - restore(backup); - throw e; - } - } - - return backup; + Node node = (Node)_parent; + Backup backup = new Backup(node.getEditable().save()); + + TemplateDescriptor templateDescriptor + = getRoot().findServerTemplateDescriptor(_descriptor.template); + + java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters); + if(!parameters.equals(_descriptor.parameterValues.keySet())) + { + backup.parameterValues = _descriptor.parameterValues; + _descriptor.parameterValues = Editor.makeParameterValues( + _descriptor.parameterValues, templateDescriptor.parameters); + } + ServerInstance newServer = node.createServer(false, _descriptor); + + + 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.removeServer(this); + try + { + node.insertServer(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.removeServer(this); + node.getEditable().removeElement(_id, _editable, Server.class); + try + { + node.insertServer(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); + Backup backup = (Backup)backupObj; + Node node = (Node)_parent; + + node.getEditable().restore(backup.nodeEditable); - if(backup.parameterValues != null) - { - _descriptor.parameterValues = backup.parameterValues; - } + if(backup.parameterValues != null) + { + _descriptor.parameterValues = backup.parameterValues; + } - TreeNode badServer = node.findChildWithDescriptor(_descriptor); + TreeNode badServer = node.findChildWithDescriptor(_descriptor); - if(badServer != null) - { - node.removeServer(badServer); - } + if(badServer != null) + { + node.removeServer(badServer); + } - try - { - node.insertServer(this, true); - } - catch(UpdateFailedException e) - { - assert false; // impossible - } + try + { + node.insertServer(this, true); + } + catch(UpdateFailedException e) + { + assert false; // impossible + } } public void tryAdd(String unsubstitutedId, PropertySetDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertPropertySet(new PropertySet(this, - Utils.substitute(unsubstitutedId, _resolver), - unsubstitutedId, - descriptor), - true); - _descriptor.servicePropertySets.put(unsubstitutedId, descriptor); - _editable.markModified(); + insertPropertySet(new PropertySet(this, + Utils.substitute(unsubstitutedId, _resolver), + unsubstitutedId, + descriptor), + true); + _descriptor.servicePropertySets.put(unsubstitutedId, descriptor); + _editable.markModified(); } public void tryRename(String oldId, String oldUnresolvedId, - String newUnsubstitutedId) - throws UpdateFailedException - { - PropertySet oldChild = (PropertySet)findChild(oldId); - assert oldChild != null; - removePropertySet(oldChild); - PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); - - try - { - insertPropertySet( - new PropertySet(this, - Utils.substitute(newUnsubstitutedId, _resolver), - newUnsubstitutedId, descriptor), - true); - } - catch(UpdateFailedException ex) - { - try - { - insertPropertySet(oldChild, true); - } - catch(UpdateFailedException ufe) - { - assert false; - } - throw ex; - } - - _editable.markModified(); - _descriptor.servicePropertySets.remove(oldUnresolvedId); - _descriptor.servicePropertySets.put(newUnsubstitutedId, descriptor); + String newUnsubstitutedId) + throws UpdateFailedException + { + PropertySet oldChild = (PropertySet)findChild(oldId); + assert oldChild != null; + removePropertySet(oldChild); + PropertySetDescriptor descriptor = (PropertySetDescriptor)oldChild.getDescriptor(); + + try + { + insertPropertySet( + new PropertySet(this, + Utils.substitute(newUnsubstitutedId, _resolver), + newUnsubstitutedId, descriptor), + true); + } + catch(UpdateFailedException ex) + { + try + { + insertPropertySet(oldChild, true); + } + catch(UpdateFailedException ufe) + { + assert false; + } + throw ex; + } + + _editable.markModified(); + _descriptor.servicePropertySets.remove(oldUnresolvedId); + _descriptor.servicePropertySets.put(newUnsubstitutedId, descriptor); } public void insertPropertySet(PropertySet nps, boolean fireEvent) - throws UpdateFailedException + throws UpdateFailedException { - insertChild(nps, fireEvent); + insertChild(nps, fireEvent); } public void removePropertySet(PropertySet nps) { - removeChild(nps); + removeChild(nps); } public void removeDescriptor(String unsubstitutedId) { - _descriptor.servicePropertySets.remove(unsubstitutedId); + _descriptor.servicePropertySets.remove(unsubstitutedId); } public Editable getEditable() { - return _editable; + return _editable; } Object[] getServiceNames() { - assert _isIceBox; - - // - // Retrieve the list of service instances - // - - Communicator.ChildList services = getRoot(). - findServerTemplate(_descriptor.template).getServices(); - - Object[] result = new Object[services.size()]; - int i = 0; - - java.util.Iterator p = services.iterator(); - while(p.hasNext()) - { - TreeNode n = (TreeNode)p.next(); - ServiceInstanceDescriptor d = (ServiceInstanceDescriptor)n.getDescriptor(); - - if(d.template.length() > 0) - { - TemplateDescriptor templateDescriptor - = (TemplateDescriptor)getRoot().findServiceTemplateDescriptor(d.template); - assert templateDescriptor != null; - Utils.Resolver serviceResolver = new Utils.Resolver(_resolver, - d.parameterValues, - templateDescriptor.parameterDefaults); - - ServiceDescriptor serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor; - - result[i++] = serviceResolver.substitute(serviceDescriptor.name); - } - else - { - result[i++] = _resolver.substitute(d.descriptor.name); - } - } - return result; + assert _isIceBox; + + // + // Retrieve the list of service instances + // + + Communicator.ChildList services = getRoot(). + findServerTemplate(_descriptor.template).getServices(); + + Object[] result = new Object[services.size()]; + int i = 0; + + java.util.Iterator p = services.iterator(); + while(p.hasNext()) + { + TreeNode n = (TreeNode)p.next(); + ServiceInstanceDescriptor d = (ServiceInstanceDescriptor)n.getDescriptor(); + + if(d.template.length() > 0) + { + TemplateDescriptor templateDescriptor + = (TemplateDescriptor)getRoot().findServiceTemplateDescriptor(d.template); + assert templateDescriptor != null; + Utils.Resolver serviceResolver = new Utils.Resolver(_resolver, + d.parameterValues, + templateDescriptor.parameterDefaults); + + ServiceDescriptor serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor; + + result[i++] = serviceResolver.substitute(serviceDescriptor.name); + } + else + { + result[i++] = _resolver.substitute(d.descriptor.name); + } + } + return result; } // // Update the server and its children // void rebuild(Utils.Resolver resolver, - ServerInstanceDescriptor instanceDescriptor, - boolean isIceBox) throws UpdateFailedException + ServerInstanceDescriptor instanceDescriptor, + boolean isIceBox) throws UpdateFailedException { - _resolver = resolver; - _isIceBox = isIceBox; - _descriptor = instanceDescriptor; - - _children.clear(); + _resolver = resolver; + _isIceBox = isIceBox; + _descriptor = instanceDescriptor; + + _children.clear(); - java.util.Iterator p = _descriptor.servicePropertySets.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String unsubstitutedId = (String)entry.getKey(); + java.util.Iterator p = _descriptor.servicePropertySets.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String unsubstitutedId = (String)entry.getKey(); - insertPropertySet(new PropertySet(this, - Utils.substitute(unsubstitutedId, _resolver), - unsubstitutedId, - (PropertySetDescriptor)entry.getValue()), - false); - } + insertPropertySet(new PropertySet(this, + Utils.substitute(unsubstitutedId, _resolver), + unsubstitutedId, + (PropertySetDescriptor)entry.getValue()), + false); + } } private void newPropertySet(PropertySetDescriptor descriptor) { - String id = makeNewChildId("Service"); - - PropertySet ps = new PropertySet(this, id, descriptor); - try - { - insertChild(ps, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(ps); + String id = makeNewChildId("Service"); + + PropertySet ps = new PropertySet(this, id, descriptor); + try + { + insertChild(ps, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(ps); } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } public String toString() { - if(_ephemeral) - { - return super.toString(); - } - else - { - return _id + ": " + _descriptor.template + "<>"; - } + if(_ephemeral) + { + return super.toString(); + } + else + { + return _id + ": " + _descriptor.template + "<>"; + } } private ServerInstanceDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/ServerInstanceEditor.java b/java/src/IceGridGUI/Application/ServerInstanceEditor.java index 6f2497bb56f..44affdcbaed 100755 --- a/java/src/IceGridGUI/Application/ServerInstanceEditor.java +++ b/java/src/IceGridGUI/Application/ServerInstanceEditor.java @@ -30,63 +30,63 @@ class ServerInstanceEditor extends AbstractServerEditor { protected void writeDescriptor() { - ServerInstanceDescriptor descriptor = getDescriptor(); - ServerTemplate t = (ServerTemplate)_template.getSelectedItem(); - - descriptor.template = t.getId(); - descriptor.parameterValues = _parameters.getValues(); - - descriptor.propertySet.references = - (String[])_propertySets.getList().toArray(new String[0]); - descriptor.propertySet.properties = _properties.getProperties(); - - ((ServerInstance)_target).isIceBox( - ((TemplateDescriptor)t.getDescriptor()).descriptor instanceof IceBoxDescriptor); + ServerInstanceDescriptor descriptor = getDescriptor(); + ServerTemplate t = (ServerTemplate)_template.getSelectedItem(); + + descriptor.template = t.getId(); + descriptor.parameterValues = _parameters.getValues(); + + descriptor.propertySet.references = + (String[])_propertySets.getList().toArray(new String[0]); + descriptor.propertySet.properties = _properties.getProperties(); + + ((ServerInstance)_target).isIceBox( + ((TemplateDescriptor)t.getDescriptor()).descriptor instanceof IceBoxDescriptor); } protected boolean isSimpleUpdate() { - ServerInstanceDescriptor descriptor = getDescriptor(); - ServerTemplate t = (ServerTemplate)_template.getSelectedItem(); + ServerInstanceDescriptor descriptor = getDescriptor(); + ServerTemplate t = (ServerTemplate)_template.getSelectedItem(); - return descriptor.template.equals(t.getId()) - && descriptor.parameterValues.equals(_parameters.getValues()); + return descriptor.template.equals(t.getId()) + && descriptor.parameterValues.equals(_parameters.getValues()); } ServerInstanceEditor() - { - _template.setToolTipText("Server template"); - - // - // Template - // - Action gotoTemplate = new AbstractAction( - "", Utils.getIcon("/icons/16x16/goto.png")) - { - public void actionPerformed(ActionEvent e) - { - TreeNode t = (TreeNode)_template.getSelectedItem(); - if(t != null) - { - t.getRoot().setSelectedNode(t); - } - } - }; - gotoTemplate.putValue(Action.SHORT_DESCRIPTION, - "Goto this server template"); - _templateButton = new JButton(gotoTemplate); - - _parameters = new ParameterValuesField(this); - - _propertySets.getDocument().addDocumentListener(_updateListener); - _propertySets.setToolTipText("Property Set References"); - - _properties = new PropertiesField(this); + { + _template.setToolTipText("Server template"); + + // + // Template + // + Action gotoTemplate = new AbstractAction( + "", Utils.getIcon("/icons/16x16/goto.png")) + { + public void actionPerformed(ActionEvent e) + { + TreeNode t = (TreeNode)_template.getSelectedItem(); + if(t != null) + { + t.getRoot().setSelectedNode(t); + } + } + }; + gotoTemplate.putValue(Action.SHORT_DESCRIPTION, + "Goto this server template"); + _templateButton = new JButton(gotoTemplate); + + _parameters = new ParameterValuesField(this); + + _propertySets.getDocument().addDocumentListener(_updateListener); + _propertySets.setToolTipText("Property Set References"); + + _properties = new PropertiesField(this); } ServerInstanceDescriptor getDescriptor() { - return (ServerInstanceDescriptor)_target.getDescriptor(); + return (ServerInstanceDescriptor)_target.getDescriptor(); } // @@ -95,128 +95,128 @@ class ServerInstanceEditor extends AbstractServerEditor Utils.Resolver getDetailResolver() { - if(_target.getCoordinator().substitute()) - { - return _target.getResolver(); - } - else - { - return null; - } + if(_target.getCoordinator().substitute()) + { + return _target.getResolver(); + } + else + { + return null; + } } protected void appendProperties(DefaultFormBuilder builder) { - builder.append("Template", _template); - builder.append(_templateButton); - builder.nextLine(); - - builder.append("Parameters"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - - builder.nextLine(); - builder.append(""); - - builder.nextRow(-6); - JScrollPane scrollPane = new JScrollPane(_parameters); - CellConstraints cc = new CellConstraints(); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); - - builder.append("Property Sets"); - builder.append(_propertySets, 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(); + builder.append("Template", _template); + builder.append(_templateButton); + builder.nextLine(); + + builder.append("Parameters"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + + builder.nextLine(); + builder.append(""); + + builder.nextRow(-6); + JScrollPane scrollPane = new JScrollPane(_parameters); + CellConstraints cc = new CellConstraints(); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); + + builder.append("Property Sets"); + builder.append(_propertySets, 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(); } void show(ServerInstance server) { - detectUpdates(false); - _target = server; - - ServerInstanceDescriptor descriptor = getDescriptor(); - Root root = server.getRoot(); - boolean isEditable = server.isEphemeral() || !root.getCoordinator().substitute(); - - Utils.Resolver resolver = isEditable ? null : - ((Node)_target.getParent()).getResolver(); - - // - // Need to make control enabled before changing it - // - _template.setEnabled(true); - - ServerTemplates serverTemplates = root.getServerTemplates(); - _template.setModel(serverTemplates.createComboBoxModel()); - - ServerTemplate t = (ServerTemplate) - serverTemplates.findChild(descriptor.template); - assert t != null; - _template.setSelectedItem(t); - - ListDataListener templateListener = new ListDataListener() - { - public void contentsChanged(ListDataEvent e) - { - updated(); - - ServerTemplate t = - (ServerTemplate)_template.getModel().getSelectedItem(); - - TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); - - // - // Replace parameters but keep existing values - // - _parameters.set(td.parameters, - makeParameterValues(_parameters.getValues(), td.parameters), - td.parameterDefaults, null); - } - - public void intervalAdded(ListDataEvent e) - {} + detectUpdates(false); + _target = server; + + ServerInstanceDescriptor descriptor = getDescriptor(); + Root root = server.getRoot(); + boolean isEditable = server.isEphemeral() || !root.getCoordinator().substitute(); + + Utils.Resolver resolver = isEditable ? null : + ((Node)_target.getParent()).getResolver(); + + // + // Need to make control enabled before changing it + // + _template.setEnabled(true); + + ServerTemplates serverTemplates = root.getServerTemplates(); + _template.setModel(serverTemplates.createComboBoxModel()); + + ServerTemplate t = (ServerTemplate) + serverTemplates.findChild(descriptor.template); + assert t != null; + _template.setSelectedItem(t); + + ListDataListener templateListener = new ListDataListener() + { + public void contentsChanged(ListDataEvent e) + { + updated(); + + ServerTemplate t = + (ServerTemplate)_template.getModel().getSelectedItem(); + + TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); + + // + // Replace parameters but keep existing values + // + _parameters.set(td.parameters, + makeParameterValues(_parameters.getValues(), td.parameters), + td.parameterDefaults, null); + } + + public void intervalAdded(ListDataEvent e) + {} - public void intervalRemoved(ListDataEvent e) - {} - }; - - _template.getModel().addListDataListener(templateListener); - _template.setEnabled(isEditable); - - TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); - _parameters.set(td.parameters, descriptor.parameterValues, - td.parameterDefaults, resolver); - - _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), - getDetailResolver()); - _propertySets.setEditable(isEditable); - - _properties.setProperties(descriptor.propertySet.properties, null, null, - getDetailResolver(), isEditable); - - _applyButton.setEnabled(server.isEphemeral()); - _discardButton.setEnabled(server.isEphemeral()); - detectUpdates(true); + public void intervalRemoved(ListDataEvent e) + {} + }; + + _template.getModel().addListDataListener(templateListener); + _template.setEnabled(isEditable); + + TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); + _parameters.set(td.parameters, descriptor.parameterValues, + td.parameterDefaults, resolver); + + _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), + getDetailResolver()); + _propertySets.setEditable(isEditable); + + _properties.setProperties(descriptor.propertySet.properties, null, null, + getDetailResolver(), isEditable); + + _applyButton.setEnabled(server.isEphemeral()); + _discardButton.setEnabled(server.isEphemeral()); + detectUpdates(true); } private JComboBox _template = new JComboBox(); diff --git a/java/src/IceGridGUI/Application/ServerInstancePropertySetEditor.java b/java/src/IceGridGUI/Application/ServerInstancePropertySetEditor.java index 76fac6c588a..ecf97467164 100644 --- a/java/src/IceGridGUI/Application/ServerInstancePropertySetEditor.java +++ b/java/src/IceGridGUI/Application/ServerInstancePropertySetEditor.java @@ -20,47 +20,47 @@ class ServerInstancePropertySetEditor extends PropertySetEditor { ServerInstancePropertySetEditor() { - super("Service Name"); - _id.setToolTipText("The name of the service"); + super("Service Name"); + _id.setToolTipText("The name of the service"); - JTextField idTextField = (JTextField) - _id.getEditor().getEditorComponent(); - idTextField.getDocument().addDocumentListener(_updateListener); + JTextField idTextField = (JTextField) + _id.getEditor().getEditorComponent(); + idTextField.getDocument().addDocumentListener(_updateListener); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Service Instance Property Set"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Service Instance Property Set"); } protected JComponent getIdComponent() { - return _id; + return _id; } protected String getIdText() { - if(_id.getSelectedItem() == null) - { - return ""; - } - else - { - return _id.getSelectedItem().toString().trim(); - } + if(_id.getSelectedItem() == null) + { + return ""; + } + else + { + return _id.getSelectedItem().toString().trim(); + } } protected void showId(String unsubstitutedId, Utils.Resolver resolver) { - ServerInstance s = (ServerInstance)_target.getParent(); - - _id.setEnabled(true); - _id.setEditable(true); - _id.setModel(new DefaultComboBoxModel(s.getServiceNames())); - _id.setSelectedItem(Utils.substitute(unsubstitutedId, resolver)); - _id.setEditable(resolver == null); - _id.setEnabled(resolver == null); + ServerInstance s = (ServerInstance)_target.getParent(); + + _id.setEnabled(true); + _id.setEditable(true); + _id.setModel(new DefaultComboBoxModel(s.getServiceNames())); + _id.setSelectedItem(Utils.substitute(unsubstitutedId, resolver)); + _id.setEditable(resolver == null); + _id.setEnabled(resolver == null); } private JComboBox _id = new JComboBox(); diff --git a/java/src/IceGridGUI/Application/ServerSubEditor.java b/java/src/IceGridGUI/Application/ServerSubEditor.java index aee4c65a92f..3acedfe0a7f 100755 --- a/java/src/IceGridGUI/Application/ServerSubEditor.java +++ b/java/src/IceGridGUI/Application/ServerSubEditor.java @@ -29,352 +29,352 @@ class ServerSubEditor extends CommunicatorSubEditor { ServerSubEditor(Editor mainEditor) { - super(mainEditor); - - _id.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _id.setToolTipText("Must be unique within this IceGrid deployment"); - - _iceVersion.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _iceVersion.setToolTipText("<html>This server's Ice version, such as 3.0 or 3.1.1;<br>" - + "leave blank to use the version of the IceGrid registry.</html>"); - - _exe.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _exe.setToolTipText("<html>Path to this server's executable, e.g.:<br>" - + "icebox<br>" - + "java<br>" - + "myHelloServer<br>" - + "C:\\testbed\\hello\\server</html>"); - - _pwd.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _pwd.setToolTipText( - "<html>If not set, the server will start in " - + "<i>node data dir</i>/servers/<i>server-id</i>;<br>" - + "relative directories are relative to the current directory" - + " of the icegridnode process.</html>"); - - _options.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _options.setToolTipText( - "<html>Command-line arguments for this server.<br>" - + "Use whitespace as separator; use double-quotes around arguments containing whitespaces</html>"); - - _user.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _user.setToolTipText( - "<html>Run the server using this user account.<br>" - + "This feature is only available on Unix/Linux, when the IceGrid node runs as root.</html>"); - - _envs = new MapField(mainEditor, "Name", "Value", true); - - _activation = new JComboBox(new Object[]{ALWAYS, MANUAL, ON_DEMAND, SESSION}); - _activation.setToolTipText("<html>always: IceGrid starts and keeps the server up all the time<br>" - + "manual: you start the server yourself<br>" - + "on-demand: IceGrid starts the server when a client needs it<br>" - + "session: IceGrid starts and shuts down the server for each session</html>"); - - JTextField activationTextField = (JTextField) - _activation.getEditor().getEditorComponent(); - activationTextField.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - - _activationTimeout.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _activationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, " - + "the IceGrid Node<br> uses the value of its " - + "IceGrid.Node.WaitTime property</html>"); - _deactivationTimeout.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _deactivationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, " - + "the IceGrid Node<br> uses the value of its " - + "IceGrid.Node.WaitTime property</html>"); - - Action allocatable = new AbstractAction("Allocatable") - { - public void actionPerformed(ActionEvent e) - { - _mainEditor.updated(); - } - }; - allocatable.putValue(Action.SHORT_DESCRIPTION, - "<html>Check this box to ensure that the well-known objects<br>" - + "of this server can only be allocated by one session at a time.</html>"); - _allocatable = new JCheckBox(allocatable); - - - Action appDistrib = new AbstractAction("Depends on the application distribution") - { - public void actionPerformed(ActionEvent e) - { - _mainEditor.updated(); - } - }; - appDistrib.putValue(Action.SHORT_DESCRIPTION, - "<html>Check this box if this server needs to be restarted<br>" - + "each time the distribution for your application is refreshed.</html>"); - - _applicationDistrib = new JCheckBox(appDistrib); - - _distrib = new JComboBox(new Object[]{NO_DISTRIB, DEFAULT_DISTRIB}); - _distrib.setToolTipText( - "The proxy to the IcePatch2 server holding your files"); - - JTextField distribTextField = (JTextField) - _distrib.getEditor().getEditorComponent(); - distribTextField.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - - _distribDirs.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _distribDirs.setToolTipText( - "<html>Include only these directories when patching.<br>" - + "Use whitespace as separator; use double-quotes around directories containing whitespaces</html>"); - + super(mainEditor); + + _id.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _id.setToolTipText("Must be unique within this IceGrid deployment"); + + _iceVersion.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _iceVersion.setToolTipText("<html>This server's Ice version, such as 3.0 or 3.1.1;<br>" + + "leave blank to use the version of the IceGrid registry.</html>"); + + _exe.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _exe.setToolTipText("<html>Path to this server's executable, e.g.:<br>" + + "icebox<br>" + + "java<br>" + + "myHelloServer<br>" + + "C:\\testbed\\hello\\server</html>"); + + _pwd.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _pwd.setToolTipText( + "<html>If not set, the server will start in " + + "<i>node data dir</i>/servers/<i>server-id</i>;<br>" + + "relative directories are relative to the current directory" + + " of the icegridnode process.</html>"); + + _options.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _options.setToolTipText( + "<html>Command-line arguments for this server.<br>" + + "Use whitespace as separator; use double-quotes around arguments containing whitespaces</html>"); + + _user.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _user.setToolTipText( + "<html>Run the server using this user account.<br>" + + "This feature is only available on Unix/Linux, when the IceGrid node runs as root.</html>"); + + _envs = new MapField(mainEditor, "Name", "Value", true); + + _activation = new JComboBox(new Object[]{ALWAYS, MANUAL, ON_DEMAND, SESSION}); + _activation.setToolTipText("<html>always: IceGrid starts and keeps the server up all the time<br>" + + "manual: you start the server yourself<br>" + + "on-demand: IceGrid starts the server when a client needs it<br>" + + "session: IceGrid starts and shuts down the server for each session</html>"); + + JTextField activationTextField = (JTextField) + _activation.getEditor().getEditorComponent(); + activationTextField.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + + _activationTimeout.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _activationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, " + + "the IceGrid Node<br> uses the value of its " + + "IceGrid.Node.WaitTime property</html>"); + _deactivationTimeout.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _deactivationTimeout.setToolTipText("<html>Number of seconds; if not set or set to 0, " + + "the IceGrid Node<br> uses the value of its " + + "IceGrid.Node.WaitTime property</html>"); + + Action allocatable = new AbstractAction("Allocatable") + { + public void actionPerformed(ActionEvent e) + { + _mainEditor.updated(); + } + }; + allocatable.putValue(Action.SHORT_DESCRIPTION, + "<html>Check this box to ensure that the well-known objects<br>" + + "of this server can only be allocated by one session at a time.</html>"); + _allocatable = new JCheckBox(allocatable); + + + Action appDistrib = new AbstractAction("Depends on the application distribution") + { + public void actionPerformed(ActionEvent e) + { + _mainEditor.updated(); + } + }; + appDistrib.putValue(Action.SHORT_DESCRIPTION, + "<html>Check this box if this server needs to be restarted<br>" + + "each time the distribution for your application is refreshed.</html>"); + + _applicationDistrib = new JCheckBox(appDistrib); + + _distrib = new JComboBox(new Object[]{NO_DISTRIB, DEFAULT_DISTRIB}); + _distrib.setToolTipText( + "The proxy to the IcePatch2 server holding your files"); + + JTextField distribTextField = (JTextField) + _distrib.getEditor().getEditorComponent(); + distribTextField.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + + _distribDirs.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _distribDirs.setToolTipText( + "<html>Include only these directories when patching.<br>" + + "Use whitespace as separator; use double-quotes around directories containing whitespaces</html>"); + } ServerDescriptor getServerDescriptor() { - return (ServerDescriptor) - _mainEditor.getSubDescriptor(); + return (ServerDescriptor) + _mainEditor.getSubDescriptor(); } void appendProperties(DefaultFormBuilder builder) { - builder.append("Server ID"); - builder.append(_id, 3); - builder.nextLine(); - builder.append("Ice Version"); - builder.append(_iceVersion, 3); - 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("Run as"); - builder.append(_user, 3); - builder.nextLine(); - builder.append("Environment Variables"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - CellConstraints cc = new CellConstraints(); - JScrollPane scrollPane = new JScrollPane(_envs); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - 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(); - builder.append("", _allocatable); - 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(_distrib, 3); - builder.nextLine(); - builder.append("Directories"); - builder.append(_distribDirs, 3); - builder.nextLine(); + builder.append("Server ID"); + builder.append(_id, 3); + builder.nextLine(); + builder.append("Ice Version"); + builder.append(_iceVersion, 3); + 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("Run as"); + builder.append(_user, 3); + builder.nextLine(); + builder.append("Environment Variables"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + CellConstraints cc = new CellConstraints(); + JScrollPane scrollPane = new JScrollPane(_envs); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + 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(); + builder.append("", _allocatable); + 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(_distrib, 3); + builder.nextLine(); + builder.append("Directories"); + builder.append(_distribDirs, 3); + builder.nextLine(); } void writeDescriptor() { - ServerDescriptor descriptor = getServerDescriptor(); - descriptor.id = _id.getText().trim(); - descriptor.iceVersion = _iceVersion.getText().trim(); - descriptor.exe = _exe.getText().trim(); - descriptor.pwd = _pwd.getText().trim(); - - descriptor.options = _options.getList(); - descriptor.user = _user.getText().trim(); - - descriptor.envs = new java.util.LinkedList(); - java.util.Iterator p = _envs.get().entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - descriptor.envs.add(entry.getKey().toString() - + "=" + entry.getValue().toString()); - } + ServerDescriptor descriptor = getServerDescriptor(); + descriptor.id = _id.getText().trim(); + descriptor.iceVersion = _iceVersion.getText().trim(); + descriptor.exe = _exe.getText().trim(); + descriptor.pwd = _pwd.getText().trim(); + + descriptor.options = _options.getList(); + descriptor.user = _user.getText().trim(); + + descriptor.envs = new java.util.LinkedList(); + java.util.Iterator p = _envs.get().entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + descriptor.envs.add(entry.getKey().toString() + + "=" + entry.getValue().toString()); + } - descriptor.activation = _activation.getSelectedItem().toString().trim(); - descriptor.activationTimeout = _activationTimeout.getText().trim(); - descriptor.deactivationTimeout = _deactivationTimeout.getText().trim(); - - descriptor.allocatable = _allocatable.isSelected(); - - descriptor.applicationDistrib = _applicationDistrib.isSelected(); - - if(_distrib.getSelectedItem() == NO_DISTRIB) - { - descriptor.distrib.icepatch = ""; - } - else - { - descriptor.distrib.icepatch = _distrib.getSelectedItem().toString().trim(); - } - descriptor.distrib.directories = _distribDirs.getList(); - - super.writeDescriptor(descriptor); - } + descriptor.activation = _activation.getSelectedItem().toString().trim(); + descriptor.activationTimeout = _activationTimeout.getText().trim(); + descriptor.deactivationTimeout = _deactivationTimeout.getText().trim(); + + descriptor.allocatable = _allocatable.isSelected(); + + descriptor.applicationDistrib = _applicationDistrib.isSelected(); + + if(_distrib.getSelectedItem() == NO_DISTRIB) + { + descriptor.distrib.icepatch = ""; + } + else + { + descriptor.distrib.icepatch = _distrib.getSelectedItem().toString().trim(); + } + descriptor.distrib.directories = _distribDirs.getList(); + + super.writeDescriptor(descriptor); + } boolean isSimpleUpdate() { - return getServerDescriptor().id.equals(_id.getText().trim()); + return getServerDescriptor().id.equals(_id.getText().trim()); } boolean validate() { - return _mainEditor.check(new String[]{ - "Server ID", _id.getText().trim(), - "Path to Executable", _exe.getText().trim()}); + return _mainEditor.check(new String[]{ + "Server ID", _id.getText().trim(), + "Path to Executable", _exe.getText().trim()}); } void show(boolean isEditable) { - ServerDescriptor descriptor = getServerDescriptor(); - Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); - - isEditable = isEditable && (detailResolver == null); - - if(detailResolver != null) - { - _id.setText(detailResolver.find("server")); - } - else - { - _id.setText(descriptor.id); - } - _id.setEditable(isEditable); - - _iceVersion.setText( - Utils.substitute(descriptor.iceVersion, detailResolver)); - _iceVersion.setEditable(isEditable); - - _exe.setText( - Utils.substitute(descriptor.exe, detailResolver)); - _exe.setEditable(isEditable); - _pwd.setText( - Utils.substitute(descriptor.pwd, detailResolver)); - _pwd.setEditable(isEditable); - - _options.setList(descriptor.options, detailResolver); - _options.setEditable(isEditable); - - _user.setText( - Utils.substitute(descriptor.user, detailResolver)); - _user.setEditable(isEditable); - - java.util.Map envMap = new java.util.TreeMap(); - java.util.Iterator p = descriptor.envs.iterator(); - while(p.hasNext()) - { - String env = (String)p.next(); - int equal = env.indexOf('='); - if(equal == -1 || equal == env.length() - 1) - { - envMap.put(env, ""); - } - else - { - envMap.put(env.substring(0, equal), - env.substring(equal + 1)); - } - } - _envs.set(envMap, detailResolver, isEditable); - - String activation = Utils.substitute(descriptor.activation, - detailResolver); - - _activation.setEnabled(true); - _activation.setEditable(true); - if(activation.equals(ALWAYS)) - { - _activation.setSelectedItem(ALWAYS); - } - else if(activation.equals(MANUAL)) - { - _activation.setSelectedItem(MANUAL); - } - else if(activation.equals(ON_DEMAND)) - { - _activation.setSelectedItem(ON_DEMAND); - } - else if(activation.equals(SESSION)) - { - _activation.setSelectedItem(SESSION); - } - else - { - _activation.setSelectedItem(activation); - } - _activation.setEnabled(isEditable); - _activation.setEditable(isEditable); - - _activationTimeout.setText( - Utils.substitute(descriptor.activationTimeout, detailResolver)); - _activationTimeout.setEditable(isEditable); - - _deactivationTimeout.setText( - Utils.substitute(descriptor.deactivationTimeout, detailResolver)); - _deactivationTimeout.setEditable(isEditable); - - _allocatable.setSelected(descriptor.allocatable); - _allocatable.setEnabled(isEditable); - - _applicationDistrib.setSelected(descriptor.applicationDistrib); - _applicationDistrib.setEnabled(isEditable); - - _distrib.setEnabled(true); - _distrib.setEditable(true); - String icepatch = Utils.substitute(descriptor.distrib.icepatch, - detailResolver); - if(icepatch.equals("")) - { - _distrib.setSelectedItem(NO_DISTRIB); - } - else - { - _distrib.setSelectedItem(icepatch); - } - _distrib.setEnabled(isEditable); - _distrib.setEditable(isEditable); - - _distribDirs.setList(descriptor.distrib.directories, detailResolver); - _distribDirs.setEditable(isEditable); - - show(descriptor, isEditable); + ServerDescriptor descriptor = getServerDescriptor(); + Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); + + isEditable = isEditable && (detailResolver == null); + + if(detailResolver != null) + { + _id.setText(detailResolver.find("server")); + } + else + { + _id.setText(descriptor.id); + } + _id.setEditable(isEditable); + + _iceVersion.setText( + Utils.substitute(descriptor.iceVersion, detailResolver)); + _iceVersion.setEditable(isEditable); + + _exe.setText( + Utils.substitute(descriptor.exe, detailResolver)); + _exe.setEditable(isEditable); + _pwd.setText( + Utils.substitute(descriptor.pwd, detailResolver)); + _pwd.setEditable(isEditable); + + _options.setList(descriptor.options, detailResolver); + _options.setEditable(isEditable); + + _user.setText( + Utils.substitute(descriptor.user, detailResolver)); + _user.setEditable(isEditable); + + java.util.Map envMap = new java.util.TreeMap(); + java.util.Iterator p = descriptor.envs.iterator(); + while(p.hasNext()) + { + String env = (String)p.next(); + int equal = env.indexOf('='); + if(equal == -1 || equal == env.length() - 1) + { + envMap.put(env, ""); + } + else + { + envMap.put(env.substring(0, equal), + env.substring(equal + 1)); + } + } + _envs.set(envMap, detailResolver, isEditable); + + String activation = Utils.substitute(descriptor.activation, + detailResolver); + + _activation.setEnabled(true); + _activation.setEditable(true); + if(activation.equals(ALWAYS)) + { + _activation.setSelectedItem(ALWAYS); + } + else if(activation.equals(MANUAL)) + { + _activation.setSelectedItem(MANUAL); + } + else if(activation.equals(ON_DEMAND)) + { + _activation.setSelectedItem(ON_DEMAND); + } + else if(activation.equals(SESSION)) + { + _activation.setSelectedItem(SESSION); + } + else + { + _activation.setSelectedItem(activation); + } + _activation.setEnabled(isEditable); + _activation.setEditable(isEditable); + + _activationTimeout.setText( + Utils.substitute(descriptor.activationTimeout, detailResolver)); + _activationTimeout.setEditable(isEditable); + + _deactivationTimeout.setText( + Utils.substitute(descriptor.deactivationTimeout, detailResolver)); + _deactivationTimeout.setEditable(isEditable); + + _allocatable.setSelected(descriptor.allocatable); + _allocatable.setEnabled(isEditable); + + _applicationDistrib.setSelected(descriptor.applicationDistrib); + _applicationDistrib.setEnabled(isEditable); + + _distrib.setEnabled(true); + _distrib.setEditable(true); + String icepatch = Utils.substitute(descriptor.distrib.icepatch, + detailResolver); + if(icepatch.equals("")) + { + _distrib.setSelectedItem(NO_DISTRIB); + } + else + { + _distrib.setSelectedItem(icepatch); + } + _distrib.setEnabled(isEditable); + _distrib.setEditable(isEditable); + + _distribDirs.setList(descriptor.distrib.directories, detailResolver); + _distribDirs.setEditable(isEditable); + + show(descriptor, isEditable); } static private final String ALWAYS = "always"; @@ -383,12 +383,12 @@ class ServerSubEditor extends CommunicatorSubEditor static private final String SESSION = "session"; static private final Object NO_DISTRIB = new Object() - { - public String toString() - { - return "None selected"; - } - }; + { + public String toString() + { + return "None selected"; + } + }; static private final String DEFAULT_DISTRIB = "${application}.IcePatch2/server"; diff --git a/java/src/IceGridGUI/Application/ServerTemplate.java b/java/src/IceGridGUI/Application/ServerTemplate.java index 8c361c5a7d9..db630008f54 100755 --- a/java/src/IceGridGUI/Application/ServerTemplate.java +++ b/java/src/IceGridGUI/Application/ServerTemplate.java @@ -31,57 +31,57 @@ class ServerTemplate extends Communicator static public TemplateDescriptor copyDescriptor(TemplateDescriptor templateDescriptor) { - TemplateDescriptor copy = (TemplateDescriptor) - templateDescriptor.clone(); + TemplateDescriptor copy = (TemplateDescriptor) + templateDescriptor.clone(); - copy.descriptor = PlainServer.copyDescriptor( - (ServerDescriptor)copy.descriptor); - return copy; + copy.descriptor = PlainServer.copyDescriptor( + (ServerDescriptor)copy.descriptor); + return copy; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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); + 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); } @@ -90,270 +90,270 @@ class ServerTemplate extends Communicator // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - if(((TreeNode)_parent).getAvailableActions()[PASTE]) - { - actions[PASTE] = true; - } - else - { - Object clipboard = getCoordinator().getClipboard(); - actions[PASTE] = clipboard != null && - ((isIceBox() && (clipboard instanceof ServiceInstanceDescriptor)) - || (!isIceBox() && (clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor))); - } - - actions[DELETE] = true; - - if(!_ephemeral) - { - actions[NEW_ADAPTER] = !_services.initialized(); - actions[NEW_SERVICE] = _services.initialized(); - actions[NEW_SERVICE_FROM_TEMPLATE] = _services.initialized(); - actions[NEW_DBENV] = _dbEnvs.initialized(); - } - - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + if(((TreeNode)_parent).getAvailableActions()[PASTE]) + { + actions[PASTE] = true; + } + else + { + Object clipboard = getCoordinator().getClipboard(); + actions[PASTE] = clipboard != null && + ((isIceBox() && (clipboard instanceof ServiceInstanceDescriptor)) + || (!isIceBox() && (clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor))); + } + + actions[DELETE] = true; + + if(!_ephemeral) + { + 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); + getCoordinator().setClipboard(copyDescriptor(_templateDescriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } 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; + 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; + if(_editor == null) + { + _editor = (ServerTemplateEditor)getRoot(). + getEditor(ServerTemplateEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ServerTemplateEditor(); + return new ServerTemplateEditor(); } 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, _editable, ServerTemplate.class); - getRoot().updated(); - } + ServerTemplates serverTemplates = (ServerTemplates)_parent; + + if(_ephemeral) + { + serverTemplates.removeChild(this); + } + else + { + serverTemplates.removeDescriptor(_id); + getRoot().removeServerInstances(_id); + serverTemplates.removeChild(this); + serverTemplates.getEditable(). + removeElement(_id, _editable, ServerTemplate.class); + getRoot().updated(); + } } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } public Object getDescriptor() { - return _templateDescriptor; + return _templateDescriptor; } CommunicatorDescriptor getCommunicatorDescriptor() { - return _templateDescriptor.descriptor; + return _templateDescriptor.descriptor; } public Object saveDescriptor() { - // - // Shallow copy - // - TemplateDescriptor clone = (TemplateDescriptor)_templateDescriptor.clone(); - clone.descriptor = (ServerDescriptor)_templateDescriptor.descriptor.clone(); - return clone; + // + // 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; - - PlainServer.shallowRestore((ServerDescriptor)clone.descriptor, - (ServerDescriptor)_templateDescriptor.descriptor); + TemplateDescriptor clone = (TemplateDescriptor)savedDescriptor; + // + // Keep the same object + // + _templateDescriptor.parameters = clone.parameters; + + PlainServer.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 + throws UpdateFailedException { - super(parent, name); - _editable = new Editable(brandNew); - _ephemeral = false; - rebuild(descriptor); + 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; - } + 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", - PlainServer.createAttributes(descriptor)); - - if(descriptor.description.length() > 0) - { - writer.writeElement("description", descriptor.description); - } - PlainServer.writeOptions(writer, descriptor.options); - PlainServer.writeEnvs(writer, descriptor.envs); - - writePropertySet(writer, "", "", descriptor.propertySet, descriptor.adapters, descriptor.logs); - writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); - writeDistribution(writer, descriptor.distrib); - - _adapters.write(writer, descriptor.propertySet.properties); - _services.write(writer); - writer.writeEndTag("icebox"); - } - else - { - ServerDescriptor descriptor = (ServerDescriptor)_templateDescriptor.descriptor; - - writer.writeStartTag("server", - PlainServer.createAttributes(descriptor)); - - if(descriptor.description.length() > 0) - { - writer.writeElement("description", descriptor.description); - } - PlainServer.writeOptions(writer, descriptor.options); - PlainServer.writeEnvs(writer, descriptor.envs); - - writePropertySet(writer, descriptor.propertySet, descriptor.adapters, descriptor.logs); - writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); - writeDistribution(writer, descriptor.distrib); - - _adapters.write(writer, descriptor.propertySet.properties); - _dbEnvs.write(writer); - writer.writeEndTag("server"); - } - writer.writeEndTag("server-template"); - } + 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", + PlainServer.createAttributes(descriptor)); + + if(descriptor.description.length() > 0) + { + writer.writeElement("description", descriptor.description); + } + PlainServer.writeOptions(writer, descriptor.options); + PlainServer.writeEnvs(writer, descriptor.envs); + + writePropertySet(writer, "", "", descriptor.propertySet, descriptor.adapters, descriptor.logs); + writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); + writeDistribution(writer, descriptor.distrib); + + _adapters.write(writer, descriptor.propertySet.properties); + _services.write(writer); + writer.writeEndTag("icebox"); + } + else + { + ServerDescriptor descriptor = (ServerDescriptor)_templateDescriptor.descriptor; + + writer.writeStartTag("server", + PlainServer.createAttributes(descriptor)); + + if(descriptor.description.length() > 0) + { + writer.writeElement("description", descriptor.description); + } + PlainServer.writeOptions(writer, descriptor.options); + PlainServer.writeEnvs(writer, descriptor.envs); + + writePropertySet(writer, descriptor.propertySet, descriptor.adapters, descriptor.logs); + writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); + writeDistribution(writer, descriptor.distrib); + + _adapters.write(writer, descriptor.propertySet.properties); + _dbEnvs.write(writer); + writer.writeEndTag("server"); + } + writer.writeEndTag("server-template"); + } } boolean isIceBox() { - return _templateDescriptor.descriptor instanceof IceBoxDescriptor; + 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(isIceBox()) - { - IceBoxDescriptor iceBoxDescriptor = - (IceBoxDescriptor)_templateDescriptor.descriptor; - - _services.init(iceBoxDescriptor.services); - - assert _templateDescriptor.descriptor.dbEnvs.size() == 0; - } - else - { - _dbEnvs.init(_templateDescriptor.descriptor.dbEnvs); - } - } + _templateDescriptor = descriptor; + + _adapters.clear(); + _dbEnvs.clear(); + _services.clear(); + + if(!_ephemeral) + { + _adapters.init(_templateDescriptor.descriptor.adapters); + + if(isIceBox()) + { + 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); + rebuild(_templateDescriptor); } void commit() { - _editable.commit(); + _editable.commit(); } Editable getEditable() { - return _editable; + return _editable; } Editable getEnclosingEditable() { - return _editable; + return _editable; } java.util.List findInstances() { - return getRoot().findServerInstances(_id); + return getRoot().findServerInstances(_id); } private TemplateDescriptor _templateDescriptor; diff --git a/java/src/IceGridGUI/Application/ServerTemplateEditor.java b/java/src/IceGridGUI/Application/ServerTemplateEditor.java index 5eef3321f8e..91a7203d926 100755 --- a/java/src/IceGridGUI/Application/ServerTemplateEditor.java +++ b/java/src/IceGridGUI/Application/ServerTemplateEditor.java @@ -14,50 +14,50 @@ class ServerTemplateEditor extends TemplateEditor { ServerTemplateEditor() { - _subEditor = new ServerSubEditor(this); + _subEditor = new ServerSubEditor(this); } void writeDescriptor() { - super.writeDescriptor(); - _subEditor.writeDescriptor(); - } + super.writeDescriptor(); + _subEditor.writeDescriptor(); + } boolean isSimpleUpdate() { - return super.isSimpleUpdate() && _subEditor.isSimpleUpdate(); + return super.isSimpleUpdate() && _subEditor.isSimpleUpdate(); } protected void appendProperties(DefaultFormBuilder builder) { - super.appendProperties(builder); - builder.appendSeparator(); - builder.nextLine(); - _subEditor.appendProperties(builder); + super.appendProperties(builder); + builder.appendSeparator(); + builder.nextLine(); + _subEditor.appendProperties(builder); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Server Template Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Server Template Properties"); } protected boolean validate() { - return super.validate() && _subEditor.validate(); + return super.validate() && _subEditor.validate(); } void show(ServerTemplate t) { - detectUpdates(false); - _target = t; - - super.show(); - _subEditor.show(true); + detectUpdates(false); + _target = t; + + super.show(); + _subEditor.show(true); - _applyButton.setEnabled(t.isEphemeral()); - _discardButton.setEnabled(t.isEphemeral()); - detectUpdates(true); + _applyButton.setEnabled(t.isEphemeral()); + _discardButton.setEnabled(t.isEphemeral()); + detectUpdates(true); } private ServerSubEditor _subEditor; diff --git a/java/src/IceGridGUI/Application/ServerTemplates.java b/java/src/IceGridGUI/Application/ServerTemplates.java index e7da327df5a..0b2374d930f 100755 --- a/java/src/IceGridGUI/Application/ServerTemplates.java +++ b/java/src/IceGridGUI/Application/ServerTemplates.java @@ -19,17 +19,17 @@ class ServerTemplates extends Templates static public java.util.Map copyDescriptors(java.util.Map descriptors) { - java.util.Map copy = new java.util.HashMap(); - java.util.Iterator p = descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - copy.put(entry.getKey(), - ServerTemplate.copyDescriptor( - (TemplateDescriptor)entry.getValue())); - } - return copy; + java.util.Map copy = new java.util.HashMap(); + java.util.Iterator p = descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + copy.put(entry.getKey(), + ServerTemplate.copyDescriptor( + (TemplateDescriptor)entry.getValue())); + } + return copy; } // @@ -37,70 +37,70 @@ class ServerTemplates extends Templates // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[NEW_TEMPLATE_SERVER] = true; - actions[NEW_TEMPLATE_SERVER_ICEBOX] = true; - - Object clipboard = getCoordinator().getClipboard(); - if(clipboard != null && clipboard instanceof TemplateDescriptor) - { - TemplateDescriptor d = (TemplateDescriptor)clipboard; - actions[PASTE] = d.descriptor instanceof ServerDescriptor; - } - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[NEW_TEMPLATE_SERVER] = true; + actions[NEW_TEMPLATE_SERVER_ICEBOX] = true; + + Object clipboard = getCoordinator().getClipboard(); + if(clipboard != null && clipboard instanceof TemplateDescriptor) + { + TemplateDescriptor d = (TemplateDescriptor)clipboard; + actions[PASTE] = d.descriptor instanceof ServerDescriptor; + } + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_TEMPLATE_SERVER)); - _popup.add(actions.get(NEW_TEMPLATE_SERVER_ICEBOX)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _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( - PlainServer.newServerDescriptor(), - new java.util.LinkedList(), - new java.util.TreeMap())); + newServerTemplate(new TemplateDescriptor( + PlainServer.newServerDescriptor(), + new java.util.LinkedList(), + new java.util.TreeMap())); } public void newTemplateServerIceBox() { - newServerTemplate(new TemplateDescriptor( - PlainServer.newIceBoxDescriptor(), - new java.util.LinkedList(), - new java.util.TreeMap())); + newServerTemplate(new TemplateDescriptor( + PlainServer.newIceBoxDescriptor(), + new java.util.LinkedList(), + new java.util.TreeMap())); } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - TemplateDescriptor td = (TemplateDescriptor)descriptor; - newServerTemplate(td); + Object descriptor = getCoordinator().getClipboard(); + TemplateDescriptor td = (TemplateDescriptor)descriptor; + newServerTemplate(td); } ServerTemplates(Root parent, java.util.Map descriptors) - throws UpdateFailedException + throws UpdateFailedException { - super(parent, "Server templates"); + super(parent, "Server templates"); - _descriptors = descriptors; + _descriptors = descriptors; - java.util.Iterator p = _descriptors.entrySet().iterator(); - - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - insertChild(new ServerTemplate(false, this, - (String)entry.getKey(), - (TemplateDescriptor)entry.getValue()), - false); - } + java.util.Iterator p = _descriptors.entrySet().iterator(); + + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + insertChild(new ServerTemplate(false, this, + (String)entry.getKey(), + (TemplateDescriptor)entry.getValue()), + false); + } } // @@ -108,165 +108,165 @@ class ServerTemplates extends Templates // Utils.Resolver getResolver() { - return null; + return null; } java.util.Map getUpdates() { - java.util.Map updates = new java.util.HashMap(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServerTemplate t = (ServerTemplate)p.next(); - if(t.getEditable().isNew() || t.getEditable().isModified()) - { - updates.put(t.getId(), t.getDescriptor()); - } - } - return updates; + java.util.Map updates = new java.util.HashMap(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + ServerTemplate t = (ServerTemplate)p.next(); + if(t.getEditable().isNew() || t.getEditable().isModified()) + { + updates.put(t.getId(), t.getDescriptor()); + } + } + return updates; } void commit() { - _editable.commit(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServerTemplate st = (ServerTemplate)p.next(); - st.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(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServerTemplate t = (ServerTemplate)p.next(); - result.addAll(t.findServiceInstances(template)); - } - return result; + java.util.List result = new java.util.LinkedList(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + ServerTemplate t = (ServerTemplate)p.next(); + result.addAll(t.findServiceInstances(template)); + } + return result; } void removeServiceInstances(String template) { - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServerTemplate t = (ServerTemplate)p.next(); - t.removeServiceInstances(template); - } + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + ServerTemplate t = (ServerTemplate)p.next(); + t.removeServiceInstances(template); + } } void newServerTemplate(TemplateDescriptor descriptor) { - String id; - if(descriptor.descriptor instanceof IceBoxDescriptor) - { - id = makeNewChildId("NewIceBoxTemplate"); - } - else - { - id = makeNewChildId("NewServerTemplate"); - } - - ServerTemplate t = new ServerTemplate(this, id, descriptor); - try - { - insertChild(t, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(t); + String id; + if(descriptor.descriptor instanceof IceBoxDescriptor) + { + id = makeNewChildId("NewIceBoxTemplate"); + } + else + { + id = makeNewChildId("NewServerTemplate"); + } + + ServerTemplate t = new ServerTemplate(this, id, descriptor); + try + { + insertChild(t, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(t); } void tryAdd(String newId, TemplateDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertChild(new ServerTemplate(true, this, newId, descriptor), - true); - _descriptors.put(newId, descriptor); + insertChild(new ServerTemplate(true, this, newId, descriptor), + true); + _descriptors.put(newId, descriptor); } void update(java.util.Map updates, String[] removeTemplates, - java.util.Set serviceTemplates) - throws UpdateFailedException + java.util.Set serviceTemplates) + throws UpdateFailedException { - // - // Note: _descriptors is updated by Root - // - - Root root = getRoot(); + // + // Note: _descriptors is updated by Root + // + + Root root = getRoot(); - // - // One big set of removes - // - removeChildren(removeTemplates); + // + // One big set of removes + // + removeChildren(removeTemplates); - // - // One big set of updates, followed by inserts - // - java.util.Vector newChildren = new java.util.Vector(); - java.util.Vector updatedChildren = new java.util.Vector(); - - java.util.Iterator p = updates.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String name = (String)entry.getKey(); - TemplateDescriptor templateDescriptor - = (TemplateDescriptor)entry.getValue(); - ServerTemplate child = (ServerTemplate)findChild(name); - if(child == null) - { - newChildren.add(new ServerTemplate(false, this, name, templateDescriptor)); - } - else - { - child.rebuild(templateDescriptor); - updatedChildren.add(child); - } - } - - // - // Rebuild template affected by service template updates - // - p = serviceTemplates.iterator(); - while(p.hasNext()) - { - java.util.List serviceInstances = - findServiceInstances((String)p.next()); - java.util.Iterator q = serviceInstances.iterator(); - while(q.hasNext()) - { - ServiceInstance service = (ServiceInstance)q.next(); - ServerTemplate serverTemplate = - (ServerTemplate)service.getParent(); - - if(!updatedChildren.contains(serverTemplate) && - !newChildren.contains(serverTemplate)) - { - serverTemplate.rebuild(); - updatedChildren.add(serverTemplate); - } - } - } - - childrenChanged(updatedChildren); - insertChildren(newChildren, true); + // + // One big set of updates, followed by inserts + // + java.util.Vector newChildren = new java.util.Vector(); + java.util.Vector updatedChildren = new java.util.Vector(); + + java.util.Iterator p = updates.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String name = (String)entry.getKey(); + TemplateDescriptor templateDescriptor + = (TemplateDescriptor)entry.getValue(); + ServerTemplate child = (ServerTemplate)findChild(name); + if(child == null) + { + newChildren.add(new ServerTemplate(false, this, name, templateDescriptor)); + } + else + { + child.rebuild(templateDescriptor); + updatedChildren.add(child); + } + } + + // + // Rebuild template affected by service template updates + // + p = serviceTemplates.iterator(); + while(p.hasNext()) + { + java.util.List serviceInstances = + findServiceInstances((String)p.next()); + java.util.Iterator q = serviceInstances.iterator(); + while(q.hasNext()) + { + ServiceInstance service = (ServiceInstance)q.next(); + ServerTemplate serverTemplate = + (ServerTemplate)service.getParent(); + + if(!updatedChildren.contains(serverTemplate) && + !newChildren.contains(serverTemplate)) + { + serverTemplate.rebuild(); + updatedChildren.add(serverTemplate); + } + } + } + + childrenChanged(updatedChildren); + insertChildren(newChildren, true); } void removeDescriptor(String id) { - _descriptors.remove(id); + _descriptors.remove(id); } Object getDescriptor() { - return _descriptors; + return _descriptors; } private java.util.Map _descriptors; diff --git a/java/src/IceGridGUI/Application/ServiceInstance.java b/java/src/IceGridGUI/Application/ServiceInstance.java index d5a93f5e7aa..00b2af1a22d 100755 --- a/java/src/IceGridGUI/Application/ServiceInstance.java +++ b/java/src/IceGridGUI/Application/ServiceInstance.java @@ -21,49 +21,49 @@ class ServiceInstance extends TreeNode implements Service, Cloneable static public ServiceInstanceDescriptor copyDescriptor(ServiceInstanceDescriptor instanceDescriptor) { - ServiceInstanceDescriptor copy = (ServiceInstanceDescriptor) - instanceDescriptor.clone(); - - copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); - - if(copy.descriptor != null) - { - copy.descriptor = PlainService.copyDescriptor((ServiceDescriptor)copy.descriptor); - } - return copy; + ServiceInstanceDescriptor copy = (ServiceInstanceDescriptor) + instanceDescriptor.clone(); + + copy.propertySet = PropertySet.copyDescriptor(copy.propertySet); + + if(copy.descriptor != null) + { + copy.descriptor = PlainService.copyDescriptor((ServiceDescriptor)copy.descriptor); + } + return copy; } static public java.util.List copyDescriptors(java.util.List descriptors) { - java.util.List copy = new java.util.LinkedList(); - java.util.Iterator p = descriptors.iterator(); - while(p.hasNext()) - { - copy.add(copyDescriptor( - (ServiceInstanceDescriptor)p.next())); - } - return copy; + java.util.List 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) + 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/service.png")); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + if(_cellRenderer == null) + { + _cellRenderer = new DefaultTreeCellRenderer(); + _cellRenderer.setLeafIcon( + Utils.getIcon("/icons/16x16/service.png")); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } // @@ -71,283 +71,283 @@ class ServiceInstance extends TreeNode implements Service, Cloneable // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[COPY] = !_ephemeral; - - if(((TreeNode)_parent).getAvailableActions()[PASTE]) - { - actions[PASTE] = true; - } - - actions[DELETE] = true; - - 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; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[COPY] = !_ephemeral; + + if(((TreeNode)_parent).getAvailableActions()[PASTE]) + { + actions[PASTE] = true; + } + + actions[DELETE] = true; + + 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(MOVE_UP)); - _popup.add(actions.get(MOVE_DOWN)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(MOVE_UP)); + _popup.add(actions.get(MOVE_DOWN)); + } + actions.setTarget(this); + return _popup; } public void copy() { - getCoordinator().setClipboard(copyDescriptor(_descriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_descriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } public void paste() { - ((TreeNode)_parent).paste(); + ((TreeNode)_parent).paste(); } public void moveUp() { - move(true); + move(true); } public void moveDown() { - move(false); + move(false); } public Object getDescriptor() { - return _descriptor; + return _descriptor; } public Object saveDescriptor() { - // - // Must be a shallow copy - // - ServiceInstanceDescriptor saved = - (ServiceInstanceDescriptor)_descriptor.clone(); - - - assert saved.descriptor == null; - return saved; + // + // Must be a shallow copy + // + ServiceInstanceDescriptor saved = + (ServiceInstanceDescriptor)_descriptor.clone(); + + + assert saved.descriptor == null; + return saved; } public void restoreDescriptor(Object savedDescriptor) { - ServiceInstanceDescriptor sd = (ServiceInstanceDescriptor)savedDescriptor; - _descriptor.template = sd.template; - _descriptor.parameterValues = sd.parameterValues; - _descriptor.propertySet = sd.propertySet; + ServiceInstanceDescriptor sd = (ServiceInstanceDescriptor)savedDescriptor; + _descriptor.template = sd.template; + _descriptor.parameterValues = sd.parameterValues; + _descriptor.propertySet = sd.propertySet; } public void destroy() { - ((Communicator)_parent).getServices().destroyChild(this); + ((Communicator)_parent).getServices().destroyChild(this); } public Editor getEditor() { - if(_editor == null) - { - _editor = (ServiceInstanceEditor)getRoot(). - getEditor(ServiceInstanceEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (ServiceInstanceEditor)getRoot(). + getEditor(ServiceInstanceEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ServiceInstanceEditor(); + return new ServiceInstanceEditor(); } public String toString() { - if(_displayString != null) - { - return _displayString; - } - else - { - return super.toString(); - } + if(_displayString != null) + { + return _displayString; + } + else + { + return super.toString(); + } } private boolean canMove(boolean up) { - if(_ephemeral) - { - return false; - } - else - { - return ((Communicator)_parent).getServices().canMove(this, 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); + assert canMove(up); + ((Communicator)_parent).getServices().move(this, up); } Editable getEnclosingEditable() { - return ((Communicator)_parent).getEnclosingEditable(); + return ((Communicator)_parent).getEnclosingEditable(); } static private class Backup { - java.util.Map parameterValues; - ServiceInstance clone; + java.util.Map parameterValues; + ServiceInstance clone; } public Object rebuild(java.util.List editables) - throws UpdateFailedException + throws UpdateFailedException { - Backup backup = new Backup(); - - // - // Fix-up _descriptor if necessary - // - if(_descriptor.template.length() > 0) - { - TemplateDescriptor templateDescriptor - = getRoot().findServiceTemplateDescriptor(_descriptor.template); - - java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters); - if(!parameters.equals(_descriptor.parameterValues.keySet())) - { - backup.parameterValues = _descriptor.parameterValues; - _descriptor.parameterValues = Editor.makeParameterValues( - _descriptor.parameterValues, templateDescriptor.parameters); - editables.add(getEnclosingEditable()); - } - } - - Communicator communicator = (Communicator)_parent; - Communicator.Services services = communicator.getServices(); - ServiceInstance newService = null; - - try - { - newService = (ServiceInstance)services.createChild(_descriptor); - } - catch(UpdateFailedException e) - { - if(backup.parameterValues != null) - { - _descriptor.parameterValues = backup.parameterValues; - } - throw e; - } - - try - { - backup.clone = (ServiceInstance)clone(); - } - catch(CloneNotSupportedException e) - { - assert false; - } - - reset(newService); - - if(backup.parameterValues != null) - { - editables.add(getEnclosingEditable()); - } - getRoot().getTreeModel().nodeChanged(this); - return backup; + Backup backup = new Backup(); + + // + // Fix-up _descriptor if necessary + // + if(_descriptor.template.length() > 0) + { + TemplateDescriptor templateDescriptor + = getRoot().findServiceTemplateDescriptor(_descriptor.template); + + java.util.Set parameters = new java.util.HashSet(templateDescriptor.parameters); + if(!parameters.equals(_descriptor.parameterValues.keySet())) + { + backup.parameterValues = _descriptor.parameterValues; + _descriptor.parameterValues = Editor.makeParameterValues( + _descriptor.parameterValues, templateDescriptor.parameters); + editables.add(getEnclosingEditable()); + } + } + + Communicator communicator = (Communicator)_parent; + Communicator.Services services = communicator.getServices(); + ServiceInstance newService = null; + + try + { + newService = (ServiceInstance)services.createChild(_descriptor); + } + catch(UpdateFailedException e) + { + if(backup.parameterValues != null) + { + _descriptor.parameterValues = backup.parameterValues; + } + throw e; + } + + try + { + backup.clone = (ServiceInstance)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) - { - _descriptor.parameterValues = backup.parameterValues; - } - - reset(backup.clone); - getRoot().getTreeModel().nodeChanged(this); + Backup backup = (Backup)backupObj; + + if(backup.parameterValues != null) + { + _descriptor.parameterValues = backup.parameterValues; + } + + reset(backup.clone); + getRoot().getTreeModel().nodeChanged(this); } private void reset(ServiceInstance from) { - _id = from._id; - _displayString = from._displayString; - _resolver = from._resolver; + _id = from._id; + _displayString = from._displayString; + _resolver = from._resolver; } ServiceInstance(Communicator parent, - String name, - String displayString, - ServiceInstanceDescriptor instanceDescriptor, - Utils.Resolver resolver) - throws UpdateFailedException + String name, + String displayString, + ServiceInstanceDescriptor instanceDescriptor, + Utils.Resolver resolver) + throws UpdateFailedException { - super(parent, name); - _displayString = displayString; - _descriptor = instanceDescriptor; - _ephemeral = false; - _resolver = resolver; + super(parent, name); + _displayString = displayString; + _descriptor = instanceDescriptor; + _ephemeral = false; + _resolver = resolver; } // // New temporary object // ServiceInstance(Communicator parent, String name, - ServiceInstanceDescriptor instanceDescriptor) + ServiceInstanceDescriptor instanceDescriptor) { - super(parent, name); - _descriptor = instanceDescriptor; - _ephemeral = true; + super(parent, name); + _descriptor = instanceDescriptor; + _ephemeral = true; } void write(XMLWriter writer) throws java.io.IOException { - if(!_ephemeral) - { - TemplateDescriptor templateDescriptor - = getRoot().findServiceTemplateDescriptor(_descriptor.template); - - java.util.LinkedList attributes = parameterValuesToAttributes( - _descriptor.parameterValues, templateDescriptor.parameters); - attributes.addFirst(createAttribute("template", _descriptor.template)); - - if(_descriptor.propertySet.references.length == 0 && - _descriptor.propertySet.properties.size() == 0) - { - writer.writeElement("service-instance", attributes); - } - else - { - writer.writeStartTag("service-instance", attributes); - writePropertySet(writer, _descriptor.propertySet, null, null); - writer.writeEndTag("service-instance"); - } - } + if(!_ephemeral) + { + TemplateDescriptor templateDescriptor + = getRoot().findServiceTemplateDescriptor(_descriptor.template); + + java.util.LinkedList attributes = parameterValuesToAttributes( + _descriptor.parameterValues, templateDescriptor.parameters); + attributes.addFirst(createAttribute("template", _descriptor.template)); + + if(_descriptor.propertySet.references.length == 0 && + _descriptor.propertySet.properties.size() == 0) + { + writer.writeElement("service-instance", attributes); + } + else + { + writer.writeStartTag("service-instance", attributes); + writePropertySet(writer, _descriptor.propertySet, null, null); + writer.writeEndTag("service-instance"); + } + } } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } private ServiceInstanceDescriptor _descriptor; diff --git a/java/src/IceGridGUI/Application/ServiceInstanceEditor.java b/java/src/IceGridGUI/Application/ServiceInstanceEditor.java index 489de0884f4..bf55a13611a 100755 --- a/java/src/IceGridGUI/Application/ServiceInstanceEditor.java +++ b/java/src/IceGridGUI/Application/ServiceInstanceEditor.java @@ -30,35 +30,35 @@ class ServiceInstanceEditor extends CommunicatorChildEditor { ServiceInstanceEditor() { - // - // Template - // - Action gotoTemplate = new AbstractAction( - "", Utils.getIcon("/icons/16x16/goto.png")) - { - public void actionPerformed(ActionEvent e) - { - TreeNode t = (TreeNode)_template.getSelectedItem(); - if(t != null) - { - t.getRoot().setSelectedNode(t); - } - } - }; - gotoTemplate.putValue(Action.SHORT_DESCRIPTION, - "Goto this service template"); - _templateButton = new JButton(gotoTemplate); - - _parameters = new ParameterValuesField(this); - - _propertySets.getDocument().addDocumentListener(_updateListener); - _propertySets.setToolTipText("Property Set References"); - _properties = new PropertiesField(this); + // + // Template + // + Action gotoTemplate = new AbstractAction( + "", Utils.getIcon("/icons/16x16/goto.png")) + { + public void actionPerformed(ActionEvent e) + { + TreeNode t = (TreeNode)_template.getSelectedItem(); + if(t != null) + { + t.getRoot().setSelectedNode(t); + } + } + }; + gotoTemplate.putValue(Action.SHORT_DESCRIPTION, + "Goto this service template"); + _templateButton = new JButton(gotoTemplate); + + _parameters = new ParameterValuesField(this); + + _propertySets.getDocument().addDocumentListener(_updateListener); + _propertySets.setToolTipText("Property Set References"); + _properties = new PropertiesField(this); } ServiceInstanceDescriptor getDescriptor() { - return (ServiceInstanceDescriptor)_target.getDescriptor(); + return (ServiceInstanceDescriptor)_target.getDescriptor(); } // @@ -66,168 +66,168 @@ class ServiceInstanceEditor extends CommunicatorChildEditor // Utils.Resolver getDetailResolver() { - ServiceInstance service = (ServiceInstance)_target; - if(service.getCoordinator().substitute()) - { - return service.getResolver(); - } - else - { - return null; - } + ServiceInstance service = (ServiceInstance)_target; + if(service.getCoordinator().substitute()) + { + return service.getResolver(); + } + else + { + return null; + } } void writeDescriptor() { - ServiceInstanceDescriptor descriptor = getDescriptor(); - descriptor.template = ((ServiceTemplate)_template.getSelectedItem()).getId(); - descriptor.parameterValues = _parameters.getValues(); - - descriptor.propertySet.references = - (String[])_propertySets.getList().toArray(new String[0]); - descriptor.propertySet.properties = _properties.getProperties(); - } + ServiceInstanceDescriptor descriptor = getDescriptor(); + descriptor.template = ((ServiceTemplate)_template.getSelectedItem()).getId(); + descriptor.parameterValues = _parameters.getValues(); + + descriptor.propertySet.references = + (String[])_propertySets.getList().toArray(new String[0]); + descriptor.propertySet.properties = _properties.getProperties(); + } boolean isSimpleUpdate() { - ServiceInstanceDescriptor descriptor = getDescriptor(); - ServiceTemplate t = (ServiceTemplate)_template.getSelectedItem(); - - return descriptor.template.equals(t.getId()) - && descriptor.parameterValues.equals(_parameters.getValues()); + ServiceInstanceDescriptor descriptor = getDescriptor(); + ServiceTemplate t = (ServiceTemplate)_template.getSelectedItem(); + + return descriptor.template.equals(t.getId()) + && descriptor.parameterValues.equals(_parameters.getValues()); } Communicator.ChildList getChildList() { - return ((Communicator)_target.getParent()).getServices(); + return ((Communicator)_target.getParent()).getServices(); } protected void appendProperties(DefaultFormBuilder builder) { - builder.append("Template", _template); - builder.append(_templateButton); - builder.nextLine(); - - builder.append("Parameters"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - - builder.nextLine(); - builder.append(""); - - builder.nextRow(-6); - JScrollPane scrollPane = new JScrollPane(_parameters); - CellConstraints cc = new CellConstraints(); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); - - builder.append("Property Sets"); - builder.append(_propertySets, 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(); + builder.append("Template", _template); + builder.append(_templateButton); + builder.nextLine(); + + builder.append("Parameters"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + + builder.nextLine(); + builder.append(""); + + builder.nextRow(-6); + JScrollPane scrollPane = new JScrollPane(_parameters); + CellConstraints cc = new CellConstraints(); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); + + builder.append("Property Sets"); + builder.append(_propertySets, 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("Service Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Service Properties"); } void show(ServiceInstance service) { - detectUpdates(false); - _target = service; - - // - // If it's not a template instance, it's shown using - // ServiceEditor.show() - // - assert getDescriptor().template.length() > 0; - - ServiceInstanceDescriptor descriptor = - (ServiceInstanceDescriptor)service.getDescriptor(); - Coordinator coordinator = service.getCoordinator(); - boolean isEditable = service.isEphemeral() || !coordinator.substitute(); - - Utils.Resolver resolver = isEditable ? null : - ((TreeNode)service.getParent()).getResolver(); - - // - // Need to make control enabled before changing it - // - _template.setEnabled(true); - - ServiceTemplates serviceTemplates = - service.getRoot().getServiceTemplates(); - _template.setModel(serviceTemplates.createComboBoxModel()); - - ServiceTemplate t = (ServiceTemplate) - serviceTemplates.findChild(descriptor.template); - assert t != null; - _template.setSelectedItem(t); - - ListDataListener templateListener = new ListDataListener() - { - public void contentsChanged(ListDataEvent e) - { - updated(); - - ServiceTemplate t = - (ServiceTemplate)_template.getModel().getSelectedItem(); - - TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); - - // - // Replace parameters but keep existing values - // - _parameters.set(td.parameters, - makeParameterValues(_parameters.getValues(), td.parameters), - td.parameterDefaults, null); - } - - public void intervalAdded(ListDataEvent e) - {} + detectUpdates(false); + _target = service; + + // + // If it's not a template instance, it's shown using + // ServiceEditor.show() + // + assert getDescriptor().template.length() > 0; + + ServiceInstanceDescriptor descriptor = + (ServiceInstanceDescriptor)service.getDescriptor(); + Coordinator coordinator = service.getCoordinator(); + boolean isEditable = service.isEphemeral() || !coordinator.substitute(); + + Utils.Resolver resolver = isEditable ? null : + ((TreeNode)service.getParent()).getResolver(); + + // + // Need to make control enabled before changing it + // + _template.setEnabled(true); + + ServiceTemplates serviceTemplates = + service.getRoot().getServiceTemplates(); + _template.setModel(serviceTemplates.createComboBoxModel()); + + ServiceTemplate t = (ServiceTemplate) + serviceTemplates.findChild(descriptor.template); + assert t != null; + _template.setSelectedItem(t); + + ListDataListener templateListener = new ListDataListener() + { + public void contentsChanged(ListDataEvent e) + { + updated(); + + ServiceTemplate t = + (ServiceTemplate)_template.getModel().getSelectedItem(); + + TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); + + // + // Replace parameters but keep existing values + // + _parameters.set(td.parameters, + makeParameterValues(_parameters.getValues(), td.parameters), + td.parameterDefaults, null); + } + + public void intervalAdded(ListDataEvent e) + {} - public void intervalRemoved(ListDataEvent e) - {} - }; - - _template.getModel().addListDataListener(templateListener); - _template.setEnabled(isEditable); - - TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); - _parameters.set(td.parameters, descriptor.parameterValues, - td.parameterDefaults, resolver); - - _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), - getDetailResolver()); - _propertySets.setEditable(isEditable); - - _properties.setProperties(descriptor.propertySet.properties, null, null, - getDetailResolver(), isEditable); - - _applyButton.setEnabled(service.isEphemeral()); - _discardButton.setEnabled(service.isEphemeral()); - detectUpdates(true); + public void intervalRemoved(ListDataEvent e) + {} + }; + + _template.getModel().addListDataListener(templateListener); + _template.setEnabled(isEditable); + + TemplateDescriptor td = (TemplateDescriptor)t.getDescriptor(); + _parameters.set(td.parameters, descriptor.parameterValues, + td.parameterDefaults, resolver); + + _propertySets.setList(java.util.Arrays.asList(descriptor.propertySet.references), + getDetailResolver()); + _propertySets.setEditable(isEditable); + + _properties.setProperties(descriptor.propertySet.properties, null, null, + getDetailResolver(), isEditable); + + _applyButton.setEnabled(service.isEphemeral()); + _discardButton.setEnabled(service.isEphemeral()); + detectUpdates(true); } private JComboBox _template = new JComboBox(); diff --git a/java/src/IceGridGUI/Application/ServiceSubEditor.java b/java/src/IceGridGUI/Application/ServiceSubEditor.java index 925ad59bf4b..0f5652e02af 100755 --- a/java/src/IceGridGUI/Application/ServiceSubEditor.java +++ b/java/src/IceGridGUI/Application/ServiceSubEditor.java @@ -23,86 +23,86 @@ class ServiceSubEditor extends CommunicatorSubEditor { ServiceSubEditor(Editor mainEditor) { - super(mainEditor); + super(mainEditor); - _name.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _name.setToolTipText("Identifies this service within an IceBox server"); + _name.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _name.setToolTipText("Identifies this service within an IceBox server"); - _entry.getDocument().addDocumentListener( - _mainEditor.getUpdateListener()); - _entry.setToolTipText( - "<html>The service entry point and optional arguments.<br>" - + "C++: <i>shared object:function-name arg1 arg2 ...</i><br>" - + "Java: <i>class-name arg1 arg2 ...</i><br>" - + "C#, Visual Basic: <i>assembly:class-name arg1 arg2 ...</i>" - + "</html>"); + _entry.getDocument().addDocumentListener( + _mainEditor.getUpdateListener()); + _entry.setToolTipText( + "<html>The service entry point and optional arguments.<br>" + + "C++: <i>shared object:function-name arg1 arg2 ...</i><br>" + + "Java: <i>class-name arg1 arg2 ...</i><br>" + + "C#, Visual Basic: <i>assembly:class-name arg1 arg2 ...</i>" + + "</html>"); } ServiceDescriptor getServiceDescriptor() { - return (ServiceDescriptor) - _mainEditor.getSubDescriptor(); + return (ServiceDescriptor) + _mainEditor.getSubDescriptor(); } void appendProperties(DefaultFormBuilder builder) { - builder.append("Service Name"); - builder.append(_name, 3); - builder.nextLine(); - - // - // Add Communicator fields - // - super.appendProperties(builder); + builder.append("Service Name"); + builder.append(_name, 3); + builder.nextLine(); + + // + // Add Communicator fields + // + super.appendProperties(builder); - builder.append("Entry Point"); - builder.append(_entry, 3); - builder.nextLine(); + builder.append("Entry Point"); + builder.append(_entry, 3); + builder.nextLine(); } void writeDescriptor() { - ServiceDescriptor descriptor = getServiceDescriptor(); - descriptor.name = _name.getText().trim(); - descriptor.entry = _entry.getText().trim(); - super.writeDescriptor(descriptor); - } + ServiceDescriptor descriptor = getServiceDescriptor(); + descriptor.name = _name.getText().trim(); + descriptor.entry = _entry.getText().trim(); + super.writeDescriptor(descriptor); + } boolean isSimpleUpdate() { - return getServiceDescriptor().name.equals(_name.getText().trim()); + return getServiceDescriptor().name.equals(_name.getText().trim()); } boolean validate() { - return _mainEditor.check(new String[]{ - "Service Name", _name.getText().trim(), - "Entry Point", _entry.getText().trim()}); + return _mainEditor.check(new String[]{ + "Service Name", _name.getText().trim(), + "Entry Point", _entry.getText().trim()}); } void show(boolean isEditable) { - ServiceDescriptor descriptor = getServiceDescriptor(); - Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); - - isEditable = isEditable && (detailResolver == null); + ServiceDescriptor descriptor = getServiceDescriptor(); + Utils.Resolver detailResolver = _mainEditor.getDetailResolver(); + + isEditable = isEditable && (detailResolver == null); - if(detailResolver != null) - { - _name.setText(detailResolver.find("service")); - } - else - { - _name.setText(descriptor.name); - } - _name.setEditable(isEditable); - - _entry.setText( - Utils.substitute(descriptor.entry, detailResolver)); - _entry.setEditable(isEditable); + if(detailResolver != null) + { + _name.setText(detailResolver.find("service")); + } + else + { + _name.setText(descriptor.name); + } + _name.setEditable(isEditable); + + _entry.setText( + Utils.substitute(descriptor.entry, detailResolver)); + _entry.setEditable(isEditable); - show(descriptor, isEditable); + show(descriptor, isEditable); } private JTextField _name = new JTextField(20); diff --git a/java/src/IceGridGUI/Application/ServiceTemplate.java b/java/src/IceGridGUI/Application/ServiceTemplate.java index a6c757519e3..72b17ec4261 100755 --- a/java/src/IceGridGUI/Application/ServiceTemplate.java +++ b/java/src/IceGridGUI/Application/ServiceTemplate.java @@ -22,35 +22,35 @@ class ServiceTemplate extends Communicator static public TemplateDescriptor copyDescriptor(TemplateDescriptor templateDescriptor) { - TemplateDescriptor copy = (TemplateDescriptor) - templateDescriptor.clone(); + TemplateDescriptor copy = (TemplateDescriptor) + templateDescriptor.clone(); - copy.descriptor = PlainService.copyDescriptor( - (ServiceDescriptor)copy.descriptor); - - return copy; + copy.descriptor = PlainService.copyDescriptor( + (ServiceDescriptor)copy.descriptor); + + return copy; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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_template.png")); - _cellRenderer.setClosedIcon( - Utils.getIcon("/icons/16x16/service_template.png")); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + if(_cellRenderer == null) + { + _cellRenderer = new DefaultTreeCellRenderer(); + _cellRenderer.setOpenIcon( + Utils.getIcon("/icons/16x16/service_template.png")); + _cellRenderer.setClosedIcon( + Utils.getIcon("/icons/16x16/service_template.png")); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } @@ -59,205 +59,205 @@ class ServiceTemplate extends Communicator // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - - if(((TreeNode)_parent).getAvailableActions()[PASTE]) - { - actions[PASTE] = true; - } - else - { - Object clipboard = getCoordinator().getClipboard(); - actions[PASTE] = clipboard != null && - (clipboard instanceof AdapterDescriptor - || clipboard instanceof DbEnvDescriptor); - } - - actions[DELETE] = true; - - if(!_ephemeral) - { - actions[COPY] = true; - actions[NEW_ADAPTER] = true; - actions[NEW_DBENV] = true; - } - - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + + if(((TreeNode)_parent).getAvailableActions()[PASTE]) + { + actions[PASTE] = true; + } + else + { + Object clipboard = getCoordinator().getClipboard(); + actions[PASTE] = clipboard != null && + (clipboard instanceof AdapterDescriptor + || clipboard instanceof DbEnvDescriptor); + } + + actions[DELETE] = true; + + if(!_ephemeral) + { + actions[COPY] = true; + actions[NEW_ADAPTER] = true; + actions[NEW_DBENV] = true; + } + + return actions; } public void copy() { - getCoordinator().setClipboard(copyDescriptor(_templateDescriptor)); - getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); + getCoordinator().setClipboard(copyDescriptor(_templateDescriptor)); + getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true); } 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)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_ADAPTER)); + _popup.add(actions.get(NEW_DBENV)); + } + actions.setTarget(this); + return _popup; } public Editor getEditor() { - if(_editor == null) - { - _editor = (ServiceTemplateEditor)getRoot().getEditor(ServiceTemplateEditor.class, this); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = (ServiceTemplateEditor)getRoot().getEditor(ServiceTemplateEditor.class, this); + } + _editor.show(this); + return _editor; } protected Editor createEditor() { - return new ServiceTemplateEditor(); + return new ServiceTemplateEditor(); } ServiceTemplate(boolean brandNew, ServiceTemplates parent, - String name, TemplateDescriptor descriptor) - throws UpdateFailedException + String name, TemplateDescriptor descriptor) + throws UpdateFailedException { - super(parent, name); - _editable = new Editable(brandNew); - _ephemeral = false; - rebuild(descriptor); + super(parent, name); + _editable = new Editable(brandNew); + _ephemeral = false; + rebuild(descriptor); } ServiceTemplate(ServiceTemplates parent, String name, TemplateDescriptor descriptor) { - super(parent, name); - _ephemeral = true; - _editable = null; - _templateDescriptor = descriptor; + super(parent, name); + _ephemeral = true; + _editable = null; + _templateDescriptor = descriptor; } 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("service-template", attributes); - writeParameters(writer, _templateDescriptor.parameters, - _templateDescriptor.parameterDefaults); - - ServiceDescriptor descriptor = (ServiceDescriptor)_templateDescriptor.descriptor; - - writer.writeStartTag("service", PlainService.createAttributes(descriptor)); - - if(descriptor.description.length() > 0) - { - writer.writeElement("description", descriptor.description); - } - - writePropertySet(writer, descriptor.propertySet, descriptor.adapters, descriptor.logs); - writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); - _adapters.write(writer, descriptor.propertySet.properties); - _dbEnvs.write(writer); - writer.writeEndTag("service"); - writer.writeEndTag("service-template"); - } + if(!_ephemeral) + { + 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", PlainService.createAttributes(descriptor)); + + if(descriptor.description.length() > 0) + { + writer.writeElement("description", descriptor.description); + } + + writePropertySet(writer, descriptor.propertySet, descriptor.adapters, descriptor.logs); + writeLogs(writer, descriptor.logs, descriptor.propertySet.properties); + _adapters.write(writer, descriptor.propertySet.properties); + _dbEnvs.write(writer); + writer.writeEndTag("service"); + writer.writeEndTag("service-template"); + } } void rebuild(TemplateDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - _templateDescriptor = descriptor; + _templateDescriptor = descriptor; - _adapters.clear(); - _dbEnvs.clear(); + _adapters.clear(); + _dbEnvs.clear(); - if(!_ephemeral) - { - _adapters.init(_templateDescriptor.descriptor.adapters); - _dbEnvs.init(_templateDescriptor.descriptor.dbEnvs); - } + if(!_ephemeral) + { + _adapters.init(_templateDescriptor.descriptor.adapters); + _dbEnvs.init(_templateDescriptor.descriptor.dbEnvs); + } } void commit() { - _editable.commit(); + _editable.commit(); } public Object getDescriptor() { - return _templateDescriptor; + return _templateDescriptor; } CommunicatorDescriptor getCommunicatorDescriptor() { - return _templateDescriptor.descriptor; + return _templateDescriptor.descriptor; } public boolean isEphemeral() { - return _ephemeral; + return _ephemeral; } public void destroy() { - ServiceTemplates serviceTemplates = (ServiceTemplates)_parent; - - if(_ephemeral) - { - serviceTemplates.removeChild(this); - } - else - { - serviceTemplates.removeDescriptor(_id); - getRoot().removeServiceInstances(_id); - serviceTemplates.removeChild(this); - serviceTemplates.getEditable(). - removeElement(_id, _editable, ServiceTemplate.class); - getRoot().updated(); - } + ServiceTemplates serviceTemplates = (ServiceTemplates)_parent; + + if(_ephemeral) + { + serviceTemplates.removeChild(this); + } + else + { + serviceTemplates.removeDescriptor(_id); + getRoot().removeServiceInstances(_id); + serviceTemplates.removeChild(this); + serviceTemplates.getEditable(). + removeElement(_id, _editable, ServiceTemplate.class); + getRoot().updated(); + } } java.util.List findInstances() { - return getRoot().findServiceInstances(_id); + return getRoot().findServiceInstances(_id); } Editable getEditable() { - return _editable; + return _editable; } Editable getEnclosingEditable() { - return _editable; + return _editable; } public Object saveDescriptor() { - // - // Shallow copy - // - TemplateDescriptor clone = (TemplateDescriptor)_templateDescriptor.clone(); - clone.descriptor = (ServiceDescriptor)_templateDescriptor.descriptor.clone(); - return clone; + // + // Shallow copy + // + TemplateDescriptor clone = (TemplateDescriptor)_templateDescriptor.clone(); + clone.descriptor = (ServiceDescriptor)_templateDescriptor.descriptor.clone(); + return clone; } public void restoreDescriptor(Object savedDescriptor) { - TemplateDescriptor clone = (TemplateDescriptor)savedDescriptor; - // - // Keep the same object - // - _templateDescriptor.parameters = clone.parameters; - - ServiceDescriptor sd = (ServiceDescriptor)_templateDescriptor.descriptor; - ServiceDescriptor csd = (ServiceDescriptor)clone.descriptor; - - sd.propertySet = csd.propertySet; - sd.description = csd.description; - sd.name = csd.name; - sd.entry = csd.entry; + TemplateDescriptor clone = (TemplateDescriptor)savedDescriptor; + // + // Keep the same object + // + _templateDescriptor.parameters = clone.parameters; + + ServiceDescriptor sd = (ServiceDescriptor)_templateDescriptor.descriptor; + ServiceDescriptor csd = (ServiceDescriptor)clone.descriptor; + + sd.propertySet = csd.propertySet; + sd.description = csd.description; + sd.name = csd.name; + sd.entry = csd.entry; } private TemplateDescriptor _templateDescriptor; diff --git a/java/src/IceGridGUI/Application/ServiceTemplateEditor.java b/java/src/IceGridGUI/Application/ServiceTemplateEditor.java index 6db6e77a692..8d37cc803f5 100755 --- a/java/src/IceGridGUI/Application/ServiceTemplateEditor.java +++ b/java/src/IceGridGUI/Application/ServiceTemplateEditor.java @@ -14,50 +14,50 @@ class ServiceTemplateEditor extends TemplateEditor { ServiceTemplateEditor() { - _subEditor = new ServiceSubEditor(this); + _subEditor = new ServiceSubEditor(this); } void writeDescriptor() { - super.writeDescriptor(); - _subEditor.writeDescriptor(); - } + super.writeDescriptor(); + _subEditor.writeDescriptor(); + } boolean isSimpleUpdate() { - return super.isSimpleUpdate() && _subEditor.isSimpleUpdate(); + return super.isSimpleUpdate() && _subEditor.isSimpleUpdate(); } protected void appendProperties(DefaultFormBuilder builder) { - super.appendProperties(builder); - builder.appendSeparator(); - builder.nextLine(); - _subEditor.appendProperties(builder); + super.appendProperties(builder); + builder.appendSeparator(); + builder.nextLine(); + _subEditor.appendProperties(builder); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Service Template Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Service Template Properties"); } protected boolean validate() { - return super.validate() && _subEditor.validate(); + return super.validate() && _subEditor.validate(); } void show(ServiceTemplate t) { - detectUpdates(false); - _target = t; - - super.show(); - _subEditor.show(true); + detectUpdates(false); + _target = t; + + super.show(); + _subEditor.show(true); - _applyButton.setEnabled(t.isEphemeral()); - _discardButton.setEnabled(t.isEphemeral()); - detectUpdates(true); + _applyButton.setEnabled(t.isEphemeral()); + _discardButton.setEnabled(t.isEphemeral()); + detectUpdates(true); } private ServiceSubEditor _subEditor; diff --git a/java/src/IceGridGUI/Application/ServiceTemplates.java b/java/src/IceGridGUI/Application/ServiceTemplates.java index a231df74f6a..74bd639ecf3 100755 --- a/java/src/IceGridGUI/Application/ServiceTemplates.java +++ b/java/src/IceGridGUI/Application/ServiceTemplates.java @@ -23,17 +23,17 @@ class ServiceTemplates extends Templates static public java.util.Map copyDescriptors(java.util.Map descriptors) { - java.util.Map copy = new java.util.HashMap(); - java.util.Iterator p = descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - copy.put(entry.getKey(), - ServiceTemplate.copyDescriptor( - (TemplateDescriptor)entry.getValue())); - } - return copy; + java.util.Map copy = new java.util.HashMap(); + java.util.Iterator p = descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + copy.put(entry.getKey(), + ServiceTemplate.copyDescriptor( + (TemplateDescriptor)entry.getValue())); + } + return copy; } @@ -42,67 +42,67 @@ class ServiceTemplates extends Templates // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[NEW_TEMPLATE_SERVICE] = true; - - Object clipboard = getCoordinator().getClipboard(); - if(clipboard != null && clipboard instanceof TemplateDescriptor) - { - TemplateDescriptor d = (TemplateDescriptor)clipboard; - actions[PASTE] = d.descriptor instanceof ServiceDescriptor; - } - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[NEW_TEMPLATE_SERVICE] = true; + + Object clipboard = getCoordinator().getClipboard(); + if(clipboard != null && clipboard instanceof TemplateDescriptor) + { + TemplateDescriptor d = (TemplateDescriptor)clipboard; + actions[PASTE] = d.descriptor instanceof ServiceDescriptor; + } + return actions; } public JPopupMenu getPopupMenu() { - ApplicationActions actions = getCoordinator().getActionsForPopup(); - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(actions.get(NEW_TEMPLATE_SERVICE)); - } - actions.setTarget(this); - return _popup; + ApplicationActions actions = getCoordinator().getActionsForPopup(); + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(actions.get(NEW_TEMPLATE_SERVICE)); + } + actions.setTarget(this); + return _popup; } public void newTemplateService() { - ServiceDescriptor sd = new ServiceDescriptor( - new java.util.LinkedList(), - new PropertySetDescriptor(new String[0], new java.util.LinkedList()), - new java.util.LinkedList(), - new String[0], - "", - "", - ""); - - newServiceTemplate(new TemplateDescriptor(sd, new java.util.LinkedList(), new java.util.TreeMap())); + ServiceDescriptor sd = new ServiceDescriptor( + new java.util.LinkedList(), + new PropertySetDescriptor(new String[0], new java.util.LinkedList()), + new java.util.LinkedList(), + new String[0], + "", + "", + ""); + + newServiceTemplate(new TemplateDescriptor(sd, new java.util.LinkedList(), new java.util.TreeMap())); } public void paste() { - Object descriptor = getCoordinator().getClipboard(); - TemplateDescriptor td = (TemplateDescriptor)descriptor; - newServiceTemplate(td); + Object descriptor = getCoordinator().getClipboard(); + TemplateDescriptor td = (TemplateDescriptor)descriptor; + newServiceTemplate(td); } ServiceTemplates(Root parent, java.util.Map descriptors) - throws UpdateFailedException + throws UpdateFailedException { - super(parent, "Service templates"); - - _descriptors = descriptors; - - java.util.Iterator p = _descriptors.entrySet().iterator(); - - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - insertChild(new ServiceTemplate(false, this, - (String)entry.getKey(), - (TemplateDescriptor)entry.getValue()), - false); - } + super(parent, "Service templates"); + + _descriptors = descriptors; + + java.util.Iterator p = _descriptors.entrySet().iterator(); + + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + insertChild(new ServiceTemplate(false, this, + (String)entry.getKey(), + (TemplateDescriptor)entry.getValue()), + false); + } } // @@ -110,110 +110,110 @@ class ServiceTemplates extends Templates // Utils.Resolver getResolver() { - return null; + return null; } void newServiceTemplate(TemplateDescriptor descriptor) { - String id = makeNewChildId("NewServiceTemplate"); - - ServiceTemplate t = new ServiceTemplate(this, id, descriptor); - try - { - insertChild(t, true); - } - catch(UpdateFailedException e) - { - assert false; - } - getRoot().setSelectedNode(t); + String id = makeNewChildId("NewServiceTemplate"); + + ServiceTemplate t = new ServiceTemplate(this, id, descriptor); + try + { + insertChild(t, true); + } + catch(UpdateFailedException e) + { + assert false; + } + getRoot().setSelectedNode(t); } void tryAdd(String newId, TemplateDescriptor descriptor) - throws UpdateFailedException + throws UpdateFailedException { - insertChild(new ServiceTemplate(true, this, newId, descriptor), - true); - _descriptors.put(newId, descriptor); + insertChild(new ServiceTemplate(true, this, newId, descriptor), + true); + _descriptors.put(newId, descriptor); } java.util.Map getUpdates() { - java.util.Map updates = new java.util.HashMap(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServiceTemplate t = (ServiceTemplate)p.next(); - if(t.getEditable().isNew() || t.getEditable().isModified()) - { - updates.put(t.getId(), t.getDescriptor()); - } - } - return updates; + java.util.Map updates = new java.util.HashMap(); + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + ServiceTemplate t = (ServiceTemplate)p.next(); + if(t.getEditable().isNew() || t.getEditable().isModified()) + { + updates.put(t.getId(), t.getDescriptor()); + } + } + return updates; } void commit() { - _editable.commit(); - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - ServiceTemplate st = (ServiceTemplate)p.next(); - st.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 + throws UpdateFailedException { - // - // Note: _descriptors is updated by Application - // - - // - // One big set of removes - // - removeChildren(removeTemplates); - - // - // One big set of updates, followed by inserts - // - java.util.Vector newChildren = new java.util.Vector(); - java.util.Vector updatedChildren = new java.util.Vector(); - - java.util.Iterator p = descriptors.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - String name = (String)entry.getKey(); - TemplateDescriptor templateDescriptor - = (TemplateDescriptor)entry.getValue(); - ServiceTemplate child = (ServiceTemplate)findChild(name); - if(child == null) - { - newChildren.add(new ServiceTemplate(false, this, name, - templateDescriptor)); - } - else - { - child.rebuild(templateDescriptor); - updatedChildren.add(child); - } - } - - childrenChanged(updatedChildren); - insertChildren(newChildren, true); + // + // Note: _descriptors is updated by Application + // + + // + // One big set of removes + // + removeChildren(removeTemplates); + + // + // One big set of updates, followed by inserts + // + java.util.Vector newChildren = new java.util.Vector(); + java.util.Vector updatedChildren = new java.util.Vector(); + + java.util.Iterator p = descriptors.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + String name = (String)entry.getKey(); + TemplateDescriptor templateDescriptor + = (TemplateDescriptor)entry.getValue(); + ServiceTemplate child = (ServiceTemplate)findChild(name); + if(child == null) + { + newChildren.add(new ServiceTemplate(false, this, name, + templateDescriptor)); + } + else + { + child.rebuild(templateDescriptor); + updatedChildren.add(child); + } + } + + childrenChanged(updatedChildren); + insertChildren(newChildren, true); } void removeDescriptor(String id) { - _descriptors.remove(id); + _descriptors.remove(id); } Object getDescriptor() { - return _descriptors; + return _descriptors; } private java.util.Map _descriptors; diff --git a/java/src/IceGridGUI/Application/TemplateEditor.java b/java/src/IceGridGUI/Application/TemplateEditor.java index aee3bedaa15..e0557b39170 100755 --- a/java/src/IceGridGUI/Application/TemplateEditor.java +++ b/java/src/IceGridGUI/Application/TemplateEditor.java @@ -27,189 +27,189 @@ class TemplateEditor extends Editor { TemplateEditor() { - _template.getDocument().addDocumentListener(_updateListener); - _template.setToolTipText("Must be unique within the enclosing application"); + _template.getDocument().addDocumentListener(_updateListener); + _template.setToolTipText("Must be unique within the enclosing application"); - _parameters = new ParametersField(this); + _parameters = new ParametersField(this); } TemplateDescriptor getDescriptor() { - return (TemplateDescriptor)_target.getDescriptor(); + return (TemplateDescriptor)_target.getDescriptor(); } Object getSubDescriptor() { - return getDescriptor().descriptor; + return getDescriptor().descriptor; } void writeDescriptor() { - TemplateDescriptor descriptor = getDescriptor(); - java.util.LinkedList parameters = new java.util.LinkedList(); - descriptor.parameterDefaults = _parameters.get(parameters); - descriptor.parameters = parameters; - } + TemplateDescriptor descriptor = getDescriptor(); + java.util.LinkedList parameters = new java.util.LinkedList(); + descriptor.parameterDefaults = _parameters.get(parameters); + descriptor.parameters = parameters; + } boolean isSimpleUpdate() { - TemplateDescriptor descriptor = getDescriptor(); - java.util.List parameters = new java.util.LinkedList(); - java.util.Map defaultValues = _parameters.get(parameters); + TemplateDescriptor descriptor = getDescriptor(); + java.util.List parameters = new java.util.LinkedList(); + java.util.Map defaultValues = _parameters.get(parameters); - return descriptor.parameters.equals(parameters) - && descriptor.parameterDefaults.equals(defaultValues); + return descriptor.parameters.equals(parameters) + && descriptor.parameterDefaults.equals(defaultValues); } protected void appendProperties(DefaultFormBuilder builder) { - builder.append("Template ID"); - builder.append(_template, 3); - builder.nextLine(); - - builder.append("Parameters"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - - builder.nextRow(-6); - JScrollPane scrollPane = new JScrollPane(_parameters); - CellConstraints cc = new CellConstraints(); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + builder.append("Template ID"); + builder.append(_template, 3); + builder.nextLine(); + + builder.append("Parameters"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + + builder.nextRow(-6); + JScrollPane scrollPane = new JScrollPane(_parameters); + CellConstraints cc = new CellConstraints(); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); } protected boolean validate() { - return check(new String[]{"Template ID", _template.getText().trim()}); + return check(new String[]{"Template ID", _template.getText().trim()}); } void show() { - TemplateDescriptor descriptor = getDescriptor(); - _template.setText(_target.getId()); - _template.setEditable(_target.isEphemeral()); + TemplateDescriptor descriptor = getDescriptor(); + _template.setText(_target.getId()); + _template.setEditable(_target.isEphemeral()); - _parameters.set(descriptor.parameters, descriptor.parameterDefaults); + _parameters.set(descriptor.parameters, descriptor.parameterDefaults); } protected boolean applyUpdate(boolean refresh) { - Root root = _target.getRoot(); - root.disableSelectionListener(); - - try - { - if(_target.isEphemeral()) - { - writeDescriptor(); - TemplateDescriptor descriptor = getDescriptor(); - Templates parent = (Templates)_target.getParent(); - _target.destroy(); // just removes the child - - try - { - parent.tryAdd(_template.getText().trim(), descriptor); - } - catch(UpdateFailedException e) - { - // - // Re-add ephemeral child - // - try - { - parent.insertChild(_target, true); - } - catch(UpdateFailedException die) - { - assert false; - } - root.setSelectedNode(_target); - - JOptionPane.showMessageDialog( - _target.getCoordinator().getMainFrame(), - e.toString(), - "Apply failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - // - // Success - // - _target = parent.findChildWithDescriptor(descriptor); - root.updated(); - _template.setEditable(false); - if(refresh) - { - root.setSelectedNode(_target); - } - } - 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); - // - // Everything was restored, user must deal with error - // - return false; - } - - // - // Success - // - ((Communicator)_target).getEnclosingEditable().markModified(); - root.updated(); - - _target = parent.findChildWithDescriptor(getDescriptor()); - if(refresh) - { - root.setSelectedNode(_target); - } - } - - if(refresh) - { - root.getCoordinator().getCurrentTab().showNode(_target); - } - _applyButton.setEnabled(false); - _discardButton.setEnabled(false); - return true; - } - finally - { - root.enableSelectionListener(); - } + Root root = _target.getRoot(); + root.disableSelectionListener(); + + try + { + if(_target.isEphemeral()) + { + writeDescriptor(); + TemplateDescriptor descriptor = getDescriptor(); + Templates parent = (Templates)_target.getParent(); + _target.destroy(); // just removes the child + + try + { + parent.tryAdd(_template.getText().trim(), descriptor); + } + catch(UpdateFailedException e) + { + // + // Re-add ephemeral child + // + try + { + parent.insertChild(_target, true); + } + catch(UpdateFailedException die) + { + assert false; + } + root.setSelectedNode(_target); + + JOptionPane.showMessageDialog( + _target.getCoordinator().getMainFrame(), + e.toString(), + "Apply failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + // + // Success + // + _target = parent.findChildWithDescriptor(descriptor); + root.updated(); + _template.setEditable(false); + if(refresh) + { + root.setSelectedNode(_target); + } + } + 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); + // + // Everything was restored, user must deal with error + // + return false; + } + + // + // Success + // + ((Communicator)_target).getEnclosingEditable().markModified(); + root.updated(); + + _target = parent.findChildWithDescriptor(getDescriptor()); + if(refresh) + { + root.setSelectedNode(_target); + } + } + + if(refresh) + { + root.getCoordinator().getCurrentTab().showNode(_target); + } + _applyButton.setEnabled(false); + _discardButton.setEnabled(false); + return true; + } + finally + { + root.enableSelectionListener(); + } } private JTextField _template = new JTextField(20); diff --git a/java/src/IceGridGUI/Application/Templates.java b/java/src/IceGridGUI/Application/Templates.java index 15b3b652211..4dc842d1bdc 100755 --- a/java/src/IceGridGUI/Application/Templates.java +++ b/java/src/IceGridGUI/Application/Templates.java @@ -16,46 +16,46 @@ import IceGridGUI.*; abstract class Templates extends ListTreeNode { abstract void tryAdd(String newId, TemplateDescriptor descriptor) - throws UpdateFailedException; + throws UpdateFailedException; protected Templates(Root parent, String id) { - super(false, parent, id); + super(false, parent, id); } void tryUpdate(Communicator child) - throws UpdateFailedException + throws UpdateFailedException { - java.util.List instanceList = child.findInstances(); - java.util.List backupList = new java.util.Vector(); + java.util.List instanceList = child.findInstances(); + java.util.List backupList = new java.util.Vector(); - java.util.List editables = new java.util.LinkedList(); + java.util.List editables = new java.util.LinkedList(); - java.util.Iterator p = instanceList.iterator(); - while(p.hasNext()) - { - TemplateInstance instance = (TemplateInstance)p.next(); - - try - { - backupList.add(instance.rebuild(editables)); - } - catch(UpdateFailedException e) - { - for(int i = backupList.size() - 1; i >= 0; --i) - { - instance = (TemplateInstance)instanceList.get(i); - instance.restore(backupList.get(i)); - } - throw e; - } - } - - p = editables.iterator(); - while(p.hasNext()) - { - Editable editable = (Editable)p.next(); - editable.markModified(); - } + java.util.Iterator p = instanceList.iterator(); + while(p.hasNext()) + { + TemplateInstance instance = (TemplateInstance)p.next(); + + try + { + backupList.add(instance.rebuild(editables)); + } + catch(UpdateFailedException e) + { + for(int i = backupList.size() - 1; i >= 0; --i) + { + instance = (TemplateInstance)instanceList.get(i); + instance.restore(backupList.get(i)); + } + throw e; + } + } + + p = editables.iterator(); + while(p.hasNext()) + { + Editable editable = (Editable)p.next(); + editable.markModified(); + } } } diff --git a/java/src/IceGridGUI/Application/TreeNode.java b/java/src/IceGridGUI/Application/TreeNode.java index ec5a2de73fa..8c8d6582b04 100755 --- a/java/src/IceGridGUI/Application/TreeNode.java +++ b/java/src/IceGridGUI/Application/TreeNode.java @@ -30,7 +30,7 @@ public abstract class TreeNode extends TreeNodeBase // public boolean isEphemeral() { - return false; + return false; } // @@ -38,26 +38,26 @@ public abstract class TreeNode extends TreeNodeBase // public void destroy() { - assert false; + assert false; } TreeNode(TreeNode parent, String id) { - super(parent, id); + super(parent, id); } public Root getRoot() { - assert _parent != null; - return ((TreeNode)_parent).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()); + // + // Default implementation just use id; not always appropriate + // + return (TreeNode)findChild(other.getId()); } // @@ -65,14 +65,14 @@ public abstract class TreeNode extends TreeNodeBase // Utils.Resolver getResolver() { - if(isEphemeral()) - { - return null; - } - else - { - return ((TreeNode)_parent).getResolver(); - } + if(isEphemeral()) + { + return null; + } + else + { + return ((TreeNode)_parent).getResolver(); + } } // @@ -80,266 +80,266 @@ public abstract class TreeNode extends TreeNodeBase // TreeNode findChildWithDescriptor(Object descriptor) { - Enumeration p = children(); - while(p.hasMoreElements()) - { - TreeNode node = (TreeNode)p.nextElement(); - if(node.getDescriptor() == descriptor) - { - return node; - } - } - return null; + 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}; + return new String[]{name, value}; } static void writeVariables(XMLWriter writer, - java.util.Map variables) - throws java.io.IOException + java.util.Map 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())); + 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); - } + writer.writeElement("variable", attributes); + } } static void writePropertySet(XMLWriter writer, PropertySetDescriptor psd, - java.util.List adapters, String[] logs) - throws java.io.IOException + java.util.List adapters, String[] logs) + throws java.io.IOException { - writePropertySet(writer, "", "", psd, adapters, logs); + writePropertySet(writer, "", "", psd, adapters, logs); } static void writePropertySet(XMLWriter writer, String id, String idAttrName, - PropertySetDescriptor psd, - java.util.List adapters, String[] logs) - throws java.io.IOException - { - if(id.length() == 0 && psd.references.length == 0 && psd.properties.size() == 0) - { - return; - } - - // - // We don't show the .Endpoint of adapters, - // since they already appear in the Adapter descriptors - // - java.util.Set hiddenPropertyNames = new java.util.HashSet(); - java.util.Set hiddenPropertyValues = new java.util.HashSet(); - - if(adapters != null) - { - java.util.Iterator p = adapters.iterator(); - while(p.hasNext()) - { - AdapterDescriptor ad = (AdapterDescriptor)p.next(); - hiddenPropertyNames.add("Ice.OA." + ad.name + ".Endpoints"); - - java.util.Iterator q = ad.objects.iterator(); - while(q.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)q.next(); - hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); - } - q = ad.allocatables.iterator(); - while(q.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)q.next(); - hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); - } - } - } - - if(logs != null) - { - for(int i = 0; i < logs.length; ++i) - { - hiddenPropertyValues.add(logs[i]); - } - } - - java.util.List attributes = new java.util.LinkedList(); - if(id.length() > 0) - { - attributes.add(createAttribute(idAttrName, id)); - } - if(psd.references.length == 0 && psd.properties.size() == 0) - { - writer.writeElement("properties", attributes); - } - else - { - writer.writeStartTag("properties", attributes); - - for(int i = 0; i < psd.references.length; ++i) - { - attributes.clear(); - attributes.add(createAttribute("refid", psd.references[i])); - writer.writeElement("properties", attributes); - } - - java.util.Iterator p = psd.properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(hiddenPropertyNames.contains(pd.name)) - { - // - // We hide only the first occurence - // - hiddenPropertyNames.remove(pd.name); - } - else if(hiddenPropertyValues.contains(pd.value)) - { - hiddenPropertyValues.remove(pd.value); - } - else - { - attributes.clear(); - attributes.add(createAttribute("name", pd.name)); - attributes.add(createAttribute("value", pd.value)); - writer.writeElement("property", attributes); - } - } - writer.writeEndTag("properties"); - } + PropertySetDescriptor psd, + java.util.List adapters, String[] logs) + throws java.io.IOException + { + if(id.length() == 0 && psd.references.length == 0 && psd.properties.size() == 0) + { + return; + } + + // + // We don't show the .Endpoint of adapters, + // since they already appear in the Adapter descriptors + // + java.util.Set hiddenPropertyNames = new java.util.HashSet(); + java.util.Set hiddenPropertyValues = new java.util.HashSet(); + + if(adapters != null) + { + java.util.Iterator p = adapters.iterator(); + while(p.hasNext()) + { + AdapterDescriptor ad = (AdapterDescriptor)p.next(); + hiddenPropertyNames.add("Ice.OA." + ad.name + ".Endpoints"); + + java.util.Iterator q = ad.objects.iterator(); + while(q.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)q.next(); + hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); + } + q = ad.allocatables.iterator(); + while(q.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)q.next(); + hiddenPropertyValues.add(Ice.Util.identityToString(od.id)); + } + } + } + + if(logs != null) + { + for(int i = 0; i < logs.length; ++i) + { + hiddenPropertyValues.add(logs[i]); + } + } + + java.util.List attributes = new java.util.LinkedList(); + if(id.length() > 0) + { + attributes.add(createAttribute(idAttrName, id)); + } + if(psd.references.length == 0 && psd.properties.size() == 0) + { + writer.writeElement("properties", attributes); + } + else + { + writer.writeStartTag("properties", attributes); + + for(int i = 0; i < psd.references.length; ++i) + { + attributes.clear(); + attributes.add(createAttribute("refid", psd.references[i])); + writer.writeElement("properties", attributes); + } + + java.util.Iterator p = psd.properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(hiddenPropertyNames.contains(pd.name)) + { + // + // We hide only the first occurence + // + hiddenPropertyNames.remove(pd.name); + } + else if(hiddenPropertyValues.contains(pd.value)) + { + hiddenPropertyValues.remove(pd.value); + } + else + { + attributes.clear(); + attributes.add(createAttribute("name", pd.name)); + attributes.add(createAttribute("value", pd.value)); + writer.writeElement("property", attributes); + } + } + writer.writeEndTag("properties"); + } } static void writeLogs(XMLWriter writer, String[] logs, java.util.List properties) - throws java.io.IOException + throws java.io.IOException { - for(int i = 0; i < logs.length; ++i) - { - java.util.List attributes = new java.util.LinkedList(); - attributes.add(createAttribute("path", logs[i])); - String prop = lookupName(logs[i], properties); - if(prop != null) - { - attributes.add(createAttribute("property", prop)); - } - writer.writeElement("log", attributes); - } + for(int i = 0; i < logs.length; ++i) + { + java.util.List attributes = new java.util.LinkedList(); + attributes.add(createAttribute("path", logs[i])); + String prop = lookupName(logs[i], properties); + if(prop != null) + { + attributes.add(createAttribute("property", prop)); + } + writer.writeElement("log", attributes); + } } static String lookupName(String val, java.util.List properties) { - java.util.Iterator p = properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - if(pd.value.equals(val)) - { - return pd.name; - } - } - return null; + java.util.Iterator p = properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + if(pd.value.equals(val)) + { + return pd.name; + } + } + return null; } 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"); - } - } + 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(String elt, XMLWriter writer, java.util.List objects, - java.util.List properties) - 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(); - String strId = Ice.Util.identityToString(od.id); - attributes.add(createAttribute("identity", strId)); - if(od.type.length() > 0) - { - attributes.add(createAttribute("type", od.type)); - } - if(properties != null) - { - String prop = lookupName(strId, properties); - if(prop != null) - { - attributes.add(createAttribute("property", prop)); - } - } - - writer.writeElement(elt, attributes); - } - } + java.util.List properties) + 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(); + String strId = Ice.Util.identityToString(od.id); + attributes.add(createAttribute("identity", strId)); + if(od.type.length() > 0) + { + attributes.add(createAttribute("type", od.type)); + } + if(properties != null) + { + String prop = lookupName(strId, properties); + if(prop != null) + { + attributes.add(createAttribute("property", prop)); + } + } + + writer.writeElement(elt, attributes); + } + } static void writeParameters(XMLWriter writer, java.util.List parameters, - java.util.Map defaultValues) - throws java.io.IOException - { - java.util.Iterator p = new java.util.LinkedHashSet(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); - } + java.util.Map defaultValues) + throws java.io.IOException + { + java.util.Iterator p = new java.util.LinkedHashSet(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(); - - // - // We use a LinkedHashSet to maintain order while eliminating duplicates - // - java.util.Iterator p = new java.util.LinkedHashSet(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; + java.util.List parameters) + { + java.util.LinkedList result = new java.util.LinkedList(); + + // + // We use a LinkedHashSet to maintain order while eliminating duplicates + // + java.util.Iterator p = new java.util.LinkedHashSet(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; } // @@ -373,94 +373,94 @@ public abstract class TreeNode extends TreeNodeBase public boolean[] getAvailableActions() { - return new boolean[ACTION_COUNT]; + return new boolean[ACTION_COUNT]; } public void newAdapter() { - assert false; + assert false; } public void newDbEnv() { - assert false; + assert false; } public void newNode() { - assert false; + assert false; } public void newPropertySet() { - assert false; + assert false; } public void newReplicaGroup() { - assert false; + assert false; } public void newServer() { - assert false; + assert false; } public void newServerIceBox() { - assert false; + assert false; } public void newServerFromTemplate() { - assert false; + assert false; } public void newService() { - assert false; + assert false; } public void newServiceFromTemplate() { - assert false; + assert false; } public void newTemplateServer() { - assert false; + assert false; } public void newTemplateServerIceBox() { - assert false; + assert false; } public void newTemplateService() { - assert false; + assert false; } public void copy() { - assert false; + assert false; } public void paste() { - assert false; + assert false; } public void delete() { - boolean enabled = getRoot().isSelectionListenerEnabled(); + boolean enabled = getRoot().isSelectionListenerEnabled(); - if(enabled) - { - getRoot().disableSelectionListener(); - } - destroy(); - getCoordinator().getCurrentTab().showNode(null); - if(enabled) - { - getRoot().enableSelectionListener(); - } + if(enabled) + { + getRoot().disableSelectionListener(); + } + destroy(); + getCoordinator().getCurrentTab().showNode(null); + if(enabled) + { + getRoot().enableSelectionListener(); + } - if(_parent != null) - { - getRoot().setSelectedNode((TreeNode)_parent); - } + if(_parent != null) + { + getRoot().setSelectedNode((TreeNode)_parent); + } } public void moveUp() { - assert false; + assert false; } public void moveDown() { - assert false; + assert false; } } diff --git a/java/src/IceGridGUI/Application/UpdateFailedException.java b/java/src/IceGridGUI/Application/UpdateFailedException.java index 6c79d5c1524..c59d580f7df 100755 --- a/java/src/IceGridGUI/Application/UpdateFailedException.java +++ b/java/src/IceGridGUI/Application/UpdateFailedException.java @@ -12,13 +12,13 @@ public class UpdateFailedException extends Exception { UpdateFailedException(TreeNode parent, String id) { - _parent = parent; - _id = id; + _parent = parent; + _id = id; } public String toString() { - return _parent.getFullId().toString() + " has already a child with '" + _id + "' as ID."; + return _parent.getFullId().toString() + " has already a child with '" + _id + "' as ID."; } private TreeNode _parent; diff --git a/java/src/IceGridGUI/ApplicationActions.java b/java/src/IceGridGUI/ApplicationActions.java index e02013b6f78..e2dfef3f538 100755 --- a/java/src/IceGridGUI/ApplicationActions.java +++ b/java/src/IceGridGUI/ApplicationActions.java @@ -26,273 +26,273 @@ public class ApplicationActions { public Action get(int index) { - return _array[index]; + return _array[index]; } public boolean[] setTarget(TreeNode target) { - _target = target; + _target = target; - boolean[] availableActions; - if(_target == null) - { - availableActions = new boolean[TreeNode.ACTION_COUNT]; - } - else - { - availableActions = _target.getAvailableActions(); - } + 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]); - } + for(int i = 0; i < _array.length; ++i) + { + _array[i].setEnabled(availableActions[i]); + } - return availableActions; + return availableActions; } ApplicationActions(boolean popup) { - final int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + final int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - _array[TreeNode.NEW_ADAPTER] = new AbstractAction( - popup ? "New Adapter" : "Adapter") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newAdapter(); - } - } - }; + _array[TreeNode.NEW_ADAPTER] = new AbstractAction( + popup ? "New Adapter" : "Adapter") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newAdapter(); + } + } + }; - _array[TreeNode.NEW_DBENV] = new AbstractAction( - popup ? "New Database Environment" : "Database Environment") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newDbEnv(); - } - } - }; - - _array[TreeNode.NEW_NODE] = new AbstractAction( - popup ? "New Node" : "Node") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newNode(); - } - } - }; + _array[TreeNode.NEW_DBENV] = new AbstractAction( + popup ? "New Database Environment" : "Database Environment") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newDbEnv(); + } + } + }; + + _array[TreeNode.NEW_NODE] = new AbstractAction( + popup ? "New Node" : "Node") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newNode(); + } + } + }; - _array[TreeNode.NEW_PROPERTY_SET] = new AbstractAction( - popup ? "New Property Set" : "Property Set") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newPropertySet(); - } - } - }; + _array[TreeNode.NEW_PROPERTY_SET] = new AbstractAction( + popup ? "New Property Set" : "Property Set") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newPropertySet(); + } + } + }; - _array[TreeNode.NEW_REPLICA_GROUP] = new AbstractAction( - popup ? "New Replica Group" : "Replica Group" ) - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newReplicaGroup(); - } - } - }; + _array[TreeNode.NEW_REPLICA_GROUP] = new AbstractAction( + popup ? "New Replica Group" : "Replica Group" ) + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newReplicaGroup(); + } + } + }; - _array[TreeNode.NEW_SERVER] = new AbstractAction( - popup ? "New Server" : "Server") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newServer(); - } - } - }; + _array[TreeNode.NEW_SERVER] = new AbstractAction( + popup ? "New Server" : "Server") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newServer(); + } + } + }; - _array[TreeNode.NEW_SERVER_ICEBOX] = new AbstractAction( - popup ? "New IceBox Server" : "IceBox Server") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newServerIceBox(); - } - } - }; + _array[TreeNode.NEW_SERVER_ICEBOX] = new AbstractAction( + popup ? "New IceBox Server" : "IceBox Server") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newServerIceBox(); + } + } + }; - _array[TreeNode.NEW_SERVER_FROM_TEMPLATE] = new AbstractAction( - popup ? "New Server from Template" : "Server from Template") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newServerFromTemplate(); - } - } - }; + _array[TreeNode.NEW_SERVER_FROM_TEMPLATE] = new AbstractAction( + popup ? "New Server from Template" : "Server from Template") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newServerFromTemplate(); + } + } + }; - _array[TreeNode.NEW_SERVICE] = new AbstractAction( - popup ? "New Service" : "Service") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newService(); - } - } - }; + _array[TreeNode.NEW_SERVICE] = new AbstractAction( + popup ? "New Service" : "Service") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newService(); + } + } + }; - _array[TreeNode.NEW_SERVICE_FROM_TEMPLATE] = new AbstractAction( - popup ? "New Service from Template" : "Service from Template") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newServiceFromTemplate(); - } - } - }; + _array[TreeNode.NEW_SERVICE_FROM_TEMPLATE] = new AbstractAction( + popup ? "New Service from Template" : "Service from Template") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newServiceFromTemplate(); + } + } + }; - _array[TreeNode.NEW_TEMPLATE_SERVER] = new AbstractAction( - popup ? "New Server Template" : "Server Template") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newTemplateServer(); - } - } - }; - - _array[TreeNode.NEW_TEMPLATE_SERVER_ICEBOX] = new AbstractAction( - popup ? "New IceBox Server Template" : "IceBox Server Template") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newTemplateServerIceBox(); - } - } - }; + _array[TreeNode.NEW_TEMPLATE_SERVER] = new AbstractAction( + popup ? "New Server Template" : "Server Template") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newTemplateServer(); + } + } + }; + + _array[TreeNode.NEW_TEMPLATE_SERVER_ICEBOX] = new AbstractAction( + popup ? "New IceBox Server Template" : "IceBox Server Template") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newTemplateServerIceBox(); + } + } + }; - _array[TreeNode.NEW_TEMPLATE_SERVICE] = new AbstractAction( - popup ? "New Service Template" : "Service Template") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.newTemplateService(); - } - } - }; - - _array[TreeNode.COPY] = new AbstractAction("Copy") - { - public void actionPerformed(ActionEvent e) - { - _target.copy(); - } - }; - - _array[TreeNode.PASTE] = new AbstractAction("Paste") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.paste(); - } - } - }; - - _array[TreeNode.DELETE] = new AbstractAction("Delete") - { - public void actionPerformed(ActionEvent e) - { - _target.delete(); - } - }; + _array[TreeNode.NEW_TEMPLATE_SERVICE] = new AbstractAction( + popup ? "New Service Template" : "Service Template") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.newTemplateService(); + } + } + }; + + _array[TreeNode.COPY] = new AbstractAction("Copy") + { + public void actionPerformed(ActionEvent e) + { + _target.copy(); + } + }; + + _array[TreeNode.PASTE] = new AbstractAction("Paste") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.paste(); + } + } + }; + + _array[TreeNode.DELETE] = new AbstractAction("Delete") + { + public void actionPerformed(ActionEvent e) + { + _target.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.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.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) - { - if(apply(_target)) - { - _target.moveUp(); - } - } - }; - - _array[TreeNode.MOVE_DOWN] = new AbstractAction("Move Down") - { - public void actionPerformed(ActionEvent e) - { - if(apply(_target)) - { - _target.moveDown(); - } - } - }; + + _array[TreeNode.MOVE_UP] = new AbstractAction("Move Up") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.moveUp(); + } + } + }; + + _array[TreeNode.MOVE_DOWN] = new AbstractAction("Move Down") + { + public void actionPerformed(ActionEvent e) + { + if(apply(_target)) + { + _target.moveDown(); + } + } + }; } static private boolean apply(TreeNode target) { - return target.getRoot().getPane().applyUpdates(false); + return target.getRoot().getPane().applyUpdates(false); } diff --git a/java/src/IceGridGUI/ApplicationObserverI.java b/java/src/IceGridGUI/ApplicationObserverI.java index de68d100dae..835c235b17e 100644 --- a/java/src/IceGridGUI/ApplicationObserverI.java +++ b/java/src/IceGridGUI/ApplicationObserverI.java @@ -16,9 +16,9 @@ class ApplicationObserverI extends _ApplicationObserverDisp ApplicationObserverI(String instanceName, Coordinator coordinator) { - _instanceName = instanceName; - _coordinator = coordinator; - _trace = coordinator.traceObservers(); + _instanceName = instanceName; + _coordinator = coordinator; + _trace = coordinator.traceObservers(); } // @@ -26,120 +26,120 @@ class ApplicationObserverI extends _ApplicationObserverDisp // synchronized void waitForInit() { - // - // TODO: configurable timeout - // - long timeout = 10000; - - if(!_initialized) - { - try - { - wait(timeout); - } - catch(InterruptedException e) - { - } - } - - if(_initialized) - { - _coordinator.applicationInit(_instanceName, _serial, _applications); - } - else - { - throw new Ice.TimeoutException(); - } + // + // TODO: configurable timeout + // + long timeout = 10000; + + if(!_initialized) + { + try + { + wait(timeout); + } + catch(InterruptedException e) + { + } + } + + if(_initialized) + { + _coordinator.applicationInit(_instanceName, _serial, _applications); + } + else + { + throw new Ice.TimeoutException(); + } } public synchronized void applicationInit(int serial, java.util.List applications, Ice.Current current) { - if(_trace) - { - if(applications.size() == 0) - { - _coordinator.traceObserver("applicationInit (no application);" - + "serial is " + serial); - } - else - { - String names = ""; - java.util.Iterator p = applications.iterator(); - while(p.hasNext()) - { - names += " " + ((ApplicationInfo)p.next()).descriptor.name; - } - - _coordinator.traceObserver("applicationInit for application" - + (applications.size() == 1 ? "" : "s") - + names - + "; serial is " + serial); - } - } - - _initialized = true; - _serial = serial; - - _applications = applications; - - notify(); + if(_trace) + { + if(applications.size() == 0) + { + _coordinator.traceObserver("applicationInit (no application);" + + "serial is " + serial); + } + else + { + String names = ""; + java.util.Iterator p = applications.iterator(); + while(p.hasNext()) + { + names += " " + ((ApplicationInfo)p.next()).descriptor.name; + } + + _coordinator.traceObserver("applicationInit for application" + + (applications.size() == 1 ? "" : "s") + + names + + "; serial is " + serial); + } + } + + _initialized = true; + _serial = serial; + + _applications = applications; + + notify(); } public void applicationAdded(final int serial, final ApplicationInfo info, - Ice.Current current) + Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("applicationAdded for application " - + info.descriptor.name - + "; serial is " + serial); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.applicationAdded(serial, info); - } - }); + if(_trace) + { + _coordinator.traceObserver("applicationAdded for application " + + info.descriptor.name + + "; serial is " + serial); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.applicationAdded(serial, info); + } + }); } public void applicationRemoved(final int serial, final String name, - final Ice.Current current) + final Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("applicationRemoved for application " - + name - + "; serial is " + serial); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.applicationRemoved(serial, name); - } - }); + if(_trace) + { + _coordinator.traceObserver("applicationRemoved for application " + + name + + "; serial is " + serial); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.applicationRemoved(serial, name); + } + }); } public void applicationUpdated(final int serial, final ApplicationUpdateInfo info, - Ice.Current current) + Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("applicationUpdated for application " - + info.descriptor.name - + "; serial is " + serial); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.applicationUpdated(serial, info); - } - }); + if(_trace) + { + _coordinator.traceObserver("applicationUpdated for application " + + info.descriptor.name + + "; serial is " + serial); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.applicationUpdated(serial, info); + } + }); } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/ApplicationPane.java b/java/src/IceGridGUI/ApplicationPane.java index 6083ceb2a07..ce94c432ad3 100755 --- a/java/src/IceGridGUI/ApplicationPane.java +++ b/java/src/IceGridGUI/ApplicationPane.java @@ -40,174 +40,174 @@ public class ApplicationPane extends JSplitPane implements Tab { public void updateUI() { - super.updateUI(); - setEmptyDividerBorder(); + super.updateUI(); + setEmptyDividerBorder(); } public void selected() { - Coordinator c = _root.getCoordinator(); - - c.getCloseApplicationAction().setEnabled(true); - - c.getSaveAction().setEnabled(_root.needsSaving() && (_root.isLive() && c.connectedToMaster() || _root.hasFile())); - c.getDiscardUpdatesAction().setEnabled(_root.needsSaving() && (_root.isLive() || _root.hasFile())); - - if(_root.isLive()) - { - c.getSaveToRegistryAction().setEnabled(_root.needsSaving() && c.connectedToMaster()); - } - else - { - c.getSaveToRegistryAction().setEnabled(c.connectedToMaster()); - } - c.getSaveToFileAction().setEnabled(true); - - - c.getBackAction().setEnabled(_previousNodes.size() > 0); - c.getForwardAction().setEnabled(_nextNodes.size() > 0); - c.showActions(_currentNode); + Coordinator c = _root.getCoordinator(); + + c.getCloseApplicationAction().setEnabled(true); + + c.getSaveAction().setEnabled(_root.needsSaving() && (_root.isLive() && c.connectedToMaster() || _root.hasFile())); + c.getDiscardUpdatesAction().setEnabled(_root.needsSaving() && (_root.isLive() || _root.hasFile())); + + if(_root.isLive()) + { + c.getSaveToRegistryAction().setEnabled(_root.needsSaving() && c.connectedToMaster()); + } + else + { + c.getSaveToRegistryAction().setEnabled(c.connectedToMaster()); + } + c.getSaveToFileAction().setEnabled(true); + + + c.getBackAction().setEnabled(_previousNodes.size() > 0); + c.getForwardAction().setEnabled(_nextNodes.size() > 0); + c.showActions(_currentNode); } public void refresh() { - if(_currentNode != null) - { - _currentEditor = _currentNode.getEditor(); - if(_root.getCoordinator().getCurrentTab() == this) - { - // - // Refresh actions as well - // - _root.getCoordinator().showActions(_currentNode); - } - } + if(_currentNode != null) + { + _currentEditor = _currentNode.getEditor(); + if(_root.getCoordinator().getCurrentTab() == this) + { + // + // Refresh actions as well + // + _root.getCoordinator().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 - { - _currentEditor = _currentNode.getEditor(); - if(_root.getCoordinator().getCurrentTab() == this) - { - // - // Refresh actions as well - // - _root.getCoordinator().showActions(_currentNode); - } - } + 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 + { + _currentEditor = _currentNode.getEditor(); + if(_root.getCoordinator().getCurrentTab() == this) + { + // + // Refresh actions as well + // + _root.getCoordinator().showActions(_currentNode); + } + } } public void back() { - // - // Auto-apply changes - // - if(_currentEditor != null && !_currentEditor.save(false)) - { - return; - } - - 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(); - } + // + // Auto-apply changes + // + if(_currentEditor != null && !_currentEditor.save(false)) + { + return; + } + + 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() { - if(_currentEditor != null && !_currentEditor.save(false)) - { - return; - } - - 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(); - } + if(_currentEditor != null && !_currentEditor.save(false)) + { + return; + } + + 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; + return _root; } // @@ -215,259 +215,259 @@ public class ApplicationPane extends JSplitPane implements Tab // public void setRoot(Root newRoot) { - boolean reset = (_root != null); - - if(reset) - { - ToolTipManager.sharedInstance().unregisterComponent(_root.getTree()); - _currentNode = null; - _previousNodes.clear(); - _nextNodes.clear(); - } - - _root = newRoot; - _root.setPane(this); - - // - // 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(); - } + boolean reset = (_root != null); + + if(reset) + { + ToolTipManager.sharedInstance().unregisterComponent(_root.getTree()); + _currentNode = null; + _previousNodes.clear(); + _nextNodes.clear(); + } + + _root = newRoot; + _root.setPane(this); + + // + // 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() { - if(_currentEditor == null || _currentEditor.save(true)) - { - _root.save(); - } + if(_currentEditor == null || _currentEditor.save(true)) + { + _root.save(); + } } public void saveToRegistry() { - if(_currentEditor == null || _currentEditor.save(true)) - { - _root.saveToRegistry(); - } + if(_currentEditor == null || _currentEditor.save(true)) + { + _root.saveToRegistry(); + } } public void saveToFile() { - if(_currentEditor == null || _currentEditor.save(true)) - { - _root.saveToFile(); - } + if(_currentEditor == null || _currentEditor.save(true)) + { + _root.saveToFile(); + } } public void discardUpdates() { - _root.discardUpdates(); + _root.discardUpdates(); } public boolean close() { - _root.getCoordinator().getMainPane().remove(this); - return true; + _root.getCoordinator().getMainPane().remove(this); + return true; } public boolean applyUpdates(boolean refresh) { - if(_currentEditor == null) - { - return true; - } - else - { - return _currentEditor.save(refresh); - } + if(_currentEditor == null) + { + return true; + } + else + { + return _currentEditor.save(refresh); + } } private void registerAction(Coordinator c, int index) { - Action action = c.getActionsForMenu().get(index); + Action action = c.getActionsForMenu().get(index); - javax.swing.ActionMap am = _leftPane.getActionMap(); - javax.swing.InputMap im = _leftPane.getInputMap(); + javax.swing.ActionMap am = _leftPane.getActionMap(); + javax.swing.InputMap im = _leftPane.getInputMap(); - im.put((KeyStroke)action.getValue(Action.ACCELERATOR_KEY), (String)action.getValue(Action.NAME)); - am.put((String)action.getValue(Action.NAME), action); + im.put((KeyStroke)action.getValue(Action.ACCELERATOR_KEY), (String)action.getValue(Action.NAME)); + am.put((String)action.getValue(Action.NAME), action); } 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)); - Coordinator c = root.getCoordinator(); - registerAction(c, TreeNode.COPY); - registerAction(c, TreeNode.PASTE); - registerAction(c, TreeNode.DELETE); - - // - // Right pane - // - _propertiesFrame = new SimpleInternalFrame("Properties"); - - setLeftComponent(_leftPane); - setRightComponent(_propertiesFrame); - - setRoot(root); + super(JSplitPane.HORIZONTAL_SPLIT, true); + setBorder(new EmptyBorder(10, 10, 10, 10)); + + _leftPane = new SimpleInternalFrame("Descriptors"); + _leftPane.setPreferredSize(new Dimension(280, 350)); + Coordinator c = root.getCoordinator(); + registerAction(c, TreeNode.COPY); + registerAction(c, TreeNode.PASTE); + registerAction(c, TreeNode.DELETE); + + // + // Right pane + // + _propertiesFrame = new SimpleInternalFrame("Properties"); + + setLeftComponent(_leftPane); + setRightComponent(_propertiesFrame); + + setRoot(root); } 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); - _currentEditor = null; - } - else - { - _currentEditor = _currentNode.getEditor(); - Component currentProperties = _currentEditor.getProperties(); - _propertiesFrame.setContent(currentProperties); - _propertiesFrame.setTitle(currentProperties.getName()); - _propertiesFrame.setToolBar(_currentEditor.getToolBar()); - } - _propertiesFrame.validate(); - _propertiesFrame.repaint(); + _root.getCoordinator().showActions(_currentNode); + + if(_currentNode == null) + { + Component oldContent = _propertiesFrame.getContent(); + if(oldContent != null) + { + _propertiesFrame.remove(oldContent); + } + _propertiesFrame.setTitle("Properties"); + _propertiesFrame.setToolBar(null); + _currentEditor = null; + } + else + { + _currentEditor = _currentNode.getEditor(); + Component currentProperties = _currentEditor.getProperties(); + _propertiesFrame.setContent(currentProperties); + _propertiesFrame.setTitle(currentProperties.getName()); + _propertiesFrame.setToolBar(_currentEditor.getToolBar()); + } + _propertiesFrame.validate(); + _propertiesFrame.repaint(); } private void setEmptyDividerBorder() { - SplitPaneUI splitPaneUI = getUI(); - if(splitPaneUI instanceof BasicSplitPaneUI) - { - BasicSplitPaneUI basicUI = (BasicSplitPaneUI)splitPaneUI; - basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder()); - } + 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()); - } - } - } - } + 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()) - { - // - // Auto-apply changes - // - if(_currentEditor != null && !_currentEditor.save(false)) - { - // - // Go back to this path - // - _root.disableSelectionListener(); - _root.setSelectedNode(_currentEditor.getTarget()); - _root.enableSelectionListener(); - } - else - { - if(e.isAddedPath()) - { - TreePath path = e.getPath(); - - if(path == null) - { - showNode(null); - } - else - { - TreeNode node = (TreeNode)path.getLastPathComponent(); - Root root = node.getRoot(); - if(root.hasNode(node)) - { - showNode(node); - } - else - { - node = root.findNodeLike(path, false); - if(node == null) - { - node = root; - } - root.setSelectedNode(node); - } - } - } - else - { - showNode(null); - } - } - } - } + public void valueChanged(TreeSelectionEvent e) + { + if(_root.isSelectionListenerEnabled()) + { + // + // Auto-apply changes + // + if(_currentEditor != null && !_currentEditor.save(false)) + { + // + // Go back to this path + // + _root.disableSelectionListener(); + _root.setSelectedNode(_currentEditor.getTarget()); + _root.enableSelectionListener(); + } + else + { + if(e.isAddedPath()) + { + TreePath path = e.getPath(); + + if(path == null) + { + showNode(null); + } + else + { + TreeNode node = (TreeNode)path.getLastPathComponent(); + Root root = node.getRoot(); + if(root.hasNode(node)) + { + showNode(node); + } + else + { + node = root.findNodeLike(path, false); + if(node == null) + { + node = root; + } + root.setSelectedNode(node); + } + } + } + else + { + showNode(null); + } + } + } + } } private Root _root; diff --git a/java/src/IceGridGUI/BareBonesBrowserLaunch.java b/java/src/IceGridGUI/BareBonesBrowserLaunch.java index eab9ab4e085..f2679e4d5f8 100755 --- a/java/src/IceGridGUI/BareBonesBrowserLaunch.java +++ b/java/src/IceGridGUI/BareBonesBrowserLaunch.java @@ -23,32 +23,32 @@ public class BareBonesBrowserLaunch { private static final String errMsg = "Error attempting to launch web browser"; public static void openURL(String url) { - String osName = System.getProperty("os.name"); - try { - if (osName.startsWith("Mac OS")) { - Class macUtils = Class.forName("com.apple.mrj.MRJFileUtils"); - Method openURL = macUtils.getDeclaredMethod("openURL", - new Class[] {String.class}); - openURL.invoke(null, new Object[] {url}); + String osName = System.getProperty("os.name"); + try { + if (osName.startsWith("Mac OS")) { + Class macUtils = Class.forName("com.apple.mrj.MRJFileUtils"); + Method openURL = macUtils.getDeclaredMethod("openURL", + new Class[] {String.class}); + openURL.invoke(null, new Object[] {url}); } - else if (osName.startsWith("Windows")) - Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); - else { //assume Unix or Linux - String[] browsers = { - "firefox", "opera", "konqueror", "mozilla", "netscape" }; - String browser = null; - for (int count = 0; count < browsers.length && browser == null; count++) - if (Runtime.getRuntime().exec( - new String[] {"which", browsers[count]}).waitFor() == 0) - browser = browsers[count]; - if (browser == null) - throw new Exception("Could not find web browser."); - else - Runtime.getRuntime().exec(new String[] {browser, url}); + else if (osName.startsWith("Windows")) + Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); + else { //assume Unix or Linux + String[] browsers = { + "firefox", "opera", "konqueror", "mozilla", "netscape" }; + String browser = null; + for (int count = 0; count < browsers.length && browser == null; count++) + if (Runtime.getRuntime().exec( + new String[] {"which", browsers[count]}).waitFor() == 0) + browser = browsers[count]; + if (browser == null) + throw new Exception("Could not find web browser."); + else + Runtime.getRuntime().exec(new String[] {browser, url}); } - } - catch (Exception e) { - JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); - } + } + catch (Exception e) { + JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage()); + } } } diff --git a/java/src/IceGridGUI/CellRenderer.java b/java/src/IceGridGUI/CellRenderer.java index bffee029157..e6135a8f641 100755 --- a/java/src/IceGridGUI/CellRenderer.java +++ b/java/src/IceGridGUI/CellRenderer.java @@ -16,24 +16,24 @@ import javax.swing.tree.DefaultTreeCellRenderer; class CellRenderer implements TreeCellRenderer { public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { - TreeCellRenderer node = (TreeCellRenderer)value; - Component result = node.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + TreeCellRenderer node = (TreeCellRenderer)value; + Component result = node.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); - if(result == null) - { - result = _defaultRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); - } - return result; + if(result == null) + { + result = _defaultRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); + } + return result; } private TreeCellRenderer _defaultRenderer = new DefaultTreeCellRenderer(); diff --git a/java/src/IceGridGUI/Coordinator.java b/java/src/IceGridGUI/Coordinator.java index 023a75bdb02..0d86c583d83 100755 --- a/java/src/IceGridGUI/Coordinator.java +++ b/java/src/IceGridGUI/Coordinator.java @@ -74,571 +74,571 @@ 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; + 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 ActionWrapper extends AbstractAction implements java.beans.PropertyChangeListener { - public ActionWrapper(String name) - { - super(name); - setEnabled(false); - } - - public void actionPerformed(ActionEvent e) - { - if(_target != null) - { - _target.actionPerformed(e); - } - } - - public void propertyChange(java.beans.PropertyChangeEvent e) - { - // - // The only property we're interested in is isEnabled - // - - java.beans.PropertyChangeListener[] l = getPropertyChangeListeners(); - for(int i = 0; i < l.length; ++i) - { - l[i].propertyChange(e); - } - } - - void setTarget(Action t) - { - if(_target != t) - { - if(_target != null) - { - _target.removePropertyChangeListener(this); - } - _target = t; - if(_target != null) - { - _target.addPropertyChangeListener(this); - setEnabled(_target.isEnabled()); - } - else - { - setEnabled(false); - } - } - } - - Action getTarget() - { - return _target; - } - - private Action _target; + public ActionWrapper(String name) + { + super(name); + setEnabled(false); + } + + public void actionPerformed(ActionEvent e) + { + if(_target != null) + { + _target.actionPerformed(e); + } + } + + public void propertyChange(java.beans.PropertyChangeEvent e) + { + // + // The only property we're interested in is isEnabled + // + + java.beans.PropertyChangeListener[] l = getPropertyChangeListeners(); + for(int i = 0; i < l.length; ++i) + { + l[i].propertyChange(e); + } + } + + void setTarget(Action t) + { + if(_target != t) + { + if(_target != null) + { + _target.removePropertyChangeListener(this); + } + _target = t; + if(_target != null) + { + _target.addPropertyChangeListener(this); + setEnabled(_target.isEnabled()); + } + else + { + setEnabled(false); + } + } + } + + Action getTarget() + { + return _target; + } + + private Action _target; } private class DeleteTextAction extends AbstractAction { - public DeleteTextAction(String name) - { - super(name); - } + public DeleteTextAction(String name) + { + super(name); + } - public void actionPerformed(ActionEvent e) - { - if(_target != null) - { - Action a = _target.getActionMap().get("delete-next"); - if(a != null) - { - a.actionPerformed(new ActionEvent(_target, ActionEvent.ACTION_PERFORMED, null)); - } - } - } + public void actionPerformed(ActionEvent e) + { + if(_target != null) + { + Action a = _target.getActionMap().get("delete-next"); + if(a != null) + { + a.actionPerformed(new ActionEvent(_target, ActionEvent.ACTION_PERFORMED, null)); + } + } + } - void setTarget(JTextComponent t) - { - _target = t; - } + void setTarget(JTextComponent t) + { + _target = t; + } - private JTextComponent _target; + private JTextComponent _target; } private class FocusListener implements java.beans.PropertyChangeListener { - public void propertyChange(java.beans.PropertyChangeEvent e) - { - Object o = e.getNewValue(); - if(o == null) - { - unknownTarget(); - } - else if(o instanceof JTextComponent) - { - enableTextEditActions((JTextComponent)o); - } - else if(o instanceof JTree) - { - JTree tree = (JTree)o; - if(tree.getModel().getRoot() instanceof IceGridGUI.Application.Root) - { - enableTreetEditActions(); - } - else - { - disableAllEditMenusAndButtons(); - } - } - else - { - unknownTarget(); - } - } - - private void unknownTarget() - { - if(_copy.getTarget() == _copyText) - { - disableAllEditMenusAndButtons(); - } - // - // Otherwise (for good tree), do nothing. - // - } - - private void disableAllEditMenusAndButtons() - { - _cut.setTarget(null); - _copy.setTarget(null); - _paste.setTarget(null); - _delete.setTarget(null); - _moveUp.setTarget(null); - _moveDown.setTarget(null); - } - - private void enableTextEditActions(JTextComponent target) - { - boolean editable = target.isEditable() && target.isEnabled(); - - _cutText.setEnabled(editable); - _copyText.setEnabled(true); - _pasteText.setEnabled(editable); - _deleteText.setEnabled(editable); - _deleteText.setTarget(target); - - if(_copy.getTarget() != _copyText) - { - _cut.setTarget(_cutText); - _copy.setTarget(_copyText); - _paste.setTarget(_pasteText); - _delete.setTarget(_deleteText); - _moveUp.setTarget(null); - _moveDown.setTarget(null); - } - } - - private void enableTreetEditActions() - { - if(_copy.getTarget() != _appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY)) - { - _cut.setTarget(null); - _copy.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY)); - _paste.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.PASTE)); - _delete.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.DELETE)); - _moveUp.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_UP)); - _moveDown.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_DOWN)); - } - } + public void propertyChange(java.beans.PropertyChangeEvent e) + { + Object o = e.getNewValue(); + if(o == null) + { + unknownTarget(); + } + else if(o instanceof JTextComponent) + { + enableTextEditActions((JTextComponent)o); + } + else if(o instanceof JTree) + { + JTree tree = (JTree)o; + if(tree.getModel().getRoot() instanceof IceGridGUI.Application.Root) + { + enableTreetEditActions(); + } + else + { + disableAllEditMenusAndButtons(); + } + } + else + { + unknownTarget(); + } + } + + private void unknownTarget() + { + if(_copy.getTarget() == _copyText) + { + disableAllEditMenusAndButtons(); + } + // + // Otherwise (for good tree), do nothing. + // + } + + private void disableAllEditMenusAndButtons() + { + _cut.setTarget(null); + _copy.setTarget(null); + _paste.setTarget(null); + _delete.setTarget(null); + _moveUp.setTarget(null); + _moveDown.setTarget(null); + } + + private void enableTextEditActions(JTextComponent target) + { + boolean editable = target.isEditable() && target.isEnabled(); + + _cutText.setEnabled(editable); + _copyText.setEnabled(true); + _pasteText.setEnabled(editable); + _deleteText.setEnabled(editable); + _deleteText.setTarget(target); + + if(_copy.getTarget() != _copyText) + { + _cut.setTarget(_cutText); + _copy.setTarget(_copyText); + _paste.setTarget(_pasteText); + _delete.setTarget(_deleteText); + _moveUp.setTarget(null); + _moveDown.setTarget(null); + } + } + + private void enableTreetEditActions() + { + if(_copy.getTarget() != _appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY)) + { + _cut.setTarget(null); + _copy.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.COPY)); + _paste.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.PASTE)); + _delete.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.DELETE)); + _moveUp.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_UP)); + _moveDown.setTarget(_appActionsForMenu.get(IceGridGUI.Application.TreeNode.MOVE_DOWN)); + } + } } 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_PROPERTY_SET)); - _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); - if(!System.getProperty("os.name").startsWith("Mac OS")) - { - fileMenu.addSeparator(); - fileMenu.add(_exit); - } - - // - // Edit menu - // - JMenu editMenu = new JMenu("Edit"); - editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E); - add(editMenu); - - editMenu.add(_cut); - editMenu.add(_copy); - editMenu.add(_paste); - editMenu.add(_delete); - editMenu.addSeparator(); - editMenu.add(_moveUp); - editMenu.add(_moveDown); - - // - // 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(_patchApplication); - _appMenu.add(_showApplicationDetails); - _appMenu.addSeparator(); - _appMenu.add(_removeApplicationFromRegistry); - _appMenu.setEnabled(false); - - - // - // Node sub-menu - // - _nodeMenu = new JMenu("Node"); - _nodeMenu.setEnabled(false); - toolsMenu.add(_nodeMenu); - _nodeMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_NODE)); - - // - // Registry sub-menu - // - _registryMenu = new JMenu("Registry"); - _registryMenu.setEnabled(false); - toolsMenu.add(_registryMenu); - _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.ADD_OBJECT)); - _registryMenu.addSeparator(); + 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_PROPERTY_SET)); + _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); + if(!System.getProperty("os.name").startsWith("Mac OS")) + { + fileMenu.addSeparator(); + fileMenu.add(_exit); + } + + // + // Edit menu + // + JMenu editMenu = new JMenu("Edit"); + editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E); + add(editMenu); + + editMenu.add(_cut); + editMenu.add(_copy); + editMenu.add(_paste); + editMenu.add(_delete); + editMenu.addSeparator(); + editMenu.add(_moveUp); + editMenu.add(_moveDown); + + // + // 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(_patchApplication); + _appMenu.add(_showApplicationDetails); + _appMenu.addSeparator(); + _appMenu.add(_removeApplicationFromRegistry); + _appMenu.setEnabled(false); + + + // + // Node sub-menu + // + _nodeMenu = new JMenu("Node"); + _nodeMenu.setEnabled(false); + toolsMenu.add(_nodeMenu); + _nodeMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_NODE)); + + // + // Registry sub-menu + // + _registryMenu = new JMenu("Registry"); + _registryMenu.setEnabled(false); + toolsMenu.add(_registryMenu); + _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.ADD_OBJECT)); + _registryMenu.addSeparator(); _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDOUT)); _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDERR)); _registryMenu.addSeparator(); - _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_REGISTRY)); - - // - // 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.PATCH_SERVER)); - _serverMenu.addSeparator(); - _serverMenu.add(_liveActionsForMenu.get( - IceGridGUI.LiveDeployment.TreeNode.WRITE_MESSAGE)); - _serverMenu.add(_liveActionsForMenu.get( - IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDOUT)); - _serverMenu.add(_liveActionsForMenu.get( - IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDERR)); - _serverMenu.add(_liveActionsForMenu.get( - IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG)); - _serverMenu.addSeparator(); - _signalMenu = new JMenu("Send Signal"); - _serverMenu.add(_signalMenu); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGHUP)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGINT)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGQUIT)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGKILL)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGUSR1)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGUSR2)); - _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGTERM)); - - // - // Service sub-menu - // - _serviceMenu = new JMenu("Service"); - _serviceMenu.setEnabled(false); - toolsMenu.add(_serviceMenu); - _serviceMenu.add(_liveActionsForMenu.get( - IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG)); - - // - // Help menu - // - JMenu helpMenu = new JMenu("Help"); - helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H); - add(helpMenu); - - helpMenu.add(_helpContents); - - helpMenu.addSeparator(); - helpMenu.add(_about); - } + _registryMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_REGISTRY)); + + // + // 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.PATCH_SERVER)); + _serverMenu.addSeparator(); + _serverMenu.add(_liveActionsForMenu.get( + IceGridGUI.LiveDeployment.TreeNode.WRITE_MESSAGE)); + _serverMenu.add(_liveActionsForMenu.get( + IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDOUT)); + _serverMenu.add(_liveActionsForMenu.get( + IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDERR)); + _serverMenu.add(_liveActionsForMenu.get( + IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG)); + _serverMenu.addSeparator(); + _signalMenu = new JMenu("Send Signal"); + _serverMenu.add(_signalMenu); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGHUP)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGINT)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGQUIT)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGKILL)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGUSR1)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGUSR2)); + _signalMenu.add(_liveActionsForMenu.get(IceGridGUI.LiveDeployment.TreeNode.SIGTERM)); + + // + // Service sub-menu + // + _serviceMenu = new JMenu("Service"); + _serviceMenu.setEnabled(false); + toolsMenu.add(_serviceMenu); + _serviceMenu.add(_liveActionsForMenu.get( + IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG)); + + // + // Help menu + // + JMenu helpMenu = new JMenu("Help"); + helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H); + add(helpMenu); + + helpMenu.add(_helpContents); + + 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); - button = new JButton(_logout); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/logout.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(_openApplicationFromRegistry); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/open_from_registry.png")); - add(button); - button = new JButton(_openApplicationFromFile); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/open_from_file.png")); - add(button); - - addSeparator(); - - button = new JButton(_save); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/save.png")); - add(button); - button = new JButton(_saveToRegistry); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/save_to_registry.png")); - add(button); - button = new JButton(_saveToFile); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/save_to_file.png")); - add(button); - button = new JButton(_discardUpdates); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/discard.png")); - add(button); - - addSeparator(); - - button = new JButton(_copy); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/copy.png")); - add(button); - button = new JButton(_paste); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/paste.png")); - add(button); - button = new JButton(_delete); - button.setText(null); - button.setIcon(Utils.getIcon("/icons/24x24/delete.png")); - add(button); - - addSeparator(); - - add(_showVarsTool); - add(_substituteTool); - } + 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); + button = new JButton(_logout); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/logout.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(_openApplicationFromRegistry); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/open_from_registry.png")); + add(button); + button = new JButton(_openApplicationFromFile); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/open_from_file.png")); + add(button); + + addSeparator(); + + button = new JButton(_save); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/save.png")); + add(button); + button = new JButton(_saveToRegistry); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/save_to_registry.png")); + add(button); + button = new JButton(_saveToFile); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/save_to_file.png")); + add(button); + button = new JButton(_discardUpdates); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/discard.png")); + add(button); + + addSeparator(); + + button = new JButton(_copy); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/copy.png")); + add(button); + button = new JButton(_paste); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/paste.png")); + add(button); + button = new JButton(_delete); + button.setText(null); + button.setIcon(Utils.getIcon("/icons/24x24/delete.png")); + add(button); + + addSeparator(); + + add(_showVarsTool); + add(_substituteTool); + } } public Ice.Communicator getCommunicator() { - if(_communicator == null) - { - try - { - _communicator = Ice.Util.initialize(_initData); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog(null, - e.toString(), - "Communicator initialization failed", - JOptionPane.ERROR_MESSAGE); - } - } - return _communicator; + if(_communicator == null) + { + try + { + _communicator = Ice.Util.initialize(_initData); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog(null, + e.toString(), + "Communicator initialization failed", + JOptionPane.ERROR_MESSAGE); + } + } + return _communicator; } public Ice.Properties getProperties() { - return _initData.properties; + return _initData.properties; } public Tab getCurrentTab() { - return (Tab)_mainPane.getSelectedComponent(); + return (Tab)_mainPane.getSelectedComponent(); } public Action getBackAction() { - return _back; + return _back; } public Action getForwardAction() { - return _forward; + return _forward; } public Action getCloseApplicationAction() { - return _closeApplication; + return _closeApplication; } public Action getSaveAction() { - return _save; + return _save; } public Action getSaveToRegistryAction() { - return _saveToRegistry; + return _saveToRegistry; } public Action getSaveToFileAction() { - return _saveToFile; + return _saveToFile; } public Action getDiscardUpdatesAction() { - return _discardUpdates; + return _discardUpdates; } // @@ -646,62 +646,62 @@ public class Coordinator // 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); - return null; - } - // - // Essential: deep-copy desc! - // - desc = IceGridGUI.Application.Root.copyDescriptor(desc); - IceGridGUI.Application.Root root; - try - { - root = new IceGridGUI.Application.Root(this, desc, true, null); - } - catch(IceGridGUI.Application.UpdateFailedException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - e.toString(), - "Bad Application Descriptor: Unable load from Registry", - JOptionPane.ERROR_MESSAGE); - return null; - } - - app = new ApplicationPane(root); - _mainPane.addApplication(app); - _liveApplications.put(applicationName, app); - } - _mainPane.setSelectedComponent(app); - return app; + 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); + return null; + } + // + // Essential: deep-copy desc! + // + desc = IceGridGUI.Application.Root.copyDescriptor(desc); + IceGridGUI.Application.Root root; + try + { + root = new IceGridGUI.Application.Root(this, desc, true, null); + } + catch(IceGridGUI.Application.UpdateFailedException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + e.toString(), + "Bad Application Descriptor: Unable load from Registry", + JOptionPane.ERROR_MESSAGE); + return null; + } + + app = new ApplicationPane(root); + _mainPane.addApplication(app); + _liveApplications.put(applicationName, app); + } + _mainPane.setSelectedComponent(app); + return app; } public void removeLiveApplication(String name) { - _liveApplications.remove(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); + ApplicationPane app = _mainPane.findApplication(root); + assert app != null; + _liveApplications.put(app.getRoot().getId(), app); } public ApplicationPane getLiveApplication(String name) { - return (ApplicationPane)_liveApplications.get(name); + return (ApplicationPane)_liveApplications.get(name); } @@ -709,65 +709,65 @@ public class Coordinator // From the Application observer: // void applicationInit(String instanceName, int serial, java.util.List applications) - { - assert _latestSerial == -1; - _latestSerial = serial; + { + assert _latestSerial == -1; + _latestSerial = serial; - _liveDeploymentRoot.applicationInit(instanceName, - _sessionKeeper.getReplicaName(), applications); - // - // When we get this init, we can't have any live Application yet. - // + _liveDeploymentRoot.applicationInit(instanceName, + _sessionKeeper.getReplicaName(), applications); + // + // When we get this init, we can't have any live Application yet. + // } void applicationAdded(int serial, ApplicationInfo info) { - _liveDeploymentRoot.applicationAdded(info); - _liveDeploymentPane.refresh(); - _statusBar.setText( - "Last update: new application '" + info.descriptor.name + "'"); - updateSerial(serial); + _liveDeploymentRoot.applicationAdded(info); + _liveDeploymentPane.refresh(); + _statusBar.setText( + "Last update: new application '" + info.descriptor.name + "'"); + updateSerial(serial); } void applicationRemoved(int serial, String name) { - _liveDeploymentRoot.applicationRemoved(name); - _liveDeploymentPane.refresh(); - _statusBar.setText( - "Last update: application '" + name + "' was removed"); - - ApplicationPane app = - (ApplicationPane)_liveApplications.get(name); - - if(app != null) - { - if(app.getRoot().kill()) - { - _mainPane.remove(app); - } - _liveApplications.remove(name); - } - updateSerial(serial); + _liveDeploymentRoot.applicationRemoved(name); + _liveDeploymentPane.refresh(); + _statusBar.setText( + "Last update: application '" + name + "' was removed"); + + ApplicationPane app = + (ApplicationPane)_liveApplications.get(name); + + if(app != null) + { + if(app.getRoot().kill()) + { + _mainPane.remove(app); + } + _liveApplications.remove(name); + } + updateSerial(serial); } void applicationUpdated(int serial, ApplicationUpdateInfo update) { - _liveDeploymentRoot.applicationUpdated(update); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.applicationUpdated(update); + _liveDeploymentPane.refresh(); - _statusBar.setText("Last update: application '" + update.descriptor.name + "' was updated"); - - ApplicationPane app = - (ApplicationPane)_liveApplications.get(update.descriptor.name); + _statusBar.setText("Last update: application '" + update.descriptor.name + "' was updated"); + + ApplicationPane app = + (ApplicationPane)_liveApplications.get(update.descriptor.name); - if(app != null) - { - if(app.getRoot().update(update.descriptor)) - { - app.refresh(); - } - } - updateSerial(serial); + if(app != null) + { + if(app.getRoot().update(update.descriptor)) + { + app.refresh(); + } + } + updateSerial(serial); } // @@ -775,26 +775,26 @@ public class Coordinator // void adapterInit(AdapterInfo[] adapters) { - _liveDeploymentRoot.adapterInit(adapters); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.adapterInit(adapters); + _liveDeploymentPane.refresh(); } void adapterAdded(AdapterInfo info) { - _liveDeploymentRoot.adapterAdded(info); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.adapterAdded(info); + _liveDeploymentPane.refresh(); } void adapterUpdated(AdapterInfo info) { - _liveDeploymentRoot.adapterUpdated(info); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.adapterUpdated(info); + _liveDeploymentPane.refresh(); } void adapterRemoved(String id) { - _liveDeploymentRoot.adapterRemoved(id); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.adapterRemoved(id); + _liveDeploymentPane.refresh(); } // @@ -802,312 +802,312 @@ public class Coordinator // void objectInit(ObjectInfo[] objects) { - _liveDeploymentRoot.objectInit(objects); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.objectInit(objects); + _liveDeploymentPane.refresh(); } void objectAdded(ObjectInfo info) { - _liveDeploymentRoot.objectAdded(info); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.objectAdded(info); + _liveDeploymentPane.refresh(); } void objectUpdated(ObjectInfo info) { - _liveDeploymentRoot.objectUpdated(info); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.objectUpdated(info); + _liveDeploymentPane.refresh(); } void objectRemoved(Ice.Identity id) { - _liveDeploymentRoot.objectRemoved(id); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.objectRemoved(id); + _liveDeploymentPane.refresh(); } public void accessDenied(AccessDeniedException e) { - JOptionPane.showMessageDialog( - _mainFrame, - "Another session (username = " + e.lockUserId - + ") has exclusive write access to the registry", - "Access Denied", - JOptionPane.ERROR_MESSAGE); + 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); + 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); + 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 void removeApplicationFromRegistry(final String name) { - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - try - { - Runnable runnable = new Runnable() - { - private void release() - { - releaseExclusiveWriteAccess(); - getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - private void handleFailure(String prefix, String title, String message) - { - release(); - getStatusBar().setText(prefix + "failed!"); - - JOptionPane.showMessageDialog( - getMainFrame(), - message, - title, - JOptionPane.ERROR_MESSAGE); - } - - public void run() - { - getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - boolean asyncRelease = false; - - - final String prefix = "Deleting application '" + name + "'..."; - AMI_Admin_removeApplication cb = new AMI_Admin_removeApplication() - { - public void ice_response() - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("removeApplication for application " + name + ": success"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - release(); - getStatusBar().setText(prefix + "done."); - } - }); - } - - public void ice_exception(final Ice.UserException e) - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("removeApplication for application " + name + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure(prefix, "Delete failed", - "IceGrid exception: " + e.toString()); - } - - }); - } - - public void ice_exception(final Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("removeApplication for application " + name + ": failed"); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure(prefix, "Delete failed", - "Communication exception: " + e.toString()); - } - }); - } - }; - - if(_traceSaveToRegistry) - { - traceSaveToRegistry("sending removeApplication for application " + name); - } - - try - { - _sessionKeeper.getAdmin().removeApplication_async(cb, name); - asyncRelease = true; - } - catch(Ice.LocalException e) - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("Ice communications exception while removing application " + name); - } - - JOptionPane.showMessageDialog( - getMainFrame(), - e.toString(), - "Communication Exception", - JOptionPane.ERROR_MESSAGE); - } - finally - { - if(!asyncRelease) - { - releaseExclusiveWriteAccess(); - getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - } - }; - - acquireExclusiveWriteAccess(runnable); - } - catch(AccessDeniedException e) - { - accessDenied(e); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "Could not remove application '" + name + - "' from IceGrid registry:\n" + e.toString(), - "Trouble with IceGrid registry", - JOptionPane.ERROR_MESSAGE); - } + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + try + { + Runnable runnable = new Runnable() + { + private void release() + { + releaseExclusiveWriteAccess(); + getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + private void handleFailure(String prefix, String title, String message) + { + release(); + getStatusBar().setText(prefix + "failed!"); + + JOptionPane.showMessageDialog( + getMainFrame(), + message, + title, + JOptionPane.ERROR_MESSAGE); + } + + public void run() + { + getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + boolean asyncRelease = false; + + + final String prefix = "Deleting application '" + name + "'..."; + AMI_Admin_removeApplication cb = new AMI_Admin_removeApplication() + { + public void ice_response() + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("removeApplication for application " + name + ": success"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + release(); + getStatusBar().setText(prefix + "done."); + } + }); + } + + public void ice_exception(final Ice.UserException e) + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("removeApplication for application " + name + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure(prefix, "Delete failed", + "IceGrid exception: " + e.toString()); + } + + }); + } + + public void ice_exception(final Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("removeApplication for application " + name + ": failed"); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure(prefix, "Delete failed", + "Communication exception: " + e.toString()); + } + }); + } + }; + + if(_traceSaveToRegistry) + { + traceSaveToRegistry("sending removeApplication for application " + name); + } + + try + { + _sessionKeeper.getAdmin().removeApplication_async(cb, name); + asyncRelease = true; + } + catch(Ice.LocalException e) + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("Ice communications exception while removing application " + name); + } + + JOptionPane.showMessageDialog( + getMainFrame(), + e.toString(), + "Communication Exception", + JOptionPane.ERROR_MESSAGE); + } + finally + { + if(!asyncRelease) + { + releaseExclusiveWriteAccess(); + getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + } + }; + + acquireExclusiveWriteAccess(runnable); + } + catch(AccessDeniedException e) + { + accessDenied(e); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "Could not remove application '" + name + + "' from IceGrid registry:\n" + e.toString(), + "Trouble with IceGrid registry", + JOptionPane.ERROR_MESSAGE); + } } public void acquireExclusiveWriteAccess(Runnable runnable) - throws AccessDeniedException - { - if(_writeSerial == -1) - { - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - try - { - _writeSerial = _sessionKeeper.getSession().startUpdate(); - - if(_traceSaveToRegistry) - { - traceSaveToRegistry("startUpdate returned serial " + _writeSerial); - } - } - finally - { - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - - assert _onExclusiveWrite == null; - - // - // Must increment now since run() can call releaseExclusiveWriteAccess() - // - _writeAccessCount++; - - if(_traceSaveToRegistry) - { - traceSaveToRegistry("acquireExclusiveWriteAccess: writeAccessCount is " + _writeAccessCount); - } - - if(runnable != null) - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("lastestSerial is " + _latestSerial); - } - - if(_writeSerial <= _latestSerial) - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("run update immediately"); - } - runnable.run(); - } - else - { - if(_traceSaveToRegistry) - { - traceSaveToRegistry("wait for updates from ApplicationObserver"); - } - _onExclusiveWrite = runnable; - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - // - // TODO: start a thread to check we don't wait forever - // - } - } + throws AccessDeniedException + { + if(_writeSerial == -1) + { + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try + { + _writeSerial = _sessionKeeper.getSession().startUpdate(); + + if(_traceSaveToRegistry) + { + traceSaveToRegistry("startUpdate returned serial " + _writeSerial); + } + } + finally + { + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + + assert _onExclusiveWrite == null; + + // + // Must increment now since run() can call releaseExclusiveWriteAccess() + // + _writeAccessCount++; + + if(_traceSaveToRegistry) + { + traceSaveToRegistry("acquireExclusiveWriteAccess: writeAccessCount is " + _writeAccessCount); + } + + if(runnable != null) + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("lastestSerial is " + _latestSerial); + } + + if(_writeSerial <= _latestSerial) + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("run update immediately"); + } + runnable.run(); + } + else + { + if(_traceSaveToRegistry) + { + traceSaveToRegistry("wait for updates from ApplicationObserver"); + } + _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) - { - try - { - _writeSerial = -1; - _sessionKeeper.getSession().finishUpdate(); - if(_traceSaveToRegistry) - { - traceSaveToRegistry("finishUpdate done"); - } - } - catch(AccessDeniedException e) - { - accessDenied(e); - } - catch(Ice.ObjectNotExistException e) - { - // - // Ignored, the session is gone, and so is the exclusive access. - // - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "Could not release exclusive write access on the IceGrid registry:\n" - + e.toString(), - "Trouble with IceGrid registry", - JOptionPane.ERROR_MESSAGE); - } - } - - if(_traceSaveToRegistry) - { - traceSaveToRegistry("releaseExclusiveWriteAccess: writeAccessCount is " + _writeAccessCount); - } + if(--_writeAccessCount == 0) + { + try + { + _writeSerial = -1; + _sessionKeeper.getSession().finishUpdate(); + if(_traceSaveToRegistry) + { + traceSaveToRegistry("finishUpdate done"); + } + } + catch(AccessDeniedException e) + { + accessDenied(e); + } + catch(Ice.ObjectNotExistException e) + { + // + // Ignored, the session is gone, and so is the exclusive access. + // + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "Could not release exclusive write access on the IceGrid registry:\n" + + e.toString(), + "Trouble with IceGrid registry", + JOptionPane.ERROR_MESSAGE); + } + } + + if(_traceSaveToRegistry) + { + traceSaveToRegistry("releaseExclusiveWriteAccess: writeAccessCount is " + _writeAccessCount); + } } private void updateSerial(int serial) { - assert serial == _latestSerial + 1; - _latestSerial = serial; - - if(_writeAccessCount > 0 && - _writeSerial <= _latestSerial && - _onExclusiveWrite != null) - { - Runnable runnable = _onExclusiveWrite; - _onExclusiveWrite = null; - - if(_traceSaveToRegistry) - { - traceSaveToRegistry("writeSerial <= latestSerial, running update"); - } - runnable.run(); - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + assert serial == _latestSerial + 1; + _latestSerial = serial; + + if(_writeAccessCount > 0 && + _writeSerial <= _latestSerial && + _onExclusiveWrite != null) + { + Runnable runnable = _onExclusiveWrite; + _onExclusiveWrite = null; + + if(_traceSaveToRegistry) + { + traceSaveToRegistry("writeSerial <= latestSerial, running update"); + } + runnable.run(); + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } // @@ -1115,14 +1115,14 @@ public class Coordinator // void registryUp(RegistryInfo info) { - _liveDeploymentRoot.registryUp(info); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.registryUp(info); + _liveDeploymentPane.refresh(); } void registryDown(String registry) { - _liveDeploymentRoot.registryDown(registry); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.registryDown(registry); + _liveDeploymentPane.refresh(); } // @@ -1130,1226 +1130,1226 @@ public class Coordinator // void nodeUp(NodeDynamicInfo updatedInfo) { - _liveDeploymentRoot.nodeUp(updatedInfo); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.nodeUp(updatedInfo); + _liveDeploymentPane.refresh(); } void nodeDown(String node) { - _liveDeploymentRoot.nodeDown(node); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.nodeDown(node); + _liveDeploymentPane.refresh(); } void updateServer(String node, ServerDynamicInfo updatedInfo) { - _liveDeploymentRoot.updateServer(node, updatedInfo); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.updateServer(node, updatedInfo); + _liveDeploymentPane.refresh(); } void updateAdapter(String node, AdapterDynamicInfo updatedInfo) { - _liveDeploymentRoot.updateAdapter(node, updatedInfo); - _liveDeploymentPane.refresh(); + _liveDeploymentRoot.updateAdapter(node, updatedInfo); + _liveDeploymentPane.refresh(); } void sessionLost() { - _latestSerial = -1; - _writeSerial = -1; - _writeAccessCount = 0; - _onExclusiveWrite = 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); - _patchApplication.setEnabled(false); - _showApplicationDetails.setEnabled(false); - _removeApplicationFromRegistry.setEnabled(false); - _appMenu.setEnabled(false); - _newApplicationWithDefaultTemplates.setEnabled(false); - _acquireExclusiveWriteAccess.setEnabled(false); - _releaseExclusiveWriteAccess.setEnabled(false); - _saveToRegistry.setEnabled(false); + _latestSerial = -1; + _writeSerial = -1; + _writeAccessCount = 0; + _onExclusiveWrite = 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); + _patchApplication.setEnabled(false); + _showApplicationDetails.setEnabled(false); + _removeApplicationFromRegistry.setEnabled(false); + _appMenu.setEnabled(false); + _newApplicationWithDefaultTemplates.setEnabled(false); + _acquireExclusiveWriteAccess.setEnabled(false); + _releaseExclusiveWriteAccess.setEnabled(false); + _saveToRegistry.setEnabled(false); } AdminSessionPrx login(SessionKeeper.LoginInfo info, - Component parent, - Ice.LongHolder keepAlivePeriodHolder) - { - _liveDeploymentRoot.clear(); - - AdminSessionPrx session = null; - - destroyCommunicator(); - - Ice.InitializationData initData = _initData; - if(info.routed && info.routerSSLEnabled || !info.routed && info.registrySSLEnabled) - { - initData = (Ice.InitializationData)initData.clone(); - initData.properties = initData.properties._clone(); - initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); - - // - // Transform SSL info into properties - // - initData.properties.setProperty("IceSSL.Keystore", info.keystore); - initData.properties.setProperty("IceSSL.Password", new String(info.keyPassword)); - initData.properties.setProperty("IceSSL.KeystorePassword", new String(info.keystorePassword)); - initData.properties.setProperty("IceSSL.Alias", info.alias); - initData.properties.setProperty("IceSSL.Truststore", info.truststore); - initData.properties.setProperty("IceSSL.TruststorePassword", new String(info.truststorePassword)); - } - - try - { - _communicator = Ice.Util.initialize(initData); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog(parent, - e.toString(), - "Communicator initialization failed", - JOptionPane.ERROR_MESSAGE); - return null; - } - - if(info.routed) - { - // - // Router - // - - Ice.Identity routerId = new Ice.Identity(); - routerId.category = info.routerInstanceName; - routerId.name = "router"; - String str = "\"" + _communicator.identityToString(routerId) + "\""; - - 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; - if(info.routerUseSSL) - { - router = Glacier2.RouterPrxHelper. - uncheckedCast(router.ice_secure(true)); - - s = router.createSessionFromSecureConnection(); - - if(s == null) - { - JOptionPane.showMessageDialog( - parent, - "createSessionFromSecureConnection returned a null session: \n" - + "verify that Glacier2.SSLSessionManager is set to " - + "<IceGridInstanceName>/AdminSSLSessionManager in your Glacier2 router configuration", - "Login failed", - JOptionPane.ERROR_MESSAGE); - - return null; - } - } - else - { - s = router.createSession( - info.routerUsername, new String(info.routerPassword)); - - if(s == null) - { - JOptionPane.showMessageDialog( - parent, - "createSession returned a null session: \n" - + "verify that Glacier2.SessionManager is set to " - + "<IceGridInstanceName>/AdminSessionManager in your Glacier2 router configuration", - "Login failed", - JOptionPane.ERROR_MESSAGE); - - return null; - } - } - - session = AdminSessionPrxHelper.uncheckedCast(s); - keepAlivePeriodHolder.value = router.getSessionTimeout() * 1000 / 2; - } - catch(Glacier2.PermissionDeniedException e) - { - if(e.reason.length() == 0) - { - e.reason = info.routerUseSSL ? "Invalid credentials" : "Invalid username/password"; - } - 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 - { - if(info.registryEndpoints.equals("")) - { - JOptionPane.showMessageDialog( - parent, - "You need to provide one or more endpoint for the Registry", - "Login failed", - JOptionPane.ERROR_MESSAGE); - - return null; - } - - // - // The client uses the locator only without routing - // - Ice.Identity locatorId = new Ice.Identity(); - locatorId.category = info.registryInstanceName; - locatorId.name = "Locator"; - String str = "\"" + _communicator.identityToString(locatorId) + "\""; - str += ":" + info.registryEndpoints; - - RegistryPrx localRegistry = null; - - try - { - IceGrid.LocatorPrx defaultLocator = IceGrid.LocatorPrxHelper. - checkedCast(_communicator.stringToProxy(str)); - - if(defaultLocator == null) - { - JOptionPane.showMessageDialog( - parent, - "This version of IceGrid Admin requires an IceGrid Registry version 3.2 or higher", - "Version Mismatch", - JOptionPane.ERROR_MESSAGE); - return null; - } - - localRegistry = defaultLocator.getLocalRegistry(); - - _communicator.setDefaultLocator(defaultLocator); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - parent, - "Could not contact '" + str + "': " + e.toString(), - "Login failed", - JOptionPane.ERROR_MESSAGE); - return null; - } - - RegistryPrx registry = localRegistry; - - if(info.connectToMaster) - { - Ice.Identity masterRegistryId = new Ice.Identity(); - masterRegistryId.category = info.registryInstanceName; - masterRegistryId.name = "Registry"; - - registry = RegistryPrxHelper. - uncheckedCast(_communicator.stringToProxy("\"" + - _communicator.identityToString(masterRegistryId) + "\"")); - } - - do - { - try - { - if(info.registryUseSSL) - { - registry = RegistryPrxHelper. - uncheckedCast(registry.ice_secure(true)); - - session = registry.createAdminSessionFromSecureConnection(); - assert session != null; - } - else - { - session = registry.createAdminSession(info.registryUsername, - new String(info.registryPassword)); - assert session != null; - } - keepAlivePeriodHolder.value = registry.getSessionTimeout() * 1000 / 2; - } - catch(IceGrid.PermissionDeniedException e) - { - JOptionPane.showMessageDialog(parent, - "Permission denied: " - + e.reason, - "Login failed", - JOptionPane.ERROR_MESSAGE); - return null; - } - catch(Ice.LocalException e) - { - if(registry.ice_getIdentity().equals(localRegistry.ice_getIdentity())) - { - JOptionPane.showMessageDialog(parent, - "Could not create session: " - + e.toString(), - "Login failed", - JOptionPane.ERROR_MESSAGE); - return null; - } - else - { - if(JOptionPane.showConfirmDialog( - parent, - "Unable to connect to the Master Registry:\n " + e.toString() - + "\n\nDo you want to connect to a Slave Registry?", - "Cannot connect to Master Registry", - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) - { - - registry = localRegistry; - } - else - { - return null; - } - } - } - } while(session == null); - } - - _logout.setEnabled(true); - _openApplicationFromRegistry.setEnabled(true); - _patchApplication.setEnabled(true); - _showApplicationDetails.setEnabled(true); - _removeApplicationFromRegistry.setEnabled(true); - _appMenu.setEnabled(true); - _newApplicationWithDefaultTemplates.setEnabled(true); - _acquireExclusiveWriteAccess.setEnabled(true); - - _mainPane.setSelectedComponent(_liveDeploymentPane); - - return session; + Component parent, + Ice.LongHolder keepAlivePeriodHolder) + { + _liveDeploymentRoot.clear(); + + AdminSessionPrx session = null; + + destroyCommunicator(); + + Ice.InitializationData initData = _initData; + if(info.routed && info.routerSSLEnabled || !info.routed && info.registrySSLEnabled) + { + initData = (Ice.InitializationData)initData.clone(); + initData.properties = initData.properties._clone(); + initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); + + // + // Transform SSL info into properties + // + initData.properties.setProperty("IceSSL.Keystore", info.keystore); + initData.properties.setProperty("IceSSL.Password", new String(info.keyPassword)); + initData.properties.setProperty("IceSSL.KeystorePassword", new String(info.keystorePassword)); + initData.properties.setProperty("IceSSL.Alias", info.alias); + initData.properties.setProperty("IceSSL.Truststore", info.truststore); + initData.properties.setProperty("IceSSL.TruststorePassword", new String(info.truststorePassword)); + } + + try + { + _communicator = Ice.Util.initialize(initData); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog(parent, + e.toString(), + "Communicator initialization failed", + JOptionPane.ERROR_MESSAGE); + return null; + } + + if(info.routed) + { + // + // Router + // + + Ice.Identity routerId = new Ice.Identity(); + routerId.category = info.routerInstanceName; + routerId.name = "router"; + String str = "\"" + _communicator.identityToString(routerId) + "\""; + + 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; + if(info.routerUseSSL) + { + router = Glacier2.RouterPrxHelper. + uncheckedCast(router.ice_secure(true)); + + s = router.createSessionFromSecureConnection(); + + if(s == null) + { + JOptionPane.showMessageDialog( + parent, + "createSessionFromSecureConnection returned a null session: \n" + + "verify that Glacier2.SSLSessionManager is set to " + + "<IceGridInstanceName>/AdminSSLSessionManager in your Glacier2 router configuration", + "Login failed", + JOptionPane.ERROR_MESSAGE); + + return null; + } + } + else + { + s = router.createSession( + info.routerUsername, new String(info.routerPassword)); + + if(s == null) + { + JOptionPane.showMessageDialog( + parent, + "createSession returned a null session: \n" + + "verify that Glacier2.SessionManager is set to " + + "<IceGridInstanceName>/AdminSessionManager in your Glacier2 router configuration", + "Login failed", + JOptionPane.ERROR_MESSAGE); + + return null; + } + } + + session = AdminSessionPrxHelper.uncheckedCast(s); + keepAlivePeriodHolder.value = router.getSessionTimeout() * 1000 / 2; + } + catch(Glacier2.PermissionDeniedException e) + { + if(e.reason.length() == 0) + { + e.reason = info.routerUseSSL ? "Invalid credentials" : "Invalid username/password"; + } + 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 + { + if(info.registryEndpoints.equals("")) + { + JOptionPane.showMessageDialog( + parent, + "You need to provide one or more endpoint for the Registry", + "Login failed", + JOptionPane.ERROR_MESSAGE); + + return null; + } + + // + // The client uses the locator only without routing + // + Ice.Identity locatorId = new Ice.Identity(); + locatorId.category = info.registryInstanceName; + locatorId.name = "Locator"; + String str = "\"" + _communicator.identityToString(locatorId) + "\""; + str += ":" + info.registryEndpoints; + + RegistryPrx localRegistry = null; + + try + { + IceGrid.LocatorPrx defaultLocator = IceGrid.LocatorPrxHelper. + checkedCast(_communicator.stringToProxy(str)); + + if(defaultLocator == null) + { + JOptionPane.showMessageDialog( + parent, + "This version of IceGrid Admin requires an IceGrid Registry version 3.2 or higher", + "Version Mismatch", + JOptionPane.ERROR_MESSAGE); + return null; + } + + localRegistry = defaultLocator.getLocalRegistry(); + + _communicator.setDefaultLocator(defaultLocator); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + parent, + "Could not contact '" + str + "': " + e.toString(), + "Login failed", + JOptionPane.ERROR_MESSAGE); + return null; + } + + RegistryPrx registry = localRegistry; + + if(info.connectToMaster) + { + Ice.Identity masterRegistryId = new Ice.Identity(); + masterRegistryId.category = info.registryInstanceName; + masterRegistryId.name = "Registry"; + + registry = RegistryPrxHelper. + uncheckedCast(_communicator.stringToProxy("\"" + + _communicator.identityToString(masterRegistryId) + "\"")); + } + + do + { + try + { + if(info.registryUseSSL) + { + registry = RegistryPrxHelper. + uncheckedCast(registry.ice_secure(true)); + + session = registry.createAdminSessionFromSecureConnection(); + assert session != null; + } + else + { + session = registry.createAdminSession(info.registryUsername, + new String(info.registryPassword)); + assert session != null; + } + keepAlivePeriodHolder.value = registry.getSessionTimeout() * 1000 / 2; + } + catch(IceGrid.PermissionDeniedException e) + { + JOptionPane.showMessageDialog(parent, + "Permission denied: " + + e.reason, + "Login failed", + JOptionPane.ERROR_MESSAGE); + return null; + } + catch(Ice.LocalException e) + { + if(registry.ice_getIdentity().equals(localRegistry.ice_getIdentity())) + { + JOptionPane.showMessageDialog(parent, + "Could not create session: " + + e.toString(), + "Login failed", + JOptionPane.ERROR_MESSAGE); + return null; + } + else + { + if(JOptionPane.showConfirmDialog( + parent, + "Unable to connect to the Master Registry:\n " + e.toString() + + "\n\nDo you want to connect to a Slave Registry?", + "Cannot connect to Master Registry", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) + { + + registry = localRegistry; + } + else + { + return null; + } + } + } + } while(session == null); + } + + _logout.setEnabled(true); + _openApplicationFromRegistry.setEnabled(true); + _patchApplication.setEnabled(true); + _showApplicationDetails.setEnabled(true); + _removeApplicationFromRegistry.setEnabled(true); + _appMenu.setEnabled(true); + _newApplicationWithDefaultTemplates.setEnabled(true); + _acquireExclusiveWriteAccess.setEnabled(true); + + _mainPane.setSelectedComponent(_liveDeploymentPane); + + return session; } void destroySession(AdminSessionPrx session) { - _liveDeploymentRoot.closeAllShowLogDialogs(); - - 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 - } + _liveDeploymentRoot.closeAllShowLogDialogs(); + + 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); + substitute(false); } void substituteVars() { - substitute(true); + substitute(true); } private void substitute(boolean newValue) { - if(_substitute != newValue) - { - _substitute = newValue; - - boolean refresh = true; - if(getCurrentTab() instanceof ApplicationPane) - { - ApplicationPane app = (ApplicationPane)getCurrentTab(); - if(!app.applyUpdates(true)) - { - _substitute = !_substitute; - refresh = false; - } - } - - if(_substitute) - { - _substituteMenuItem.setSelected(true); - _substituteTool.setSelected(true); - } - else - { - _showVarsMenuItem.setSelected(true); - _showVarsTool.setSelected(true); - } - - if(refresh) - { - getCurrentTab().refresh(); - } - } + if(_substitute != newValue) + { + _substitute = newValue; + + boolean refresh = true; + if(getCurrentTab() instanceof ApplicationPane) + { + ApplicationPane app = (ApplicationPane)getCurrentTab(); + if(!app.applyUpdates(true)) + { + _substitute = !_substitute; + refresh = false; + } + } + + if(_substitute) + { + _substituteMenuItem.setSelected(true); + _substituteTool.setSelected(true); + } + else + { + _showVarsMenuItem.setSelected(true); + _showVarsTool.setSelected(true); + } + + if(refresh) + { + getCurrentTab().refresh(); + } + } } public boolean substitute() { - return _substitute; + return _substitute; } public AdminPrx getAdmin() { - return _sessionKeeper.getAdmin(); + return _sessionKeeper.getAdmin(); } public StatusBar getStatusBar() { - return _statusBar; + return _statusBar; } public JFrame getMainFrame() { - return _mainFrame; + return _mainFrame; } public MainPane getMainPane() { - return _mainPane; + return _mainPane; } public ApplicationDescriptor parseFile(File file) { - if(_icegridadminProcess == null) - { - // - // Start icegridadmin server - // - try - { - _icegridadminProcess = Runtime.getRuntime().exec("icegridadmin --server"); - } - catch(java.io.IOException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "Failed to start icegridadmin subprocess: " + e.toString(), - "IO Exception", - JOptionPane.ERROR_MESSAGE); - return null; - } - - try - { - BufferedReader reader = - new BufferedReader(new InputStreamReader(_icegridadminProcess.getInputStream(), - "US-ASCII")); - - String str = reader.readLine(); - reader.close(); - - if(str == null || str.length() == 0) - { - JOptionPane.showMessageDialog( - _mainFrame, - "The icegridadmin subprocess failed", - "Subprocess failure", - JOptionPane.ERROR_MESSAGE); - destroyIceGridAdmin(); - return null; - } - _fileParser = str; - } - catch(java.io.UnsupportedEncodingException e) - { - assert false; - } - catch(java.io.IOException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "IO Exception: " + e.toString(), - "IO Exception", - JOptionPane.ERROR_MESSAGE); - - destroyIceGridAdmin(); - return null; - } - } - - try - { - FileParserPrx fileParser = FileParserPrxHelper.checkedCast( - getCommunicator().stringToProxy(_fileParser).ice_router(null)); - return fileParser.parse(file.getAbsolutePath(), - _sessionKeeper.getRoutedAdmin()); - } - catch(ParseException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "Failed to parse file '" + file.getAbsolutePath() + "':\n" + e.toString(), - "Parse error", - JOptionPane.ERROR_MESSAGE); - return null; - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - _mainFrame, - "Operation on FileParser failed:\n" + e.toString(), - "Communication error", - JOptionPane.ERROR_MESSAGE); - destroyIceGridAdmin(); - return null; - } + if(_icegridadminProcess == null) + { + // + // Start icegridadmin server + // + try + { + _icegridadminProcess = Runtime.getRuntime().exec("icegridadmin --server"); + } + catch(java.io.IOException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "Failed to start icegridadmin subprocess: " + e.toString(), + "IO Exception", + JOptionPane.ERROR_MESSAGE); + return null; + } + + try + { + BufferedReader reader = + new BufferedReader(new InputStreamReader(_icegridadminProcess.getInputStream(), + "US-ASCII")); + + String str = reader.readLine(); + reader.close(); + + if(str == null || str.length() == 0) + { + JOptionPane.showMessageDialog( + _mainFrame, + "The icegridadmin subprocess failed", + "Subprocess failure", + JOptionPane.ERROR_MESSAGE); + destroyIceGridAdmin(); + return null; + } + _fileParser = str; + } + catch(java.io.UnsupportedEncodingException e) + { + assert false; + } + catch(java.io.IOException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "IO Exception: " + e.toString(), + "IO Exception", + JOptionPane.ERROR_MESSAGE); + + destroyIceGridAdmin(); + return null; + } + } + + try + { + FileParserPrx fileParser = FileParserPrxHelper.checkedCast( + getCommunicator().stringToProxy(_fileParser).ice_router(null)); + return fileParser.parse(file.getAbsolutePath(), + _sessionKeeper.getRoutedAdmin()); + } + catch(ParseException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "Failed to parse file '" + file.getAbsolutePath() + "':\n" + e.toString(), + "Parse error", + JOptionPane.ERROR_MESSAGE); + return null; + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + _mainFrame, + "Operation on FileParser failed:\n" + e.toString(), + "Communication error", + JOptionPane.ERROR_MESSAGE); + destroyIceGridAdmin(); + return null; + } } private void destroyIceGridAdmin() { - if(_icegridadminProcess != null) - { - try - { - _icegridadminProcess.destroy(); - } - catch(Exception e) - {} - _icegridadminProcess = null; - _fileParser = null; - } + if(_icegridadminProcess != null) + { + try + { + _icegridadminProcess.destroy(); + } + catch(Exception e) + {} + _icegridadminProcess = null; + _fileParser = null; + } } public File saveToFile(boolean ask, IceGridGUI.Application.Root root, - File file) - { - if(ask || file == null) - { - if(file != null) - { - _saveXMLChooser.setSelectedFile(file); - } - else - { - _saveXMLChooser.setCurrentDirectory(_openChooser.getCurrentDirectory()); - } - - int result = _saveXMLChooser.showSaveDialog(_mainFrame); - - if(file == null || result == JFileChooser.APPROVE_OPTION) - { - _openChooser.setCurrentDirectory(_saveXMLChooser.getCurrentDirectory()); - } - - if(result == JFileChooser.APPROVE_OPTION) - { - file = _saveXMLChooser.getSelectedFile(); - } - else - { - file = null; - } - } - if(file != null) - { - if(!file.exists() && file.getName().indexOf('.') == -1) - { - file = new File(file.getAbsolutePath() + ".xml"); - } - - 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; + File file) + { + if(ask || file == null) + { + if(file != null) + { + _saveXMLChooser.setSelectedFile(file); + } + else + { + _saveXMLChooser.setCurrentDirectory(_openChooser.getCurrentDirectory()); + } + + int result = _saveXMLChooser.showSaveDialog(_mainFrame); + + if(file == null || result == JFileChooser.APPROVE_OPTION) + { + _openChooser.setCurrentDirectory(_saveXMLChooser.getCurrentDirectory()); + } + + if(result == JFileChooser.APPROVE_OPTION) + { + file = _saveXMLChooser.getSelectedFile(); + } + else + { + file = null; + } + } + if(file != null) + { + if(!file.exists() && file.getName().indexOf('.') == -1) + { + file = new File(file.getAbsolutePath() + ".xml"); + } + + 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; } public JFileChooser getSaveLogChooser() { - return _saveLogChooser; + return _saveLogChooser; } static private Ice.Properties createProperties(Ice.StringSeqHolder args) { - Ice.Properties properties = Ice.Util.createProperties(); - - // - // Set various default values - // - properties.setProperty("Ice.Override.ConnectTimeout", "5000"); - - properties.setProperty("Ice.ThreadPerConnection", "1"); - - // - // For Glacier - // - properties.setProperty("Ice.ACM.Client", "0"); - properties.setProperty("Ice.MonitorConnections", "5"); - - // - // Disable retries - // - properties.setProperty("Ice.RetryIntervals", "-1"); - - return Ice.Util.createProperties(args, properties); + Ice.Properties properties = Ice.Util.createProperties(); + + // + // Set various default values + // + properties.setProperty("Ice.Override.ConnectTimeout", "5000"); + + properties.setProperty("Ice.ThreadPerConnection", "1"); + + // + // For Glacier + // + properties.setProperty("Ice.ACM.Client", "0"); + properties.setProperty("Ice.MonitorConnections", "5"); + + // + // Disable retries + // + properties.setProperty("Ice.RetryIntervals", "-1"); + + return Ice.Util.createProperties(args, properties); } Coordinator(JFrame mainFrame, Ice.StringSeqHolder args, Preferences prefs) - { - _mainFrame = mainFrame; - _prefs = prefs; - _initData = new Ice.InitializationData(); - - _initData.logger = new Logger(mainFrame); - _initData.properties = createProperties(args); - - if(args.value.length > 0) - { - String msg = "Extra command-line arguments: "; - for(int i = 0; i < args.value.length; ++i) - { - msg += args.value[i] + " "; - } - _initData.logger.warning(msg); - } - - _traceObservers = _initData.properties.getPropertyAsInt("IceGridAdmin.Trace.Observers") > 0; - _traceSaveToRegistry = _initData.properties.getPropertyAsInt("IceGridAdmin.Trace.SaveToRegistry") > 0; - - _liveDeploymentRoot = new IceGridGUI.LiveDeployment.Root(this); - - _sessionKeeper = new SessionKeeper(this); - - _shutdownHook = new Thread("Shutdown hook") - { - public void run() - { - destroyIceGridAdmin(); - destroyCommunicator(); - } - }; - Runtime.getRuntime().addShutdownHook(_shutdownHook); - - - _saveXMLChooser = new JFileChooser( - _prefs.get("current directory", null)); - - _saveXMLChooser.addChoosableFileFilter(new FileFilter() - { - public boolean accept(File f) - { - return f.isDirectory() || f.getName().endsWith(".xml"); - } - - public String getDescription() - { - return ".xml files"; - } - }); - - _saveLogChooser = new JFileChooser( - _prefs.get("current directory", null)); - - _saveLogChooser.addChoosableFileFilter(new FileFilter() - { - public boolean accept(File f) - { - return f.isDirectory() || - f.getName().endsWith(".out") || - f.getName().endsWith(".err") || - f.getName().endsWith(".log") || - f.getName().endsWith(".txt"); - } - - public String getDescription() - { - return ".out .err .log .txt files"; - } - }); - - javax.swing.UIManager.put("FileChooser.readOnly", Boolean.TRUE); - - _openChooser = new JFileChooser(_saveXMLChooser.getCurrentDirectory()); - - _openChooser.addChoosableFileFilter(_saveXMLChooser.getChoosableFileFilters()[1]); - - - 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) - { - _sessionKeeper.relog(true); - } - }; - _login.putValue(Action.SHORT_DESCRIPTION, - "Log into an IceGrid Registry"); - - _logout = new AbstractAction("Logout") - { - public void actionPerformed(ActionEvent e) - { - _sessionKeeper.logout(true); - } - }; - _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 = _openChooser.showOpenDialog(_mainFrame); - if(result == JFileChooser.APPROVE_OPTION) - { - File file = _openChooser.getSelectedFile(); - - ApplicationDescriptor desc = parseFile(file); - - if(desc != null) - { - IceGridGUI.Application.Root root; - try - { - root = new IceGridGUI.Application.Root(Coordinator.this, desc, false, file); - } - catch(IceGridGUI.Application.UpdateFailedException ex) - { - JOptionPane.showMessageDialog( - _mainFrame, - ex.toString(), - "Bad Application Descriptor: Unable load from file", - JOptionPane.ERROR_MESSAGE); - return; - } - - ApplicationPane app = new ApplicationPane(root); - _mainPane.addApplication(app); - _mainPane.setSelectedComponent(app); - root.setSelectedNode(root); - } - } - } - }; - _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(); - - if(applicationNames.length == 0) - { - JOptionPane.showMessageDialog( - _mainFrame, - "The registry does not contain any application", - "Empty registry", - JOptionPane.INFORMATION_MESSAGE); - } - else - { - 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) - { - ApplicationPane app = openLiveApplication(appName); - if(app != null) - { - IceGridGUI.Application.Root root = app.getRoot(); - if(root.getSelectedNode() == null) - { - root.setSelectedNode(root); - } - } - } - } - } - }; - _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"); - - if(System.getProperty("os.name").startsWith("Mac OS")) - { - _closeApplication.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_W, MENU_MASK)); - } - else - { - _closeApplication.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_F4, MENU_MASK)); - } - _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 and reload application"); - - - _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(); - } - }; - - _about = new AbstractAction("About") - { - public void actionPerformed(ActionEvent e) - { - about(); - } - }; - - _patchApplication = new AbstractAction("Patch Distribution") - { - public void actionPerformed(ActionEvent e) - { - Object[] applicationNames = _liveDeploymentRoot.getPatchableApplicationNames(); - - if(applicationNames.length == 0) - { - JOptionPane.showMessageDialog( - _mainFrame, - "No application in this IceGrid registry can be patched", - "No application", - JOptionPane.INFORMATION_MESSAGE); - } - else - { - String appName = (String)JOptionPane.showInputDialog( - _mainFrame, "Which Application do you want to patch?", - "Patch application", - JOptionPane.QUESTION_MESSAGE, null, - applicationNames, applicationNames[0]); - - if(appName != null) - { - _liveDeploymentRoot.patch(appName); - } - } - } - }; - _patchApplication.setEnabled(false); - - _showApplicationDetails = new AbstractAction("Show details") - { - public void actionPerformed(ActionEvent e) - { - Object[] applicationNames = _liveDeploymentRoot.getApplicationNames(); - - if(applicationNames.length == 0) - { - JOptionPane.showMessageDialog( - _mainFrame, - "There is no application deployed in this IceGrid registry", - "No application", - JOptionPane.INFORMATION_MESSAGE); - } - else - { - String appName = (String)JOptionPane.showInputDialog( - _mainFrame, "Which Application do you to display", - "Show details", - JOptionPane.QUESTION_MESSAGE, null, - applicationNames, applicationNames[0]); - - if(appName != null) - { - _liveDeploymentRoot.showApplicationDetails(appName); - } - } - } - }; - _showApplicationDetails.setEnabled(false); + { + _mainFrame = mainFrame; + _prefs = prefs; + _initData = new Ice.InitializationData(); + + _initData.logger = new Logger(mainFrame); + _initData.properties = createProperties(args); + + if(args.value.length > 0) + { + String msg = "Extra command-line arguments: "; + for(int i = 0; i < args.value.length; ++i) + { + msg += args.value[i] + " "; + } + _initData.logger.warning(msg); + } + + _traceObservers = _initData.properties.getPropertyAsInt("IceGridAdmin.Trace.Observers") > 0; + _traceSaveToRegistry = _initData.properties.getPropertyAsInt("IceGridAdmin.Trace.SaveToRegistry") > 0; + + _liveDeploymentRoot = new IceGridGUI.LiveDeployment.Root(this); + + _sessionKeeper = new SessionKeeper(this); + + _shutdownHook = new Thread("Shutdown hook") + { + public void run() + { + destroyIceGridAdmin(); + destroyCommunicator(); + } + }; + Runtime.getRuntime().addShutdownHook(_shutdownHook); + + + _saveXMLChooser = new JFileChooser( + _prefs.get("current directory", null)); + + _saveXMLChooser.addChoosableFileFilter(new FileFilter() + { + public boolean accept(File f) + { + return f.isDirectory() || f.getName().endsWith(".xml"); + } + + public String getDescription() + { + return ".xml files"; + } + }); + + _saveLogChooser = new JFileChooser( + _prefs.get("current directory", null)); + + _saveLogChooser.addChoosableFileFilter(new FileFilter() + { + public boolean accept(File f) + { + return f.isDirectory() || + f.getName().endsWith(".out") || + f.getName().endsWith(".err") || + f.getName().endsWith(".log") || + f.getName().endsWith(".txt"); + } + + public String getDescription() + { + return ".out .err .log .txt files"; + } + }); + + javax.swing.UIManager.put("FileChooser.readOnly", Boolean.TRUE); + + _openChooser = new JFileChooser(_saveXMLChooser.getCurrentDirectory()); + + _openChooser.addChoosableFileFilter(_saveXMLChooser.getChoosableFileFilters()[1]); + + + 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) + { + _sessionKeeper.relog(true); + } + }; + _login.putValue(Action.SHORT_DESCRIPTION, + "Log into an IceGrid Registry"); + + _logout = new AbstractAction("Logout") + { + public void actionPerformed(ActionEvent e) + { + _sessionKeeper.logout(true); + } + }; + _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 = _openChooser.showOpenDialog(_mainFrame); + if(result == JFileChooser.APPROVE_OPTION) + { + File file = _openChooser.getSelectedFile(); + + ApplicationDescriptor desc = parseFile(file); + + if(desc != null) + { + IceGridGUI.Application.Root root; + try + { + root = new IceGridGUI.Application.Root(Coordinator.this, desc, false, file); + } + catch(IceGridGUI.Application.UpdateFailedException ex) + { + JOptionPane.showMessageDialog( + _mainFrame, + ex.toString(), + "Bad Application Descriptor: Unable load from file", + JOptionPane.ERROR_MESSAGE); + return; + } + + ApplicationPane app = new ApplicationPane(root); + _mainPane.addApplication(app); + _mainPane.setSelectedComponent(app); + root.setSelectedNode(root); + } + } + } + }; + _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(); + + if(applicationNames.length == 0) + { + JOptionPane.showMessageDialog( + _mainFrame, + "The registry does not contain any application", + "Empty registry", + JOptionPane.INFORMATION_MESSAGE); + } + else + { + 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) + { + ApplicationPane app = openLiveApplication(appName); + if(app != null) + { + IceGridGUI.Application.Root root = app.getRoot(); + if(root.getSelectedNode() == null) + { + root.setSelectedNode(root); + } + } + } + } + } + }; + _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"); + + if(System.getProperty("os.name").startsWith("Mac OS")) + { + _closeApplication.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_W, MENU_MASK)); + } + else + { + _closeApplication.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_F4, MENU_MASK)); + } + _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 and reload application"); + + + _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(); + } + }; + + _about = new AbstractAction("About") + { + public void actionPerformed(ActionEvent e) + { + about(); + } + }; + + _patchApplication = new AbstractAction("Patch Distribution") + { + public void actionPerformed(ActionEvent e) + { + Object[] applicationNames = _liveDeploymentRoot.getPatchableApplicationNames(); + + if(applicationNames.length == 0) + { + JOptionPane.showMessageDialog( + _mainFrame, + "No application in this IceGrid registry can be patched", + "No application", + JOptionPane.INFORMATION_MESSAGE); + } + else + { + String appName = (String)JOptionPane.showInputDialog( + _mainFrame, "Which Application do you want to patch?", + "Patch application", + JOptionPane.QUESTION_MESSAGE, null, + applicationNames, applicationNames[0]); + + if(appName != null) + { + _liveDeploymentRoot.patch(appName); + } + } + } + }; + _patchApplication.setEnabled(false); + + _showApplicationDetails = new AbstractAction("Show details") + { + public void actionPerformed(ActionEvent e) + { + Object[] applicationNames = _liveDeploymentRoot.getApplicationNames(); + + if(applicationNames.length == 0) + { + JOptionPane.showMessageDialog( + _mainFrame, + "There is no application deployed in this IceGrid registry", + "No application", + JOptionPane.INFORMATION_MESSAGE); + } + else + { + String appName = (String)JOptionPane.showInputDialog( + _mainFrame, "Which Application do you to display", + "Show details", + JOptionPane.QUESTION_MESSAGE, null, + applicationNames, applicationNames[0]); + + if(appName != null) + { + _liveDeploymentRoot.showApplicationDetails(appName); + } + } + } + }; + _showApplicationDetails.setEnabled(false); - _removeApplicationFromRegistry = new AbstractAction("Remove from Registry") - { - public void actionPerformed(ActionEvent e) - { - Object[] applicationNames = _liveDeploymentRoot.getApplicationNames(); - - if(applicationNames.length == 0) - { - JOptionPane.showMessageDialog( - _mainFrame, - "There is no application deployed in this IceGrid registry", - "No application", - JOptionPane.INFORMATION_MESSAGE); - } - else - { - String appName = (String)JOptionPane.showInputDialog( - _mainFrame, "Which Application do you want to remove?", - "Remove application", - JOptionPane.QUESTION_MESSAGE, null, - applicationNames, applicationNames[0]); - - if(appName != null) - { - removeApplicationFromRegistry(appName); - } - } - } - }; - _removeApplicationFromRegistry.setEnabled(false); - - - _cut = new ActionWrapper("Cut"); - _cut.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_X, MENU_MASK)); - _cut.putValue(Action.SHORT_DESCRIPTION, "Cut"); - - _copy = new ActionWrapper("Copy"); - _copy.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); - _copy.putValue(Action.SHORT_DESCRIPTION, "Copy"); - - _paste = new ActionWrapper("Paste"); - _paste.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_V, MENU_MASK)); - _paste.putValue(Action.SHORT_DESCRIPTION, "Paste"); - - _delete = new ActionWrapper("Delete"); - _delete.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke("DELETE")); - _delete.putValue(Action.SHORT_DESCRIPTION, "Delete"); - - _moveUp = new ActionWrapper("Move Up"); - _moveDown = new ActionWrapper("Move Down"); - - _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); + _removeApplicationFromRegistry = new AbstractAction("Remove from Registry") + { + public void actionPerformed(ActionEvent e) + { + Object[] applicationNames = _liveDeploymentRoot.getApplicationNames(); + + if(applicationNames.length == 0) + { + JOptionPane.showMessageDialog( + _mainFrame, + "There is no application deployed in this IceGrid registry", + "No application", + JOptionPane.INFORMATION_MESSAGE); + } + else + { + String appName = (String)JOptionPane.showInputDialog( + _mainFrame, "Which Application do you want to remove?", + "Remove application", + JOptionPane.QUESTION_MESSAGE, null, + applicationNames, applicationNames[0]); + + if(appName != null) + { + removeApplicationFromRegistry(appName); + } + } + } + }; + _removeApplicationFromRegistry.setEnabled(false); + + + _cut = new ActionWrapper("Cut"); + _cut.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_X, MENU_MASK)); + _cut.putValue(Action.SHORT_DESCRIPTION, "Cut"); + + _copy = new ActionWrapper("Copy"); + _copy.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); + _copy.putValue(Action.SHORT_DESCRIPTION, "Copy"); + + _paste = new ActionWrapper("Paste"); + _paste.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_V, MENU_MASK)); + _paste.putValue(Action.SHORT_DESCRIPTION, "Paste"); + + _delete = new ActionWrapper("Delete"); + _delete.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke("DELETE")); + _delete.putValue(Action.SHORT_DESCRIPTION, "Delete"); + + _moveUp = new ActionWrapper("Move Up"); + _moveDown = new ActionWrapper("Move Down"); + + _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); + _mainFrame.getContentPane().add((StatusBarI)_statusBar, + BorderLayout.PAGE_END); - - java.awt.KeyboardFocusManager kbm = java.awt.KeyboardFocusManager. - getCurrentKeyboardFocusManager(); - kbm.addPropertyChangeListener("permanentFocusOwner", new FocusListener()); - - _liveDeploymentPane = new LiveDeploymentPane(_liveDeploymentRoot); - _mainPane = new MainPane(this); - _mainFrame.getContentPane().add(_mainPane, BorderLayout.CENTER); + + java.awt.KeyboardFocusManager kbm = java.awt.KeyboardFocusManager. + getCurrentKeyboardFocusManager(); + kbm.addPropertyChangeListener("permanentFocusOwner", new FocusListener()); + + _liveDeploymentPane = new LiveDeploymentPane(_liveDeploymentRoot); + _mainPane = new MainPane(this); + _mainFrame.getContentPane().add(_mainPane, BorderLayout.CENTER); } JComponent getLiveDeploymentPane() { - return _liveDeploymentPane; + return _liveDeploymentPane; } public IceGridGUI.LiveDeployment.Root getLiveDeploymentRoot() { - return _liveDeploymentRoot; + 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()), - "", - new java.util.HashMap()); - IceGridGUI.Application.Root root = new IceGridGUI.Application.Root(this, desc); - ApplicationPane app = new ApplicationPane(root); - _mainPane.addApplication(app); - _mainPane.setSelectedComponent(app); - root.setSelectedNode(root); + 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()), + "", + new java.util.HashMap()); + 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 = getAdmin().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)); - } + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try + { + ApplicationDescriptor descriptor = getAdmin().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)); + } } private void helpContents() @@ -2392,54 +2392,54 @@ public class Coordinator private void about() { - String text = "IceGrid Admin version " - + IceUtil.Version.ICE_STRING_VERSION + "\n" - + "Copyright \u00A9 2005-2007 ZeroC, Inc. All rights reserved.\n"; - - JOptionPane.showMessageDialog( - _mainFrame, - text, - "About - IceGrid Admin", - JOptionPane.INFORMATION_MESSAGE); + String text = "IceGrid Admin version " + + IceUtil.Version.ICE_STRING_VERSION + "\n" + + "Copyright \u00A9 2005-2007 ZeroC, Inc. All rights reserved.\n"; + + JOptionPane.showMessageDialog( + _mainFrame, + text, + "About - IceGrid Admin", + JOptionPane.INFORMATION_MESSAGE); } public void setClipboard(Object copy) { - _clipboard = copy; + _clipboard = copy; } public Object getClipboard() { - return _clipboard; + return _clipboard; } void showMainFrame() { - if(!loadWindowPrefs()) - { - _mainFrame.setLocation(100, 100); - _mainFrame.pack(); - } - _mainFrame.setVisible(true); + if(!loadWindowPrefs()) + { + _mainFrame.setLocation(100, 100); + _mainFrame.pack(); + } + _mainFrame.setVisible(true); } void exit(int status) { - if(_openChooser != null) - { - File dir = _openChooser.getCurrentDirectory(); - if(dir != null) - { - _prefs.put("current directory", dir.getAbsolutePath()); - } - } - - storeWindowPrefs(); - destroyIceGridAdmin(); - destroyCommunicator(); - Runtime.getRuntime().removeShutdownHook(_shutdownHook); - _mainFrame.dispose(); - Runtime.getRuntime().exit(status); + if(_openChooser != null) + { + File dir = _openChooser.getCurrentDirectory(); + if(dir != null) + { + _prefs.put("current directory", dir.getAbsolutePath()); + } + } + + storeWindowPrefs(); + destroyIceGridAdmin(); + destroyCommunicator(); + Runtime.getRuntime().removeShutdownHook(_shutdownHook); + _mainFrame.dispose(); + Runtime.getRuntime().exit(status); } // @@ -2447,185 +2447,185 @@ public class Coordinator // private void destroyCommunicator() { - if(_communicator != null) - { - try - { - _communicator.destroy(); - } - catch(Ice.LocalException e) - { - System.err.println("_communicator.destroy() raised " - + e.toString()); - e.printStackTrace(); - } - _communicator = null; - } + if(_communicator != null) + { + try + { + _communicator.destroy(); + } + catch(Ice.LocalException e) + { + System.err.println("_communicator.destroy() raised " + + e.toString()); + e.printStackTrace(); + } + _communicator = null; + } } 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; + 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); + 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 AdminSessionPrx getSession() { - return _sessionKeeper.getSession(); + return _sessionKeeper.getSession(); } public boolean connectedToMaster() { - return _sessionKeeper.connectedToMaster(); + return _sessionKeeper.connectedToMaster(); } SessionKeeper getSessionKeeper() { - return _sessionKeeper; + return _sessionKeeper; } public Preferences getPrefs() { - return _prefs; + return _prefs; } public LiveActions getLiveActionsForPopup() { - return _liveActionsForPopup; + return _liveActionsForPopup; } public LiveActions getLiveActionsForMenu() { - return _liveActionsForMenu; + return _liveActionsForMenu; } public ApplicationActions getActionsForMenu() { - return _appActionsForMenu; + return _appActionsForMenu; } public ApplicationActions getActionsForPopup() { - return _appActionsForPopup; + 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]); - - _registryMenu.setEnabled( - availableActions[IceGridGUI.LiveDeployment.TreeNode.ADD_OBJECT] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_REGISTRY]); - - _signalMenu.setEnabled( - availableActions[IceGridGUI.LiveDeployment.TreeNode.SIGHUP]); - - _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.PATCH_SERVER] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.WRITE_MESSAGE] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDOUT] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDERR] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG] || - availableActions[IceGridGUI.LiveDeployment.TreeNode.SIGHUP]); - - _serviceMenu.setEnabled( - availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG]); - } - + 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]); + + _registryMenu.setEnabled( + availableActions[IceGridGUI.LiveDeployment.TreeNode.ADD_OBJECT] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.SHUTDOWN_REGISTRY]); + + _signalMenu.setEnabled( + availableActions[IceGridGUI.LiveDeployment.TreeNode.SIGHUP]); + + _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.PATCH_SERVER] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.WRITE_MESSAGE] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDOUT] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_STDERR] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG] || + availableActions[IceGridGUI.LiveDeployment.TreeNode.SIGHUP]); + + _serviceMenu.setEnabled( + availableActions[IceGridGUI.LiveDeployment.TreeNode.RETRIEVE_LOG]); + } + 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); - _registryMenu.setEnabled(false); - _signalMenu.setEnabled(false); - _serverMenu.setEnabled(false); - _serviceMenu.setEnabled(false); + 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); + _registryMenu.setEnabled(false); + _signalMenu.setEnabled(false); + _serverMenu.setEnabled(false); + _serviceMenu.setEnabled(false); } public boolean traceObservers() { - return _traceObservers; + return _traceObservers; } public void traceObserver(String message) { - trace("Observers", message); + trace("Observers", message); } public boolean traceSaveToRegistry() { - return _traceSaveToRegistry; + return _traceSaveToRegistry; } public void traceSaveToRegistry(String message) { - trace("SaveToRegistry", message); + trace("SaveToRegistry", message); } // @@ -2633,11 +2633,11 @@ public class Coordinator // private void trace(String category, String message) { - // - // It would be nicer to use the communicator's logger, - // but accessing _communicator is not thread-safe. - // - _initData.logger.trace(category, message); + // + // It would be nicer to use the communicator's logger, + // but accessing _communicator is not thread-safe. + // + _initData.logger.trace(category, message); } diff --git a/java/src/IceGridGUI/EditorBase.java b/java/src/IceGridGUI/EditorBase.java index 01bef75c8e1..985a5ceb3ae 100755 --- a/java/src/IceGridGUI/EditorBase.java +++ b/java/src/IceGridGUI/EditorBase.java @@ -29,42 +29,42 @@ public abstract class EditorBase { public JComponent getProperties() { - if(_propertiesPanel == null) - { - buildPropertiesPanel(); - } - return _propertiesPanel; + if(_propertiesPanel == null) + { + buildPropertiesPanel(); + } + return _propertiesPanel; } public JToolBar getToolBar() { - return null; + return null; } 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); + 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/IceGridGUI/LiveActions.java b/java/src/IceGridGUI/LiveActions.java index 1c847da7aea..0a66db5911b 100755 --- a/java/src/IceGridGUI/LiveActions.java +++ b/java/src/IceGridGUI/LiveActions.java @@ -22,179 +22,179 @@ public class LiveActions { class SendSignal extends AbstractAction { - SendSignal(String name) - { - super(name); - _name = name; - putValue(Action.SHORT_DESCRIPTION, - "Send " + _name); - } - - public void actionPerformed(ActionEvent e) - { - _target.signal(_name); - } - private String _name; + SendSignal(String name) + { + super(name); + _name = name; + putValue(Action.SHORT_DESCRIPTION, + "Send " + _name); + } + + public void actionPerformed(ActionEvent e) + { + _target.signal(_name); + } + private String _name; }; public Action get(int index) { - return _array[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; + _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.SIGHUP] = new SendSignal("SIGHUP"); - _array[TreeNode.SIGINT] = new SendSignal("SIGINT"); - _array[TreeNode.SIGQUIT] = new SendSignal("SIGQUIT"); - _array[TreeNode.SIGKILL] = new SendSignal("SIGKILL"); - _array[TreeNode.SIGUSR1] = new SendSignal("SIGUSR1"); - _array[TreeNode.SIGUSR2] = new SendSignal("SIGUSR2"); - _array[TreeNode.SIGTERM] = new SendSignal("SIGTERM"); - - _array[TreeNode.WRITE_MESSAGE] = new AbstractAction("Write Message") - { - public void actionPerformed(ActionEvent e) - { - _target.writeMessage(); - } - }; - _array[TreeNode.WRITE_MESSAGE].putValue(Action.SHORT_DESCRIPTION, - "Write message to stdout or stderr"); - - - _array[TreeNode.RETRIEVE_STDOUT] = new AbstractAction("Retrieve stdout") - { - public void actionPerformed(ActionEvent e) - { - _target.retrieveOutput(true); - } - }; - _array[TreeNode.RETRIEVE_STDOUT].putValue(Action.SHORT_DESCRIPTION, - "Retrieve stdout"); - - _array[TreeNode.RETRIEVE_STDERR] = new AbstractAction("Retrieve stderr") - { - public void actionPerformed(ActionEvent e) - { - _target.retrieveOutput(false); - } - }; - _array[TreeNode.RETRIEVE_STDERR].putValue(Action.SHORT_DESCRIPTION, - "Retrieve stderr"); - - _array[TreeNode.RETRIEVE_LOG] = new AbstractAction("Retrieve Log") - { - public void actionPerformed(ActionEvent e) - { - _target.retrieveLog(); - } - }; - _array[TreeNode.RETRIEVE_LOG].putValue(Action.SHORT_DESCRIPTION, - "Retrieve log file from the server"); - - - _array[TreeNode.SHUTDOWN_NODE] = new AbstractAction("Shutdown") - { - public void actionPerformed(ActionEvent e) - { - _target.shutdownNode(); - } - }; - - _array[TreeNode.SHUTDOWN_REGISTRY] = new AbstractAction("Shutdown") - { - public void actionPerformed(ActionEvent e) - { - _target.shutdownRegistry(); - } - }; - - _array[TreeNode.PATCH_SERVER] = - new AbstractAction("Patch Distribution") - { - public void actionPerformed(ActionEvent e) - { - _target.patchServer(); - } - }; - - _array[TreeNode.ADD_OBJECT] = - new AbstractAction("Add Well-known Object") - { - public void actionPerformed(ActionEvent e) - { - _target.addObject(); - } - }; + _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.SIGHUP] = new SendSignal("SIGHUP"); + _array[TreeNode.SIGINT] = new SendSignal("SIGINT"); + _array[TreeNode.SIGQUIT] = new SendSignal("SIGQUIT"); + _array[TreeNode.SIGKILL] = new SendSignal("SIGKILL"); + _array[TreeNode.SIGUSR1] = new SendSignal("SIGUSR1"); + _array[TreeNode.SIGUSR2] = new SendSignal("SIGUSR2"); + _array[TreeNode.SIGTERM] = new SendSignal("SIGTERM"); + + _array[TreeNode.WRITE_MESSAGE] = new AbstractAction("Write Message") + { + public void actionPerformed(ActionEvent e) + { + _target.writeMessage(); + } + }; + _array[TreeNode.WRITE_MESSAGE].putValue(Action.SHORT_DESCRIPTION, + "Write message to stdout or stderr"); + + + _array[TreeNode.RETRIEVE_STDOUT] = new AbstractAction("Retrieve stdout") + { + public void actionPerformed(ActionEvent e) + { + _target.retrieveOutput(true); + } + }; + _array[TreeNode.RETRIEVE_STDOUT].putValue(Action.SHORT_DESCRIPTION, + "Retrieve stdout"); + + _array[TreeNode.RETRIEVE_STDERR] = new AbstractAction("Retrieve stderr") + { + public void actionPerformed(ActionEvent e) + { + _target.retrieveOutput(false); + } + }; + _array[TreeNode.RETRIEVE_STDERR].putValue(Action.SHORT_DESCRIPTION, + "Retrieve stderr"); + + _array[TreeNode.RETRIEVE_LOG] = new AbstractAction("Retrieve Log") + { + public void actionPerformed(ActionEvent e) + { + _target.retrieveLog(); + } + }; + _array[TreeNode.RETRIEVE_LOG].putValue(Action.SHORT_DESCRIPTION, + "Retrieve log file from the server"); + + + _array[TreeNode.SHUTDOWN_NODE] = new AbstractAction("Shutdown") + { + public void actionPerformed(ActionEvent e) + { + _target.shutdownNode(); + } + }; + + _array[TreeNode.SHUTDOWN_REGISTRY] = new AbstractAction("Shutdown") + { + public void actionPerformed(ActionEvent e) + { + _target.shutdownRegistry(); + } + }; + + _array[TreeNode.PATCH_SERVER] = + new AbstractAction("Patch Distribution") + { + public void actionPerformed(ActionEvent e) + { + _target.patchServer(); + } + }; + + _array[TreeNode.ADD_OBJECT] = + new AbstractAction("Add Well-known Object") + { + public void actionPerformed(ActionEvent e) + { + _target.addObject(); + } + }; } private TreeNode _target; diff --git a/java/src/IceGridGUI/LiveDeployment/Adapter.java b/java/src/IceGridGUI/LiveDeployment/Adapter.java index 546f9ffa43c..48cd5e4d1e2 100755 --- a/java/src/IceGridGUI/LiveDeployment/Adapter.java +++ b/java/src/IceGridGUI/LiveDeployment/Adapter.java @@ -26,137 +26,137 @@ class Adapter extends TreeNode { public Editor getEditor() { - if(_editor == null) - { - _editor = new AdapterEditor(); - } - _editor.show(this); - return _editor; + 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) + 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); + 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) + String adapterId, AdapterDescriptor descriptor, Ice.ObjectPrx proxy) { - super(parent, adapterName); - _resolver = resolver; - _adapterId = adapterId; - _descriptor = descriptor; + super(parent, adapterName); + _resolver = resolver; + _adapterId = adapterId; + _descriptor = descriptor; - setCurrentEndpoints(proxy); + setCurrentEndpoints(proxy); } AdapterDescriptor getDescriptor() { - return _descriptor; + return _descriptor; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } String getCurrentEndpoints() { - return _currentEndpoints; + return _currentEndpoints; } java.util.Map getProperties() { - if(_parent instanceof Server) - { - return ((Server)_parent).getProperties(); - } - else - { - return ((Service)_parent).getProperties(); - } + if(_parent instanceof Server) + { + return ((Server)_parent).getProperties(); + } + else + { + return ((Service)_parent).getProperties(); + } } 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; - } + 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; + 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 = proxy.toString(); - int index = str.indexOf(':'); - if(index == -1 || index == str.length() - 1) - { - _currentEndpoints = ""; - } - else - { - _currentEndpoints = str.substring(index + 1); - } - _toolTip = "Published endpoints: " + _currentEndpoints; - } + if(proxy == null) + { + _currentEndpoints = null; + _toolTip = "Inactive"; + } + else + { + String str = proxy.toString(); + int index = str.indexOf(':'); + if(index == -1 || index == str.length() - 1) + { + _currentEndpoints = ""; + } + else + { + _currentEndpoints = str.substring(index + 1); + } + _toolTip = "Published endpoints: " + _currentEndpoints; + } } diff --git a/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java b/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java index 2e77071fdba..f4b64e8a23d 100755 --- a/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/AdapterEditor.java @@ -30,141 +30,141 @@ class AdapterEditor extends Editor { AdapterEditor() { - _currentStatus.setEditable(false); - _currentEndpoints.setEditable(false); - _description.setEditable(false); - _description.setOpaque(false); - _id.setEditable(false); - _replicaGroupId.setEditable(false); - _priority.setEditable(false); - _endpoints.setEditable(false); - _publishedEndpoints.setEditable(false); - _registerProcess.setEnabled(false); - _serverLifetime.setEnabled(false); + _currentStatus.setEditable(false); + _currentEndpoints.setEditable(false); + _description.setEditable(false); + _description.setOpaque(false); + _id.setEditable(false); + _replicaGroupId.setEditable(false); + _priority.setEditable(false); + _endpoints.setEditable(false); + _publishedEndpoints.setEditable(false); + _registerProcess.setEnabled(false); + _serverLifetime.setEnabled(false); } void show(Adapter adapter) { - AdapterDescriptor descriptor = adapter.getDescriptor(); - Utils.Resolver resolver = adapter.getResolver(); - - _id.setText(resolver.substitute(descriptor.id)); - - String currentEndpoints = adapter.getCurrentEndpoints(); - - if(currentEndpoints == null) - { - _currentStatus.setText("Inactive"); - _currentEndpoints.setText(""); - } - else - { - _currentStatus.setText("Active"); - _currentEndpoints.setText(currentEndpoints); - } - - _description.setText(resolver.substitute(descriptor.description)); - _replicaGroupId.setText(resolver.substitute(descriptor.replicaGroupId)); - _priority.setText(resolver.substitute(descriptor.priority)); - - java.util.Map properties = adapter.getProperties(); - - // getId() returns the name of the adapter! - _endpoints.setText(resolver.substitute((String)properties.get("Ice.OA." + adapter.getId() + ".Endpoints"))); - _publishedEndpoints.setText( - resolver.substitute((String)properties.get("Ice.OA." + adapter.getId() + ".PublishedEndpoints"))); - - _registerProcess.setSelected(descriptor.registerProcess); - _serverLifetime.setSelected(descriptor.serverLifetime); - - _objects.setObjects(descriptor.objects, resolver); - _allocatables.setObjects(descriptor.allocatables, resolver); + AdapterDescriptor descriptor = adapter.getDescriptor(); + Utils.Resolver resolver = adapter.getResolver(); + + _id.setText(resolver.substitute(descriptor.id)); + + String currentEndpoints = adapter.getCurrentEndpoints(); + + if(currentEndpoints == null) + { + _currentStatus.setText("Inactive"); + _currentEndpoints.setText(""); + } + else + { + _currentStatus.setText("Active"); + _currentEndpoints.setText(currentEndpoints); + } + + _description.setText(resolver.substitute(descriptor.description)); + _replicaGroupId.setText(resolver.substitute(descriptor.replicaGroupId)); + _priority.setText(resolver.substitute(descriptor.priority)); + + java.util.Map properties = adapter.getProperties(); + + // getId() returns the name of the adapter! + _endpoints.setText(resolver.substitute((String)properties.get("Ice.OA." + adapter.getId() + ".Endpoints"))); + _publishedEndpoints.setText( + resolver.substitute((String)properties.get("Ice.OA." + adapter.getId() + ".PublishedEndpoints"))); + + _registerProcess.setSelected(descriptor.registerProcess); + _serverLifetime.setSelected(descriptor.serverLifetime); + + _objects.setObjects(descriptor.objects, resolver); + _allocatables.setObjects(descriptor.allocatables, resolver); } 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("Priority"); - builder.append(_priority, 3); - builder.nextLine(); - - builder.append("Endpoints"); - builder.append(_endpoints, 3); - builder.nextLine(); - - builder.append("Published Endpoints"); - builder.append(_publishedEndpoints, 3); - builder.nextLine(); - - builder.append("", _registerProcess); - builder.nextLine(); - builder.append("", _serverLifetime); - builder.nextLine(); - - builder.append("Well-known Objects"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_objects); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); - - builder.append("Allocatable Objects"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - scrollPane = new JScrollPane(_allocatables); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + 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("Priority"); + builder.append(_priority, 3); + builder.nextLine(); + + builder.append("Endpoints"); + builder.append(_endpoints, 3); + builder.nextLine(); + + builder.append("Published Endpoints"); + builder.append(_publishedEndpoints, 3); + builder.nextLine(); + + builder.append("", _registerProcess); + builder.nextLine(); + builder.append("", _serverLifetime); + builder.nextLine(); + + builder.append("Well-known Objects"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_objects); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); + + builder.append("Allocatable Objects"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + scrollPane = new JScrollPane(_allocatables); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Adapter Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Adapter Properties"); } private JTextField _currentStatus = new JTextField(20); diff --git a/java/src/IceGridGUI/LiveDeployment/ApplicationDetailsDialog.java b/java/src/IceGridGUI/LiveDeployment/ApplicationDetailsDialog.java index e6865e63bc2..3f8ac8ba611 100644 --- a/java/src/IceGridGUI/LiveDeployment/ApplicationDetailsDialog.java +++ b/java/src/IceGridGUI/LiveDeployment/ApplicationDetailsDialog.java @@ -38,59 +38,59 @@ class ApplicationDetailsDialog extends JDialog { ApplicationDetailsDialog(final Root root) { - super(root.getCoordinator().getMainFrame(), - "Application Details - IceGrid Admin", true); - setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); - _mainFrame = root.getCoordinator().getMainFrame(); + super(root.getCoordinator().getMainFrame(), + "Application Details - IceGrid Admin", true); + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); + _mainFrame = root.getCoordinator().getMainFrame(); - _name.setEditable(false); - _uuid.setEditable(false); - _createTime.setEditable(false); - _createUser.setEditable(false); - _updateTime.setEditable(false); - _updateUser.setEditable(false); - _revision.setEditable(false); - - FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - builder.append("Name", _name); - builder.nextLine(); - builder.append("UUID", _uuid); - builder.nextLine(); - builder.append("Created", _createTime); - builder.nextLine(); - builder.append("Created by", _createUser); - builder.nextLine(); - builder.append("Last Update", _updateTime); - builder.nextLine(); - builder.append("Updated by", _updateUser); - builder.nextLine(); - builder.append("Revision", _revision); - builder.nextLine(); + _name.setEditable(false); + _uuid.setEditable(false); + _createTime.setEditable(false); + _createUser.setEditable(false); + _updateTime.setEditable(false); + _updateUser.setEditable(false); + _revision.setEditable(false); + + FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + builder.append("Name", _name); + builder.nextLine(); + builder.append("UUID", _uuid); + builder.nextLine(); + builder.append("Created", _createTime); + builder.nextLine(); + builder.append("Created by", _createUser); + builder.nextLine(); + builder.append("Last Update", _updateTime); + builder.nextLine(); + builder.append("Updated by", _updateUser); + builder.nextLine(); + builder.append("Revision", _revision); + builder.nextLine(); - Container contentPane = getContentPane(); - contentPane.add(builder.getPanel()); - - pack(); - setResizable(false); + Container contentPane = getContentPane(); + contentPane.add(builder.getPanel()); + + pack(); + setResizable(false); } void showDialog(ApplicationInfo info) { - _name.setText(info.descriptor.name); - _uuid.setText(info.uuid); - _createTime.setText(java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(info.createTime))); - _createUser.setText(info.createUser); - _updateTime.setText(java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(info.updateTime))); - _updateUser.setText(info.updateUser); - _revision.setText(Integer.toString(info.revision)); + _name.setText(info.descriptor.name); + _uuid.setText(info.uuid); + _createTime.setText(java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(info.createTime))); + _createUser.setText(info.createUser); + _updateTime.setText(java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(info.updateTime))); + _updateUser.setText(info.updateUser); + _revision.setText(Integer.toString(info.revision)); - setLocationRelativeTo(_mainFrame); - setVisible(true); + setLocationRelativeTo(_mainFrame); + setVisible(true); } private JTextField _name = new JTextField(30); diff --git a/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java b/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java index d356d00f249..a443db8949d 100755 --- a/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/CommunicatorEditor.java @@ -21,46 +21,46 @@ class CommunicatorEditor extends Editor { protected CommunicatorEditor() { - _description.setEditable(false); - _description.setOpaque(false); + _description.setEditable(false); + _description.setOpaque(false); } protected void show(CommunicatorDescriptor descriptor, - java.util.SortedMap properties, - Utils.Resolver resolver) + java.util.SortedMap properties, + Utils.Resolver resolver) { - _description.setText(resolver.substitute(descriptor.description)); - _properties.setSortedMap(properties); + _description.setText(resolver.substitute(descriptor.description)); + _properties.setSortedMap(properties); } 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.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.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(); + 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); diff --git a/java/src/IceGridGUI/LiveDeployment/DbEnv.java b/java/src/IceGridGUI/LiveDeployment/DbEnv.java index c6656dbeeb6..98a98051fb7 100755 --- a/java/src/IceGridGUI/LiveDeployment/DbEnv.java +++ b/java/src/IceGridGUI/LiveDeployment/DbEnv.java @@ -21,50 +21,50 @@ import IceGridGUI.*; class DbEnv extends TreeNode { public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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); + 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; + if(_editor == null) + { + _editor = new DbEnvEditor(); + } + _editor.show(this); + return _editor; } DbEnv(TreeNode parent, String dbEnvName, Utils.Resolver resolver, - DbEnvDescriptor descriptor) + DbEnvDescriptor descriptor) { - super(parent, dbEnvName); - _resolver = resolver; - _descriptor = descriptor; + super(parent, dbEnvName); + _resolver = resolver; + _descriptor = descriptor; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } DbEnvDescriptor getDescriptor() { - return _descriptor; + return _descriptor; } private Utils.Resolver _resolver; diff --git a/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java b/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java index 76e9b8870cb..d97f22668ad 100755 --- a/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/DbEnvEditor.java @@ -26,68 +26,68 @@ class DbEnvEditor extends Editor { DbEnvEditor() { - _description.setEditable(false); - _description.setOpaque(false); - _dbHome.setEditable(false); + _description.setEditable(false); + _description.setOpaque(false); + _dbHome.setEditable(false); } void show(DbEnv dbEnv) { - DbEnvDescriptor descriptor = dbEnv.getDescriptor(); - Utils.Resolver resolver = dbEnv.getResolver(); - _description.setText(resolver.substitute(descriptor.description)); + 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)); - } + if(descriptor.dbHome.length() == 0) + { + _dbHome.setText("Created by the IceGrid Node"); + } + else + { + _dbHome.setText(resolver.substitute(descriptor.dbHome)); + } - _properties.setProperties(descriptor.properties, resolver); + _properties.setProperties(descriptor.properties, resolver); } 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("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("Properties"); + builder.nextLine(); - builder.append(""); - builder.nextLine(); + builder.append(""); + 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(); + 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("Database Environment Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Database Environment Properties"); } private JTextArea _description = new JTextArea(3, 20); diff --git a/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java b/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java index 5835e1a1ece..2428af55fa4 100755 --- a/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java +++ b/java/src/IceGridGUI/LiveDeployment/ListArrayTreeNode.java @@ -20,120 +20,120 @@ 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; - } + 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 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; + 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); + 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; + 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; + 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; + 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]; + 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 index 96275ac1af1..ae7bebdd1ef 100755 --- a/java/src/IceGridGUI/LiveDeployment/ListTreeNode.java +++ b/java/src/IceGridGUI/LiveDeployment/ListTreeNode.java @@ -20,61 +20,61 @@ abstract class ListTreeNode extends TreeNode { public Enumeration children() { - return new Enumeration() - { - public boolean hasMoreElements() - { - return _p.hasNext(); - } + return new Enumeration() + { + public boolean hasMoreElements() + { + return _p.hasNext(); + } - public Object nextElement() - { - return _p.next(); - } - - private java.util.Iterator _p = _children.iterator(); - }; + public Object nextElement() + { + return _p.next(); + } + + private java.util.Iterator _p = _children.iterator(); + }; } public boolean getAllowsChildren() { - return true; + 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); - } + 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(); + return _children.size(); } public int getIndex(javax.swing.tree.TreeNode node) { - return _children.indexOf(node); + return _children.indexOf(node); } public boolean isLeaf() { - return _children.isEmpty(); + return _children.isEmpty(); } protected ListTreeNode(TreeNode parent, String id) { - super(parent, 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 index 0b238b47206..704a7dfc8ed 100755 --- a/java/src/IceGridGUI/LiveDeployment/Node.java +++ b/java/src/IceGridGUI/LiveDeployment/Node.java @@ -34,902 +34,902 @@ class Node extends ListTreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[SHUTDOWN_NODE] = _up; - actions[RETRIEVE_STDOUT] = _up; - actions[RETRIEVE_STDERR] = _up; - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[SHUTDOWN_NODE] = _up; + actions[RETRIEVE_STDOUT] = _up; + actions[RETRIEVE_STDERR] = _up; + return actions; } public void retrieveOutput(final boolean stdout) { - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, NodeNotExistException, NodeUnreachableException - { - AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); - - if(stdout) - { - return adminSession.openNodeStdOut(_id, count); - } - else - { - return adminSession.openNodeStdErr(_id, count); - } - } - - public String getTitle() - { - return "Node " + _id + " " + (stdout ? "stdout" : "stderr"); - } - - public String getDefaultFilename() - { - return _id + (stdout ? ".out" : ".err"); - } - }); + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, NodeNotExistException, NodeUnreachableException + { + AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); + + if(stdout) + { + return adminSession.openNodeStdOut(_id, count); + } + else + { + return adminSession.openNodeStdErr(_id, count); + } + } + + public String getTitle() + { + return "Node " + _id + " " + (stdout ? "stdout" : "stderr"); + } + + public String getDefaultFilename() + { + return _id + (stdout ? ".out" : ".err"); + } + }); } 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)); - } + 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(RETRIEVE_STDOUT)); - _popup.add(la.get(RETRIEVE_STDERR)); - _popup.addSeparator(); - _popup.add(la.get(SHUTDOWN_NODE)); - } - - la.setTarget(this); - return _popup; + LiveActions la = getCoordinator().getLiveActionsForPopup(); + + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(la.get(RETRIEVE_STDOUT)); + _popup.add(la.get(RETRIEVE_STDERR)); + _popup.addSeparator(); + _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; + 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); + 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.info.name); - up(info, false); + super(parent, info.info.name); + up(info, false); } Node(Root parent, ApplicationDescriptor appDesc, - String nodeName, NodeDescriptor nodeDesc) + String nodeName, NodeDescriptor nodeDesc) { - super(parent, nodeName); - add(appDesc, 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 == null ? "" : update.loadFactor.value, - update.description == null ? "" : update.description.value, - update.propertySets); - - appDesc.nodes.put(_id, nodeDesc); - add(appDesc, nodeDesc); + super(parent, update.name); + + NodeDescriptor nodeDesc = new NodeDescriptor( + update.variables, + update.serverInstances, + update.servers, + update.loadFactor == null ? "" : update.loadFactor.value, + update.description == null ? "" : update.description.value, + update.propertySets); + + appDesc.nodes.put(_id, nodeDesc); + add(appDesc, nodeDesc); } Utils.ExpandedPropertySet expand(PropertySetDescriptor descriptor, - String applicationName, Utils.Resolver resolver) - { - Utils.ExpandedPropertySet result = new Utils.ExpandedPropertySet(); - result.references = new Utils.ExpandedPropertySet[descriptor.references.length]; - - for(int i = 0; i < descriptor.references.length; ++i) - { - result.references[i] = expand( - findNamedPropertySet(resolver.substitute(descriptor.references[i]), - applicationName), - applicationName, resolver); - } - - result.properties = descriptor.properties; - return result; + String applicationName, Utils.Resolver resolver) + { + Utils.ExpandedPropertySet result = new Utils.ExpandedPropertySet(); + result.references = new Utils.ExpandedPropertySet[descriptor.references.length]; + + for(int i = 0; i < descriptor.references.length; ++i) + { + result.references[i] = expand( + findNamedPropertySet(resolver.substitute(descriptor.references[i]), + applicationName), + applicationName, resolver); + } + + result.properties = descriptor.properties; + return result; } PropertySetDescriptor findNamedPropertySet(String name, String applicationName) { - ApplicationData appData = (ApplicationData)_map.get(applicationName); - if(appData != null) - { - NodeDescriptor descriptor = appData.descriptor; - PropertySetDescriptor result = (PropertySetDescriptor)descriptor.propertySets.get(name); - if(result != null) - { - return result; - } - } - return getRoot().findNamedPropertySet(name, applicationName); + ApplicationData appData = (ApplicationData)_map.get(applicationName); + if(appData != null) + { + NodeDescriptor descriptor = appData.descriptor; + PropertySetDescriptor result = (PropertySetDescriptor)descriptor.propertySets.get(name); + if(result != null) + { + return result; + } + } + return getRoot().findNamedPropertySet(name, applicationName); } 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); - putInfoVariables(data.resolver); - - _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)); - } + 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); + putInfoVariables(data.resolver); + + _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(index); - 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; + _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(index); + 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); - - if(data == null) - { - if(update != null) - { - NodeDescriptor nodeDesc = new NodeDescriptor( - update.variables, - update.serverInstances, - update.servers, - update.loadFactor == null ? "" : update.loadFactor.value, - update.description == null ? "" : update.description.value, - update.propertySets); - - appDesc.nodes.put(_id, nodeDesc); - add(appDesc, nodeDesc); - } - // - // Else, nothing to do. - // - - return; - } - - 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(); - } - - nodeDesc.propertySets.keySet().removeAll( - java.util.Arrays.asList(update.removePropertySets)); - nodeDesc.propertySets.putAll(update.propertySets); - - // - // Remove servers - // - for(int i = 0; i < update.removeServers.length; ++i) - { - Server server = findServer(update.removeServers[i]); - removeDescriptor(nodeDesc, server); - 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); - nodeDesc.serverInstances.add(desc); - } - else - { - removeDescriptor(nodeDesc, oldServer); - 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); - nodeDesc.servers.add(desc); - } - else - { - removeDescriptor(nodeDesc, oldServer); - oldServer.rebuild(server); - freshServers.add(oldServer); - nodeDesc.servers.add(desc); - } - } - } - - if(variablesChanged || !serviceTemplates.isEmpty() || !serverTemplates.isEmpty()) - { - // - // Rebuild every other server in this application - // - java.util.Iterator p = _children.iterator(); - while(p.hasNext()) - { - Server server = (Server)p.next(); - if(server.getApplication() == appDesc) - { - if(!freshServers.contains(server)) - { - server.rebuild(data.resolver, - variablesChanged, - serviceTemplates, serverTemplates); - } - } - } - } + boolean variablesChanged, java.util.Set serviceTemplates, + java.util.Set serverTemplates) + { + ApplicationData data = (ApplicationData)_map.get(appDesc.name); + + if(data == null) + { + if(update != null) + { + NodeDescriptor nodeDesc = new NodeDescriptor( + update.variables, + update.serverInstances, + update.servers, + update.loadFactor == null ? "" : update.loadFactor.value, + update.description == null ? "" : update.description.value, + update.propertySets); + + appDesc.nodes.put(_id, nodeDesc); + add(appDesc, nodeDesc); + } + // + // Else, nothing to do. + // + + return; + } + + 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(); + } + + nodeDesc.propertySets.keySet().removeAll( + java.util.Arrays.asList(update.removePropertySets)); + nodeDesc.propertySets.putAll(update.propertySets); + + // + // Remove servers + // + for(int i = 0; i < update.removeServers.length; ++i) + { + Server server = findServer(update.removeServers[i]); + removeDescriptor(nodeDesc, server); + 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); + nodeDesc.serverInstances.add(desc); + } + else + { + removeDescriptor(nodeDesc, oldServer); + 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); + nodeDesc.servers.add(desc); + } + else + { + removeDescriptor(nodeDesc, oldServer); + oldServer.rebuild(server); + freshServers.add(oldServer); + nodeDesc.servers.add(desc); + } + } + } + + if(variablesChanged || !serviceTemplates.isEmpty() || !serverTemplates.isEmpty()) + { + // + // Rebuild every other server in this application + // + java.util.Iterator p = _children.iterator(); + while(p.hasNext()) + { + Server server = (Server)p.next(); + if(server.getApplication() == appDesc) + { + if(!freshServers.contains(server)) + { + server.rebuild(data.resolver, + variablesChanged, + serviceTemplates, serverTemplates); + } + } + } + } } NodeInfo getStaticInfo() { - if(_info == null) - { - return null; - } - else - { - return _info.info; - } + if(_info == null) + { + return null; + } + else + { + return _info.info; + } } boolean isRunningWindows() { - return _windows; + return _windows; } private boolean putInfoVariables(Utils.Resolver resolver) { - if(_info == null) - { - return false; - } - else - { - boolean updated = resolver.put("node.os", _info.info.os); - updated = resolver.put("node.hostname", _info.info.hostname) || updated; - updated = resolver.put("node.release", _info.info.release) || updated; - updated = resolver.put("node.version", _info.info.version) || updated; - updated = resolver.put("node.machine", _info.info.machine) || updated; - updated = resolver.put("node.datadir", _info.info.dataDir) || updated; - return updated; - } + if(_info == null) + { + return false; + } + else + { + boolean updated = resolver.put("node.os", _info.info.os); + updated = resolver.put("node.hostname", _info.info.hostname) || updated; + updated = resolver.put("node.release", _info.info.release) || updated; + updated = resolver.put("node.version", _info.info.version) || updated; + updated = resolver.put("node.machine", _info.info.machine) || updated; + updated = resolver.put("node.datadir", _info.info.dataDir) || updated; + return updated; + } } void up(NodeDynamicInfo info, boolean fireEvent) { - _up = true; - _info = info; - _windows = info.info.os.toLowerCase().startsWith("windows"); - - // - // Update variables and rebuild all affected servers - // - java.util.Iterator p = _map.values().iterator(); - while(p.hasNext()) - { - ApplicationData data = (ApplicationData)p.next(); - - if(putInfoVariables(data.resolver)) - { - String appName = data.resolver.find("application"); - - java.util.Iterator q = _children.iterator(); - while(q.hasNext()) - { - Server server = (Server)q.next(); - if(server.getApplication().name.equals(appName)) - { - server.rebuild(data.resolver, true, null, null); - } - } - } - } - - // - // Tell every server on this node - // - java.util.Set updatedServers = new java.util.HashSet(); - 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); - } + _up = true; + _info = info; + _windows = info.info.os.toLowerCase().startsWith("windows"); + + // + // Update variables and rebuild all affected servers + // + java.util.Iterator p = _map.values().iterator(); + while(p.hasNext()) + { + ApplicationData data = (ApplicationData)p.next(); + + if(putInfoVariables(data.resolver)) + { + String appName = data.resolver.find("application"); + + java.util.Iterator q = _children.iterator(); + while(q.hasNext()) + { + Server server = (Server)q.next(); + if(server.getApplication().name.equals(appName)) + { + server.rebuild(data.resolver, true, null, null); + } + } + } + } + + // + // Tell every server on this node + // + java.util.Set updatedServers = new java.util.HashSet(); + 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; - } + _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); - } + 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; - } - } + 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.id.equals(adapterId)) - { - return ainfo.proxy; - } - } - } - return null; + if(_info != null) + { + java.util.ListIterator p = _info.adapters.listIterator(); + while(p.hasNext()) + { + AdapterDynamicInfo ainfo = (AdapterDynamicInfo)p.next(); + if(ainfo.id.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; + 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)); - } + 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); + 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); + 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()); + insertSortedChild(server, _children, getRoot().getTreeModel()); } private Server findServer(String id) { - return (Server)find(id, _children); + return (Server)find(id, _children); } private void removeDescriptor(NodeDescriptor nodeDesc, Server server) { - ServerInstanceDescriptor instanceDescriptor = - server.getInstanceDescriptor(); - if(instanceDescriptor != null) - { - removeDescriptor(nodeDesc, instanceDescriptor); - } - else - { - removeDescriptor(nodeDesc, server.getServerDescriptor()); - } + ServerInstanceDescriptor instanceDescriptor = + server.getInstanceDescriptor(); + if(instanceDescriptor != null) + { + removeDescriptor(nodeDesc, instanceDescriptor); + } + else + { + removeDescriptor(nodeDesc, server.getServerDescriptor()); + } } private void removeDescriptor(NodeDescriptor nodeDesc, ServerDescriptor sd) { - // - // A straight remove uses equals(), which is not the desired behavior - // - java.util.Iterator p = nodeDesc.servers.iterator(); - while(p.hasNext()) - { - if(sd == p.next()) - { - p.remove(); - break; - } - } + // + // A straight remove uses equals(), which is not the desired behavior + // + java.util.Iterator p = nodeDesc.servers.iterator(); + while(p.hasNext()) + { + if(sd == p.next()) + { + p.remove(); + break; + } + } } private void removeDescriptor(NodeDescriptor nodeDesc, ServerInstanceDescriptor sd) { - // - // A straight remove uses equals(), which is not the desired behavior - // - java.util.Iterator p = nodeDesc.serverInstances.iterator(); - while(p.hasNext()) - { - if(sd == p.next()) - { - p.remove(); - break; - } - } + // + // A straight remove uses equals(), which is not the desired behavior + // + java.util.Iterator p = nodeDesc.serverInstances.iterator(); + while(p.hasNext()) + { + if(sd == p.next()) + { + p.remove(); + break; + } + } } static class ApplicationData { - NodeDescriptor descriptor; - Utils.Resolver resolver; + NodeDescriptor descriptor; + Utils.Resolver resolver; } // diff --git a/java/src/IceGridGUI/LiveDeployment/NodeEditor.java b/java/src/IceGridGUI/LiveDeployment/NodeEditor.java index 9011062e08c..d036f936ddb 100755 --- a/java/src/IceGridGUI/LiveDeployment/NodeEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/NodeEditor.java @@ -28,119 +28,119 @@ 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); + _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); } 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); + _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); _os.setCaretPosition(0); - _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(); - } - - _loadFactor.setSortedMap(node.getLoadFactors()); + _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(); + } + + _loadFactor.setSortedMap(node.getLoadFactors()); } void setLoad(String load, Node node) { - if(node == _target) - { - _loadAverage.setText(load); - } - // - // Otherwise, we've already moved to another 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(_loadFactor); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - builder.nextLine(); + 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(_loadFactor); + 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"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Node Properties"); } private JTextField _hostname = new JTextField(20); diff --git a/java/src/IceGridGUI/LiveDeployment/ObjectDialog.java b/java/src/IceGridGUI/LiveDeployment/ObjectDialog.java index 1d54b5bc70d..b5c5e742727 100755 --- a/java/src/IceGridGUI/LiveDeployment/ObjectDialog.java +++ b/java/src/IceGridGUI/LiveDeployment/ObjectDialog.java @@ -38,12 +38,12 @@ class ObjectDialog extends JDialog { ObjectDialog(final Root root, boolean readOnly) { - super(root.getCoordinator().getMainFrame(), + super(root.getCoordinator().getMainFrame(), (readOnly ? "" : "New ") + "Dynamic Well-Known Object - IceGrid Admin", true); - setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); - _mainFrame = root.getCoordinator().getMainFrame(); - + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); + _mainFrame = root.getCoordinator().getMainFrame(); + _proxy.setLineWrap(true); if(readOnly) @@ -73,7 +73,7 @@ class ObjectDialog extends JDialog cc.xywh(builder.getColumn(), builder.getRow(), 1, 3)); builder.nextRow(2); builder.nextLine(); - + if(readOnly) { builder.append("Type", _type); @@ -94,9 +94,9 @@ class ObjectDialog extends JDialog { JButton okButton = new JButton("OK"); ActionListener okListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { + { + public void actionPerformed(ActionEvent e) + { if(_proxy.isEditable()) { String type = null; @@ -114,11 +114,11 @@ class ObjectDialog extends JDialog { setVisible(false); } - } - }; + } + }; okButton.addActionListener(okListener); getRootPane().setDefaultButton(okButton); - + JButton cancelButton = new JButton("Cancel"); ActionListener cancelListener = new ActionListener() { @@ -132,11 +132,11 @@ class ObjectDialog extends JDialog JComponent buttonBar = ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); - buttonBar.setBorder(Borders.DIALOG_BORDER); + buttonBar.setBorder(Borders.DIALOG_BORDER); - contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); - contentPane.add(builder.getPanel()); - contentPane.add(buttonBar); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + contentPane.add(builder.getPanel()); + contentPane.add(buttonBar); } pack(); @@ -147,10 +147,10 @@ class ObjectDialog extends JDialog { assert _proxy.isEditable(); - _proxy.setText(""); + _proxy.setText(""); _typeCombo.setSelectedItem(QUERY_OBJECT); - setLocationRelativeTo(_mainFrame); - setVisible(true); + setLocationRelativeTo(_mainFrame); + setVisible(true); } void showDialog(String proxy, String type) @@ -161,7 +161,7 @@ class ObjectDialog extends JDialog _type.setText(type); setLocationRelativeTo(_mainFrame); - setVisible(true); + setVisible(true); } private JTextArea _proxy = new JTextArea(3, 40); @@ -170,10 +170,10 @@ class ObjectDialog extends JDialog private JFrame _mainFrame; static private final Object QUERY_OBJECT = new Object() - { - public String toString() - { - return "Query object to retrieve type"; - } - }; + { + public String toString() + { + return "Query object to retrieve type"; + } + }; } diff --git a/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java b/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java index dc3f9ac57e6..6856e6f12ec 100755 --- a/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/RegistryEditor.java @@ -35,93 +35,93 @@ class RegistryEditor extends Editor { RegistryEditor() { - _hostname.setEditable(false); - - Action openDefinition = new AbstractAction("Open definition") - { - public void actionPerformed(ActionEvent e) - { - int selectedRow = _applications.getSelectedRow(); - if(selectedRow != -1) - { - String appName = (String)_applications.getValueAt(selectedRow, 0); - ApplicationPane app = _target.getCoordinator().openLiveApplication(appName); - - if(app != null && app.getRoot().getSelectedNode() == null) - { - app.getRoot().setSelectedNode(app.getRoot()); - } - } - } - }; - - Action showDetails = new AbstractAction("Show details") - { - public void actionPerformed(ActionEvent e) - { - int selectedRow = _applications.getSelectedRow(); - if(selectedRow != -1) - { - String appName = (String)_applications.getValueAt(selectedRow, 0); - _target.showApplicationDetails(appName); - } - } - }; + _hostname.setEditable(false); + + Action openDefinition = new AbstractAction("Open definition") + { + public void actionPerformed(ActionEvent e) + { + int selectedRow = _applications.getSelectedRow(); + if(selectedRow != -1) + { + String appName = (String)_applications.getValueAt(selectedRow, 0); + ApplicationPane app = _target.getCoordinator().openLiveApplication(appName); + + if(app != null && app.getRoot().getSelectedNode() == null) + { + app.getRoot().setSelectedNode(app.getRoot()); + } + } + } + }; + + Action showDetails = new AbstractAction("Show details") + { + public void actionPerformed(ActionEvent e) + { + int selectedRow = _applications.getSelectedRow(); + if(selectedRow != -1) + { + String appName = (String)_applications.getValueAt(selectedRow, 0); + _target.showApplicationDetails(appName); + } + } + }; final Action patch = new AbstractAction("Patch distribution") - { - public void actionPerformed(ActionEvent e) - { - int selectedRow = _applications.getSelectedRow(); - if(selectedRow != -1) - { - String appName = (String)_applications.getValueAt(selectedRow, 0); - _target.patch(appName); - } - } - }; - - Action removeApplication = new AbstractAction("Remove from registry") - { - public void actionPerformed(ActionEvent e) - { - int selectedRow = _applications.getSelectedRow(); - if(selectedRow != -1) - { - String appName = (String)_applications.getValueAt(selectedRow, 0); - - int confirm = JOptionPane.showConfirmDialog( - _target.getCoordinator().getMainFrame(), - "You are about to remove application '" + appName + "' from the IceGrid registry. " - + "Do you want to proceed?", - "Remove Confirmation", - JOptionPane.YES_NO_OPTION); - - if(confirm == JOptionPane.YES_OPTION) - { - _target.getCoordinator().removeApplicationFromRegistry(appName); - } - } - } - }; - - removeApplication.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke("DELETE")); - - _applications.getActionMap().put("delete", removeApplication); - _applications.getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); - - final JPopupMenu appPopup = new JPopupMenu(); - appPopup.add(openDefinition); - appPopup.add(showDetails); - appPopup.addSeparator(); - appPopup.add(patch); + { + public void actionPerformed(ActionEvent e) + { + int selectedRow = _applications.getSelectedRow(); + if(selectedRow != -1) + { + String appName = (String)_applications.getValueAt(selectedRow, 0); + _target.patch(appName); + } + } + }; + + Action removeApplication = new AbstractAction("Remove from registry") + { + public void actionPerformed(ActionEvent e) + { + int selectedRow = _applications.getSelectedRow(); + if(selectedRow != -1) + { + String appName = (String)_applications.getValueAt(selectedRow, 0); + + int confirm = JOptionPane.showConfirmDialog( + _target.getCoordinator().getMainFrame(), + "You are about to remove application '" + appName + "' from the IceGrid registry. " + + "Do you want to proceed?", + "Remove Confirmation", + JOptionPane.YES_NO_OPTION); + + if(confirm == JOptionPane.YES_OPTION) + { + _target.getCoordinator().removeApplicationFromRegistry(appName); + } + } + } + }; + + removeApplication.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke("DELETE")); + + _applications.getActionMap().put("delete", removeApplication); + _applications.getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); + + final JPopupMenu appPopup = new JPopupMenu(); + appPopup.add(openDefinition); + appPopup.add(showDetails); + appPopup.addSeparator(); + appPopup.add(patch); appPopup.addSeparator(); - appPopup.add(removeApplication); + appPopup.add(removeApplication); - _applications.addMouseListener(new MouseAdapter() - { + _applications.addMouseListener(new MouseAdapter() + { public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 2) @@ -135,56 +135,56 @@ class RegistryEditor extends Editor } } - public void mousePressed(MouseEvent e) - { - maybeShowPopup(e); - } - - public void mouseReleased(MouseEvent e) - { - maybeShowPopup(e); - } - - private void maybeShowPopup(MouseEvent e) - { + public void mousePressed(MouseEvent e) + { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) + { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) + { int selectedRow = _applications.getSelectedRow(); - if (e.isPopupTrigger() && selectedRow != -1) - { + if (e.isPopupTrigger() && selectedRow != -1) + { String appName = (String)_applications.getValueAt(selectedRow, 0); ApplicationDescriptor desc = _target.getApplicationDescriptor(appName); patch.setEnabled(desc != null && desc.distrib.icepatch.length() > 0); - appPopup.show(_applications, e.getX(), e.getY()); - } - } - }); - - - Action deleteObject = new AbstractAction("Remove selected object") - { - public void actionPerformed(ActionEvent e) - { - if(_target.getCoordinator().connectedToMaster()) - { - int selectedRow = _objects.getSelectedRow(); - if(selectedRow != -1) - { - _target.removeObject((String)_objects.getValueAt(selectedRow, 0)); - } - } - } - }; - deleteObject.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke("DELETE")); - - _objects.getActionMap().put("delete", deleteObject); - _objects.getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); - - + appPopup.show(_applications, e.getX(), e.getY()); + } + } + }); + + + Action deleteObject = new AbstractAction("Remove selected object") + { + public void actionPerformed(ActionEvent e) + { + if(_target.getCoordinator().connectedToMaster()) + { + int selectedRow = _objects.getSelectedRow(); + if(selectedRow != -1) + { + _target.removeObject((String)_objects.getValueAt(selectedRow, 0)); + } + } + } + }; + deleteObject.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke("DELETE")); + + _objects.getActionMap().put("delete", deleteObject); + _objects.getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); + + Action showObject = new AbstractAction("Show details") { public void actionPerformed(ActionEvent e) - { + { int selectedRow = _objects.getSelectedRow(); if(selectedRow != -1) { @@ -192,40 +192,40 @@ class RegistryEditor extends Editor String type = (String)_objects.getValueAt(selectedRow, 1); _target.showObject(proxy, type); } - } + } }; - Action addObject = new AbstractAction("Add a new well-known object") - { - public void actionPerformed(ActionEvent e) - { - if(_target.getCoordinator().connectedToMaster()) - { - _target.addObject(); - } - } - }; - addObject.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke("INSERT")); - - _objects.getActionMap().put("insert", addObject); - _objects.getInputMap().put( - KeyStroke.getKeyStroke("INSERT"), "insert"); - - _objects.setToolTipText("<html>Well-known objects registered through the Admin interface.<br>" - + "Well-known objects registered using Adapter or Replica Group<br>" - + "definitions are not displayed here.</html>"); - - - final JPopupMenu objectsPopup = new JPopupMenu(); - objectsPopup.add(addObject); - objectsPopup.addSeparator(); - final JMenuItem deleteObjectMenuItem = objectsPopup.add(deleteObject); + Action addObject = new AbstractAction("Add a new well-known object") + { + public void actionPerformed(ActionEvent e) + { + if(_target.getCoordinator().connectedToMaster()) + { + _target.addObject(); + } + } + }; + addObject.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke("INSERT")); + + _objects.getActionMap().put("insert", addObject); + _objects.getInputMap().put( + KeyStroke.getKeyStroke("INSERT"), "insert"); + + _objects.setToolTipText("<html>Well-known objects registered through the Admin interface.<br>" + + "Well-known objects registered using Adapter or Replica Group<br>" + + "definitions are not displayed here.</html>"); + + + final JPopupMenu objectsPopup = new JPopupMenu(); + objectsPopup.add(addObject); + objectsPopup.addSeparator(); + final JMenuItem deleteObjectMenuItem = objectsPopup.add(deleteObject); objectsPopup.addSeparator(); final JMenuItem showObjectMenuItem = objectsPopup.add(showObject); - _objects.addMouseListener(new MouseAdapter() - { + _objects.addMouseListener(new MouseAdapter() + { public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 2) @@ -240,168 +240,168 @@ class RegistryEditor extends Editor } } - public void mousePressed(MouseEvent e) - { - maybeShowPopup(e); - } - - public void mouseReleased(MouseEvent e) - { - maybeShowPopup(e); - } - - private void maybeShowPopup(MouseEvent e) - { - if (e.isPopupTrigger()) - { + public void mousePressed(MouseEvent e) + { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) + { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) + { + if (e.isPopupTrigger()) + { showObjectMenuItem.setEnabled(_objects.getSelectedRow() != -1); - deleteObjectMenuItem.setEnabled(_objects.getSelectedRow() != -1); - objectsPopup.show(_objects, e.getX(), e.getY()); - } - } - }); + deleteObjectMenuItem.setEnabled(_objects.getSelectedRow() != -1); + objectsPopup.show(_objects, e.getX(), e.getY()); + } + } + }); - Action deleteAdapter = new AbstractAction("Remove selected adapter") - { - public void actionPerformed(ActionEvent e) - { - if(_target.getCoordinator().connectedToMaster()) - { - int selectedRow = _adapters.getSelectedRow(); - if(selectedRow != -1) - { - _target.removeAdapter((String)_adapters.getValueAt(selectedRow, 0)); - } - } - } - }; - deleteAdapter.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke("DELETE")); - - _adapters.getActionMap().put("delete", deleteAdapter); - _adapters.getInputMap().put( - KeyStroke.getKeyStroke("DELETE"), "delete"); - _adapters.setToolTipText("<html>Object adapters registered at run time.</html>"); - - final JPopupMenu adaptersPopup = new JPopupMenu(); - adaptersPopup.add(deleteAdapter); - - _adapters.addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - maybeShowPopup(e); - } - - public void mouseReleased(MouseEvent e) - { - maybeShowPopup(e); - } - - private void maybeShowPopup(MouseEvent e) - { - if (e.isPopupTrigger() && _adapters.getSelectedRow() != -1) - { - adaptersPopup.show(_adapters, e.getX(), e.getY()); - } - } - }); + Action deleteAdapter = new AbstractAction("Remove selected adapter") + { + public void actionPerformed(ActionEvent e) + { + if(_target.getCoordinator().connectedToMaster()) + { + int selectedRow = _adapters.getSelectedRow(); + if(selectedRow != -1) + { + _target.removeAdapter((String)_adapters.getValueAt(selectedRow, 0)); + } + } + } + }; + deleteAdapter.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke("DELETE")); + + _adapters.getActionMap().put("delete", deleteAdapter); + _adapters.getInputMap().put( + KeyStroke.getKeyStroke("DELETE"), "delete"); + _adapters.setToolTipText("<html>Object adapters registered at run time.</html>"); + + final JPopupMenu adaptersPopup = new JPopupMenu(); + adaptersPopup.add(deleteAdapter); + + _adapters.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent e) + { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) + { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) + { + if (e.isPopupTrigger() && _adapters.getSelectedRow() != -1) + { + adaptersPopup.show(_adapters, e.getX(), e.getY()); + } + } + }); } protected void appendProperties(DefaultFormBuilder builder) { - CellConstraints cc = new CellConstraints(); - - builder.append("Hostname" ); - builder.append(_hostname, 3); - builder.nextLine(); - - builder.appendSeparator("Deployed Applications"); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-14); - JScrollPane scrollPane = new JScrollPane(_applications); - scrollPane.setToolTipText(_applications.getToolTipText()); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); - builder.nextRow(14); - builder.nextLine(); - - builder.appendSeparator("Dynamic Well-Known Objects"); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-14); - scrollPane = new JScrollPane(_objects); - scrollPane.setToolTipText(_objects.getToolTipText()); - builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); - builder.nextRow(14); - builder.nextLine(); - - builder.appendSeparator("Dynamic Object Adapters"); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-14); - scrollPane = new JScrollPane(_adapters); - scrollPane.setToolTipText(_adapters.getToolTipText()); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); - builder.nextRow(14); - builder.nextLine(); + CellConstraints cc = new CellConstraints(); + + builder.append("Hostname" ); + builder.append(_hostname, 3); + builder.nextLine(); + + builder.appendSeparator("Deployed Applications"); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-14); + JScrollPane scrollPane = new JScrollPane(_applications); + scrollPane.setToolTipText(_applications.getToolTipText()); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); + builder.nextRow(14); + builder.nextLine(); + + builder.appendSeparator("Dynamic Well-Known Objects"); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-14); + scrollPane = new JScrollPane(_objects); + scrollPane.setToolTipText(_objects.getToolTipText()); + builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); + builder.nextRow(14); + builder.nextLine(); + + builder.appendSeparator("Dynamic Object Adapters"); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-14); + scrollPane = new JScrollPane(_adapters); + scrollPane.setToolTipText(_adapters.getToolTipText()); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 14)); + builder.nextRow(14); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Registry Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Registry Properties"); } void show(Root root) { - _target = root; - _hostname.setText(root.getRegistryInfo().hostname); - _applications.setSortedMap(root.getApplicationMap()); - _objects.setObjects(root.getObjects()); - _adapters.setAdapters(root.getAdapters()); + _target = root; + _hostname.setText(root.getRegistryInfo().hostname); + _applications.setSortedMap(root.getApplicationMap()); + _objects.setObjects(root.getObjects()); + _adapters.setAdapters(root.getAdapters()); } private JTextField _hostname = new JTextField(20); diff --git a/java/src/IceGridGUI/LiveDeployment/Root.java b/java/src/IceGridGUI/LiveDeployment/Root.java index c67c97b9a2a..f7433b44968 100755 --- a/java/src/IceGridGUI/LiveDeployment/Root.java +++ b/java/src/IceGridGUI/LiveDeployment/Root.java @@ -33,195 +33,195 @@ public class Root extends ListArrayTreeNode { public Root(Coordinator coordinator) { - super(null, "Root", 2); - _coordinator = coordinator; - _childrenArray[0] = _slaves; - _childrenArray[1] = _nodes; - _messageSizeMax = Ice.Util.getInstance(_coordinator.getCommunicator()).messageSizeMax(); - - _tree = new JTree(this, true); - _treeModel = (DefaultTreeModel)_tree.getModel(); - _addObjectDialog = new ObjectDialog(this, false); + super(null, "Root", 2); + _coordinator = coordinator; + _childrenArray[0] = _slaves; + _childrenArray[1] = _nodes; + _messageSizeMax = Ice.Util.getInstance(_coordinator.getCommunicator()).messageSizeMax(); + + _tree = new JTree(this, true); + _treeModel = (DefaultTreeModel)_tree.getModel(); + _addObjectDialog = new ObjectDialog(this, false); _showObjectDialog = new ObjectDialog(this, true); - _tree.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener() - { - public void treeWillExpand(javax.swing.event.TreeExpansionEvent event) - { - } - - public void treeWillCollapse(javax.swing.event.TreeExpansionEvent event) - throws javax.swing.tree.ExpandVetoException - { - if(event.getPath().getLastPathComponent() == Root.this) - { - throw new javax.swing.tree.ExpandVetoException(event); - } - } - }); - - loadLogPrefs(); + _tree.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener() + { + public void treeWillExpand(javax.swing.event.TreeExpansionEvent event) + { + } + + public void treeWillCollapse(javax.swing.event.TreeExpansionEvent event) + throws javax.swing.tree.ExpandVetoException + { + if(event.getPath().getLastPathComponent() == Root.this) + { + throw new javax.swing.tree.ExpandVetoException(event); + } + } + }); + + loadLogPrefs(); } public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - actions[ADD_OBJECT] = _coordinator.connectedToMaster(); - actions[SHUTDOWN_REGISTRY] = true; - actions[RETRIEVE_STDOUT] = true; - actions[RETRIEVE_STDERR] = true; - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + actions[ADD_OBJECT] = _coordinator.connectedToMaster(); + actions[SHUTDOWN_REGISTRY] = true; + actions[RETRIEVE_STDOUT] = true; + actions[RETRIEVE_STDERR] = true; + return actions; } public void shutdownRegistry() { - final String prefix = "Shutting down registry '" + _replicaName + "'..."; - getCoordinator().getStatusBar().setText(prefix); - - AMI_Admin_shutdownRegistry cb = new AMI_Admin_shutdownRegistry() - { - // - // Called by another thread! - // - public void ice_response() - { - amiSuccess(prefix); - } - - public void ice_exception(Ice.UserException e) - { - amiFailure(prefix, "Failed to shutdown " + _replicaName, e); - } - - public void ice_exception(Ice.LocalException e) - { - amiFailure(prefix, "Failed to shutdown " + _replicaName, - e.toString()); - } - }; - - try - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - _coordinator.getAdmin().shutdownRegistry_async(cb, _replicaName); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to shutdown " + _replicaName, e.toString()); - } - finally - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + final String prefix = "Shutting down registry '" + _replicaName + "'..."; + getCoordinator().getStatusBar().setText(prefix); + + AMI_Admin_shutdownRegistry cb = new AMI_Admin_shutdownRegistry() + { + // + // Called by another thread! + // + public void ice_response() + { + amiSuccess(prefix); + } + + public void ice_exception(Ice.UserException e) + { + amiFailure(prefix, "Failed to shutdown " + _replicaName, e); + } + + public void ice_exception(Ice.LocalException e) + { + amiFailure(prefix, "Failed to shutdown " + _replicaName, + e.toString()); + } + }; + + try + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + _coordinator.getAdmin().shutdownRegistry_async(cb, _replicaName); + } + catch(Ice.LocalException e) + { + failure(prefix, "Failed to shutdown " + _replicaName, e.toString()); + } + finally + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } public ApplicationDescriptor getApplicationDescriptor(String name) { - ApplicationInfo app = (ApplicationInfo)_infoMap.get(name); - if(app == null) - { - return null; - } - else - { - return app.descriptor; - } + ApplicationInfo app = (ApplicationInfo)_infoMap.get(name); + if(app == null) + { + return null; + } + else + { + return app.descriptor; + } } public Object[] getApplicationNames() { - return _infoMap.keySet().toArray(); + return _infoMap.keySet().toArray(); } public Object[] getPatchableApplicationNames() { - java.util.List result = new java.util.ArrayList(); - - java.util.Iterator p = _infoMap.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - ApplicationInfo app = (ApplicationInfo)entry.getValue(); - if(app.descriptor.distrib.icepatch.length() > 0) - { - result.add(entry.getKey()); - } - } - return result.toArray(); + java.util.List result = new java.util.ArrayList(); + + java.util.Iterator p = _infoMap.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + ApplicationInfo app = (ApplicationInfo)entry.getValue(); + if(app.descriptor.distrib.icepatch.length() > 0) + { + result.add(entry.getKey()); + } + } + return result.toArray(); } public java.util.SortedMap getApplicationMap() { - java.util.SortedMap r = new java.util.TreeMap(); - - java.util.Iterator p = _infoMap.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - - ApplicationInfo app = (ApplicationInfo)entry.getValue(); - - r.put(entry.getKey(), - java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(app.updateTime))); - } - return r; + java.util.SortedMap r = new java.util.TreeMap(); + + java.util.Iterator p = _infoMap.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + + ApplicationInfo app = (ApplicationInfo)entry.getValue(); + + r.put(entry.getKey(), + java.text.DateFormat.getDateTimeInstance().format(new java.util.Date(app.updateTime))); + } + return r; } public Editor getEditor() { - if(_editor == null) - { - _editor = new RegistryEditor(); - } - _editor.show(this); - return _editor; + if(_editor == null) + { + _editor = new RegistryEditor(); + } + _editor.show(this); + return _editor; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { - if(_cellRenderer == null) - { - // - // Initialization - // - _cellRenderer = new DefaultTreeCellRenderer(); - - Icon icon = Utils.getIcon("/icons/16x16/registry.png"); - _cellRenderer.setOpenIcon(icon); - _cellRenderer.setClosedIcon(icon); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + if(_cellRenderer == null) + { + // + // Initialization + // + _cellRenderer = new DefaultTreeCellRenderer(); + + Icon icon = Utils.getIcon("/icons/16x16/registry.png"); + _cellRenderer.setOpenIcon(icon); + _cellRenderer.setClosedIcon(icon); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } public void applicationInit(String instanceName, String replicaName, java.util.List applications) { - closeAllShowLogDialogs(); - - _replicaName = replicaName; - _label = instanceName + " (" + _replicaName + ")"; - _tree.setRootVisible(true); - - java.util.Iterator p = applications.iterator(); - while(p.hasNext()) - { - applicationAdded((ApplicationInfo)p.next()); - } + closeAllShowLogDialogs(); + + _replicaName = replicaName; + _label = instanceName + " (" + _replicaName + ")"; + _tree.setRootVisible(true); + + java.util.Iterator p = applications.iterator(); + while(p.hasNext()) + { + applicationAdded((ApplicationInfo)p.next()); + } } // @@ -229,89 +229,89 @@ public class Root extends ListArrayTreeNode // public void clear() { - _adapters.clear(); - _objects.clear(); - _replicaName = null; - - _infoMap.clear(); - _nodes.clear(); - _slaves.clear(); - _treeModel.nodeStructureChanged(this); - _tree.setRootVisible(false); + _adapters.clear(); + _objects.clear(); + _replicaName = null; + + _infoMap.clear(); + _nodes.clear(); + _slaves.clear(); + _treeModel.nodeStructureChanged(this); + _tree.setRootVisible(false); } public void patch(final String applicationName) { - int shutdown = JOptionPane.showConfirmDialog( - _coordinator.getMainFrame(), - "You are about to install or refresh your" - + " application distribution.\n" - + " Do you want shut down all servers affected by this update?", - "Patch Confirmation", - JOptionPane.YES_NO_CANCEL_OPTION); + int shutdown = JOptionPane.showConfirmDialog( + _coordinator.getMainFrame(), + "You are about to install or refresh your" + + " application distribution.\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 application '" + applicationName + "'..."; - - _coordinator.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 '" - + applicationName + "'", e); - } - - public void ice_exception(Ice.LocalException e) - { - amiFailure(prefix, "Failed to patch '" + - applicationName + "'", e.toString()); - } - }; - - try - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + if(shutdown == JOptionPane.CANCEL_OPTION) + { + return; + } + + final String prefix = "Patching application '" + applicationName + "'..."; + + _coordinator.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 '" + + applicationName + "'", e); + } + + public void ice_exception(Ice.LocalException e) + { + amiFailure(prefix, "Failed to patch '" + + applicationName + "'", e.toString()); + } + }; + + try + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); _coordinator.getAdmin(). patchApplication_async(cb, applicationName, shutdown == JOptionPane.YES_OPTION); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to patch " + _id, e.toString()); - } - finally - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + } + catch(Ice.LocalException e) + { + failure(prefix, "Failed to patch " + _id, e.toString()); + } + finally + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } public void showApplicationDetails(String appName) { - ApplicationInfo app = (ApplicationInfo)_infoMap.get(appName); - if(app != null) - { - if(_applicationDetailsDialog == null) - { - _applicationDetailsDialog = new ApplicationDetailsDialog(this); - } - - _applicationDetailsDialog.showDialog(app); - } + ApplicationInfo app = (ApplicationInfo)_infoMap.get(appName); + if(app != null) + { + if(_applicationDetailsDialog == null) + { + _applicationDetailsDialog = new ApplicationDetailsDialog(this); + } + + _applicationDetailsDialog.showDialog(app); + } } // @@ -319,233 +319,233 @@ public class Root extends ListArrayTreeNode // public void applicationAdded(ApplicationInfo info) { - _infoMap.put(info.descriptor.name, info); - - java.util.Iterator p = info.descriptor.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, info.descriptor, nodeName, nodeDesc)); - } - else - { - node.add(info.descriptor, nodeDesc); - } - } + _infoMap.put(info.descriptor.name, info); + + java.util.Iterator p = info.descriptor.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, info.descriptor, nodeName, nodeDesc)); + } + else + { + node.add(info.descriptor, nodeDesc); + } + } } public void applicationRemoved(String name) { - _infoMap.remove(name); - - java.util.List toRemove = new java.util.LinkedList(); - int[] toRemoveIndices = new int[_nodes.size()]; - - int i = 0; - for(int index = 0; index < _nodes.size(); ++index) - { - Node node = (Node)_nodes.get(index); - if(node.remove(name)) - { - toRemove.add(node); - toRemoveIndices[i++] = _slaves.size() + index; - } - } - - removeNodes(resize(toRemoveIndices, toRemove.size()), toRemove); + _infoMap.remove(name); + + java.util.List toRemove = new java.util.LinkedList(); + int[] toRemoveIndices = new int[_nodes.size()]; + + int i = 0; + for(int index = 0; index < _nodes.size(); ++index) + { + Node node = (Node)_nodes.get(index); + if(node.remove(name)) + { + toRemove.add(node); + toRemoveIndices[i++] = _slaves.size() + index; + } + } + + removeNodes(resize(toRemoveIndices, toRemove.size()), toRemove); } public void applicationUpdated(ApplicationUpdateInfo update) { - ApplicationInfo app = (ApplicationInfo)_infoMap.get(update.descriptor.name); - - app.updateTime = update.updateTime; - app.updateUser = update.updateUser; - app.revision = update.revision; - - ApplicationDescriptor appDesc = app.descriptor; - - // - // Update various fields of appDesc - // - if(update.descriptor.description != null) - { - appDesc.description = update.descriptor.description.value; - } - if(update.descriptor.distrib != null) - { - appDesc.distrib = update.descriptor.distrib.value; - } - - appDesc.variables.keySet().removeAll(java.util.Arrays.asList(update.descriptor.removeVariables)); - appDesc.variables.putAll(update.descriptor.variables); - boolean variablesChanged = update.descriptor.removeVariables.length > 0 || !update.descriptor.variables.isEmpty(); - - // - // Update only descriptors (no tree node shown in this view) - // - appDesc.propertySets.keySet(). - removeAll(java.util.Arrays.asList(update.descriptor.removePropertySets)); - appDesc.propertySets.putAll(update.descriptor.propertySets); - - for(int i = 0; i < update.descriptor.removeReplicaGroups.length; ++i) - { - for(int j = 0; j < appDesc.replicaGroups.size(); ++j) - { - ReplicaGroupDescriptor rgd = (ReplicaGroupDescriptor)appDesc.replicaGroups.get(j); - if(rgd.id.equals(update.descriptor.removeReplicaGroups[i])) - { - appDesc.replicaGroups.remove(j); - break; // for - } - } - } - - for(int i = 0; i < update.descriptor.replicaGroups.size(); ++i) - { - ReplicaGroupDescriptor newRgd = (ReplicaGroupDescriptor)update.descriptor.replicaGroups.get(i); - - boolean replaced = false; - int j = 0; - while(j < appDesc.replicaGroups.size() && !replaced) - { - ReplicaGroupDescriptor oldRgd = (ReplicaGroupDescriptor)appDesc.replicaGroups.get(j); - - if(newRgd.id.equals(oldRgd.id)) - { - appDesc.replicaGroups.set(j, newRgd); - replaced = true; - } - j++; - } - - if(!replaced) - { - appDesc.replicaGroups.add(newRgd); - } - } + ApplicationInfo app = (ApplicationInfo)_infoMap.get(update.descriptor.name); + + app.updateTime = update.updateTime; + app.updateUser = update.updateUser; + app.revision = update.revision; + + ApplicationDescriptor appDesc = app.descriptor; + + // + // Update various fields of appDesc + // + if(update.descriptor.description != null) + { + appDesc.description = update.descriptor.description.value; + } + if(update.descriptor.distrib != null) + { + appDesc.distrib = update.descriptor.distrib.value; + } + + appDesc.variables.keySet().removeAll(java.util.Arrays.asList(update.descriptor.removeVariables)); + appDesc.variables.putAll(update.descriptor.variables); + boolean variablesChanged = update.descriptor.removeVariables.length > 0 || !update.descriptor.variables.isEmpty(); + + // + // Update only descriptors (no tree node shown in this view) + // + appDesc.propertySets.keySet(). + removeAll(java.util.Arrays.asList(update.descriptor.removePropertySets)); + appDesc.propertySets.putAll(update.descriptor.propertySets); + + for(int i = 0; i < update.descriptor.removeReplicaGroups.length; ++i) + { + for(int j = 0; j < appDesc.replicaGroups.size(); ++j) + { + ReplicaGroupDescriptor rgd = (ReplicaGroupDescriptor)appDesc.replicaGroups.get(j); + if(rgd.id.equals(update.descriptor.removeReplicaGroups[i])) + { + appDesc.replicaGroups.remove(j); + break; // for + } + } + } + + for(int i = 0; i < update.descriptor.replicaGroups.size(); ++i) + { + ReplicaGroupDescriptor newRgd = (ReplicaGroupDescriptor)update.descriptor.replicaGroups.get(i); + + boolean replaced = false; + int j = 0; + while(j < appDesc.replicaGroups.size() && !replaced) + { + ReplicaGroupDescriptor oldRgd = (ReplicaGroupDescriptor)appDesc.replicaGroups.get(j); + + if(newRgd.id.equals(oldRgd.id)) + { + appDesc.replicaGroups.set(j, newRgd); + replaced = true; + } + j++; + } + + if(!replaced) + { + appDesc.replicaGroups.add(newRgd); + } + } - appDesc.serviceTemplates.keySet(). - removeAll(java.util.Arrays.asList(update.descriptor.removeServiceTemplates)); - appDesc.serviceTemplates.putAll(update.descriptor.serviceTemplates); - - appDesc.serverTemplates.keySet(). - removeAll(java.util.Arrays.asList(update.descriptor.removeServerTemplates)); - appDesc.serverTemplates.putAll(update.descriptor.serverTemplates); - - // - // Nodes - // - - // - // Removal - // - appDesc.nodes.keySet().removeAll(java.util.Arrays.asList(update.descriptor.removeNodes)); - - for(int i = 0; i < update.descriptor.removeNodes.length; ++i) - { - Node node = findNode(update.descriptor.removeNodes[i]); - if(node.remove(update.descriptor.name)) - { - int index = getIndex(node); - _nodes.remove(node); - _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node}); - } - } - - // - // Add/update - // - java.util.Iterator p = update.descriptor.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.descriptor.serviceTemplates.keySet(), update.descriptor.serverTemplates.keySet()); - } - freshNodes.add(node); - } - - // - // Notify non-fresh nodes if needed - // - if(variablesChanged || !update.descriptor.serviceTemplates.isEmpty() || !update.descriptor.serverTemplates.isEmpty()) - { - p = _nodes.iterator(); - while(p.hasNext()) - { - Node node = (Node)p.next(); - if(!freshNodes.contains(node)) - { - node.update(appDesc, null, variablesChanged, - update.descriptor.serviceTemplates.keySet(), update.descriptor.serverTemplates.keySet()); - } - } - } + appDesc.serviceTemplates.keySet(). + removeAll(java.util.Arrays.asList(update.descriptor.removeServiceTemplates)); + appDesc.serviceTemplates.putAll(update.descriptor.serviceTemplates); + + appDesc.serverTemplates.keySet(). + removeAll(java.util.Arrays.asList(update.descriptor.removeServerTemplates)); + appDesc.serverTemplates.putAll(update.descriptor.serverTemplates); + + // + // Nodes + // + + // + // Removal + // + appDesc.nodes.keySet().removeAll(java.util.Arrays.asList(update.descriptor.removeNodes)); + + for(int i = 0; i < update.descriptor.removeNodes.length; ++i) + { + Node node = findNode(update.descriptor.removeNodes[i]); + if(node.remove(update.descriptor.name)) + { + int index = getIndex(node); + _nodes.remove(node); + _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node}); + } + } + + // + // Add/update + // + java.util.Iterator p = update.descriptor.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.descriptor.serviceTemplates.keySet(), update.descriptor.serverTemplates.keySet()); + } + freshNodes.add(node); + } + + // + // Notify non-fresh nodes if needed + // + if(variablesChanged || !update.descriptor.serviceTemplates.isEmpty() || !update.descriptor.serverTemplates.isEmpty()) + { + p = _nodes.iterator(); + while(p.hasNext()) + { + Node node = (Node)p.next(); + if(!freshNodes.contains(node)) + { + node.update(appDesc, null, variablesChanged, + update.descriptor.serviceTemplates.keySet(), update.descriptor.serverTemplates.keySet()); + } + } + } } public void adapterInit(AdapterInfo[] adapters) { - for(int i = 0; i < adapters.length; ++i) - { - _adapters.put(adapters[i].id, adapters[i]); - } + for(int i = 0; i < adapters.length; ++i) + { + _adapters.put(adapters[i].id, adapters[i]); + } } public void adapterAdded(AdapterInfo info) { - _adapters.put(info.id, info); + _adapters.put(info.id, info); } public void adapterUpdated(AdapterInfo info) { - _adapters.put(info.id, info); + _adapters.put(info.id, info); } public void adapterRemoved(String id) { - _adapters.remove(id); + _adapters.remove(id); } public void objectInit(ObjectInfo[] objects) { - for(int i = 0; i < objects.length; ++i) - { - _objects.put(Ice.Util.identityToString(objects[i].proxy.ice_getIdentity()), objects[i]); - } + for(int i = 0; i < objects.length; ++i) + { + _objects.put(Ice.Util.identityToString(objects[i].proxy.ice_getIdentity()), objects[i]); + } } public void objectAdded(ObjectInfo info) { - _objects.put(Ice.Util.identityToString(info.proxy.ice_getIdentity()), info); + _objects.put(Ice.Util.identityToString(info.proxy.ice_getIdentity()), info); } public void objectUpdated(ObjectInfo info) { - _objects.put(Ice.Util.identityToString(info.proxy.ice_getIdentity()), info); + _objects.put(Ice.Util.identityToString(info.proxy.ice_getIdentity()), info); } public void objectRemoved(Ice.Identity id) { - _objects.remove(Ice.Util.identityToString(id)); + _objects.remove(Ice.Util.identityToString(id)); } @@ -554,38 +554,38 @@ public class Root extends ListArrayTreeNode // public void registryUp(RegistryInfo info) { - if(info.name.equals(_replicaName)) - { - _info = info; - } - else - { - Slave newSlave = new Slave(this, info, _replicaName); - - int i; - for(i = 0; i < _slaves.size(); ++i) - { - String otherName = _slaves.get(i).toString(); - if(info.name.compareTo(otherName) > 0) - { - i++; - break; - } - } - _slaves.add(i, newSlave); - _treeModel.nodesWereInserted(this, new int[]{i}); - } + if(info.name.equals(_replicaName)) + { + _info = info; + } + else + { + Slave newSlave = new Slave(this, info, _replicaName); + + int i; + for(i = 0; i < _slaves.size(); ++i) + { + String otherName = _slaves.get(i).toString(); + if(info.name.compareTo(otherName) > 0) + { + i++; + break; + } + } + _slaves.add(i, newSlave); + _treeModel.nodesWereInserted(this, new int[]{i}); + } } public void registryDown(String name) { - TreeNodeBase registry = find(name, _slaves); - if(registry != null) - { - int index = getIndex(registry); - _slaves.remove(registry); - _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{registry}); - } + TreeNodeBase registry = find(name, _slaves); + if(registry != null) + { + int index = getIndex(registry); + _slaves.remove(registry); + _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{registry}); + } } // @@ -593,91 +593,91 @@ public class Root extends ListArrayTreeNode // public void nodeUp(NodeDynamicInfo updatedInfo) { - Node node = findNode(updatedInfo.info.name); - if(node != null) - { - node.up(updatedInfo, true); - } - else - { - insertNode(new Node(this, updatedInfo)); - } + Node node = findNode(updatedInfo.info.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); - _nodes.remove(node); - _treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node}); - } - } + Node node = findNode(nodeName); + if(node != null) + { + if(node.down()) + { + int index = getIndex(node); + _nodes.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); - } + 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); - } + Node node = findNode(nodeName); + if(node != null) + { + node.updateAdapter(updatedInfo); + } } public JPopupMenu getPopupMenu() { - LiveActions la = _coordinator.getLiveActionsForPopup(); - - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(la.get(ADD_OBJECT)); - _popup.addSeparator(); - _popup.add(la.get(RETRIEVE_STDOUT)); - _popup.add(la.get(RETRIEVE_STDERR)); - _popup.addSeparator(); - _popup.add(la.get(SHUTDOWN_REGISTRY)); - } - - la.setTarget(this); - return _popup; + LiveActions la = _coordinator.getLiveActionsForPopup(); + + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(la.get(ADD_OBJECT)); + _popup.addSeparator(); + _popup.add(la.get(RETRIEVE_STDOUT)); + _popup.add(la.get(RETRIEVE_STDERR)); + _popup.addSeparator(); + _popup.add(la.get(SHUTDOWN_REGISTRY)); + } + + la.setTarget(this); + return _popup; } public void setSelectedNode(TreeNode node) { - _tree.setSelectionPath(node.getPath()); + _tree.setSelectionPath(node.getPath()); } public JTree getTree() { - return _tree; + return _tree; } public DefaultTreeModel getTreeModel() { - return _treeModel; + return _treeModel; } public Coordinator getCoordinator() { - return _coordinator; + return _coordinator; } public String toString() { - return _label; + return _label; } // @@ -685,24 +685,24 @@ public class Root extends ListArrayTreeNode // 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; + while(node != this) + { + TreeNode parent = (TreeNode)node.getParent(); + if(parent.getIndex(node) == -1) + { + return false; + } + else + { + node = parent; + } + } + return true; } public void addObject() { - _addObjectDialog.showDialog(); + _addObjectDialog.showDialog(); } public void showObject(String proxy, String type) @@ -712,347 +712,347 @@ public class Root extends ListArrayTreeNode Root getRoot() { - return this; + return this; } java.util.SortedMap getObjects() { - return _objects; + return _objects; } java.util.SortedMap getAdapters() { - return _adapters; + return _adapters; } RegistryInfo getRegistryInfo() { - return _info; + return _info; } boolean addObject(String strProxy, String type) { - Ice.ObjectPrx proxy = null; - - try - { - proxy = _coordinator.getCommunicator().stringToProxy(strProxy); - } - catch(Ice.LocalException e) - { - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - "Cannot parse proxy '" + strProxy + "'", - "addObject failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - if(proxy == null) - { - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - "You must provide a non-null proxy", - "addObject failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - String strIdentity = Ice.Util.identityToString(proxy.ice_getIdentity()); - - String prefix = "Adding well-known object '" + strIdentity + "'..."; - try - { - _coordinator.getStatusBar().setText(prefix); - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - if(type == null) - { - _coordinator.getAdmin().addObject(proxy); - } - else - { - _coordinator.getAdmin().addObjectWithType(proxy, type); - } - } - catch(ObjectExistsException e) - { - _coordinator.getStatusBar().setText(prefix + "failed."); - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - "An object with this identity is already registered as a well-known object", - "addObject failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - catch(DeploymentException e) - { - _coordinator.getStatusBar().setText(prefix + "failed."); - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - "Deployment exception: " + e.reason, - "addObject failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - catch(Ice.LocalException e) - { - _coordinator.getStatusBar().setText(prefix + "failed."); - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - e.toString(), - "addObject failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - finally - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - _coordinator.getStatusBar().setText(prefix + "done."); - return true; + Ice.ObjectPrx proxy = null; + + try + { + proxy = _coordinator.getCommunicator().stringToProxy(strProxy); + } + catch(Ice.LocalException e) + { + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + "Cannot parse proxy '" + strProxy + "'", + "addObject failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + if(proxy == null) + { + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + "You must provide a non-null proxy", + "addObject failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + String strIdentity = Ice.Util.identityToString(proxy.ice_getIdentity()); + + String prefix = "Adding well-known object '" + strIdentity + "'..."; + try + { + _coordinator.getStatusBar().setText(prefix); + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + if(type == null) + { + _coordinator.getAdmin().addObject(proxy); + } + else + { + _coordinator.getAdmin().addObjectWithType(proxy, type); + } + } + catch(ObjectExistsException e) + { + _coordinator.getStatusBar().setText(prefix + "failed."); + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + "An object with this identity is already registered as a well-known object", + "addObject failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + catch(DeploymentException e) + { + _coordinator.getStatusBar().setText(prefix + "failed."); + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + "Deployment exception: " + e.reason, + "addObject failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + catch(Ice.LocalException e) + { + _coordinator.getStatusBar().setText(prefix + "failed."); + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + e.toString(), + "addObject failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + finally + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + _coordinator.getStatusBar().setText(prefix + "done."); + return true; } void removeObject(String strProxy) { - Ice.ObjectPrx proxy = _coordinator.getCommunicator().stringToProxy(strProxy); - Ice.Identity identity = proxy.ice_getIdentity(); - final String strIdentity = Ice.Util.identityToString(identity); - - final String prefix = "Removing well-known object '" + strIdentity + "'..."; - _coordinator.getStatusBar().setText(prefix); - - AMI_Admin_removeObject cb = new AMI_Admin_removeObject() - { - // - // Called by another thread! - // - public void ice_response() - { - amiSuccess(prefix); - } - - public void ice_exception(Ice.UserException e) - { - amiFailure(prefix, "Failed to remove object '" + strIdentity + "'", e); - } - - public void ice_exception(Ice.LocalException e) - { - amiFailure(prefix, "Failed to remove object '" + strIdentity + "'", - e.toString()); - } - }; - - try - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - _coordinator.getAdmin().removeObject_async(cb, identity); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to remove object '" + strIdentity + "'", - e.toString()); - } - finally - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + Ice.ObjectPrx proxy = _coordinator.getCommunicator().stringToProxy(strProxy); + Ice.Identity identity = proxy.ice_getIdentity(); + final String strIdentity = Ice.Util.identityToString(identity); + + final String prefix = "Removing well-known object '" + strIdentity + "'..."; + _coordinator.getStatusBar().setText(prefix); + + AMI_Admin_removeObject cb = new AMI_Admin_removeObject() + { + // + // Called by another thread! + // + public void ice_response() + { + amiSuccess(prefix); + } + + public void ice_exception(Ice.UserException e) + { + amiFailure(prefix, "Failed to remove object '" + strIdentity + "'", e); + } + + public void ice_exception(Ice.LocalException e) + { + amiFailure(prefix, "Failed to remove object '" + strIdentity + "'", + e.toString()); + } + }; + + try + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + _coordinator.getAdmin().removeObject_async(cb, identity); + } + catch(Ice.LocalException e) + { + failure(prefix, "Failed to remove object '" + strIdentity + "'", + e.toString()); + } + finally + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } void removeAdapter(final String adapterId) { - final String prefix = "Removing adapter '" + adapterId + "'..."; - _coordinator.getStatusBar().setText(prefix); - - AMI_Admin_removeAdapter cb = new AMI_Admin_removeAdapter() - { - // - // Called by another thread! - // - public void ice_response() - { - amiSuccess(prefix); - } - - public void ice_exception(Ice.UserException e) - { - amiFailure(prefix, "Failed to remove adapter '" + adapterId + "'", e); - } - - public void ice_exception(Ice.LocalException e) - { - amiFailure(prefix, "Failed to remove adapter '" + adapterId + "'", - e.toString()); - } - }; - - try - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - _coordinator.getAdmin().removeAdapter_async(cb, adapterId); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to remove adapter '" + adapterId + "'", e.toString()); - } - finally - { - _coordinator.getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + final String prefix = "Removing adapter '" + adapterId + "'..."; + _coordinator.getStatusBar().setText(prefix); + + AMI_Admin_removeAdapter cb = new AMI_Admin_removeAdapter() + { + // + // Called by another thread! + // + public void ice_response() + { + amiSuccess(prefix); + } + + public void ice_exception(Ice.UserException e) + { + amiFailure(prefix, "Failed to remove adapter '" + adapterId + "'", e); + } + + public void ice_exception(Ice.LocalException e) + { + amiFailure(prefix, "Failed to remove adapter '" + adapterId + "'", + e.toString()); + } + }; + + try + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + _coordinator.getAdmin().removeAdapter_async(cb, adapterId); + } + catch(Ice.LocalException e) + { + failure(prefix, "Failed to remove adapter '" + adapterId + "'", e.toString()); + } + finally + { + _coordinator.getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } public void retrieveOutput(final boolean stdout) { - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, RegistryNotExistException, RegistryUnreachableException - { - AdminSessionPrx session = _coordinator.getSession(); - - if(stdout) - { - return session.openRegistryStdOut(_replicaName, count); - } - else - { - return session.openRegistryStdErr(_replicaName, count); - } - } - - public String getTitle() - { - return "Registry " + _label + " " + (stdout ? "stdout" : "stderr"); - } - - public String getDefaultFilename() - { - return _replicaName + (stdout ? ".out" : ".err"); - } - }); + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, RegistryNotExistException, RegistryUnreachableException + { + AdminSessionPrx session = _coordinator.getSession(); + + if(stdout) + { + return session.openRegistryStdOut(_replicaName, count); + } + else + { + return session.openRegistryStdErr(_replicaName, count); + } + } + + public String getTitle() + { + return "Registry " + _label + " " + (stdout ? "stdout" : "stderr"); + } + + public String getDefaultFilename() + { + return _replicaName + (stdout ? ".out" : ".err"); + } + }); } PropertySetDescriptor findNamedPropertySet(String name, String applicationName) { - ApplicationInfo app = (ApplicationInfo) - _infoMap.get(applicationName); - return (PropertySetDescriptor)app.descriptor.propertySets.get(name); + ApplicationInfo app = (ApplicationInfo) + _infoMap.get(applicationName); + return (PropertySetDescriptor)app.descriptor.propertySets.get(name); } void openShowLogDialog(ShowLogDialog.FileIteratorFactory factory) { - ShowLogDialog d = (ShowLogDialog)_showLogDialogMap.get(factory.getTitle()); - if(d == null) - { - d = new ShowLogDialog(this, factory, - _logMaxLines, _logMaxSize, _logInitialLines, _logMaxReadSize, _logPeriod); - - _showLogDialogMap.put(factory.getTitle(), d); - } - else - { - d.toFront(); - } + ShowLogDialog d = (ShowLogDialog)_showLogDialogMap.get(factory.getTitle()); + if(d == null) + { + d = new ShowLogDialog(this, factory, + _logMaxLines, _logMaxSize, _logInitialLines, _logMaxReadSize, _logPeriod); + + _showLogDialogMap.put(factory.getTitle(), d); + } + else + { + d.toFront(); + } } void removeShowLogDialog(String title) { - _showLogDialogMap.remove(title); + _showLogDialogMap.remove(title); } public void closeAllShowLogDialogs() { - java.util.Iterator p = _showLogDialogMap.values().iterator(); - while(p.hasNext()) - { - ShowLogDialog d = (ShowLogDialog)p.next(); - d.close(false); - } - _showLogDialogMap.clear(); + java.util.Iterator p = _showLogDialogMap.values().iterator(); + while(p.hasNext()) + { + ShowLogDialog d = (ShowLogDialog)p.next(); + d.close(false); + } + _showLogDialogMap.clear(); } public int getMessageSizeMax() { - return _messageSizeMax; + return _messageSizeMax; } public void setLogPrefs(int maxLines, int maxSize, int initialLines, int maxReadSize, int period) { - _logMaxLines = maxLines; - _logMaxSize = maxSize; - _logInitialLines = initialLines; - _logMaxReadSize = maxReadSize; - _logPeriod = period; + _logMaxLines = maxLines; + _logMaxSize = maxSize; + _logInitialLines = initialLines; + _logMaxReadSize = maxReadSize; + _logPeriod = period; - storeLogPrefs(); + storeLogPrefs(); } private void loadLogPrefs() { - Preferences logPrefs = _coordinator.getPrefs().node("Log"); - _logMaxLines = logPrefs.getInt("maxLines", 500); - _logMaxSize = logPrefs.getInt("maxSize", 20000); - _logInitialLines = logPrefs.getInt("initialLines", 10); - _logMaxReadSize = logPrefs.getInt("maxReadSize", 10000); - _logPeriod = logPrefs.getInt("period", 300); - - if(_logMaxReadSize + 512 > _messageSizeMax) - { - _logMaxReadSize = _messageSizeMax - 512; - } + Preferences logPrefs = _coordinator.getPrefs().node("Log"); + _logMaxLines = logPrefs.getInt("maxLines", 500); + _logMaxSize = logPrefs.getInt("maxSize", 20000); + _logInitialLines = logPrefs.getInt("initialLines", 10); + _logMaxReadSize = logPrefs.getInt("maxReadSize", 10000); + _logPeriod = logPrefs.getInt("period", 300); + + if(_logMaxReadSize + 512 > _messageSizeMax) + { + _logMaxReadSize = _messageSizeMax - 512; + } } private void storeLogPrefs() { - Preferences logPrefs = _coordinator.getPrefs().node("Log"); - logPrefs.putInt("maxLines", _logMaxLines); - logPrefs.putInt("maxSize", _logMaxSize); - logPrefs.putInt("initialLines", _logInitialLines); - logPrefs.putInt("maxReadSize", _logMaxReadSize); - logPrefs.putInt("period", _logPeriod); + Preferences logPrefs = _coordinator.getPrefs().node("Log"); + logPrefs.putInt("maxLines", _logMaxLines); + logPrefs.putInt("maxSize", _logMaxSize); + logPrefs.putInt("initialLines", _logInitialLines); + logPrefs.putInt("maxReadSize", _logMaxReadSize); + logPrefs.putInt("period", _logPeriod); } private Node findNode(String nodeName) { - return (Node)find(nodeName, _nodes); + return (Node)find(nodeName, _nodes); } private void insertNode(Node node) { - String nodeName = node.toString(); - int i; - for(i = 0; i < _nodes.size(); ++i) - { - String otherNodeName = _nodes.get(i).toString(); - if(nodeName.compareTo(otherNodeName) > 0) - { - i++; - break; - } - } - _nodes.add(i, node); - _treeModel.nodesWereInserted(this, new int[]{_slaves.size() + i}); + String nodeName = node.toString(); + int i; + for(i = 0; i < _nodes.size(); ++i) + { + String otherNodeName = _nodes.get(i).toString(); + if(nodeName.compareTo(otherNodeName) > 0) + { + i++; + break; + } + } + _nodes.add(i, node); + _treeModel.nodesWereInserted(this, new int[]{_slaves.size() + i}); } private void removeNodes(int[] toRemoveIndices, java.util.List toRemove) { - if(toRemove.size() > 0) - { - _nodes.removeAll(toRemove); - _treeModel.nodesWereRemoved(this, toRemoveIndices, toRemove.toArray()); - } + if(toRemove.size() > 0) + { + _nodes.removeAll(toRemove); + _treeModel.nodesWereRemoved(this, toRemoveIndices, toRemove.toArray()); + } } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/LiveDeployment/Server.java b/java/src/IceGridGUI/LiveDeployment/Server.java index e2bdab1af37..275bc022f46 100755 --- a/java/src/IceGridGUI/LiveDeployment/Server.java +++ b/java/src/IceGridGUI/LiveDeployment/Server.java @@ -31,888 +31,888 @@ class Server extends ListArrayTreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; - - if(_state != null) - { - actions[START] = _state == ServerState.Inactive && _enabled - && !_resolver.substitute(_serverDescriptor.activation).equals("session"); - - actions[STOP] = _state != ServerState.Inactive; - actions[ENABLE] = !_enabled; - actions[DISABLE] = _enabled; - actions[WRITE_MESSAGE] = _state != ServerState.Inactive; - actions[RETRIEVE_STDOUT] = true; - actions[RETRIEVE_STDERR] = true; - actions[RETRIEVE_LOG] = _serverDescriptor.logs.length > 0; - - actions[PATCH_SERVER] = - !_serverDescriptor.distrib.icepatch.equals(""); - - if(_state != ServerState.Inactive) - { - Node node = (Node)_parent; - if(!node.isRunningWindows()) - { - for(int i = SIGHUP; i <= SIGTERM; ++i) - { - actions[i] = true; - } - } - } - } - - return actions; + boolean[] actions = new boolean[ACTION_COUNT]; + + if(_state != null) + { + actions[START] = _state == ServerState.Inactive && _enabled + && !_resolver.substitute(_serverDescriptor.activation).equals("session"); + + actions[STOP] = _state != ServerState.Inactive; + actions[ENABLE] = !_enabled; + actions[DISABLE] = _enabled; + actions[WRITE_MESSAGE] = _state != ServerState.Inactive; + actions[RETRIEVE_STDOUT] = true; + actions[RETRIEVE_STDERR] = true; + actions[RETRIEVE_LOG] = _serverDescriptor.logs.length > 0; + + actions[PATCH_SERVER] = + !_serverDescriptor.distrib.icepatch.equals(""); + + if(_state != ServerState.Inactive) + { + Node node = (Node)_parent; + if(!node.isRunningWindows()) + { + for(int i = SIGHUP; i <= SIGTERM; ++i) + { + actions[i] = true; + } + } + } + } + + 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)); - } + 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)); - } + 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); + enableServer(true); } public void disable() { - enableServer(false); + enableServer(false); } public void writeMessage() { - if(_writeMessageDialog == null) - { - _writeMessageDialog = new WriteMessageDialog(getRoot()); - } - _writeMessageDialog.showDialog(_id); + if(_writeMessageDialog == null) + { + _writeMessageDialog = new WriteMessageDialog(getRoot()); + } + _writeMessageDialog.showDialog(_id); } public void retrieveOutput(final boolean stdout) { - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, DeploymentException - { - AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); - - if(stdout) - { - return adminSession.openServerStdOut(_id, count); - } - else - { - return adminSession.openServerStdErr(_id, count); - } - } - - public String getTitle() - { - return "Server " + _id + " " + (stdout ? "stdout" : "stderr"); - } - - public String getDefaultFilename() - { - return _id + (stdout ? ".out" : ".err"); - } - }); + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, DeploymentException + { + AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); + + if(stdout) + { + return adminSession.openServerStdOut(_id, count); + } + else + { + return adminSession.openServerStdErr(_id, count); + } + } + + public String getTitle() + { + return "Server " + _id + " " + (stdout ? "stdout" : "stderr"); + } + + public String getDefaultFilename() + { + return _id + (stdout ? ".out" : ".err"); + } + }); } public void retrieveLog() { - assert _serverDescriptor.logs.length > 0; - - String path = null; - - if(_serverDescriptor.logs.length == 1) - { - path = _resolver.substitute(_serverDescriptor.logs[0]); - } - else - { - Object[] pathArray = new Object[_serverDescriptor.logs.length]; - for(int i = 0; i < _serverDescriptor.logs.length; ++i) - { - pathArray[i] = _resolver.substitute(_serverDescriptor.logs[i]); - } - - path = (String)JOptionPane.showInputDialog( - getCoordinator().getMainFrame(), - "Which log file do you want to retrieve?", - "Retrieve Log File", - JOptionPane.QUESTION_MESSAGE, null, - pathArray, pathArray[0]); - } + assert _serverDescriptor.logs.length > 0; + + String path = null; + + if(_serverDescriptor.logs.length == 1) + { + path = _resolver.substitute(_serverDescriptor.logs[0]); + } + else + { + Object[] pathArray = new Object[_serverDescriptor.logs.length]; + for(int i = 0; i < _serverDescriptor.logs.length; ++i) + { + pathArray[i] = _resolver.substitute(_serverDescriptor.logs[i]); + } + + path = (String)JOptionPane.showInputDialog( + getCoordinator().getMainFrame(), + "Which log file do you want to retrieve?", + "Retrieve Log File", + JOptionPane.QUESTION_MESSAGE, null, + pathArray, pathArray[0]); + } - if(path != null) - { - final String fPath = path; - - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, - DeploymentException - { - AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); - return adminSession.openServerLog(_id, fPath, count); - } - - public String getTitle() - { - return "Server " + _id + " " + new java.io.File(fPath).getName(); - } - - public String getDefaultFilename() - { - return new java.io.File(fPath).getName(); - } - }); - } + if(path != null) + { + final String fPath = path; + + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, + DeploymentException + { + AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); + return adminSession.openServerLog(_id, fPath, count); + } + + public String getTitle() + { + return "Server " + _id + " " + new java.io.File(fPath).getName(); + } + + public String getDefaultFilename() + { + return new java.io.File(fPath).getName(); + } + }); + } } public void signal(final String s) { - final String prefix = "Sending '" + s + "' to server '" + _id + "'..."; - getCoordinator().getStatusBar().setText(prefix); - - AMI_Admin_sendSignal cb = new AMI_Admin_sendSignal() - { - // - // Called by another thread! - // - public void ice_response() - { - amiSuccess(prefix); - } - - public void ice_exception(Ice.UserException e) - { - amiFailure(prefix, "Failed to deliver signal " + s + " to " + _id, e); - } - - public void ice_exception(Ice.LocalException e) - { - amiFailure(prefix, "Failed to deliver signal " + s + " to " + _id, e.toString()); - } - }; - - try - { - getCoordinator().getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - getCoordinator().getAdmin().sendSignal_async(cb, _id, s); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to deliver signal " + s + " to " + _id, e.toString()); - } - finally - { - getCoordinator().getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + final String prefix = "Sending '" + s + "' to server '" + _id + "'..."; + getCoordinator().getStatusBar().setText(prefix); + + AMI_Admin_sendSignal cb = new AMI_Admin_sendSignal() + { + // + // Called by another thread! + // + public void ice_response() + { + amiSuccess(prefix); + } + + public void ice_exception(Ice.UserException e) + { + amiFailure(prefix, "Failed to deliver signal " + s + " to " + _id, e); + } + + public void ice_exception(Ice.LocalException e) + { + amiFailure(prefix, "Failed to deliver signal " + s + " to " + _id, e.toString()); + } + }; + + try + { + getCoordinator().getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + getCoordinator().getAdmin().sendSignal_async(cb, _id, s); + } + catch(Ice.LocalException e) + { + failure(prefix, "Failed to deliver signal " + s + " to " + _id, e.toString()); + } + finally + { + getCoordinator().getMainFrame().setCursor( + Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } } public void patchServer() { - String message = _serverDescriptor.applicationDistrib ? - "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?" : - "You are about to install or refresh the distribution for this server.\n" - + "Do you want to shut down the server for this update?"; - - int shutdown = JOptionPane.showConfirmDialog( - getCoordinator().getMainFrame(), - message, - "Patch Confirmation", - JOptionPane.YES_NO_CANCEL_OPTION); + String message = _serverDescriptor.applicationDistrib ? + "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?" : + "You are about to install or refresh the distribution for this server.\n" + + "Do you want to shut down the server for this update?"; + + int shutdown = JOptionPane.showConfirmDialog( + getCoordinator().getMainFrame(), + message, + "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)); - } + 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)); - } + 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(PATCH_SERVER)); - _popup.addSeparator(); - _popup.add(la.get(WRITE_MESSAGE)); - _popup.add(la.get(RETRIEVE_STDOUT)); - _popup.add(la.get(RETRIEVE_STDERR)); - _popup.add(la.get(RETRIEVE_LOG)); - _popup.addSeparator(); - - _signalMenu = new JMenu("Send Signal"); - _popup.add(_signalMenu); - - _signalMenu.add(la.get(SIGHUP)); - _signalMenu.add(la.get(SIGINT)); - _signalMenu.add(la.get(SIGQUIT)); - _signalMenu.add(la.get(SIGKILL)); - _signalMenu.add(la.get(SIGUSR1)); - _signalMenu.add(la.get(SIGUSR2)); - _signalMenu.add(la.get(SIGTERM)); - } - - la.setTarget(this); - _signalMenu.setEnabled(la.get(SIGHUP).isEnabled()); - return _popup; + 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(PATCH_SERVER)); + _popup.addSeparator(); + _popup.add(la.get(WRITE_MESSAGE)); + _popup.add(la.get(RETRIEVE_STDOUT)); + _popup.add(la.get(RETRIEVE_STDERR)); + _popup.add(la.get(RETRIEVE_LOG)); + _popup.addSeparator(); + + _signalMenu = new JMenu("Send Signal"); + _popup.add(_signalMenu); + + _signalMenu.add(la.get(SIGHUP)); + _signalMenu.add(la.get(SIGINT)); + _signalMenu.add(la.get(SIGQUIT)); + _signalMenu.add(la.get(SIGKILL)); + _signalMenu.add(la.get(SIGUSR1)); + _signalMenu.add(la.get(SIGUSR2)); + _signalMenu.add(la.get(SIGTERM)); + } + + la.setTarget(this); + _signalMenu.setEnabled(la.get(SIGHUP).isEnabled()); + return _popup; } public Editor getEditor() { - if(_editor == null) - { - _editor = new ServerEditor(getCoordinator()); - } - _editor.show(this); - return _editor; + 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[8][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.ActivationTimedOut.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.ActivationTimedOut.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.ActivationTimedOut.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.ActivationTimedOut.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); + 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[8][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.ActivationTimedOut.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.ActivationTimedOut.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.ActivationTimedOut.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.ActivationTimedOut.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(); + 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; + return _application; } ServerInstanceDescriptor getInstanceDescriptor() { - return _instanceDescriptor; + return _instanceDescriptor; } ServerDescriptor getServerDescriptor() { - return _serverDescriptor; + return _serverDescriptor; } ServerState getState() { - return _state; + return _state; } int getPid() { - return _pid; + return _pid; } boolean isEnabled() { - return _enabled; + return _enabled; } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } void rebuild(Server server) - { - _resolver = server._resolver; - _instanceDescriptor = server._instanceDescriptor; - _serverDescriptor = server._serverDescriptor; - _application = server._application; - _adapters = server._adapters; - _dbEnvs = server._dbEnvs; + { + _resolver = server._resolver; + _instanceDescriptor = server._instanceDescriptor; + _serverDescriptor = server._serverDescriptor; + _application = server._application; + _adapters = server._adapters; + _dbEnvs = server._dbEnvs; - _services = server._services; - - _childrenArray[0] = _adapters; - _childrenArray[1] = _dbEnvs; - _childrenArray[2] = _services; + _services = server._services; + + _childrenArray[0] = _adapters; + _childrenArray[1] = _dbEnvs; + _childrenArray[2] = _services; - getRoot().getTreeModel().nodeStructureChanged(this); + getRoot().getTreeModel().nodeStructureChanged(this); } void rebuild(Utils.Resolver resolver, boolean variablesChanged, java.util.Set serviceTemplates, - java.util.Set serverTemplates) - { - if(variablesChanged || - (_instanceDescriptor != null && serverTemplates != 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); - _serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor; - } - else - { - _resolver.reset(resolver); - _resolver.put("server", _id); - } - - _adapters.clear(); - createAdapters(); - _dbEnvs.clear(); - createDbEnvs(); - _services.clear(); - _servicePropertySets.clear(); - createServices(); - - getRoot().getTreeModel().nodeStructureChanged(this); - } - else if(serviceTemplates != null && serviceTemplates.size() > 0 && _serverDescriptor instanceof IceBoxDescriptor) - { - _services.clear(); - _servicePropertySets.clear(); - createServices(); - getRoot().getTreeModel().nodeStructureChanged(this); - } + java.util.Set serverTemplates) + { + if(variablesChanged || + (_instanceDescriptor != null && serverTemplates != 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); + _serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor; + } + else + { + _resolver.reset(resolver); + _resolver.put("server", _id); + } + + _adapters.clear(); + createAdapters(); + _dbEnvs.clear(); + createDbEnvs(); + _services.clear(); + _servicePropertySets.clear(); + createServices(); + + getRoot().getTreeModel().nodeStructureChanged(this); + } + else if(serviceTemplates != null && serviceTemplates.size() > 0 && _serverDescriptor instanceof IceBoxDescriptor) + { + _services.clear(); + _servicePropertySets.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); - } - } + 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; + 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; + 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); + 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(); - } + 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(); + } } java.util.SortedMap getProperties() { - java.util.List psList = new java.util.LinkedList(); - Node node = (Node)_parent; + java.util.List psList = new java.util.LinkedList(); + Node node = (Node)_parent; - - psList.add(node.expand(_serverDescriptor.propertySet, - _application.name, _resolver)); + + psList.add(node.expand(_serverDescriptor.propertySet, + _application.name, _resolver)); - if(_instanceDescriptor != null) - { - psList.add(node.expand(_instanceDescriptor.propertySet, - _application.name, _resolver)); - } + if(_instanceDescriptor != null) + { + psList.add(node.expand(_instanceDescriptor.propertySet, + _application.name, _resolver)); + } - return Utils.propertySetsToMap(psList, _resolver); + return Utils.propertySetsToMap(psList, _resolver); } 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); - } + 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); - } + 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) - { - if(_instanceDescriptor != null) - { - java.util.Iterator p = _instanceDescriptor.servicePropertySets.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - _servicePropertySets.put(_resolver.substitute((String)entry.getKey()), entry.getValue()); - } - } - - IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)_serverDescriptor; - - java.util.Iterator p = iceBoxDescriptor.services.iterator(); - while(p.hasNext()) - { - ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor)p.next(); - createService(descriptor); - } - } + if(_serverDescriptor instanceof IceBoxDescriptor) + { + if(_instanceDescriptor != null) + { + java.util.Iterator p = _instanceDescriptor.servicePropertySets.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + _servicePropertySets.put(_resolver.substitute((String)entry.getKey()), entry.getValue()); + } + } + + 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); - } - - PropertySetDescriptor serverInstancePSDescriptor = - (PropertySetDescriptor)_servicePropertySets.get(serviceName); - - _services.add(new Service(this, serviceName, serviceResolver, - descriptor, serviceDescriptor, serverInstancePSDescriptor)); + 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); + } + + PropertySetDescriptor serverInstancePSDescriptor = + (PropertySetDescriptor)_servicePropertySets.get(serviceName); + + _services.add(new Service(this, serviceName, serviceResolver, + descriptor, serviceDescriptor, serverInstancePSDescriptor)); } 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; + String result = (state == null ? "Unknown" : state.toString()); + + if(!enabled) + { + result += ", disabled"; + } + + if(pid != 0) + { + result += ", pid: " + pid; + } + return result; } diff --git a/java/src/IceGridGUI/LiveDeployment/ServerEditor.java b/java/src/IceGridGUI/LiveDeployment/ServerEditor.java index 16a6d05f888..37299ce5be2 100755 --- a/java/src/IceGridGUI/LiveDeployment/ServerEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/ServerEditor.java @@ -34,244 +34,244 @@ class ServerEditor extends CommunicatorEditor { public JToolBar getToolBar() { - if(_toolBar == null) - { - _toolBar = new ToolBar(); - } - return _toolBar; + 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); - _iceVersion.setEditable(false); - _exe.setEditable(false); - _pwd.setEditable(false); + _coordinator = c; + _currentState.setEditable(false); + _currentPid.setEditable(false); + _enabled.setEnabled(false); + + _application.setEditable(false); + _iceVersion.setEditable(false); + _exe.setEditable(false); + _pwd.setEditable(false); - _activation.setEditable(false); - _activationTimeout.setEditable(false); - _deactivationTimeout.setEditable(false); - - _options.setEditable(false); - _user.setEditable(false); - - _allocatable.setEnabled(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) - { - ApplicationPane app = _coordinator.openLiveApplication(_application.getText()); - if(app != null) - { - app.getRoot(). - selectServer(((Node)_target.getParent()).getId(), _target.getId()); - } - } - }; - gotoApplication.putValue(Action.SHORT_DESCRIPTION, - "View/Edit this application"); - _gotoApplication = new JButton(gotoApplication); + _activation.setEditable(false); + _activationTimeout.setEditable(false); + _deactivationTimeout.setEditable(false); + + _options.setEditable(false); + _user.setEditable(false); + + _allocatable.setEnabled(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) + { + ApplicationPane app = _coordinator.openLiveApplication(_application.getText()); + if(app != null) + { + app.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")); - _iceVersion.setText(resolver.substitute(descriptor.iceVersion)); - - super.show(descriptor, server.getProperties(), 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); - - _envs.setEnvs(descriptor.envs, resolver); - - _user.setText(resolver.substitute(descriptor.user)); - - _activation.setText(resolver.substitute(descriptor.activation)); - _activationTimeout.setText(resolver.substitute(descriptor.activationTimeout)); - _deactivationTimeout.setText(resolver.substitute(descriptor.deactivationTimeout)); - - _allocatable.setSelected(descriptor.allocatable); - - _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); + _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")); + _iceVersion.setText(resolver.substitute(descriptor.iceVersion)); + + super.show(descriptor, server.getProperties(), 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); + + _envs.setEnvs(descriptor.envs, resolver); + + _user.setText(resolver.substitute(descriptor.user)); + + _activation.setText(resolver.substitute(descriptor.activation)); + _activationTimeout.setText(resolver.substitute(descriptor.activationTimeout)); + _deactivationTimeout.setText(resolver.substitute(descriptor.deactivationTimeout)); + + _allocatable.setSelected(descriptor.allocatable); + + _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(); - builder.append("Ice Version"); - builder.append(_iceVersion, 3); - 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("Run as"); - builder.append(_user, 3); - builder.nextLine(); - builder.append("Environment Variables"); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextLine(); - builder.append(""); - builder.nextRow(-6); - CellConstraints cc = new CellConstraints(); - JScrollPane scrollPane = new JScrollPane(_envs); - builder.add(scrollPane, - cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); - builder.nextRow(6); - 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(); - builder.append("", _allocatable); - 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(); + 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(); + builder.append("Ice Version"); + builder.append(_iceVersion, 3); + 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("Run as"); + builder.append(_user, 3); + builder.nextLine(); + builder.append("Environment Variables"); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextLine(); + builder.append(""); + builder.nextRow(-6); + CellConstraints cc = new CellConstraints(); + JScrollPane scrollPane = new JScrollPane(_envs); + builder.add(scrollPane, + cc.xywh(builder.getColumn(), builder.getRow(), 3, 7)); + builder.nextRow(6); + 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(); + builder.append("", _allocatable); + 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"); + 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 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)); + } } diff --git a/java/src/IceGridGUI/LiveDeployment/Service.java b/java/src/IceGridGUI/LiveDeployment/Service.java index dae7bd628a4..5fd67100a4f 100755 --- a/java/src/IceGridGUI/LiveDeployment/Service.java +++ b/java/src/IceGridGUI/LiveDeployment/Service.java @@ -27,247 +27,247 @@ class Service extends ListArrayTreeNode // public boolean[] getAvailableActions() { - boolean[] actions = new boolean[ACTION_COUNT]; + boolean[] actions = new boolean[ACTION_COUNT]; - if(((Server)_parent).getState() != null) - { - actions[RETRIEVE_LOG] = _serviceDescriptor.logs.length > 0; - } - return actions; + if(((Server)_parent).getState() != null) + { + actions[RETRIEVE_LOG] = _serviceDescriptor.logs.length > 0; + } + return actions; } public void retrieveLog() { - assert _serviceDescriptor.logs.length > 0; - - String path = null; - - if(_serviceDescriptor.logs.length == 1) - { - path = _resolver.substitute(_serviceDescriptor.logs[0]); - } - else - { - Object[] pathArray = new Object[_serviceDescriptor.logs.length]; - for(int i = 0; i < _serviceDescriptor.logs.length; ++i) - { - pathArray[i] = _resolver.substitute(_serviceDescriptor.logs[i]); - } - - path = (String)JOptionPane.showInputDialog( - getCoordinator().getMainFrame(), - "Which log file do you want to retrieve?", - "Retrieve Log File", - JOptionPane.QUESTION_MESSAGE, null, - pathArray, pathArray[0]); - } + assert _serviceDescriptor.logs.length > 0; + + String path = null; + + if(_serviceDescriptor.logs.length == 1) + { + path = _resolver.substitute(_serviceDescriptor.logs[0]); + } + else + { + Object[] pathArray = new Object[_serviceDescriptor.logs.length]; + for(int i = 0; i < _serviceDescriptor.logs.length; ++i) + { + pathArray[i] = _resolver.substitute(_serviceDescriptor.logs[i]); + } + + path = (String)JOptionPane.showInputDialog( + getCoordinator().getMainFrame(), + "Which log file do you want to retrieve?", + "Retrieve Log File", + JOptionPane.QUESTION_MESSAGE, null, + pathArray, pathArray[0]); + } - if(path != null) - { - final String fPath = path; - - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, - DeploymentException - { - AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); - return adminSession.openServerLog(_parent.getId(), fPath, count); - } - - public String getTitle() - { - return "Service " + _parent.getId() + "/" + _id + " " + new java.io.File(fPath).getName(); - } - - public String getDefaultFilename() - { - return new java.io.File(fPath).getName(); - } - }); - } + if(path != null) + { + final String fPath = path; + + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, ServerNotExistException, NodeUnreachableException, + DeploymentException + { + AdminSessionPrx adminSession = getRoot().getCoordinator().getSession(); + return adminSession.openServerLog(_parent.getId(), fPath, count); + } + + public String getTitle() + { + return "Service " + _parent.getId() + "/" + _id + " " + new java.io.File(fPath).getName(); + } + + public String getDefaultFilename() + { + return new java.io.File(fPath).getName(); + } + }); + } } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + 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); + 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; + if(_editor == null) + { + _editor = new ServiceEditor(); + } + _editor.show(this); + return _editor; } public JPopupMenu getPopupMenu() { - LiveActions la = getCoordinator().getLiveActionsForPopup(); - - if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(la.get(RETRIEVE_LOG)); - } - - la.setTarget(this); - return _popup; + LiveActions la = getCoordinator().getLiveActionsForPopup(); + + if(_popup == null) + { + _popup = new JPopupMenu(); + _popup.add(la.get(RETRIEVE_LOG)); + } + + la.setTarget(this); + return _popup; } Service(Server parent, String serviceName, Utils.Resolver resolver, - ServiceInstanceDescriptor descriptor, - ServiceDescriptor serviceDescriptor, - PropertySetDescriptor serverInstancePSDescriptor) + ServiceInstanceDescriptor descriptor, + ServiceDescriptor serviceDescriptor, + PropertySetDescriptor serverInstancePSDescriptor) { - super(parent, serviceName, 2); - _resolver = resolver; - - _instanceDescriptor = descriptor; - _serviceDescriptor = serviceDescriptor; - _serverInstancePSDescriptor = serverInstancePSDescriptor; - - _childrenArray[0] = _adapters; - _childrenArray[1] = _dbEnvs; - - createAdapters(); - createDbEnvs(); + super(parent, serviceName, 2); + _resolver = resolver; + + _instanceDescriptor = descriptor; + _serviceDescriptor = serviceDescriptor; + _serverInstancePSDescriptor = serverInstancePSDescriptor; + + _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; + 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; + 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); - } + java.util.Iterator p = _adapters.iterator(); + while(p.hasNext()) + { + Adapter adapter = (Adapter)p.next(); + adapter.update((AdapterDynamicInfo)null); + } } Utils.Resolver getResolver() { - return _resolver; + return _resolver; } ServiceDescriptor getServiceDescriptor() { - return _serviceDescriptor; + return _serviceDescriptor; } ServiceInstanceDescriptor getInstanceDescriptor() { - return _instanceDescriptor; + return _instanceDescriptor; } java.util.SortedMap getProperties() { - java.util.List psList = new java.util.LinkedList(); - Node node = (Node)_parent.getParent(); + java.util.List psList = new java.util.LinkedList(); + Node node = (Node)_parent.getParent(); - String applicationName = ((Server)_parent).getApplication().name; + String applicationName = ((Server)_parent).getApplication().name; - psList.add(node.expand(_serviceDescriptor.propertySet, - applicationName, _resolver)); + psList.add(node.expand(_serviceDescriptor.propertySet, + applicationName, _resolver)); - if(_instanceDescriptor != null) - { - psList.add(node.expand(_instanceDescriptor.propertySet, - applicationName, _resolver)); - } + if(_instanceDescriptor != null) + { + psList.add(node.expand(_instanceDescriptor.propertySet, + applicationName, _resolver)); + } - if(_serverInstancePSDescriptor != null) - { - psList.add(node.expand(_serverInstancePSDescriptor, - applicationName, _resolver)); + if(_serverInstancePSDescriptor != null) + { + psList.add(node.expand(_serverInstancePSDescriptor, + applicationName, _resolver)); - } + } - return Utils.propertySetsToMap(psList, _resolver); + return Utils.propertySetsToMap(psList, _resolver); } 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); - } + 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); - } + 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 final ServiceInstanceDescriptor _instanceDescriptor; diff --git a/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java b/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java index 53e5e1c4e6e..e4768aa7c19 100755 --- a/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/ServiceEditor.java @@ -18,32 +18,32 @@ class ServiceEditor extends CommunicatorEditor { ServiceEditor() { - _entry.setEditable(false); + _entry.setEditable(false); } void show(Service service) { - ServiceDescriptor descriptor = service.getServiceDescriptor(); - Utils.Resolver resolver = service.getResolver(); + ServiceDescriptor descriptor = service.getServiceDescriptor(); + Utils.Resolver resolver = service.getResolver(); - show(descriptor, service.getProperties(), resolver); - _entry.setText(resolver.substitute(descriptor.entry)); + show(descriptor, service.getProperties(), resolver); + _entry.setText(resolver.substitute(descriptor.entry)); } protected void appendProperties(DefaultFormBuilder builder) { - super.appendProperties(builder); + super.appendProperties(builder); - builder.append("Entry Point"); - builder.append(_entry, 3); - builder.nextLine(); + builder.append("Entry Point"); + builder.append(_entry, 3); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Service Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Service Properties"); } private JTextField _entry = new JTextField(20); diff --git a/java/src/IceGridGUI/LiveDeployment/ShowLogDialog.java b/java/src/IceGridGUI/LiveDeployment/ShowLogDialog.java index c74f3508866..6454cbfeac8 100644 --- a/java/src/IceGridGUI/LiveDeployment/ShowLogDialog.java +++ b/java/src/IceGridGUI/LiveDeployment/ShowLogDialog.java @@ -48,697 +48,697 @@ class ShowLogDialog extends JDialog { static interface FileIteratorFactory { - FileIteratorPrx open(int count) - throws Ice.UserException; + FileIteratorPrx open(int count) + throws Ice.UserException; - String getTitle(); + String getTitle(); - String getDefaultFilename(); + String getDefaultFilename(); } private class FIFOTextArea extends JTextArea { - FIFOTextArea(int rows, int colums) - { - super(rows, colums); - setEditable(false); - setLineWrap(true); - } - - public void appendLines(final String[] lines, final int maxLines, final int maxSize) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - for(int i = 0; i < lines.length; ++i) - { - // - // The last line is always incomplete - // - if(i + 1 != lines.length) - { - append(lines[i] + "\n"); - } - else - { - append(lines[i]); - } - removeLines(maxLines, maxSize); - } - } - }); - } - - public void removeLines(int maxLines, int maxSize) - { - javax.swing.text.Document doc = getDocument(); - javax.swing.text.Element rootElt = doc.getDefaultRootElement(); - - // - // We keep at least one line, no matter its length - // - int lineCount = getLineCount(); - while(lineCount > 1 && (doc.getLength() > maxSize || (lineCount > maxLines))) - { - javax.swing.text.Element firstLine = rootElt.getElement(0); - try - { - doc.remove(0, firstLine.getEndOffset()); - } - catch(javax.swing.text.BadLocationException ble) - { - assert false; - } - lineCount--; - } - setCaretPosition(doc.getLength()); - } + FIFOTextArea(int rows, int colums) + { + super(rows, colums); + setEditable(false); + setLineWrap(true); + } + + public void appendLines(final String[] lines, final int maxLines, final int maxSize) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + for(int i = 0; i < lines.length; ++i) + { + // + // The last line is always incomplete + // + if(i + 1 != lines.length) + { + append(lines[i] + "\n"); + } + else + { + append(lines[i]); + } + removeLines(maxLines, maxSize); + } + } + }); + } + + public void removeLines(int maxLines, int maxSize) + { + javax.swing.text.Document doc = getDocument(); + javax.swing.text.Element rootElt = doc.getDefaultRootElement(); + + // + // We keep at least one line, no matter its length + // + int lineCount = getLineCount(); + while(lineCount > 1 && (doc.getLength() > maxSize || (lineCount > maxLines))) + { + javax.swing.text.Element firstLine = rootElt.getElement(0); + try + { + doc.remove(0, firstLine.getEndOffset()); + } + catch(javax.swing.text.BadLocationException ble) + { + assert false; + } + lineCount--; + } + setCaretPosition(doc.getLength()); + } } private class ReaderThread extends Thread { - ReaderThread() - { - _threadMaxLines = _maxLines; - _threadMaxSize = _maxSize; - _threadInitialLines = _initialLines; - _threadMaxReadSize = _maxReadSize; - _threadPeriod = _period; - - _playButton.setSelected(true); - _playItem.setSelected(true); - _pause.setEnabled(true); - } - - private void openError(final String message) - { - SwingUtilities.invokeLater( - new Runnable() - { - public void run() - { - if(_textArea.getText() == null || _textArea.getText().length() == 0) - { - close(true); - } - else - { - stopReading(); - } - - JOptionPane.showMessageDialog( - ShowLogDialog.this, - message, - _factory.getTitle() + ": cannot open file", - JOptionPane.ERROR_MESSAGE); - } - }); - } - - - public void run() - { - // - // Open file - // - int initialLines; - - synchronized(this) - { - initialLines = _threadInitialLines; - } - - try - { - _p = _factory.open(initialLines); - } - catch(Ice.UserException e) - { - openError(e.toString()); - return; - } - catch(Ice.LocalException e) - { - openError(e.toString()); - return; - } - - SwingUtilities.invokeLater( - new Runnable() - { - public void run() - { - if(isVisible()) - { - _textArea.setText(null); - } - else - { - setVisible(true); - } - } - }); - - boolean firstRun = true; - for(;;) - { - synchronized(this) - { - if(!_done) - { - if(_paused) - { - while(_paused && !_done) - { - try - { - wait(); - } - catch(InterruptedException e) - { - } - } - } - else if(!firstRun) - { - try - { - wait(_threadPeriod); - } - catch(InterruptedException e) - { - } - } - else - { - firstRun = false; - } - } - - if(_done) - { - cleanupIterator(); - return; - } - } - - boolean eofEncountered = false; - - while(!eofEncountered) - { - int maxLines; - int maxSize; - int maxReadSize; - - synchronized(this) - { - if(_done || _paused) - { - break; // while(!eofEncountered) - } - - maxLines = _threadMaxLines; - maxSize = _threadMaxSize; - maxReadSize = _threadMaxReadSize; - } - - Ice.StringSeqHolder linesHolder = new Ice.StringSeqHolder(); - - try - { - eofEncountered = _p.read(maxReadSize, linesHolder); - } - catch(IceGrid.FileNotAvailableException e) - { - _textArea.appendLines(new String[] - { - "---------------------------", - "IceGridAdmin caught: " + e.toString(), - "---------------------------" - }, maxLines, maxSize); - SwingUtilities.invokeLater( - new Runnable() - { - public void run() - { - stopReading(); - } - }); - cleanupIterator(); - return; - } - catch(Ice.LocalException e) - { - _textArea.appendLines(new String[] - { - "---------------------------", - "IceGridAdmin caught: " + e.toString(), - "---------------------------" - }, maxLines, maxSize); - SwingUtilities.invokeLater( - new Runnable() - { - public void run() - { - stopReading(); - } - }); - return; - } - - _textArea.appendLines(linesHolder.value, maxLines, maxSize); - } - } - } - - private void cleanupIterator() - { - try - { - _p.destroy(); - } - catch(Ice.LocalException e) - { - // Ignored, maybe should log warning - } - } - - synchronized void pause() - { - if(!_paused) - { - _paused = true; - notify(); - } - } - - synchronized void terminate() - { - if(!_done) - { - _done = true; - notify(); - } - } - - synchronized void play() - { - if(_paused) - { - _paused = false; - notify(); - } - } - - synchronized void setPrefs() - { - _threadMaxLines = _maxLines; - _threadMaxSize = _maxSize; - _threadInitialLines = _initialLines; - _threadMaxReadSize = _maxReadSize; - _threadPeriod = _period; - } - - private FileIteratorPrx _p; - private boolean _done = false; - private boolean _paused = false; - - private int _threadMaxLines; - private int _threadMaxSize; - private int _threadInitialLines; - private int _threadMaxReadSize; - private int _threadPeriod; + ReaderThread() + { + _threadMaxLines = _maxLines; + _threadMaxSize = _maxSize; + _threadInitialLines = _initialLines; + _threadMaxReadSize = _maxReadSize; + _threadPeriod = _period; + + _playButton.setSelected(true); + _playItem.setSelected(true); + _pause.setEnabled(true); + } + + private void openError(final String message) + { + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + if(_textArea.getText() == null || _textArea.getText().length() == 0) + { + close(true); + } + else + { + stopReading(); + } + + JOptionPane.showMessageDialog( + ShowLogDialog.this, + message, + _factory.getTitle() + ": cannot open file", + JOptionPane.ERROR_MESSAGE); + } + }); + } + + + public void run() + { + // + // Open file + // + int initialLines; + + synchronized(this) + { + initialLines = _threadInitialLines; + } + + try + { + _p = _factory.open(initialLines); + } + catch(Ice.UserException e) + { + openError(e.toString()); + return; + } + catch(Ice.LocalException e) + { + openError(e.toString()); + return; + } + + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + if(isVisible()) + { + _textArea.setText(null); + } + else + { + setVisible(true); + } + } + }); + + boolean firstRun = true; + for(;;) + { + synchronized(this) + { + if(!_done) + { + if(_paused) + { + while(_paused && !_done) + { + try + { + wait(); + } + catch(InterruptedException e) + { + } + } + } + else if(!firstRun) + { + try + { + wait(_threadPeriod); + } + catch(InterruptedException e) + { + } + } + else + { + firstRun = false; + } + } + + if(_done) + { + cleanupIterator(); + return; + } + } + + boolean eofEncountered = false; + + while(!eofEncountered) + { + int maxLines; + int maxSize; + int maxReadSize; + + synchronized(this) + { + if(_done || _paused) + { + break; // while(!eofEncountered) + } + + maxLines = _threadMaxLines; + maxSize = _threadMaxSize; + maxReadSize = _threadMaxReadSize; + } + + Ice.StringSeqHolder linesHolder = new Ice.StringSeqHolder(); + + try + { + eofEncountered = _p.read(maxReadSize, linesHolder); + } + catch(IceGrid.FileNotAvailableException e) + { + _textArea.appendLines(new String[] + { + "---------------------------", + "IceGridAdmin caught: " + e.toString(), + "---------------------------" + }, maxLines, maxSize); + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + stopReading(); + } + }); + cleanupIterator(); + return; + } + catch(Ice.LocalException e) + { + _textArea.appendLines(new String[] + { + "---------------------------", + "IceGridAdmin caught: " + e.toString(), + "---------------------------" + }, maxLines, maxSize); + SwingUtilities.invokeLater( + new Runnable() + { + public void run() + { + stopReading(); + } + }); + return; + } + + _textArea.appendLines(linesHolder.value, maxLines, maxSize); + } + } + } + + private void cleanupIterator() + { + try + { + _p.destroy(); + } + catch(Ice.LocalException e) + { + // Ignored, maybe should log warning + } + } + + synchronized void pause() + { + if(!_paused) + { + _paused = true; + notify(); + } + } + + synchronized void terminate() + { + if(!_done) + { + _done = true; + notify(); + } + } + + synchronized void play() + { + if(_paused) + { + _paused = false; + notify(); + } + } + + synchronized void setPrefs() + { + _threadMaxLines = _maxLines; + _threadMaxSize = _maxSize; + _threadInitialLines = _initialLines; + _threadMaxReadSize = _maxReadSize; + _threadPeriod = _period; + } + + private FileIteratorPrx _p; + private boolean _done = false; + private boolean _paused = false; + + private int _threadMaxLines; + private int _threadMaxSize; + private int _threadInitialLines; + private int _threadMaxReadSize; + private int _threadPeriod; } private class MenuBar extends JMenuBar { - private MenuBar() - { - putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); - putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR); - - final int MENU_MASK = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - - // - // File menu - // - JMenu fileMenu = new JMenu("File"); - fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F); - add(fileMenu); - - ButtonGroup bg = new ButtonGroup(); - - _pauseItem = new JRadioButtonMenuItem(_pause); - fileMenu.add(_pauseItem); - bg.add(_pauseItem); - _playItem = new JRadioButtonMenuItem(_play); - fileMenu.add(_playItem); - bg.add(_playItem); - _stopItem = new JRadioButtonMenuItem(_stop); - fileMenu.add(_stopItem); - bg.add(_stopItem); - fileMenu.addSeparator(); + private MenuBar() + { + putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); + putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR); + + final int MENU_MASK = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + + // + // File menu + // + JMenu fileMenu = new JMenu("File"); + fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F); + add(fileMenu); + + ButtonGroup bg = new ButtonGroup(); + + _pauseItem = new JRadioButtonMenuItem(_pause); + fileMenu.add(_pauseItem); + bg.add(_pauseItem); + _playItem = new JRadioButtonMenuItem(_play); + fileMenu.add(_playItem); + bg.add(_playItem); + _stopItem = new JRadioButtonMenuItem(_stop); + fileMenu.add(_stopItem); + bg.add(_stopItem); + fileMenu.addSeparator(); - Action save = new AbstractAction("Save As...") - { - public void actionPerformed(ActionEvent e) - { - JFileChooser fileChooser = _root.getCoordinator().getSaveLogChooser(); - - fileChooser.setSelectedFile(new java.io.File(fileChooser.getCurrentDirectory(), - _factory.getDefaultFilename())); - - java.io.File file = null; - - while(file == null) - { - int result = fileChooser.showSaveDialog(ShowLogDialog.this); - if(result == JFileChooser.APPROVE_OPTION) - { - file = fileChooser.getSelectedFile(); - - if(file != null) - { - if(!file.exists() && file.getName().indexOf('.') == -1) - { - file = new java.io.File(file.getAbsolutePath() + ".log"); - } - - java.io.OutputStreamWriter os = null; - - try - { - os = new java.io.OutputStreamWriter(new java.io.FileOutputStream(file)); - String txt = _textArea.getText(); - if(txt == null) - { - txt = ""; - } - os.write(txt, 0, txt.length()); - } - catch(java.io.IOException io) - { - JOptionPane.showMessageDialog( - ShowLogDialog.this, - io.toString(), - "Cannot write file", - JOptionPane.ERROR_MESSAGE); - } - finally - { - if(os != null) - { - try - { - os.close(); - } - catch(java.io.IOException io) - { - } - } - } - } - } - else - { - break; // while - } - } - } - }; - save.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK)); - save.putValue(Action.SHORT_DESCRIPTION, "Save As..."); - fileMenu.add(save); - fileMenu.addSeparator(); - - fileMenu.add(new AbstractAction("Close") - { - public void actionPerformed(ActionEvent e) - { - close(true); - } - }); - JMenu editMenu = new JMenu("Edit"); - editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E); - add(editMenu); - - Action copy = new AbstractAction("Copy") - { - public void actionPerformed(ActionEvent e) - { - _textArea.copy(); - } - - }; - copy.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); - copy.putValue(Action.SHORT_DESCRIPTION, "Copy"); - editMenu.add(copy); - - editMenu.addSeparator(); - Action selectAll = new AbstractAction("Select All") - { - public void actionPerformed(ActionEvent e) - { - _textArea.grabFocus(); - _textArea.selectAll(); - } - }; - selectAll.putValue(Action.ACCELERATOR_KEY, - KeyStroke.getKeyStroke(KeyEvent.VK_A, MENU_MASK)); - selectAll.putValue(Action.SHORT_DESCRIPTION, "Select All"); - - editMenu.add(selectAll); - editMenu.addSeparator(); - editMenu.add(new AbstractAction("Preferences...") - { - public void actionPerformed(ActionEvent e) - { - new ShowLogPrefsDialog(ShowLogDialog.this); - } - }); - } + Action save = new AbstractAction("Save As...") + { + public void actionPerformed(ActionEvent e) + { + JFileChooser fileChooser = _root.getCoordinator().getSaveLogChooser(); + + fileChooser.setSelectedFile(new java.io.File(fileChooser.getCurrentDirectory(), + _factory.getDefaultFilename())); + + java.io.File file = null; + + while(file == null) + { + int result = fileChooser.showSaveDialog(ShowLogDialog.this); + if(result == JFileChooser.APPROVE_OPTION) + { + file = fileChooser.getSelectedFile(); + + if(file != null) + { + if(!file.exists() && file.getName().indexOf('.') == -1) + { + file = new java.io.File(file.getAbsolutePath() + ".log"); + } + + java.io.OutputStreamWriter os = null; + + try + { + os = new java.io.OutputStreamWriter(new java.io.FileOutputStream(file)); + String txt = _textArea.getText(); + if(txt == null) + { + txt = ""; + } + os.write(txt, 0, txt.length()); + } + catch(java.io.IOException io) + { + JOptionPane.showMessageDialog( + ShowLogDialog.this, + io.toString(), + "Cannot write file", + JOptionPane.ERROR_MESSAGE); + } + finally + { + if(os != null) + { + try + { + os.close(); + } + catch(java.io.IOException io) + { + } + } + } + } + } + else + { + break; // while + } + } + } + }; + save.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK)); + save.putValue(Action.SHORT_DESCRIPTION, "Save As..."); + fileMenu.add(save); + fileMenu.addSeparator(); + + fileMenu.add(new AbstractAction("Close") + { + public void actionPerformed(ActionEvent e) + { + close(true); + } + }); + JMenu editMenu = new JMenu("Edit"); + editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E); + add(editMenu); + + Action copy = new AbstractAction("Copy") + { + public void actionPerformed(ActionEvent e) + { + _textArea.copy(); + } + + }; + copy.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_C, MENU_MASK)); + copy.putValue(Action.SHORT_DESCRIPTION, "Copy"); + editMenu.add(copy); + + editMenu.addSeparator(); + Action selectAll = new AbstractAction("Select All") + { + public void actionPerformed(ActionEvent e) + { + _textArea.grabFocus(); + _textArea.selectAll(); + } + }; + selectAll.putValue(Action.ACCELERATOR_KEY, + KeyStroke.getKeyStroke(KeyEvent.VK_A, MENU_MASK)); + selectAll.putValue(Action.SHORT_DESCRIPTION, "Select All"); + + editMenu.add(selectAll); + editMenu.addSeparator(); + editMenu.add(new AbstractAction("Preferences...") + { + public void actionPerformed(ActionEvent e) + { + new ShowLogPrefsDialog(ShowLogDialog.this); + } + }); + } } 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); - - _pauseButton = new JToggleButton(_pause); - _pauseButton.setText(null); - _pauseButton.setIcon(Utils.getIcon("/icons/16x16/pause.png")); - add(_pauseButton); - _playButton = new JToggleButton(_play); - _playButton.setText(null); - _playButton.setIcon(Utils.getIcon("/icons/16x16/start.png")); - add(_playButton); - _stopButton = new JToggleButton(_stop); - _stopButton.setText(null); - _stopButton.setIcon(Utils.getIcon("/icons/16x16/stop.png")); - add(_stopButton); - - ButtonGroup bg = new ButtonGroup(); - bg.add(_pauseButton); - bg.add(_playButton); - bg.add(_stopButton); - } + private ToolBar() + { + putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); + putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR); + setFloatable(false); + putClientProperty("JToolBar.isRollover", Boolean.TRUE); + + _pauseButton = new JToggleButton(_pause); + _pauseButton.setText(null); + _pauseButton.setIcon(Utils.getIcon("/icons/16x16/pause.png")); + add(_pauseButton); + _playButton = new JToggleButton(_play); + _playButton.setText(null); + _playButton.setIcon(Utils.getIcon("/icons/16x16/start.png")); + add(_playButton); + _stopButton = new JToggleButton(_stop); + _stopButton.setText(null); + _stopButton.setIcon(Utils.getIcon("/icons/16x16/stop.png")); + add(_stopButton); + + ButtonGroup bg = new ButtonGroup(); + bg.add(_pauseButton); + bg.add(_playButton); + bg.add(_stopButton); + } } ShowLogDialog(Root root, FileIteratorFactory factory, - int maxLines, int maxSize, int initialLines, int maxReadSize, int period) + int maxLines, int maxSize, int initialLines, int maxReadSize, int period) { - super(root.getCoordinator().getMainFrame(), factory.getTitle() + " - IceGrid Admin", false); - - _maxLines = maxLines; - _maxSize = maxSize; - _initialLines = initialLines; - _maxReadSize = maxReadSize; - _period = period; - _factory = factory; - _root = root; - - setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - addWindowListener(new java.awt.event.WindowAdapter() - { - public void windowClosing(java.awt.event.WindowEvent e) - { - close(true); - } - }); - - _pause = new AbstractAction("Pause") - { - public void actionPerformed(ActionEvent e) - { - pause(); - } - }; - - _play = new AbstractAction("Play") - { - public void actionPerformed(ActionEvent e) - { - play(); - } - }; - - _stop = new AbstractAction("Stop") - { - public void actionPerformed(ActionEvent e) - { - stopReading(); - } - }; - - setJMenuBar(new MenuBar()); - getContentPane().add(new ToolBar(), - BorderLayout.PAGE_START); - - JScrollPane scrollPane = new JScrollPane(_textArea, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - getContentPane().add(scrollPane); - - pack(); - setResizable(true); - - setLocationRelativeTo(root.getCoordinator().getMainFrame()); - play(); + super(root.getCoordinator().getMainFrame(), factory.getTitle() + " - IceGrid Admin", false); + + _maxLines = maxLines; + _maxSize = maxSize; + _initialLines = initialLines; + _maxReadSize = maxReadSize; + _period = period; + _factory = factory; + _root = root; + + setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + addWindowListener(new java.awt.event.WindowAdapter() + { + public void windowClosing(java.awt.event.WindowEvent e) + { + close(true); + } + }); + + _pause = new AbstractAction("Pause") + { + public void actionPerformed(ActionEvent e) + { + pause(); + } + }; + + _play = new AbstractAction("Play") + { + public void actionPerformed(ActionEvent e) + { + play(); + } + }; + + _stop = new AbstractAction("Stop") + { + public void actionPerformed(ActionEvent e) + { + stopReading(); + } + }; + + setJMenuBar(new MenuBar()); + getContentPane().add(new ToolBar(), + BorderLayout.PAGE_START); + + JScrollPane scrollPane = new JScrollPane(_textArea, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + getContentPane().add(scrollPane); + + pack(); + setResizable(true); + + setLocationRelativeTo(root.getCoordinator().getMainFrame()); + play(); } void pause() { - _thread.pause(); - _pauseItem.setSelected(true); - _pauseButton.setSelected(true); + _thread.pause(); + _pauseItem.setSelected(true); + _pauseButton.setSelected(true); } void stopReading() { - if(_thread != null) - { - _thread.terminate(); - - try - { - _thread.join(); - } - catch(InterruptedException e) - { - } - - _thread = null; - _stopItem.setSelected(true); - _stopButton.setSelected(true); - _pause.setEnabled(false); - } + if(_thread != null) + { + _thread.terminate(); + + try + { + _thread.join(); + } + catch(InterruptedException e) + { + } + + _thread = null; + _stopItem.setSelected(true); + _stopButton.setSelected(true); + _pause.setEnabled(false); + } } void play() { - if(_thread != null) - { - _thread.play(); - _playItem.setSelected(true); - _playButton.setSelected(true); - _pause.setEnabled(true); - } - else - { - _thread = new ReaderThread(); - _thread.start(); - } + if(_thread != null) + { + _thread.play(); + _playItem.setSelected(true); + _playButton.setSelected(true); + _pause.setEnabled(true); + } + else + { + _thread = new ReaderThread(); + _thread.start(); + } } int getMaxLines() { - return _maxLines; + return _maxLines; } int getMaxSize() { - return _maxSize; + return _maxSize; } int getInitialLines() { - return _initialLines; + return _initialLines; } int getMaxReadSize() { - return _maxReadSize; + return _maxReadSize; } int getPeriod() { - return _period; + return _period; } void setPrefs(int maxLines, int maxSize, int initialLines, int maxReadSize, int period) { - if(maxLines < 50) - { - maxLines = 50; - } - _maxLines = maxLines; - - if(maxSize < 1000) - { - maxSize = 1000; - } - _maxSize = maxSize; - - _initialLines = initialLines; - - if(maxReadSize < 100) - { - maxReadSize = 100; - } - else if(maxReadSize + 512 > _root.getMessageSizeMax()) - { - maxReadSize = _root.getMessageSizeMax() - 512; - } - _maxReadSize = maxReadSize; - - if(period < 200) - { - period = 200; - } - else if(period > 5000) - { - period = 5000; - } - _period = period; - - if(_thread != null) - { - _thread.setPrefs(); - } - - _root.setLogPrefs(_maxLines, _maxSize, _initialLines, _maxReadSize, _period); + if(maxLines < 50) + { + maxLines = 50; + } + _maxLines = maxLines; + + if(maxSize < 1000) + { + maxSize = 1000; + } + _maxSize = maxSize; + + _initialLines = initialLines; + + if(maxReadSize < 100) + { + maxReadSize = 100; + } + else if(maxReadSize + 512 > _root.getMessageSizeMax()) + { + maxReadSize = _root.getMessageSizeMax() - 512; + } + _maxReadSize = maxReadSize; + + if(period < 200) + { + period = 200; + } + else if(period > 5000) + { + period = 5000; + } + _period = period; + + if(_thread != null) + { + _thread.setPrefs(); + } + + _root.setLogPrefs(_maxLines, _maxSize, _initialLines, _maxReadSize, _period); } void close(boolean notifyRoot) { - stopReading(); + stopReading(); - if(notifyRoot) - { - _root.removeShowLogDialog(_factory.getTitle()); - } - dispose(); + if(notifyRoot) + { + _root.removeShowLogDialog(_factory.getTitle()); + } + dispose(); } private final Root _root; diff --git a/java/src/IceGridGUI/LiveDeployment/ShowLogPrefsDialog.java b/java/src/IceGridGUI/LiveDeployment/ShowLogPrefsDialog.java index 25277c1baf6..11154d46c90 100644 --- a/java/src/IceGridGUI/LiveDeployment/ShowLogPrefsDialog.java +++ b/java/src/IceGridGUI/LiveDeployment/ShowLogPrefsDialog.java @@ -32,131 +32,131 @@ class ShowLogPrefsDialog extends JDialog { ShowLogPrefsDialog(final ShowLogDialog sld) { - super(sld, "Preferences - IceGrid Admin", true); - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - - final JTextField maxLinesField = new JTextField(10); - maxLinesField.setText(Integer.toString(sld.getMaxLines())); - maxLinesField.setToolTipText("Maximum number of lines in this dialog's buffer"); - - final JTextField maxSizeField = new JTextField(10); - maxSizeField.setText(Integer.toString(sld.getMaxSize())); - maxSizeField.setToolTipText("Maximum number of characters in this dialog's buffer"); + super(sld, "Preferences - IceGrid Admin", true); + setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + + final JTextField maxLinesField = new JTextField(10); + maxLinesField.setText(Integer.toString(sld.getMaxLines())); + maxLinesField.setToolTipText("Maximum number of lines in this dialog's buffer"); + + final JTextField maxSizeField = new JTextField(10); + maxSizeField.setText(Integer.toString(sld.getMaxSize())); + maxSizeField.setToolTipText("Maximum number of characters in this dialog's buffer"); - final JTextField initialLinesField = new JTextField(10); - initialLinesField.setText(Integer.toString(sld.getInitialLines())); - initialLinesField.setToolTipText("Start by retrieving <num> lines from the server; -1 means retrieve all"); + final JTextField initialLinesField = new JTextField(10); + initialLinesField.setText(Integer.toString(sld.getInitialLines())); + initialLinesField.setToolTipText("Start by retrieving <num> lines from the server; -1 means retrieve all"); - final JTextField maxReadSizeField = new JTextField(10); - maxReadSizeField.setText(Integer.toString(sld.getMaxReadSize())); - maxReadSizeField.setToolTipText("Maximum number of bytes read by each request"); + final JTextField maxReadSizeField = new JTextField(10); + maxReadSizeField.setText(Integer.toString(sld.getMaxReadSize())); + maxReadSizeField.setToolTipText("Maximum number of bytes read by each request"); - final JTextField periodField = new JTextField(10); - periodField.setText(Float.toString((float)sld.getPeriod() / 1000)); - periodField.setToolTipText("After reaching EOF, check every <num> seconds for new output"); + final JTextField periodField = new JTextField(10); + periodField.setText(Float.toString((float)sld.getPeriod() / 1000)); + periodField.setToolTipText("After reaching EOF, check every <num> seconds for new output"); - JButton okButton = new JButton("OK"); - ActionListener okListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - try - { - int maxLines = parseInt(maxLinesField, "Max lines in buffer"); - int maxSize = parseInt(maxSizeField, "Max characters in buffer"); - int initialLines = parseInt(initialLinesField, "Initial tail (lines)"); - int maxReadSize = parseInt(maxReadSizeField, "Max bytes read per request"); - int period = (int)(parseFloat(periodField, "Poll period (seconds)") * 1000); - - sld.setPrefs(maxLines, maxSize, initialLines, maxReadSize, period); - dispose(); - } - catch(NumberFormatException ex) - { - return; - } - } - }; - okButton.addActionListener(okListener); - getRootPane().setDefaultButton(okButton); - - JButton cancelButton = new JButton("Cancel"); - ActionListener cancelListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - dispose(); - } - }; - cancelButton.addActionListener(cancelListener); - - - FormLayout layout = new FormLayout("left:pref, 3dlu, fill:pref:grow", ""); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - builder.append("Max lines in buffer", maxLinesField); - builder.nextLine(); - builder.append("Max characters in buffer", maxSizeField); - builder.nextLine(); - builder.append("Initial tail (lines)", initialLinesField); - builder.nextLine(); - builder.append("Max bytes read per request", maxReadSizeField); - builder.nextLine(); - builder.append("Poll period (seconds)", periodField); - builder.nextLine(); - - JComponent buttonBar = - ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); - buttonBar.setBorder(Borders.DIALOG_BORDER); - - java.awt.Container contentPane = getContentPane(); - contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); - contentPane.add(builder.getPanel()); - contentPane.add(buttonBar); - - pack(); - setResizable(false); - setLocationRelativeTo(sld); - setVisible(true); + JButton okButton = new JButton("OK"); + ActionListener okListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + try + { + int maxLines = parseInt(maxLinesField, "Max lines in buffer"); + int maxSize = parseInt(maxSizeField, "Max characters in buffer"); + int initialLines = parseInt(initialLinesField, "Initial tail (lines)"); + int maxReadSize = parseInt(maxReadSizeField, "Max bytes read per request"); + int period = (int)(parseFloat(periodField, "Poll period (seconds)") * 1000); + + sld.setPrefs(maxLines, maxSize, initialLines, maxReadSize, period); + dispose(); + } + catch(NumberFormatException ex) + { + return; + } + } + }; + okButton.addActionListener(okListener); + getRootPane().setDefaultButton(okButton); + + JButton cancelButton = new JButton("Cancel"); + ActionListener cancelListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + dispose(); + } + }; + cancelButton.addActionListener(cancelListener); + + + FormLayout layout = new FormLayout("left:pref, 3dlu, fill:pref:grow", ""); + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + builder.append("Max lines in buffer", maxLinesField); + builder.nextLine(); + builder.append("Max characters in buffer", maxSizeField); + builder.nextLine(); + builder.append("Initial tail (lines)", initialLinesField); + builder.nextLine(); + builder.append("Max bytes read per request", maxReadSizeField); + builder.nextLine(); + builder.append("Poll period (seconds)", periodField); + builder.nextLine(); + + JComponent buttonBar = + ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); + buttonBar.setBorder(Borders.DIALOG_BORDER); + + java.awt.Container contentPane = getContentPane(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + contentPane.add(builder.getPanel()); + contentPane.add(buttonBar); + + pack(); + setResizable(false); + setLocationRelativeTo(sld); + setVisible(true); } private int parseInt(JTextField field, String label) throws NumberFormatException { - try - { - return Integer.parseInt(field.getText()); - } - catch(NumberFormatException e) - { - JOptionPane.showMessageDialog( - this, - label + " must be an integer", - "Invalid entry", - JOptionPane.ERROR_MESSAGE); - - throw e; - } + try + { + return Integer.parseInt(field.getText()); + } + catch(NumberFormatException e) + { + JOptionPane.showMessageDialog( + this, + label + " must be an integer", + "Invalid entry", + JOptionPane.ERROR_MESSAGE); + + throw e; + } } private float parseFloat(JTextField field, String label) throws NumberFormatException { - try - { - return Float.parseFloat(field.getText()); - } - catch(NumberFormatException e) - { - JOptionPane.showMessageDialog( - this, - label + " must be a decimal number", - "Invalid entry", - JOptionPane.ERROR_MESSAGE); - - throw e; - } + try + { + return Float.parseFloat(field.getText()); + } + catch(NumberFormatException e) + { + JOptionPane.showMessageDialog( + this, + label + " must be a decimal number", + "Invalid entry", + JOptionPane.ERROR_MESSAGE); + + throw e; + } } } diff --git a/java/src/IceGridGUI/LiveDeployment/Slave.java b/java/src/IceGridGUI/LiveDeployment/Slave.java index 83f6da5157f..63c450d5928 100644 --- a/java/src/IceGridGUI/LiveDeployment/Slave.java +++ b/java/src/IceGridGUI/LiveDeployment/Slave.java @@ -30,143 +30,143 @@ class Slave extends TreeNode public boolean[] getAvailableActions() { boolean[] actions = new boolean[ACTION_COUNT]; - actions[SHUTDOWN_REGISTRY] = true; - actions[RETRIEVE_STDOUT] = true; - actions[RETRIEVE_STDERR] = true; - return actions; + actions[SHUTDOWN_REGISTRY] = true; + actions[RETRIEVE_STDOUT] = true; + actions[RETRIEVE_STDERR] = true; + return actions; } public void shutdownRegistry() { - final String prefix = "Shutting down registry '" + _id + "'..."; - getCoordinator().getStatusBar().setText(prefix); - - AMI_Admin_shutdownRegistry cb = new AMI_Admin_shutdownRegistry() - { - // - // 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().shutdownRegistry_async(cb, _id); - } - catch(Ice.LocalException e) - { - failure(prefix, "Failed to shutdown " + _id, e.toString()); - } - finally - { - getCoordinator().getMainFrame().setCursor( - Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } + final String prefix = "Shutting down registry '" + _id + "'..."; + getCoordinator().getStatusBar().setText(prefix); + + AMI_Admin_shutdownRegistry cb = new AMI_Admin_shutdownRegistry() + { + // + // 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().shutdownRegistry_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 void retrieveOutput(final boolean stdout) { - getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() - { - public FileIteratorPrx open(int count) - throws FileNotAvailableException, RegistryNotExistException, RegistryUnreachableException - { - AdminSessionPrx session = getCoordinator().getSession(); - - if(stdout) - { - return session.openRegistryStdOut(_id, count); - } - else - { - return session.openRegistryStdErr(_id, count); - } - } - - public String getTitle() - { - return "Registry " + _title + " " + (stdout ? "stdout" : "stderr"); - } - - public String getDefaultFilename() - { - return _id + (stdout ? ".out" : ".err"); - } - }); + getRoot().openShowLogDialog(new ShowLogDialog.FileIteratorFactory() + { + public FileIteratorPrx open(int count) + throws FileNotAvailableException, RegistryNotExistException, RegistryUnreachableException + { + AdminSessionPrx session = getCoordinator().getSession(); + + if(stdout) + { + return session.openRegistryStdOut(_id, count); + } + else + { + return session.openRegistryStdErr(_id, count); + } + } + + public String getTitle() + { + return "Registry " + _title + " " + (stdout ? "stdout" : "stderr"); + } + + public String getDefaultFilename() + { + return _id + (stdout ? ".out" : ".err"); + } + }); } public JPopupMenu getPopupMenu() { - LiveActions la = getCoordinator().getLiveActionsForPopup(); + LiveActions la = getCoordinator().getLiveActionsForPopup(); if(_popup == null) - { - _popup = new JPopupMenu(); - _popup.add(la.get(RETRIEVE_STDOUT)); - _popup.add(la.get(RETRIEVE_STDERR)); - _popup.addSeparator(); - _popup.add(la.get(SHUTDOWN_REGISTRY)); - } - - la.setTarget(this); - return _popup; + { + _popup = new JPopupMenu(); + _popup.add(la.get(RETRIEVE_STDOUT)); + _popup.add(la.get(RETRIEVE_STDERR)); + _popup.addSeparator(); + _popup.add(la.get(SHUTDOWN_REGISTRY)); + } + + la.setTarget(this); + return _popup; } public Editor getEditor() { - if(_editor == null) - { - _editor = new SlaveEditor(); - } - _editor.show(_info); - return _editor; + if(_editor == null) + { + _editor = new SlaveEditor(); + } + _editor.show(_info); + return _editor; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { - if(_cellRenderer == null) - { - // - // TODO: separate icon for master - // - - _cellRenderer = new DefaultTreeCellRenderer(); - _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/registry.png")); - } - - return _cellRenderer.getTreeCellRendererComponent( - tree, value, sel, expanded, leaf, row, hasFocus); + if(_cellRenderer == null) + { + // + // TODO: separate icon for master + // + + _cellRenderer = new DefaultTreeCellRenderer(); + _cellRenderer.setLeafIcon(Utils.getIcon("/icons/16x16/registry.png")); + } + + return _cellRenderer.getTreeCellRendererComponent( + tree, value, sel, expanded, leaf, row, hasFocus); } Slave(TreeNode parent, RegistryInfo info, String instanceName) { - super(parent, info.name); - _info = info; + super(parent, info.name); + _info = info; _title = instanceName + " (" + info.name + ")"; } diff --git a/java/src/IceGridGUI/LiveDeployment/SlaveEditor.java b/java/src/IceGridGUI/LiveDeployment/SlaveEditor.java index 4ce8d7ee4f0..a6c2348330a 100644 --- a/java/src/IceGridGUI/LiveDeployment/SlaveEditor.java +++ b/java/src/IceGridGUI/LiveDeployment/SlaveEditor.java @@ -19,25 +19,25 @@ class SlaveEditor extends Editor { SlaveEditor() { - _hostname.setEditable(false); + _hostname.setEditable(false); } void show(RegistryInfo info) { - _hostname.setText(info.hostname); + _hostname.setText(info.hostname); } protected void appendProperties(DefaultFormBuilder builder) { - builder.append("Hostname" ); - builder.append(_hostname, 3); - builder.nextLine(); + builder.append("Hostname" ); + builder.append(_hostname, 3); + builder.nextLine(); } protected void buildPropertiesPanel() { - super.buildPropertiesPanel(); - _propertiesPanel.setName("Slave Registry Properties"); + super.buildPropertiesPanel(); + _propertiesPanel.setName("Slave Registry Properties"); } private JTextField _hostname = new JTextField(20); diff --git a/java/src/IceGridGUI/LiveDeployment/TableField.java b/java/src/IceGridGUI/LiveDeployment/TableField.java index 767b0fc3486..610872ed7cb 100755 --- a/java/src/IceGridGUI/LiveDeployment/TableField.java +++ b/java/src/IceGridGUI/LiveDeployment/TableField.java @@ -32,161 +32,161 @@ import javax.swing.table.DefaultTableModel; public class TableField extends JTable { public TableField(String headKey, String headValue) - { - _columnNames = new java.util.Vector(2); - _columnNames.add(headKey); - _columnNames.add(headValue); - init(); + { + _columnNames = new java.util.Vector(2); + _columnNames.add(headKey); + _columnNames.add(headValue); + init(); } public TableField(String headKey, String headValue1, String headValue2) - { - _columnNames = new java.util.Vector(3); - _columnNames.add(headKey); - _columnNames.add(headValue1); - _columnNames.add(headValue2); - init(); + { + _columnNames = new java.util.Vector(3); + _columnNames.add(headKey); + _columnNames.add(headValue1); + _columnNames.add(headValue2); + init(); } private void init() { - _model = new DefaultTableModel() - { - public boolean isCellEditable(int row, int column) - { - return false; - } - }; - setModel(_model); - - setCellSelectionEnabled(false); - setOpaque(false); - setPreferredScrollableViewportSize(getPreferredSize()); + _model = new DefaultTableModel() + { + public boolean isCellEditable(int row, int column) + { + return false; + } + }; + setModel(_model); + + setCellSelectionEnabled(false); + setOpaque(false); + setPreferredScrollableViewportSize(getPreferredSize()); } public void setProperties(java.util.List properties, Utils.Resolver resolver) { - java.util.SortedMap map = new java.util.TreeMap(); - java.util.Iterator p = properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - map.put(resolver.substitute(pd.name), resolver.substitute(pd.value)); - } - setSortedMap(map); + java.util.SortedMap map = new java.util.TreeMap(); + java.util.Iterator p = properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + map.put(resolver.substitute(pd.name), resolver.substitute(pd.value)); + } + setSortedMap(map); } public void setObjects(java.util.List objects, Utils.Resolver resolver) { - java.util.SortedMap map = new java.util.TreeMap(); - java.util.Iterator p = objects.iterator(); - while(p.hasNext()) - { - ObjectDescriptor od = (ObjectDescriptor)p.next(); - Ice.Identity id = new Ice.Identity( - resolver.substitute(od.id.name), - resolver.substitute(od.id.category)); - - map.put(Ice.Util.identityToString(id), resolver.substitute(od.type)); - } - setSortedMap(map); + java.util.SortedMap map = new java.util.TreeMap(); + java.util.Iterator p = objects.iterator(); + while(p.hasNext()) + { + ObjectDescriptor od = (ObjectDescriptor)p.next(); + Ice.Identity id = new Ice.Identity( + resolver.substitute(od.id.name), + resolver.substitute(od.id.category)); + + map.put(Ice.Util.identityToString(id), resolver.substitute(od.type)); + } + setSortedMap(map); } public void setObjects(java.util.SortedMap objects) { - java.util.SortedMap map = new java.util.TreeMap(); - java.util.Iterator p = objects.values().iterator(); - while(p.hasNext()) - { - ObjectInfo oi = (ObjectInfo)p.next(); - map.put(oi.proxy.toString(), oi.type); - } - setSortedMap(map); + java.util.SortedMap map = new java.util.TreeMap(); + java.util.Iterator p = objects.values().iterator(); + while(p.hasNext()) + { + ObjectInfo oi = (ObjectInfo)p.next(); + map.put(oi.proxy.toString(), oi.type); + } + setSortedMap(map); } public void setEnvs(java.util.List envs, Utils.Resolver resolver) { - java.util.SortedMap map = new java.util.TreeMap(); - - java.util.Iterator p = envs.iterator(); - while(p.hasNext()) - { - String env = resolver.substitute((String)p.next()); - - int equal = env.indexOf('='); - if(equal == -1 || equal == env.length() - 1) - { - map.put(env, ""); - } - else - { - map.put(env.substring(0, equal), - env.substring(equal + 1)); - } - } - setSortedMap(map); + java.util.SortedMap map = new java.util.TreeMap(); + + java.util.Iterator p = envs.iterator(); + while(p.hasNext()) + { + String env = resolver.substitute((String)p.next()); + + int equal = env.indexOf('='); + if(equal == -1 || equal == env.length() - 1) + { + map.put(env, ""); + } + else + { + map.put(env.substring(0, equal), + env.substring(equal + 1)); + } + } + setSortedMap(map); } public void setAdapters(java.util.SortedMap adapters) { - java.util.Vector vector = new java.util.Vector(adapters.size()); - java.util.Iterator p = adapters.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Vector row = new java.util.Vector(3); - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - row.add((String)entry.getKey()); - - AdapterInfo ai = (AdapterInfo)entry.getValue(); - - if(ai.proxy == null) - { - row.add(""); - } - else - { - String str = ai.proxy.toString(); - int index = str.indexOf(':'); - if(index == -1 || index == str.length() - 1) - { - row.add(""); - } - else - { - row.add(str.substring(index + 1)); - } - } - - row.add(ai.replicaGroupId); - vector.add(row); - } - - _model.setDataVector(vector, _columnNames); - - DefaultTableCellRenderer cr = (DefaultTableCellRenderer) - getDefaultRenderer(String.class); - cr.setOpaque(false); + java.util.Vector vector = new java.util.Vector(adapters.size()); + java.util.Iterator p = adapters.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Vector row = new java.util.Vector(3); + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + row.add((String)entry.getKey()); + + AdapterInfo ai = (AdapterInfo)entry.getValue(); + + if(ai.proxy == null) + { + row.add(""); + } + else + { + String str = ai.proxy.toString(); + int index = str.indexOf(':'); + if(index == -1 || index == str.length() - 1) + { + row.add(""); + } + else + { + row.add(str.substring(index + 1)); + } + } + + row.add(ai.replicaGroupId); + vector.add(row); + } + + _model.setDataVector(vector, _columnNames); + + DefaultTableCellRenderer cr = (DefaultTableCellRenderer) + getDefaultRenderer(String.class); + cr.setOpaque(false); } public void setSortedMap(java.util.SortedMap map) { - java.util.Vector vector = new java.util.Vector(map.size()); - java.util.Iterator p = map.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Vector row = new java.util.Vector(2); - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - row.add((String)entry.getKey()); - row.add((String)entry.getValue()); - vector.add(row); - } - - _model.setDataVector(vector, _columnNames); - - DefaultTableCellRenderer cr = (DefaultTableCellRenderer) - getDefaultRenderer(String.class); - cr.setOpaque(false); + java.util.Vector vector = new java.util.Vector(map.size()); + java.util.Iterator p = map.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Vector row = new java.util.Vector(2); + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + row.add((String)entry.getKey()); + row.add((String)entry.getValue()); + vector.add(row); + } + + _model.setDataVector(vector, _columnNames); + + DefaultTableCellRenderer cr = (DefaultTableCellRenderer) + getDefaultRenderer(String.class); + cr.setOpaque(false); } private DefaultTableModel _model; diff --git a/java/src/IceGridGUI/LiveDeployment/TreeNode.java b/java/src/IceGridGUI/LiveDeployment/TreeNode.java index 9583c9232d3..b182730f70d 100755 --- a/java/src/IceGridGUI/LiveDeployment/TreeNode.java +++ b/java/src/IceGridGUI/LiveDeployment/TreeNode.java @@ -20,13 +20,13 @@ public abstract class TreeNode extends TreeNodeBase TreeNode(TreeNode parent, String id) { - super(parent, id); + super(parent, id); } Root getRoot() { - assert _parent != null; - return ((TreeNode)_parent).getRoot(); + assert _parent != null; + return ((TreeNode)_parent).getRoot(); } // @@ -62,57 +62,57 @@ public abstract class TreeNode extends TreeNodeBase public boolean[] getAvailableActions() { - return new boolean[ACTION_COUNT]; + return new boolean[ACTION_COUNT]; } public void start() { - assert false; + assert false; } public void stop() { - assert false; + assert false; } public void enable() { - assert false; + assert false; } public void disable() { - assert false; + assert false; } public void writeMessage() { - assert false; + assert false; } public void retrieveOutput(boolean stdout) { - assert false; + assert false; } public void retrieveLog() { - assert false; + assert false; } public void signal(String s) { - assert false; + assert false; } public void shutdownNode() { - assert false; + assert false; } public void shutdownRegistry() { - assert false; + assert false; } public void patchServer() { - assert false; + assert false; } public void addObject() { - assert false; + assert false; } // @@ -120,99 +120,99 @@ public abstract class TreeNode extends TreeNodeBase // protected void amiSuccess(final String prefix) { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - getCoordinator().getStatusBar().setText(prefix + "done."); - } - }); + 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; - - String message = ""; - for(int i = 0; i < pe.reasons.length; ++i) - { - if(message.length() == 0) - { - message += "\n"; - message += pe.reasons[i]; - } - } - amiFailure(prefix, title, message); - } - 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 if(e instanceof IceGrid.DeploymentException) - { - IceGrid.DeploymentException de = (IceGrid.DeploymentException)e; - amiFailure(prefix, title, "Deployment exception: " + de.reason); - } - else - { - amiFailure(prefix, title, e.toString()); - } + 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; + + String message = ""; + for(int i = 0; i < pe.reasons.length; ++i) + { + if(message.length() == 0) + { + message += "\n"; + message += pe.reasons[i]; + } + } + amiFailure(prefix, title, message); + } + 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 if(e instanceof IceGrid.DeploymentException) + { + IceGrid.DeploymentException de = (IceGrid.DeploymentException)e; + amiFailure(prefix, title, "Deployment exception: " + de.reason); + } + else + { + amiFailure(prefix, title, e.toString()); + } } protected void amiFailure(final String prefix, - final String title, final String message) + final String title, final String message) { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - failure(prefix, title, 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!"); + getCoordinator().getStatusBar().setText(prefix + "failed!"); - JOptionPane.showMessageDialog( - getCoordinator().getMainFrame(), - message, - title, - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog( + getCoordinator().getMainFrame(), + message, + title, + JOptionPane.ERROR_MESSAGE); } } diff --git a/java/src/IceGridGUI/LiveDeployment/WriteMessageDialog.java b/java/src/IceGridGUI/LiveDeployment/WriteMessageDialog.java index 104c5136945..7c6f1cba72c 100644 --- a/java/src/IceGridGUI/LiveDeployment/WriteMessageDialog.java +++ b/java/src/IceGridGUI/LiveDeployment/WriteMessageDialog.java @@ -45,151 +45,151 @@ class WriteMessageDialog extends JDialog { WriteMessageDialog(final Root root) { - super(root.getCoordinator().getMainFrame(), - "Write Message - IceGrid Admin", true); - setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); - - _mainFrame = root.getCoordinator().getMainFrame(); - - _stdOut = new JRadioButton("Write to stdout"); - _stdOut.setSelected(true); - JRadioButton stdErr = new JRadioButton("Write to stderr"); - ButtonGroup bg = new ButtonGroup(); - bg.add(_stdOut); - bg.add(stdErr); - - JButton okButton = new JButton("OK"); - ActionListener okListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - final Coordinator c = root.getCoordinator(); - final String target = _target; - final String prefix = "Writing message to server '" + target + "'..."; - - - AMI_Admin_writeMessage cb = new AMI_Admin_writeMessage() - { - public void ice_response() - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - c.getStatusBar().setText(prefix + "done."); - } - }); - } - - public void ice_exception(final Ice.UserException e) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure("IceGrid exception: " + e.toString()); - } - - }); - } - - public void ice_exception(final Ice.LocalException e) - { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - handleFailure("Communication exception: " + e.toString()); - } - }); - } - - private void handleFailure(String message) - { - c.getStatusBar().setText(prefix + "failed!"); - - JOptionPane.showMessageDialog( - _mainFrame, - message, - "Writing message to server '" + target + "' failed", - JOptionPane.ERROR_MESSAGE); - } - }; - - try - { - c.getStatusBar().setText(prefix); - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - - c.getAdmin().writeMessage_async( - cb, _target, _message.getText(), _stdOut.isSelected() ? 1 : 2); - } - catch(Ice.LocalException ex) - { - c.getStatusBar().setText(prefix + "failed."); - JOptionPane.showMessageDialog( - _mainFrame, - "Communication exception: " + ex.toString(), - "Writing message to server '" + target + "' failed", - JOptionPane.ERROR_MESSAGE); - - return; - } - finally - { - _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - setVisible(false); - } - }; - okButton.addActionListener(okListener); - getRootPane().setDefaultButton(okButton); - - JButton cancelButton = new JButton("Cancel"); - ActionListener cancelListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - setVisible(false); - } - }; - cancelButton.addActionListener(cancelListener); - - FormLayout layout = new FormLayout("left:pref, 3dlu, fill:pref:grow", ""); - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - _message.setLineWrap(true); - JScrollPane scrollPane = new JScrollPane(_message, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - builder.append(scrollPane, 3); - builder.nextLine(); - builder.append(_stdOut); - builder.append(stdErr); - builder.nextLine(); - JComponent buttonBar = - ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); - buttonBar.setBorder(Borders.DIALOG_BORDER); - - Container contentPane = getContentPane(); - contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); - contentPane.add(builder.getPanel()); - contentPane.add(buttonBar); - - pack(); - setResizable(false); + super(root.getCoordinator().getMainFrame(), + "Write Message - IceGrid Admin", true); + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); + + _mainFrame = root.getCoordinator().getMainFrame(); + + _stdOut = new JRadioButton("Write to stdout"); + _stdOut.setSelected(true); + JRadioButton stdErr = new JRadioButton("Write to stderr"); + ButtonGroup bg = new ButtonGroup(); + bg.add(_stdOut); + bg.add(stdErr); + + JButton okButton = new JButton("OK"); + ActionListener okListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + final Coordinator c = root.getCoordinator(); + final String target = _target; + final String prefix = "Writing message to server '" + target + "'..."; + + + AMI_Admin_writeMessage cb = new AMI_Admin_writeMessage() + { + public void ice_response() + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + c.getStatusBar().setText(prefix + "done."); + } + }); + } + + public void ice_exception(final Ice.UserException e) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure("IceGrid exception: " + e.toString()); + } + + }); + } + + public void ice_exception(final Ice.LocalException e) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + handleFailure("Communication exception: " + e.toString()); + } + }); + } + + private void handleFailure(String message) + { + c.getStatusBar().setText(prefix + "failed!"); + + JOptionPane.showMessageDialog( + _mainFrame, + message, + "Writing message to server '" + target + "' failed", + JOptionPane.ERROR_MESSAGE); + } + }; + + try + { + c.getStatusBar().setText(prefix); + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + c.getAdmin().writeMessage_async( + cb, _target, _message.getText(), _stdOut.isSelected() ? 1 : 2); + } + catch(Ice.LocalException ex) + { + c.getStatusBar().setText(prefix + "failed."); + JOptionPane.showMessageDialog( + _mainFrame, + "Communication exception: " + ex.toString(), + "Writing message to server '" + target + "' failed", + JOptionPane.ERROR_MESSAGE); + + return; + } + finally + { + _mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + setVisible(false); + } + }; + okButton.addActionListener(okListener); + getRootPane().setDefaultButton(okButton); + + JButton cancelButton = new JButton("Cancel"); + ActionListener cancelListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setVisible(false); + } + }; + cancelButton.addActionListener(cancelListener); + + FormLayout layout = new FormLayout("left:pref, 3dlu, fill:pref:grow", ""); + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + _message.setLineWrap(true); + JScrollPane scrollPane = new JScrollPane(_message, + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + builder.append(scrollPane, 3); + builder.nextLine(); + builder.append(_stdOut); + builder.append(stdErr); + builder.nextLine(); + JComponent buttonBar = + ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); + buttonBar.setBorder(Borders.DIALOG_BORDER); + + Container contentPane = getContentPane(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + contentPane.add(builder.getPanel()); + contentPane.add(buttonBar); + + pack(); + setResizable(false); } void showDialog(String serverId) { - _target = serverId; - _message.setText(""); - setLocationRelativeTo(_mainFrame); - setVisible(true); + _target = serverId; + _message.setText(""); + setLocationRelativeTo(_mainFrame); + setVisible(true); } private JRadioButton _stdOut; diff --git a/java/src/IceGridGUI/LiveDeploymentPane.java b/java/src/IceGridGUI/LiveDeploymentPane.java index f6a49390464..4cef88fd09b 100755 --- a/java/src/IceGridGUI/LiveDeploymentPane.java +++ b/java/src/IceGridGUI/LiveDeploymentPane.java @@ -40,296 +40,296 @@ public class LiveDeploymentPane extends JSplitPane implements Tab { public void updateUI() { - super.updateUI(); - setEmptyDividerBorder(); + 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); + 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 refresh() { - if(_currentNode != null) - { - _currentNode.getEditor(); - - if(_root.getCoordinator().getCurrentTab() == this) - { - // - // Refresh actions as well - // - _root.getCoordinator().showActions(_currentNode); - } - } + if(_currentNode != null) + { + _currentNode.getEditor(); + + if(_root.getCoordinator().getCurrentTab() == this) + { + // + // Refresh actions as well + // + _root.getCoordinator().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(); - } + 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 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(); - } + 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(); - } + 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; + assert false; } public void saveToRegistry() { - assert false; + assert false; } public void saveToFile() { - assert false; + assert false; } public void discardUpdates() { - assert false; + assert false; } public boolean close() { - return false; + 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); + 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(); + _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()); - } + 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()); - } - } - } + 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()); - } - } - } - } + 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; diff --git a/java/src/IceGridGUI/Logger.java b/java/src/IceGridGUI/Logger.java index 1f4be52fcef..1fb4b45efdb 100644 --- a/java/src/IceGridGUI/Logger.java +++ b/java/src/IceGridGUI/Logger.java @@ -18,65 +18,65 @@ public class Logger extends Ice.LocalObjectImpl implements Ice.Logger public Logger(JFrame mainFrame) { - _mainFrame = mainFrame; + _mainFrame = mainFrame; } public void print(String message) { - System.err.println(message); + System.err.println(message); } public void trace(String category, String message) { - StringBuffer s = new StringBuffer("[ "); - s.append(_date.format(new java.util.Date())); - s.append(' '); - s.append(_prefix); - s.append(category); - s.append(": "); - s.append(message); - s.append(" ]"); - int idx = 0; - while((idx = s.indexOf("\n", idx)) != -1) - { - s.insert(idx + 1, " "); - ++idx; - } - System.err.println(s.toString()); + StringBuffer s = new StringBuffer("[ "); + s.append(_date.format(new java.util.Date())); + s.append(' '); + s.append(_prefix); + s.append(category); + s.append(": "); + s.append(message); + s.append(" ]"); + int idx = 0; + while((idx = s.indexOf("\n", idx)) != -1) + { + s.insert(idx + 1, " "); + ++idx; + } + System.err.println(s.toString()); } public void warning(final String message) { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - JOptionPane.showMessageDialog( - _mainFrame, - message, - "Warning - IceGrid Admin Logger", - JOptionPane.WARNING_MESSAGE); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + JOptionPane.showMessageDialog( + _mainFrame, + message, + "Warning - IceGrid Admin Logger", + JOptionPane.WARNING_MESSAGE); + } + }); } public void error(final String message) { - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - JOptionPane.showMessageDialog( - _mainFrame, - message, - "Error - IceGrid Admin Logger", - JOptionPane.ERROR_MESSAGE); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + JOptionPane.showMessageDialog( + _mainFrame, + message, + "Error - IceGrid Admin Logger", + JOptionPane.ERROR_MESSAGE); + } + }); } private final String _prefix = "IceGrid Admin: "; diff --git a/java/src/IceGridGUI/Main.java b/java/src/IceGridGUI/Main.java index f4182cb4775..d54556e5bfc 100755 --- a/java/src/IceGridGUI/Main.java +++ b/java/src/IceGridGUI/Main.java @@ -26,64 +26,64 @@ public class Main extends JFrame public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - createAndShowGUI(args); - } - }); + { + 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()); - } + 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); - } - } - }); + setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + if(_coordinator != null) + { + _coordinator.exit(0); + } + } + }); - _coordinator = - new Coordinator(this, new Ice.StringSeqHolder(args), - Preferences.userNodeForPackage(getClass())); - - _coordinator.showMainFrame(); + _coordinator = + new Coordinator(this, new Ice.StringSeqHolder(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()); - } - - // + 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); } diff --git a/java/src/IceGridGUI/MainPane.java b/java/src/IceGridGUI/MainPane.java index 6fa4ea4603e..737a09f661b 100755 --- a/java/src/IceGridGUI/MainPane.java +++ b/java/src/IceGridGUI/MainPane.java @@ -19,134 +19,134 @@ public class MainPane extends JTabbedPane { public void addApplication(ApplicationPane application) { - IceGridGUI.Application.Root root = application.getRoot(); - super.addTab(computeTitle(root.getId()), - getIcon(root), 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)); + super.setTitleAt(index, computeTitle(title)); } public void resetTitle(IceGridGUI.Application.Root root) { - int i = findIndex(root); - if(i > 0) - { - setTitleAt(i, root.getId()); - } + int i = findIndex(root); + if(i > 0) + { + setTitleAt(i, root.getId()); + } } public void resetIcon(IceGridGUI.Application.Root root) { - int i = findIndex(root); - if(i > 0) - { - setIconAt(i, getIcon(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; + 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; + 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; - } - } + 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(); - } - }); - - _registryIcon = Utils.getIcon("/icons/16x16/registry_bound_application.png"); - _fileIcon = Utils.getIcon("/icons/16x16/file_bound_application.png"); - - addTab("Live Deployment", - Utils.getIcon("/icons/16x16/live_deployment.png"), - _coordinator.getLiveDeploymentPane()); + _coordinator = coordinator; + setBorder(new EmptyBorder(10, 10, 10, 10)); + + addChangeListener(new ChangeListener() + { + public void stateChanged(ChangeEvent evt) + { + Tab tab = (Tab)getSelectedComponent(); + tab.selected(); + } + }); + + _registryIcon = Utils.getIcon("/icons/16x16/registry_bound_application.png"); + _fileIcon = Utils.getIcon("/icons/16x16/file_bound_application.png"); + + addTab("Live Deployment", + Utils.getIcon("/icons/16x16/live_deployment.png"), + _coordinator.getLiveDeploymentPane()); } private String computeTitle(String name) { - String title = name; - int i = 0; - while(hasTitle(title)) - { - title = name + " (" + Integer.toString(++i) + ")"; - } - return title; + 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; + 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 _registryIcon; - } - else if(root.hasFile()) - { - return _fileIcon; - } - else - { - return null; - } + if(root.isLive()) + { + return _registryIcon; + } + else if(root.hasFile()) + { + return _fileIcon; + } + else + { + return null; + } } diff --git a/java/src/IceGridGUI/NodeObserverI.java b/java/src/IceGridGUI/NodeObserverI.java index e3eecaddba3..c798dad003d 100755 --- a/java/src/IceGridGUI/NodeObserverI.java +++ b/java/src/IceGridGUI/NodeObserverI.java @@ -15,112 +15,112 @@ class NodeObserverI extends _NodeObserverDisp { NodeObserverI(Coordinator coordinator) { - _coordinator = coordinator; - _trace = _coordinator.traceObservers(); + _coordinator = coordinator; + _trace = _coordinator.traceObservers(); } public void nodeInit(final NodeDynamicInfo[] nodes, Ice.Current current) { - if(_trace) - { - if(nodes.length == 0) - { - _coordinator.traceObserver("nodeInit (no node)"); - } - else - { - String names = ""; - for(int i = 0; i < nodes.length; ++i) - { - names += " " + nodes[i].info.name; - } - _coordinator.traceObserver("nodeInit for node" - + (nodes.length == 1 ? "" : "s") - + names); - } - } + if(_trace) + { + if(nodes.length == 0) + { + _coordinator.traceObserver("nodeInit (no node)"); + } + else + { + String names = ""; + for(int i = 0; i < nodes.length; ++i) + { + names += " " + nodes[i].info.name; + } + _coordinator.traceObserver("nodeInit for node" + + (nodes.length == 1 ? "" : "s") + + names); + } + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - for(int i = 0; i < nodes.length; ++i) - { - _coordinator.nodeUp(nodes[i]); - } - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + for(int i = 0; i < nodes.length; ++i) + { + _coordinator.nodeUp(nodes[i]); + } + } + }); } public void nodeUp(final NodeDynamicInfo nodeInfo, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("nodeUp for node " + nodeInfo.info.name); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.nodeUp(nodeInfo); - } - }); + if(_trace) + { + _coordinator.traceObserver("nodeUp for node " + nodeInfo.info.name); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.nodeUp(nodeInfo); + } + }); } public void nodeDown(final String nodeName, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("nodeUp for node " + nodeName); - } + if(_trace) + { + _coordinator.traceObserver("nodeUp for node " + nodeName); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.nodeDown(nodeName); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.nodeDown(nodeName); + } + }); } public void updateServer(final String node, final ServerDynamicInfo updatedInfo, - Ice.Current current) - { - if(_trace) - { - _coordinator.traceObserver("updateServer for server " + updatedInfo.id - + " on node " + node + "; new state is " - + updatedInfo.state.toString()); - } + Ice.Current current) + { + if(_trace) + { + _coordinator.traceObserver("updateServer for server " + updatedInfo.id + + " on node " + node + "; new state is " + + updatedInfo.state.toString()); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.updateServer(node, updatedInfo); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.updateServer(node, updatedInfo); + } + }); } public void updateAdapter(final String node, final AdapterDynamicInfo updatedInfo, - Ice.Current current) + Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("updateAdapter for adapter " + updatedInfo.id - + " on node " + node + "; new proxy is " - + (updatedInfo.proxy == null ? "null" - : updatedInfo.proxy.toString())); - } - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.updateAdapter(node, updatedInfo); - } - }); + if(_trace) + { + _coordinator.traceObserver("updateAdapter for adapter " + updatedInfo.id + + " on node " + node + "; new proxy is " + + (updatedInfo.proxy == null ? "null" + : updatedInfo.proxy.toString())); + } + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.updateAdapter(node, updatedInfo); + } + }); } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/ObjectObserverI.java b/java/src/IceGridGUI/ObjectObserverI.java index e08001f1083..63e6dd10c7e 100644 --- a/java/src/IceGridGUI/ObjectObserverI.java +++ b/java/src/IceGridGUI/ObjectObserverI.java @@ -16,85 +16,85 @@ class ObjectObserverI extends _ObjectObserverDisp ObjectObserverI(Coordinator coordinator) { - _coordinator = coordinator; - _trace = coordinator.traceObservers(); + _coordinator = coordinator; + _trace = coordinator.traceObservers(); } public synchronized void objectInit(final ObjectInfo[] objects, Ice.Current current) { - if(_trace) - { - if(objects.length == 0) - { - _coordinator.traceObserver("objectInit (no object)"); - } - else - { - String names = ""; - for(int i = 0; i < objects.length; ++i) - { - names += " " + objects[i].proxy.toString(); - } - - _coordinator.traceObserver("objectInit for objects" + names); - } - } + if(_trace) + { + if(objects.length == 0) + { + _coordinator.traceObserver("objectInit (no object)"); + } + else + { + String names = ""; + for(int i = 0; i < objects.length; ++i) + { + names += " " + objects[i].proxy.toString(); + } + + _coordinator.traceObserver("objectInit for objects" + names); + } + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.objectInit(objects); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.objectInit(objects); + } + }); } public void objectAdded(final ObjectInfo info, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("objectAdded for object " + info.proxy.toString()); - } + if(_trace) + { + _coordinator.traceObserver("objectAdded for object " + info.proxy.toString()); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.objectAdded(info); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.objectAdded(info); + } + }); } public void objectUpdated(final ObjectInfo info, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("objectUpdated for object " + info.proxy.toString()); - } + if(_trace) + { + _coordinator.traceObserver("objectUpdated for object " + info.proxy.toString()); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.objectUpdated(info); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.objectUpdated(info); + } + }); } public void objectRemoved(final Ice.Identity id, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("objectRemoved for object " + Ice.Util.identityToString(id)); - } + if(_trace) + { + _coordinator.traceObserver("objectRemoved for object " + Ice.Util.identityToString(id)); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.objectRemoved(id); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.objectRemoved(id); + } + }); } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/RegistryObserverI.java b/java/src/IceGridGUI/RegistryObserverI.java index d6f6f404dac..f2093ca225c 100755 --- a/java/src/IceGridGUI/RegistryObserverI.java +++ b/java/src/IceGridGUI/RegistryObserverI.java @@ -16,73 +16,73 @@ class RegistryObserverI extends _RegistryObserverDisp RegistryObserverI(Coordinator coordinator) { - _coordinator = coordinator; - _trace = _coordinator.traceObservers(); + _coordinator = coordinator; + _trace = _coordinator.traceObservers(); } public void registryInit(final RegistryInfo[] registryInfos, Ice.Current current) { - if(_trace) - { - if(registryInfos.length == 0) - { - _coordinator.traceObserver("registryInit (no registry)"); - } - else - { - String names = ""; - for(int i = 0; i < registryInfos.length; ++i) - { - names += " " + registryInfos[i].name; - } - _coordinator.traceObserver("registryInit for registr" + - (registryInfos.length == 1 ? "y" : "ies") - + names); - } - } + if(_trace) + { + if(registryInfos.length == 0) + { + _coordinator.traceObserver("registryInit (no registry)"); + } + else + { + String names = ""; + for(int i = 0; i < registryInfos.length; ++i) + { + names += " " + registryInfos[i].name; + } + _coordinator.traceObserver("registryInit for registr" + + (registryInfos.length == 1 ? "y" : "ies") + + names); + } + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - for(int i = 0; i < registryInfos.length; ++i) - { - _coordinator.registryUp(registryInfos[i]); - } - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + for(int i = 0; i < registryInfos.length; ++i) + { + _coordinator.registryUp(registryInfos[i]); + } + } + }); } public void registryUp(final RegistryInfo registryInfo, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("registryUp for registry " + registryInfo.name); - } + if(_trace) + { + _coordinator.traceObserver("registryUp for registry " + registryInfo.name); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.registryUp(registryInfo); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.registryUp(registryInfo); + } + }); } public void registryDown(final String registryName, Ice.Current current) { - if(_trace) - { - _coordinator.traceObserver("registryDown for registry " + registryName); - } + if(_trace) + { + _coordinator.traceObserver("registryDown for registry " + registryName); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - _coordinator.registryDown(registryName); - } - }); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + _coordinator.registryDown(registryName); + } + }); } private final Coordinator _coordinator; diff --git a/java/src/IceGridGUI/SessionKeeper.java b/java/src/IceGridGUI/SessionKeeper.java index ae7c5cd7119..77dd373f426 100755 --- a/java/src/IceGridGUI/SessionKeeper.java +++ b/java/src/IceGridGUI/SessionKeeper.java @@ -49,1036 +49,1036 @@ class SessionKeeper // private class Session { - Session(AdminSessionPrx session, long keepAliveperiod, Component parent) - { - _session = session; - - try - { - _admin = session.getAdmin(); - } - catch(Ice.LocalException e) - { - logout(true); - JOptionPane.showMessageDialog( - parent, - "Could not retrieve Admin proxy: " + e.toString(), - "Login failed", - JOptionPane.ERROR_MESSAGE); - throw e; - } - - _thread = new Pinger(_session, keepAliveperiod); - _thread.start(); - - try - { - registerObservers(); - } - catch(Ice.LocalException e) - { - logout(true); - JOptionPane.showMessageDialog(parent, - "Could not register observers: " - + e.toString(), - "Login failed", - JOptionPane.ERROR_MESSAGE); - throw e; - } - } - - void logout(boolean destroySession) - { - close(destroySession); - _coordinator.sessionLost(); - _connectedToMaster = false; - _replicaName = ""; - } - - AdminSessionPrx getSession() - { - return _session; - } - - AdminPrx getAdmin() - { - return _admin; - } - - AdminPrx getRoutedAdmin() - { - assert _admin != null; - - if(_routedAdmin == null) - { - // - // Create a local Admin object used to route some operations to the real - // Admin. - // Routing admin calls is even necessary when we don't through Glacier2 - // since the Admin object provided by the registry is a well-known object - // (indirect, locator-dependent). - // - Ice.ObjectAdapter adminRouterAdapter = _coordinator.getCommunicator(). - createObjectAdapterWithEndpoints("IceGrid.AdminRouter", "tcp -h localhost"); - - _routedAdmin = AdminPrxHelper.uncheckedCast( - adminRouterAdapter.addWithUUID(new AdminRouter(_admin))); - - adminRouterAdapter.activate(); - } - return _routedAdmin; - } - - void close(boolean destroySession) - { - if(_thread != null) - { - _thread.done(); - - for(;;) - { - try - { - _thread.join(); - break; - } - catch(InterruptedException e) - { - } - } - } - - if(_adapter != null) - { - try - { - _adapter.remove(_applicationObserverIdentity); - } - catch(Ice.NotRegisteredException e) - { - } - - try - { - _adapter.remove(_adapterObserverIdentity); - } - catch(Ice.NotRegisteredException e) - { - } - - try - { - _adapter.remove(_objectObserverIdentity); - } - catch(Ice.NotRegisteredException e) - { - } - - try - { - _adapter.remove(_registryObserverIdentity); - } - catch(Ice.NotRegisteredException e) - { - } - - try - { - _adapter.remove(_nodeObserverIdentity); - } - catch(Ice.NotRegisteredException e) - { - } - } - - if(destroySession) - { - _coordinator.destroySession(_session); - } - _coordinator.getStatusBar().setConnected(false); - } - - private void registerObservers() - { - // - // Create the object adapter for the observers - // - String category; - - Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast( - _coordinator.getCommunicator().getDefaultRouter()); - if(router == null) - { - category = "observer"; - - _adapter = - _coordinator.getCommunicator().createObjectAdapter(""); - _adapter.activate(); - _session.ice_getConnection().setAdapter(_adapter); - } - else - { - category = router.getCategoryForClient(); - - _adapter = - _coordinator.getCommunicator().createObjectAdapterWithRouter("RoutedAdapter", router); - _adapter.activate(); - } - - // - // Create servants and proxies - // - _applicationObserverIdentity.name = "application-" + Ice.Util.generateUUID(); - _applicationObserverIdentity.category = category; - _adapterObserverIdentity.name = "adapter-" + Ice.Util.generateUUID(); - _adapterObserverIdentity.category = category; - _objectObserverIdentity.name = "object-" + Ice.Util.generateUUID(); - _objectObserverIdentity.category = category; - _registryObserverIdentity.name = "registry-" + Ice.Util.generateUUID(); - _registryObserverIdentity.category = category; - _nodeObserverIdentity.name = "node-" + Ice.Util.generateUUID(); - _nodeObserverIdentity.category = category; - - ApplicationObserverI applicationObserverServant = new ApplicationObserverI( - _admin.ice_getIdentity().category, _coordinator); - - ApplicationObserverPrx applicationObserver = - ApplicationObserverPrxHelper.uncheckedCast( - _adapter.add( - applicationObserverServant, _applicationObserverIdentity)); - - AdapterObserverPrx adapterObserver = - AdapterObserverPrxHelper.uncheckedCast( - _adapter.add( - new AdapterObserverI(_coordinator), _adapterObserverIdentity)); - - ObjectObserverPrx objectObserver = - ObjectObserverPrxHelper.uncheckedCast( - _adapter.add( - new ObjectObserverI(_coordinator), _objectObserverIdentity)); - - RegistryObserverPrx registryObserver = - RegistryObserverPrxHelper.uncheckedCast( - _adapter.add( - new RegistryObserverI(_coordinator), _registryObserverIdentity)); - - NodeObserverPrx nodeObserver = - NodeObserverPrxHelper.uncheckedCast( - _adapter.add( - new NodeObserverI(_coordinator), _nodeObserverIdentity)); - - try - { - if(router != null) - { - _session.setObservers(registryObserver, - nodeObserver, - applicationObserver, - adapterObserver, - objectObserver); - } - else - { - _session.setObserversByIdentity( - _registryObserverIdentity, - _nodeObserverIdentity, - _applicationObserverIdentity, - _adapterObserverIdentity, - _objectObserverIdentity); - } - } - catch(ObserverAlreadyRegisteredException ex) - { - assert false; // We use UUIDs for the observer identities. - } - - applicationObserverServant.waitForInit(); - } - - - private final AdminSessionPrx _session; - private Pinger _thread; - - private Ice.ObjectAdapter _adapter; - private AdminPrx _admin; - private AdminPrx _routedAdmin; - private Ice.Identity _applicationObserverIdentity = new Ice.Identity(); - private Ice.Identity _adapterObserverIdentity = new Ice.Identity(); - private Ice.Identity _objectObserverIdentity = new Ice.Identity(); - private Ice.Identity _registryObserverIdentity = new Ice.Identity(); - private Ice.Identity _nodeObserverIdentity = new Ice.Identity(); + Session(AdminSessionPrx session, long keepAliveperiod, Component parent) + { + _session = session; + + try + { + _admin = session.getAdmin(); + } + catch(Ice.LocalException e) + { + logout(true); + JOptionPane.showMessageDialog( + parent, + "Could not retrieve Admin proxy: " + e.toString(), + "Login failed", + JOptionPane.ERROR_MESSAGE); + throw e; + } + + _thread = new Pinger(_session, keepAliveperiod); + _thread.start(); + + try + { + registerObservers(); + } + catch(Ice.LocalException e) + { + logout(true); + JOptionPane.showMessageDialog(parent, + "Could not register observers: " + + e.toString(), + "Login failed", + JOptionPane.ERROR_MESSAGE); + throw e; + } + } + + void logout(boolean destroySession) + { + close(destroySession); + _coordinator.sessionLost(); + _connectedToMaster = false; + _replicaName = ""; + } + + AdminSessionPrx getSession() + { + return _session; + } + + AdminPrx getAdmin() + { + return _admin; + } + + AdminPrx getRoutedAdmin() + { + assert _admin != null; + + if(_routedAdmin == null) + { + // + // Create a local Admin object used to route some operations to the real + // Admin. + // Routing admin calls is even necessary when we don't through Glacier2 + // since the Admin object provided by the registry is a well-known object + // (indirect, locator-dependent). + // + Ice.ObjectAdapter adminRouterAdapter = _coordinator.getCommunicator(). + createObjectAdapterWithEndpoints("IceGrid.AdminRouter", "tcp -h localhost"); + + _routedAdmin = AdminPrxHelper.uncheckedCast( + adminRouterAdapter.addWithUUID(new AdminRouter(_admin))); + + adminRouterAdapter.activate(); + } + return _routedAdmin; + } + + void close(boolean destroySession) + { + if(_thread != null) + { + _thread.done(); + + for(;;) + { + try + { + _thread.join(); + break; + } + catch(InterruptedException e) + { + } + } + } + + if(_adapter != null) + { + try + { + _adapter.remove(_applicationObserverIdentity); + } + catch(Ice.NotRegisteredException e) + { + } + + try + { + _adapter.remove(_adapterObserverIdentity); + } + catch(Ice.NotRegisteredException e) + { + } + + try + { + _adapter.remove(_objectObserverIdentity); + } + catch(Ice.NotRegisteredException e) + { + } + + try + { + _adapter.remove(_registryObserverIdentity); + } + catch(Ice.NotRegisteredException e) + { + } + + try + { + _adapter.remove(_nodeObserverIdentity); + } + catch(Ice.NotRegisteredException e) + { + } + } + + if(destroySession) + { + _coordinator.destroySession(_session); + } + _coordinator.getStatusBar().setConnected(false); + } + + private void registerObservers() + { + // + // Create the object adapter for the observers + // + String category; + + Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.uncheckedCast( + _coordinator.getCommunicator().getDefaultRouter()); + if(router == null) + { + category = "observer"; + + _adapter = + _coordinator.getCommunicator().createObjectAdapter(""); + _adapter.activate(); + _session.ice_getConnection().setAdapter(_adapter); + } + else + { + category = router.getCategoryForClient(); + + _adapter = + _coordinator.getCommunicator().createObjectAdapterWithRouter("RoutedAdapter", router); + _adapter.activate(); + } + + // + // Create servants and proxies + // + _applicationObserverIdentity.name = "application-" + Ice.Util.generateUUID(); + _applicationObserverIdentity.category = category; + _adapterObserverIdentity.name = "adapter-" + Ice.Util.generateUUID(); + _adapterObserverIdentity.category = category; + _objectObserverIdentity.name = "object-" + Ice.Util.generateUUID(); + _objectObserverIdentity.category = category; + _registryObserverIdentity.name = "registry-" + Ice.Util.generateUUID(); + _registryObserverIdentity.category = category; + _nodeObserverIdentity.name = "node-" + Ice.Util.generateUUID(); + _nodeObserverIdentity.category = category; + + ApplicationObserverI applicationObserverServant = new ApplicationObserverI( + _admin.ice_getIdentity().category, _coordinator); + + ApplicationObserverPrx applicationObserver = + ApplicationObserverPrxHelper.uncheckedCast( + _adapter.add( + applicationObserverServant, _applicationObserverIdentity)); + + AdapterObserverPrx adapterObserver = + AdapterObserverPrxHelper.uncheckedCast( + _adapter.add( + new AdapterObserverI(_coordinator), _adapterObserverIdentity)); + + ObjectObserverPrx objectObserver = + ObjectObserverPrxHelper.uncheckedCast( + _adapter.add( + new ObjectObserverI(_coordinator), _objectObserverIdentity)); + + RegistryObserverPrx registryObserver = + RegistryObserverPrxHelper.uncheckedCast( + _adapter.add( + new RegistryObserverI(_coordinator), _registryObserverIdentity)); + + NodeObserverPrx nodeObserver = + NodeObserverPrxHelper.uncheckedCast( + _adapter.add( + new NodeObserverI(_coordinator), _nodeObserverIdentity)); + + try + { + if(router != null) + { + _session.setObservers(registryObserver, + nodeObserver, + applicationObserver, + adapterObserver, + objectObserver); + } + else + { + _session.setObserversByIdentity( + _registryObserverIdentity, + _nodeObserverIdentity, + _applicationObserverIdentity, + _adapterObserverIdentity, + _objectObserverIdentity); + } + } + catch(ObserverAlreadyRegisteredException ex) + { + assert false; // We use UUIDs for the observer identities. + } + + applicationObserverServant.waitForInit(); + } + + + private final AdminSessionPrx _session; + private Pinger _thread; + + private Ice.ObjectAdapter _adapter; + private AdminPrx _admin; + private AdminPrx _routedAdmin; + private Ice.Identity _applicationObserverIdentity = new Ice.Identity(); + private Ice.Identity _adapterObserverIdentity = new Ice.Identity(); + private Ice.Identity _objectObserverIdentity = new Ice.Identity(); + private Ice.Identity _registryObserverIdentity = new Ice.Identity(); + private Ice.Identity _nodeObserverIdentity = new Ice.Identity(); } static public class LoginInfo { - LoginInfo(Preferences connectionPrefs, Coordinator coordinator) - { - _connectionPrefs = connectionPrefs; - - String prop = System.getProperty("java.net.ssl.keyStorePassword"); - if(prop != null) - { - keystorePassword = prop.toCharArray(); - } - prop = System.getProperty("java.net.ssl.trustStorePassword"); - if(prop != null) - { - truststorePassword = prop.toCharArray(); - } - - Ice.Properties properties = coordinator.getProperties(); - - // - // Registry properties - // - Ice.ObjectPrx defaultLocatorProxy = null; - try - { - defaultLocatorProxy = coordinator.getCommunicator().propertyToProxy("Ice.Default.Locator"); - } - catch(Ice.LocalException e) - { - // Ignored, keep null defaultLocatorProxy - } - if(defaultLocatorProxy != null) - { - // - // Set new defaults - // - registryInstanceName = defaultLocatorProxy.ice_getIdentity().category; - registryEndpoints = ""; - Ice.Endpoint[] endpoints = defaultLocatorProxy.ice_getEndpoints(); - for(int i = 0; i < endpoints.length; ++i) - { - if(i > 0) - { - registryEndpoints += ":"; - } - registryEndpoints += endpoints[i].toString(); - } - } - else - { - registryInstanceName = - _connectionPrefs.get("registry.instanceName", registryInstanceName); - registryEndpoints = - _connectionPrefs.get("registry.endpoints", registryEndpoints); - } - connectToMaster = _connectionPrefs.getBoolean("registry.connectToMaster", connectToMaster); - - - // - // Glacier2 properties - // - Ice.ObjectPrx defaultRouterProxy = null; - try - { - defaultRouterProxy = coordinator.getCommunicator().propertyToProxy("Ice.Default.Router"); - } - catch(Ice.LocalException e) - { - // Ignored, keep null defaultRouterProxy - } - if(defaultRouterProxy != null) - { - // - // Set new defaults - // - routerInstanceName = defaultRouterProxy.ice_getIdentity().category; - routerEndpoints = ""; - Ice.Endpoint[] endpoints = defaultRouterProxy.ice_getEndpoints(); - for(int i = 0; i < endpoints.length; ++i) - { - if(i > 0) - { - routerEndpoints += ":"; - } - routerEndpoints += endpoints[i].toString(); - } - } - else - { - routerInstanceName = _connectionPrefs.get("router.instanceName", routerInstanceName); - routerEndpoints = _connectionPrefs.get("router.endpoints", routerEndpoints); - } - registrySSLEnabled = _connectionPrefs.getBoolean("routerSSLEnabled", registrySSLEnabled); - - // - // Property, if defined, prevails - // - registryUsername = _connectionPrefs.get("registry.username", registryUsername); - registryUsername = properties.getPropertyWithDefault("IceGridAdmin.Username", registryUsername); - registryPassword = properties.getProperty("IceGridAdmin.Password").toCharArray(); - - registryUseSSL = _connectionPrefs.getBoolean("registry.useSSL", registryUseSSL); - registryUseSSL = properties.getPropertyAsIntWithDefault("IceGridAdmin.AuthenticateUsingSSL", - registryUseSSL ? 1 : 0) > 0; - - registrySSLEnabled = registryUseSSL || _connectionPrefs.getBoolean("registry.sslEnabled", registrySSLEnabled); - - routerUsername = _connectionPrefs.get("router.username", routerUsername); - routerUsername = properties.getPropertyWithDefault("IceGridAdmin.Username", routerUsername); - routerPassword = properties.getProperty("IceGridAdmin.Password").toCharArray(); - - routerUseSSL = _connectionPrefs.getBoolean("router.useSSL", routerUseSSL); - routerUseSSL = properties.getPropertyAsIntWithDefault("IceGridAdmin.AuthenticateUsingSSL", - routerUseSSL ? 1 : 0) > 0; - - routerSSLEnabled = routerUseSSL || _connectionPrefs.getBoolean("router.sslEnabled", routerSSLEnabled); - - routed = properties.getPropertyAsInt("IceGridAdmin.Routed") > 0 || _connectionPrefs.getBoolean("routed", routed); - - // - // SSL Configuration - // - keystore = properties.getPropertyWithDefault("IceSSL.Keystore", - _connectionPrefs.get("keystore", keystore)); - - alias = properties.getPropertyWithDefault("IceSSL.Alias", - _connectionPrefs.get("alias", "")); - - truststore = properties.getPropertyWithDefault("IceSSL.Truststore", - _connectionPrefs.get("truststore", truststore)); - } - - void save() - { - _connectionPrefs.putBoolean("routed", routed); - - if(routed) - { - _connectionPrefs.put("router.username", routerUsername); - _connectionPrefs.putBoolean("router.useSSL", routerUseSSL); - _connectionPrefs.putBoolean("router.sslEnabled", routerSSLEnabled); - _connectionPrefs.put("router.instanceName", routerInstanceName); - _connectionPrefs.put("router.endpoints", routerEndpoints); - } - else - { - _connectionPrefs.put("registry.username", registryUsername); - _connectionPrefs.putBoolean("registry.useSSL", registryUseSSL); - _connectionPrefs.putBoolean("registry.sslEnabled", registrySSLEnabled); - _connectionPrefs.put("registry.instanceName", registryInstanceName); - _connectionPrefs.put("registry.endpoints", registryEndpoints); - _connectionPrefs.putBoolean("registry.connectToMaster", connectToMaster); - } - - // - // SSL Configuration - // - _connectionPrefs.put("keystore", keystore); - _connectionPrefs.put("alias", alias); - _connectionPrefs.put("truststore", truststore); - } - - boolean routed = false; - - String registryUsername = System.getProperty("user.name"); - char[] registryPassword; - boolean registryUseSSL = false; - boolean registrySSLEnabled = false; - String registryInstanceName = "IceGrid"; - String registryEndpoints = ""; - boolean connectToMaster = true; - - String routerUsername = System.getProperty("user.name"); - char[] routerPassword; - boolean routerUseSSL = false; - boolean routerSSLEnabled = false; - String routerInstanceName = "Glacier2"; - String routerEndpoints = ""; - - // - // SSL Configuration - // - String keystore = System.getProperty("java.net.ssl.keyStore"); - char[] keyPassword; - char[] keystorePassword; - String alias; - String truststore = System.getProperty("java.net.ssl.trustStore"); - char[] truststorePassword; - private Preferences _connectionPrefs; + LoginInfo(Preferences connectionPrefs, Coordinator coordinator) + { + _connectionPrefs = connectionPrefs; + + String prop = System.getProperty("java.net.ssl.keyStorePassword"); + if(prop != null) + { + keystorePassword = prop.toCharArray(); + } + prop = System.getProperty("java.net.ssl.trustStorePassword"); + if(prop != null) + { + truststorePassword = prop.toCharArray(); + } + + Ice.Properties properties = coordinator.getProperties(); + + // + // Registry properties + // + Ice.ObjectPrx defaultLocatorProxy = null; + try + { + defaultLocatorProxy = coordinator.getCommunicator().propertyToProxy("Ice.Default.Locator"); + } + catch(Ice.LocalException e) + { + // Ignored, keep null defaultLocatorProxy + } + if(defaultLocatorProxy != null) + { + // + // Set new defaults + // + registryInstanceName = defaultLocatorProxy.ice_getIdentity().category; + registryEndpoints = ""; + Ice.Endpoint[] endpoints = defaultLocatorProxy.ice_getEndpoints(); + for(int i = 0; i < endpoints.length; ++i) + { + if(i > 0) + { + registryEndpoints += ":"; + } + registryEndpoints += endpoints[i].toString(); + } + } + else + { + registryInstanceName = + _connectionPrefs.get("registry.instanceName", registryInstanceName); + registryEndpoints = + _connectionPrefs.get("registry.endpoints", registryEndpoints); + } + connectToMaster = _connectionPrefs.getBoolean("registry.connectToMaster", connectToMaster); + + + // + // Glacier2 properties + // + Ice.ObjectPrx defaultRouterProxy = null; + try + { + defaultRouterProxy = coordinator.getCommunicator().propertyToProxy("Ice.Default.Router"); + } + catch(Ice.LocalException e) + { + // Ignored, keep null defaultRouterProxy + } + if(defaultRouterProxy != null) + { + // + // Set new defaults + // + routerInstanceName = defaultRouterProxy.ice_getIdentity().category; + routerEndpoints = ""; + Ice.Endpoint[] endpoints = defaultRouterProxy.ice_getEndpoints(); + for(int i = 0; i < endpoints.length; ++i) + { + if(i > 0) + { + routerEndpoints += ":"; + } + routerEndpoints += endpoints[i].toString(); + } + } + else + { + routerInstanceName = _connectionPrefs.get("router.instanceName", routerInstanceName); + routerEndpoints = _connectionPrefs.get("router.endpoints", routerEndpoints); + } + registrySSLEnabled = _connectionPrefs.getBoolean("routerSSLEnabled", registrySSLEnabled); + + // + // Property, if defined, prevails + // + registryUsername = _connectionPrefs.get("registry.username", registryUsername); + registryUsername = properties.getPropertyWithDefault("IceGridAdmin.Username", registryUsername); + registryPassword = properties.getProperty("IceGridAdmin.Password").toCharArray(); + + registryUseSSL = _connectionPrefs.getBoolean("registry.useSSL", registryUseSSL); + registryUseSSL = properties.getPropertyAsIntWithDefault("IceGridAdmin.AuthenticateUsingSSL", + registryUseSSL ? 1 : 0) > 0; + + registrySSLEnabled = registryUseSSL || _connectionPrefs.getBoolean("registry.sslEnabled", registrySSLEnabled); + + routerUsername = _connectionPrefs.get("router.username", routerUsername); + routerUsername = properties.getPropertyWithDefault("IceGridAdmin.Username", routerUsername); + routerPassword = properties.getProperty("IceGridAdmin.Password").toCharArray(); + + routerUseSSL = _connectionPrefs.getBoolean("router.useSSL", routerUseSSL); + routerUseSSL = properties.getPropertyAsIntWithDefault("IceGridAdmin.AuthenticateUsingSSL", + routerUseSSL ? 1 : 0) > 0; + + routerSSLEnabled = routerUseSSL || _connectionPrefs.getBoolean("router.sslEnabled", routerSSLEnabled); + + routed = properties.getPropertyAsInt("IceGridAdmin.Routed") > 0 || _connectionPrefs.getBoolean("routed", routed); + + // + // SSL Configuration + // + keystore = properties.getPropertyWithDefault("IceSSL.Keystore", + _connectionPrefs.get("keystore", keystore)); + + alias = properties.getPropertyWithDefault("IceSSL.Alias", + _connectionPrefs.get("alias", "")); + + truststore = properties.getPropertyWithDefault("IceSSL.Truststore", + _connectionPrefs.get("truststore", truststore)); + } + + void save() + { + _connectionPrefs.putBoolean("routed", routed); + + if(routed) + { + _connectionPrefs.put("router.username", routerUsername); + _connectionPrefs.putBoolean("router.useSSL", routerUseSSL); + _connectionPrefs.putBoolean("router.sslEnabled", routerSSLEnabled); + _connectionPrefs.put("router.instanceName", routerInstanceName); + _connectionPrefs.put("router.endpoints", routerEndpoints); + } + else + { + _connectionPrefs.put("registry.username", registryUsername); + _connectionPrefs.putBoolean("registry.useSSL", registryUseSSL); + _connectionPrefs.putBoolean("registry.sslEnabled", registrySSLEnabled); + _connectionPrefs.put("registry.instanceName", registryInstanceName); + _connectionPrefs.put("registry.endpoints", registryEndpoints); + _connectionPrefs.putBoolean("registry.connectToMaster", connectToMaster); + } + + // + // SSL Configuration + // + _connectionPrefs.put("keystore", keystore); + _connectionPrefs.put("alias", alias); + _connectionPrefs.put("truststore", truststore); + } + + boolean routed = false; + + String registryUsername = System.getProperty("user.name"); + char[] registryPassword; + boolean registryUseSSL = false; + boolean registrySSLEnabled = false; + String registryInstanceName = "IceGrid"; + String registryEndpoints = ""; + boolean connectToMaster = true; + + String routerUsername = System.getProperty("user.name"); + char[] routerPassword; + boolean routerUseSSL = false; + boolean routerSSLEnabled = false; + String routerInstanceName = "Glacier2"; + String routerEndpoints = ""; + + // + // SSL Configuration + // + String keystore = System.getProperty("java.net.ssl.keyStore"); + char[] keyPassword; + char[] keystorePassword; + String alias; + String truststore = System.getProperty("java.net.ssl.trustStore"); + char[] truststorePassword; + private Preferences _connectionPrefs; } private class LoginDialog extends JDialog { - LoginDialog() - { - super(_coordinator.getMainFrame(), "Login - IceGrid Admin", true); - setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); - - final File defaultDir = new java.io.File(_coordinator.getProperties().getProperty("IceSSL.DefaultDir")); - _keystoreType = - _coordinator.getProperties().getPropertyWithDefault("IceSSL.KeystoreType", - java.security.KeyStore.getDefaultType()); - - JButton okButton = new JButton("OK"); - ActionListener okListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - writeInfo(); - - if(login(LoginDialog.this)) - { - setVisible(false); - } - - // - // Otherwise go back to the dialog - // - } - }; - okButton.addActionListener(okListener); - getRootPane().setDefaultButton(okButton); - - JButton cancelButton = new JButton("Cancel"); - ActionListener cancelListener = new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - setVisible(false); - } - }; - cancelButton.addActionListener(cancelListener); - - Action registryUseSSL = new AbstractAction("Use SSL for authentication") - { - public void actionPerformed(ActionEvent e) - { - selectRegistryUseSSL(_registryUseSSL.isSelected()); - } - }; - _registryUseSSL = new JCheckBox(registryUseSSL); - - - Action routerUseSSL = new AbstractAction("Use SSL for authentication") - { - public void actionPerformed(ActionEvent e) - { - selectRouterUseSSL(_routerUseSSL.isSelected()); - } - }; - _routerUseSSL = new JCheckBox(routerUseSSL); - - Action registrySSLEnabled = new AbstractAction("Enable IceSSL") - { - public void actionPerformed(ActionEvent e) - { - selectRegistrySSLEnabled(_registrySSLEnabled.isSelected()); - } - }; - _registrySSLEnabled = new JCheckBox(registrySSLEnabled); - - Action routerSSLEnabled = new AbstractAction("Enable IceSSL") - { - public void actionPerformed(ActionEvent e) - { - selectRouterSSLEnabled(_routerSSLEnabled.isSelected()); - } - }; - _routerSSLEnabled = new JCheckBox(routerSSLEnabled); - - - _keystore.setEditable(false); - _advancedKeystore.setEditable(false); - Action chooseKeystore = new AbstractAction("...") - { - public void actionPerformed(ActionEvent e) - { - String store = _keystore.getText(); - if(store == null || store.length() == 0) - { - _fileChooser.setCurrentDirectory(defaultDir); - } - else - { - File file = new File(store); - if(file.isAbsolute()) - { - _fileChooser.setSelectedFile(file); - } - else - { - _fileChooser.setSelectedFile(new File(defaultDir, store)); - } - } - - int result = _fileChooser.showOpenDialog(LoginDialog.this); - if(result == JFileChooser.APPROVE_OPTION) - { - File file = _fileChooser.getSelectedFile(); - _keystore.setText(file.getAbsolutePath()); - updateAlias(file, _alias.getSelectedItem()); - } - } - private JFileChooser _fileChooser = new JFileChooser(); - }; - - _truststore.setEditable(false); - Action chooseTruststore = new AbstractAction("...") - { - public void actionPerformed(ActionEvent e) - { - String store = _truststore.getText(); - if(store == null || store.length() == 0) - { - _fileChooser.setCurrentDirectory(defaultDir); - } - else - { - File file = new File(store); - if(file.isAbsolute()) - { - _fileChooser.setSelectedFile(file); - } - else - { - _fileChooser.setSelectedFile(new File(defaultDir, store)); - } - } - - int result = _fileChooser.showOpenDialog(LoginDialog.this); - if(result == JFileChooser.APPROVE_OPTION) - { - File file = _fileChooser.getSelectedFile(); - _truststore.setText(file.getAbsolutePath()); - } - } - - private JFileChooser _fileChooser = new JFileChooser(); - }; - - - _registryUsername.setToolTipText("Your username"); - _registryPassword.setToolTipText("Your password in this IceGrid registry"); - _registryUseSSL.setToolTipText("Do you want to use SSL instead of username/password for authentication?"); - _registryInstanceName.setToolTipText("The instance name of your IceGrid registry. For example: DemoIceGrid"); - _registryEndpoints.setToolTipText("<html>Corresponds to the client endpoints of this IceGrid registry.<br>" - + "For example: tcp -h registry.domain.com -p 12000</html>"); - - _routerUsername.setToolTipText("Your username"); - _routerPassword.setToolTipText("Your password in this Glacier2 router"); - _routerUseSSL.setToolTipText("Do you want to use SSL instead of username/password for authentication?"); - _routerInstanceName.setToolTipText("The instance name of your Glacier2 router. For example: DemoGlacier2"); - _routerEndpoints.setToolTipText("<html>Corresponds to client endpoints of this Glacier2 router.<br>" - + "For example: ssl -h glacier2router.domain.com -p 11000</html>"); - - _keystore.setToolTipText("SSL keystore file"); - _keyPassword.setToolTipText("Password for keys in the selected keystore file"); - _advancedKeystore.setToolTipText("SSL keystore file"); - _advancedKeyPassword.setToolTipText("Password for keys in the selected keystore file"); - - _keystorePassword.setToolTipText("Password used to check the integrity of the keystore"); - _alias.setToolTipText("Use this alias when authenticating IceGrid Admin with the IceGrid registry or Glacier2 router"); - - _truststore.setToolTipText("SSL truststore file"); - _truststorePassword.setToolTipText("Password used to check the integrity of the truststore"); - - - JPanel directPanel = null; - { - FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); - - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - _registryUsernameLabel = builder.append("Username", _registryUsername); - builder.nextLine(); - _registryPasswordLabel = builder.append("Password", _registryPassword); - builder.nextLine(); - builder.append("", _registryUseSSL); - builder.nextLine(); - builder.append("", _registrySSLEnabled); - builder.nextLine(); - builder.append("IceGrid Instance Name", _registryInstanceName); - builder.nextLine(); - builder.append("IceGrid Registry Endpoint(s)", _registryEndpoints); - builder.nextLine(); - builder.append("", _connectToMaster); - builder.nextLine(); - - directPanel = builder.getPanel(); - } - - - JPanel routedPanel = null; - { - FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); - - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - _routerUsernameLabel = builder.append("Username", _routerUsername); - builder.nextLine(); - _routerPasswordLabel = builder.append("Password", _routerPassword); - builder.nextLine(); - builder.append("", _routerUseSSL); - builder.nextLine(); - builder.append("", _routerSSLEnabled); - builder.nextLine(); - builder.append("Glacier2 Instance Name", _routerInstanceName); - builder.nextLine(); - builder.append("Glacier2 Router Endpoint(s)", _routerEndpoints); - builder.nextLine(); - - routedPanel = builder.getPanel(); - } - - _mainPane.addTab("Direct", null, directPanel, "Log directly into the IceGrid registry"); - _mainPane.addTab("Routed", null, routedPanel, "Log into the IceGrid registry through a Glacier2 router"); - _mainPane.setBorder(Borders.DIALOG_BORDER); - - _mainPane.addChangeListener(new javax.swing.event.ChangeListener() - { - public void stateChanged(javax.swing.event.ChangeEvent e) - { - if(_mainPane.getSelectedIndex() == 0) - { - directTabSelected(); - } - else - { - routedTabSelected(); - } - } - }); - - JPanel basicSSLPanel = null; - { - FormLayout layout = new FormLayout( - "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", ""); - - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - builder.appendSeparator("Keystore"); - builder.append("File", _keystore); - builder.append(new JButton(chooseKeystore)); - builder.nextLine(); - builder.append("Key Password"); - builder.append(_keyPassword, 3); - builder.nextLine(); - - basicSSLPanel = builder.getPanel(); - } - - JPanel advancedSSLPanel = null; - { - FormLayout layout = new FormLayout( - "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", ""); - - DefaultFormBuilder builder = new DefaultFormBuilder(layout); - builder.setDefaultDialogBorder(); - builder.setRowGroupingEnabled(true); - builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); - - builder.appendSeparator("Keystore"); - builder.append("File", _advancedKeystore); - builder.append(new JButton(chooseKeystore)); - builder.nextLine(); - builder.append("Key Password"); - builder.append(_advancedKeyPassword, 3); - builder.nextLine(); - builder.append("Integrity Password"); - builder.append(_keystorePassword, 3); - builder.nextLine(); - builder.append("Alias"); - builder.append(_alias, 3); - builder.nextLine(); - - builder.appendSeparator("Truststore"); - builder.append("File", _truststore); - builder.append(new JButton(chooseTruststore));; - builder.nextLine(); - builder.append("Integrity Password"); - builder.append(_truststorePassword, 3); - builder.nextLine(); - - advancedSSLPanel = builder.getPanel(); - } - - - _sslPane.addTab("Basic", basicSSLPanel); - _sslPane.addTab("Advanced", advancedSSLPanel); - TitledBorder titledBorder = BorderFactory.createTitledBorder(Borders.DIALOG_BORDER, - "SSL Configuration"); - _sslPane.setBorder(titledBorder); - - JComponent buttonBar = - ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); - buttonBar.setBorder(Borders.DIALOG_BORDER); - - Container contentPane = getContentPane(); - contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); - contentPane.add(_mainPane); - contentPane.add(_sslPane); - contentPane.add(buttonBar); - - pack(); - setResizable(false); - } - - void showDialog() - { - if(isVisible() == false) - { - _mainPane.setSelectedIndex(_loginInfo.routed ? 1 : 0); - - _registryUsername.setText(_loginInfo.registryUsername); - _registryPassword.setText(new String(_loginInfo.registryPassword)); - - selectRegistryUseSSL(_loginInfo.registryUseSSL); - - _registryInstanceName.setText(_loginInfo.registryInstanceName); - _registryEndpoints.setText(_loginInfo.registryEndpoints); - _registrySSLEnabled.setSelected(_loginInfo.registrySSLEnabled); - _connectToMaster.setSelected(_loginInfo.connectToMaster); - - _routerUsername.setText(_loginInfo.routerUsername); - _routerPassword.setText(new String(_loginInfo.routerPassword)); - selectRouterUseSSL(_loginInfo.routerUseSSL); - - _routerInstanceName.setText(_loginInfo.routerInstanceName); - _routerEndpoints.setText(_loginInfo.routerEndpoints); - _routerSSLEnabled.setSelected(_loginInfo.routerSSLEnabled); - - _keystore.setText(_loginInfo.keystore); - if(_loginInfo.keystore == null) - { - clearAlias(); - } - else - { - updateAlias(new File(_loginInfo.keystore), _loginInfo.alias); - } - _truststore.setText(_loginInfo.truststore); - - if(_loginInfo.routed) - { - routedTabSelected(); - } - else - { - directTabSelected(); - } - - setLocationRelativeTo(_coordinator.getMainFrame()); - setVisible(true); - } - - // - // Otherwise it was already on the screen! - // - } + LoginDialog() + { + super(_coordinator.getMainFrame(), "Login - IceGrid Admin", true); + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); + + final File defaultDir = new java.io.File(_coordinator.getProperties().getProperty("IceSSL.DefaultDir")); + _keystoreType = + _coordinator.getProperties().getPropertyWithDefault("IceSSL.KeystoreType", + java.security.KeyStore.getDefaultType()); + + JButton okButton = new JButton("OK"); + ActionListener okListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + writeInfo(); + + if(login(LoginDialog.this)) + { + setVisible(false); + } + + // + // Otherwise go back to the dialog + // + } + }; + okButton.addActionListener(okListener); + getRootPane().setDefaultButton(okButton); + + JButton cancelButton = new JButton("Cancel"); + ActionListener cancelListener = new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setVisible(false); + } + }; + cancelButton.addActionListener(cancelListener); + + Action registryUseSSL = new AbstractAction("Use SSL for authentication") + { + public void actionPerformed(ActionEvent e) + { + selectRegistryUseSSL(_registryUseSSL.isSelected()); + } + }; + _registryUseSSL = new JCheckBox(registryUseSSL); + + + Action routerUseSSL = new AbstractAction("Use SSL for authentication") + { + public void actionPerformed(ActionEvent e) + { + selectRouterUseSSL(_routerUseSSL.isSelected()); + } + }; + _routerUseSSL = new JCheckBox(routerUseSSL); + + Action registrySSLEnabled = new AbstractAction("Enable IceSSL") + { + public void actionPerformed(ActionEvent e) + { + selectRegistrySSLEnabled(_registrySSLEnabled.isSelected()); + } + }; + _registrySSLEnabled = new JCheckBox(registrySSLEnabled); + + Action routerSSLEnabled = new AbstractAction("Enable IceSSL") + { + public void actionPerformed(ActionEvent e) + { + selectRouterSSLEnabled(_routerSSLEnabled.isSelected()); + } + }; + _routerSSLEnabled = new JCheckBox(routerSSLEnabled); + + + _keystore.setEditable(false); + _advancedKeystore.setEditable(false); + Action chooseKeystore = new AbstractAction("...") + { + public void actionPerformed(ActionEvent e) + { + String store = _keystore.getText(); + if(store == null || store.length() == 0) + { + _fileChooser.setCurrentDirectory(defaultDir); + } + else + { + File file = new File(store); + if(file.isAbsolute()) + { + _fileChooser.setSelectedFile(file); + } + else + { + _fileChooser.setSelectedFile(new File(defaultDir, store)); + } + } + + int result = _fileChooser.showOpenDialog(LoginDialog.this); + if(result == JFileChooser.APPROVE_OPTION) + { + File file = _fileChooser.getSelectedFile(); + _keystore.setText(file.getAbsolutePath()); + updateAlias(file, _alias.getSelectedItem()); + } + } + private JFileChooser _fileChooser = new JFileChooser(); + }; + + _truststore.setEditable(false); + Action chooseTruststore = new AbstractAction("...") + { + public void actionPerformed(ActionEvent e) + { + String store = _truststore.getText(); + if(store == null || store.length() == 0) + { + _fileChooser.setCurrentDirectory(defaultDir); + } + else + { + File file = new File(store); + if(file.isAbsolute()) + { + _fileChooser.setSelectedFile(file); + } + else + { + _fileChooser.setSelectedFile(new File(defaultDir, store)); + } + } + + int result = _fileChooser.showOpenDialog(LoginDialog.this); + if(result == JFileChooser.APPROVE_OPTION) + { + File file = _fileChooser.getSelectedFile(); + _truststore.setText(file.getAbsolutePath()); + } + } + + private JFileChooser _fileChooser = new JFileChooser(); + }; + + + _registryUsername.setToolTipText("Your username"); + _registryPassword.setToolTipText("Your password in this IceGrid registry"); + _registryUseSSL.setToolTipText("Do you want to use SSL instead of username/password for authentication?"); + _registryInstanceName.setToolTipText("The instance name of your IceGrid registry. For example: DemoIceGrid"); + _registryEndpoints.setToolTipText("<html>Corresponds to the client endpoints of this IceGrid registry.<br>" + + "For example: tcp -h registry.domain.com -p 12000</html>"); + + _routerUsername.setToolTipText("Your username"); + _routerPassword.setToolTipText("Your password in this Glacier2 router"); + _routerUseSSL.setToolTipText("Do you want to use SSL instead of username/password for authentication?"); + _routerInstanceName.setToolTipText("The instance name of your Glacier2 router. For example: DemoGlacier2"); + _routerEndpoints.setToolTipText("<html>Corresponds to client endpoints of this Glacier2 router.<br>" + + "For example: ssl -h glacier2router.domain.com -p 11000</html>"); + + _keystore.setToolTipText("SSL keystore file"); + _keyPassword.setToolTipText("Password for keys in the selected keystore file"); + _advancedKeystore.setToolTipText("SSL keystore file"); + _advancedKeyPassword.setToolTipText("Password for keys in the selected keystore file"); + + _keystorePassword.setToolTipText("Password used to check the integrity of the keystore"); + _alias.setToolTipText("Use this alias when authenticating IceGrid Admin with the IceGrid registry or Glacier2 router"); + + _truststore.setToolTipText("SSL truststore file"); + _truststorePassword.setToolTipText("Password used to check the integrity of the truststore"); + + + JPanel directPanel = null; + { + FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); + + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + _registryUsernameLabel = builder.append("Username", _registryUsername); + builder.nextLine(); + _registryPasswordLabel = builder.append("Password", _registryPassword); + builder.nextLine(); + builder.append("", _registryUseSSL); + builder.nextLine(); + builder.append("", _registrySSLEnabled); + builder.nextLine(); + builder.append("IceGrid Instance Name", _registryInstanceName); + builder.nextLine(); + builder.append("IceGrid Registry Endpoint(s)", _registryEndpoints); + builder.nextLine(); + builder.append("", _connectToMaster); + builder.nextLine(); + + directPanel = builder.getPanel(); + } + + + JPanel routedPanel = null; + { + FormLayout layout = new FormLayout("right:pref, 3dlu, pref", ""); + + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + _routerUsernameLabel = builder.append("Username", _routerUsername); + builder.nextLine(); + _routerPasswordLabel = builder.append("Password", _routerPassword); + builder.nextLine(); + builder.append("", _routerUseSSL); + builder.nextLine(); + builder.append("", _routerSSLEnabled); + builder.nextLine(); + builder.append("Glacier2 Instance Name", _routerInstanceName); + builder.nextLine(); + builder.append("Glacier2 Router Endpoint(s)", _routerEndpoints); + builder.nextLine(); + + routedPanel = builder.getPanel(); + } + + _mainPane.addTab("Direct", null, directPanel, "Log directly into the IceGrid registry"); + _mainPane.addTab("Routed", null, routedPanel, "Log into the IceGrid registry through a Glacier2 router"); + _mainPane.setBorder(Borders.DIALOG_BORDER); + + _mainPane.addChangeListener(new javax.swing.event.ChangeListener() + { + public void stateChanged(javax.swing.event.ChangeEvent e) + { + if(_mainPane.getSelectedIndex() == 0) + { + directTabSelected(); + } + else + { + routedTabSelected(); + } + } + }); + + JPanel basicSSLPanel = null; + { + FormLayout layout = new FormLayout( + "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", ""); + + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + builder.appendSeparator("Keystore"); + builder.append("File", _keystore); + builder.append(new JButton(chooseKeystore)); + builder.nextLine(); + builder.append("Key Password"); + builder.append(_keyPassword, 3); + builder.nextLine(); + + basicSSLPanel = builder.getPanel(); + } + + JPanel advancedSSLPanel = null; + { + FormLayout layout = new FormLayout( + "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", ""); + + DefaultFormBuilder builder = new DefaultFormBuilder(layout); + builder.setDefaultDialogBorder(); + builder.setRowGroupingEnabled(true); + builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad()); + + builder.appendSeparator("Keystore"); + builder.append("File", _advancedKeystore); + builder.append(new JButton(chooseKeystore)); + builder.nextLine(); + builder.append("Key Password"); + builder.append(_advancedKeyPassword, 3); + builder.nextLine(); + builder.append("Integrity Password"); + builder.append(_keystorePassword, 3); + builder.nextLine(); + builder.append("Alias"); + builder.append(_alias, 3); + builder.nextLine(); + + builder.appendSeparator("Truststore"); + builder.append("File", _truststore); + builder.append(new JButton(chooseTruststore));; + builder.nextLine(); + builder.append("Integrity Password"); + builder.append(_truststorePassword, 3); + builder.nextLine(); + + advancedSSLPanel = builder.getPanel(); + } + + + _sslPane.addTab("Basic", basicSSLPanel); + _sslPane.addTab("Advanced", advancedSSLPanel); + TitledBorder titledBorder = BorderFactory.createTitledBorder(Borders.DIALOG_BORDER, + "SSL Configuration"); + _sslPane.setBorder(titledBorder); + + JComponent buttonBar = + ButtonBarFactory.buildOKCancelBar(okButton, cancelButton); + buttonBar.setBorder(Borders.DIALOG_BORDER); + + Container contentPane = getContentPane(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + contentPane.add(_mainPane); + contentPane.add(_sslPane); + contentPane.add(buttonBar); + + pack(); + setResizable(false); + } + + void showDialog() + { + if(isVisible() == false) + { + _mainPane.setSelectedIndex(_loginInfo.routed ? 1 : 0); + + _registryUsername.setText(_loginInfo.registryUsername); + _registryPassword.setText(new String(_loginInfo.registryPassword)); + + selectRegistryUseSSL(_loginInfo.registryUseSSL); + + _registryInstanceName.setText(_loginInfo.registryInstanceName); + _registryEndpoints.setText(_loginInfo.registryEndpoints); + _registrySSLEnabled.setSelected(_loginInfo.registrySSLEnabled); + _connectToMaster.setSelected(_loginInfo.connectToMaster); + + _routerUsername.setText(_loginInfo.routerUsername); + _routerPassword.setText(new String(_loginInfo.routerPassword)); + selectRouterUseSSL(_loginInfo.routerUseSSL); + + _routerInstanceName.setText(_loginInfo.routerInstanceName); + _routerEndpoints.setText(_loginInfo.routerEndpoints); + _routerSSLEnabled.setSelected(_loginInfo.routerSSLEnabled); + + _keystore.setText(_loginInfo.keystore); + if(_loginInfo.keystore == null) + { + clearAlias(); + } + else + { + updateAlias(new File(_loginInfo.keystore), _loginInfo.alias); + } + _truststore.setText(_loginInfo.truststore); + + if(_loginInfo.routed) + { + routedTabSelected(); + } + else + { + directTabSelected(); + } + + setLocationRelativeTo(_coordinator.getMainFrame()); + setVisible(true); + } + + // + // Otherwise it was already on the screen! + // + } - private void writeInfo() - { - _loginInfo.routed = (_mainPane.getSelectedIndex() == 1); - - _loginInfo.registryUsername = _registryUsername.getText(); - _loginInfo.registryPassword = _registryPassword.getPassword(); - _loginInfo.registryUseSSL = _registryUseSSL.isSelected(); - _loginInfo.registrySSLEnabled = _registrySSLEnabled.isSelected(); - _loginInfo.registryInstanceName = _registryInstanceName.getText(); - _loginInfo.registryEndpoints = _registryEndpoints.getText(); - _loginInfo.connectToMaster = _connectToMaster.isSelected(); - - _loginInfo.routerUsername = _routerUsername.getText(); - _loginInfo.routerPassword = _routerPassword.getPassword(); - _loginInfo.routerUseSSL = _routerUseSSL.isSelected(); - _loginInfo.routerSSLEnabled = _routerSSLEnabled.isSelected(); - _loginInfo.routerInstanceName = _routerInstanceName.getText(); - _loginInfo.routerEndpoints = _routerEndpoints.getText(); - - _loginInfo.keystore = _keystore.getText(); - _loginInfo.keyPassword = _keyPassword.getPassword(); - _loginInfo.keystorePassword = _keystorePassword.getPassword(); - if(_alias.getSelectedItem() == null) - { - _loginInfo.alias = ""; - } - else - { - _loginInfo.alias = _alias.getSelectedItem().toString(); - } - _loginInfo.truststore = _truststore.getText(); - _loginInfo.truststorePassword = _truststorePassword.getPassword(); - } - - private void updateAlias(File file, Object selectedAlias) - { - if(file.isFile()) - { - InputStream is = null; - try - { - is = new FileInputStream(file); - } - catch(java.io.IOException e) - { - clearAlias(); - return; - } - - java.util.Vector aliasVector = new java.util.Vector(); - - try - { - KeyStore ks = KeyStore.getInstance(_keystoreType); - ks.load(is, null); - java.util.Enumeration p = ks.aliases(); - while(p.hasMoreElements()) - { - aliasVector.add(p.nextElement()); - } - } - catch(Exception e) - { - clearAlias(); - return; - } - finally - { - try - { - is.close(); - } - catch(java.io.IOException e) - {} - } - _alias.setModel(new DefaultComboBoxModel(aliasVector)); - if(selectedAlias != null) - { - _alias.setSelectedItem(selectedAlias); - } - } - else - { - clearAlias(); - } - } - - private void clearAlias() - { - _alias.setModel(new DefaultComboBoxModel()); - } - - private void selectRegistryUseSSL(boolean selected) - { - _registryUseSSL.setSelected(selected); - _registryUsername.setEnabled(!selected); - _registryUsernameLabel.setEnabled(!selected); - _registryPassword.setEnabled(!selected); - _registryPasswordLabel.setEnabled(!selected); - - if(selected && _registrySSLEnabled.isSelected() == false) - { - selectRegistrySSLEnabled(selected); - } - } - - private void selectRouterUseSSL(boolean selected) - { - _routerUseSSL.setSelected(selected); - _routerUsername.setEnabled(!selected); - _routerUsernameLabel.setEnabled(!selected); - _routerPassword.setEnabled(!selected); - _routerPasswordLabel.setEnabled(!selected); - - if(selected && _routerSSLEnabled.isSelected() == false) - { - selectRouterSSLEnabled(selected); - } - } - - private void selectRegistrySSLEnabled(boolean selected) - { - _registrySSLEnabled.setSelected(selected); - recursiveSetEnabled(_sslPane, selected); - if(!selected && _registryUseSSL.isSelected()) - { - selectRegistryUseSSL(selected); - } - } - - private void selectRouterSSLEnabled(boolean selected) - { - _routerSSLEnabled.setSelected(selected); - recursiveSetEnabled(_sslPane, selected); - if(!selected && _routerUseSSL.isSelected()) - { - selectRouterUseSSL(selected); - } - } - - private void recursiveSetEnabled(java.awt.Container c, boolean enabled) - { - for(int i = 0; i < c.getComponentCount(); ++i) - { - java.awt.Component comp = c.getComponent(i); - if(comp instanceof java.awt.Container) - { - recursiveSetEnabled((java.awt.Container)comp, enabled); - } - comp.setEnabled(enabled); - } - c.setEnabled(enabled); - } - - private void directTabSelected() - { - recursiveSetEnabled(_sslPane, _registrySSLEnabled.isSelected()); - } - - private void routedTabSelected() - { - recursiveSetEnabled(_sslPane, _routerSSLEnabled.isSelected()); - } - - private JTabbedPane _mainPane = new JTabbedPane(); - private JTextField _registryUsername = new JTextField(30); - private JLabel _registryUsernameLabel; - private JPasswordField _registryPassword = new JPasswordField(30); - private JLabel _registryPasswordLabel; - private JCheckBox _registryUseSSL; - private JCheckBox _registrySSLEnabled; - private JTextField _registryInstanceName = new JTextField(30); - private JTextField _registryEndpoints = new JTextField(30); - private JCheckBox _connectToMaster = new JCheckBox("Connect to Master Registry"); - - private JTextField _routerUsername = new JTextField(30); - private JLabel _routerUsernameLabel; - private JPasswordField _routerPassword = new JPasswordField(30); - private JLabel _routerPasswordLabel; - private JCheckBox _routerUseSSL; - private JCheckBox _routerSSLEnabled; - private JTextField _routerInstanceName = new JTextField(30); - private JTextField _routerEndpoints = new JTextField(30); - - private JTabbedPane _sslPane = new JTabbedPane(); - private JTextField _keystore = new JTextField(30); - private JPasswordField _keyPassword = new JPasswordField(30); - - private JTextField _advancedKeystore = new JTextField( - _keystore.getDocument(), null, 30); - private JPasswordField _advancedKeyPassword = new JPasswordField( - _keyPassword.getDocument(), null, 30); - - private JPasswordField _keystorePassword = new JPasswordField(30); - private JComboBox _alias = new JComboBox(); - - private JTextField _truststore = new JTextField(30); - private JPasswordField _truststorePassword = new JPasswordField(30); - - private String _keystoreType; + private void writeInfo() + { + _loginInfo.routed = (_mainPane.getSelectedIndex() == 1); + + _loginInfo.registryUsername = _registryUsername.getText(); + _loginInfo.registryPassword = _registryPassword.getPassword(); + _loginInfo.registryUseSSL = _registryUseSSL.isSelected(); + _loginInfo.registrySSLEnabled = _registrySSLEnabled.isSelected(); + _loginInfo.registryInstanceName = _registryInstanceName.getText(); + _loginInfo.registryEndpoints = _registryEndpoints.getText(); + _loginInfo.connectToMaster = _connectToMaster.isSelected(); + + _loginInfo.routerUsername = _routerUsername.getText(); + _loginInfo.routerPassword = _routerPassword.getPassword(); + _loginInfo.routerUseSSL = _routerUseSSL.isSelected(); + _loginInfo.routerSSLEnabled = _routerSSLEnabled.isSelected(); + _loginInfo.routerInstanceName = _routerInstanceName.getText(); + _loginInfo.routerEndpoints = _routerEndpoints.getText(); + + _loginInfo.keystore = _keystore.getText(); + _loginInfo.keyPassword = _keyPassword.getPassword(); + _loginInfo.keystorePassword = _keystorePassword.getPassword(); + if(_alias.getSelectedItem() == null) + { + _loginInfo.alias = ""; + } + else + { + _loginInfo.alias = _alias.getSelectedItem().toString(); + } + _loginInfo.truststore = _truststore.getText(); + _loginInfo.truststorePassword = _truststorePassword.getPassword(); + } + + private void updateAlias(File file, Object selectedAlias) + { + if(file.isFile()) + { + InputStream is = null; + try + { + is = new FileInputStream(file); + } + catch(java.io.IOException e) + { + clearAlias(); + return; + } + + java.util.Vector aliasVector = new java.util.Vector(); + + try + { + KeyStore ks = KeyStore.getInstance(_keystoreType); + ks.load(is, null); + java.util.Enumeration p = ks.aliases(); + while(p.hasMoreElements()) + { + aliasVector.add(p.nextElement()); + } + } + catch(Exception e) + { + clearAlias(); + return; + } + finally + { + try + { + is.close(); + } + catch(java.io.IOException e) + {} + } + _alias.setModel(new DefaultComboBoxModel(aliasVector)); + if(selectedAlias != null) + { + _alias.setSelectedItem(selectedAlias); + } + } + else + { + clearAlias(); + } + } + + private void clearAlias() + { + _alias.setModel(new DefaultComboBoxModel()); + } + + private void selectRegistryUseSSL(boolean selected) + { + _registryUseSSL.setSelected(selected); + _registryUsername.setEnabled(!selected); + _registryUsernameLabel.setEnabled(!selected); + _registryPassword.setEnabled(!selected); + _registryPasswordLabel.setEnabled(!selected); + + if(selected && _registrySSLEnabled.isSelected() == false) + { + selectRegistrySSLEnabled(selected); + } + } + + private void selectRouterUseSSL(boolean selected) + { + _routerUseSSL.setSelected(selected); + _routerUsername.setEnabled(!selected); + _routerUsernameLabel.setEnabled(!selected); + _routerPassword.setEnabled(!selected); + _routerPasswordLabel.setEnabled(!selected); + + if(selected && _routerSSLEnabled.isSelected() == false) + { + selectRouterSSLEnabled(selected); + } + } + + private void selectRegistrySSLEnabled(boolean selected) + { + _registrySSLEnabled.setSelected(selected); + recursiveSetEnabled(_sslPane, selected); + if(!selected && _registryUseSSL.isSelected()) + { + selectRegistryUseSSL(selected); + } + } + + private void selectRouterSSLEnabled(boolean selected) + { + _routerSSLEnabled.setSelected(selected); + recursiveSetEnabled(_sslPane, selected); + if(!selected && _routerUseSSL.isSelected()) + { + selectRouterUseSSL(selected); + } + } + + private void recursiveSetEnabled(java.awt.Container c, boolean enabled) + { + for(int i = 0; i < c.getComponentCount(); ++i) + { + java.awt.Component comp = c.getComponent(i); + if(comp instanceof java.awt.Container) + { + recursiveSetEnabled((java.awt.Container)comp, enabled); + } + comp.setEnabled(enabled); + } + c.setEnabled(enabled); + } + + private void directTabSelected() + { + recursiveSetEnabled(_sslPane, _registrySSLEnabled.isSelected()); + } + + private void routedTabSelected() + { + recursiveSetEnabled(_sslPane, _routerSSLEnabled.isSelected()); + } + + private JTabbedPane _mainPane = new JTabbedPane(); + private JTextField _registryUsername = new JTextField(30); + private JLabel _registryUsernameLabel; + private JPasswordField _registryPassword = new JPasswordField(30); + private JLabel _registryPasswordLabel; + private JCheckBox _registryUseSSL; + private JCheckBox _registrySSLEnabled; + private JTextField _registryInstanceName = new JTextField(30); + private JTextField _registryEndpoints = new JTextField(30); + private JCheckBox _connectToMaster = new JCheckBox("Connect to Master Registry"); + + private JTextField _routerUsername = new JTextField(30); + private JLabel _routerUsernameLabel; + private JPasswordField _routerPassword = new JPasswordField(30); + private JLabel _routerPasswordLabel; + private JCheckBox _routerUseSSL; + private JCheckBox _routerSSLEnabled; + private JTextField _routerInstanceName = new JTextField(30); + private JTextField _routerEndpoints = new JTextField(30); + + private JTabbedPane _sslPane = new JTabbedPane(); + private JTextField _keystore = new JTextField(30); + private JPasswordField _keyPassword = new JPasswordField(30); + + private JTextField _advancedKeystore = new JTextField( + _keystore.getDocument(), null, 30); + private JPasswordField _advancedKeyPassword = new JPasswordField( + _keyPassword.getDocument(), null, 30); + + private JPasswordField _keystorePassword = new JPasswordField(30); + private JComboBox _alias = new JComboBox(); + + private JTextField _truststore = new JTextField(30); + private JPasswordField _truststorePassword = new JPasswordField(30); + + private String _keystoreType; } @@ -1087,69 +1087,69 @@ class SessionKeeper // class Pinger extends Thread { - Pinger(AdminSessionPrx session, long period) - { - _session = session; - _period = period; - } - - public synchronized void run() - { - do - { - try - { - _session.keepAlive(); - } - catch(final Ice.LocalException e) - { - _done = true; - - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - sessionLost("Failed to contact the IceGrid registry: " - + e.toString()); - } - }); - } - - if(!_done) - { - try - { - wait(_period); - } - catch(InterruptedException e) - { - // Ignored - } - } - } while(!_done); - } - - public synchronized void done() - { - if(!_done) - { - _done = true; - notify(); - } - } - - private AdminSessionPrx _session; - private long _period; - private boolean _done = false; + Pinger(AdminSessionPrx session, long period) + { + _session = session; + _period = period; + } + + public synchronized void run() + { + do + { + try + { + _session.keepAlive(); + } + catch(final Ice.LocalException e) + { + _done = true; + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + sessionLost("Failed to contact the IceGrid registry: " + + e.toString()); + } + }); + } + + if(!_done) + { + try + { + wait(_period); + } + catch(InterruptedException e) + { + // Ignored + } + } + } while(!_done); + } + + public synchronized void done() + { + if(!_done) + { + _done = true; + notify(); + } + } + + private AdminSessionPrx _session; + private long _period; + private boolean _done = false; } SessionKeeper(Coordinator coordinator) { - _coordinator = coordinator; - _loginDialog = new LoginDialog(); - _loginPrefs = coordinator.getPrefs().node("Connection"); + _coordinator = coordinator; + _loginDialog = new LoginDialog(); + _loginPrefs = coordinator.getPrefs().node("Connection"); } // @@ -1157,133 +1157,133 @@ class SessionKeeper // void createSession() { - _loginInfo = new LoginInfo(_loginPrefs, _coordinator); - _loginDialog.showDialog(); + _loginInfo = new LoginInfo(_loginPrefs, _coordinator); + _loginDialog.showDialog(); } void relog(boolean showDialog) { - if(_loginInfo == null) - { - createSession(); - } - else - { - if(showDialog || !login(_coordinator.getMainFrame())) - { - _loginDialog.showDialog(); - } - } + if(_loginInfo == null) + { + createSession(); + } + else + { + if(showDialog || !login(_coordinator.getMainFrame())) + { + _loginDialog.showDialog(); + } + } } private boolean login(Component parent) { - if(_session != null) - { - logout(true); - } - assert _session == null; - - Cursor oldCursor = parent.getCursor(); - try - { - parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + if(_session != null) + { + logout(true); + } + assert _session == null; + + Cursor oldCursor = parent.getCursor(); + try + { + parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - Ice.LongHolder keepAlivePeriodHolder = new Ice.LongHolder(); - - AdminSessionPrx session = _coordinator.login( - _loginInfo, parent, keepAlivePeriodHolder); - if(session == null) - { - return false; - } - try - { - _replicaName = session.getReplicaName(); - } - catch(Ice.LocalException e) - { - logout(true); - JOptionPane.showMessageDialog( - parent, - "Could not retrieve replica name: " + e.toString(), - "Login failed", - JOptionPane.ERROR_MESSAGE); - return false; - } - - _coordinator.getStatusBar().setConnected(true); - - _connectedToMaster = _replicaName.equals("Master"); - if(_connectedToMaster) - { - _coordinator.getStatusBar().setText("Logged into Master Registry"); - } - else - { - _coordinator.getStatusBar().setText("Logged into Slave Registry '" + _replicaName + "'"); - } - - try - { - _session = new Session(session, keepAlivePeriodHolder.value, parent); - } - catch(Ice.LocalException e) - { - return false; - } - _loginInfo.save(); - } - finally - { - parent.setCursor(oldCursor); - } - return true; + Ice.LongHolder keepAlivePeriodHolder = new Ice.LongHolder(); + + AdminSessionPrx session = _coordinator.login( + _loginInfo, parent, keepAlivePeriodHolder); + if(session == null) + { + return false; + } + try + { + _replicaName = session.getReplicaName(); + } + catch(Ice.LocalException e) + { + logout(true); + JOptionPane.showMessageDialog( + parent, + "Could not retrieve replica name: " + e.toString(), + "Login failed", + JOptionPane.ERROR_MESSAGE); + return false; + } + + _coordinator.getStatusBar().setConnected(true); + + _connectedToMaster = _replicaName.equals("Master"); + if(_connectedToMaster) + { + _coordinator.getStatusBar().setText("Logged into Master Registry"); + } + else + { + _coordinator.getStatusBar().setText("Logged into Slave Registry '" + _replicaName + "'"); + } + + try + { + _session = new Session(session, keepAlivePeriodHolder.value, parent); + } + catch(Ice.LocalException e) + { + return false; + } + _loginInfo.save(); + } + finally + { + parent.setCursor(oldCursor); + } + return true; } void sessionLost(String message) { - JOptionPane.showMessageDialog( - _coordinator.getMainFrame(), - message, - "Session lost", - JOptionPane.ERROR_MESSAGE); - - logout(false); + JOptionPane.showMessageDialog( + _coordinator.getMainFrame(), + message, + "Session lost", + JOptionPane.ERROR_MESSAGE); + + logout(false); } void logout(boolean destroySession) { - if(_session != null) - { - _session.logout(destroySession); - _session = null; - } + if(_session != null) + { + _session.logout(destroySession); + _session = null; + } } AdminSessionPrx getSession() { - return _session == null ? null : _session.getSession(); + return _session == null ? null : _session.getSession(); } AdminPrx getAdmin() { - return _session == null ? null : _session.getAdmin(); + return _session == null ? null : _session.getAdmin(); } AdminPrx getRoutedAdmin() { - return _session == null ? null : _session.getRoutedAdmin(); + return _session == null ? null : _session.getRoutedAdmin(); } boolean connectedToMaster() { - return _session != null && _connectedToMaster; + return _session != null && _connectedToMaster; } String getReplicaName() { - return _replicaName; + return _replicaName; } private LoginDialog _loginDialog; diff --git a/java/src/IceGridGUI/SimpleInternalFrame.java b/java/src/IceGridGUI/SimpleInternalFrame.java index 8743464048c..9bd936bf37f 100755 --- a/java/src/IceGridGUI/SimpleInternalFrame.java +++ b/java/src/IceGridGUI/SimpleInternalFrame.java @@ -171,7 +171,7 @@ public class SimpleInternalFrame extends JPanel { } public JLabel getTitleLabel() { - return titleLabel; + return titleLabel; } @@ -290,12 +290,12 @@ public class SimpleInternalFrame extends JPanel { gradientPanel.setBorder(BorderFactory.createEmptyBorder(3, 4, 3, 1)); headerPanel = new JPanel(new BorderLayout()); - - Dimension prefSize = new Dimension(0, 24); - Dimension maxSize = new Dimension(Short.MAX_VALUE, 24); - headerPanel.setMinimumSize(prefSize); - headerPanel.setPreferredSize(prefSize); - headerPanel.setMaximumSize(maxSize); + + Dimension prefSize = new Dimension(0, 24); + Dimension maxSize = new Dimension(Short.MAX_VALUE, 24); + headerPanel.setMinimumSize(prefSize); + headerPanel.setPreferredSize(prefSize); + headerPanel.setMaximumSize(maxSize); headerPanel.add(gradientPanel, BorderLayout.CENTER); setToolBar(bar); diff --git a/java/src/IceGridGUI/TreeNodeBase.java b/java/src/IceGridGUI/TreeNodeBase.java index ef064f03aa2..c25becaadcd 100755 --- a/java/src/IceGridGUI/TreeNodeBase.java +++ b/java/src/IceGridGUI/TreeNodeBase.java @@ -25,326 +25,326 @@ public class TreeNodeBase implements javax.swing.tree.TreeNode, TreeCellRenderer { public Coordinator getCoordinator() { - return _parent.getCoordinator(); + return _parent.getCoordinator(); } public Enumeration children() { - return new Enumeration() - { - public boolean hasMoreElements() - { - return false; - } + return new Enumeration() + { + public boolean hasMoreElements() + { + return false; + } - public Object nextElement() - { - throw new java.util.NoSuchElementException(); - } - }; + public Object nextElement() + { + throw new java.util.NoSuchElementException(); + } + }; } public boolean getAllowsChildren() { - return false; + return false; } public javax.swing.tree.TreeNode getChildAt(int childIndex) { - return null; + return null; } public int getChildCount() { - return 0; + return 0; } public int getIndex(javax.swing.tree.TreeNode node) { - return -1; + return -1; } public javax.swing.tree.TreeNode getParent() { - return _parent; + return _parent; } public boolean isLeaf() { - return true; + return true; } public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { - return null; + return null; } public String toString() { - return _id; + return _id; } public JPopupMenu getPopupMenu() { - return null; + return null; } public String getId() { - return _id; + return _id; } public TreePath getPath() { - if(_parent == null) - { - return new TreePath(this); - } - else - { - return _parent.getPath().pathByAddingChild(this); - } + 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(); + java.util.LinkedList result = _parent == null ? + new java.util.LinkedList() : + _parent.getFullId(); - result.add(_id); - return result; + 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; + Enumeration p = children(); + while(p.hasMoreElements()) + { + TreeNodeBase child = (TreeNodeBase)p.nextElement(); + if(child.getId().equals(id)) + { + return child; + } + } + return null; } protected String makeNewChildId(String base) { - String id = base; - int i = 0; - while(findChild(id) != null) - { - id = base + "-" + (++i); - } - return id; + String id = base; + int i = 0; + while(findChild(id) != null) + { + id = base + "-" + (++i); + } + return id; } protected TreeNodeBase(TreeNodeBase parent, String id) { - _parent = parent; - _id = id; + _parent = parent; + _id = id; } // // Helper functions // protected boolean insertSortedChild(TreeNodeBase newChild, java.util.List children, - DefaultTreeModel treeModel) + 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); + 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(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; + if(treeModel != null) + { + treeModel.nodesWereInserted(this, new int[]{getIndex(newChild)}); + } + return true; } protected String insertSortedChildren(java.util.List newChildren, - java.util.List intoChildren, - DefaultTreeModel treeModel) + java.util.List intoChildren, + DefaultTreeModel treeModel) { - TreeNodeBase[] children = (TreeNodeBase[])newChildren.toArray(new TreeNodeBase[0]); - java.util.Arrays.sort(children, _childComparator); - - int[] indices = new int[children.length]; + TreeNodeBase[] children = (TreeNodeBase[])newChildren.toArray(new TreeNodeBase[0]); + java.util.Arrays.sort(children, _childComparator); + + int[] indices = new int[children.length]; - int offset = -1; + int offset = -1; - int i = 0; - boolean checkInsert = true; - for(int j = 0; j < children.length; ++j) - { - String id = children[j].getId(); - - if(checkInsert) - { - while(i < intoChildren.size()) - { - TreeNodeBase existingChild = (TreeNodeBase)intoChildren.get(i); - int cmp = id.compareTo(existingChild.getId()); - if(cmp == 0) - { - return id; - } - if(cmp < 0) - { - break; // while - } - i++; - } - - if(i < intoChildren.size()) - { - // Insert here, and increment i (since children is sorted) - intoChildren.add(i, children[j]); - if(offset == -1) - { - offset = getIndex((TreeNodeBase)intoChildren.get(0)); - } + int i = 0; + boolean checkInsert = true; + for(int j = 0; j < children.length; ++j) + { + String id = children[j].getId(); + + if(checkInsert) + { + while(i < intoChildren.size()) + { + TreeNodeBase existingChild = (TreeNodeBase)intoChildren.get(i); + int cmp = id.compareTo(existingChild.getId()); + if(cmp == 0) + { + return id; + } + if(cmp < 0) + { + break; // while + } + i++; + } + + if(i < intoChildren.size()) + { + // Insert here, and increment i (since children is sorted) + intoChildren.add(i, children[j]); + if(offset == -1) + { + offset = getIndex((TreeNodeBase)intoChildren.get(0)); + } - indices[j] = offset + i; - i++; continue; // for - } - else - { - checkInsert = false; - } - } - - // - // Append - // - intoChildren.add(children[j]); - if(offset == -1) - { - offset = getIndex((TreeNodeBase)intoChildren.get(0)); - } - indices[j] = offset + i; - i++; - } - - if(treeModel != null) - { - treeModel.nodesWereInserted(this, indices); - } - - return null; + indices[j] = offset + i; + i++; continue; // for + } + else + { + checkInsert = false; + } + } + + // + // Append + // + intoChildren.add(children[j]); + if(offset == -1) + { + offset = getIndex((TreeNodeBase)intoChildren.get(0)); + } + indices[j] = offset + i; + i++; + } + + if(treeModel != null) + { + treeModel.nodesWereInserted(this, indices); + } + + return null; } protected void removeSortedChildren(String[] childIds, - java.util.List fromChildren, - DefaultTreeModel treeModel) + java.util.List fromChildren, + DefaultTreeModel treeModel) { - if(childIds.length == 0) - { - return; // nothing to do - } - assert fromChildren.size() > 0; + 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(); + 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); + 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); - } + 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); + 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; + 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; + 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()); - } - }; + { + 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/IceGridGUI/Utils.java b/java/src/IceGridGUI/Utils.java index e8253b87f08..4a4310c61f6 100755 --- a/java/src/IceGridGUI/Utils.java +++ b/java/src/IceGridGUI/Utils.java @@ -15,382 +15,382 @@ public class Utils { static public ImageIcon getIcon(String path) { - java.net.URL imgURL = Utils.class.getResource(path); - if(imgURL == null) - { - System.err.println("Could not find icon " + path); - return null; - } - else - { - return new ImageIcon(imgURL); - } + java.net.URL imgURL = Utils.class.getResource(path); + if(imgURL == null) + { + System.err.println("Could not find icon " + path); + return null; + } + else + { + return new ImageIcon(imgURL); + } } static public interface Stringifier { - public String toString(Object obj); + public String toString(Object obj); } // // Stringify helpers // static public String stringify(java.util.Collection col, - Stringifier stringifier, - String separator, - Ice.StringHolder toolTipHolder) + Stringifier stringifier, + String separator, + Ice.StringHolder toolTipHolder) { - String result = ""; - if(toolTipHolder != null) - { - toolTipHolder.value = null; - } + String result = ""; + if(toolTipHolder != null) + { + toolTipHolder.value = null; + } - java.util.Iterator p = col.iterator(); - - boolean firstElement = true; - while(p.hasNext()) - { - String elt = stringifier.toString(p.next()); - if(elt != null) - { - if(firstElement) - { - firstElement = false; - if(toolTipHolder != null) - { - toolTipHolder.value = "<html>"; - } - } - else - { - result += separator; - if(toolTipHolder != null) - { - toolTipHolder.value += "<br>"; - } - } - - if(elt.length() == 0) - { - result += "\"\""; - } - else if(elt.matches("\\S*")) - { - // - // Only non-whitespace characters - // - result += elt; - } - else - { - result += '"' + elt + '"'; - } + java.util.Iterator p = col.iterator(); + + boolean firstElement = true; + while(p.hasNext()) + { + String elt = stringifier.toString(p.next()); + if(elt != null) + { + if(firstElement) + { + firstElement = false; + if(toolTipHolder != null) + { + toolTipHolder.value = "<html>"; + } + } + else + { + result += separator; + if(toolTipHolder != null) + { + toolTipHolder.value += "<br>"; + } + } + + if(elt.length() == 0) + { + result += "\"\""; + } + else if(elt.matches("\\S*")) + { + // + // Only non-whitespace characters + // + result += elt; + } + else + { + result += '"' + elt + '"'; + } - if(toolTipHolder != null) - { - toolTipHolder.value += elt; - } - } - } - if(toolTipHolder != null && toolTipHolder.value != null) - { - toolTipHolder.value += "</html>"; - } - - return result; + if(toolTipHolder != null) + { + toolTipHolder.value += elt; + } + } + } + if(toolTipHolder != null && toolTipHolder.value != null) + { + toolTipHolder.value += "</html>"; + } + + return result; } static public String stringify(java.util.Collection col, - String separator, - Ice.StringHolder toolTipHolder) + String separator, + Ice.StringHolder toolTipHolder) { - - Stringifier stringifier = new Stringifier() - { - public String toString(Object obj) - { - return (String)obj; - } - }; - return stringify(col, stringifier, separator, toolTipHolder); + + Stringifier stringifier = new Stringifier() + { + public String toString(Object obj) + { + return (String)obj; + } + }; + return stringify(col, stringifier, separator, toolTipHolder); } static public String stringify(String[] stringSeq, String separator, - Ice.StringHolder toolTipHolder) + Ice.StringHolder toolTipHolder) { - return stringify(java.util.Arrays.asList(stringSeq), separator, toolTipHolder); + return stringify(java.util.Arrays.asList(stringSeq), separator, toolTipHolder); } static public String stringify(java.util.Map stringMap, - final String pairSeparator, - String separator, - Ice.StringHolder toolTipHolder) + final String pairSeparator, + String separator, + Ice.StringHolder toolTipHolder) { - Stringifier stringifier = new Stringifier() - { - public String toString(Object obj) - { - java.util.Map.Entry entry = (java.util.Map.Entry)obj; - return (String)entry.getKey() + pairSeparator + (String)entry.getValue(); - } - }; + Stringifier stringifier = new Stringifier() + { + public String toString(Object obj) + { + java.util.Map.Entry entry = (java.util.Map.Entry)obj; + return (String)entry.getKey() + pairSeparator + (String)entry.getValue(); + } + }; - return stringify(stringMap.entrySet(), stringifier, separator, toolTipHolder); + return stringify(stringMap.entrySet(), stringifier, separator, toolTipHolder); } static public class Resolver { - // - // Application-level resolver - // - public Resolver(java.util.Map variables) - { - this(new java.util.Map[]{variables}); - } + // + // Application-level resolver + // + public Resolver(java.util.Map variables) + { + this(new java.util.Map[]{variables}); + } - public Resolver(java.util.Map[] variables) - { - _variables = variables; - _predefinedVariables = new java.util.HashMap(); - - _parameters = null; - _subResolver = this; - } + public Resolver(java.util.Map[] variables) + { + _variables = variables; + _predefinedVariables = new java.util.HashMap(); + + _parameters = null; + _subResolver = this; + } - // - // Resolver for instance; in-parameters are not yet substituted - // - public Resolver(Resolver parent, java.util.Map parameters, - java.util.Map defaults) - { - _variables = parent._variables; + // + // Resolver for instance; in-parameters are not yet substituted + // + public Resolver(Resolver parent, java.util.Map parameters, + java.util.Map defaults) + { + _variables = parent._variables; - // - // Whenever the parent's predefined variables change, the resolver - // must be recreated - // - reset(parent, parameters, defaults); - } - - // - // Resolver for plain server or service - // - public Resolver(Resolver parent) - { - _variables = parent._variables; - _predefinedVariables = new java.util.HashMap(parent._predefinedVariables); - _parameters = parent._parameters; - if(_parameters == null) - { - _subResolver = this; - } - else - { - _subResolver = new Resolver(_variables, _predefinedVariables); - } - } + // + // Whenever the parent's predefined variables change, the resolver + // must be recreated + // + reset(parent, parameters, defaults); + } + + // + // Resolver for plain server or service + // + public Resolver(Resolver parent) + { + _variables = parent._variables; + _predefinedVariables = new java.util.HashMap(parent._predefinedVariables); + _parameters = parent._parameters; + if(_parameters == null) + { + _subResolver = this; + } + else + { + _subResolver = new Resolver(_variables, _predefinedVariables); + } + } - private Resolver(java.util.Map[] variables, - java.util.Map predefinedVariables) - { - _variables = variables; - _predefinedVariables = _predefinedVariables; + private Resolver(java.util.Map[] variables, + java.util.Map predefinedVariables) + { + _variables = variables; + _predefinedVariables = _predefinedVariables; - _parameters = null; - _subResolver = this; - } + _parameters = null; + _subResolver = this; + } - public String find(String name) - { - if(_parameters != null) - { - Object obj = _parameters.get(name); - if(obj != null) - { - return (String)obj; - } - } + public String find(String name) + { + if(_parameters != null) + { + Object obj = _parameters.get(name); + if(obj != null) + { + return (String)obj; + } + } - Object obj = _predefinedVariables.get(name); - if(obj != null) - { - return (String)obj; - } - - for(int i = 0; i < _variables.length; ++i) - { - obj = _variables[i].get(name); - if(obj != null) - { - return _subResolver.substitute((String)obj); - } - } - return null; - } + Object obj = _predefinedVariables.get(name); + if(obj != null) + { + return (String)obj; + } + + for(int i = 0; i < _variables.length; ++i) + { + obj = _variables[i].get(name); + if(obj != null) + { + return _subResolver.substitute((String)obj); + } + } + return null; + } - // - // Set a pre-defined variable; returns true if value was updated - // - public boolean put(String name, String value) - { - String oldVal = (String)_predefinedVariables.get(name); - if(oldVal == null || !oldVal.equals(value)) - { - _predefinedVariables.put(name, value); - return true; - } - else - { - return false; - } - } + // + // Set a pre-defined variable; returns true if value was updated + // + public boolean put(String name, String value) + { + String oldVal = (String)_predefinedVariables.get(name); + if(oldVal == null || !oldVal.equals(value)) + { + _predefinedVariables.put(name, value); + return true; + } + else + { + return false; + } + } - // - // 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); - } + // + // 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); + } - public void reset(Resolver parent) - { - assert _variables == parent._variables; - _predefinedVariables = new java.util.HashMap(parent._predefinedVariables); - - assert _parameters == parent._parameters; - if(_parameters == null) - { - _subResolver = this; - } - else - { - _subResolver = new Resolver(_variables, _predefinedVariables); - } - } + public void reset(Resolver parent) + { + assert _variables == parent._variables; + _predefinedVariables = new java.util.HashMap(parent._predefinedVariables); + + assert _parameters == parent._parameters; + if(_parameters == null) + { + _subResolver = this; + } + else + { + _subResolver = new Resolver(_variables, _predefinedVariables); + } + } - // - // The sorted substituted parameters - // - public java.util.Map getParameters() - { - return _parameters; - } + // + // The sorted substituted parameters + // + public java.util.Map getParameters() + { + return _parameters; + } - public String substitute(String input) - { - if(input == null) - { - return input; - } + public String substitute(String input) + { + if(input == 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 substitute anything else - // - return input; - } - - String name = input.substring(beg + 2, end); - - // - // Resolve name - // - String val = find(name); - 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; - } + 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 substitute anything else + // + return input; + } + + String name = input.substring(beg + 2, end); + + // + // Resolve name + // + String val = find(name); + 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; + } - // - // Substitute all the values from the input map - // - public java.util.Map substituteParameterValues(java.util.Map input, - java.util.Map defaults) - { - 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(), substitute((String)entry.getValue())); - } - p = defaults.entrySet().iterator(); - while(p.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - if(!result.containsKey(entry.getKey())) - { - result.put(entry.getKey(), substitute((String)entry.getValue())); - } - } - return result; - } + // + // Substitute all the values from the input map + // + public java.util.Map substituteParameterValues(java.util.Map input, + java.util.Map defaults) + { + 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(), substitute((String)entry.getValue())); + } + p = defaults.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + if(!result.containsKey(entry.getKey())) + { + result.put(entry.getKey(), substitute((String)entry.getValue())); + } + } + return result; + } - private java.util.Map[] _variables; - private java.util.Map _parameters; - private java.util.Map _predefinedVariables; + private java.util.Map[] _variables; + private java.util.Map _parameters; + private java.util.Map _predefinedVariables; - private Resolver _subResolver; + private Resolver _subResolver; } static public String substitute(String input, Resolver resolver) { - if(resolver != null) - { - return resolver.substitute(input); - } - else - { - return input; - } + if(resolver != null) + { + return resolver.substitute(input); + } + else + { + return input; + } } // @@ -398,52 +398,52 @@ public class Utils // static public class ExpandedPropertySet { - public ExpandedPropertySet[] references; - public java.util.List properties; // list of PropertyDescriptor + public ExpandedPropertySet[] references; + public java.util.List properties; // list of PropertyDescriptor } static public java.util.SortedMap propertySetsToMap( - java.util.List propertySets, - Resolver resolver) + java.util.List propertySets, + Resolver resolver) { - java.util.SortedMap toMap = new java.util.TreeMap(); - java.util.Iterator p = propertySets.iterator(); - while(p.hasNext()) - { - ExpandedPropertySet propertySet = (ExpandedPropertySet)p.next(); - addSet(propertySet, resolver, toMap); - } - return toMap; + java.util.SortedMap toMap = new java.util.TreeMap(); + java.util.Iterator p = propertySets.iterator(); + while(p.hasNext()) + { + ExpandedPropertySet propertySet = (ExpandedPropertySet)p.next(); + addSet(propertySet, resolver, toMap); + } + return toMap; } static public java.util.SortedMap propertySetToMap( - ExpandedPropertySet propertySet, - Resolver resolver) + ExpandedPropertySet propertySet, + Resolver resolver) { - java.util.List list = new java.util.LinkedList(); - list.add(propertySet); - return propertySetsToMap(list, resolver); + java.util.List list = new java.util.LinkedList(); + list.add(propertySet); + return propertySetsToMap(list, resolver); } static private void addSet(ExpandedPropertySet set, Resolver resolver, - java.util.SortedMap toMap) + java.util.SortedMap toMap) { - for(int i = 0; i < set.references.length; ++i) - { - addSet(set.references[i], resolver, toMap); - } - - java.util.Iterator p = set.properties.iterator(); - while(p.hasNext()) - { - PropertyDescriptor pd = (PropertyDescriptor)p.next(); - String name = (String)pd.name; - String val = (String)pd.value; - - name = substitute(pd.name, resolver); - val = substitute(pd.value, resolver); - - toMap.put(name, val); - } + for(int i = 0; i < set.references.length; ++i) + { + addSet(set.references[i], resolver, toMap); + } + + java.util.Iterator p = set.properties.iterator(); + while(p.hasNext()) + { + PropertyDescriptor pd = (PropertyDescriptor)p.next(); + String name = (String)pd.name; + String val = (String)pd.value; + + name = substitute(pd.name, resolver); + val = substitute(pd.value, resolver); + + toMap.put(name, val); + } } } diff --git a/java/src/IceGridGUI/XMLWriter.java b/java/src/IceGridGUI/XMLWriter.java index 64226e5ad35..bdcbc3df416 100755 --- a/java/src/IceGridGUI/XMLWriter.java +++ b/java/src/IceGridGUI/XMLWriter.java @@ -17,98 +17,98 @@ 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); + 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 + throws IOException { - _writer.write(_indent); - _writer.write("<" + name); - writeAttributes(attributes); - _writer.write("/>" + _newline); + _writer.write(_indent); + _writer.write("<" + name); + writeAttributes(attributes); + _writer.write("/>" + _newline); } public void writeElement(String name) throws IOException { - writeElement(name, (java.util.List)null); + writeElement(name, (java.util.List)null); } public void writeElement(String name, String content) throws IOException { - _writer.write(_indent); - _writer.write("<" + name + ">" + escape(content) + - "</" + name + ">" + _newline); + _writer.write(_indent); + _writer.write("<" + name + ">" + escape(content) + + "</" + name + ">" + _newline); } public void writeStartTag(String name, java.util.List attributes) - throws IOException + throws IOException { - _writer.write(_indent); - _writer.write("<" + name); - writeAttributes(attributes); - _writer.write(">"); - _writer.write(_newline); - increaseIndent(); + _writer.write(_indent); + _writer.write("<" + name); + writeAttributes(attributes); + _writer.write(">"); + _writer.write(_newline); + increaseIndent(); } public void writeStartTag(String name) throws IOException { - writeStartTag(name, null); + writeStartTag(name, null); } public void writeEndTag(String name) throws IOException { - decreaseIndent(); - _writer.write(_indent); - _writer.write("</" + name + ">" + _newline); + decreaseIndent(); + _writer.write(_indent); + _writer.write("</" + name + ">" + _newline); } public void close() throws IOException { - _writer.close(); + _writer.close(); } public void flush() throws IOException { - _writer.flush(); + _writer.flush(); } private void writeAttributes(java.util.List attributes) - throws IOException + 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] + "\""); - } - } + 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 += " "; + _indent += " "; } private void decreaseIndent() { - if(_indent.length() > 0) - { - _indent = _indent.substring(3); - } + if(_indent.length() > 0) + { + _indent = _indent.substring(3); + } } private String |