summaryrefslogtreecommitdiff
path: root/java/src/IceGridGUI/Application/PlainService.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2006-05-08 20:55:38 +0000
committerBernard Normier <bernard@zeroc.com>2006-05-08 20:55:38 +0000
commit8ff9dd62a9241109b599896c1f06516009275fe0 (patch)
treed397a64aa0bb37b2496d7fa7d0b484da9d7fa73e /java/src/IceGridGUI/Application/PlainService.java
parentFix (diff)
downloadice-8ff9dd62a9241109b599896c1f06516009275fe0.tar.bz2
ice-8ff9dd62a9241109b599896c1f06516009275fe0.tar.xz
ice-8ff9dd62a9241109b599896c1f06516009275fe0.zip
Simplified Application view; fixed PropertySets issues
Diffstat (limited to 'java/src/IceGridGUI/Application/PlainService.java')
-rwxr-xr-xjava/src/IceGridGUI/Application/PlainService.java316
1 files changed, 316 insertions, 0 deletions
diff --git a/java/src/IceGridGUI/Application/PlainService.java b/java/src/IceGridGUI/Application/PlainService.java
new file mode 100755
index 00000000000..c350fa4d9e1
--- /dev/null
+++ b/java/src/IceGridGUI/Application/PlainService.java
@@ -0,0 +1,316 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.Component;
+import javax.swing.JPopupMenu;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class 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;
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus)
+ {
+ if(_cellRenderer == null)
+ {
+ _cellRenderer = new DefaultTreeCellRenderer();
+ _cellRenderer.setOpenIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+
+ _cellRenderer.setClosedIcon(
+ Utils.getIcon("/icons/16x16/service.png"));
+ }
+
+ return _cellRenderer.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+
+ //
+ // Actions
+ //
+ public boolean[] getAvailableActions()
+ {
+ boolean[] actions = new boolean[ACTION_COUNT];
+ actions[COPY] = true;
+
+ if(((TreeNode)_parent).getAvailableActions()[PASTE])
+ {
+ actions[PASTE] = true;
+ }
+
+ 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;
+ }
+ public void copy()
+ {
+ getCoordinator().setClipboard(ServiceInstance.copyDescriptor(_descriptor));
+ getCoordinator().getActionsForMenu().get(PASTE).setEnabled(true);
+ }
+
+ public void moveUp()
+ {
+ move(true);
+ }
+ public void moveDown()
+ {
+ move(false);
+ }
+
+ public Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ public Object saveDescriptor()
+ {
+ return _descriptor.clone();
+ }
+
+ public void restoreDescriptor(Object 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;
+ }
+
+ public void destroy()
+ {
+ ((Communicator)_parent).getServices().destroyChild(this);
+ }
+
+ public Editor getEditor()
+ {
+ if(_editor == null)
+ {
+ _editor = (PlainServiceEditor)getRoot().getEditor(PlainServiceEditor.class, this);
+ }
+ _editor.show(this);
+ return _editor;
+ }
+
+ protected Editor createEditor()
+ {
+ return new PlainServiceEditor(getCoordinator().getMainFrame());
+ }
+
+ Editable getEnclosingEditable()
+ {
+ return ((Communicator)_parent).getEnclosingEditable();
+ }
+
+ private boolean canMove(boolean up)
+ {
+ if(_ephemeral)
+ {
+ return false;
+ }
+ else
+ {
+ return ((Communicator)_parent).getServices().canMove(this, up);
+ }
+ }
+
+ private void move(boolean up)
+ {
+ assert canMove(up);
+ ((Communicator)_parent).getServices().move(this, up);
+ }
+
+
+ java.util.List findInstances(boolean includeTemplate)
+ {
+ java.util.List result = new java.util.LinkedList();
+
+ //
+ // First find all instances of the enclosing Communicator, including
+ // the ServerTemplate itself (if that's my parent)
+ //
+ java.util.List communicatorList = ((Communicator)_parent).findInstances(true);
+
+ java.util.Iterator p = communicatorList.iterator();
+ while(p.hasNext())
+ {
+ Services services = ((Communicator)p.next()).getServices();
+ Service service = (Service)services.findChildWithDescriptor(_descriptor);
+ assert service != null;
+ result.add(service);
+ }
+ return result;
+ }
+
+ public Object rebuild(java.util.List editables)
+ 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;
+ }
+
+ public void restore(Object backupObj)
+ {
+ 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;
+ }
+
+ PlainService(Communicator parent,
+ String name,
+ ServiceInstanceDescriptor descriptor,
+ Utils.Resolver resolver)
+ throws UpdateFailedException
+ {
+ super(parent, name);
+ _descriptor = descriptor;
+ _ephemeral = false;
+ _resolver = resolver;
+
+ _adapters.init(_descriptor.descriptor.adapters);
+ _dbEnvs.init(_descriptor.descriptor.dbEnvs);
+ }
+
+ //
+ // New temporary object
+ //
+ PlainService(Communicator parent, ServiceInstanceDescriptor descriptor)
+ {
+ 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;
+ }
+
+ 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);
+ _adapters.write(writer);
+ _dbEnvs.write(writer);
+ writer.writeEndTag("service");
+ }
+ }
+
+ CommunicatorDescriptor getCommunicatorDescriptor()
+ {
+ return _descriptor.descriptor;
+ }
+
+ Utils.Resolver getResolver()
+ {
+ return _resolver;
+ }
+
+ public boolean isEphemeral()
+ {
+ return _ephemeral;
+ }
+
+ private ServiceInstanceDescriptor _descriptor;
+
+ private final boolean _ephemeral;
+
+ private Utils.Resolver _resolver;
+ private PlainServiceEditor _editor;
+
+ static private DefaultTreeCellRenderer _cellRenderer;
+ static private JPopupMenu _popup;
+}