KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > JavaProjectNature


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.java.freeform;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.swing.Icon JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.SourceGroup;
32 import org.netbeans.modules.ant.freeform.spi.ProjectNature;
33 import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
34 import org.netbeans.spi.java.project.support.ui.PackageView;
35 import org.netbeans.spi.project.AuxiliaryConfiguration;
36 import org.netbeans.spi.project.support.ant.AntProjectHelper;
37 import org.netbeans.spi.project.support.ant.PathMatcher;
38 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
39 import org.openide.filesystems.FileObject;
40 import org.openide.filesystems.FileUtil;
41
42 /**
43  * General hook for registration of the Java nature for freeform projects.
44  * @author David Konecny
45  */

46 public class JavaProjectNature implements ProjectNature {
47
48     public static final String JavaDoc NS_JAVA_1 = "http://www.netbeans.org/ns/freeform-project-java/1"; // NOI18N
49
public static final String JavaDoc NS_JAVA_2 = "http://www.netbeans.org/ns/freeform-project-java/2"; // NOI18N
50
public static final String JavaDoc EL_JAVA = "java-data"; // NOI18N
51
private static final String JavaDoc SCHEMA_1 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java.xsd"; // NOI18N
52
private static final String JavaDoc SCHEMA_2 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java-2.xsd"; // NOI18N
53
public static final String JavaDoc STYLE_PACKAGES = "packages"; // NOI18N
54

55     
56     public JavaProjectNature() {}
57     
58     public List JavaDoc<TargetDescriptor> getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
59         return new ArrayList JavaDoc<TargetDescriptor>();
60     }
61
62     public Set JavaDoc<String JavaDoc> getSchemas() {
63         return new HashSet JavaDoc<String JavaDoc>(Arrays.asList(SCHEMA_1, SCHEMA_2));
64     }
65
66     public Set JavaDoc<String JavaDoc> getSourceFolderViewStyles() {
67         return Collections.singleton(STYLE_PACKAGES);
68     }
69     
70     public org.openide.nodes.Node createSourceFolderView(Project project, final FileObject folder, final String JavaDoc includes,
71             final String JavaDoc excludes, String JavaDoc style, final String JavaDoc name, final String JavaDoc displayName) throws IllegalArgumentException JavaDoc {
72         if (style.equals(STYLE_PACKAGES)) {
73             return PackageView.createPackageView(new SourceGroup() {
74                 PathMatcher matcher = new PathMatcher(includes, excludes, FileUtil.toFile(folder));
75                 public FileObject getRootFolder() {
76                     return folder;
77                 }
78                 public String JavaDoc getName() {
79                     return name;
80                 }
81                 public String JavaDoc getDisplayName() {
82                     if (displayName != null) {
83                         return displayName;
84                     } else {
85                         // Don't use folder.getNodeDelegate().getDisplayName() since we are not listening to changes anyway.
86
return folder.getNameExt();
87                     }
88                 }
89                 public Icon JavaDoc getIcon(boolean opened) {
90                     return null;
91                 }
92                 public boolean contains(FileObject file) throws IllegalArgumentException JavaDoc {
93                     String JavaDoc path = FileUtil.getRelativePath(folder, file);
94                     assert path != null : file + " not in " + folder;
95                     if (file.isFolder()) {
96                         path += "/"; // NOI18N
97
}
98                     return matcher.matches(path, true);
99                 }
100                 public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {}
101                 public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {}
102             });
103         } else {
104             throw new IllegalArgumentException JavaDoc();
105         }
106     }
107
108     public org.openide.nodes.Node findSourceFolderViewPath(Project project, org.openide.nodes.Node root, Object JavaDoc target) {
109         return PackageView.findPath(root, target);
110     }
111
112     
113
114
115
116
117
118     
119 }
120
Popular Tags