This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 70497
Collapse All | Expand All

(-)java/project/nbproject/project.xml:1.39 (-1 / +2 lines)
Lines 95-101 Link Here
95
                    <compile-dependency/>
95
                    <compile-dependency/>
96
                    <run-dependency>
96
                    <run-dependency>
97
                        <release-version>1</release-version>
97
                        <release-version>1</release-version>
98
                        <specification-version>1.15</specification-version>
98
                        <specification-version>1.17</specification-version>
99
                    </run-dependency>
99
                    </run-dependency>
100
                </dependency>
100
                </dependency>
101
                <dependency>
101
                <dependency>
Lines 334-339 Link Here
334
                <package>org.netbeans.api.java.project.classpath</package>
334
                <package>org.netbeans.api.java.project.classpath</package>
335
                <package>org.netbeans.spi.java.project.classpath</package>
335
                <package>org.netbeans.spi.java.project.classpath</package>
336
                <package>org.netbeans.spi.java.project.classpath.support</package>
336
                <package>org.netbeans.spi.java.project.classpath.support</package>
337
                <package>org.netbeans.spi.java.project.support</package>
337
                <package>org.netbeans.spi.java.project.support.ui</package>
338
                <package>org.netbeans.spi.java.project.support.ui</package>
338
                <package>org.netbeans.spi.java.project.support.ui.templates</package>
339
                <package>org.netbeans.spi.java.project.support.ui.templates</package>
339
            </public-packages>
340
            </public-packages>
(-)java/project/src/META-INF/services/org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation:1.3 (+2 lines)
Lines 1-2 Link Here
1
org.netbeans.modules.java.project.JavadocForBinaryQueryImpl
1
org.netbeans.modules.java.project.JavadocForBinaryQueryImpl
2
#position=100
2
#position=100
3
org.netbeans.modules.java.project.ExtraJavadocForBinaryQueryImplementation
4
#position=9999
(-)java/project/src/META-INF/services/org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation:1.3 (+2 lines)
Lines 1-2 Link Here
1
org.netbeans.modules.java.project.ProjectSourceForBinaryQuery
1
org.netbeans.modules.java.project.ProjectSourceForBinaryQuery
2
#position=100
2
#position=100
3
org.netbeans.modules.java.project.ExtraSourceForBinaryQueryImplementation
4
#position=6666
(-)/dev/null (+185 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.project;
41
42
import java.beans.PropertyChangeEvent;
43
import org.netbeans.spi.project.support.ant.*;
44
import java.beans.PropertyChangeListener;
45
import java.net.URL;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.HashMap;
49
import java.util.HashSet;
50
import java.util.List;
51
import java.util.Map;
52
import java.util.Set;
53
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
56
import org.netbeans.api.project.Project;
57
import org.netbeans.api.project.ui.OpenProjects;
58
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
59
import org.openide.util.ChangeSupport;
60
import org.openide.util.WeakListeners;
61
62
/**
63
 *
64
 * @author mkleint
65
 */
66
public final class ExtraJavadocForBinaryQueryImplementation implements JavadocForBinaryQueryImplementation {
67
68
    
69
    public ExtraJavadocForBinaryQueryImplementation() {
70
    }
71
72
    /**
73
     * We always return a result here, never null, otherwise we loose the ability to 
74
     * fire a result change when new project gets opened.
75
     * @return
76
     */
77
    public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
78
        return new Result(binaryRoot);
79
    }
80
81
    public static JavadocForBinaryQueryImplementation createProjectInstance(AntProjectHelper helper, PropertyEvaluator evaluator) {
82
        return new ExtraProjectJavadocForBinaryQueryImpl(helper, evaluator);
83
    }
84
85
    private static class Result implements JavadocForBinaryQuery.Result {
86
        
87
        private URL binaryRoot;
88
        private PropertyChangeListener listener;
89
        private final ChangeSupport cs = new ChangeSupport(this);
90
        private Map<Project, JavadocForBinaryQuery.Result> cachedResults;
91
        private final Object LOCK = new Object();
92
        private ChangeListener changeListener;
93
        
94
95
        private Result(URL binaryRoot) {
96
            this.binaryRoot = binaryRoot;
97
            changeListener = new ChangeListener() {
98
                public void stateChanged(ChangeEvent e) {
99
                    cs.fireChange();
100
                }
101
            };
102
            
103
            listener = new PropertyChangeListener() {
104
                public void propertyChange( PropertyChangeEvent evt ) {
105
                    if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) {
106
                        synchronized (LOCK) {
107
                            if (cachedResults != null) {
108
                                Map<Project, JavadocForBinaryQuery.Result> newRes = results();
109
                                Set<Project> oldprjs = new HashSet<Project>(cachedResults.keySet());
110
                                Set<Project> newprjs = new HashSet<Project>(newRes.keySet());
111
                                newprjs.removeAll(cachedResults.keySet());
112
                                oldprjs.removeAll(newRes.keySet());
113
                                for (Project p : oldprjs) {
114
                                    JavadocForBinaryQuery.Result res = cachedResults.get(p);
115
                                    res.removeChangeListener(changeListener);
116
                                }
117
                                for (Project p : newprjs) {
118
                                    JavadocForBinaryQuery.Result res = newRes.get(p);
119
                                    res.addChangeListener(changeListener);
120
                                }
121
                                cachedResults = newRes; 
122
                            }
123
                        }
124
                        cs.fireChange();
125
                    }
126
                }
127
            };
128
            OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(listener, OpenProjects.getDefault()));
129
        }
