001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui;
043:
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.List;
047: import javax.swing.event.ChangeEvent;
048: import javax.swing.event.ChangeListener;
049: import org.netbeans.api.java.project.JavaProjectConstants;
050: import org.netbeans.api.project.Project;
051: import org.netbeans.api.project.ProjectUtils;
052: import org.netbeans.api.project.SourceGroup;
053: import org.netbeans.api.project.Sources;
054: import org.netbeans.modules.apisupport.project.NbModuleProject;
055: import org.netbeans.spi.java.project.support.ui.PackageView;
056: import org.netbeans.spi.project.support.GenericSources;
057: import org.netbeans.spi.project.ui.support.NodeFactory;
058: import org.netbeans.spi.project.ui.support.NodeList;
059: import org.openide.filesystems.FileObject;
060: import org.openide.nodes.Node;
061: import org.openide.util.ChangeSupport;
062: import org.openide.util.NbBundle;
063:
064: /**
065: *
066: * @author mkleint
067: */
068: public class SourcesNodeFactory implements NodeFactory {
069:
070: /** Creates a new instance of SourcesNodeFactory */
071: public SourcesNodeFactory() {
072: }
073:
074: public NodeList createNodes(Project p) {
075: NbModuleProject prj = p.getLookup().lookup(
076: NbModuleProject.class);
077: return new SourceNL(prj);
078: }
079:
080: private static class SourceNL implements NodeList<SourceGroup>,
081: ChangeListener {
082: private final ChangeSupport changeSupport = new ChangeSupport(
083: this );
084: private static final String[] SOURCE_GROUP_TYPES = {
085: JavaProjectConstants.SOURCES_TYPE_JAVA,
086: NbModuleProject.SOURCES_TYPE_JAVAHELP, };
087:
088: private final NbModuleProject project;
089:
090: SourceNL(NbModuleProject prj) {
091: project = prj;
092: }
093:
094: public void addChangeListener(ChangeListener l) {
095: changeSupport.addChangeListener(l);
096: }
097:
098: public void removeChangeListener(ChangeListener l) {
099: changeSupport.removeChangeListener(l);
100: }
101:
102: public void addNotify() {
103: ProjectUtils.getSources(project).addChangeListener(this );
104: }
105:
106: public void removeNotify() {
107: ProjectUtils.getSources(project).removeChangeListener(this );
108: }
109:
110: public Node node(SourceGroup key) {
111: return PackageView.createPackageView(key);
112: }
113:
114: public List<SourceGroup> keys() {
115: List<SourceGroup> l = new ArrayList<SourceGroup>();
116: Sources s = ProjectUtils.getSources(project);
117: for (int i = 0; i < SOURCE_GROUP_TYPES.length; i++) {
118: SourceGroup[] groups = s
119: .getSourceGroups(SOURCE_GROUP_TYPES[i]);
120: l.addAll(Arrays.asList(groups));
121: }
122: SourceGroup javadocDocfiles = makeJavadocDocfilesSourceGroup();
123: if (javadocDocfiles != null) {
124: l.add(javadocDocfiles);
125: }
126: return l;
127: }
128:
129: private SourceGroup makeJavadocDocfilesSourceGroup() {
130: String propname = "javadoc.docfiles"; // NOI18N
131: FileObject root = resolveFileObjectFromProperty(propname);
132: if (root == null) {
133: return null;
134: }
135: return GenericSources.group(project, root, propname,
136: NbBundle.getMessage(ModuleLogicalView.class,
137: "LBL_extra_javadoc_files"), null, null);
138: }
139:
140: private FileObject resolveFileObjectFromProperty(String property) {
141: String filename = project.evaluator().getProperty(property);
142: if (filename == null) {
143: return null;
144: }
145: return project.getHelper().resolveFileObject(filename);
146: }
147:
148: public void stateChanged(ChangeEvent arg0) {
149: changeSupport.fireChange();
150: }
151: }
152: }
|