Index: java/project/nbproject/project.xml diff -u java/project/nbproject/project.xml:1.39 java/project/nbproject/project.xml:1.38.2.3 --- java/project/nbproject/project.xml:1.39 Mon Oct 1 07:23:21 2007 +++ java/project/nbproject/project.xml Fri Nov 30 06:01:45 2007 @@ -95,7 +95,7 @@ 1 - 1.15 + 1.17 @@ -334,6 +334,7 @@ org.netbeans.api.java.project.classpath org.netbeans.spi.java.project.classpath org.netbeans.spi.java.project.classpath.support + org.netbeans.spi.java.project.support org.netbeans.spi.java.project.support.ui org.netbeans.spi.java.project.support.ui.templates Index: java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation diff -u java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation:1.3 java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation:1.3.160.2 --- java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation:1.3 Wed May 26 07:00:13 2004 +++ java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation Fri Jan 11 03:26:48 2008 @@ -1,2 +1,4 @@ org.netbeans.modules.java.project.JavadocForBinaryQueryImpl #position=100 +org.netbeans.modules.java.project.ExtraJavadocForBinaryQueryImplementation +#position=9999 Index: java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation diff -u java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation:1.3 java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation:1.3.160.2 --- java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation:1.3 Wed May 26 07:00:13 2004 +++ java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation Fri Jan 11 03:26:48 2008 @@ -1,2 +1,4 @@ org.netbeans.modules.java.project.ProjectSourceForBinaryQuery #position=100 +org.netbeans.modules.java.project.ExtraSourceForBinaryQueryImplementation +#position=6666 Index: java/project/src/org/netbeans/modules/java/project/ExtraJavadocForBinaryQueryImplementation.java diff -u /dev/null java/project/src/org/netbeans/modules/java/project/ExtraJavadocForBinaryQueryImplementation.java:1.1.2.1 --- /dev/null Mon Jan 14 06:07:35 2008 +++ java/project/src/org/netbeans/modules/java/project/ExtraJavadocForBinaryQueryImplementation.java Fri Jan 11 03:26:49 2008 @@ -0,0 +1,185 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import java.beans.PropertyChangeEvent; +import org.netbeans.spi.project.support.ant.*; +import java.beans.PropertyChangeListener; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.openide.util.ChangeSupport; +import org.openide.util.WeakListeners; + +/** + * + * @author mkleint + */ +public final class ExtraJavadocForBinaryQueryImplementation implements JavadocForBinaryQueryImplementation { + + + public ExtraJavadocForBinaryQueryImplementation() { + } + + /** + * We always return a result here, never null, otherwise we loose the ability to + * fire a result change when new project gets opened. + * @return + */ + public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) { + return new Result(binaryRoot); + } + + public static JavadocForBinaryQueryImplementation createProjectInstance(AntProjectHelper helper, PropertyEvaluator evaluator) { + return new ExtraProjectJavadocForBinaryQueryImpl(helper, evaluator); + } + + private static class Result implements JavadocForBinaryQuery.Result { + + private URL binaryRoot; + private PropertyChangeListener listener; + private final ChangeSupport cs = new ChangeSupport(this); + private Map cachedResults; + private final Object LOCK = new Object(); + private ChangeListener changeListener; + + + private Result(URL binaryRoot) { + this.binaryRoot = binaryRoot; + changeListener = new ChangeListener() { + public void stateChanged(ChangeEvent e) { + cs.fireChange(); + } + }; + + listener = new PropertyChangeListener() { + public void propertyChange( PropertyChangeEvent evt ) { + if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) { + synchronized (LOCK) { + if (cachedResults != null) { + Map newRes = results(); + Set oldprjs = new HashSet(cachedResults.keySet()); + Set newprjs = new HashSet(newRes.keySet()); + newprjs.removeAll(cachedResults.keySet()); + oldprjs.removeAll(newRes.keySet()); + for (Project p : oldprjs) { + JavadocForBinaryQuery.Result res = cachedResults.get(p); + res.removeChangeListener(changeListener); + } + for (Project p : newprjs) { + JavadocForBinaryQuery.Result res = newRes.get(p); + res.addChangeListener(changeListener); + } + cachedResults = newRes; + } + } + cs.fireChange(); + } + } + }; + OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(listener, OpenProjects.getDefault())); + } + + public URL[] getRoots() { + List fos = new ArrayList(); + synchronized (LOCK) { + if (cachedResults == null) { + cachedResults = results(); + for (JavadocForBinaryQuery.Result result : cachedResults.values()) { + result.addChangeListener(changeListener); + } + } + for (JavadocForBinaryQuery.Result result : cachedResults.values()) { + URL[] f = result.getRoots(); + fos.addAll(Arrays.asList(f)); + } + } + return fos.toArray(new URL[fos.size()]); + } + + private Map results() { + HashMap res = new HashMap(); + Project[] prj = OpenProjects.getDefault().getOpenProjects(); + for (Project project : prj) { + //TODO ask jtulach why this lookup query fails.. + ExtraProjectJavadocForBinaryQueryImpl impl = project.getLookup().lookup(ExtraProjectJavadocForBinaryQueryImpl.class); + //workaround to make it works.. + if (impl == null) { + for (JavadocForBinaryQueryImplementation im : project.getLookup().lookupAll(JavadocForBinaryQueryImplementation.class)) { + if (im instanceof ExtraProjectJavadocForBinaryQueryImpl) { + impl = (ExtraProjectJavadocForBinaryQueryImpl)im; + } + } + } + if (impl != null) { + JavadocForBinaryQuery.Result result = impl.findJavadoc(binaryRoot); + if (result != null) { + res.put(project, result); + } + } + } + return res; + } + + public void addChangeListener(ChangeListener l) { + assert l != null : "Listener cannot be null"; // NOI18N + cs.addChangeListener(l); + + } + + public void removeChangeListener(ChangeListener l) { + assert l != null : "Listener cannot be null"; // NOI18N + cs.removeChangeListener(l); + } + + } + +} Index: java/project/src/org/netbeans/modules/java/project/ExtraProjectJavadocForBinaryQueryImpl.java diff -u /dev/null java/project/src/org/netbeans/modules/java/project/ExtraProjectJavadocForBinaryQueryImpl.java:1.1.2.1 --- /dev/null Mon Jan 14 06:07:35 2008 +++ java/project/src/org/netbeans/modules/java/project/ExtraProjectJavadocForBinaryQueryImpl.java Fri Jan 11 03:26:50 2008 @@ -0,0 +1,199 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.net.MalformedURLException; +import org.netbeans.api.java.queries.JavadocForBinaryQuery; +import org.netbeans.spi.project.support.ant.*; +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import javax.swing.event.ChangeListener; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.openide.filesystems.FileUtil; +import org.openide.util.ChangeSupport; +import org.openide.util.Exceptions; + +/** + * + * @author mkleint + */ +public final class ExtraProjectJavadocForBinaryQueryImpl extends ProjectOpenedHook implements JavadocForBinaryQueryImplementation { + + private static final String REF_START = "file.reference."; //NOI18N + private static final String JAVADOC_START = "javadoc.reference."; //NOI18N + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private Map cache = new HashMap(); + private PropertyChangeListener listener; + private Map mappings = new HashMap(); + + public ExtraProjectJavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { + this.helper = helper; + this.evaluator = evaluator; + listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == null || evt.getPropertyName().startsWith(JAVADOC_START)) { + mappings = getExtraSources(); + Collection results = null; + synchronized (cache) { + results = new ArrayList(cache.values()); + } + for (ExtraResult res : results) { + res.fire(); + } + } + } + + }; + + } + + /** + * return null only if the javadoc and also the binary url are missing in project.. + * @param binaryRoot + * @return + */ + public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) { + synchronized (cache) { + ExtraResult res = cache.get(binaryRoot); + if (res != null) { + return res; + } + if (mappings.containsKey(binaryRoot)) { + res = new ExtraResult(binaryRoot); + cache.put (binaryRoot, res); + return res; + } + } + return null; + } + + @Override + protected void projectOpened() { + mappings = getExtraSources(); + evaluator.addPropertyChangeListener(listener); + } + + @Override + protected void projectClosed() + { + mappings = new HashMap(); + evaluator.removePropertyChangeListener(listener); + } + + + Map getExtraSources() { + Map result = new HashMap(); + Map props = evaluator.getProperties(); + for (Map.Entry entry : props.entrySet()) { + if (entry.getKey().startsWith(REF_START)) { + String val = entry.getKey().substring(REF_START.length()); + String sourceKey = JAVADOC_START + val; + String source = props.get(sourceKey); + try { + File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue()); + URL binURL = bin.toURI().toURL(); + if (FileUtil.isArchiveFile(binURL)) { + binURL = FileUtil.getArchiveRoot(binURL); + } + if (source != null) { + File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source); + result.put(binURL, src.toURI()); + } else { + result.put(binURL, null); + } + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + } + return result; + } + + private class ExtraResult implements JavadocForBinaryQuery.Result { + private URL binaryroot; + private ChangeSupport chs = new ChangeSupport(this); + + + public ExtraResult(URL binary) { + binaryroot = binary; + } + + public URL[] getRoots() { + URI source = mappings.get(binaryroot); + if (source != null) { + try + { + URL url = source.toURL(); + if (FileUtil.isArchiveFile(url)) { + url = FileUtil.getArchiveRoot(url); + } + return new URL[] { url }; + } catch ( MalformedURLException ex ) + { + Exceptions.printStackTrace( ex ); + } + } + return new URL[0]; + } + + public void fire() { + chs.fireChange(); + } + + public void addChangeListener(ChangeListener l) { + chs.addChangeListener(l); + } + + public void removeChangeListener(ChangeListener l) { + chs.removeChangeListener(l); + } + + } +} Index: java/project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java diff -u /dev/null java/project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java:1.1.2.1 --- /dev/null Mon Jan 14 06:07:35 2008 +++ java/project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java Fri Jan 11 03:26:50 2008 @@ -0,0 +1,209 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.net.MalformedURLException; +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.URLMapper; +import org.openide.util.ChangeSupport; +import org.openide.util.Exceptions; + +/** + * + * @author mkleint + */ +public final class ExtraProjectSourceForBinaryQueryImpl extends ProjectOpenedHook implements SourceForBinaryQueryImplementation { + + private static final String REF_START = "file.reference."; //NOI18N + private static final String SOURCE_START = "source.reference."; //NOI18N + + private final AntProjectHelper helper; + private final PropertyEvaluator evaluator; + private Map cache = new HashMap(); + private PropertyChangeListener listener; + private Map mappings = new HashMap(); + + public ExtraProjectSourceForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) { + this.helper = helper; + this.evaluator = evaluator; + listener = new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == null || evt.getPropertyName().startsWith(SOURCE_START)) { + mappings = getExtraSources(); + Collection results = null; + synchronized (cache) { + results = new ArrayList(cache.values()); + } + for (ExtraResult res : results) { + res.fire(); + } + } + } + + }; + } + + /** + * + * returns a result even if only the binary root is found in the project. + * only returns null when the binary root is missing from project altogether. + * @param binaryRoot + * @return + */ + public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { + synchronized (cache) { + ExtraResult res = cache.get(binaryRoot); + if (res != null) { + return res; + } + if (mappings.containsKey(binaryRoot)) { + res = new ExtraResult(binaryRoot); + cache.put (binaryRoot, res); + return res; + } + } + return null; + } + + @Override + protected void projectOpened() { + mappings = getExtraSources(); + evaluator.addPropertyChangeListener(listener); + } + + @Override + protected void projectClosed() { + mappings = new HashMap(); + evaluator.removePropertyChangeListener(listener); + } + + + Map getExtraSources() { + Map result = new HashMap(); + Map props = evaluator.getProperties(); + for (Map.Entry entry : props.entrySet()) { + if (entry.getKey().startsWith(REF_START)) { + String val = entry.getKey().substring(REF_START.length()); + String sourceKey = SOURCE_START + val; + String source = props.get(sourceKey); + File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue()); + try { + URL binURL = bin.toURI().toURL(); + if (FileUtil.isArchiveFile(binURL)) { + binURL = FileUtil.getArchiveRoot(binURL); + } + if (source != null) { + File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source); + result.put(binURL, src.toURI()); + } else { + result.put(binURL, null); + } + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + } + return result; + } + + private class ExtraResult implements SourceForBinaryQuery.Result { + private URL binaryroot; + private ChangeSupport chs = new ChangeSupport(this); + + public ExtraResult(URL binary) { + binaryroot = binary; + } + + public FileObject[] getRoots() { + URI source = mappings.get(binaryroot); + if (source != null) { + try + { + URL url = source.toURL(); + if (FileUtil.isArchiveFile(url)) { + url = FileUtil.getArchiveRoot(url); + } + FileObject fo = URLMapper.findFileObject(url); + if ( fo != null ) + { + return new FileObject[]{fo}; + } + } catch ( MalformedURLException ex ) + { + Exceptions.printStackTrace( ex ); + } + } + return new FileObject[0]; + } + + public void fire() { + chs.fireChange(); + } + + public void addChangeListener(ChangeListener l) { + chs.addChangeListener(l); + } + + public void removeChangeListener(ChangeListener l) { + chs.removeChangeListener(l); + } + + } + + + +} Index: java/project/src/org/netbeans/modules/java/project/ExtraSourceForBinaryQueryImplementation.java diff -u /dev/null java/project/src/org/netbeans/modules/java/project/ExtraSourceForBinaryQueryImplementation.java:1.1.2.1 --- /dev/null Mon Jan 14 06:07:35 2008 +++ java/project/src/org/netbeans/modules/java/project/ExtraSourceForBinaryQueryImplementation.java Fri Jan 11 03:26:50 2008 @@ -0,0 +1,185 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.java.project; + +import java.beans.PropertyChangeEvent; +import javax.swing.event.ChangeEvent; +import org.netbeans.spi.project.support.ant.*; +import java.beans.PropertyChangeListener; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.queries.SourceForBinaryQuery; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ui.OpenProjects; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.openide.filesystems.FileObject; +import org.openide.util.ChangeSupport; +import org.openide.util.WeakListeners; + +/** + * + * @author mkleint + */ +public final class ExtraSourceForBinaryQueryImplementation implements SourceForBinaryQueryImplementation { + + + public ExtraSourceForBinaryQueryImplementation() { + } + + /** + * We always return a result here, never null, otherwise we loose the ability to + * fire a result change when new project gets opened. + * @return + */ + public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { + return new Result(binaryRoot); + } + + public static SourceForBinaryQueryImplementation createProjectInstance(AntProjectHelper helper, PropertyEvaluator evaluator) { + return new ExtraProjectSourceForBinaryQueryImpl(helper, evaluator); + } + + private static class Result implements SourceForBinaryQuery.Result { + + private URL binaryRoot; + private PropertyChangeListener listener; + private final ChangeSupport cs = new ChangeSupport(this); + private Map cachedResults; + private final Object LOCK = new Object(); + private ChangeListener changeListener; + + private Result(URL binaryRoot) { + this.binaryRoot = binaryRoot; + changeListener = new ChangeListener() { + public void stateChanged(ChangeEvent e) { + cs.fireChange(); + } + + }; + listener = new PropertyChangeListener() { + public void propertyChange( PropertyChangeEvent evt ) { + if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) { + synchronized (LOCK) { + if (cachedResults != null) { + Map newRes = results(); + Set oldprjs = new HashSet(cachedResults.keySet()); + Set newprjs = new HashSet(newRes.keySet()); + newprjs.removeAll(cachedResults.keySet()); + oldprjs.removeAll(newRes.keySet()); + for (Project p : oldprjs) { + SourceForBinaryQuery.Result res = cachedResults.get(p); + res.removeChangeListener(changeListener); + } + for (Project p : newprjs) { + SourceForBinaryQuery.Result res = newRes.get(p); + res.addChangeListener(changeListener); + } + cachedResults = newRes; + } + } + cs.fireChange(); + } + } + }; + OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(listener, OpenProjects.getDefault())); + } + + public FileObject[] getRoots() { + List fos = new ArrayList(); + synchronized (LOCK) { + if (cachedResults == null) { + cachedResults = results(); + for (SourceForBinaryQuery.Result result : cachedResults.values()) { + result.addChangeListener(changeListener); + } + } + for (SourceForBinaryQuery.Result result : cachedResults.values()) { + FileObject[] f = result.getRoots(); + fos.addAll(Arrays.asList(f)); + } + } + return fos.toArray(new FileObject[fos.size()]); + } + + private Map results() { + HashMap res = new HashMap(); + Project[] prj = OpenProjects.getDefault().getOpenProjects(); + for (Project project : prj) { + //TODO ask jtulach why this lookup query fails.. + ExtraProjectSourceForBinaryQueryImpl impl = project.getLookup().lookup(ExtraProjectSourceForBinaryQueryImpl.class); + //workaround to make it works.. + if (impl == null) { + for (SourceForBinaryQueryImplementation im : project.getLookup().lookupAll(SourceForBinaryQueryImplementation.class)) { + if (im instanceof ExtraProjectSourceForBinaryQueryImpl) { + impl = (ExtraProjectSourceForBinaryQueryImpl)im; + } + } + } + if (impl != null) { + SourceForBinaryQuery.Result result = impl.findSourceRoots(binaryRoot); + if (result != null) { + res.put(project, result); + } + } + } + return res; + } + + public void addChangeListener(ChangeListener l) { + assert l != null : "Listener cannot be null"; // NOI18N + cs.addChangeListener(l); + + } + + public void removeChangeListener(ChangeListener l) { + assert l != null : "Listener cannot be null"; // NOI18N + cs.removeChangeListener(l); + } + + } + +} Index: java/project/src/org/netbeans/spi/java/project/support/ExtraSourceJavadocSupport.java diff -u /dev/null java/project/src/org/netbeans/spi/java/project/support/ExtraSourceJavadocSupport.java:1.1.2.1 --- /dev/null Mon Jan 14 06:07:37 2008 +++ java/project/src/org/netbeans/spi/java/project/support/ExtraSourceJavadocSupport.java Fri Jan 11 03:26:47 2008 @@ -0,0 +1,85 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.java.project.support; + +import org.netbeans.modules.java.project.ExtraProjectSourceForBinaryQueryImpl; +import org.netbeans.modules.java.project.ExtraProjectJavadocForBinaryQueryImpl; +import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; +import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; + +/** + * Utility factory class for ant-based project implementors, the created instances, once + * put into project's lookup, make sure the javadoc and source references in project properties + * are correctly recognized and used by the java infrastructure. + * The format of project properties used is as follows: + *
    + *
  • file.reference.__jarName__ - the binary file reference used to point to files on project classpath.
  • + *
  • javadoc.reference.__jarName__ - the file reference pointing to javadoc for file.reference.__jarName__
  • + *
  • source.reference.__jarName__ - the file reference pointing to sources for file.reference.__jarName__
  • + *