130
131
        public URL[] getRoots() {
132
            List<URL> fos = new ArrayList<URL>();
133
            synchronized (LOCK) {
134
                if (cachedResults == null) {
135
                    cachedResults = results();
136
                    for (JavadocForBinaryQuery.Result result : cachedResults.values()) {
137
                        result.addChangeListener(changeListener);
138
                    }
139
                }
140
                for (JavadocForBinaryQuery.Result result : cachedResults.values()) {
141
                    URL[] f = result.getRoots();
142
                    fos.addAll(Arrays.asList(f));
143
                }
144
            }
145
            return fos.toArray(new URL[fos.size()]);
146
        }
147
        
148
        private Map<Project, JavadocForBinaryQuery.Result> results() {
149
            HashMap<Project, JavadocForBinaryQuery.Result> res = new HashMap<Project,JavadocForBinaryQuery.Result>();
150
            Project[] prj = OpenProjects.getDefault().getOpenProjects();
151
            for (Project project : prj) {
152
                //TODO ask jtulach why this lookup query fails..
153
                ExtraProjectJavadocForBinaryQueryImpl impl = project.getLookup().lookup(ExtraProjectJavadocForBinaryQueryImpl.class);
154
                //workaround to make it works..
155
                if (impl == null) {
156
                    for (JavadocForBinaryQueryImplementation im : project.getLookup().lookupAll(JavadocForBinaryQueryImplementation.class)) {
157
                        if (im instanceof ExtraProjectJavadocForBinaryQueryImpl) {
158
                            impl = (ExtraProjectJavadocForBinaryQueryImpl)im;
159
                        }
160
                    }   
161
                }
162
                if (impl != null) {
163
                    JavadocForBinaryQuery.Result result = impl.findJavadoc(binaryRoot);
164
                    if (result != null) {
165
                        res.put(project, result);
166
                    }
167
                }
168
            }
169
            return res;
170
        }
171
172
        public void addChangeListener(ChangeListener l) {
173
            assert l != null : "Listener cannot be null"; // NOI18N
174
            cs.addChangeListener(l);
175
            
176
        }
177
178
        public void removeChangeListener(ChangeListener l) {
179
            assert l != null : "Listener cannot be null"; // NOI18N
180
            cs.removeChangeListener(l);
181
        }
182
        
183
    }
184
185
}
(-)/dev/null (+199 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.project;
41
42
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeListener;
44
import java.net.MalformedURLException;
45
import org.netbeans.api.java.queries.JavadocForBinaryQuery;
46
import org.netbeans.spi.project.support.ant.*;
47
import java.io.File;
48
import java.net.URI;
49
import java.net.URL;
50
import java.util.ArrayList;
51
import java.util.Collection;
52
import java.util.HashMap;
53
import java.util.Map;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
56
import org.netbeans.spi.project.ui.ProjectOpenedHook;
57
import org.openide.filesystems.FileUtil;
58
import org.openide.util.ChangeSupport;
59
import org.openide.util.Exceptions;
60
61
/**
62
 *
63
 * @author mkleint
64
 */
65
public final class ExtraProjectJavadocForBinaryQueryImpl extends ProjectOpenedHook implements JavadocForBinaryQueryImplementation {
66
67
    private static final String REF_START = "file.reference."; //NOI18N
68
    private static final String JAVADOC_START = "javadoc.reference."; //NOI18N
69
    
70
    private final AntProjectHelper helper;
71
    private final PropertyEvaluator evaluator;
72
    private Map<URL,ExtraResult>  cache = new HashMap<URL,ExtraResult>();
73
    private PropertyChangeListener listener;
74
    private Map<URL, URI> mappings = new HashMap<URL, URI>();
75
76
    public ExtraProjectJavadocForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) {
77
        this.helper = helper;
78
        this.evaluator = evaluator;
79
        listener = new PropertyChangeListener() {
80
            public void propertyChange(PropertyChangeEvent evt) {
81
                if (evt.getPropertyName() == null || evt.getPropertyName().startsWith(JAVADOC_START)) {
82
                    mappings = getExtraSources();
83
                    Collection<ExtraResult> results = null;
84
                    synchronized (cache) {
85
                        results = new ArrayList<ExtraResult>(cache.values());
86
                    }
87
                    for (ExtraResult res : results) {
88
                        res.fire();
89
                    }
90
                }
91
            }
92
            
93
        };
94
        
95
    }
96
97
    /**
98
     * return null only if the javadoc and also the binary url are missing in project..
99
     * @param binaryRoot
100
     * @return
101
     */
102
    public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) {
103
        synchronized (cache) {
104
            ExtraResult res = cache.get(binaryRoot);
105
            if (res != null) {
106
                return res;
107
            }
108
            if (mappings.containsKey(binaryRoot)) {
109
                res = new ExtraResult(binaryRoot);
110
                cache.put (binaryRoot, res);
111
                return res;
112
            }
113
        }
114
        return null;
115
    }
116
    
117
    @Override
118
    protected void projectOpened() {
119
        mappings = getExtraSources();
120
        evaluator.addPropertyChangeListener(listener);
121
    }
122
123
    @Override
124
    protected void projectClosed()
125
    {
126
        mappings = new HashMap<URL, URI>();
127
        evaluator.removePropertyChangeListener(listener);
128
    }
129
    
