1 19 20 package org.netbeans.modules.java.freeform; 21 22 import java.beans.PropertyChangeListener ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.Collections ; 26 import java.util.HashSet ; 27 import java.util.List ; 28 import java.util.Set ; 29 import javax.swing.Icon ; 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 46 public class JavaProjectNature implements ProjectNature { 47 48 public static final String NS_JAVA_1 = "http://www.netbeans.org/ns/freeform-project-java/1"; public static final String NS_JAVA_2 = "http://www.netbeans.org/ns/freeform-project-java/2"; public static final String EL_JAVA = "java-data"; private static final String SCHEMA_1 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java.xsd"; private static final String SCHEMA_2 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java-2.xsd"; public static final String STYLE_PACKAGES = "packages"; 55 56 public JavaProjectNature() {} 57 58 public List <TargetDescriptor> getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { 59 return new ArrayList <TargetDescriptor>(); 60 } 61 62 public Set <String > getSchemas() { 63 return new HashSet <String >(Arrays.asList(SCHEMA_1, SCHEMA_2)); 64 } 65 66 public Set <String > getSourceFolderViewStyles() { 67 return Collections.singleton(STYLE_PACKAGES); 68 } 69 70 public org.openide.nodes.Node createSourceFolderView(Project project, final FileObject folder, final String includes, 71 final String excludes, String style, final String name, final String displayName) throws IllegalArgumentException { 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 getName() { 79 return name; 80 } 81 public String getDisplayName() { 82 if (displayName != null) { 83 return displayName; 84 } else { 85 return folder.getNameExt(); 87 } 88 } 89 public Icon getIcon(boolean opened) { 90 return null; 91 } 92 public boolean contains(FileObject file) throws IllegalArgumentException { 93 String path = FileUtil.getRelativePath(folder, file); 94 assert path != null : file + " not in " + folder; 95 if (file.isFolder()) { 96 path += "/"; } 98 return matcher.matches(path, true); 99 } 100 public void addPropertyChangeListener(PropertyChangeListener listener) {} 101 public void removePropertyChangeListener(PropertyChangeListener listener) {} 102 }); 103 } else { 104 throw new IllegalArgumentException (); 105 } 106 } 107 108 public org.openide.nodes.Node findSourceFolderViewPath(Project project, org.openide.nodes.Node root, Object target) { 109 return PackageView.findPath(root, target); 110 } 111 112 113 114 115 116 117 118 119 } 120 | Popular Tags |