+ * @author mkleint + */ +public class ExtraSourceJavadocSupport { + + /** + * Create project's SourceForBinaryQueryImplementation object for handling + * property based sources + * @param helper project's AntProjectHelper instance + * @param eval project's PropertyEvaluator instance + * @return object to use in project's lookup. + */ + public static SourceForBinaryQueryImplementation createExtraSourceQueryImplementation (AntProjectHelper helper, PropertyEvaluator eval) { + return new ExtraProjectSourceForBinaryQueryImpl(helper, eval); + } + + /** + * Create project's JavadocForBinaryQueryImplementation object for handling + * property based javadoc + * @param helper project's AntProjectHelper instance + * @param eval project's PropertyEvaluator instance + * @return object to use in project's lookup. + */ + public static JavadocForBinaryQueryImplementation createExtraJavadocQueryImplementation (AntProjectHelper helper, PropertyEvaluator eval) { + return new ExtraProjectJavadocForBinaryQueryImpl(helper, eval); + } + +} Index: java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties diff -u java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties:1.14 java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties:1.13.8.2 --- java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties:1.14 Mon Oct 1 07:23:26 2007 +++ java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties Wed Dec 5 06:28:09 2007 @@ -56,3 +56,15 @@ IncludeExcludeVisualizerPanel.includesLabel.text=&Includes: IncludeExcludeVisualizerPanel.excludesLabel.text=&Excludes: IncludeExcludeVisualizerPanel.explanation.text=Sample patterns: com/mycorp/, **/doc-files/, **/*.html +EditJarPanel.lblJar.text=Jar/Folder: +EditJarPanel.lblJavadoc.text=&Javadoc: +EditJarPanel.btnJavadoc.text=&Browse... +EditJarPanel.lblSource.text=&Sources: +EditJarPanel.btnSource.text=&Browse... +MakeSharableVisualPanel2.lblJars.text=The following artifacts require action: +MakeSharableVisualPanel2.lblHint.text=The sharability of this projects depends on files listed below. In general it is recommended to store all required files in close proximity of project(s) using them, therefore copy them to shared libraries definition file location. +MakeSharableVisualPanel2.lblDetails.text=Details: +MakeSharableVisualPanel1.lblNote.text=Note: Either choose an existing libraries definition that is shared with other projects or setup a new one.

Ideally the location shall be accessible on other computers using the same path, either relative or absolute. +MakeSharableVisualPanel1.btnDefinition.text=Browse... +MakeSharableVisualPanel1.lblDefinition.text=Sharable Libraries Definition: +LBL_Edit_Jar_Panel_browse=Select jar/folder Index: java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.form diff -u /dev/null java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.form:1.1.2.2 --- /dev/null Mon Jan 14 06:07:37 2008 +++ java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.form Mon Jan 7 00:49:06 2008 @@ -0,0 +1,130 @@ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Index: java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.java diff -u /dev/null java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.java:1.1.2.3 --- /dev/null Mon Jan 14 06:07:37 2008 +++ java/project/src/org/netbeans/spi/java/project/support/ui/EditJarPanel.java Wed Jan 9 00:18:30 2008 @@ -0,0 +1,243 @@ +/* + * EditJarPanel.java + * + * Created on December 5, 2007, 2:17 PM + */ +package org.netbeans.spi.java.project.support.ui; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; +import org.netbeans.api.project.ant.FileChooser; +import org.netbeans.spi.java.project.support.ui.EditJarSupport; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; + +/** + * + * @author mkleint + */ +class EditJarPanel extends javax.swing.JPanel { + + private EditJarSupport.Item item; + private AntProjectHelper helper; + + /** Creates new form EditJarPanel */ + private EditJarPanel() { + initComponents(); + } + + EditJarPanel(EditJarSupport.Item item, AntProjectHelper helper) { + this(); + this.item = item; + this.helper = helper; + txtJar.setText(item.jarFile.getPath()); + if (item.sourceFile != null) { + txtSource.setText(item.sourceFile.getPath()); + } + if (item.javadocFile != null) { + txtJavadoc.setText(item.javadocFile.getPath()); + } + } + + EditJarSupport.Item assignValues() { + if (txtSource.getText() != null && txtSource.getText().trim().length() > 0) { + item.sourceFile = new File(txtSource.getText().trim()); + } else { + item.sourceFile = null; + } + if (txtJavadoc.getText() != null && txtJavadoc.getText().trim().length() > 0) { + item.javadocFile = new File(txtJavadoc.getText().trim()); + } else { + item.javadocFile = null; + } + return item; + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + lblJar = new javax.swing.JLabel(); + txtJar = new javax.swing.JTextField(); + lblJavadoc = new javax.swing.JLabel(); + txtJavadoc = new javax.swing.JTextField(); + btnJavadoc = new javax.swing.JButton(); + lblSource = new javax.swing.JLabel(); + txtSource = new javax.swing.JTextField(); + btnSource = new javax.swing.JButton(); + + lblJar.setLabelFor(txtJar); + org.openide.awt.Mnemonics.setLocalizedText(lblJar, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJar.text")); // NOI18N + + txtJar.setEditable(false); + + lblJavadoc.setLabelFor(txtJavadoc); + org.openide.awt.Mnemonics.setLocalizedText(lblJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJavadoc.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(btnJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnJavadoc.text")); // NOI18N + btnJavadoc.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnJavadocActionPerformed(evt); + } + }); + + lblSource.setLabelFor(txtSource); + org.openide.awt.Mnemonics.setLocalizedText(lblSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblSource.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(btnSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnSource.text")); // NOI18N + btnSource.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSourceActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(lblJar) + .add(lblJavadoc) + .add(lblSource)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(txtSource, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE) + .add(txtJavadoc, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(btnSource) + .add(btnJavadoc))) + .add(txtJar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(lblJar) + .add(txtJar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(lblJavadoc) + .add(btnJavadoc) + .add(txtJavadoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(lblSource) + .add(btnSource) + .add(txtSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + private void btnJavadocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJavadocActionPerformed + // Let user search for the Jar file + FileChooser chooser = new FileChooser(helper, true); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse")); + //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order. + chooser.setAcceptAllFileFilterUsed(false); + chooser.setFileFilter(new SimpleFileFilter( + "Javadoc Entry (folder, ZIP or JAR file)", + new String[]{"ZIP", "JAR"})); // NOI18N + File curDir = helper.resolveFile(item.jarFile.getPath()); + chooser.setCurrentDirectory(curDir); + int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser + + if (option == JFileChooser.APPROVE_OPTION) { + File files[]; + try { + files = chooser.getFiles(); + } catch (IOException ex) { + // TODO: add localized message + Exceptions.printStackTrace(ex); + return; + } + txtJavadoc.setText(files[0].getPath()); + } + + }//GEN-LAST:event_btnJavadocActionPerformed + + private void btnSourceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSourceActionPerformed + FileChooser chooser = new FileChooser(helper, true); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse")); + //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order. + chooser.setAcceptAllFileFilterUsed(false); + chooser.setFileFilter(new SimpleFileFilter( + "Source Entry (folder, ZIP or JAR file)", + new String[]{"ZIP", "JAR"})); // NOI18N + File curDir = helper.resolveFile(item.jarFile.getPath()); + chooser.setCurrentDirectory(curDir); + int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser + + if (option == JFileChooser.APPROVE_OPTION) { + File files[]; + try { + files = chooser.getFiles(); + } catch (IOException ex) { + // TODO: add localized message + Exceptions.printStackTrace(ex); + return; + } + txtSource.setText(files[0].getPath()); + } + + }//GEN-LAST:event_btnSourceActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnJavadoc; + private javax.swing.JButton btnSource; + private javax.swing.JLabel lblJar; + private javax.swing.JLabel lblJavadoc; + private javax.swing.JLabel lblSource; + private javax.swing.JTextField txtJar; + private javax.swing.JTextField txtJavadoc; + private javax.swing.JTextField txtSource; + // End of variables declaration//GEN-END:variables + private static class SimpleFileFilter extends FileFilter { + + private String description; + private Collection extensions; + + public SimpleFileFilter(String description, String[] extensions) { + this.description = description; + this.extensions = Arrays.asList(extensions); + } + + public boolean accept(File f) { + if (f.isDirectory()) { + return true; + } + String name = f.getName(); + int index = name.lastIndexOf('.'); //NOI18N + if (index <= 0 || index == name.length() - 1) { + return false; + } + String extension = name.substring(index + 1).toUpperCase(); + return this.extensions.contains(extension); + } + + public String getDescription() { + return this.description; + } + } +} Index: java/project/src/org/netbeans/spi/java/project/support/ui/EditJarSupport.java diff -u /dev/null java/project/src/org/netbeans/spi/java/project/support/ui/EditJarSupport.java:1.1.2.2 --- /dev/null Mon Jan 14 06:07:37 2008 +++ java/project/src/org/netbeans/spi/java/project/support/ui/EditJarSupport.java Mon Jan 14 02:34:59 2008 @@ -0,0 +1,93 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.java.project.support.ui; + +import java.io.File; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; + +/** + * Factory for creating a dialog for editing jar/folder-based classpath dependencies + * for Ant based projects. Allows to add/modify/remove source and javadoc jars. + * @author mkleint + */ +public final class EditJarSupport { + + /** + * Show dialog that allows to edit source and javadoc jar/folder locations + * for a given jar/folder on the classpath. Returns null when dialog was cancelled, + * otherwise returns EditJarSupport.Item bean with new values. + * + * @param helper + * @param item - bean with currently used values for classpath jar, source and javadoc jars location + * @return null if dialog cancelled, or the original item with modified values + */ + public static Item showEditDialog(AntProjectHelper helper, Item item) { + EditJarPanel panel = new EditJarPanel(item, helper); + DialogDescriptor dd = new DialogDescriptor(panel, "Edit jar reference"); + Object ret = DialogDisplayer.getDefault().notify(dd); + if (DialogDescriptor.OK_OPTION == ret) { + return panel.assignValues(); + } + return null; + } + + /** + * Simple object holding information used for passing information in and out of the + * EditJarSupport.showEditDialog method. + * + */ + public static final class Item { + /** + * classpath file location, can be relative or absolute path (relative to project basedir) + */ + public File jarFile; + /** + * source file location, can be relative or absolute path (relative to project basedir) + */ + public File sourceFile; + /** + * javadoc file location, can be relative or absolute path (relative to project basedir) + */ + public File javadocFile; + } + +}