130
131
    Map<URL, URI> getExtraSources() {
132
        Map<URL, URI> result = new HashMap<URL, URI>();
133
        Map<String, String> props = evaluator.getProperties();
134
        for (Map.Entry<String, String> entry : props.entrySet()) {
135
            if (entry.getKey().startsWith(REF_START)) {
136
                String val = entry.getKey().substring(REF_START.length());
137
                String sourceKey = JAVADOC_START + val;
138
                String source = props.get(sourceKey);
139
                try {
140
                    File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
141
                    URL binURL = bin.toURI().toURL();
142
                    if (FileUtil.isArchiveFile(binURL)) {
143
                        binURL = FileUtil.getArchiveRoot(binURL);
144
                    }
145
                    if (source != null) {
146
                        File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
147
                        result.put(binURL, src.toURI());
148
                    } else {
149
                        result.put(binURL, null);
150
                    }
151
                } catch (MalformedURLException ex) {
152
                    Exceptions.printStackTrace(ex);
153
                }
154
            }
155
        }
156
        return result;
157
    }
158
    
159
    private class ExtraResult implements JavadocForBinaryQuery.Result {
160
        private URL binaryroot;
161
        private ChangeSupport chs = new ChangeSupport(this);
162
        
163
        
164
        public ExtraResult(URL binary) {
165
            binaryroot = binary;
166
        }
167
168
        public URL[] getRoots() {
169
            URI source = mappings.get(binaryroot);
170
            if (source != null) {
171
                try
172
                {
173
                    URL url = source.toURL();
174
                    if (FileUtil.isArchiveFile(url)) {
175
                        url = FileUtil.getArchiveRoot(url);
176
                    }
177
                    return new URL[] { url };
178
                } catch ( MalformedURLException ex )
179
                {
180
                    Exceptions.printStackTrace( ex );
181
                }
182
            }
183
            return new URL[0];
184
        }
185
186
        public void fire() {
187
            chs.fireChange();
188
        }
189
190
        public void addChangeListener(ChangeListener l) {
191
            chs.addChangeListener(l);
192
        }
193
194
        public void removeChangeListener(ChangeListener l) {
195
            chs.removeChangeListener(l);
196
        }
197
        
198
    }
199
}
(-)/dev/null (+209 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.project;
41
42
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeListener;
44
import java.net.MalformedURLException;
45
import java.io.File;
46
import java.net.URI;
47
import java.net.URL;
48
import java.util.ArrayList;
49
import java.util.Collection;
50
import java.util.HashMap;
51
import java.util.Map;
52
import javax.swing.event.ChangeListener;
53
import org.netbeans.api.java.queries.SourceForBinaryQuery;
54
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
55
import org.netbeans.spi.project.support.ant.AntProjectHelper;
56
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
57
import org.netbeans.spi.project.support.ant.PropertyUtils;
58
import org.netbeans.spi.project.ui.ProjectOpenedHook;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.URLMapper;
62
import org.openide.util.ChangeSupport;
63
import org.openide.util.Exceptions;
64
65
/**
66
 *
67
 * @author mkleint
68
 */
69
public final class ExtraProjectSourceForBinaryQueryImpl extends ProjectOpenedHook implements SourceForBinaryQueryImplementation {
70
71
    private static final String REF_START = "file.reference."; //NOI18N
72
    private static final String SOURCE_START = "source.reference."; //NOI18N
73
    
74
    private final AntProjectHelper helper;
75
    private final PropertyEvaluator evaluator;
76
    private Map<URL,ExtraResult>  cache = new HashMap<URL,ExtraResult>();
77
    private PropertyChangeListener listener;
78
    private Map<URL, URI> mappings = new HashMap<URL, URI>();
79
80
    public ExtraProjectSourceForBinaryQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator) {
81
        this.helper = helper;
82
        this.evaluator = evaluator;
83
        listener = new PropertyChangeListener() {
84
            public void propertyChange(PropertyChangeEvent evt) {
85
                if (evt.getPropertyName() == null || evt.getPropertyName().startsWith(SOURCE_START)) {
86
                    mappings = getExtraSources();
87
                    Collection<ExtraResult> results = null;
88
                    synchronized (cache) {
89
                        results = new ArrayList<ExtraResult>(cache.values());
90
                    }
91
                    for (ExtraResult res : results) {
92
                        res.fire();
93
                    }
94
                }
95
            }
96
            
97
        };
98
    }
99
100
    /**
101
     * 
102
     * returns a result even if only the binary root is found in the project.
103
     * only returns null when the binary root is missing from project altogether.
104
     * @param binaryRoot
105
     * @return
106
     */
107
    public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
108
        synchronized (cache) {
109
            ExtraResult res = cache.get(binaryRoot);
110
            if (res != null) {
111
                return res;
112
            }
113
            if (mappings.containsKey(binaryRoot)) {
114
                res = new ExtraResult(binaryRoot);
115
                cache.put (binaryRoot, res);
116
                return res;
117
            }
118
        }
119
        return null;
120
    }
121
    
122
    @Override
123
    protected void projectOpened() {
124
        mappings = getExtraSources();
125
        evaluator.addPropertyChangeListener(listener);
126
    }
127
128
    @Override
129
    protected void projectClosed()   {
130
        mappings = new HashMap<URL, URI>();
131
        evaluator.removePropertyChangeListener(listener);
132
    }
133
    
134
135
    Map<URL, URI> getExtraSources() {
136
        Map<URL, URI> result = new HashMap<URL, URI>();
137
        Map<String, String> props = evaluator.getProperties();
138
        for (Map.Entry<String, String> entry : props.entrySet()) {
139
            if (entry.getKey().startsWith(REF_START)) {
140
                String val = entry.getKey().substring(REF_START.length());
141
                String sourceKey = SOURCE_START + val;
142
                String source = props.get(sourceKey);
143
                File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
144
                try {
145
                    URL binURL = bin.toURI().toURL();
146
                    if (FileUtil.isArchiveFile(binURL)) {
147
                        binURL = FileUtil.getArchiveRoot(binURL);
148
                    }
149
                    if (source != null) {
150
                        File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
151
                        result.put(binURL, src.toURI());
152
                    } else {
153
                        result.put(binURL, null);
154
                    }
155
                } catch (MalformedURLException ex) {
156
                    Exceptions.printStackTrace(ex);
157
                }
158
            }
159
        }
160
        return result;
161
    }
