KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > apis > AppserverMgmtContainerNode


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 package org.netbeans.modules.j2ee.sun.bridge.apis;
20
21 import java.util.logging.Level JavaDoc;
22
23 import javax.swing.Action JavaDoc;
24 import org.netbeans.modules.j2ee.sun.util.ContainerChildFactory;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.Node;
28 import org.openide.util.RequestProcessor;
29 import org.openide.util.actions.SystemAction;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  *
35  *
36  */

37 public class AppserverMgmtContainerNode extends AppserverMgmtNode implements RefreshCookie {
38
39         public static final class WaitNode extends AbstractNode {
40         public WaitNode() {
41             super(Children.LEAF);
42             setIconBase("org/netbeans/modules/java/navigation/resources/wait"); // NOI18N
43
setDisplayName(NbBundle.getMessage(AppserverMgmtContainerNode.class,"WAITNODE")); //NOI18N
44
setName(getClass().getName());
45         }
46     } // End of WaitNode class
47

48     /**
49      *
50      */

51     public AppserverMgmtContainerNode(final AppserverMgmtController controller, final String JavaDoc type) {
52         super(controller, getChildren(controller, type), type);
53     }
54     /**
55      *
56      *
57      */

58     public AppserverMgmtContainerNode(final AppserverMgmtController controller, final Children children, final String JavaDoc nodeType) {
59         super(controller, children, nodeType);
60
61     }
62     
63     /**
64      * Return the actions associated with the menu drop down seen when
65      * a user right-clicks on an Applications node in the plugin.
66      *
67      * @param boolean true/false
68      * @return An array of Action objects.
69      */

70     public Action JavaDoc[] getActions(boolean flag) {
71         return new SystemAction[] {
72             SystemAction.get(RefreshAction.class)
73         };
74     }
75
76     /**
77      *
78      */

79     static Children getChildren(final AppserverMgmtController controller, final String JavaDoc type){
80         return new ContainerChildren(controller, type);
81     }
82
83     
84     /**
85      *
86      *
87      */

88     public void refresh(){
89         setChildren(new ContainerChildren(getAppserverMgmtController(), getNodeType()));
90         ContainerChildren ch = (ContainerChildren)getChildren();
91         ch.updateKeys();
92     }
93
94     
95     /**
96      *
97      *
98      */

99     public static class ContainerChildren extends Children.Keys {
100         String JavaDoc type;
101         ContainerChildFactory cfactory;
102         public ContainerChildren(AppserverMgmtController controller, String JavaDoc type) {
103             if(controller == null) {
104                 getLogger().log(Level.FINE, "Controller for child factory " +
105                     "is null");
106                 getLogger().log(Level.FINE, "Type: " + type);
107             }
108             this.type = type;
109             this.cfactory = new ContainerChildFactory(controller);
110         }
111         protected void addNotify() {
112             
113             Node n[]= new Node[1];
114             n[0]=new WaitNode();
115             setKeys(n);
116             RequestProcessor.getDefault().post(new Runnable JavaDoc() {
117                 public void run() {
118                     try {
119                         setKeys(cfactory.getChildrenObject(type));
120                     } catch (RuntimeException JavaDoc e) {
121                         getLogger().log(Level.FINE, e.getMessage(), e);
122                     }
123                 }
124             });
125             
126         }
127         protected void removeNotify() {
128             setKeys(java.util.Collections.EMPTY_SET);
129         }
130         public void updateKeys() {
131             refresh();
132         }
133         protected org.openide.nodes.Node[] createNodes(Object JavaDoc obj) {
134             try {
135                 return new Node[] { (Node)obj };
136             } catch(RuntimeException JavaDoc rex) {
137                 getLogger().log(Level.FINE, rex.getMessage(), rex);
138                 return new Node[] {};
139             } catch(Exception JavaDoc e) {
140                 getLogger().log(Level.FINE, e.getMessage(), e);
141                 return new Node[] {};
142             }
143         }
144     }
145 }
146
Popular Tags