1 19 20 package org.netbeans.modules.j2ee.deployment.impl.ui; 21 22 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 23 import org.netbeans.modules.j2ee.deployment.impl.ServerTarget; 24 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 25 import org.openide.nodes.Node; 26 import java.util.List ; 27 import java.util.Arrays ; 28 import java.util.ArrayList ; 29 import java.util.Collections ; 30 import org.openide.nodes.AbstractNode; 31 import org.openide.nodes.Children; 32 import org.openide.util.NbBundle; 33 import org.openide.util.RequestProcessor; 34 35 36 42 public class InstanceTargetXNode extends FilterXNode implements ServerInstance.StateListener { 43 44 private ServerTarget instanceTarget; 45 private ServerInstance instance; 46 private InstanceProperties instanceProperties; 47 private InstanceTargetChildren instanceTargetChildren; 48 49 public InstanceTargetXNode(Node instanceNode, ServerInstance instance) { 50 this(instanceNode, Node.EMPTY, new InstanceTargetChildren(Node.EMPTY)); 51 this.instance = instance; 52 instanceProperties = instance.getInstanceProperties(); 53 instance.addStateListener(this); 54 } 55 56 private InstanceTargetXNode(Node instanceNode, Node xnode, InstanceTargetChildren instanceTargetChildren) { 57 super(instanceNode, xnode, true, instanceTargetChildren); 58 this.instanceTargetChildren = instanceTargetChildren; 59 } 60 61 private ServerTarget getServerTarget() { 62 if (instanceTarget != null) { 63 return instanceTarget; 64 } 65 instanceTarget = instance.getCoTarget(); 66 return instanceTarget; 67 } 68 69 public Node getDelegateTargetNode() { 70 if (xnode != null && xnode != Node.EMPTY) 71 return xnode; 72 ServerTarget st = getServerTarget(); 73 if (st == null) 74 return xnode; 75 Node tn = instance.getServer().getNodeProvider().createTargetNode(st); 76 if (tn != null) 77 xnode = tn; 78 return xnode; 79 } 80 81 private void resetDelegateTargetNode() { 82 xnode = null; 83 } 84 85 public javax.swing.Action [] getActions(boolean context) { 86 List actions = new ArrayList (); 87 actions.addAll(Arrays.asList(getOriginal().getActions(context))); 88 90 if (getServerTarget() != null) { 91 actions.addAll(Arrays.asList(getDelegateTargetNode().getActions(context))); 92 } 93 94 return (javax.swing.Action []) actions.toArray(new javax.swing.Action [actions.size()]); 95 } 96 97 public PropertySet[] getPropertySets() { 98 Node delegateNode = getDelegateTargetNode(); 99 if (delegateNode == null) 100 return getOriginal().getPropertySets(); 101 return FilterXNode.merge(getOriginal().getPropertySets(), delegateNode.getPropertySets()); 102 } 103 104 public org.openide.nodes.Node.Cookie getCookie(Class type) { 105 Node tn = getDelegateTargetNode(); 106 org.openide.nodes.Node.Cookie c = null; 107 if (tn != null) 108 c = tn.getCookie(type); 109 if (c == null) 110 c = super.getCookie(type); 111 return c; 112 } 113 114 116 public void stateChanged(int oldState, int newState) { 117 if (newState == ServerInstance.STATE_RUNNING || newState == ServerInstance.STATE_DEBUGGING 118 || newState == ServerInstance.STATE_PROFILING) { 119 if (oldState == ServerInstance.STATE_SUSPENDED) { 120 instanceTargetChildren.showLastNodes(); 123 getChildren().getNodes(true); } else { 125 instanceTarget = null; 126 resetDelegateTargetNode(); 127 instanceTargetChildren.hideNodes(); 128 setChildren(instanceTargetChildren); 129 instanceTargetChildren.updateNodes(this); 130 getChildren().getNodes(true); } 132 } else { 133 instanceTargetChildren.hideNodes(); 134 } 135 } 136 137 public static class InstanceTargetChildren extends Children { 138 139 private ServerTarget target; 140 private Node lastDelegateTargetNode; 141 142 public InstanceTargetChildren(Node original) { 143 super(original); 144 } 145 146 public void updateNodes(final InstanceTargetXNode parent) { 147 if (isFurtherExpandable()) { 148 if (original == Node.EMPTY) { 149 changeOriginal(createWaitNode()); 150 RequestProcessor.getDefault().post(new Runnable () { 151 public void run() { 152 Node newOriginal = null; 153 if (parent != null) { 154 newOriginal = parent.getDelegateTargetNode(); 155 lastDelegateTargetNode = newOriginal; 156 } 157 if (newOriginal != null) { 158 changeOriginal(newOriginal); 159 } else { 160 changeOriginal(Node.EMPTY); 161 } 162 } 163 }); 164 } 165 } else { 166 changeOriginal(Node.EMPTY); 167 } 168 } 169 170 public void hideNodes() { 171 changeOriginal(Node.EMPTY); 172 } 173 174 public void showLastNodes() { 175 Node node = lastDelegateTargetNode; 176 if (node != null) { 177 changeOriginal(node); 178 } 179 } 180 181 private Node createWaitNode() { 182 AbstractNode node = new AbstractNode(Children.LEAF); 183 node.setName(NbBundle.getMessage(InstanceTargetXNode.class, "LBL_WaitNode_DisplayName")); 184 node.setIconBaseWithExtension("org/netbeans/modules/j2ee/deployment/impl/ui/resources/wait.gif"); 186 Children.Array children = new Children.Array(); 187 children.add(new Node[]{node}); 188 return new AbstractNode(children); 189 } 190 191 private boolean isFurtherExpandable() { 192 ServerRegistryNode root = ServerRegistryNode.getServerRegistryNode(); 193 if (root != null) { 194 return root.isExpandablePassTargetNode(); 195 } 196 return true; 197 } 198 } 199 } 200 | Popular Tags |