162
    
163
    private class ExtraResult implements SourceForBinaryQuery.Result {
164
        private URL binaryroot;
165
        private ChangeSupport chs = new ChangeSupport(this);
166
        
167
        public ExtraResult(URL binary) {
168
            binaryroot = binary;
169
        }
170
171
        public FileObject[] getRoots() {
172
            URI source = mappings.get(binaryroot);
173
            if (source != null) {
174
                try
175
                {
176
                    URL url = source.toURL();
177
                    if (FileUtil.isArchiveFile(url)) {
178
                        url = FileUtil.getArchiveRoot(url);
179
                    }
180
                    FileObject fo = URLMapper.findFileObject(url);
181
                    if ( fo != null )
182
                    {
183
                        return new FileObject[]{fo};
184
                    }
185
                } catch ( MalformedURLException ex )
186
                {
187
                    Exceptions.printStackTrace( ex );
188
                }
189
            }
190
            return new FileObject[0];
191
        }
192
        
193
        public void fire() {
194
            chs.fireChange();
195
        }
196
197
        public void addChangeListener(ChangeListener l) {
198
            chs.addChangeListener(l);
199
        }
200
201
        public void removeChangeListener(ChangeListener l) {
202
            chs.removeChangeListener(l);
203
        }
204
        
205
    }
206
207
208
209
}
(-)/dev/null (+185 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.project;
41
42
import java.beans.PropertyChangeEvent;
43
import javax.swing.event.ChangeEvent;
44
import org.netbeans.spi.project.support.ant.*;
45
import java.beans.PropertyChangeListener;
46
import java.net.URL;
47
import java.util.ArrayList;
48
import java.util.Arrays;
49
import java.util.HashMap;
50
import java.util.HashSet;
51
import java.util.List;
52
import java.util.Map;
53
import java.util.Set;
54
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.java.queries.SourceForBinaryQuery;
56
import org.netbeans.api.project.Project;
57
import org.netbeans.api.project.ui.OpenProjects;
58
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
59
import org.openide.filesystems.FileObject;
60
import org.openide.util.ChangeSupport;
61
import org.openide.util.WeakListeners;
62
63
/**
64
 *
65
 * @author mkleint
66
 */
67
public final class ExtraSourceForBinaryQueryImplementation implements SourceForBinaryQueryImplementation {
68
69
    
70
    public ExtraSourceForBinaryQueryImplementation() {
71
    }
72
    
73
     /**
74
     * We always return a result here, never null, otherwise we loose the ability to 
75
     * fire a result change when new project gets opened.
76
     * @return
77
     */
78
    public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) {
79
        return new Result(binaryRoot);
80
    }
81
    
82
    public static SourceForBinaryQueryImplementation createProjectInstance(AntProjectHelper helper, PropertyEvaluator evaluator) {
83
        return new ExtraProjectSourceForBinaryQueryImpl(helper, evaluator);
84
    }
85
86
    private static class Result implements SourceForBinaryQuery.Result {
87
        
88
        private URL binaryRoot;
89
        private PropertyChangeListener listener;
90
        private final ChangeSupport cs = new ChangeSupport(this);
91
        private Map<Project, SourceForBinaryQuery.Result> cachedResults;
92
        private final Object LOCK = new Object();
93
        private ChangeListener changeListener;
94
95
        private Result(URL binaryRoot) {
96
            this.binaryRoot = binaryRoot;
97
            changeListener = new ChangeListener() {
98
                public void stateChanged(ChangeEvent e) {
99
                    cs.fireChange();
100
                }
101
                
102
            };
103
            listener = new PropertyChangeListener() {
104
                public void propertyChange( PropertyChangeEvent evt ) {
105
                    if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName())) {
106
                        synchronized (LOCK) {
107
                            if (cachedResults != null) {
108
                                Map<Project, SourceForBinaryQuery.Result> newRes = results();
109
                                Set<Project> oldprjs = new HashSet<Project>(cachedResults.keySet());
110
                                Set<Project> newprjs = new HashSet<Project>(newRes.keySet());
111
                                newprjs.removeAll(cachedResults.keySet());
112
                                oldprjs.removeAll(newRes.keySet());
113
                                for (Project p : oldprjs) {
114
                                    SourceForBinaryQuery.Result res = cachedResults.get(p);
115
                                    res.removeChangeListener(changeListener);
116
                                }
117
                                for (Project p : newprjs) {
118
                                    SourceForBinaryQuery.Result res = newRes.get(p);
119
                                    res.addChangeListener(changeListener);
120
                                }
121
                                cachedResults = newRes; 
122
                            }
123
                        }
124
                        cs.fireChange();
125
                    }
126
                }
127
            };
128
            OpenProjects.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(listener, OpenProjects.getDefault()));
129
        }
130
131
        public FileObject[] getRoots() {
132
            List<FileObject> fos = new ArrayList<FileObject>();
133
            synchronized (LOCK) {
134
                if (cachedResults == null) {
135
                    cachedResults = results();
136
                    for (SourceForBinaryQuery.Result result : cachedResults.values()) {
137
                        result.addChangeListener(changeListener);
138
                    }
139
                }
140
                for (SourceForBinaryQuery.Result result : cachedResults.values()) {
141
                    FileObject[] f = result.getRoots();
142
                    fos.addAll(Arrays.asList(f));
143
                }
144
            }
145
            return fos.toArray(new FileObject[fos.size()]);
146
        }
