KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > LibrariesNodeFactory


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.apisupport.project.ui;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.event.ChangeListener JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.apisupport.project.NbModuleProject;
27 import org.netbeans.spi.project.ui.support.NodeFactory;
28 import org.netbeans.spi.project.ui.support.NodeList;
29 import org.openide.filesystems.FileObject;
30 import org.openide.nodes.Node;
31
32 /**
33  *
34  * @author mkleint
35  */

36 public class LibrariesNodeFactory implements NodeFactory {
37     
38     /** Creates a new instance of LibrariesNodeFactory */
39     public LibrariesNodeFactory() {
40     }
41     
42     public NodeList createNodes(Project p) {
43         NbModuleProject proj = p.getLookup().lookup(NbModuleProject.class);
44         assert proj != null;
45         return new LibraryNL(proj);
46     }
47     
48     private static class LibraryNL implements NodeList<String JavaDoc> {
49         
50         private NbModuleProject project;
51         
52         LibraryNL(NbModuleProject prj) {
53             project = prj;
54         }
55     
56         public List JavaDoc<String JavaDoc> keys() {
57             List JavaDoc<String JavaDoc> toRet = new ArrayList JavaDoc<String JavaDoc>();
58             toRet.add(LibrariesNode.LIBRARIES_NAME);
59             if(resolveFileObjectFromProperty("test.unit.src.dir") != null) { //NOI18N
60
toRet.add(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME);
61             }
62             return toRet;
63         }
64         
65         private FileObject resolveFileObjectFromProperty(String JavaDoc property){
66             String JavaDoc filename = project.evaluator().getProperty(property);
67             if (filename == null) {
68                 return null;
69             }
70             return project.getHelper().resolveFileObject(filename);
71         }
72
73         public void addChangeListener(ChangeListener JavaDoc l) {
74         }
75
76         public void removeChangeListener(ChangeListener JavaDoc l) {
77         }
78
79         public Node node(String JavaDoc key) {
80             if (key == LibrariesNode.LIBRARIES_NAME) {
81                 return new LibrariesNode(project);
82             } else if (key == UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME) {
83                 return new UnitTestLibrariesNode(project);
84             }
85             throw new AssertionError JavaDoc("Unknown key: " + key);
86         }
87
88         public void addNotify() {
89             //TODO shall we somehow listen on project and ech for the
90
// test.unit.src.dir prop appearance/disappearance ??
91
}
92
93         public void removeNotify() {
94         }
95 }
96
97 }
98
Popular Tags