KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ui > SetupDirNodeFactory


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
32 import org.netbeans.modules.web.project.WebProject;
33 import org.netbeans.spi.project.ui.support.NodeFactory;
34 import org.netbeans.spi.project.ui.support.NodeList;
35 import org.openide.nodes.Node;
36
37 /**
38  *
39  * @author mkleint
40  */

41 public final class SetupDirNodeFactory implements NodeFactory {
42     
43     /** Creates a new instance of LibrariesNodeFactory */
44     public SetupDirNodeFactory() {
45     }
46
47     public NodeList createNodes(Project p) {
48         WebProject project = (WebProject) p.getLookup().lookup(WebProject.class);
49         assert project != null;
50         return new SetupDirNodeList(project);
51     }
52
53     private static class SetupDirNodeList implements NodeList<String JavaDoc>, PropertyChangeListener JavaDoc {
54         private static final String JavaDoc SETUP_DIR = "setupDir"; //NOI18N
55

56         private final WebProject project;
57         private final ArrayList JavaDoc<ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
58
59         SetupDirNodeList(WebProject proj) {
60             project = proj;
61             WebLogicalViewProvider logView = (WebLogicalViewProvider) project.getLookup().lookup(WebLogicalViewProvider.class);
62             assert logView != null;
63         }
64         
65         public List JavaDoc<String JavaDoc> keys() {
66             List JavaDoc<String JavaDoc> result = new ArrayList JavaDoc<String JavaDoc>();
67             result.add(SETUP_DIR);
68             return result;
69         }
70
71         public synchronized void addChangeListener(ChangeListener JavaDoc l) {
72             listeners.add(l);
73         }
74
75         public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
76             listeners.remove(l);
77         }
78         
79         private void fireChange() {
80             ArrayList JavaDoc<ChangeListener JavaDoc> list = new ArrayList JavaDoc<ChangeListener JavaDoc>();
81             synchronized (this) {
82                 list.addAll(listeners);
83             }
84             Iterator JavaDoc<ChangeListener JavaDoc> it = list.iterator();
85             while (it.hasNext()) {
86                 ChangeListener JavaDoc elem = it.next();
87                 elem.stateChanged(new ChangeEvent JavaDoc( this ));
88             }
89         }
90
91         public Node node(String JavaDoc key) {
92             if (key == SETUP_DIR) {
93                 return J2eeProjectView.createServerResourcesNode(project);
94             }
95             assert false: "No node for key: " + key;
96             return null;
97         }
98
99         public void addNotify() {
100         }
101
102         public void removeNotify() {
103         }
104
105         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
106             // The caller holds ProjectManager.mutex() read lock
107
SwingUtilities.invokeLater(new Runnable JavaDoc() {
108                 public void run() {
109                     fireChange();
110                 }
111             });
112         }
113         
114     }
115     
116 }
117
Popular Tags