147
        
148
        private Map<Project, SourceForBinaryQuery.Result> results() {
149
            HashMap<Project, SourceForBinaryQuery.Result> res = new HashMap<Project,SourceForBinaryQuery.Result>();
150
            Project[] prj = OpenProjects.getDefault().getOpenProjects();
151
            for (Project project : prj) {
152
                //TODO ask jtulach why this lookup query fails..
153
                ExtraProjectSourceForBinaryQueryImpl impl = project.getLookup().lookup(ExtraProjectSourceForBinaryQueryImpl.class);
154
                //workaround to make it works..
155
                if (impl == null) {
156
                    for (SourceForBinaryQueryImplementation im : project.getLookup().lookupAll(SourceForBinaryQueryImplementation.class)) {
157
                        if (im instanceof ExtraProjectSourceForBinaryQueryImpl) {
158
                            impl = (ExtraProjectSourceForBinaryQueryImpl)im;
159
                        }
160
                    }   
161
                }
162
                if (impl != null) {
163
                    SourceForBinaryQuery.Result result = impl.findSourceRoots(binaryRoot);
164
                    if (result != null) {
165
                        res.put(project, result);
166
                    }
167
                }
168
            }
169
            return res;
170
        }
171
172
        public void addChangeListener(ChangeListener l) {
173
            assert l != null : "Listener cannot be null"; // NOI18N
174
            cs.addChangeListener(l);
175
            
176
        }
177
178
        public void removeChangeListener(ChangeListener l) {
179
            assert l != null : "Listener cannot be null"; // NOI18N
180
            cs.removeChangeListener(l);
181
        }
182
        
183
    }
