KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ui > InstanceNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.deployment.impl.ui;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JFrame JavaDoc;
25 import javax.swing.SwingUtilities JavaDoc;
26 import org.openide.nodes.*;
27 import org.openide.util.HelpCtx;
28 import org.netbeans.modules.j2ee.deployment.impl.*;
29 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*;
30 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
31
32 import org.openide.windows.WindowManager;
33
34 import org.openide.util.RequestProcessor;
35 import org.openide.util.Utilities;
36
37
38
39 /**
40  * Instance node is a base for any manager node. The behaviour of this base instance
41  * node can be customized/extended by the manager node provided by the plugin.
42  *
43  * @author George FinKlang
44  */

45 public class InstanceNode extends AbstractNode implements ServerInstance.StateListener {
46     
47     private static int cursorChangeCounter = 0;
48     
49     protected ServerInstance instance;
50     
51     private boolean running;
52     
53     public InstanceNode(ServerInstance instance, boolean addStateListener) {
54         super(new InstanceChildren(instance));
55         this.instance = instance;
56         setIconBase(instance.getServer().getIconBase());
57         getCookieSet().add(instance);
58         if (addStateListener) {
59             instance.addStateListener(this);
60         }
61     }
62     
63     public HelpCtx getHelpCtx() {
64         return HelpCtx.DEFAULT_HELP;
65     }
66     
67     public org.openide.nodes.Node.Cookie getCookie(Class JavaDoc type) {
68         if (ServerInstance.class.isAssignableFrom(type)) {
69             return instance;
70         }
71         return super.getCookie(type);
72     }
73     
74     // StateListener implementation -------------------------------------------
75

76     public void stateChanged(int oldState, int newState) {
77         if (instance.getServerState() != ServerInstance.STATE_WAITING
78             && instance.getServerState() != ServerInstance.STATE_SUSPENDED) {
79             setChildren(new InstanceChildren(instance));
80             getChildren().getNodes(true);
81         } else if (instance.getServerState() == ServerInstance.STATE_SUSPENDED) {
82             setChildren(Children.LEAF);
83         }
84     }
85     
86      public static class InstanceChildren extends Children.Keys {
87         ServerInstance serverInstance;
88         public InstanceChildren(ServerInstance inst) {
89             this.serverInstance = inst;
90         }
91         protected void addNotify() {
92             setKeys(serverInstance.getTargets());
93         }
94         protected void removeNotify() {
95             setKeys(java.util.Collections.EMPTY_SET);
96         }
97         protected org.openide.nodes.Node[] createNodes(Object JavaDoc obj) {
98             ServerTarget child = (ServerTarget) obj;
99             //return new Node[] { new TargetBaseNode(org.openide.nodes.Children.LEAF, child) };
100
return new Node[] { serverInstance.getServer().
101                                  getNodeProvider().createTargetNode(child) };
102         }
103     }
104     
105 }
106
Popular Tags