1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.List ; 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 import org.netbeans.api.java.project.JavaProjectConstants; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectUtils; 30 import org.netbeans.api.project.SourceGroup; 31 import org.netbeans.api.project.Sources; 32 import org.netbeans.modules.apisupport.project.NbModuleProject; 33 import org.netbeans.spi.java.project.support.ui.PackageView; 34 import org.netbeans.spi.project.support.GenericSources; 35 import org.netbeans.spi.project.ui.support.NodeFactory; 36 import org.netbeans.spi.project.ui.support.NodeList; 37 import org.openide.filesystems.FileObject; 38 import org.openide.nodes.Node; 39 import org.openide.util.NbBundle; 40 41 45 public class SourcesNodeFactory implements NodeFactory { 46 47 48 public SourcesNodeFactory() { 49 } 50 51 public NodeList createNodes(Project p) { 52 NbModuleProject prj = p.getLookup().lookup(NbModuleProject.class); 53 return new SourceNL(prj); 54 } 55 56 57 private static class SourceNL implements NodeList<SourceGroup>, ChangeListener { 58 private List <ChangeListener > list = new ArrayList <ChangeListener >(); 59 private static final String [] SOURCE_GROUP_TYPES = { 60 JavaProjectConstants.SOURCES_TYPE_JAVA, 61 NbModuleProject.SOURCES_TYPE_JAVAHELP, 62 }; 63 64 private final NbModuleProject project; 65 66 SourceNL(NbModuleProject prj) { 67 project = prj; 68 } 69 public void addChangeListener(ChangeListener l) { 70 list.add(l); 71 } 72 73 public void removeChangeListener(ChangeListener l) { 74 list.remove(l); 75 } 76 77 public void addNotify() { 78 ProjectUtils.getSources(project).addChangeListener(this); 79 } 80 81 public void removeNotify() { 82 ProjectUtils.getSources(project).removeChangeListener(this); 83 } 84 85 public Node node(SourceGroup key) { 86 return PackageView.createPackageView(key); 87 } 88 89 public List <SourceGroup> keys() { 90 List <SourceGroup> l = new ArrayList <SourceGroup>(); 91 Sources s = ProjectUtils.getSources(project); 92 for (int i = 0; i < SOURCE_GROUP_TYPES.length; i++) { 93 SourceGroup[] groups = s.getSourceGroups(SOURCE_GROUP_TYPES[i]); 94 l.addAll(Arrays.asList(groups)); 95 } 96 SourceGroup javadocDocfiles = makeJavadocDocfilesSourceGroup(); 97 if (javadocDocfiles != null) { 98 l.add(javadocDocfiles); 99 } 100 return l; 101 } 102 103 private SourceGroup makeJavadocDocfilesSourceGroup() { 104 String propname = "javadoc.docfiles"; FileObject root = resolveFileObjectFromProperty(propname); 106 if(root == null) { 107 return null; 108 } 109 return GenericSources.group(project, root, propname, NbBundle.getMessage(ModuleLogicalView.class, "LBL_extra_javadoc_files"), null, null); 110 } 111 112 private FileObject resolveFileObjectFromProperty(String property){ 113 String filename = project.evaluator().getProperty(property); 114 if (filename == null) { 115 return null; 116 } 117 return project.getHelper().resolveFileObject(filename); 118 } 119 120 public void stateChanged(ChangeEvent arg0) { 121 for (ChangeListener lst : list) { 122 lst.stateChanged(new ChangeEvent (this)); 123 } 124 } 125 } 126 } 127 | Popular Tags |