184
185
}
(-)/dev/null (+85 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support;
41
42
import org.netbeans.modules.java.project.ExtraProjectSourceForBinaryQueryImpl;
43
import org.netbeans.modules.java.project.ExtraProjectJavadocForBinaryQueryImpl;
44
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
45
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation;
46
import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
48
49
/**
50
 * Utility factory class for ant-based project implementors, the created instances, once
51
 * put into project's lookup, make sure the javadoc and source references in project properties
52
 * are correctly recognized and used by the java infrastructure.
53
 * The format of project properties used is as follows:
54
 * <ul>
55
 *      <li>file.reference.__jarName__ - the binary file reference used to point to files on project classpath. </li>
56
 *      <li>javadoc.reference.__jarName__ - the file reference pointing to javadoc for file.reference.__jarName__ </li>
57
 *      <li>source.reference.__jarName__ - the file reference pointing to sources for file.reference.__jarName__ </li>
58
 * </ul>
59
 * @author mkleint
60
 */
61
public class ExtraSourceJavadocSupport {
62
63
    /**
64
     * Create project's SourceForBinaryQueryImplementation object for handling 
65
     * property based sources
66
     * @param helper project's AntProjectHelper instance
67
     * @param eval project's PropertyEvaluator instance
68
     * @return object to use in project's lookup.
69
     */
70
    public static SourceForBinaryQueryImplementation createExtraSourceQueryImplementation (AntProjectHelper helper, PropertyEvaluator eval) {
71
        return new ExtraProjectSourceForBinaryQueryImpl(helper, eval);
72
    }
73
    
74
    /**
75
     * Create project's JavadocForBinaryQueryImplementation object for handling 
76
     * property based javadoc
77
     * @param helper project's AntProjectHelper instance
78
     * @param eval project's PropertyEvaluator instance
79
     * @return object to use in project's lookup.
80
     */
81
    public static JavadocForBinaryQueryImplementation createExtraJavadocQueryImplementation (AntProjectHelper helper, PropertyEvaluator eval) {
82
        return new ExtraProjectJavadocForBinaryQueryImpl(helper, eval);
83
    }
84
    
85
}
(-)java/project/src/org/netbeans/spi/java/project/support/ui/Bundle.properties:1.14 (+12 lines)
Lines 56-58 Link Here
56
IncludeExcludeVisualizerPanel.includesLabel.text=&Includes:
56
IncludeExcludeVisualizerPanel.includesLabel.text=&Includes:
57
IncludeExcludeVisualizerPanel.excludesLabel.text=&Excludes:
57
IncludeExcludeVisualizerPanel.excludesLabel.text=&Excludes:
58
IncludeExcludeVisualizerPanel.explanation.text=Sample patterns: com/mycorp/, **/doc-files/, **/*.html
58
IncludeExcludeVisualizerPanel.explanation.text=Sample patterns: com/mycorp/, **/doc-files/, **/*.html
59
EditJarPanel.lblJar.text=Jar/Folder:
60
EditJarPanel.lblJavadoc.text=&Javadoc:
61
EditJarPanel.btnJavadoc.text=&Browse...
62
EditJarPanel.lblSource.text=&Sources:
63
EditJarPanel.btnSource.text=&Browse...
64
MakeSharableVisualPanel2.lblJars.text=<html><b>The following artifacts require action:</b></html>
65
MakeSharableVisualPanel2.lblHint.text=<html>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.</html>
66
MakeSharableVisualPanel2.lblDetails.text=Details:
67
MakeSharableVisualPanel1.lblNote.text=<html>Note: Either choose an existing libraries definition that is shared with other projects or setup a new one. <p>Ideally the location shall be accessible on other computers using the same path, either relative or absolute.</html>
68
MakeSharableVisualPanel1.btnDefinition.text=Browse...
69
MakeSharableVisualPanel1.lblDefinition.text=Sharable Libraries Definition:
70
LBL_Edit_Jar_Panel_browse=Select jar/folder
(-)/dev/null (+130 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
10
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
11
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
12
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
13
  </AuxValues>
14
15
  <Layout>
16
    <DimensionLayout dim="0">
17
      <Group type="103" groupAlignment="0" attributes="0">
18
          <Group type="102" attributes="0">
19
              <EmptySpace max="-2" attributes="0"/>
20
              <Group type="103" groupAlignment="0" attributes="0">
21
                  <Component id="lblJar" alignment="0" min="-2" max="-2" attributes="0"/>
22
                  <Component id="lblJavadoc" alignment="0" min="-2" max="-2" attributes="0"/>
23
                  <Component id="lblSource" alignment="0" min="-2" max="-2" attributes="0"/>
24
              </Group>
25
              <EmptySpace max="-2" attributes="0"/>
26
              <Group type="103" groupAlignment="0" attributes="0">
27
                  <Group type="102" attributes="0">
28
                      <Group type="103" groupAlignment="0" attributes="0">
29
                          <Component id="txtSource" alignment="0" pref="320" max="32767" attributes="0"/>
30
                          <Component id="txtJavadoc" alignment="0" pref="320" max="32767" attributes="0"/>
31
                      </Group>
32
                      <EmptySpace max="-2" attributes="0"/>
33
                      <Group type="103" groupAlignment="0" attributes="0">
34
                          <Component id="btnSource" min="-2" max="-2" attributes="0"/>
35
                          <Component id="btnJavadoc" alignment="0" min="-2" max="-2" attributes="0"/>
36
                      </Group>
37
                  </Group>
38
                  <Component id="txtJar" pref="407" max="32767" attributes="0"/>
39
              </Group>
40
              <EmptySpace max="-2" attributes="0"/>
41
          </Group>
42
      </Group>
43
    </DimensionLayout>
44
    <DimensionLayout dim="1">
45
      <Group type="103" groupAlignment="0" attributes="0">
46
          <Group type="102" attributes="0">
47
              <EmptySpace max="-2" attributes="0"/>
48
              <Group type="103" groupAlignment="3" attributes="0">
49
                  <Component id="lblJar" alignment="3" min="-2" max="-2" attributes="0"/>
50
                  <Component id="txtJar" alignment="3" min="-2" max="-2" attributes="0"/>
51
              </Group>
52
              <EmptySpace type="separate" max="-2" attributes="0"/>
53
              <Group type="103" groupAlignment="3" attributes="0">
54
                  <Component id="lblJavadoc" alignment="3" min="-2" max="-2" attributes="0"/>
55
                  <Component id="btnJavadoc" alignment="3" min="-2" max="-2" attributes="0"/>
56
                  <Component id="txtJavadoc" alignment="3" min="-2" max="-2" attributes="0"/>
57
              </Group>
58
              <EmptySpace max="-2" attributes="0"/>
59
              <Group type="103" groupAlignment="3" attributes="0">
60
                  <Component id="lblSource" alignment="3" min="-2" max="-2" attributes="0"/>
61
                  <Component id="btnSource" alignment="3" min="-2" max="-2" attributes="0"/>
62
                  <Component id="txtSource" alignment="3" min="-2" max="-2" attributes="0"/>
63
              </Group>
64
              <EmptySpace max="32767" attributes="0"/>
65
          </Group>
66
      </Group>
67
    </DimensionLayout>
68
  </Layout>
69
  <SubComponents>
70
    <Component class="javax.swing.JLabel" name="lblJar">
71
      <Properties>
72
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
73
          <ComponentRef name="txtJar"/>
74
        </Property>
75
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
76
          <ResourceString bundle="org/netbeans/spi/java/project/support/ui/Bundle.properties" key="EditJarPanel.lblJar.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
77
        </Property>
78
      </Properties>
79
    </Component>
80
    <Component class="javax.swing.JTextField" name="txtJar">
81
      <Properties>
82
        <Property name="editable" type="boolean" value="false"/>
83
      </Properties>
84
    </Component>
85
    <Component class="javax.swing.JLabel" name="lblJavadoc">
86
      <Properties>
87
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
88
          <ComponentRef name="txtJavadoc"/>
89
        </Property>
90
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
91
          <ResourceString bundle="org/netbeans/spi/java/project/support/ui/Bundle.properties" key="EditJarPanel.lblJavadoc.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
92
        </Property>
93
      </Properties>
94
    </Component>
95
    <Component class="javax.swing.JTextField" name="txtJavadoc">
96
    </Component>
97
    <Component class="javax.swing.JButton" name="btnJavadoc">
98
      <Properties>
99
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
100
          <ResourceString bundle="org/netbeans/spi/java/project/support/ui/Bundle.properties" key="EditJarPanel.btnJavadoc.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
101
        </Property>
102
      </Properties>
103
      <Events>
104
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnJavadocActionPerformed"/>
105
      </Events>
106
    </Component>
107
    <Component class="javax.swing.JLabel" name="lblSource">
108
      <Properties>
109
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
110
          <ComponentRef name="txtSource"/>
111
        </Property>
112
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
113
          <ResourceString bundle="org/netbeans/spi/java/project/support/ui/Bundle.properties" key="EditJarPanel.lblSource.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
114
        </Property>
115
      </Properties>
116
    </Component>
117
    <Component class="javax.swing.JTextField" name="txtSource">
118
    </Component>
119
    <Component class="javax.swing.JButton" name="btnSource">
120
      <Properties>
121
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
122
          <ResourceString bundle="org/netbeans/spi/java/project/support/ui/Bundle.properties" key="EditJarPanel.btnSource.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
123
        </Property>
124
      </Properties>
125
      <Events>
126
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSourceActionPerformed"/>
127
      </Events>
128
    </Component>
129
  </SubComponents>
130
</Form>
(-)/dev/null (+243 lines)
Added Link Here
1
/*
2
 * EditJarPanel.java
3
 *
4
 * Created on December 5, 2007, 2:17 PM
5
 */
6
package org.netbeans.spi.java.project.support.ui;
7
8
import java.io.File;
9
import java.io.IOException;
10
import java.util.Arrays;
11
import java.util.Collection;
12
import javax.swing.JFileChooser;
13
import javax.swing.SwingUtilities;
14
import javax.swing.filechooser.FileFilter;
15
import org.netbeans.api.project.ant.FileChooser;
16
import org.netbeans.spi.java.project.support.ui.EditJarSupport;
17
import org.netbeans.spi.project.support.ant.AntProjectHelper;
18
import org.openide.filesystems.FileUtil;
19
import org.openide.util.Exceptions;
20
import org.openide.util.NbBundle;
21
22
/**
23
 *
24
 * @author  mkleint
25
 */
26
class EditJarPanel extends javax.swing.JPanel {
27
28
    private EditJarSupport.Item item;
29
    private AntProjectHelper helper;
30
31
    /** Creates new form EditJarPanel */
32
    private EditJarPanel() {
33
        initComponents();
34
    }
35
36
    EditJarPanel(EditJarSupport.Item item, AntProjectHelper helper) {
37
        this();
38
        this.item = item;
39
        this.helper = helper;
40
        txtJar.setText(item.jarFile.getPath());
41
        if (item.sourceFile != null) {
42
            txtSource.setText(item.sourceFile.getPath());
43
        }
44
        if (item.javadocFile != null) {
45
            txtJavadoc.setText(item.javadocFile.getPath());
46
        }
47
    }
48
49
    EditJarSupport.Item assignValues() {
50
        if (txtSource.getText() != null && txtSource.getText().trim().length() > 0) {
51
            item.sourceFile = new File(txtSource.getText().trim());
52
        } else {
53
            item.sourceFile = null;
54
        }
55
        if (txtJavadoc.getText() != null && txtJavadoc.getText().trim().length() > 0) {
56
            item.javadocFile = new File(txtJavadoc.getText().trim());
57
        } else {
58
            item.javadocFile = null;
59
        }
60
        return item;
61
    }
62
63
    /** This method is called from within the constructor to
64
     * initialize the form.
65
     * WARNING: Do NOT modify this code. The content of this method is
66
     * always regenerated by the Form Editor.
67
     */
68
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
69
    private void initComponents() {
70
71
        lblJar = new javax.swing.JLabel();
72
        txtJar = new javax.swing.JTextField();
73
        lblJavadoc = new javax.swing.JLabel();
74
        txtJavadoc = new javax.swing.JTextField();
75
        btnJavadoc = new javax.swing.JButton();
76
        lblSource = new javax.swing.JLabel();
77
        txtSource = new javax.swing.JTextField();
78
        btnSource = new javax.swing.JButton();
79
80
        lblJar.setLabelFor(txtJar);
81
        org.openide.awt.Mnemonics.setLocalizedText(lblJar, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJar.text")); // NOI18N
82
83
        txtJar.setEditable(false);
84
85
        lblJavadoc.setLabelFor(txtJavadoc);
86
        org.openide.awt.Mnemonics.setLocalizedText(lblJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblJavadoc.text")); // NOI18N
87
88
        org.openide.awt.Mnemonics.setLocalizedText(btnJavadoc, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnJavadoc.text")); // NOI18N
89
        btnJavadoc.addActionListener(new java.awt.event.ActionListener() {
90
            public void actionPerformed(java.awt.event.ActionEvent evt) {
91
                btnJavadocActionPerformed(evt);
92
            }
93
        });
94
95
        lblSource.setLabelFor(txtSource);
96
        org.openide.awt.Mnemonics.setLocalizedText(lblSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.lblSource.text")); // NOI18N
97
98
        org.openide.awt.Mnemonics.setLocalizedText(btnSource, org.openide.util.NbBundle.getMessage(EditJarPanel.class, "EditJarPanel.btnSource.text")); // NOI18N
99
        btnSource.addActionListener(new java.awt.event.ActionListener() {
100
            public void actionPerformed(java.awt.event.ActionEvent evt) {
101
                btnSourceActionPerformed(evt);
102
            }
103
        });
104
105
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
106
        this.setLayout(layout);
107
        layout.setHorizontalGroup(
108
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
109
            .add(layout.createSequentialGroup()
110
                .addContainerGap()
111
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
112
                    .add(lblJar)
113
                    .add(lblJavadoc)
114
                    .add(lblSource))
115
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
116
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
117
                    .add(layout.createSequentialGroup()
118
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
119
                            .add(txtSource, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
120
                            .add(txtJavadoc, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
121
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
122
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
123
                            .add(btnSource)
124
                            .add(btnJavadoc)))
125
                    .add(txtJar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
126
                .addContainerGap())
127
        );
128
        layout.setVerticalGroup(
129
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
130
            .add(layout.createSequentialGroup()
131
                .addContainerGap()
132
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
133
                    .add(lblJar)
134
                    .add(txtJar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
135
                .add(18, 18, 18)
136
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
137
                    .add(lblJavadoc)
138
                    .add(btnJavadoc)
139
                    .add(txtJavadoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
140
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
141
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
142
                    .add(lblSource)
143
                    .add(btnSource)
144
                    .add(txtSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
145
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
146
        );
147
    }// </editor-fold>//GEN-END:initComponents
148
    private void btnJavadocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJavadocActionPerformed
149
        // Let user search for the Jar file
150
        FileChooser chooser = new FileChooser(helper, true);
151
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
152
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
153
        chooser.setMultiSelectionEnabled(false);
154
        chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse"));
155
        //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
156
        chooser.setAcceptAllFileFilterUsed(false);
157
        chooser.setFileFilter(new SimpleFileFilter(
158
                "Javadoc Entry (folder, ZIP or JAR file)", 
159
                new String[]{"ZIP", "JAR"}));   // NOI18N 
160
        File curDir = helper.resolveFile(item.jarFile.getPath());
161
        chooser.setCurrentDirectory(curDir);
162
        int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
163
164
        if (option == JFileChooser.APPROVE_OPTION) {
165
            File files[];
166
            try {
167
                files = chooser.getFiles();
168
            } catch (IOException ex) {
169
                // TODO: add localized message
170
                Exceptions.printStackTrace(ex);
171
                return;
172
            }
173
            txtJavadoc.setText(files[0].getPath());
174
        }
175
        
176
    }//GEN-LAST:event_btnJavadocActionPerformed
177
178
    private void btnSourceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSourceActionPerformed
179
        FileChooser chooser = new FileChooser(helper, true);
180
        FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
181
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
182
        chooser.setMultiSelectionEnabled(false);
183
        chooser.setDialogTitle(NbBundle.getMessage(EditJarPanel.class, "LBL_Edit_Jar_Panel_browse"));
184
        //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
185
        chooser.setAcceptAllFileFilterUsed(false);
186
        chooser.setFileFilter(new SimpleFileFilter(
187
                "Source Entry (folder, ZIP or JAR file)", 
188
                new String[]{"ZIP", "JAR"}));   // NOI18N 
189
        File curDir = helper.resolveFile(item.jarFile.getPath());
190
        chooser.setCurrentDirectory(curDir);
191
        int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)); // Sow the chooser
192
193
        if (option == JFileChooser.APPROVE_OPTION) {
194
            File files[];
195
            try {
196
                files = chooser.getFiles();
197
            } catch (IOException ex) {
198
                // TODO: add localized message
199
                Exceptions.printStackTrace(ex);
200
                return;
201
            }
202
            txtSource.setText(files[0].getPath());
203
        }
204
205
    }//GEN-LAST:event_btnSourceActionPerformed
206
    // Variables declaration - do not modify//GEN-BEGIN:variables
207
    private javax.swing.JButton btnJavadoc;
208
    private javax.swing.JButton btnSource;
209
    private javax.swing.JLabel lblJar;
210
    private javax.swing.JLabel lblJavadoc;
211
    private javax.swing.JLabel lblSource;
212
    private javax.swing.JTextField txtJar;
213
    private javax.swing.JTextField txtJavadoc;
214
    private javax.swing.JTextField txtSource;
215
    // End of variables declaration//GEN-END:variables
216
    private static class SimpleFileFilter extends FileFilter {
217
218
        private String description;
219
        private Collection extensions;
220
221
        public SimpleFileFilter(String description, String[] extensions) {
222
            this.description = description;
223
            this.extensions = Arrays.asList(extensions);
224
        }
225
226
        public boolean accept(File f) {
227
            if (f.isDirectory()) {
228
                return true;
229
            }
230
            String name = f.getName();
231
            int index = name.lastIndexOf('.');   //NOI18N
232
            if (index <= 0 || index == name.length() - 1) {
233
                return false;
234
            }
235
            String extension = name.substring(index + 1).toUpperCase();
236
            return this.extensions.contains(extension);
237
        }
238
239
        public String getDescription() {
240
            return this.description;
241
        }
242
    }
243
}
(-)/dev/null (+93 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.java.project.support.ui;
41
42
import java.io.File;
43
import org.netbeans.spi.project.support.ant.AntProjectHelper;
44
import org.openide.DialogDescriptor;
45
import org.openide.DialogDisplayer;
46
47
/**
48
 * Factory for creating a dialog for editing jar/folder-based classpath dependencies 
49
 * for Ant based projects. Allows to add/modify/remove source and javadoc jars.
50
 * @author mkleint
51
 */
52
public final class EditJarSupport {
53
    
54
    /**
55
     * Show dialog that allows to edit source and javadoc jar/folder locations
56
     * for a given jar/folder on the classpath. Returns null when dialog was cancelled,
57
     * otherwise returns EditJarSupport.Item bean with new values.
58
     * 
59
     * @param helper
60
     * @param item - bean with currently used values for classpath jar, source and javadoc jars location
61
     * @return null if dialog cancelled, or the original item with modified values
62
     */
63
    public static Item showEditDialog(AntProjectHelper helper, Item item) {
64
        EditJarPanel panel = new EditJarPanel(item, helper);
65
        DialogDescriptor dd = new DialogDescriptor(panel, "Edit jar reference");
66
        Object ret = DialogDisplayer.getDefault().notify(dd);
67
        if (DialogDescriptor.OK_OPTION == ret) {
68
            return panel.assignValues();
69
        }
70
        return null;
71
    }
72
    
73
    /**
74
     * Simple object holding information used for passing information in and out of the 
75
     * <code>EditJarSupport.showEditDialog</code> method.
76
     * 
77
     */
78
    public static final class Item {
79
        /**
80
         * classpath file location, can be relative or absolute path (relative to project basedir)
81
         */
82
        public File jarFile;
83
        /**
84
         * source file location, can be relative or absolute path (relative to project basedir)
85
         */
86
        public File sourceFile;
87
        /**
88
         * javadoc file location, can be relative or absolute path (relative to project basedir)
89
         */
90
        public File javadocFile;
91
    }
92
93
}

Return to bug 70497