KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > nodes > WS70WebModulesChildren


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 /*
21  * WS70WebModulesChildren.java
22  *
23  */

24
25 package org.netbeans.modules.j2ee.sun.ws7.nodes;
26
27 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
28 import javax.enterprise.deploy.spi.Target JavaDoc;
29 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
30
31 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
32
33 import org.openide.util.Lookup;
34 import org.openide.nodes.AbstractNode;
35 import org.openide.nodes.Node;
36 import org.openide.nodes.Children;
37 import org.openide.util.NbBundle;
38 import org.openide.util.RequestProcessor;
39
40 import java.util.TreeSet JavaDoc;
41
42
43 /**
44  *
45  * @author Administrator
46  */

47 public class WS70WebModulesChildren extends Children.Keys{
48     private static final String JavaDoc WAIT_NODE = "wait_node"; //NOI18N
49
private Lookup lookup;
50     /** Creates a new instance of WS70WebModulesChildren */
51     public WS70WebModulesChildren(Lookup lookup) {
52         this.lookup = lookup;
53     }
54     
55     protected Node[] createNodes(Object JavaDoc key){
56         if (key instanceof WS70WebModule){
57             WS70WebModule module = (WS70WebModule)key;
58             WS70WebModuleNode node = new WS70WebModuleNode(module);
59             return new Node[]{node};
60         }
61         if (key instanceof String JavaDoc && key.equals(WAIT_NODE)){
62             return new Node[]{createWaitNode ()};
63         }
64         return null;
65     }
66     
67     public void updateKeys(){
68         Target JavaDoc target = (Target JavaDoc)lookup.lookup(Target JavaDoc.class);
69         DeploymentManager JavaDoc dm = (DeploymentManager JavaDoc)lookup.lookup(DeploymentManager JavaDoc.class);
70         TreeSet JavaDoc ts = new TreeSet JavaDoc();
71         ts.add(WAIT_NODE);
72         setKeys(ts);
73         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
74             public void run () {
75                 DeploymentManager JavaDoc manager = (DeploymentManager JavaDoc)lookup.lookup(DeploymentManager JavaDoc.class);
76                 Target JavaDoc target = (Target JavaDoc)lookup.lookup(Target JavaDoc.class);
77                 TreeSet JavaDoc list = new TreeSet JavaDoc(new WS70WmComparator());
78                 if (target != null){
79
80                     try{
81                         TargetModuleID JavaDoc[] modules = manager.getAvailableModules(ModuleType.WAR, new Target JavaDoc[]{target});
82                          for (int i = 0; i < modules.length; i ++){
83                              list.add(new WS70WebModule(manager, modules[i]));
84                          }
85                        }
86                     
87                     catch (Exception JavaDoc e) {
88                         e.printStackTrace();
89                     }
90                 }
91                setKeys(list);
92        
93             }
94         }, 0);
95     }
96     
97     protected void addNotify() {
98         updateKeys();
99     }
100    
101     protected void removeNotify() {
102         setKeys(java.util.Collections.EMPTY_SET);
103     }
104     private Node createWaitNode () {
105         AbstractNode n = new AbstractNode(Children.LEAF);
106         n.setName(NbBundle.getMessage(WS70WebModulesChildren.class, "LBL_WaitNode_DisplayName")); //NOI18N
107
n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); // NOI18N
108
return n;
109     }
110     public static class WS70WmComparator implements java.util.Comparator JavaDoc{
111         
112        public int compare(Object JavaDoc o1, Object JavaDoc o2) {
113             WS70WebModule wm1 = (WS70WebModule) o1;
114             WS70WebModule wm2 = (WS70WebModule) o2;
115             return wm1.getName().compareTo(wm2.getName());
116         }
117         
118     }
119
120 }
121
122
Popular Tags