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 90562
Collapse All | Expand All

(-)ant/freeform/apichanges.xml (-1 / +19 lines)
Lines 82-93 Link Here
82
82
83
    <changes>
83
    <changes>
84
84
85
        <change id="remove_nature_lookup_customizer">
86
            <summary>Simplify ProjectNature and align with common project extensibility APIs</summary>
87
            <version major="1" minor="14"/>
88
            <date day="10" month="2" year="2007"/>
89
            <author login="mkleint"/>
90
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="no" />
91
            <description>
92
                <p>
93
                    Removed class <code>org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel</code>
94
                    and removed methods from <code>org.netbeans.modules.ant.freeform.spi.ProjectNature</code>.
95
                    The removed methods were replaced by new project extensibility APIs.
96
                </p>
97
            </description>
98
             <class package="org.netbeans.modules.ant.freeform.spi" name="ProjectPropertiesPanel"/>
99
             <class package="org.netbeans.modules.ant.freeform.spi" name="ProjectNature"/>
100
            <issue number="90562" />
101
        </change>
102
        
85
        <change id="deprecate_LookupMerger">
103
        <change id="deprecate_LookupMerger">
86
            <summary>Remove LookupMerger</summary>
104
            <summary>Remove LookupMerger</summary>
87
            <version major="1" minor="13"/>
105
            <version major="1" minor="13"/>
88
            <date day="11" month="10" year="2006"/>
106
            <date day="11" month="10" year="2006"/>
89
            <author login="mkleint"/>
107
            <author login="mkleint"/>
90
            <compatibility binary="no" source="no" semantic="no" addition="no" />
108
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="no" />
91
            <description>
109
            <description>
92
                <p>
110
                <p>
93
                    Removed class <code>org.netbeans.modules.ant.freeform.spi.LookupMerger</code>
111
                    Removed class <code>org.netbeans.modules.ant.freeform.spi.LookupMerger</code>
(-)ant/freeform/arch.xml (-3 / +104 lines)
Lines 1003-1011 Link Here
1003
        </question>
1003
        </question>
1004
-->
1004
-->
1005
 <answer id="resources-layer">
1005
 <answer id="resources-layer">
1006
  <p>
1006
    <api group="layer" name="AntFreeformLogicalViewProvider" type="export" category="official">
1007
   No.
1007
     <p>
1008
  </p>
1008
       "Projects/org-netbeans-modules-ant-freeform/Nodes" folder's content is used to construct the project's child nodes.
1009
       It's content is expected to be <code>NodeFactory</code> instances.
1010
     </p>
1011
    </api>
1012
    <api group="layer" name="AntFreeformLookup" type="export" category="official">
1013
     <p>
1014
       "Projects/org-netbeans-modules-ant-freeform/Lookup" folder's content is used to construct the project's additional lookup.
1015
       It's content is expected to be <code>LookupProvider</code> instances. Freeform project provides <code>LookupMerger</code>s 
1016
       for <code>ActionProvider</code>, <code>PrivilegedTemplates</code> and <code>RecommendedTemplates</code>. Implementations added by 3rd parties 
1017
       will be merged into a single instance in the project's lookup.
1018
     </p>
1019
    </api>
1020
    <api group="layer" name="AntFreeformCustomizer" type="export" category="official">
1021
     <p>
1022
       "Projects/org-netbeans-modules-ant-freeform/Customizer" folder's content is used to construct the project's customizer.
1023
       It's content is expected to be <code>ProjectCustomizer.CompositeCategoryProvider</code> instances.
1024
       The lookup passed to the panels contains an instance of <code>Project</code>, <code>AuxiliaryConfiguration</code> and <code>ProjectAccessor</code>
1025
       Each panel is assumed to save it's own changed content by setting an <code>ActionListener</code> on it's <code>ProjectCutomizer.Category</code>
1026
     </p>
1027
    </api>
1028
    
1009
 </answer>
1029
 </answer>
1010
1030
1011
1031
Lines 1081-1086 Link Here
1081
 <answer id="security-policy">
1101
 <answer id="security-policy">
1082
  <p>
1102
  <p>
1083
   No.
1103
   No.
1104
  </p>
1105
 </answer>
1106
1107
1108
1109
1110
<!--
1111
        <question id="arch-where" when="impl">
1112
            Where one can find sources for your module?
1113
            <hint>
1114
                Please provide link to the CVS web client at
1115
                http://www.netbeans.org/download/source_browse.html
1116
                or just use tag defaultanswer generate='here'
1117
            </hint>
1118
        </question>
1119
-->
1120
 <answer id="arch-where">
1121
  <defaultanswer generate='here' />
1122
 </answer>
1123
1124
1125
1126
<!--
1127
        <question id="compat-deprecation" when="init">
1128
            How the introduction of your project influences functionality
1129
            provided by previous version of the product?
1130
            <hint>
1131
            If you are planning to deprecate/remove/change any existing APIs,
1132
            list them here accompanied with the reason explaining why you
1133
            are doing so.
1134
            </hint>
1135
        </question>
1136
-->
1137
 <answer id="compat-deprecation">
1138
  <p>
1139
   XXX no answer for compat-deprecation
1140
  </p>
1141
 </answer>
1142
1143
1144
1145
<!--
1146
        <question id="exec-ant-tasks" when="impl">
1147
            Do you define or register any ant tasks that other can use?
1148
            
1149
            <hint>
1150
            If you provide an ant task that users can use, you need to be very
1151
            careful about its syntax and behaviour, as it most likely forms an
1152
	          API for end users and as there is a lot of end users, their reaction
1153
            when such API gets broken can be pretty strong.
1154
            </hint>
1155
        </question>
1156
-->
1157
 <answer id="exec-ant-tasks">
1158
  <p>
1159
   XXX no answer for exec-ant-tasks
1160
  </p>
1161
 </answer>
1162
1163
1164
1165
<!--
1166
        <question id="resources-preferences" when="final">
1167
            Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1168
            or regular JDK Preferences ? Does it read, write or both ? 
1169
            Does it share preferences with other modules ? If so, then why ?
1170
            <hint>
1171
                You may use
1172
                    &lt;api type="export" group="preferences"
1173
                    name="preference node name" category="private"&gt;
1174
                    description of individual keys, where it is used, what it
1175
                    influences, whether the module reads/write it, etc.
1176
                    &lt;/api&gt;
1177
                Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1178
                Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1179
            </hint>
1180
        </question>
1181
-->
1182
 <answer id="resources-preferences">
1183
  <p>
1184
   XXX no answer for resources-preferences
1084
  </p>
1185
  </p>
1085
 </answer>
1186
 </answer>
1086
1187
(-)ant/freeform/manifest.mf (-1 / +2 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.ant.freeform/1
2
OpenIDE-Module: org.netbeans.modules.ant.freeform/1
3
OpenIDE-Module-Specification-Version: 1.13
3
OpenIDE-Module-Specification-Version: 1.14
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/ant/freeform/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/ant/freeform/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/ant/freeform/resources/layer.xml
5
6
(-)ant/freeform/nbproject/project.xml (-37 / +67 lines)
Lines 154-196 Link Here
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
            </module-dependencies>
156
            </module-dependencies>
157
          <test-dependencies>
157
            <test-dependencies>
158
              <test-type>
158
                <test-type>
159
                  <name>unit</name>
159
                    <name>unit</name>
160
                  <test-dependency>
160
                    <test-dependency>
161
                      <code-name-base>org.netbeans.modules.ant.freeform</code-name-base>
161
                        <code-name-base>org.apache.xml.resolver</code-name-base>
162
                      <recursive/>
162
                        <compile-dependency/>
163
                      <compile-dependency/>
163
                    </test-dependency>
164
                  </test-dependency>
164
                    <test-dependency>
165
                  <test-dependency>
165
                        <code-name-base>org.netbeans.bootstrap</code-name-base>
166
                      <code-name-base>org.openide.modules</code-name-base>
166
                    </test-dependency>
167
                      <compile-dependency/>
167
                    <test-dependency>
168
                  </test-dependency>
168
                        <code-name-base>org.netbeans.core.execution</code-name-base>
169
                  <test-dependency>
169
                        <recursive/>
170
                      <code-name-base>org.openidex.util</code-name-base>
170
                        <compile-dependency/>
171
                  </test-dependency>
171
                    </test-dependency>
172
                  <test-dependency>
172
                    <test-dependency>
173
                      <code-name-base>org.openide.options</code-name-base>
173
                        <code-name-base>org.netbeans.core.startup</code-name-base>
174
                  </test-dependency>
174
                    </test-dependency>
175
                  <test-dependency>
175
                    <test-dependency>
176
                      <code-name-base>org.netbeans.modules.projectui</code-name-base>
176
                        <code-name-base>org.netbeans.core.ui</code-name-base>
177
                  </test-dependency>
177
                        <compile-dependency/>
178
                  <test-dependency>
178
                    </test-dependency>
179
                      <code-name-base>org.netbeans.modules.masterfs</code-name-base>
179
                    <test-dependency>
180
                  </test-dependency>
180
                        <code-name-base>org.netbeans.libs.xerces</code-name-base>
181
                  <test-dependency>
181
                    </test-dependency>
182
                      <code-name-base>org.netbeans.core.startup</code-name-base>
182
                    <test-dependency>
183
                  </test-dependency>
183
                        <code-name-base>org.netbeans.modules.ant.freeform</code-name-base>
184
                  <test-dependency>
184
                        <recursive/>
185
                      <code-name-base>org.netbeans.bootstrap</code-name-base>
185
                        <compile-dependency/>
186
                  </test-dependency>
186
                    </test-dependency>
187
                  <test-dependency>
187
                    <test-dependency>
188
                      <code-name-base>org.netbeans.libs.xerces</code-name-base>
188
                        <code-name-base>org.netbeans.modules.editor.mimelookup.impl</code-name-base>
189
                  </test-dependency>
189
                        <compile-dependency/>
190
              </test-type>
190
                    </test-dependency>
191
              <test-type>
191
                    <test-dependency>
192
                  <name>qa-functional</name>
192
                        <code-name-base>org.netbeans.modules.favorites</code-name-base>
193
              </test-type>
193
                        <compile-dependency/>
194
                    </test-dependency>
195
                    <test-dependency>
196
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
197
                    </test-dependency>
198
                    <test-dependency>
199
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
200
                    </test-dependency>
201
                    <test-dependency>
202
                        <code-name-base>org.netbeans.modules.xml.catalog</code-name-base>
203
                        <compile-dependency/>
204
                    </test-dependency>
205
                    <test-dependency>
206
                        <code-name-base>org.netbeans.modules.xml.core</code-name-base>
207
                        <recursive/>
208
                        <compile-dependency/>
209
                    </test-dependency>
210
                    <test-dependency>
211
                        <code-name-base>org.openide.modules</code-name-base>
212
                        <compile-dependency/>
213
                    </test-dependency>
214
                    <test-dependency>
215
                        <code-name-base>org.openide.options</code-name-base>
216
                    </test-dependency>
217
                    <test-dependency>
218
                        <code-name-base>org.openidex.util</code-name-base>
219
                    </test-dependency>
220
                </test-type>
221
                <test-type>
222
                    <name>qa-functional</name>
223
                </test-type>
194
            </test-dependencies>
224
            </test-dependencies>
195
            <friend-packages>
225
            <friend-packages>
196
                <friend>org.netbeans.modules.j2ee.ejbfreeform</friend>
226
                <friend>org.netbeans.modules.j2ee.ejbfreeform</friend>
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/Accessor.java (+44 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform;
21
22
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
23
24
/**
25
 *
26
 * @author mkleint
27
 */
28
public abstract class Accessor {
29
    
30
    protected static Accessor DEFAULT = null;
31
32
    static {
33
        // invokes static initializer of Item.class
34
        // that will assign value to the DEFAULT field above
35
        Class c = ProjectAccessor.class;
36
        try {
37
            Class.forName(c.getName(), true, c.getClassLoader());
38
        } catch (Exception ex) {
39
            ex.printStackTrace();
40
        }
41
    }    
42
    
43
    public abstract ProjectAccessor createProjectAccessor(FreeformProject desc);
44
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java (-93 / +8 lines)
Lines 19-31 Link Here
19
19
20
package org.netbeans.modules.ant.freeform;
20
package org.netbeans.modules.ant.freeform;
21
21
22
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
22
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeListener;
23
import java.io.IOException;
24
import java.io.IOException;
24
import java.lang.ref.Reference;
25
import java.lang.ref.WeakReference;
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.List;
29
import javax.swing.Icon;
25
import javax.swing.Icon;
30
import javax.swing.ImageIcon;
26
import javax.swing.ImageIcon;
31
import org.netbeans.api.project.Project;
27
import org.netbeans.api.project.Project;
Lines 36-55 Link Here
36
import org.netbeans.modules.ant.freeform.ui.ProjectCustomizerProvider;
32
import org.netbeans.modules.ant.freeform.ui.ProjectCustomizerProvider;
37
import org.netbeans.modules.ant.freeform.ui.View;
33
import org.netbeans.modules.ant.freeform.ui.View;
38
import org.netbeans.spi.project.AuxiliaryConfiguration;
34
import org.netbeans.spi.project.AuxiliaryConfiguration;
35
import org.netbeans.spi.project.support.LookupProviderSupport;
39
import org.netbeans.spi.project.support.ant.AntProjectHelper;
36
import org.netbeans.spi.project.support.ant.AntProjectHelper;
40
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
37
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
41
import org.netbeans.spi.project.support.ant.PropertyUtils;
38
import org.netbeans.spi.project.support.ant.PropertyUtils;
42
import org.netbeans.spi.project.ui.support.UILookupMergerSupport;
39
import org.netbeans.spi.project.ui.support.UILookupMergerSupport;
43
import org.openide.ErrorManager;
44
import org.openide.filesystems.FileObject;
40
import org.openide.filesystems.FileObject;
45
import org.openide.util.Lookup;
41
import org.openide.util.Lookup;
46
import org.openide.util.LookupEvent;
47
import org.openide.util.LookupListener;
48
import org.openide.util.Mutex;
42
import org.openide.util.Mutex;
49
import org.openide.util.Utilities;
43
import org.openide.util.Utilities;
50
import org.openide.util.WeakListeners;
51
import org.openide.util.lookup.Lookups;
44
import org.openide.util.lookup.Lookups;
52
import org.openide.util.lookup.ProxyLookup;
53
import org.w3c.dom.Element;
45
import org.w3c.dom.Element;
54
import org.w3c.dom.NodeList;
46
import org.w3c.dom.NodeList;
55
47
Lines 80-85 Link Here
80
    private Lookup initLookup() throws IOException {
72
    private Lookup initLookup() throws IOException {
81
        aux = helper().createAuxiliaryConfiguration(); // AuxiliaryConfiguration
73
        aux = helper().createAuxiliaryConfiguration(); // AuxiliaryConfiguration
82
        Lookup baseLookup = Lookups.fixed(
74
        Lookup baseLookup = Lookups.fixed(
75
            this,
83
            new Info(), // ProjectInformation
76
            new Info(), // ProjectInformation
84
            new FreeformSources(this), // Sources
77
            new FreeformSources(this), // Sources
85
            new Actions(this), // ActionProvider
78
            new Actions(this), // ActionProvider
Lines 90-101 Link Here
90
            new Subprojects(this), // SubprojectProvider
83
            new Subprojects(this), // SubprojectProvider
91
            new ArtifactProvider(this), // AntArtifactProvider
84
            new ArtifactProvider(this), // AntArtifactProvider
92
            new LookupMergerImpl(), // LookupMerger or ActionProvider
85
            new LookupMergerImpl(), // LookupMerger or ActionProvider
93
            UILookupMergerSupport.createPrivilegedTemplatesMerger(), 
86
            UILookupMergerSupport.createPrivilegedTemplatesMerger(),
87
            UILookupMergerSupport.createRecommendedTemplatesMerger(),
94
            new FreeformProjectOperations(this),
88
            new FreeformProjectOperations(this),
95
	    new FreeformSharabilityQuery(helper()), //SharabilityQueryImplementation
89
	    new FreeformSharabilityQuery(helper()), //SharabilityQueryImplementation
96
            new ProjectAccessor(this) //Access to AntProjectHelper and PropertyEvaluator
90
            Accessor.DEFAULT.createProjectAccessor(this) //Access to AntProjectHelper and PropertyEvaluator
97
        );
91
        );
98
        return new FreeformLookup(baseLookup, this, helper, eval, aux);
92
        return LookupProviderSupport.createCompositeLookup(baseLookup, "Projects/org-netbeans-modules-ant-freeform/Lookup"); //NOI18N
99
    }
93
    }
100
    
94
    
101
    public FileObject getProjectDirectory() {
95
    public FileObject getProjectDirectory() {
Lines 183-268 Link Here
183
        
177
        
184
    }
178
    }
185
    
179
    
186
    private static final class FreeformLookup extends ProxyLookup implements LookupListener {
180
 
187
188
        private final Lookup baseLookup;
189
        private final AntProjectHelper helper;
190
        private final PropertyEvaluator evaluator;
191
        private final FreeformProject project;
192
        private final AuxiliaryConfiguration aux;
193
        private Lookup.Result<org.netbeans.spi.project.LookupMerger> mergers2;
194
        private Reference<LookupListener> listenerRef2;
195
        
196
        //#68623: the proxy lookup fires changes only if someone listens on a particular template:
197
        private List<Lookup.Result<?>> results;
198
        
199
        public FreeformLookup(Lookup baseLookup, FreeformProject project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
200
            super();
201
            this.baseLookup = baseLookup;
202
            this.project = project;
203
            this.helper = helper;
204
            this.evaluator = evaluator;
205
            this.aux = aux;
206
            this.results = Collections.emptyList();
207
            updateLookup();
208
            PROJECT_NATURES.addLookupListener(WeakListeners.create(LookupListener.class, this, PROJECT_NATURES));
209
        }
210
        
211
        public void resultChanged (LookupEvent ev) {
212
            updateLookup();
213
        }
214
        
215
        private void updateLookup() {
216
            //unregister listeners from the old results:
217
            for (Lookup.Result<?> r : results) {
218
                r.removeLookupListener(this);
219
            }
220
            
221
            results = new ArrayList<Lookup.Result<?>>();
222
            
223
            List<Lookup> lookups = new ArrayList<Lookup>();
224
            lookups.add(baseLookup);
225
            for (ProjectNature pn : PROJECT_NATURES.allInstances()) {
226
                lookups.add(pn.getLookup(project, helper, evaluator, aux));
227
            }
228
            Lookup lkp = new ProxyLookup(lookups.toArray(new Lookup[lookups.size()]));
229
            
230
            //merge:
231
            List<Class<?>> filteredClasses = new ArrayList<Class<?>>();
232
            List<Object> mergedInstances = new ArrayList<Object>();
233
            //first comes the new project API's LookupMerger
234
            //merge:
235
            LookupListener l = listenerRef2 != null ? listenerRef2.get() : null;
236
            if (l != null) {
237
                mergers2.removeLookupListener(l);
238
            }
239
            mergers2 = lkp.lookupResult(org.netbeans.spi.project.LookupMerger.class);
240
            l = WeakListeners.create(LookupListener.class, this, mergers2);
241
            listenerRef2 = new WeakReference<LookupListener>(l);
242
            mergers2.addLookupListener(l);
243
            for (org.netbeans.spi.project.LookupMerger lm : mergers2.allInstances()) {
244
                Class<?> c = lm.getMergeableClass();
245
                if (filteredClasses.contains(c)) {
246
                    ErrorManager.getDefault().log(ErrorManager.WARNING,
247
                            "Two LookupMerger registered for class " + c +
248
                            ". Only first one will be used"); // NOI18N
249
                    continue;
250
                }
251
                filteredClasses.add(c);
252
                mergedInstances.add(lm.merge(lkp));
253
                
254
                Lookup.Result<?> result = lkp.lookupResult(c);
255
                
256
                result.addLookupListener(this);
257
                results.add(result);
258
            }
259
            
260
            lkp = Lookups.exclude(lkp, filteredClasses.toArray(new Class<?>[filteredClasses.size()]));
261
            Lookup fixed = Lookups.fixed(mergedInstances.toArray(new Object[mergedInstances.size()]));
262
            setLookups(fixed, lkp);
263
        }
264
        
265
    }
266
    
181
    
267
    /**
182
    /**
268
     * Utility method to decide if the project actually uses Ant scripting.
183
     * Utility method to decide if the project actually uses Ant scripting.
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/LookupMergerImpl.java (-2 lines)
Lines 22-32 Link Here
22
import java.util.Arrays;
22
import java.util.Arrays;
23
import java.util.Collection;
23
import java.util.Collection;
24
import java.util.HashSet;
24
import java.util.HashSet;
25
import java.util.LinkedHashSet;
26
import java.util.Set;
25
import java.util.Set;
27
import org.netbeans.spi.project.ActionProvider;
26
import org.netbeans.spi.project.ActionProvider;
28
import org.netbeans.spi.project.LookupMerger;
27
import org.netbeans.spi.project.LookupMerger;
29
import org.netbeans.spi.project.ui.PrivilegedTemplates;
30
import org.openide.util.Lookup;
28
import org.openide.util.Lookup;
31
29
32
/**
30
/**
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ProjectAccessor.java (-45 lines)
Removed Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.ant.freeform;
20
21
import org.netbeans.spi.project.support.ant.AntProjectHelper;
22
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
23
24
/**
25
 *
26
 * @author Jan Lahoda
27
 */
28
public final class ProjectAccessor {
29
30
    private FreeformProject p;
31
32
    /** Creates a new instance of ProjectAccessor */
33
    public ProjectAccessor(FreeformProject p) {
34
        this.p = p;
35
    }
36
37
    public AntProjectHelper getHelper() {
38
        return p.helper();
39
    }
40
41
    public PropertyEvaluator getEvaluator() {
42
        return p.evaluator();
43
    }
44
    
45
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml (+36 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
The contents of this file are subject to the terms of the Common Development
4
and Distribution License (the License). You may not use this file except in
5
compliance with the License.
6
7
You can obtain a copy of the License at http://www.netbeans.org/cddl.html
8
or http://www.netbeans.org/cddl.txt.
9
10
When distributing Covered Code, include this CDDL Header Notice in each file
11
and include the License file at http://www.netbeans.org/cddl.txt.
12
If applicable, add the following below the CDDL Header, with the fields
13
enclosed by brackets [] replaced by your own identifying information:
14
"Portions Copyrighted [year] [name of copyright owner]"
15
16
The Original Software is NetBeans. The Initial Developer of the Original
17
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
18
Microsystems, Inc. All Rights Reserved.
19
-->
20
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
21
<filesystem>
22
    
23
    <folder name="Projects">
24
        <folder name="org-netbeans-modules-ant-freeform">
25
            <folder name="Lookup"/>
26
            <folder name="Customizer">
27
                <file name="org-netbeans-modules-ant-freeform-ui-TargetMappingCategoryProvider.instance"/>
28
                <attr name="org-netbeans-modules-java-freeform-ui-OutputCategoryProvider.instance/org-netbeans-modules-ant-freeform-ui-TargetMappingCategoryProvider.instance" boolvalue="true"/>
29
            </folder>    
30
            <folder name="Nodes">
31
                <file name="org-netbeans-modules-ant-freeform-ui-FolderNodeFactory.instance"/>
32
            </folder>    
33
         </folder>
34
    </folder>
35
    
36
</filesystem>
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/spi/AccessorImpl.java (+43 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform.spi;
21
22
import org.netbeans.modules.ant.freeform.Accessor;
23
import org.netbeans.modules.ant.freeform.FreeformProject;
24
25
/**
26
 *
27
 * @author mkleint
28
 */
29
class AccessorImpl extends Accessor {
30
    
31
    /** Creates a new instance of AccessorImpl */
32
    private  AccessorImpl() {
33
    }
34
    
35
    static void createAccesor() {
36
        if (DEFAULT == null) {
37
            DEFAULT = new AccessorImpl();
38
        }
39
    }
40
    public ProjectAccessor createProjectAccessor(FreeformProject p) {
41
        return new ProjectAccessor(p);
42
    }
43
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectAccessor.java (+49 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.ant.freeform.spi;
20
21
import org.netbeans.modules.ant.freeform.*;
22
import org.netbeans.spi.project.support.ant.AntProjectHelper;
23
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
24
25
/**
26
 * Accessor for AntProjectHelper and PropertyEvaluator, resides in project's lookup.
27
 * @author Jan Lahoda
28
 */
29
public final class ProjectAccessor {
30
31
    private FreeformProject p;
32
    
33
    static {
34
        AccessorImpl.createAccesor();
35
    }
36
    /** Creates a new instance of ProjectAccessor */
37
    ProjectAccessor(FreeformProject p) {
38
        this.p = p;
39
    }
40
41
    public AntProjectHelper getHelper() {
42
        return p.helper();
43
    }
44
45
    public PropertyEvaluator getEvaluator() {
46
        return p.evaluator();
47
    }
48
    
49
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectNature.java (-14 lines)
Lines 41-60 Link Here
41
public interface ProjectNature {
41
public interface ProjectNature {
42
42
43
    /**
43
    /**
44
     * Check project and provide additional lookup if it is project of your type.
45
     * @return lookup additional lookup to insert; cannot be null (use {@link Lookup#EMPTY} instead)
46
     */
47
    Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux);
48
    
49
    /**
50
     * Check project and provide additional customizer panels if it is project of your type.
51
     * Order of panels is unimportant because 
52
     * {@link ProjectPropertiesPanel#getPreferredPosition} will be used for ordering.
53
     * @return a list of {@link ProjectPropertiesPanel}s (can be empty but not null)
54
     */
55
    Set<ProjectPropertiesPanel> getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux);
56
    
57
    /**
58
     * Check project and provide additional build targets to be shown in 
44
     * Check project and provide additional build targets to be shown in 
59
     * target mapping customizer panel if it is project of your type. Order
45
     * target mapping customizer panel if it is project of your type. Order
60
     * of targets is important.
46
     * of targets is important.
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/spi/ProjectPropertiesPanel.java (-59 lines)
Removed Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform.spi;
21
22
import javax.swing.JComponent;
23
import org.netbeans.spi.project.support.ant.AntProjectHelper;
24
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
25
26
/**
27
 * Interface describing one customizer panel. The panels are added to
28
 * the project customizer by {@link ProjectNature#getCustomizerPanels}.
29
 * @author David Konecny
30
 */
31
public interface ProjectPropertiesPanel {
32
33
    /**
34
     * Returns panel to be shown in UI.
35
     */
36
    JComponent getComponent();
37
38
    /**
39
     * Returns display name of the panel which is used in the category list.
40
     */
41
    String getDisplayName();
42
    
43
    /**
44
     * Persists customizations done in the panel. Called only when user
45
     * pressed OK in customizer. The panel may or may not be retrieved
46
     * by getComponent() method.
47
     */
48
    void storeValues();
49
50
    /**
51
     * Preferred position in the list of panels at which it should be displayed.
52
     * Check other panels positions to sort it. When multiple panels has the same
53
     * position the order is undefined.
54
     */
55
    int getPreferredPosition();
56
57
    //Icon getIcon();
58
    
59
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/spi/support/Util.java (-1 / +1 lines)
Lines 34-40 Link Here
34
import org.netbeans.modules.ant.freeform.FreeformProject;
34
import org.netbeans.modules.ant.freeform.FreeformProject;
35
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
35
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
36
import org.netbeans.modules.ant.freeform.FreeformProjectType;
36
import org.netbeans.modules.ant.freeform.FreeformProjectType;
37
import org.netbeans.modules.ant.freeform.ProjectAccessor;
37
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
38
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
38
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
39
import org.netbeans.spi.project.AuxiliaryConfiguration;
39
import org.netbeans.spi.project.AuxiliaryConfiguration;
40
import org.netbeans.spi.project.support.ant.AntProjectHelper;
40
import org.netbeans.spi.project.support.ant.AntProjectHelper;
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/FolderNodeFactory.java (+281 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
21
package org.netbeans.modules.ant.freeform.ui;
22
23
import java.util.ArrayList;
24
import java.util.Collections;
25
import java.util.List;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.event.ChangeListener;
28
import javax.swing.event.EventListenerList;
29
import org.netbeans.api.project.Project;
30
import org.netbeans.api.queries.VisibilityQuery;
31
import org.netbeans.modules.ant.freeform.FreeformProject;
32
import org.netbeans.modules.ant.freeform.FreeformProjectType;
33
import org.netbeans.modules.ant.freeform.spi.support.Util;
34
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
35
import org.netbeans.spi.project.support.ant.AntProjectEvent;
36
import org.netbeans.spi.project.support.ant.AntProjectListener;
37
import org.netbeans.spi.project.ui.support.NodeFactory;
38
import org.netbeans.spi.project.ui.support.NodeList;
39
import org.openide.filesystems.FileObject;
40
import org.openide.loaders.ChangeableDataFilter;
41
import org.openide.loaders.DataFilter;
42
import org.openide.loaders.DataFolder;
43
import org.openide.loaders.DataObject;
44
import org.openide.loaders.DataObjectNotFoundException;
45
import org.openide.nodes.FilterNode;
46
import org.openide.nodes.Node;
47
import org.openide.util.Lookup;
48
import org.openide.util.RequestProcessor;
49
import org.w3c.dom.Element;
50
51
52
/**
53
 *
54
 * @author mkleint
55
 */
56
public class FolderNodeFactory implements NodeFactory {
57
    
58
    /** Creates a new instance of FolderNodeFactory */
59
    public FolderNodeFactory() {
60
    }
61
    
62
    public NodeList createNodes(Project p) {
63
        FreeformProject project = p.getLookup().lookup(FreeformProject.class);
64
        assert project != null;
65
        return new RootChildren(project);
66
    }
67
68
    
69
    private static final class RootChildren implements NodeList<Element>, AntProjectListener {
70
        
71
        private final FreeformProject p;
72
        private List<Element> keys = new ArrayList<Element>();
73
        private List<ChangeListener> listeners = new ArrayList<ChangeListener>();
74
        
75
        public RootChildren(FreeformProject p) {
76
            this.p = p;
77
        }
78
        
79
        public void addNotify() {
80
            updateKeys(false);
81
            p.helper().addAntProjectListener(this);
82
            // XXX should probably listen to project.evaluator also?
83
        }
84
        
85
        public void removeNotify() {
86
            keys = null;
87
            p.helper().removeAntProjectListener(this);
88
        }
89
        
90
        private void updateKeys(boolean fromListener) {
91
            Element genldata = p.helper().getPrimaryConfigurationData(true);
92
            Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
93
            if (viewEl != null) {
94
                Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
95
                keys = Util.findSubElements(itemsEl);
96
                if (fromListener) {
97
                    // #50328 - post setKeys to different thread to prevent deadlocks
98
                    RequestProcessor.getDefault().post(new Runnable() {
99
                            public void run() {
100
                                fireChange();
101
                            }
102
                        });
103
                } 
104
            } else {
105
                if (fromListener) {
106
                    keys = Collections.<Element>emptyList();
107
                    // #58491 - post setKeys to different thread to prevent deadlocks
108
                    RequestProcessor.getDefault().post(new Runnable() {
109
                        public void run() {
110
                            fireChange();
111
                        }
112
                    });
113
                }
114
            }
115
        }
116
        
117
118
        public void configurationXmlChanged(AntProjectEvent ev) {
119
            updateKeys(true);
120
        }
121
122
        public void propertiesChanged(AntProjectEvent ev) {
123
            // ignore
124
        }
125
        
126
        public List<Element> keys() {
127
            return keys;
128
        }
129
130
        public void addChangeListener(ChangeListener l) {
131
            listeners.add(l);
132
        }
133
134
        public void removeChangeListener(ChangeListener l) {
135
            listeners.remove(l);
136
        }
137
        
138
        private void fireChange() {
139
            List<ChangeListener> list = new ArrayList<ChangeListener>();
140
            list.addAll(listeners);
141
            for (ChangeListener ls : listeners) {
142
                ls.stateChanged(new ChangeEvent(this));
143
            }
144
        }
145
146
        public Node node(Element itemEl) {
147
            
148
            Element locationEl = Util.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N
149
            String location = Util.findText(locationEl);
150
            String locationEval = p.evaluator().evaluate(location);
151
            if (locationEval == null) {
152
                return null;
153
            }
154
            FileObject file = p.helper().resolveFileObject(locationEval);
155
            if (file == null) {
156
                // Not there... skip this node.
157
                return null;
158
            }
159
            String label;
160
            Element labelEl = Util.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
161
            if (labelEl != null) {
162
                label = Util.findText(labelEl);
163
            } else {
164
                label = null;
165
            }
166
            if (itemEl.getLocalName().equals("source-folder")) { // NOI18N
167
                if (!file.isFolder()) {
168
                    // Just a file. Skip it.
169
                    return null;
170
                }
171
                String style = itemEl.getAttribute("style"); // NOI18N
172
                for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) {
173
                    if (nature.getSourceFolderViewStyles().contains(style)) {
174
                        return nature.createSourceFolderView(p, file, style, location, label);
175
                    }
176
                }
177
                // fall back to tree display
178
                // assert style.equals(STYLE_TREE);
179
                DataObject fileDO;
180
                try {
181
                    fileDO = DataObject.find(file);
182
                } catch (DataObjectNotFoundException e) {
183
                    throw new AssertionError(e);
184
                }
185
                return new ViewItemNode((DataFolder) fileDO, location, label);
186
            } else {
187
                assert itemEl.getLocalName().equals("source-file") : itemEl; // NOI18N
188
                    DataObject fileDO;
189
                    try {
190
                        fileDO = DataObject.find(file);
191
                    } catch (DataObjectNotFoundException e) {
192
                        throw new AssertionError(e);
193
                    }
194
                return new ViewItemNode(fileDO.getNodeDelegate(), location, label);
195
            }
196
        }
197
    }
198
    
199
    
200
    static final class VisibilityQueryDataFilter implements ChangeListener, ChangeableDataFilter {
201
        
202
        EventListenerList ell = new EventListenerList();        
203
        
204
        public VisibilityQueryDataFilter() {
205
            VisibilityQuery.getDefault().addChangeListener( this );
206
        }
207
                
208
        public boolean acceptDataObject(DataObject obj) {                
209
            FileObject fo = obj.getPrimaryFile();                
210
            return VisibilityQuery.getDefault().isVisible( fo );
211
        }
212
        
213
        public void stateChanged( ChangeEvent e) {            
214
            Object[] listeners = ell.getListenerList();     
215
            ChangeEvent event = null;
216
            for (int i = listeners.length-2; i>=0; i-=2) {
217
                if (listeners[i] == ChangeListener.class) {             
218
                    if ( event == null) {
219
                        event = new ChangeEvent( this );
220
                    }
221
                    ((ChangeListener)listeners[i+1]).stateChanged( event );
222
                }
223
            }
224
        }        
225
    
226
        public void addChangeListener( ChangeListener listener ) {
227
            ell.add( ChangeListener.class, listener );
228
        }        
229
                        
230
        public void removeChangeListener( ChangeListener listener ) {
231
            ell.remove( ChangeListener.class, listener );
232
        }
233
        
234
    }
235
    
236
     private static final class ViewItemNode extends FilterNode {
237
        
238
        private final String name;
239
        
240
        private final String displayName;
241
        private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter();
242
       
243
        public ViewItemNode(Node orig, String name, String displayName) {
244
            super(orig);
245
            this.name = name;
246
            this.displayName = displayName;
247
        }
248
        
249
        public ViewItemNode(DataFolder folder, String name, String displayName) {
250
            super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER));
251
            this.name = name;
252
            this.displayName = displayName;
253
        }
254
        
255
        public String getName() {
256
            return name;
257
        }
258
        
259
        public String getDisplayName() {
260
            if (displayName != null) {
261
                return displayName;
262
            } else {
263
                // #50425: show original name incl. annotations
264
                return super.getDisplayName();
265
            }
266
        }
267
        
268
        public boolean canRename() {
269
            return false;
270
        }
271
        
272
        public boolean canDestroy() {
273
            return false;
274
        }
275
        
276
        public boolean canCut() {
277
            return false;
278
        }
279
        
280
    }    
281
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.form (-88 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
6
      <Dimension value="[750, 450]"/>
7
    </Property>
8
  </Properties>
9
  <AccessibilityProperties>
10
    <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
11
      <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="ACSD_ProjectCustomizer" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
12
    </Property>
13
  </AccessibilityProperties>
14
15
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
16
  <SubComponents>
17
    <Container class="javax.swing.JPanel" name="categoryPanel">
18
      <Properties>
19
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
20
          <Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
21
            <EtchetBorder/>
22
          </Border>
23
        </Property>
24
        <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
25
          <Dimension value="[220, 4]"/>
26
        </Property>
27
        <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
28
          <Dimension value="[220, 4]"/>
29
        </Property>
30
      </Properties>
31
      <AccessibilityProperties>
32
        <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
33
          <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="ACSN_ProjectCustomizer_categoryPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
34
        </Property>
35
        <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
36
          <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="ACSD_ProjectCustomizer_categoryPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
37
        </Property>
38
      </AccessibilityProperties>
39
      <Constraints>
40
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
41
          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="8" insetsBottom="8" insetsRight="8" anchor="10" weightX="0.0" weightY="1.0"/>
42
        </Constraint>
43
      </Constraints>
44
45
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
46
    </Container>
47
    <Container class="javax.swing.JPanel" name="jPanel1">
48
      <Constraints>
49
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
50
          <GridBagConstraints gridX="1" gridY="1" gridWidth="0" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="8" insetsRight="8" anchor="10" weightX="1.0" weightY="1.0"/>
51
        </Constraint>
52
      </Constraints>
53
54
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
55
      <SubComponents>
56
        <Container class="javax.swing.JPanel" name="customizerPanel">
57
          <AccessibilityProperties>
58
            <Property name="AccessibleContext.accessibleName" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
59
              <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="ACSN_ProjectCustomizer_customizerPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
60
            </Property>
61
            <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
62
              <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="ACSD_ProjectCustomizer_customizerPanel" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
63
            </Property>
64
          </AccessibilityProperties>
65
          <Constraints>
66
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
67
              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="0" gridHeight="0" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
68
            </Constraint>
69
          </Constraints>
70
71
          <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
72
        </Container>
73
      </SubComponents>
74
    </Container>
75
    <Component class="javax.swing.JLabel" name="jLabel1">
76
      <Properties>
77
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
78
          <ResourceString bundle="org/netbeans/modules/ant/freeform/ui/Bundle.properties" key="LBL_Customizer_Categories" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
79
        </Property>
80
      </Properties>
81
      <Constraints>
82
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
83
          <GridBagConstraints gridX="0" gridY="0" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="8" insetsLeft="8" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
84
        </Constraint>
85
      </Constraints>
86
    </Component>
87
  </SubComponents>
88
</Form>
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizer.java (-438 lines)
Removed Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform.ui;
21
22
import java.awt.BorderLayout;
23
import java.awt.Component;
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.Image;
27
import java.beans.PropertyChangeEvent;
28
import java.beans.PropertyChangeListener;
29
import java.beans.PropertyVetoException;
30
import java.util.ArrayList;
31
import java.util.Arrays;
32
import java.util.Collection;
33
import java.util.Collections;
34
import java.util.Comparator;
35
import java.util.Iterator;
36
import java.util.List;
37
import javax.swing.JPanel;
38
import javax.swing.tree.TreeSelectionModel;
39
import org.netbeans.modules.ant.freeform.FreeformProject;
40
import org.netbeans.modules.ant.freeform.Util;
41
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
42
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
43
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
44
import org.netbeans.spi.project.AuxiliaryConfiguration;
45
import org.netbeans.spi.project.support.ant.AntProjectHelper;
46
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
47
import org.openide.DialogDescriptor;
48
import org.openide.explorer.ExplorerManager;
49
import org.openide.explorer.view.BeanTreeView;
50
import org.openide.nodes.AbstractNode;
51
import org.openide.nodes.Children;
52
import org.openide.nodes.Node;
53
import org.openide.util.HelpCtx;
54
import org.openide.util.Utilities;
55
56
/**
57
 *
58
 * @author Petr Hrebejk, David Konecny
59
 */
60
public class ProjectCustomizer extends JPanel implements HelpCtx.Provider {
61
62
    private Component currentCustomizer;
63
    private GridBagConstraints fillConstraints;
64
    private List<ProjectPropertiesPanel> panels;
65
    private FreeformProject project;
66
67
    private DialogDescriptor dialogDescriptor;
68
    
69
    private static final String GENERAL_ICON = "general.gif"; // NOI18N
70
    
71
    public ProjectCustomizer(FreeformProject project) {
72
        this.project = project;
73
        initComponents();
74
        HelpCtx.setHelpIDString( customizerPanel, "org.netbeans.modules.ant.freeform.ui.ProjectCustomizer." + Util.getMergedHelpIDFragments(project)); // NOI18N
75
        
76
        fillConstraints = new GridBagConstraints();
77
        fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
78
        fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
79
        fillConstraints.fill = java.awt.GridBagConstraints.BOTH;
80
        fillConstraints.weightx = 1.0;
81
        fillConstraints.weighty = 1.0;
82
        createProjectCustomizerPanels();
83
        categoryPanel.add(new CategoryView(createRootNode()), fillConstraints);
84
    }
85
86
    void save() {
87
        for (ProjectPropertiesPanel panel : panels) {
88
            panel.storeValues();
89
        }
90
   }
91
92
    /** This method is called from within the constructor to
93
     * initialize the form.
94
     * WARNING: Do NOT modify this code. The content of this method is
95
     * always regenerated by the Form Editor.
96
     */
97
    private void initComponents() {//GEN-BEGIN:initComponents
98
        java.awt.GridBagConstraints gridBagConstraints;
99
100
        categoryPanel = new javax.swing.JPanel();
101
        jPanel1 = new javax.swing.JPanel();
102
        customizerPanel = new javax.swing.JPanel();
103
        jLabel1 = new javax.swing.JLabel();
104
105
        setLayout(new java.awt.GridBagLayout());
106
107
        setPreferredSize(new java.awt.Dimension(750, 450));
108
        getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer"));
109
        categoryPanel.setLayout(new java.awt.GridBagLayout());
110
111
        categoryPanel.setBorder(new javax.swing.border.EtchedBorder());
112
        categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4));
113
        categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4));
114
        gridBagConstraints = new java.awt.GridBagConstraints();
115
        gridBagConstraints.gridx = 0;
116
        gridBagConstraints.gridy = 1;
117
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
118
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
119
        gridBagConstraints.weighty = 1.0;
120
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 8, 8);
121
        add(categoryPanel, gridBagConstraints);
122
        categoryPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_categoryPanel"));
123
        categoryPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_categoryPanel"));
124
125
        jPanel1.setLayout(new java.awt.GridBagLayout());
126
127
        customizerPanel.setLayout(new java.awt.GridBagLayout());
128
129
        gridBagConstraints = new java.awt.GridBagConstraints();
130
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
131
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
132
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
133
        gridBagConstraints.weightx = 1.0;
134
        gridBagConstraints.weighty = 1.0;
135
        jPanel1.add(customizerPanel, gridBagConstraints);
136
        customizerPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_customizerPanel"));
137
        customizerPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_customizerPanel"));
138
139
        gridBagConstraints = new java.awt.GridBagConstraints();
140
        gridBagConstraints.gridx = 1;
141
        gridBagConstraints.gridy = 1;
142
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
143
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
144
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
145
        gridBagConstraints.weightx = 1.0;
146
        gridBagConstraints.weighty = 1.0;
147
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 8, 8);
148
        add(jPanel1, gridBagConstraints);
149
150
        jLabel1.setText(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "LBL_Customizer_Categories"));
151
        gridBagConstraints = new java.awt.GridBagConstraints();
152
        gridBagConstraints.gridx = 0;
153
        gridBagConstraints.gridy = 0;
154
        gridBagConstraints.gridwidth = 2;
155
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156
        gridBagConstraints.insets = new java.awt.Insets(8, 8, 0, 0);
157
        add(jLabel1, gridBagConstraints);
158
159
    }//GEN-END:initComponents
160
161
162
    // Variables declaration - do not modify//GEN-BEGIN:variables
163
    private javax.swing.JPanel categoryPanel;
164
    private javax.swing.JPanel customizerPanel;
165
    private javax.swing.JLabel jLabel1;
166
    private javax.swing.JPanel jPanel1;
167
    // End of variables declaration//GEN-END:variables
168
169
    public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) {
170
        this.dialogDescriptor = dialogDescriptor;
171
    }
172
    
173
    // HelpCtx.Provider implementation -----------------------------------------
174
    
175
    public HelpCtx getHelpCtx() {
176
        if ( currentCustomizer != null ) {
177
            HelpCtx customizerCtx = HelpCtx.findHelp( currentCustomizer );
178
            if (customizerCtx.getHelpID() != null) {
179
                return new HelpCtx(customizerCtx.getHelpID() + "." + Util.getMergedHelpIDFragments(project)); // NOI18N
180
            } else {
181
                return customizerCtx;
182
            }
183
        } else {
184
            return HelpCtx.findHelp( customizerPanel );
185
        }
186
    }
187
    
188
    // Private innerclasses ----------------------------------------------------
189
190
    private class CategoryView extends JPanel implements ExplorerManager.Provider {
191
192
        private ExplorerManager manager;
193
        private BeanTreeView btv;
194
195
        CategoryView( Node rootNode ) {
196
197
            // See #36315
198
            manager = new ExplorerManager();
199
200
            setLayout( new BorderLayout() );
201
202
            Dimension size = new Dimension( 220, 4 );
203
            btv = new BeanTreeView();    // Add the BeanTreeView
204
            btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
205
            btv.setPopupAllowed( false );
206
            btv.setRootVisible( false );
207
            btv.setDefaultActionAllowed( false );
208
            btv.setMinimumSize( size );
209
            btv.setPreferredSize( size );
210
            btv.setMaximumSize( size );
211
            btv.setDragSource (false);
212
            btv.setDragSource (false);
213
            this.add( btv, BorderLayout.CENTER );
214
            manager.setRootContext( rootNode );
215
            manager.addPropertyChangeListener( new ManagerChangeListener() );
216
            selectFirstNode();
217
            btv.expandAll();
218
219
        }
220
221
        public ExplorerManager getExplorerManager() {
222
            return manager;
223
        }
224
225
        public void addNotify() {
226
            super.addNotify();
227
            btv.expandAll();
228
        }
229
230
        private void selectFirstNode() {
231
232
            Children ch = manager.getRootContext().getChildren();
233
            if ( ch != null ) {
234
                Node nodes[] = ch.getNodes();
235
236
                if ( nodes != null && nodes.length > 0 ) {
237
                    try {
238
                        manager.setSelectedNodes( new Node[] { nodes[0] } );
239
                    }
240
                    catch ( PropertyVetoException e ) {
241
                        // No node will be selected
242
                    }
243
                }
244
            }
245
246
        }
247
248
249
        /** Listens to selection change and shows the customizers as
250
         *  panels
251
         */
252
253
        private class ManagerChangeListener implements PropertyChangeListener {
254
255
            public void propertyChange(PropertyChangeEvent evt) {
256
                if(evt.getSource() != manager) {
257
                    return;
258
                }
259
260
                if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
261
                    Node nodes[] = manager.getSelectedNodes();
262
                    if ( nodes == null || nodes.length <= 0 ) {
263
                        return;
264
                    }
265
                    Node node = nodes[0];
266
267
                    if ( currentCustomizer != null ) {
268
                        customizerPanel.remove( currentCustomizer );
269
                    }
270
                    if ( node.hasCustomizer() ) {
271
                        currentCustomizer = node.getCustomizer();
272
                        customizerPanel.add( currentCustomizer, fillConstraints );
273
                        customizerPanel.validate();
274
                        customizerPanel.repaint();
275
                        if ( ProjectCustomizer.this.dialogDescriptor != null ) {
276
                            ProjectCustomizer.this.dialogDescriptor.setHelpCtx( ProjectCustomizer.this.getHelpCtx() );
277
                        }
278
279
280
                    }
281
                    else {
282
                        currentCustomizer = null;
283
                    }
284
285
                    return;
286
                }
287
            }
288
        }
289
    }
290
291
    // Private methods ---------------------------------------------------------
292
293
    private List<ProjectPropertiesPanel> createProjectCustomizerPanels() {
294
        AuxiliaryConfiguration aux = project.getLookup().lookup(AuxiliaryConfiguration.class);
295
        AntProjectHelper helper = project.helper();
296
        PropertyEvaluator eval = project.evaluator();
297
        panels = new ArrayList<ProjectPropertiesPanel>();
298
        List<TargetDescriptor> extraTargets = new ArrayList<TargetDescriptor>();
299
        for (ProjectNature pn : FreeformProject.PROJECT_NATURES.allInstances()) {
300
            panels.addAll(pn.getCustomizerPanels(project, helper, eval, aux));
301
            extraTargets.addAll(pn.getExtraTargets(project, helper, eval, aux));
302
        }
303
        if (project.usesAntScripting()) {
304
            panels.add(new TargetMappingPanel.Panel(extraTargets, eval, helper));
305
        }
306
        
307
        Collections.sort(panels, new PanelsComparator());
308
        return panels;
309
    }
310
311
    private static class PanelsComparator implements Comparator<ProjectPropertiesPanel> {
312
        public int compare(ProjectPropertiesPanel p1, ProjectPropertiesPanel p2) {
313
            if (p1.getPreferredPosition() == p2.getPreferredPosition()) {
314
                return 0;
315
            } else {
316
                return p1.getPreferredPosition() - p2.getPreferredPosition();
317
            }
318
        }
319
    }
320
    
321
    private Node createRootNode() {
322
323
        String ICON_FOLDER = "org/netbeans/modules/ant/freeform/resources/"; // NOI18N
324
        
325
        List<ConfigurationDescription> l = new ArrayList<ConfigurationDescription>();
326
        for (ProjectPropertiesPanel panel : panels) {
327
            ConfigurationDescription cd = new ConfigurationDescription(
328
                panel.getDisplayName(),
329
                panel.getDisplayName(),
330
                ICON_FOLDER + GENERAL_ICON,
331
                panel,
332
                null);
333
            l.add(cd);
334
        }
335
336
        ConfigurationDescription rootDescription = new ConfigurationDescription(
337
        "InvisibleRoot", "InvisibleRoot", null, null, l.toArray(new ConfigurationDescription[l.size()]));  // NOI18N
338
339
        return new ConfigurationNode( rootDescription );
340
    }
341
342
    // Private innerclasses ----------------------------------------------------
343
344
    /** Class describing the configuration node. Prototype of the
345
     *  configuration node.
346
     */
347
    private static class ConfigurationDescription {
348
349
350
        private String name;
351
        private String displayName;
352
        private String iconResource;
353
        private ProjectPropertiesPanel panel;
354
        private ConfigurationDescription[] children;
355
        // XXX Add Node.Properties
356
357
        ConfigurationDescription( String name,
358
        String displayName,
359
        String iconResource,
360
        ProjectPropertiesPanel panel,
361
        ConfigurationDescription[] children ) {
362
363
            this.name = name;
364
            this.displayName = displayName;
365
            this.iconResource = iconResource;
366
            this.panel = panel;
367
            this.children = children;
368
        }
369
370
    }
371
372
373
    /** Node to be used for configuration
374
     */
375
    private static class ConfigurationNode extends AbstractNode {
376
377
        private ProjectPropertiesPanel panel;
378
        /** resource path to icon, or null */
379
        private final String iconResource;
380
381
        public ConfigurationNode( ConfigurationDescription description ) {
382
            super( description.children == null ? Children.LEAF : new ConfigurationChildren( description.children ) );
383
            setName( description.name );
384
            setDisplayName( description.displayName );
385
            this.iconResource = description.iconResource;
386
            this.panel = description.panel;
387
        }
388
389
        public boolean hasCustomizer() {
390
            return true;
391
        }
392
393
        public Component getCustomizer() {
394
            if (panel == null) {
395
                return null;
396
            }
397
            return panel.getComponent();
398
        }
399
400
        public Image getIcon(int type) {
401
            if (iconResource != null) {
402
                return Utilities.loadImage(iconResource, true);
403
            } else {
404
                return super.getIcon(type);
405
            }
406
        }
407
408
        public Image getOpenedIcon(int type) {
409
            if (iconResource != null) {
410
                return Utilities.loadImage(iconResource, true);
411
            } else {
412
                return super.getOpenedIcon(type);
413
            }
414
        }
415
416
    }
417
418
    private static class ConfigurationChildren extends Children.Keys<ConfigurationDescription> {
419
420
        private ConfigurationDescription[] descriptions;
421
422
        public ConfigurationChildren(ConfigurationDescription[] descriptions) {
423
            this.descriptions = descriptions;
424
        }
425
426
        public void addNotify() {
427
            setKeys(descriptions);
428
        }
429
430
        public void removeNotify() {
431
            setKeys(new ConfigurationDescription[0]);
432
        }
433
434
        protected Node[] createNodes(ConfigurationDescription key) {
435
            return new Node[] {new ConfigurationNode(key)};
436
        }
437
    }
438
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/ProjectCustomizerProvider.java (-79 / +60 lines)
Lines 22-41 Link Here
22
import java.awt.Dialog;
22
import java.awt.Dialog;
23
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
24
import java.awt.event.ActionListener;
25
import java.io.IOException;
25
import java.awt.event.WindowAdapter;
26
import java.awt.event.WindowEvent;
26
import java.text.MessageFormat;
27
import java.text.MessageFormat;
28
import java.util.HashMap;
27
import java.util.Map;
29
import java.util.Map;
28
import java.util.WeakHashMap;
29
import javax.swing.JButton;
30
import org.netbeans.api.project.Project;
30
import org.netbeans.api.project.Project;
31
import org.netbeans.api.project.ProjectManager;
31
import org.netbeans.api.project.ProjectManager;
32
import org.netbeans.api.project.ProjectUtils;
32
import org.netbeans.api.project.ProjectUtils;
33
import org.netbeans.modules.ant.freeform.FreeformProject;
33
import org.netbeans.modules.ant.freeform.FreeformProject;
34
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
35
import org.netbeans.spi.project.AuxiliaryConfiguration;
34
import org.netbeans.spi.project.ui.CustomizerProvider;
36
import org.netbeans.spi.project.ui.CustomizerProvider;
35
import org.openide.DialogDescriptor;
37
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
36
import org.openide.DialogDisplayer;
38
import org.openide.util.Lookup;
37
import org.openide.ErrorManager;
38
import org.openide.util.NbBundle;
39
import org.openide.util.NbBundle;
40
import org.openide.util.lookup.AbstractLookup;
41
import org.openide.util.lookup.InstanceContent;
39
42
40
/**
43
/**
41
 *
44
 *
Lines 45-147 Link Here
45
    
48
    
46
    private final FreeformProject project;
49
    private final FreeformProject project;
47
    
50
    
48
    // Option indexes
51
    public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ant-freeform/Customizer"; //NO18N
49
    private static final int OPTION_OK = 0;
50
    private static final int OPTION_CANCEL = OPTION_OK + 1;
51
    
52
    // Option command names
53
    private static final String COMMAND_OK = "OK";          // NOI18N
54
    private static final String COMMAND_CANCEL = "CANCEL";  // NOI18N
55
    
52
    
56
    private DialogDescriptor dialogDescriptor;
53
    private static Map /*<Project,Dialog>*/project2Dialog = new HashMap(); 
57
    private Map<FreeformProject,Dialog> customizerPerProject = new WeakHashMap<FreeformProject,Dialog>(); // Is weak needed here?
58
    
54
    
59
    public ProjectCustomizerProvider(FreeformProject project) {
55
    public ProjectCustomizerProvider(FreeformProject project) {
60
        this.project = project;
56
        this.project = project;
61
    }
57
    }
62
            
58
            
63
    public void showCustomizer() {
59
    public void showCustomizer() {
64
        
60
        Dialog dialog = (Dialog)project2Dialog.get (project);
65
        if (customizerPerProject.containsKey (project)) {
61
        if ( dialog != null ) {            
66
            Dialog dlg = customizerPerProject.get(project);
62
            dialog.setVisible(true);
67
            
63
            return;
68
            // check if the project is being customized
69
            if (dlg.isShowing ()) {
70
                // make it showed
71
                dlg.setVisible(true);
72
                return ;
73
            }
74
        }
64
        }
65
        else {
66
            InstanceContent ic = new InstanceContent();
67
            Lookup context = new AbstractLookup(ic);
68
            ic.add(project);
69
            ic.add(project.getLookup().lookup(ProjectAccessor.class));
70
            ic.add(project.getLookup().lookup(AuxiliaryConfiguration.class));
71
            //TODO replace with generic apis..
72
            ic.add(ic);
73
            
74
            OptionListener listener = new OptionListener( project );
75
            dialog = ProjectCustomizer.createCustomizerDialog(CUSTOMIZER_FOLDER_PATH, context, null, listener, null );
76
            dialog.addWindowListener( listener );
77
            dialog.setTitle( MessageFormat.format(                 
78
                    NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N 
79
                    new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ) );
75
80
76
        // Create options
81
            project2Dialog.put(project, dialog);
77
        JButton options[] = new JButton[] { 
82
            dialog.setVisible(true);
78
            new JButton( NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Ok_Option") ), // NOI18N
83
        }
79
            new JButton( NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Cancel_Option" ) ) , // NOI18N
80
        };
81
82
        // Set commands
83
        options[ OPTION_OK ].setActionCommand( COMMAND_OK );
84
        options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL );
85
86
        ProjectCustomizer pc = new ProjectCustomizer(project);
87
        // RegisterListener
88
        ActionListener optionsListener = new OptionListener( project, pc);
89
        options[ OPTION_OK ].addActionListener( optionsListener );
90
        options[ OPTION_OK ].getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ProjectCustomizerProvider.class, "ACSD_Customizer_Ok_Option")); // NOI18N
91
        options[ OPTION_CANCEL ].addActionListener( optionsListener );
92
        options[ OPTION_CANCEL ].getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ProjectCustomizerProvider.class, "ACSD_Customizer_Cancel_Option")); // NOI18N
93
94
        dialogDescriptor = new DialogDescriptor( 
95
            pc, // innerPane
96
            MessageFormat.format(                 // displayName
97
                NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N 
98
                new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ),    
99
            false,                                  // modal
100
            options,                                // options
101
            options[OPTION_OK],                     // initial value
102
            DialogDescriptor.BOTTOM_ALIGN,          // options align
103
            null,                                   // helpCtx
104
            null );                                 // listener 
105
106
        pc.setDialogDescriptor( dialogDescriptor );        
107
        dialogDescriptor.setClosingOptions( new Object[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } );
108
109
        Dialog dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
110
111
        customizerPerProject.put (project, dialog);
112
113
        dialog.setVisible(true);
114
        
115
    }    
84
    }    
116
    
85
    
117
86
118
    
119
    /** Listens to the actions on the Customizer's option buttons */
87
    /** Listens to the actions on the Customizer's option buttons */
120
    private static class OptionListener implements ActionListener {
88
    private class OptionListener extends WindowAdapter implements ActionListener {
121
    
89
    
122
        private Project project;
90
        private Project project;
123
        private ProjectCustomizer projectCustomizer;
124
        
91
        
125
        private OptionListener(Project project, ProjectCustomizer projectCustomizer) {
92
        OptionListener( Project project) {
126
            this.project = project;
93
            this.project = project;
127
            this.projectCustomizer = projectCustomizer;
128
        }
94
        }
129
        
95
        
96
        // Listening to OK button ----------------------------------------------
97
        
130
        public void actionPerformed( ActionEvent e ) {
98
        public void actionPerformed( ActionEvent e ) {
131
            String command = e.getActionCommand();
99
            // Store the properties into project 
100
            assert !ProjectManager.getDefault().isModified(project) : 
101
                "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
132
            
102
            
133
            if ( COMMAND_OK.equals( command ) ) {
103
            // Close & dispose the the dialog
134
                projectCustomizer.save();
104
            Dialog dialog = (Dialog)project2Dialog.get( project );
135
                
105
            if ( dialog != null ) {
136
                try {
106
                dialog.setVisible(false);
137
                    ProjectManager.getDefault().saveProject(project);
107
                dialog.dispose();
138
                } catch ( IOException ex ) {
139
                    ErrorManager.getDefault().notify( ex );
140
                }
141
            }
108
            }
142
            
143
        }        
109
        }        
144
        
110
        
111
        // Listening to window events ------------------------------------------
112
                
113
        public void windowClosed( WindowEvent e) {
114
            project2Dialog.remove( project );
115
        }    
116
        
117
        public void windowClosing (WindowEvent e) {
118
            //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
119
            //may not be called
120
            Dialog dialog = (Dialog)project2Dialog.get( project );
121
            if ( dialog != null ) {
122
                dialog.setVisible(false);
123
                dialog.dispose();
124
            }
125
        }
145
    }
126
    }
146
                            
127
                            
147
}
128
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingCategoryProvider.java (+74 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform.ui;
21
22
import java.util.ArrayList;
23
import java.util.List;
24
import javax.swing.JComponent;
25
import org.netbeans.api.project.Project;
26
import org.netbeans.modules.ant.freeform.FreeformProject;
27
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
28
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
29
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
30
import org.netbeans.spi.project.AuxiliaryConfiguration;
31
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
32
import org.openide.util.Lookup;
33
import org.openide.util.NbBundle;
34
35
36
/**
37
 *
38
 * @author mkleint
39
 */
40
public class TargetMappingCategoryProvider implements org.netbeans.spi.project.ui.support.ProjectCustomizer.CompositeCategoryProvider {
41
    
42
    /** Creates a new instance of TargetMappingCustomizerProvider */
43
    public TargetMappingCategoryProvider() {
44
    }
45
    
46
    public Category createCategory(Lookup context) {
47
        FreeformProject project = context.lookup(FreeformProject.class);
48
        assert project != null;
49
        if (project.usesAntScripting()) {
50
            return org.netbeans.spi.project.ui.support.ProjectCustomizer.Category.create("targetMapping", 
51
                    NbBundle.getMessage(TargetMappingPanel.class, "LBL_ProjectCustomizer_Category_Targets"), null, null);
52
        }
53
        return null;
54
    }
55
56
    public JComponent createComponent(Category category, Lookup context) {
57
        Project project = context.lookup(Project.class);
58
        ProjectAccessor acc = context.lookup(ProjectAccessor.class);
59
        AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class);
60
        assert aux != null;
61
        assert acc != null;
62
        assert project != null;
63
        
64
        List<TargetDescriptor> extraTargets = new ArrayList<TargetDescriptor>();
65
        for (ProjectNature pn : FreeformProject.PROJECT_NATURES.allInstances()) {
66
            extraTargets.addAll(pn.getExtraTargets(project, acc.getHelper(), acc.getEvaluator(), aux));
67
        }
68
        
69
        TargetMappingPanel panel = new TargetMappingPanel(extraTargets, acc.getEvaluator(), acc.getHelper());
70
        category.setOkButtonListener(panel.getCustomizerOkListener());
71
        return panel;
72
    }
73
74
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/TargetMappingPanel.java (-59 / +31 lines)
Lines 20-25 Link Here
20
package org.netbeans.modules.ant.freeform.ui;
20
package org.netbeans.modules.ant.freeform.ui;
21
21
22
import java.awt.Frame;
22
import java.awt.Frame;
23
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24
import java.awt.event.ActionListener;
24
import java.util.ArrayList;
25
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.Arrays;
Lines 32-38 Link Here
32
import javax.swing.ComboBoxModel;
33
import javax.swing.ComboBoxModel;
33
import javax.swing.DefaultCellEditor;
34
import javax.swing.DefaultCellEditor;
34
import javax.swing.JComboBox;
35
import javax.swing.JComboBox;
35
import javax.swing.JComponent;
36
import javax.swing.JDialog;
36
import javax.swing.JDialog;
37
import javax.swing.JLabel;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
38
import javax.swing.JPanel;
Lines 41-47 Link Here
41
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
41
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
42
import org.netbeans.modules.ant.freeform.Util;
42
import org.netbeans.modules.ant.freeform.Util;
43
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
43
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
44
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
45
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
44
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
46
import org.netbeans.spi.project.support.ant.AntProjectHelper;
45
import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
46
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
Lines 83-89 Link Here
83
    
82
    
84
    /** Any change in custom tasks which needs to be persisted? */
83
    /** Any change in custom tasks which needs to be persisted? */
85
    private boolean dirtyCustom;
84
    private boolean dirtyCustom;
86
85
    
86
    private AntProjectHelper helper;
87
    
87
    
88
    public TargetMappingPanel(boolean advancedPart) {
88
    public TargetMappingPanel(boolean advancedPart) {
89
        this(new ArrayList<TargetDescriptor>(), advancedPart);
89
        this(new ArrayList<TargetDescriptor>(), advancedPart);
Lines 104-110 Link Here
104
104
105
    public TargetMappingPanel(List<TargetDescriptor> extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) {
105
    public TargetMappingPanel(List<TargetDescriptor> extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) {
106
        this(extraTargets, true);
106
        this(extraTargets, true);
107
        
107
        this.helper = helper;
108
        FileObject as = FreeformProjectGenerator.getAntScript(helper, evaluator);
108
        FileObject as = FreeformProjectGenerator.getAntScript(helper, evaluator);
109
        List<String> l = null;
109
        List<String> l = null;
110
        // #50933 - script can be null
110
        // #50933 - script can be null
Lines 621-685 Link Here
621
        remove.setEnabled(custTargets.size() > 0);
621
        remove.setEnabled(custTargets.size() > 0);
622
    }
622
    }
623
    
623
    
624
    public static class Panel implements ProjectPropertiesPanel {
624
    
625
        
625
    ActionListener getCustomizerOkListener() {
626
        private List<TargetDescriptor> extraTargets;
626
        return new ActionListener() {
627
        private PropertyEvaluator evaluator;
627
            public void actionPerformed(ActionEvent arg0) {
628
        private AntProjectHelper helper;
628
                List<FreeformProjectGenerator.TargetMapping> mapping = getMapping();
629
        private TargetMappingPanel panel;
629
                if (dirtyRegular) {
630
        
630
                    FreeformProjectGenerator.putTargetMappings(helper, mapping);
631
        public Panel(List<TargetDescriptor> extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) {
631
                    FreeformProjectGenerator.putContextMenuAction(helper, mapping);
632
            this.helper = helper;
632
                }
633
            this.extraTargets = extraTargets;
633
                
634
            this.evaluator = evaluator;
634
                if (dirtyCustom) {
635
        }
635
                    List<FreeformProjectGenerator.CustomTarget> l = new ArrayList<FreeformProjectGenerator.CustomTarget>(custTargets);
636
        
636
                    Iterator<FreeformProjectGenerator.CustomTarget> it = l.iterator();
637
        /* ProjectCustomizer.Panel save */
637
                    while (it.hasNext()) {
638
        public void storeValues() {
638
                        FreeformProjectGenerator.CustomTarget ct = it.next();
639
            if (panel == null) {
639
                        // ignore row if target was not set
640
                return;
640
                        if (ct.targets == null || ct.targets.size() == 0) {
641
            }
641
                            it.remove();
642
            List<FreeformProjectGenerator.TargetMapping> mapping = panel.getMapping();
642
                            continue;
643
            if (panel.dirtyRegular) {
643
                        }
644
                FreeformProjectGenerator.putTargetMappings(helper, mapping);
644
                        if (ct.label == null || ct.label.length() == 0) {
645
                FreeformProjectGenerator.putContextMenuAction(helper, mapping);
645
                            ct.label = ct.targets.get(0);
646
            }
646
                        }
647
648
            if (panel.dirtyCustom) {
649
                List<FreeformProjectGenerator.CustomTarget> l = new ArrayList<FreeformProjectGenerator.CustomTarget>(panel.custTargets);
650
                Iterator<FreeformProjectGenerator.CustomTarget> it = l.iterator();
651
                while (it.hasNext()) {
652
                    FreeformProjectGenerator.CustomTarget ct = it.next();
653
                    // ignore row if target was not set
654
                    if (ct.targets == null || ct.targets.size() == 0) {
655
                        it.remove();
656
                        continue;
657
                    }
658
                    if (ct.label == null || ct.label.length() == 0) {
659
                        ct.label = ct.targets.get(0);
660
                    }
647
                    }
648
                    FreeformProjectGenerator.putCustomContextMenuActions(helper, l);
661
                }
649
                }
662
                FreeformProjectGenerator.putCustomContextMenuActions(helper, l);
663
            }
650
            }
664
        }
651
        };
665
666
        public String getDisplayName() {
667
            return NbBundle.getMessage(TargetMappingPanel.class, "LBL_ProjectCustomizer_Category_Targets");
668
        }
669
670
        public JComponent getComponent() {
671
            if (panel == null) {
672
                panel = new TargetMappingPanel(extraTargets, evaluator, helper);
673
            }
674
            return panel;
675
        }
676
677
        public int getPreferredPosition() {
678
            return 1000;
679
        }
680
        
681
    }
652
    }
682
    
653
    
654
    
683
    // Variables declaration - do not modify//GEN-BEGIN:variables
655
    // Variables declaration - do not modify//GEN-BEGIN:variables
684
    private javax.swing.JButton add;
656
    private javax.swing.JButton add;
685
    private javax.swing.JLabel additionalTargetsLabel;
657
    private javax.swing.JLabel additionalTargetsLabel;
Lines 791-795 Link Here
791
            dlg.setVisible(true);
763
            dlg.setVisible(true);
792
        }
764
        }
793
    }
765
    }
794
    
766
795
}
767
}
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ui/View.java (-211 / +3 lines)
Lines 24-63 Link Here
24
import java.util.List;
24
import java.util.List;
25
import java.util.StringTokenizer;
25
import java.util.StringTokenizer;
26
import javax.swing.Action;
26
import javax.swing.Action;
27
import javax.swing.event.ChangeEvent;
28
import javax.swing.event.ChangeListener;
29
import javax.swing.event.EventListenerList;
30
import org.netbeans.api.project.ProjectUtils;
27
import org.netbeans.api.project.ProjectUtils;
31
import org.netbeans.api.queries.VisibilityQuery;
32
import org.netbeans.modules.ant.freeform.Actions;
28
import org.netbeans.modules.ant.freeform.Actions;
33
import org.netbeans.modules.ant.freeform.FreeformProject;
29
import org.netbeans.modules.ant.freeform.FreeformProject;
34
import org.netbeans.modules.ant.freeform.FreeformProjectType;
35
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
30
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
36
import org.netbeans.modules.ant.freeform.spi.support.Util;
37
import org.netbeans.spi.project.support.ant.AntProjectEvent;
38
import org.netbeans.spi.project.support.ant.AntProjectListener;
39
import org.netbeans.spi.project.ui.LogicalViewProvider;
31
import org.netbeans.spi.project.ui.LogicalViewProvider;
40
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
32
import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
33
import org.netbeans.spi.project.ui.support.NodeFactorySupport;
41
import org.openide.filesystems.FileObject;
34
import org.openide.filesystems.FileObject;
42
import org.openide.filesystems.FileUtil;
35
import org.openide.filesystems.FileUtil;
43
import org.openide.loaders.ChangeableDataFilter;
44
import org.openide.loaders.DataFilter;
45
import org.openide.loaders.DataFolder;
46
import org.openide.loaders.DataObject;
36
import org.openide.loaders.DataObject;
47
import org.openide.loaders.DataObjectNotFoundException;
48
import org.openide.nodes.AbstractNode;
37
import org.openide.nodes.AbstractNode;
49
import org.openide.nodes.Children;
50
import org.openide.nodes.FilterNode;
51
import org.openide.nodes.Node;
38
import org.openide.nodes.Node;
52
import org.openide.nodes.NodeNotFoundException;
39
import org.openide.nodes.NodeNotFoundException;
53
import org.openide.nodes.NodeOp;
40
import org.openide.nodes.NodeOp;
54
import org.openide.util.HelpCtx;
41
import org.openide.util.HelpCtx;
55
import org.openide.util.Lookup;
42
import org.openide.util.Lookup;
56
import org.openide.util.NbCollections;
43
import org.openide.util.NbCollections;
57
import org.openide.util.RequestProcessor;
58
import org.openide.util.Utilities;
44
import org.openide.util.Utilities;
59
import org.openide.util.lookup.Lookups;
45
import org.openide.util.lookup.Lookups;
60
import org.w3c.dom.Element;
61
46
62
/**
47
/**
63
 * Logical view of a freeform project.
48
 * Logical view of a freeform project.
Lines 113-236 Link Here
113
        return null;
98
        return null;
114
    }
99
    }
115
    
100
    
116
    private static final class RootChildren extends Children.Keys<Element> implements AntProjectListener {
117
        
118
        private final FreeformProject p;
119
        
120
        public RootChildren(FreeformProject p) {
121
            this.p = p;
122
        }
123
        
124
        protected void addNotify() {
125
            super.addNotify();
126
            updateKeys(false);
127
            p.helper().addAntProjectListener(this);
128
            // XXX should probably listen to project.evaluator also?
129
        }
130
        
131
        protected void removeNotify() {
132
            setKeys(Collections.<Element>emptySet());
133
            p.helper().removeAntProjectListener(this);
134
            super.removeNotify();
135
        }
136
        
137
        private void updateKeys(boolean fromListener) {
138
            Element genldata = p.helper().getPrimaryConfigurationData(true);
139
            Element viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
140
            if (viewEl != null) {
141
                Element itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
142
                final List<Element> keys = Util.findSubElements(itemsEl);
143
                if (fromListener) {
144
                    // #50328 - post setKeys to different thread to prevent deadlocks
145
                    RequestProcessor.getDefault().post(new Runnable() {
146
                            public void run() {
147
                                setKeys(keys);
148
                            }
149
                        });
150
                } else {
151
                    setKeys(keys);
152
                }
153
            } else {
154
                if (fromListener) {
155
                    // #58491 - post setKeys to different thread to prevent deadlocks
156
                    RequestProcessor.getDefault().post(new Runnable() {
157
                        public void run() {
158
                            setKeys(Collections.<Element>emptySet());
159
                        }
160
                    });
161
                } else {
162
                    setKeys(Collections.<Element>emptySet());
163
                }
164
            }
165
        }
166
        
167
        protected Node[] createNodes(Element itemEl) {
168
            Element locationEl = Util.findElement(itemEl, "location", FreeformProjectType.NS_GENERAL); // NOI18N
169
            String location = Util.findText(locationEl);
170
            String locationEval = p.evaluator().evaluate(location);
171
            if (locationEval == null) {
172
                return null;
173
            }
174
            FileObject file = p.helper().resolveFileObject(locationEval);
175
            if (file == null) {
176
                // Not there... skip this node.
177
                return null;
178
            }
179
            String label;
180
            Element labelEl = Util.findElement(itemEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
181
            if (labelEl != null) {
182
                label = Util.findText(labelEl);
183
            } else {
184
                label = null;
185
            }
186
            if (itemEl.getLocalName().equals("source-folder")) { // NOI18N
187
                if (!file.isFolder()) {
188
                    // Just a file. Skip it.
189
                    return null;
190
                }
191
                String style = itemEl.getAttribute("style"); // NOI18N
192
                for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) {
193
                    if (nature.getSourceFolderViewStyles().contains(style)) {
194
                        return new Node[] {nature.createSourceFolderView(p, file, style, location, label)};
195
                    }
196
                }
197
                // fall back to tree display
198
                // assert style.equals(STYLE_TREE);
199
                DataObject fileDO;
200
                try {
201
                    fileDO = DataObject.find(file);
202
                } catch (DataObjectNotFoundException e) {
203
                    throw new AssertionError(e);
204
                }
205
                return new Node[] {new ViewItemNode((DataFolder) fileDO, location, label)};
206
            } else {
207
                assert itemEl.getLocalName().equals("source-file") : itemEl; // NOI18N
208
                    DataObject fileDO;
209
                    try {
210
                        fileDO = DataObject.find(file);
211
                    } catch (DataObjectNotFoundException e) {
212
                        throw new AssertionError(e);
213
                    }
214
                return new Node[] {new ViewItemNode(fileDO.getNodeDelegate(), location, label)};
215
            }
216
        }
217
218
        public void configurationXmlChanged(AntProjectEvent ev) {
219
            updateKeys(true);
220
        }
221
222
        public void propertiesChanged(AntProjectEvent ev) {
223
            // ignore
224
        }
225
        
226
    }
227
    
228
    private static final class RootNode extends AbstractNode {
101
    private static final class RootNode extends AbstractNode {
229
        
102
        
230
        private final FreeformProject p;
103
        private final FreeformProject p;
231
        
104
        
232
        public RootNode(FreeformProject p) {
105
        public RootNode(FreeformProject p) {
233
            super(new RootChildren(p), Lookups.singleton(p));
106
            super(NodeFactorySupport.createCompositeChildren(p, "Projects/org-netbeans-modules-ant-freeform/Nodes"), Lookups.singleton(p));
234
            this.p = p;
107
            this.p = p;
235
        }
108
        }
236
        
109
        
Lines 275-361 Link Here
275
        }
148
        }
276
        
149
        
277
    }
150
    }
278
    
151
279
    static final class VisibilityQueryDataFilter implements ChangeListener, ChangeableDataFilter {
280
        
281
        EventListenerList ell = new EventListenerList();        
282
        
283
        public VisibilityQueryDataFilter() {
284
            VisibilityQuery.getDefault().addChangeListener( this );
285
        }
286
                
287
        public boolean acceptDataObject(DataObject obj) {                
288
            FileObject fo = obj.getPrimaryFile();                
289
            return VisibilityQuery.getDefault().isVisible( fo );
290
        }
291
        
292
        public void stateChanged( ChangeEvent e) {            
293
            Object[] listeners = ell.getListenerList();     
294
            ChangeEvent event = null;
295
            for (int i = listeners.length-2; i>=0; i-=2) {
296
                if (listeners[i] == ChangeListener.class) {             
297
                    if ( event == null) {
298
                        event = new ChangeEvent( this );
299
                    }
300
                    ((ChangeListener)listeners[i+1]).stateChanged( event );
301
                }
302
            }
303
        }        
304
    
305
        public void addChangeListener( ChangeListener listener ) {
306
            ell.add( ChangeListener.class, listener );
307
        }        
308
                        
309
        public void removeChangeListener( ChangeListener listener ) {
310
            ell.remove( ChangeListener.class, listener );
311
        }
312
        
313
    }
314
    
315
     private static final class ViewItemNode extends FilterNode {
316
        
317
        private final String name;
318
        
319
        private final String displayName;
320
        private static final DataFilter VISIBILITY_QUERY_FILTER = new VisibilityQueryDataFilter();
321
       
322
        public ViewItemNode(Node orig, String name, String displayName) {
323
            super(orig);
324
            this.name = name;
325
            this.displayName = displayName;
326
        }
327
        
328
        public ViewItemNode(DataFolder folder, String name, String displayName) {
329
            super(folder.getNodeDelegate(), folder.createNodeChildren(VISIBILITY_QUERY_FILTER));
330
            this.name = name;
331
            this.displayName = displayName;
332
        }
333
        
334
        public String getName() {
335
            return name;
336
        }
337
        
338
        public String getDisplayName() {
339
            if (displayName != null) {
340
                return displayName;
341
            } else {
342
                // #50425: show original name incl. annotations
343
                return super.getDisplayName();
344
            }
345
        }
346
        
347
        public boolean canRename() {
348
            return false;
349
        }
350
        
351
        public boolean canDestroy() {
352
            return false;
353
        }
354
        
355
        public boolean canCut() {
356
            return false;
357
        }
358
        
359
    }
360
    
152
    
361
}
153
}
(-)ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/spi/ProjectNatureTest.java (-205 lines)
Removed Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.ant.freeform.spi;
21
22
import java.io.File;
23
import java.util.ArrayList;
24
import java.util.Arrays;
25
import java.util.Collections;
26
import java.util.HashSet;
27
import java.util.Iterator;
28
import java.util.LinkedHashSet;
29
import java.util.List;
30
import java.util.Set;
31
import org.netbeans.api.project.Project;
32
import org.netbeans.api.project.ProjectManager;
33
import org.netbeans.junit.NbTestCase;
34
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
35
import org.netbeans.spi.project.AuxiliaryConfiguration;
36
import org.netbeans.spi.project.LookupMerger;
37
import org.netbeans.spi.project.support.ant.AntProjectHelper;
38
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
39
import org.openide.filesystems.FileObject;
40
import org.openide.nodes.Node;
41
import org.openide.util.Lookup;
42
import org.openide.util.lookup.Lookups;
43
import org.openide.util.lookup.ProxyLookup;
44
45
// XXX testActionProviderMergeSemantics
46
47
/**
48
 * Tests correct behavior of merging of lookups from project natures
49
 * and merging of instances by LookupMerger.
50
 *
51
 * @author dk125166
52
 */
53
public class ProjectNatureTest extends NbTestCase {
54
    
55
    public ProjectNatureTest(String testName) {
56
        super(testName);
57
    }
58
59
    protected void setUp() throws Exception {
60
        clearWorkDir();
61
    }
62
    
63
    private AntProjectHelper createEmptyProject(String projectFolder, String projectName) throws Exception {
64
        File base = new File(getWorkDir(), projectFolder);
65
        base.mkdir();
66
        AntProjectHelper helper = FreeformProjectGenerator.createProject(base, base, projectName, null);
67
        return helper;
68
    }
69
    
70
    public void testGetLookup() throws Exception {
71
        AntProjectHelper h = createEmptyProject("mrg", "ee");
72
        JavaNature javaNature = Lookup.getDefault().lookup(JavaNature.class);
73
        assertNotNull("found java nature", javaNature);
74
        WebNature webNature = Lookup.getDefault().lookup(WebNature.class);
75
        assertNotNull("found web nature", webNature);
76
77
        // first test merging of lookups without LookupMerger:
78
        Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory());
79
        Lookup.Result<TemplatesQuery> tqr = p.getLookup().lookupResult(TemplatesQuery.class);
80
        assertEquals("no TemplatesQuery in project yet", 0, tqr.allInstances().size());
81
        
82
        TemplatesQuery javaTemplates = new BaseTemplates(new String[]{"class", "main", "library"});
83
        javaNature.setLookups(new Lookup[]{Lookups.fixed(javaTemplates)});
84
        assertEquals("javaTemplates in project", 1, tqr.allInstances().size());
85
        
86
        TemplatesQuery webTemplates = new BaseTemplatesAndSomeProvider(new String[]{"class", "dd"});
87
        webNature.setLookups(new Lookup[]{Lookups.fixed(webTemplates)});
88
        assertEquals("webTemplates and javaTemplates in project", 2, tqr.allInstances().size());
89
        assertEquals("one SomeProvider", 1, p.getLookup().lookupAll(SomeProvider.class).size());
90
91
        // test merging:
92
        LookupMerger lm = new TemplatesQueryMerger();
93
        javaNature.setLookups(new Lookup[]{Lookups.fixed(javaTemplates, lm)});
94
        assertEquals("only mergedTemplates in project: " + tqr.allInstances(), 1, tqr.allInstances().size());
95
        TemplatesQuery tq  = p.getLookup().lookup(TemplatesQuery.class);
96
        assertEquals("three merged templates", 4, tq.getTemplates().size());
97
        assertEquals("one SomeProvider", 1, p.getLookup().lookupAll(SomeProvider.class).size());
98
99
        // test nature uninstallation:
100
        webNature.setLookups(new Lookup[]{Lookup.EMPTY});
101
        assertEquals("only javaTemplates in project", 1, tqr.allInstances().size());
102
        tq  = p.getLookup().lookup(TemplatesQuery.class);
103
        assertEquals("two java templates", 3, tq.getTemplates().size());
104
        assertEquals("no SomeProvider", 0, p.getLookup().lookupAll(SomeProvider.class).size());
105
    }
106
    
107
    private static class BaseNature implements ProjectNature {
108
        
109
        private ChangeableLookup lookup = new ChangeableLookup();
110
        
111
        public BaseNature() {}
112
113
        public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
114
            return lookup;
115
        }
116
117
        public void setLookups(Lookup[] lookups) {
118
            lookup.setLookups2(lookups);
119
        }
120
        
121
        public Set<ProjectPropertiesPanel> getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
122
            return Collections.emptySet();
123
        }
124
125
        public List<TargetDescriptor> getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
126
            return Collections.emptyList();
127
        }
128
129
        public Set<String> getSchemas() {
130
            return Collections.emptySet();
131
        }
132
133
        public Set<String> getSourceFolderViewStyles() {
134
            return Collections.emptySet();
135
        }
136
137
        public Node createSourceFolderView(Project project, FileObject folder, String style, String name, String displayName) throws IllegalArgumentException {
138
            return null;
139
        }
140
141
        public Node findSourceFolderViewPath(Project project, Node root, Object target) {
142
            return null;
143
        }
144
        
145
    }
146
147
    public static class JavaNature extends BaseNature {
148
        public JavaNature() {}
149
    }
150
    
151
    public static class WebNature extends BaseNature {
152
        public WebNature() {}
153
    }
154
155
    private static final class ChangeableLookup extends ProxyLookup {
156
        public ChangeableLookup() {}
157
        
158
        public void setLookups2(Lookup[] lookups) {
159
            setLookups(lookups);
160
        }
161
    }
162
    
163
    private interface TemplatesQuery {
164
        List<String> getTemplates();
165
    }
166
    
167
    private static class BaseTemplates implements TemplatesQuery {
168
        private List<String> list = new ArrayList<String>();
169
        public BaseTemplates(String arr[]) {
170
            list.addAll(Arrays.asList(arr));
171
        }
172
        public List<String> getTemplates() {
173
            return list;
174
        }
175
    }
176
    
177
    private static class BaseTemplatesAndSomeProvider extends BaseTemplates implements SomeProvider {
178
        public BaseTemplatesAndSomeProvider(String arr[]) {
179
            super(arr);
180
        }
181
        public Object find() {
182
            return null;
183
        }
184
    }
185
    
186
    private interface SomeProvider {
187
        public Object find();
188
    }
189
190
    private static class TemplatesQueryMerger implements LookupMerger<TemplatesQuery> {
191
        public TemplatesQueryMerger() {}
192
        public Class<TemplatesQuery> getMergeableClass() {
193
            return TemplatesQuery.class;
194
        }
195
196
        public ProjectNatureTest.TemplatesQuery merge(Lookup lookup) {
197
            Set<String> set = new LinkedHashSet<String>();
198
            for (TemplatesQuery tq : lookup.lookupAll(TemplatesQuery.class)) {
199
                set.addAll(tq.getTemplates());
200
            }
201
            return new BaseTemplates(set.toArray(new String[set.size()]));
202
        }
203
    }
204
    
205
}
(-)ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/ViewTest.java (+3 lines)
Lines 29-40 Link Here
29
import org.netbeans.spi.project.ui.LogicalViewProvider;
29
import org.netbeans.spi.project.ui.LogicalViewProvider;
30
import org.openide.filesystems.FileObject;
30
import org.openide.filesystems.FileObject;
31
import org.openide.loaders.DataObject;
31
import org.openide.loaders.DataObject;
32
import org.openide.modules.ModuleInfo;
32
import org.openide.nodes.Children;
33
import org.openide.nodes.Children;
33
import org.openide.nodes.Node;
34
import org.openide.nodes.Node;
34
import org.openide.nodes.NodeEvent;
35
import org.openide.nodes.NodeEvent;
35
import org.openide.nodes.NodeListener;
36
import org.openide.nodes.NodeListener;
36
import org.openide.nodes.NodeMemberEvent;
37
import org.openide.nodes.NodeMemberEvent;
37
import org.openide.nodes.NodeReorderEvent;
38
import org.openide.nodes.NodeReorderEvent;
39
import org.openide.util.Lookup;
38
import org.w3c.dom.Element;
40
import org.w3c.dom.Element;
39
import org.w3c.dom.NodeList;
41
import org.w3c.dom.NodeList;
40
42
Lines 54-59 Link Here
54
    
56
    
55
    protected void setUp() throws Exception {
57
    protected void setUp() throws Exception {
56
        super.setUp();
58
        super.setUp();
59
        ModuleInfo info = Lookup.getDefault().lookup(ModuleInfo.class);
57
        lvp = extsrcroot.getLookup().lookup(LogicalViewProvider.class);
60
        lvp = extsrcroot.getLookup().lookup(LogicalViewProvider.class);
58
        assertNotNull("found a LogicalViewProvider", lvp);
61
        assertNotNull("found a LogicalViewProvider", lvp);
59
    }
62
    }
(-)j2ee/ejbfreeform/nbproject/project.xml (-1 / +1 lines)
Lines 38-44 Link Here
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>1</release-version>
40
                        <release-version>1</release-version>
41
                        <specification-version>1.13</specification-version>
41
                        <specification-version>1.14</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/EJBProjectNature.java (-157 / +2 lines)
Lines 20-52 Link Here
20
package org.netbeans.modules.j2ee.ejbfreeform;
20
package org.netbeans.modules.j2ee.ejbfreeform;
21
21
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.lang.ref.WeakReference;
24
import java.util.ArrayList;
23
import java.util.ArrayList;
25
import java.util.Arrays;
24
import java.util.Arrays;
26
import java.util.HashSet;
25
import java.util.HashSet;
27
import java.util.List;
26
import java.util.List;
28
import java.util.Set;
27
import java.util.Set;
29
import java.util.WeakHashMap;
30
import org.netbeans.api.java.classpath.ClassPath;
28
import org.netbeans.api.java.classpath.ClassPath;
31
import org.netbeans.api.project.Project;
29
import org.netbeans.api.project.Project;
32
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
33
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
30
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
34
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
35
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
31
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
36
import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
32
import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
37
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
33
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
38
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
39
import org.netbeans.modules.j2ee.ejbfreeform.ui.EJBLocationsPanel;
40
import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
34
import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView;
41
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport;
42
import org.netbeans.spi.project.AuxiliaryConfiguration;
35
import org.netbeans.spi.project.AuxiliaryConfiguration;
43
import org.netbeans.spi.project.support.ant.AntProjectEvent;
44
import org.netbeans.spi.project.support.ant.AntProjectHelper;
36
import org.netbeans.spi.project.support.ant.AntProjectHelper;
45
import org.netbeans.spi.project.support.ant.AntProjectListener;
46
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
37
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
47
import org.netbeans.spi.project.ui.PrivilegedTemplates;
48
import org.netbeans.spi.project.ui.ProjectOpenedHook;
49
import org.netbeans.spi.project.ui.RecommendedTemplates;
50
import org.openide.ErrorManager;
38
import org.openide.ErrorManager;
51
import org.openide.filesystems.FileObject;
39
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileUtil;
40
import org.openide.filesystems.FileUtil;
Lines 55-64 Link Here
55
import org.openide.nodes.Node;
43
import org.openide.nodes.Node;
56
import org.openide.nodes.NodeNotFoundException;
44
import org.openide.nodes.NodeNotFoundException;
57
import org.openide.nodes.NodeOp;
45
import org.openide.nodes.NodeOp;
58
import org.openide.util.Lookup;
59
import org.openide.util.NbBundle;
46
import org.openide.util.NbBundle;
60
import org.openide.util.lookup.Lookups;
61
import org.openide.util.lookup.ProxyLookup;
62
47
63
/**
48
/**
64
 * @author David Konecny
49
 * @author David Konecny
Lines 73-104 Link Here
73
    public static final String EL_EJB = "ejb-data"; // NOI18N
58
    public static final String EL_EJB = "ejb-data"; // NOI18N
74
    public static final String STYLE_CONFIG_FILES = "configFiles"; // NOI18N
59
    public static final String STYLE_CONFIG_FILES = "configFiles"; // NOI18N
75
    public static final String STYLE_EJBS = "ejbs"; // NOI18N
60
    public static final String STYLE_EJBS = "ejbs"; // NOI18N
76
77
    private static final String HELP_ID_FRAGMENT = "ejb"; // NOI18N
78
    
79
    private static final WeakHashMap/*<Project,WeakReference<Lookup>>*/ lookupCache = new WeakHashMap();
80
    
61
    
81
    public EJBProjectNature() {}
62
    public EJBProjectNature() {}
82
63
83
    public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
64
   
84
        WeakReference wr = (WeakReference)lookupCache.get(project);
85
        Lookup lookup = wr != null ? (Lookup)wr.get() : null;
86
        if (lookup == null) {
87
            lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux);
88
            lookupCache.put(project, new WeakReference(lookup));
89
        }
90
        return lookup;
91
    }
92
    
93
    public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
94
        HashSet l = new HashSet();
95
        if (!isMyProject(aux)) {
96
            return l;
97
        }
98
        ProjectPropertiesPanel ejb = new EJBLocationsPanel.Panel(project, projectHelper, projectEvaluator, aux);
99
        l.add(ejb);
100
        return l;
101
    }
102
    
65
    
103
    public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
66
    public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
104
        ArrayList l = new ArrayList();
67
        ArrayList l = new ArrayList();
Lines 175-181 Link Here
175
        }
138
        }
176
    }
139
    }
177
140
178
    private static boolean isMyProject(AuxiliaryConfiguration aux) {
141
    public static boolean isMyProject(AuxiliaryConfiguration aux) {
179
        return (aux.getConfigurationFragment(EL_EJB, NS_EJB, true) != null) ||
142
        return (aux.getConfigurationFragment(EL_EJB, NS_EJB, true) != null) ||
180
               (aux.getConfigurationFragment(EL_EJB, NS_EJB_2, true) != null);
143
               (aux.getConfigurationFragment(EL_EJB, NS_EJB_2, true) != null);
181
    }
144
    }
Lines 186-308 Link Here
186
            NbBundle.getMessage(EJBProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N
149
            NbBundle.getMessage(EJBProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N
187
    }
150
    }
188
    
151
    
189
    private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
190
        
191
        EJBFreeformProvider ejbFFProvider = new EJBFreeformProvider(project, projectHelper, projectEvaluator);
192
        EJBFreeformModule ejbFFModule = new EJBFreeformModule(project, projectHelper, projectEvaluator);
193
        ejbFFProvider.setJ2eeModule(ejbFFModule);
194
                
195
        return Lookups.fixed(new Object[] {
196
            ejbFFProvider,
197
            ejbFFModule,
198
            new EJBModules(project, projectHelper, projectEvaluator), // EJBModuleProvider, ClassPathProvider
199
            new PrivilegedTemplatesImpl(), // List of templates in New action popup
200
            EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(project, projectHelper),
201
            new EjbFreeFormActionProvider(project, projectHelper, aux),
202
            new ProjectOpenedHookImpl(project),
203
            new LookupMergerImpl(),
204
            new HelpIDFragmentProviderImpl(),
205
        });
206
    }
207
    
208
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
209
        public String getHelpIDFragment() {
210
            return HELP_ID_FRAGMENT;
211
        }
212
    }
213
    
214
    private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
215
216
        private AntProjectHelper helper;
217
        private PropertyEvaluator evaluator;
218
        private Project project;
219
        private AuxiliaryConfiguration aux;
220
        private boolean isMyProject;
221
        
222
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
223
            super(new Lookup[0]);
224
            this.project = project;
225
            this.helper = helper;
226
            this.evaluator = evaluator;
227
            this.aux = aux;
228
            this.isMyProject = isMyProject(aux);
229
            updateLookup();
230
            helper.addAntProjectListener(this);
231
        }
232
        
233
        private void updateLookup() {
234
            Lookup l = Lookup.EMPTY;
235
            if (isMyProject) {
236
                l = initLookup(project, helper, evaluator, aux);
237
            }
238
            setLookups(new Lookup[]{l});
239
        }
240
        
241
        public void configurationXmlChanged(AntProjectEvent ev) {
242
            if (isMyProject(aux) != isMyProject) {
243
                isMyProject = !isMyProject;
244
                updateLookup();
245
            }
246
        }
247
        
248
        public void propertiesChanged(AntProjectEvent ev) {
249
            // ignore
250
        }
251
        
252
    }
253
    
254
    private static final class ProjectOpenedHookImpl extends ProjectOpenedHook {
255
        
256
        private Project project;
257
        
258
        public ProjectOpenedHookImpl(Project project) {
259
            this.project = project;
260
        }
261
        
262
        protected void projectOpened() {
263
            // initialize the server configuration
264
            J2eeModuleProvider j2eeModule = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
265
            j2eeModule.getConfigSupport().ensureConfigurationReady();
266
        }
267
268
        protected void projectClosed() {
269
        }
270
    }
271
272
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
273
        
274
        private static final String[] PRIVILEGED_NAMES = new String[] {
275
            "Templates/J2EE/Session", // NOI18N
276
            "Templates/J2EE/Entity",  // NOI18N
277
            "Templates/J2EE/ServiceLocator.java", // NOI18N
278
            "Templates/Classes/Class.java" // NOI18N
279
        };
280
        
281
        private static final String[] RECOMENDED_TYPES = new String[] {
282
            "java-classes",         // NOI18N
283
            "ejb-types",            // NOI18N
284
            "ejb-types_2_1",        // NOI18N
285
            "j2ee-types",           // NOI18N
286
            "java-beans",           // NOI18N
287
            "oasis-XML-catalogs",   // NOI18N
288
            "XML",                  // NOI18N
289
            "wsdl",                 // NOI18N
290
            "ant-script",           // NOI18N
291
            "ant-task",             // NOI18N
292
            "junit",                // NOI18N
293
            "simple-files"          // NOI18N
294
        };
295
        
296
        public String[] getPrivilegedTemplates() {
297
            return PRIVILEGED_NAMES;
298
        }
299
300
        public String[] getRecommendedTypes() {
301
            return RECOMENDED_TYPES;
302
        }
303
     
304
    
305
    
306
    }
307
    
152
    
308
}
153
}
(-)j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/LookupProviderImpl.java (+182 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.ejbfreeform;
21
22
import org.netbeans.api.project.Project;
23
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
24
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
25
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
26
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport;
27
import org.netbeans.spi.project.AuxiliaryConfiguration;
28
import org.netbeans.spi.project.LookupProvider;
29
import org.netbeans.spi.project.support.ant.AntProjectEvent;
30
import org.netbeans.spi.project.support.ant.AntProjectHelper;
31
import org.netbeans.spi.project.support.ant.AntProjectListener;
32
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
33
import org.netbeans.spi.project.ui.PrivilegedTemplates;
34
import org.netbeans.spi.project.ui.ProjectOpenedHook;
35
import org.netbeans.spi.project.ui.RecommendedTemplates;
36
import org.openide.util.Lookup;
37
import org.openide.util.lookup.Lookups;
38
import org.openide.util.lookup.ProxyLookup;
39
40
/**
41
 *
42
 * @author mkleint
43
 */
44
public class LookupProviderImpl implements LookupProvider {
45
    
46
    private static final String HELP_ID_FRAGMENT = "ejb"; // NOI18N
47
   
48
    /** Creates a new instance of LookupProviderImpl */
49
    public LookupProviderImpl() {
50
    }
51
    
52
    public Lookup createAdditionalLookup(Lookup baseContext) {
53
        Project prj = (Project)baseContext.lookup(Project.class);
54
        ProjectAccessor acc = (ProjectAccessor)baseContext.lookup(ProjectAccessor.class);
55
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)baseContext.lookup(AuxiliaryConfiguration.class);
56
        assert aux != null;
57
        assert prj != null;
58
        assert acc != null;
59
        return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux);
60
    }
61
    
62
    private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
63
        
64
        EJBFreeformProvider ejbFFProvider = new EJBFreeformProvider(project, projectHelper, projectEvaluator);
65
        EJBFreeformModule ejbFFModule = new EJBFreeformModule(project, projectHelper, projectEvaluator);
66
        ejbFFProvider.setJ2eeModule(ejbFFModule);
67
                
68
        return Lookups.fixed(new Object[] {
69
            ejbFFProvider,
70
            ejbFFModule,
71
            new EJBModules(project, projectHelper, projectEvaluator), // EJBModuleProvider, ClassPathProvider
72
            new PrivilegedTemplatesImpl(), // List of templates in New action popup
73
            EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(project, projectHelper),
74
            new EjbFreeFormActionProvider(project, projectHelper, aux),
75
            new ProjectOpenedHookImpl(project),
76
            new LookupMergerImpl(),
77
            new HelpIDFragmentProviderImpl(),
78
        });
79
    }
80
    
81
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
82
        public String getHelpIDFragment() {
83
            return HELP_ID_FRAGMENT;
84
        }
85
    }
86
    
87
    private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
88
89
        private AntProjectHelper helper;
90
        private PropertyEvaluator evaluator;
91
        private Project project;
92
        private AuxiliaryConfiguration aux;
93
        private boolean isMyProject;
94
        
95
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
96
            super(new Lookup[0]);
97
            this.project = project;
98
            this.helper = helper;
99
            this.evaluator = evaluator;
100
            this.aux = aux;
101
            this.isMyProject = EJBProjectNature.isMyProject(aux);
102
            updateLookup();
103
            helper.addAntProjectListener(this);
104
        }
105
        
106
        private void updateLookup() {
107
            Lookup l = Lookup.EMPTY;
108
            if (isMyProject) {
109
                l = initLookup(project, helper, evaluator, aux);
110
            }
111
            setLookups(new Lookup[]{l});
112
        }
113
        
114
        public void configurationXmlChanged(AntProjectEvent ev) {
115
            if (EJBProjectNature.isMyProject(aux) != isMyProject) {
116
                isMyProject = !isMyProject;
117
                updateLookup();
118
            }
119
        }
120
        
121
        public void propertiesChanged(AntProjectEvent ev) {
122
            // ignore
123
        }
124
        
125
    }
126
    
127
    private static final class ProjectOpenedHookImpl extends ProjectOpenedHook {
128
        
129
        private Project project;
130
        
131
        public ProjectOpenedHookImpl(Project project) {
132
            this.project = project;
133
        }
134
        
135
        protected void projectOpened() {
136
            // initialize the server configuration
137
            J2eeModuleProvider j2eeModule = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
138
            j2eeModule.getConfigSupport().ensureConfigurationReady();
139
        }
140
141
        protected void projectClosed() {
142
        }
143
    }
144
145
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
146
        
147
        private static final String[] PRIVILEGED_NAMES = new String[] {
148
            "Templates/J2EE/Session", // NOI18N
149
            "Templates/J2EE/Entity",  // NOI18N
150
            "Templates/J2EE/ServiceLocator.java", // NOI18N
151
            "Templates/Classes/Class.java" // NOI18N
152
        };
153
        
154
        private static final String[] RECOMENDED_TYPES = new String[] {
155
            "java-classes",         // NOI18N
156
            "ejb-types",            // NOI18N
157
            "ejb-types_2_1",        // NOI18N
158
            "j2ee-types",           // NOI18N
159
            "java-beans",           // NOI18N
160
            "oasis-XML-catalogs",   // NOI18N
161
            "XML",                  // NOI18N
162
            "wsdl",                 // NOI18N
163
            "ant-script",           // NOI18N
164
            "ant-task",             // NOI18N
165
            "junit",                // NOI18N
166
            "simple-files"          // NOI18N
167
        };
168
        
169
        public String[] getPrivilegedTemplates() {
170
            return PRIVILEGED_NAMES;
171
        }
172
173
        public String[] getRecommendedTypes() {
174
            return RECOMENDED_TYPES;
175
        }
176
     
177
    
178
    
179
    }
180
    
181
182
}
(-)j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/resources/layer.xml (+12 lines)
Lines 35-38 Link Here
35
35
36
        </folder>
36
        </folder>
37
    </folder>
37
    </folder>
38
    <folder name="Projects">
39
        <folder name="org-netbeans-modules-ant-freeform">
40
            <folder name="Lookup">
41
                <file name="org-netbeans-modules-j2ee-ejbfreeform-LookupProviderImpl.instance"/>
42
            </folder>
43
            <folder name="Customizer">
44
                <file name="org-netbeans-modules-j2ee-ejbfreeform-ui-EjbLocationsCategoryProvider.instance"/>
45
                <attr name="org-netbeans-modules-j2ee-ejbfreeform-ui-EjbLocationsCategoryProvider.instance/org-netbeans-modules-java-freeform-ui-SourceFoldersCategoryProvider.instance" boolvalue="true"/>
46
            </folder>
47
        </folder>
48
    </folder>
49
    
38
</filesystem>
50
</filesystem>
(-)j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EJBLocationsPanel.java (-57 / +28 lines)
Lines 19-24 Link Here
19
19
20
package org.netbeans.modules.j2ee.ejbfreeform.ui;
20
package org.netbeans.modules.j2ee.ejbfreeform.ui;
21
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
22
import java.io.File;
24
import java.io.File;
23
import java.io.FilenameFilter;
25
import java.io.FilenameFilter;
24
import java.io.IOException;
26
import java.io.IOException;
Lines 27-40 Link Here
27
import java.util.HashSet;
29
import java.util.HashSet;
28
import java.util.List;
30
import java.util.List;
29
import java.util.Set;
31
import java.util.Set;
30
import javax.swing.JComponent;
31
import javax.swing.JFileChooser;
32
import javax.swing.JFileChooser;
32
import javax.swing.event.ChangeListener;
33
import javax.swing.event.ChangeListener;
33
import javax.swing.event.DocumentEvent;
34
import javax.swing.event.DocumentEvent;
34
import javax.swing.event.DocumentListener;
35
import javax.swing.event.DocumentListener;
35
import org.netbeans.api.project.Project;
36
import org.netbeans.api.project.Project;
36
import org.netbeans.api.queries.CollocationQuery;
37
import org.netbeans.api.queries.CollocationQuery;
37
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
38
import org.netbeans.modules.ant.freeform.spi.support.Util;
38
import org.netbeans.modules.ant.freeform.spi.support.Util;
39
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
39
import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
40
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
40
import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
Lines 582-645 Link Here
582
        return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation);
582
        return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation);
583
    }
583
    }
584
    
584
    
585
    public static class Panel implements ProjectPropertiesPanel {
585
    ActionListener getCustomizerOkListener() {
586
        
586
        return new ActionListener() {
587
        private Project project;
587
            public void actionPerformed(ActionEvent arg0) {
588
        private AntProjectHelper projectHelper;
588
                
589
        private PropertyEvaluator projectEvaluator;
589
                AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
590
        private AuxiliaryConfiguration aux;
590
                EJBProjectGenerator.putEJBModules(projectHelper, aux, getEJBModules());
591
        private EJBLocationsPanel panel;
591
                EJBProjectGenerator.putServerID(projectHelper, getSelectedServerID());
592
        
592
                EJBProjectGenerator.putResourceFolder(projectHelper, getResourcesFolder());
593
        public Panel(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
593
                
594
            this.project = project;
594
                String j2eeLevel = ((EJBProjectGenerator.EJBModule)getEJBModules().get(0)).j2eeSpecLevel;
595
            this.projectHelper = projectHelper;
595
                EJBProjectGenerator.putJ2EELevel(projectHelper, j2eeLevel);
596
            this.projectEvaluator = projectEvaluator;
596
                
597
            this.aux = aux;
597
                // update the DD to 2.1 if it is 2.0 and the user switched to J2EE 1.4
598
        }
598
                FileObject ejbJarXml = findEbjJarXml(getConfigFilesLocation());
599
        
599
                try {
600
        public void storeValues() {
600
                    if (j2eeLevel.equals("1.4") && !new BigDecimal(EjbJar.VERSION_2_1).equals(getEjbJarXmlVersion(ejbJarXml))) { // NOI18N
601
            if (panel == null) {
601
                        EjbJar root = DDProvider.getDefault().getDDRoot(ejbJarXml);
602
                return;
602
                        root.setVersion(new BigDecimal(EjbJar.VERSION_2_1));
603
            }
603
                        root.write(ejbJarXml);
604
            AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
604
                    }
605
            EJBProjectGenerator.putEJBModules(projectHelper, aux, panel.getEJBModules());
605
                } catch (IOException e) {
606
            EJBProjectGenerator.putServerID(projectHelper, panel.getSelectedServerID());
606
                    final ErrorManager errorManager = ErrorManager.getDefault();
607
            EJBProjectGenerator.putResourceFolder(projectHelper, panel.getResourcesFolder());
607
                    String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted");
608
            
608
                    errorManager.notify(errorManager.annotate(e, message));
609
            String j2eeLevel = ((EJBProjectGenerator.EJBModule)panel.getEJBModules().get(0)).j2eeSpecLevel;
610
            EJBProjectGenerator.putJ2EELevel(projectHelper, j2eeLevel);
611
            
612
            // update the DD to 2.1 if it is 2.0 and the user switched to J2EE 1.4
613
            FileObject ejbJarXml = findEbjJarXml(panel.getConfigFilesLocation());
614
            try {
615
                if (j2eeLevel.equals("1.4") && !new BigDecimal(EjbJar.VERSION_2_1).equals(getEjbJarXmlVersion(ejbJarXml))) { // NOI18N
616
                    EjbJar root = DDProvider.getDefault().getDDRoot(ejbJarXml);
617
                    root.setVersion(new BigDecimal(EjbJar.VERSION_2_1));
618
                    root.write(ejbJarXml);
619
                }
609
                }
620
            }
610
            }
621
            catch (IOException e) {
611
        };
622
                final ErrorManager errorManager = ErrorManager.getDefault();
623
                String message = NbBundle.getMessage(EJBLocationsPanel.class, "MSG_EjbJarXmlCorrupted");
624
                errorManager.notify(errorManager.annotate(e, message));
625
            }
626
        }
627
        
628
        public String getDisplayName() {
629
            return NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ProjectCustomizer_Category_EJB");
630
        }
631
        
632
        public JComponent getComponent() {
633
            if (panel == null) {
634
                panel = new EJBLocationsPanel(null, project, projectHelper, projectEvaluator, aux);
635
            }
636
            return panel;
637
        }
638
        
639
        public int getPreferredPosition() {
640
            return 40; // before Java sources panel
641
        }
642
    }
612
    }
613
        
643
    
614
    
644
    private void initServerInstances() {
615
    private void initServerInstances() {
645
        String[] servInstIDs = Deployment.getDefault().getServerInstanceIDs();
616
        String[] servInstIDs = Deployment.getDefault().getServerInstanceIDs();
(-)j2ee/ejbfreeform/src/org/netbeans/modules/j2ee/ejbfreeform/ui/EjbLocationsCategoryProvider.java (+66 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.j2ee.ejbfreeform.ui;
21
22
import javax.swing.JComponent;
23
import org.netbeans.api.project.Project;
24
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
25
import org.netbeans.modules.j2ee.ejbfreeform.EJBProjectNature;
26
import org.netbeans.spi.project.AuxiliaryConfiguration;
27
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
28
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
29
import org.openide.util.Lookup;
30
import org.openide.util.NbBundle;
31
32
/**
33
 *
34
 * @author mkleint
35
 */
36
public class EjbLocationsCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
37
    
38
    /** Creates a new instance of EjbLocationsCategoryProvider */
39
    public EjbLocationsCategoryProvider() {
40
    }
41
    
42
    public Category createCategory(Lookup context) {
43
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
44
        assert aux != null;
45
        if (EJBProjectNature.isMyProject(aux)) {
46
            Category cat = ProjectCustomizer.Category.create("EjbLocations", //NOI18N
47
                    NbBundle.getMessage(EJBLocationsPanel.class, "LBL_ProjectCustomizer_Category_EJB"), null, null);
48
            return cat;
49
        }
50
        return null;
51
    }
52
53
    public JComponent createComponent(Category category, Lookup context) {
54
        Project project = (Project)context.lookup(Project.class);
55
        ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class);
56
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
57
        assert aux != null;
58
        assert acc != null;
59
        assert project != null;
60
        
61
        EJBLocationsPanel panel = new EJBLocationsPanel(null, project, acc.getHelper(), acc.getEvaluator(), aux);
62
        category.setOkButtonListener(panel.getCustomizerOkListener());
63
        return panel;
64
    }
65
66
}
(-)java/freeform/nbproject/project.xml (-1 / +1 lines)
Lines 56-62 Link Here
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>1</release-version>
58
                        <release-version>1</release-version>
59
                        <specification-version>1.13</specification-version>
59
                        <specification-version>1.14</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
(-)java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java (-244 lines)
Lines 19-65 Link Here
19
19
20
package org.netbeans.modules.java.freeform;
20
package org.netbeans.modules.java.freeform;
21
21
22
import java.lang.ref.Reference;
23
import java.lang.ref.WeakReference;
24
import java.util.ArrayList;
22
import java.util.ArrayList;
25
import java.util.Arrays;
23
import java.util.Arrays;
26
import java.util.Collections;
24
import java.util.Collections;
27
import java.util.HashSet;
25
import java.util.HashSet;
28
import java.util.List;
26
import java.util.List;
29
import java.util.Map;
30
import java.util.Set;
27
import java.util.Set;
31
import java.util.WeakHashMap;
32
import org.netbeans.api.project.Project;
28
import org.netbeans.api.project.Project;
33
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
34
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
29
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
35
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
36
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
30
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
37
import org.netbeans.modules.ant.freeform.spi.support.Util;
38
import org.netbeans.modules.java.freeform.ui.ClasspathPanel;
39
import org.netbeans.modules.java.freeform.ui.OutputPanel;
40
import org.netbeans.modules.java.freeform.ui.ProjectModel;
41
import org.netbeans.modules.java.freeform.ui.SourceFoldersPanel;
42
import org.netbeans.spi.java.project.support.ui.PackageView;
31
import org.netbeans.spi.java.project.support.ui.PackageView;
43
import org.netbeans.spi.project.AuxiliaryConfiguration;
32
import org.netbeans.spi.project.AuxiliaryConfiguration;
44
import org.netbeans.spi.project.support.GenericSources;
33
import org.netbeans.spi.project.support.GenericSources;
45
import org.netbeans.spi.project.support.ant.AntProjectEvent;
46
import org.netbeans.spi.project.support.ant.AntProjectHelper;
34
import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
import org.netbeans.spi.project.support.ant.AntProjectListener;
48
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
35
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
49
import org.netbeans.spi.project.ui.PrivilegedTemplates;
50
import org.netbeans.spi.project.ui.ProjectOpenedHook;
51
import org.netbeans.spi.project.ui.RecommendedTemplates;
52
import org.openide.filesystems.FileObject;
36
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
54
import org.openide.util.Lookup;
55
import org.openide.util.lookup.Lookups;
56
import org.openide.util.lookup.ProxyLookup;
57
import org.w3c.dom.Comment;
58
import org.w3c.dom.Document;
59
import org.w3c.dom.Element;
60
import org.w3c.dom.NamedNodeMap;
61
import org.w3c.dom.NodeList;
62
import org.w3c.dom.Text;
63
37
64
/**
38
/**
65
 * General hook for registration of the Java nature for freeform projects.
39
 * General hook for registration of the Java nature for freeform projects.
Lines 74-109 Link Here
74
    private static final String SCHEMA_2 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java-2.xsd"; // NOI18N
48
    private static final String SCHEMA_2 = "nbres:/org/netbeans/modules/java/freeform/resources/freeform-project-java-2.xsd"; // NOI18N
75
    public static final String STYLE_PACKAGES = "packages"; // NOI18N
49
    public static final String STYLE_PACKAGES = "packages"; // NOI18N
76
    
50
    
77
    private static final String HELP_ID_FRAGMENT = "java"; // NOI18N
78
    
79
    private static final Map<Project,Reference<Lookup>> lookupCache = new WeakHashMap<Project,Reference<Lookup>>();
80
    
51
    
81
    public JavaProjectNature() {}
52
    public JavaProjectNature() {}
82
83
    public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
84
        Reference<Lookup> wr = lookupCache.get(project);
85
        Lookup lookup = wr != null ? wr.get() : null;
86
        if (lookup == null) {
87
            lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux);
88
            lookupCache.put(project, new WeakReference<Lookup>(lookup));
89
        }
90
        return lookup;
91
    }
92
    
93
    public Set<ProjectPropertiesPanel> getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
94
        Set<ProjectPropertiesPanel> l = new HashSet<ProjectPropertiesPanel>();
95
        if (!isMyProject(aux)) {
96
            return l;
97
        }
98
        ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(projectHelper, projectEvaluator), FileUtil.toFile(project.getProjectDirectory()), projectEvaluator, projectHelper);
99
        ProjectPropertiesPanel sfp = new SourceFoldersPanel.Panel(pm, projectHelper);
100
        l.add(sfp);
101
        ProjectPropertiesPanel cpp = new ClasspathPanel.Panel(project, projectHelper, projectEvaluator, pm);
102
        l.add(cpp);
103
        ProjectPropertiesPanel op = new OutputPanel.Panel(pm);
104
        l.add(op);
105
        return l;
106
    }
107
    
53
    
108
    public List<TargetDescriptor> getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
54
    public List<TargetDescriptor> getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
109
        return new ArrayList<TargetDescriptor>();
55
        return new ArrayList<TargetDescriptor>();
Lines 133-333 Link Here
133
        return PackageView.findPath(root, target);
79
        return PackageView.findPath(root, target);
134
    }
80
    }
135
81
136
    private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
137
        Classpaths cp = new Classpaths(projectHelper, projectEvaluator, aux);
138
        return Lookups.fixed(
139
            cp, // ClassPathProvider
140
            new SourceLevelQueryImpl(projectHelper, projectEvaluator, aux), // SourceLevelQueryImplementation
141
            new SourceForBinaryQueryImpl(projectHelper, projectEvaluator, aux), // SourceForBinaryQueryImplementation
142
            new OpenHook(cp), // ProjectOpenedHook
143
            new TestQuery(projectHelper, projectEvaluator, aux), // MultipleRootsUnitTestForSourceQueryImplementation
144
            new JavadocQuery(projectHelper, projectEvaluator, aux), // JavadocForBinaryQueryImplementation
145
            new PrivilegedTemplatesImpl(), // PrivilegedTemplates
146
            new JavaActions(project, projectHelper, projectEvaluator, aux), // ActionProvider
147
            new LookupMergerImpl(), // LookupMerger
148
            new JavaFreeformFileBuiltQuery(project, projectHelper, projectEvaluator, aux), // FileBuiltQueryImplementation
149
            new HelpIDFragmentProviderImpl());
150
    }
151
    
152
    private static boolean isMyProject(AuxiliaryConfiguration aux) {
153
        return aux.getConfigurationFragment(EL_JAVA, NS_JAVA_1, true) != null ||
154
               aux.getConfigurationFragment(EL_JAVA, NS_JAVA_2, true) != null;
155
    }
156
    
82
    
157
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
158
        public String getHelpIDFragment() {
159
            return HELP_ID_FRAGMENT;
160
        }
161
    }
162
    
163
    private static class OpenHook extends ProjectOpenedHook {
164
        
165
        private final Classpaths cp;
166
        
167
        public OpenHook(Classpaths cp) {
168
            this.cp = cp;
169
        }
170
        
171
        protected void projectOpened() {
172
            cp.opened();
173
        }
174
        
175
        protected void projectClosed() {
176
            cp.closed();
177
        }
178
        
179
    }
180
    
181
    /**
182
     * Transparently handles /1 -> /2 schema upgrade (on read only, not write!).
183
     */
184
    static final class UpgradingAuxiliaryConfiguration implements AuxiliaryConfiguration {
185
        
186
        private final AuxiliaryConfiguration delegate;
187
        
188
        public UpgradingAuxiliaryConfiguration(AuxiliaryConfiguration delegate) {
189
            this.delegate = delegate;
190
        }
191
192
        public Element getConfigurationFragment(String elementName, String namespace, boolean shared) {
193
            if (elementName.equals(EL_JAVA) && namespace.equals(NS_JAVA_2) && shared) {
194
                Element nue = delegate.getConfigurationFragment(EL_JAVA, NS_JAVA_2, true);
195
                if (nue == null) {
196
                    Element old = delegate.getConfigurationFragment(EL_JAVA, NS_JAVA_1, true);
197
                    if (old != null) {
198
                        nue = upgradeSchema(old);
199
                    }
200
                }
201
                return nue;
202
            } else {
203
                return delegate.getConfigurationFragment(elementName, namespace, shared);
204
            }
205
        }
206
83
207
        public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException {
208
            delegate.putConfigurationFragment(fragment, shared);
209
        }
210
        
211
        public boolean removeConfigurationFragment(String elementName, String namespace, boolean shared) throws IllegalArgumentException {
212
            return delegate.removeConfigurationFragment(elementName, namespace, shared);
213
        }
214
        
215
    }
216
84
217
    static Element upgradeSchema(Element old) {
218
        Document doc = old.getOwnerDocument();
219
        Element nue = doc.createElementNS(NS_JAVA_2, EL_JAVA);
220
        copyXMLTree(doc, old, nue, NS_JAVA_2);
221
        return nue;
222
    }
223
85
224
    // Copied from org.netbeans.modules.java.j2seproject.UpdateHelper with changes; could be an API eventually:
225
    private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) {
226
        NodeList nl = from.getChildNodes();
227
        int length = nl.getLength();
228
        for (int i = 0; i < length; i++) {
229
            org.w3c.dom.Node node = nl.item(i);
230
            org.w3c.dom.Node newNode;
231
            switch (node.getNodeType()) {
232
                case org.w3c.dom.Node.ELEMENT_NODE:
233
                    Element oldElement = (Element) node;
234
                    newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
235
                    NamedNodeMap attrs = oldElement.getAttributes();
236
                    int alength = attrs.getLength();
237
                    for (int j = 0; j < alength; j++) {
238
                        org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j);
239
                        ((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue());
240
                    }
241
                    copyXMLTree(doc, oldElement, (Element) newNode, newNamespace);
242
                    break;
243
                case org.w3c.dom.Node.TEXT_NODE:
244
                    newNode = doc.createTextNode(((Text) node).getData());
245
                    break;
246
                case org.w3c.dom.Node.COMMENT_NODE:
247
                    newNode = doc.createComment(((Comment) node).getData());
248
                    break;
249
                default:
250
                    // Other types (e.g. CDATA) not yet handled.
251
                    throw new AssertionError(node);
252
            }
253
            to.appendChild(newNode);
254
        }
255
    }
256
86
257
    private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
258
87
259
        private AntProjectHelper helper;
260
        private PropertyEvaluator evaluator;
261
        private Project project;
262
        private AuxiliaryConfiguration aux;
263
        private boolean isMyProject;
264
        
265
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
266
            super(new Lookup[0]);
267
            this.project = project;
268
            this.helper = helper;
269
            this.evaluator = evaluator;
270
            this.aux = new UpgradingAuxiliaryConfiguration(aux);
271
            this.isMyProject = isMyProject(aux);
272
            updateLookup();
273
            helper.addAntProjectListener(this);
274
        }
275
        
276
        private void updateLookup() {
277
            Lookup l = Lookup.EMPTY;
278
            if (isMyProject) {
279
                l = initLookup(project, helper, evaluator, aux);
280
            }
281
            setLookups(new Lookup[]{l});
282
        }
283
        
284
        public void configurationXmlChanged(AntProjectEvent ev) {
285
            if (isMyProject(aux) != isMyProject) {
286
                isMyProject = !isMyProject;
287
                updateLookup();
288
            }
289
        }
290
        
291
        public void propertiesChanged(AntProjectEvent ev) {
292
            // ignore
293
        }
294
        
295
    }
296
    
297
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
298
        
299
        private static final String[] PRIVILEGED_NAMES = new String[] {
300
            "Templates/Classes/Class.java", // NOI18N
301
            "Templates/Classes/Package", // NOI18N
302
            "Templates/Classes/Interface.java", // NOI18N
303
        };
304
        
305
        // List of primarily supported templates = J2SEProject.LIBRARY_TYPES + J2SEProject.APPLICATION_TYPES
306
        private static final String[] RECOMENDED_TYPES = new String[] { 
307
            "java-classes",         // NOI18N
308
            "java-main-class",      // NOI18N
309
            "java-forms",           // NOI18N
310
            "gui-java-application", // NOI18N
311
            "java-beans",           // NOI18N
312
            "oasis-XML-catalogs",   // NOI18N
313
            "XML",                  // NOI18N
314
            "ant-script",           // NOI18N
315
            "ant-task",             // NOI18N
316
            "servlet-types",        // NOI18N
317
            "wsdl",                 // NOI18N
318
            "junit",                // NOI18N
319
            // "MIDP",              // NOI18N
320
            "simple-files"          // NOI18N
321
        };
322
        
323
        public String[] getRecommendedTypes() {            
324
            return RECOMENDED_TYPES;
325
        }
326
        
327
        public String[] getPrivilegedTemplates() {
328
            return PRIVILEGED_NAMES;
329
        }
330
        
331
    }
332
    
88
    
333
}
89
}
(-)java/freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java (+261 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.java.freeform;
21
22
import org.netbeans.api.project.Project;
23
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
24
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
25
import org.netbeans.spi.project.AuxiliaryConfiguration;
26
import org.netbeans.spi.project.LookupProvider;
27
import org.netbeans.spi.project.support.ant.AntProjectEvent;
28
import org.netbeans.spi.project.support.ant.AntProjectHelper;
29
import org.netbeans.spi.project.support.ant.AntProjectListener;
30
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
31
import org.netbeans.spi.project.ui.PrivilegedTemplates;
32
import org.netbeans.spi.project.ui.ProjectOpenedHook;
33
import org.netbeans.spi.project.ui.RecommendedTemplates;
34
import org.openide.util.Lookup;
35
import org.openide.util.lookup.Lookups;
36
import org.openide.util.lookup.ProxyLookup;
37
import org.w3c.dom.Comment;
38
import org.w3c.dom.Document;
39
import org.w3c.dom.Element;
40
import org.w3c.dom.NamedNodeMap;
41
import org.w3c.dom.NodeList;
42
import org.w3c.dom.Text;
43
44
/**
45
 *
46
 * @author mkleint
47
 */
48
public class LookupProviderImpl implements LookupProvider {
49
     private static final String HELP_ID_FRAGMENT = "java"; // NOI18N
50
  
51
    /** Creates a new instance of LookupProviderImpl */
52
    public LookupProviderImpl() {
53
    }
54
    
55
    public Lookup createAdditionalLookup(Lookup baseContext) {
56
        Project prj = baseContext.lookup(Project.class);
57
        ProjectAccessor acc = baseContext.lookup(ProjectAccessor.class);
58
        AuxiliaryConfiguration aux = baseContext.lookup(AuxiliaryConfiguration.class);
59
        assert aux != null;
60
        assert prj != null;
61
        assert acc != null;
62
        return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux);
63
    }
64
    
65
    private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
66
        Classpaths cp = new Classpaths(projectHelper, projectEvaluator, aux);
67
        return Lookups.fixed(
68
            cp, // ClassPathProvider
69
            new SourceLevelQueryImpl(projectHelper, projectEvaluator, aux), // SourceLevelQueryImplementation
70
            new SourceForBinaryQueryImpl(projectHelper, projectEvaluator, aux), // SourceForBinaryQueryImplementation
71
            new OpenHook(cp), // ProjectOpenedHook
72
            new TestQuery(projectHelper, projectEvaluator, aux), // MultipleRootsUnitTestForSourceQueryImplementation
73
            new JavadocQuery(projectHelper, projectEvaluator, aux), // JavadocForBinaryQueryImplementation
74
            new PrivilegedTemplatesImpl(), // PrivilegedTemplates
75
            new JavaActions(project, projectHelper, projectEvaluator, aux), // ActionProvider
76
            new LookupMergerImpl(), // LookupMerger
77
            new JavaFreeformFileBuiltQuery(project, projectHelper, projectEvaluator, aux), // FileBuiltQueryImplementation
78
            new HelpIDFragmentProviderImpl());
79
    }
80
    
81
    public static boolean isMyProject(AuxiliaryConfiguration aux) {
82
        return aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true) != null ||
83
               aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true) != null;
84
    }
85
    
86
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
87
        public String getHelpIDFragment() {
88
            return HELP_ID_FRAGMENT;
89
        }
90
    }
91
    
92
    private static class OpenHook extends ProjectOpenedHook {
93
        
94
        private final Classpaths cp;
95
        
96
        public OpenHook(Classpaths cp) {
97
            this.cp = cp;
98
        }
99
        
100
        protected void projectOpened() {
101
            cp.opened();
102
        }
103
        
104
        protected void projectClosed() {
105
            cp.closed();
106
        }
107
        
108
    }
109
    
110
    /**
111
     * Transparently handles /1 -> /2 schema upgrade (on read only, not write!).
112
     */
113
    static final class UpgradingAuxiliaryConfiguration implements AuxiliaryConfiguration {
114
        
115
        private final AuxiliaryConfiguration delegate;
116
        
117
        public UpgradingAuxiliaryConfiguration(AuxiliaryConfiguration delegate) {
118
            this.delegate = delegate;
119
        }
120
121
        public Element getConfigurationFragment(String elementName, String namespace, boolean shared) {
122
            if (elementName.equals(JavaProjectNature.EL_JAVA) && namespace.equals(JavaProjectNature.NS_JAVA_2) && shared) {
123
                Element nue = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true);
124
                if (nue == null) {
125
                    Element old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true);
126
                    if (old != null) {
127
                        nue = upgradeSchema(old);
128
                    }
129
                }
130
                return nue;
131
            } else {
132
                return delegate.getConfigurationFragment(elementName, namespace, shared);
133
            }
134
        }
135
136
        public void putConfigurationFragment(Element fragment, boolean shared) throws IllegalArgumentException {
137
            delegate.putConfigurationFragment(fragment, shared);
138
        }
139
        
140
        public boolean removeConfigurationFragment(String elementName, String namespace, boolean shared) throws IllegalArgumentException {
141
            return delegate.removeConfigurationFragment(elementName, namespace, shared);
142
        }
143
        
144
    }
145
    
146
    static Element upgradeSchema(Element old) {
147
        Document doc = old.getOwnerDocument();
148
        Element nue = doc.createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA);
149
        copyXMLTree(doc, old, nue, JavaProjectNature.NS_JAVA_2);
150
        return nue;
151
    }  
152
    // Copied from org.netbeans.modules.java.j2seproject.UpdateHelper with changes; could be an API eventually:
153
    private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) {
154
        NodeList nl = from.getChildNodes();
155
        int length = nl.getLength();
156
        for (int i = 0; i < length; i++) {
157
            org.w3c.dom.Node node = nl.item(i);
158
            org.w3c.dom.Node newNode;
159
            switch (node.getNodeType()) {
160
                case org.w3c.dom.Node.ELEMENT_NODE:
161
                    Element oldElement = (Element) node;
162
                    newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
163
                    NamedNodeMap attrs = oldElement.getAttributes();
164
                    int alength = attrs.getLength();
165
                    for (int j = 0; j < alength; j++) {
166
                        org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j);
167
                        ((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue());
168
                    }
169
                    copyXMLTree(doc, oldElement, (Element) newNode, newNamespace);
170
                    break;
171
                case org.w3c.dom.Node.TEXT_NODE:
172
                    newNode = doc.createTextNode(((Text) node).getData());
173
                    break;
174
                case org.w3c.dom.Node.COMMENT_NODE:
175
                    newNode = doc.createComment(((Comment) node).getData());
176
                    break;
177
                default:
178
                    // Other types (e.g. CDATA) not yet handled.
179
                    throw new AssertionError(node);
180
            }
181
            to.appendChild(newNode);
182
        }
183
    }    
184
    
185
    
186
    
187
   private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
188
189
        private AntProjectHelper helper;
190
        private PropertyEvaluator evaluator;
191
        private Project project;
192
        private AuxiliaryConfiguration aux;
193
        private boolean isMyProject;
194
        
195
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
196
            super(new Lookup[0]);
197
            this.project = project;
198
            this.helper = helper;
199
            this.evaluator = evaluator;
200
            this.aux = new UpgradingAuxiliaryConfiguration(aux);
201
            this.isMyProject = isMyProject(aux);
202
            updateLookup();
203
            helper.addAntProjectListener(this);
204
        }
205
        
206
        private void updateLookup() {
207
            Lookup l = Lookup.EMPTY;
208
            if (isMyProject) {
209
                l = initLookup(project, helper, evaluator, aux);
210
            }
211
            setLookups(new Lookup[]{l});
212
        }
213
        
214
        public void configurationXmlChanged(AntProjectEvent ev) {
215
            if (isMyProject(aux) != isMyProject) {
216
                isMyProject = !isMyProject;
217
                updateLookup();
218
            }
219
        }
220
        
221
        public void propertiesChanged(AntProjectEvent ev) {
222
            // ignore
223
        }
224
        
225
    }
226
   private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
227
        
228
        private static final String[] PRIVILEGED_NAMES = new String[] {
229
            "Templates/Classes/Class.java", // NOI18N
230
            "Templates/Classes/Package", // NOI18N
231
            "Templates/Classes/Interface.java", // NOI18N
232
        };
233
        
234
        // List of primarily supported templates = J2SEProject.LIBRARY_TYPES + J2SEProject.APPLICATION_TYPES
235
        private static final String[] RECOMENDED_TYPES = new String[] { 
236
            "java-classes",         // NOI18N
237
            "java-main-class",      // NOI18N
238
            "java-forms",           // NOI18N
239
            "gui-java-application", // NOI18N
240
            "java-beans",           // NOI18N
241
            "oasis-XML-catalogs",   // NOI18N
242
            "XML",                  // NOI18N
243
            "ant-script",           // NOI18N
244
            "ant-task",             // NOI18N
245
            "servlet-types",        // NOI18N
246
            "wsdl",                 // NOI18N
247
            "junit",                // NOI18N
248
            // "MIDP",              // NOI18N
249
            "simple-files"          // NOI18N
250
        };
251
        
252
        public String[] getRecommendedTypes() {            
253
            return RECOMENDED_TYPES;
254
        }
255
        
256
        public String[] getPrivilegedTemplates() {
257
            return PRIVILEGED_NAMES;
258
        }
259
        
260
    }   
261
}
(-)java/freeform/src/org/netbeans/modules/java/freeform/resources/layer.xml (+15 lines)
Lines 36-39 Link Here
36
            </folder>
36
            </folder>
37
        </folder>
37
        </folder>
38
    </folder>
38
    </folder>
39
    <folder name="Projects">
40
        <folder name="org-netbeans-modules-ant-freeform">
41
            <folder name="Lookup">
42
                <file name="org-netbeans-modules-java-freeform-LookupProviderImpl.instance"/>
43
            </folder>
44
            <folder name="Customizer">
45
                <file name="org-netbeans-modules-java-freeform-ui-SourceFoldersCategoryProvider.instance"/>
46
                <attr name="org-netbeans-modules-java-freeform-ui-SourceFoldersCategoryProvider.instance/org-netbeans-modules-java-freeform-ui-ClasspathCategoryProvider.instance" boolvalue="true"/>
47
                <file name="org-netbeans-modules-java-freeform-ui-ClasspathCategoryProvider.instance"/>
48
                <attr name="org-netbeans-modules-java-freeform-ui-ClasspathCategoryProvider.instance/org-netbeans-modules-java-freeform-ui-OutputCategoryProvider.instance" boolvalue="true"/>
49
                <file name="org-netbeans-modules-java-freeform-ui-OutputCategoryProvider.instance"/>
50
            </folder>
51
        </folder>
52
    </folder>
53
    
39
</filesystem>
54
</filesystem>
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathCategoryProvider.java (+97 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.java.freeform.ui;
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24
import java.io.IOException;
25
import javax.swing.JComponent;
26
import javax.swing.event.ChangeEvent;
27
import javax.swing.event.ChangeListener;
28
import org.netbeans.api.java.platform.JavaPlatform;
29
import org.netbeans.api.project.Project;
30
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
31
import org.netbeans.modules.java.freeform.LookupProviderImpl;
32
import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration;
33
import org.netbeans.spi.project.AuxiliaryConfiguration;
34
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
35
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
36
import org.openide.ErrorManager;
37
import org.openide.util.Lookup;
38
import org.openide.util.NbBundle;
39
40
/**
41
 *
42
 * @author mkleint
43
 */
44
public class ClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
45
    
46
    /** Creates a new instance of ClasspathCategoryProvider */
47
    public ClasspathCategoryProvider() {
48
    }
49
    
50
    public Category createCategory(Lookup context) {
51
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
52
        assert aux != null;
53
        if (LookupProviderImpl.isMyProject(aux)) {
54
            Category cat = ProjectCustomizer.Category.create("classpath", //NOI18N
55
                    NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null);
56
            return cat;
57
        }
58
        return null;
59
    }
60
61
    public JComponent createComponent(Category category, Lookup context) {
62
        Project project = (Project)context.lookup(Project.class);
63
        ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class);
64
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
65
        assert aux != null;
66
        assert acc != null;
67
        assert project != null;
68
        
69
        final JdkConfiguration jdkConf = new JdkConfiguration(project, acc.getHelper(), acc.getEvaluator());
70
        
71
        final ClasspathPanel panel = new ClasspathPanel(jdkConf);
72
        final JavaPlatform initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem();
73
        ProjectModel pm = context.lookup(ProjectModel.class);
74
        assert pm != null;
75
        panel.setModel(pm);
76
        pm.addChangeListener(new ChangeListener() {
77
            public void stateChanged(ChangeEvent arg0) {
78
                panel.updateControls();
79
            }
80
        });
81
        category.setOkButtonListener(new ActionListener() {
82
            public void actionPerformed(ActionEvent arg0) {
83
                JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem();
84
                if (p != initialPlatform) {
85
                    try {
86
                        jdkConf.setSelectedPlatform(p);
87
                    } catch (IOException x) {
88
                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x);
89
                    }
90
                }
91
            }
92
        });
93
        return panel;
94
        
95
    }
96
97
}
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form (+3 lines)
Lines 287-292 Link Here
287
          </Constraints>
287
          </Constraints>
288
        </Component>
288
        </Component>
289
        <Component class="javax.swing.JComboBox" name="javaPlatform">
289
        <Component class="javax.swing.JComboBox" name="javaPlatform">
290
          <AuxValues>
291
            <AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
292
          </AuxValues>
290
          <Constraints>
293
          <Constraints>
291
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
294
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
292
              <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="6" anchor="17" weightX="1.0" weightY="0.0"/>
295
              <GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="6" anchor="17" weightX="1.0" weightY="0.0"/>
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java (-59 / +3 lines)
Lines 22-28 Link Here
22
import java.awt.Component;
22
import java.awt.Component;
23
import java.awt.event.ItemEvent;
23
import java.awt.event.ItemEvent;
24
import java.io.File;
24
import java.io.File;
25
import java.io.IOException;
26
import java.net.MalformedURLException;
25
import java.net.MalformedURLException;
27
import java.text.Collator;
26
import java.text.Collator;
28
import java.util.ArrayList;
27
import java.util.ArrayList;
Lines 36-56 Link Here
36
import javax.swing.DefaultComboBoxModel;
35
import javax.swing.DefaultComboBoxModel;
37
import javax.swing.DefaultListCellRenderer;
36
import javax.swing.DefaultListCellRenderer;
38
import javax.swing.DefaultListModel;
37
import javax.swing.DefaultListModel;
39
import javax.swing.JComponent;
40
import javax.swing.JFileChooser;
38
import javax.swing.JFileChooser;
41
import javax.swing.JList;
39
import javax.swing.JList;
42
import javax.swing.event.ChangeEvent;
43
import javax.swing.event.ChangeListener;
44
import javax.swing.filechooser.FileFilter;
40
import javax.swing.filechooser.FileFilter;
45
import org.netbeans.api.java.platform.JavaPlatform;
41
import org.netbeans.api.java.platform.JavaPlatform;
46
import org.netbeans.api.java.platform.JavaPlatformManager;
42
import org.netbeans.api.java.platform.JavaPlatformManager;
47
import org.netbeans.api.java.platform.PlatformsCustomizer;
43
import org.netbeans.api.java.platform.PlatformsCustomizer;
48
import org.netbeans.api.project.Project;
49
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
50
import org.netbeans.modules.ant.freeform.spi.support.Util;
44
import org.netbeans.modules.ant.freeform.spi.support.Util;
51
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
45
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
52
import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration;
46
import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
54
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
47
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
55
import org.netbeans.spi.project.support.ant.PropertyUtils;
48
import org.netbeans.spi.project.support.ant.PropertyUtils;
56
import org.openide.ErrorManager;
49
import org.openide.ErrorManager;
Lines 83-89 Link Here
83
    /**
76
    /**
84
     * Create new panel in project properties mode.
77
     * Create new panel in project properties mode.
85
     */
78
     */
86
    private ClasspathPanel(JdkConfiguration jdkConf) {
79
    ClasspathPanel(JdkConfiguration jdkConf) {
87
        this.jdkConf = jdkConf;
80
        this.jdkConf = jdkConf;
88
        basicInit();
81
        basicInit();
89
        jTextArea1.setText(NbBundle.getMessage(ClasspathPanel.class, "LBL_ClasspathPanel_Explanation"));
82
        jTextArea1.setText(NbBundle.getMessage(ClasspathPanel.class, "LBL_ClasspathPanel_Explanation"));
Lines 130-136 Link Here
130
        return new HelpCtx( ClasspathPanel.class );
123
        return new HelpCtx( ClasspathPanel.class );
131
    }
124
    }
132
    
125
    
133
    private void updateControls() {
126
    void updateControls() {
134
        sourceFolder.removeAllItems();
127
        sourceFolder.removeAllItems();
135
        compUnitsKeys = model.createCompilationUnitKeys();
128
        compUnitsKeys = model.createCompilationUnitKeys();
136
        isSeparateClasspath = !ProjectModel.isSingleCompilationUnit(compUnitsKeys);
129
        isSeparateClasspath = !ProjectModel.isSingleCompilationUnit(compUnitsKeys);
Lines 666-720 Link Here
666
        }
659
        }
667
    }
660
    }
668
661
669
    public static class Panel implements ProjectPropertiesPanel, ChangeListener {
670
        
671
        private ClasspathPanel panel;
672
        private ProjectModel model;
673
        private final JdkConfiguration jdkConf;
674
        private JavaPlatform initialPlatform;
675
        
676
        public Panel(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, ProjectModel model) {
677
            jdkConf = new JdkConfiguration(project, helper, evaluator);
678
            this.model = model;
679
        }
680
    
681
        public void storeValues() {
682
            if (panel != null) {
683
                JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem();
684
                if (p != initialPlatform) {
685
                    try {
686
                        jdkConf.setSelectedPlatform(p);
687
                    } catch (IOException x) {
688
                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x);
689
                    }
690
                }
691
            }
692
        }
693
694
        public String getDisplayName() {
695
            return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath");
696
        }
697
698
        public JComponent getComponent() {
699
            if (panel == null) {
700
                panel = new ClasspathPanel(jdkConf);
701
                panel.setModel(model);
702
                model.addChangeListener(this);
703
                initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem();
704
            }
705
            return panel;
706
        }
707
        
708
        public void stateChanged(ChangeEvent e) {
709
            panel.updateControls();
710
        }
711
712
        public int getPreferredPosition() {
713
            return 200;
714
        }
715
        
716
    }
717
    
718
    public void setModel(ProjectModel model) {
662
    public void setModel(ProjectModel model) {
719
        this.model = model;
663
        this.model = model;
720
        updateControls();
664
        updateControls();
Lines 728-734 Link Here
728
    private javax.swing.JPanel jPanel1;
672
    private javax.swing.JPanel jPanel1;
729
    private javax.swing.JScrollPane jScrollPane1;
673
    private javax.swing.JScrollPane jScrollPane1;
730
    private javax.swing.JTextArea jTextArea1;
674
    private javax.swing.JTextArea jTextArea1;
731
    private javax.swing.JComboBox javaPlatform;
675
    javax.swing.JComboBox javaPlatform;
732
    private javax.swing.JButton javaPlatformButton;
676
    private javax.swing.JButton javaPlatformButton;
733
    private javax.swing.JTextArea javaPlatformIntro;
677
    private javax.swing.JTextArea javaPlatformIntro;
734
    private javax.swing.JLabel javaPlatformLabel;
678
    private javax.swing.JLabel javaPlatformLabel;
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputCategoryProvider.java (+59 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.java.freeform.ui;
21
22
import javax.swing.JComponent;
23
import org.netbeans.modules.java.freeform.LookupProviderImpl;
24
import org.netbeans.spi.project.AuxiliaryConfiguration;
25
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
26
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
27
import org.openide.util.Lookup;
28
import org.openide.util.NbBundle;
29
30
/**
31
 *
32
 * @author mkleint
33
 */
34
public class OutputCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
35
    
36
    /** Creates a new instance of OutputCategoryProvider */
37
    public OutputCategoryProvider() {
38
    }
39
    
40
    public Category createCategory(Lookup context) {
41
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
42
        assert aux != null;
43
        if (LookupProviderImpl.isMyProject(aux)) {
44
            Category cat = ProjectCustomizer.Category.create("Output", //NOI18N
45
                    NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Output"), null, null);
46
            return cat;
47
        }
48
        return null;
49
    }
50
51
    public JComponent createComponent(Category category, Lookup context) {
52
        ProjectModel pm = context.lookup(ProjectModel.class);
53
        assert pm != null;
54
        OutputPanel panel = new OutputPanel();
55
        panel.setModel(pm);
56
        return panel;
57
    }
58
59
}
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/OutputPanel.java (-41 / +6 lines)
Lines 19-39 Link Here
19
19
20
package org.netbeans.modules.java.freeform.ui;
20
package org.netbeans.modules.java.freeform.ui;
21
21
22
import java.awt.event.FocusAdapter;
23
import java.awt.event.FocusEvent;
24
import java.awt.event.ItemEvent;
22
import java.awt.event.ItemEvent;
25
import java.io.File;
23
import java.io.File;
26
import java.util.ArrayList;
24
import java.util.ArrayList;
27
import java.util.Iterator;
28
import java.util.List;
25
import java.util.List;
29
import javax.swing.DefaultListModel;
26
import javax.swing.DefaultListModel;
30
import javax.swing.JComponent;
31
import javax.swing.JFileChooser;
27
import javax.swing.JFileChooser;
32
import javax.swing.ListSelectionModel;
28
import javax.swing.ListSelectionModel;
33
import javax.swing.event.ChangeEvent;
29
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeListener;
30
import javax.swing.event.ChangeListener;
35
import javax.swing.event.DocumentEvent;
31
import javax.swing.event.DocumentEvent;
36
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
37
import org.netbeans.modules.ant.freeform.spi.support.Util;
32
import org.netbeans.modules.ant.freeform.spi.support.Util;
38
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
33
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
39
import org.openide.filesystems.FileUtil;
34
import org.openide.filesystems.FileUtil;
Lines 509-552 Link Here
509
        }
504
        }
510
    }
505
    }
511
    
506
    
512
    public static class Panel implements ProjectPropertiesPanel, ChangeListener {
507
    void setModel(ProjectModel model) {
513
        
514
        private OutputPanel panel;
515
        private ProjectModel model;
516
        
517
        public Panel(ProjectModel model) {
518
            this.model = model;
519
        }
520
    
521
        public void storeValues() {
522
        }    
523
524
        public String getDisplayName() {
525
        return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Output");
526
        }
527
528
        public JComponent getComponent() {
529
            if (panel == null) {
530
                panel = new OutputPanel();
531
                panel.setModel(model);
532
                model.addChangeListener(this);
533
            }
534
            return panel;
535
        }
536
537
        public void stateChanged(ChangeEvent e) {
538
            panel.updateControls();
539
        }
540
541
        public int getPreferredPosition() {
542
            return 300;
543
        }
544
        
545
    }
546
    
547
    private void setModel(ProjectModel model) {
548
        this.model = model;
508
        this.model = model;
549
        updateControls();
509
        updateControls();
510
        model.addChangeListener(new ChangeListener() {
511
            public void stateChanged(ChangeEvent arg0) {
512
                updateControls();
513
            }
514
        });
550
    }
515
    }
551
516
552
    
517
    
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersCategoryProvider.java (+83 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.java.freeform.ui;
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24
import javax.swing.JComponent;
25
import org.netbeans.api.project.Project;
26
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
27
import org.netbeans.modules.ant.freeform.spi.support.Util;
28
import org.netbeans.modules.java.freeform.LookupProviderImpl;
29
import org.netbeans.spi.project.AuxiliaryConfiguration;
30
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
31
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
32
import org.openide.filesystems.FileUtil;
33
import org.openide.util.Lookup;
34
import org.openide.util.NbBundle;
35
import org.openide.util.lookup.InstanceContent;
36
37
/**
38
 *
39
 * @author mkleint
40
 */
41
public class SourceFoldersCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
42
    
43
    /** Creates a new instance of SouceFoldersCustomizerProvider */
44
    public SourceFoldersCategoryProvider() {
45
    }
46
    
47
    public Category createCategory(Lookup context) {
48
        AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class);
49
        final ProjectAccessor acc = context.lookup(ProjectAccessor.class);
50
        Project project = context.lookup(Project.class);
51
        assert aux != null;
52
        assert acc != null;
53
        assert project != null;
54
        if (LookupProviderImpl.isMyProject(aux)) {
55
            Category cat = ProjectCustomizer.Category.create("SourceFolders", //NOI18N
56
                    NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Sources"), null, null);
57
            final ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(acc.getHelper(), acc.getEvaluator()), 
58
                    FileUtil.toFile(project.getProjectDirectory()), acc.getEvaluator(), acc.getHelper());
59
            InstanceContent ic = context.lookup(InstanceContent.class);
60
            assert ic != null;
61
            ic.add(pm);
62
            cat.setOkButtonListener(new ActionListener() {
63
                public void actionPerformed(ActionEvent arg0) {
64
                   // store changes always because model could be modified in ClasspathPanel or OutputPanel
65
                    ProjectModel.saveProject(acc.getHelper(), pm);                
66
                }
67
            });
68
            return cat;
69
        }
70
        return null;
71
    }
72
73
    public JComponent createComponent(Category category, Lookup context) {
74
        ProjectModel pm = context.lookup(ProjectModel.class);
75
        ProjectAccessor acc = context.lookup(ProjectAccessor.class);
76
        assert pm != null;
77
        SourceFoldersPanel panel = new SourceFoldersPanel(false);
78
        panel.setModel(pm, acc.getHelper());    
79
        return panel;
80
        
81
    }
82
83
}
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java (-36 lines)
Lines 48-54 Link Here
48
import org.netbeans.api.project.ProjectUtils;
48
import org.netbeans.api.project.ProjectUtils;
49
import org.netbeans.api.queries.CollocationQuery;
49
import org.netbeans.api.queries.CollocationQuery;
50
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
50
import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
51
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
52
import org.netbeans.modules.ant.freeform.spi.support.Util;
51
import org.netbeans.modules.ant.freeform.spi.support.Util;
53
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
52
import org.netbeans.modules.java.freeform.JavaProjectGenerator;
54
import org.netbeans.modules.java.freeform.JavaProjectNature;
53
import org.netbeans.modules.java.freeform.JavaProjectNature;
Lines 757-797 Link Here
757
    
756
    
758
    public boolean hasSomeSourceFolder() {
757
    public boolean hasSomeSourceFolder() {
759
        return model.getSourceFoldersCount() > 0;
758
        return model.getSourceFoldersCount() > 0;
760
    }
761
    
762
    public static class Panel implements ProjectPropertiesPanel {
763
        
764
        private SourceFoldersPanel panel;
765
        private ProjectModel model;
766
        private AntProjectHelper projectHelper;
767
        
768
        public Panel(ProjectModel model, AntProjectHelper projectHelper) {
769
            this.model = model;
770
            this.projectHelper = projectHelper;
771
        }
772
    
773
        /* ProjectCustomizer.Panel save */
774
        public void storeValues() {
775
            // store changes always because model could be modified in ClasspathPanel or OutputPanel
776
            ProjectModel.saveProject(projectHelper, model);
777
        }    
778
779
        public String getDisplayName() {
780
            return NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Sources");
781
        }
782
783
        public JComponent getComponent() {
784
            if (panel == null) {
785
                panel = new SourceFoldersPanel(false);
786
                panel.setModel(model, projectHelper);
787
            }
788
            return panel;
789
        }
790
791
        public int getPreferredPosition() {
792
            return 100;
793
        }
794
        
795
    }
759
    }
796
    
760
    
797
    // Variables declaration - do not modify//GEN-BEGIN:variables
761
    // Variables declaration - do not modify//GEN-BEGIN:variables
(-)web/freeform/nbproject/project.xml (-66 / +66 lines)
Lines 24-52 Link Here
24
            <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
24
            <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
25
            <module-dependencies>
25
            <module-dependencies>
26
                <dependency>
26
                <dependency>
27
                    <code-name-base>org.netbeans.modules.ant.freeform</code-name-base>
27
                    <code-name-base>org.netbeans.api.java</code-name-base>
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>1</release-version>
31
                        <release-version>1</release-version>
32
                        <specification-version>1.8</specification-version>
32
                        <specification-version>1.5</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.api.java</code-name-base>
36
                    <code-name-base>org.netbeans.api.web.webmodule</code-name-base>
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency/>
40
                        <release-version>1</release-version>
41
                        <specification-version>1.5</specification-version>
42
                    </run-dependency>
43
                </dependency>
40
                </dependency>
44
                <dependency>
41
                <dependency>
45
                    <code-name-base>org.netbeans.modules.java.project</code-name-base>
42
                    <code-name-base>org.netbeans.modules.ant.freeform</code-name-base>
46
                    <build-prerequisite/>
43
                    <build-prerequisite/>
47
                    <compile-dependency/>
44
                    <compile-dependency/>
48
                    <run-dependency>
45
                    <run-dependency>
49
                        <release-version>1</release-version>
46
                        <release-version>1</release-version>
47
                        <specification-version>1.14</specification-version>
50
                    </run-dependency>
48
                    </run-dependency>
51
                </dependency>
49
                </dependency>
52
                <dependency>
50
                <dependency>
Lines 59-65 Link Here
59
                    </run-dependency>
57
                    </run-dependency>
60
                </dependency>
58
                </dependency>
61
                <dependency>
59
                <dependency>
62
                    <code-name-base>org.netbeans.modules.project.ant</code-name-base>
60
                    <code-name-base>org.netbeans.modules.java.project</code-name-base>
63
                    <build-prerequisite/>
61
                    <build-prerequisite/>
64
                    <compile-dependency/>
62
                    <compile-dependency/>
65
                    <run-dependency>
63
                    <run-dependency>
Lines 67-73 Link Here
67
                    </run-dependency>
65
                    </run-dependency>
68
                </dependency>
66
                </dependency>
69
                <dependency>
67
                <dependency>
70
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
68
                    <code-name-base>org.netbeans.modules.project.ant</code-name-base>
71
                    <build-prerequisite/>
69
                    <build-prerequisite/>
72
                    <compile-dependency/>
70
                    <compile-dependency/>
73
                    <run-dependency>
71
                    <run-dependency>
Lines 83-105 Link Here
83
                    </run-dependency>
81
                    </run-dependency>
84
                </dependency>
82
                </dependency>
85
                <dependency>
83
                <dependency>
86
                    <code-name-base>org.openide.filesystems</code-name-base>
84
                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
87
                    <build-prerequisite/>
85
                    <build-prerequisite/>
88
                    <compile-dependency/>
86
                    <compile-dependency/>
89
                    <run-dependency>
87
                    <run-dependency>
90
                        <specification-version>6.2</specification-version>
88
                        <release-version>1</release-version>
91
                    </run-dependency>
89
                    </run-dependency>
92
                </dependency>
90
                </dependency>
93
                <dependency>
91
                <dependency>
94
                    <code-name-base>org.openide.util</code-name-base>
92
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
95
                    <build-prerequisite/>
93
                    <build-prerequisite/>
96
                    <compile-dependency/>
94
                    <compile-dependency/>
97
                    <run-dependency>
95
                    <run-dependency>
98
                        <specification-version>6.2</specification-version>
96
                        <release-version>1</release-version>
99
                    </run-dependency>
97
                    </run-dependency>
100
                </dependency>
98
                </dependency>
101
                <dependency>
99
                <dependency>
102
                    <code-name-base>org.openide.nodes</code-name-base>
100
                    <code-name-base>org.openide.awt</code-name-base>
103
                    <build-prerequisite/>
101
                    <build-prerequisite/>
104
                    <compile-dependency/>
102
                    <compile-dependency/>
105
                    <run-dependency>
103
                    <run-dependency>
Lines 107-113 Link Here
107
                    </run-dependency>
105
                    </run-dependency>
108
                </dependency>
106
                </dependency>
109
                <dependency>
107
                <dependency>
110
                    <code-name-base>org.openide.awt</code-name-base>
108
                    <code-name-base>org.openide.dialogs</code-name-base>
111
                    <build-prerequisite/>
109
                    <build-prerequisite/>
112
                    <compile-dependency/>
110
                    <compile-dependency/>
113
                    <run-dependency>
111
                    <run-dependency>
Lines 115-121 Link Here
115
                    </run-dependency>
113
                    </run-dependency>
116
                </dependency>
114
                </dependency>
117
                <dependency>
115
                <dependency>
118
                    <code-name-base>org.openide.dialogs</code-name-base>
116
                    <code-name-base>org.openide.filesystems</code-name-base>
119
                    <build-prerequisite/>
117
                    <build-prerequisite/>
120
                    <compile-dependency/>
118
                    <compile-dependency/>
121
                    <run-dependency>
119
                    <run-dependency>
Lines 123-195 Link Here
123
                    </run-dependency>
121
                    </run-dependency>
124
                </dependency>
122
                </dependency>
125
                <dependency>
123
                <dependency>
126
                    <code-name-base>org.openide.text</code-name-base>
124
                    <code-name-base>org.openide.loaders</code-name-base>
127
                    <build-prerequisite/>
125
                    <build-prerequisite/>
128
                    <compile-dependency/>
126
                    <compile-dependency/>
129
                    <run-dependency>
127
                    <run-dependency/>
130
                        <specification-version>6.2</specification-version>
131
                    </run-dependency>
132
                </dependency>
128
                </dependency>
133
                <dependency>
129
                <dependency>
134
                    <code-name-base>org.netbeans.api.web.webmodule</code-name-base>
130
                    <code-name-base>org.openide.nodes</code-name-base>
135
                    <build-prerequisite/>
131
                    <build-prerequisite/>
136
                    <compile-dependency/>
132
                    <compile-dependency/>
137
                    <run-dependency/>
133
                    <run-dependency>
134
                        <specification-version>6.2</specification-version>
135
                    </run-dependency>
138
                </dependency>
136
                </dependency>
139
                <dependency>
137
                <dependency>
140
                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
138
                    <code-name-base>org.openide.text</code-name-base>
141
                    <build-prerequisite/>
139
                    <build-prerequisite/>
142
                    <compile-dependency/>
140
                    <compile-dependency/>
143
                    <run-dependency>
141
                    <run-dependency>
144
                        <release-version>1</release-version>
142
                        <specification-version>6.2</specification-version>
145
                    </run-dependency>
143
                    </run-dependency>
146
                </dependency>
144
                </dependency>
147
                <dependency>
145
                <dependency>
148
                    <code-name-base>org.openide.loaders</code-name-base>
146
                    <code-name-base>org.openide.util</code-name-base>
149
                    <build-prerequisite/>
147
                    <build-prerequisite/>
150
                    <compile-dependency/>
148
                    <compile-dependency/>
151
                    <run-dependency/>
149
                    <run-dependency>
150
                        <specification-version>6.2</specification-version>
151
                    </run-dependency>
152
                </dependency>
152
                </dependency>
153
            </module-dependencies>
153
            </module-dependencies>
154
          <test-dependencies>
154
            <test-dependencies>
155
              <test-type>
155
                <test-type>
156
                  <name>unit</name>
156
                    <name>unit</name>
157
                  <test-dependency>
157
                    <test-dependency>
158
                      <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
158
                        <code-name-base>org.netbeans.modules.web.freeform</code-name-base>
159
                      <recursive/>
159
                        <recursive/>
160
                      <compile-dependency/>
160
                        <compile-dependency/>
161
                  </test-dependency>
161
                    </test-dependency>
162
                  <test-dependency>
162
                    <test-dependency>
163
                      <code-name-base>org.openidex.util</code-name-base>
163
                        <code-name-base>org.openidex.util</code-name-base>
164
                  </test-dependency>
164
                    </test-dependency>
165
                  <test-dependency>
165
                    <test-dependency>
166
                      <code-name-base>org.apache.tools.ant.module</code-name-base>
166
                        <code-name-base>org.apache.tools.ant.module</code-name-base>
167
                  </test-dependency>
167
                    </test-dependency>
168
                  <test-dependency>
168
                    <test-dependency>
169
                      <code-name-base>org.openide.io</code-name-base>
169
                        <code-name-base>org.openide.io</code-name-base>
170
                  </test-dependency>
170
                    </test-dependency>
171
                  <test-dependency>
171
                    <test-dependency>
172
                      <code-name-base>org.openide.compat</code-name-base>
172
                        <code-name-base>org.openide.compat</code-name-base>
173
                  </test-dependency>
173
                    </test-dependency>
174
                  <test-dependency>
174
                    <test-dependency>
175
                      <code-name-base>org.netbeans.core</code-name-base>
175
                        <code-name-base>org.netbeans.core</code-name-base>
176
                  </test-dependency>
176
                    </test-dependency>
177
                  <test-dependency>
177
                    <test-dependency>
178
                      <code-name-base>org.netbeans.swing.plaf</code-name-base>
178
                        <code-name-base>org.netbeans.swing.plaf</code-name-base>
179
                  </test-dependency>
179
                    </test-dependency>
180
                  <test-dependency>
180
                    <test-dependency>
181
                      <code-name-base>org.netbeans.modules.projectui</code-name-base>
181
                        <code-name-base>org.netbeans.modules.projectui</code-name-base>
182
                  </test-dependency>
182
                    </test-dependency>
183
                  <test-dependency>
183
                    <test-dependency>
184
                      <code-name-base>org.netbeans.modules.masterfs</code-name-base>
184
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
185
                  </test-dependency>
185
                    </test-dependency>
186
                  <test-dependency>
186
                    <test-dependency>
187
                      <code-name-base>org.openide.modules</code-name-base>
187
                        <code-name-base>org.openide.modules</code-name-base>
188
                  </test-dependency>
188
                    </test-dependency>
189
              </test-type>
189
                </test-type>
190
              <test-type>
190
                <test-type>
191
                  <name>qa-functional</name>
191
                    <name>qa-functional</name>
192
              </test-type>
192
                </test-type>
193
            </test-dependencies>
193
            </test-dependencies>
194
            <public-packages/>
194
            <public-packages/>
195
        </data>
195
        </data>
(-)web/freeform/src/org/netbeans/modules/web/freeform/LookupProviderImpl.java (+281 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
21
package org.netbeans.modules.web.freeform;
22
23
import java.beans.PropertyChangeEvent;
24
import java.beans.PropertyChangeListener;
25
import java.beans.PropertyChangeSupport;
26
import java.io.File;
27
import java.util.ArrayList;
28
import java.util.Collections;
29
import java.util.Iterator;
30
import java.util.List;
31
import org.netbeans.api.java.classpath.ClassPath;
32
import org.netbeans.api.java.classpath.GlobalPathRegistry;
33
import org.netbeans.api.project.Project;
34
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
35
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
36
import org.netbeans.modules.ant.freeform.spi.support.Util;
37
import org.netbeans.spi.java.classpath.ClassPathImplementation;
38
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
39
import org.netbeans.spi.project.AuxiliaryConfiguration;
40
import org.netbeans.spi.project.LookupProvider;
41
import org.netbeans.spi.project.support.ant.AntProjectEvent;
42
import org.netbeans.spi.project.support.ant.AntProjectHelper;
43
import org.netbeans.spi.project.support.ant.AntProjectListener;
44
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
45
import org.netbeans.spi.project.ui.PrivilegedTemplates;
46
import org.netbeans.spi.project.ui.ProjectOpenedHook;
47
import org.netbeans.spi.project.ui.RecommendedTemplates;
48
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Lookup;
51
import org.openide.util.lookup.Lookups;
52
import org.openide.util.lookup.ProxyLookup;
53
import org.w3c.dom.Element;
54
55
/**
56
 *
57
 * @author mkleint
58
 */
59
public class LookupProviderImpl implements LookupProvider {
60
61
    private static final String HELP_ID_FRAGMENT = "web"; // NOI18N
62
    
63
    /** Creates a new instance of LookupProviderImpl */
64
    public LookupProviderImpl() {
65
    }
66
    
67
    public Lookup createAdditionalLookup(Lookup baseContext) {
68
        Project prj = (Project)baseContext.lookup(Project.class);
69
        ProjectAccessor acc = (ProjectAccessor)baseContext.lookup(ProjectAccessor.class);
70
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)baseContext.lookup(AuxiliaryConfiguration.class);
71
        assert aux != null;
72
        assert prj != null;
73
        assert acc != null;
74
        return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux);
75
    }
76
77
   private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
78
        WebClasspath webcp = new WebClasspath(projectHelper, projectEvaluator, aux, project);
79
        return Lookups.fixed(new Object[] {
80
            new ProjectOpenedHookImpl(webcp),       // register webroots as source classpath
81
            new PrivilegedTemplatesImpl(),          // List of templates in New action popup
82
            new WebModules(project, projectHelper, projectEvaluator), // WebModuleProvider, ClassPathProvider
83
            new WebFreeFormActionProvider(project, projectHelper, aux),   //ActionProvider
84
            new HelpIDFragmentProviderImpl(),
85
        });
86
    }
87
   
88
    public static boolean isMyProject(AuxiliaryConfiguration aux) {
89
        return aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true) != null; // NOI18N
90
    }   
91
    
92
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
93
        public String getHelpIDFragment() {
94
            return HELP_ID_FRAGMENT;
95
        }
96
    }
97
    
98
    private static class ProjectOpenedHookImpl extends ProjectOpenedHook {
99
        private final WebClasspath webcp;
100
        public ProjectOpenedHookImpl(WebClasspath wcp) {
101
            this.webcp = wcp;
102
        }
103
        protected void projectOpened() {
104
            webcp.prjOpened();
105
        }
106
        protected void projectClosed() {
107
            webcp.prjClosed();
108
        }
109
    }
110
    
111
    public static final class WebClasspath implements AntProjectListener, PropertyChangeListener {
112
        
113
        private ClassPath registeredCP[] = new ClassPath[0];
114
        private List/*<FileObject>*/ registeredRoots = Collections.EMPTY_LIST;
115
        
116
        private PropertyEvaluator evaluator;
117
        private AuxiliaryConfiguration aux;
118
        private Project project;
119
        
120
        private PropertyChangeSupport pcs;
121
        
122
        private boolean prjClosed = false;
123
        
124
        public WebClasspath(AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux, Project proj) {
125
            this.evaluator = evaluator;
126
            this.aux = aux;
127
            this.project = proj;
128
            helper.addAntProjectListener(this);
129
            evaluator.addPropertyChangeListener(this);
130
            pcs = new PropertyChangeSupport(this);
131
        }
132
        
133
        public void prjOpened() {
134
            registeredRoots = getWebRoots(aux, project, evaluator);
135
            FileObject fos[] = new FileObject[registeredRoots.size()];
136
            ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) registeredRoots.toArray(fos));
137
            registeredCP = new ClassPath[] { cp };
138
            GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP);
139
            prjClosed = false;
140
        }
141
        
142
        public void prjClosed() {
143
            if (!registeredRoots.isEmpty()) {
144
                GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP);
145
            }
146
            registeredRoots = Collections.EMPTY_LIST;
147
            prjClosed = true;
148
        }
149
        
150
        public void configurationXmlChanged(AntProjectEvent ev) {
151
            updateClasspath();
152
        }
153
        
154
        public void propertiesChanged(AntProjectEvent ev) {
155
            // ignore
156
        }
157
        
158
        public void propertyChange(PropertyChangeEvent ev) {
159
            updateClasspath();
160
        }
161
        
162
        public void addPropertyChangeListener(PropertyChangeListener listener) {
163
            pcs.addPropertyChangeListener(listener);
164
        }
165
        
166
        public void removePropertyChangeListener(PropertyChangeListener listener) {
167
            pcs.removePropertyChangeListener(listener);
168
        }
169
        
170
        private synchronized void updateClasspath() {
171
            if (!prjClosed) {
172
                List newRoots = getWebRoots(aux, project, evaluator);
173
                if (!newRoots.equals(registeredRoots)) {
174
                    FileObject fos[] = new FileObject[newRoots.size()];
175
                    ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) newRoots.toArray(fos));
176
                    GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP);
177
                    registeredCP = new ClassPath[] { cp };
178
                    registeredRoots = newRoots;
179
                    GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP);
180
                    pcs.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, null, null);
181
                }
182
            }
183
        }
184
        
185
        private List/*<FileObject>*/ getWebRoots(AuxiliaryConfiguration aux, Project proj, PropertyEvaluator evaluator) {
186
            Element web = aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true); // NOI18N
187
            if (web == null) {
188
                return null;
189
            }
190
            List webModules = Util.findSubElements(web);
191
            Iterator it = webModules.iterator();
192
            List/*<FileObject>*/ roots = new ArrayList();
193
            while (it.hasNext()) {
194
                Element webModulesEl = (Element) it.next();
195
                assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N
196
                roots.add(FileUtil.toFileObject(getFile(webModulesEl, "doc-root", proj, evaluator))); // NOI18N
197
            }
198
            return roots;
199
        }
200
        
201
        private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) {
202
            Element el = Util.findElement(parent, fileElName, WebProjectNature.NS_WEB);
203
            return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), Util.findText(el));
204
        }
205
        
206
    }
207
    
208
    private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
209
210
        private AntProjectHelper helper;
211
        private PropertyEvaluator evaluator;
212
        private Project project;
213
        private AuxiliaryConfiguration aux;
214
        private boolean isMyProject;
215
        
216
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
217
            super(new Lookup[0]);
218
            this.project = project;
219
            this.helper = helper;
220
            this.evaluator = evaluator;
221
            this.aux = aux;
222
            this.isMyProject = isMyProject(aux);
223
            updateLookup();
224
            helper.addAntProjectListener(this);
225
        }
226
        
227
        private void updateLookup() {
228
            Lookup l = Lookup.EMPTY;
229
            if (isMyProject) {
230
                l = initLookup(project, helper, evaluator, aux);
231
            }
232
            setLookups(new Lookup[]{l});
233
        }
234
        
235
        public void configurationXmlChanged(AntProjectEvent ev) {
236
            if (isMyProject(aux) != isMyProject) {
237
                isMyProject = !isMyProject;
238
                updateLookup();
239
            }
240
        }
241
        
242
        public void propertiesChanged(AntProjectEvent ev) {
243
            // ignore
244
        }
245
        
246
    }
247
    
248
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
249
        
250
        private static final String[] PRIVILEGED_NAMES = new String[] {
251
            "Templates/JSP_Servlet/JSP.jsp",
252
            "Templates/JSP_Servlet/Html.html",
253
            "Templates/JSP_Servlet/Servlet.java",
254
            "Templates/Classes/Class.java",
255
        };
256
        
257
        private static final String[] RECOMENDED_TYPES = new String[] {         
258
            "java-classes",         // NOI18N
259
            "java-main-class",      // NOI18N
260
            "java-beans",           // NOI18N
261
            "oasis-XML-catalogs",   // NOI18N
262
            "XML",                  // NOI18N
263
            "wsdl",                 // NOI18N
264
            "ant-script",           // NOI18N
265
            "ant-task",             // NOI18N
266
            "servlet-types",        // NOI18N
267
            "web-types",            // NOI18N
268
            "j2ee-types",           // NOI18N
269
            "junit",                // NOI18N
270
            "simple-files"          // NOI18N
271
        };
272
        
273
        public String[] getPrivilegedTemplates() {
274
            return PRIVILEGED_NAMES;
275
        }
276
277
        public String[] getRecommendedTypes() {
278
            return RECOMENDED_TYPES;
279
        }
280
    }    
281
}
(-)web/freeform/src/org/netbeans/modules/web/freeform/WebProjectNature.java (-256 / +4 lines)
Lines 18-65 Link Here
18
 */
18
 */
19
19
20
package org.netbeans.modules.web.freeform;
20
package org.netbeans.modules.web.freeform;
21
import java.beans.PropertyChangeEvent;
22
import java.beans.PropertyChangeListener;
23
import java.beans.PropertyChangeSupport;
24
import java.io.File;
25
import java.lang.ref.WeakReference;
26
import java.util.ArrayList;
21
import java.util.ArrayList;
27
import java.util.Arrays;
22
import java.util.Arrays;
28
import java.util.Collections;
23
import java.util.Collections;
29
import java.util.HashSet;
30
import java.util.Iterator;
31
import java.util.List;
24
import java.util.List;
32
import java.util.Set;
25
import java.util.Set;
33
import java.util.WeakHashMap;
34
import org.netbeans.api.java.classpath.ClassPath;
35
import org.netbeans.api.java.classpath.GlobalPathRegistry;
36
import org.netbeans.api.project.Project;
26
import org.netbeans.api.project.Project;
37
import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider;
38
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
27
import org.netbeans.modules.ant.freeform.spi.ProjectNature;
39
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
40
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
28
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
41
import org.netbeans.modules.ant.freeform.spi.support.Util;
42
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
29
import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
43
import org.netbeans.modules.web.freeform.ui.WebClasspathPanel;
44
import org.netbeans.modules.web.freeform.ui.WebLocationsPanel;
45
import org.netbeans.spi.java.classpath.ClassPathImplementation;
46
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
47
import org.netbeans.spi.project.AuxiliaryConfiguration;
30
import org.netbeans.spi.project.AuxiliaryConfiguration;
48
import org.netbeans.spi.project.support.ant.AntProjectEvent;
49
import org.netbeans.spi.project.support.ant.AntProjectHelper;
31
import org.netbeans.spi.project.support.ant.AntProjectHelper;
50
import org.netbeans.spi.project.support.ant.AntProjectListener;
51
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
32
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
52
import org.netbeans.spi.project.ui.PrivilegedTemplates;
53
import org.netbeans.spi.project.ui.ProjectOpenedHook;
54
import org.netbeans.spi.project.ui.RecommendedTemplates;
55
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.nodes.Node;
34
import org.openide.nodes.Node;
58
import org.openide.util.Lookup;
59
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
60
import org.openide.util.lookup.Lookups;
61
import org.openide.util.lookup.ProxyLookup;
62
import org.w3c.dom.Element;
63
36
64
/**
37
/**
65
 * @author David Konecny
38
 * @author David Konecny
Lines 69-104 Link Here
69
    public static final String NS_WEB = "http://www.netbeans.org/ns/freeform-project-web/1"; // NOI18N
42
    public static final String NS_WEB = "http://www.netbeans.org/ns/freeform-project-web/1"; // NOI18N
70
    private static final String SCHEMA = "nbres:/org/netbeans/modules/web/freeform/resources/freeform-project-web.xsd"; // NOI18N
43
    private static final String SCHEMA = "nbres:/org/netbeans/modules/web/freeform/resources/freeform-project-web.xsd"; // NOI18N
71
    
44
    
72
    private static final String HELP_ID_FRAGMENT = "web"; // NOI18N
45
  
73
    
74
    private static final WeakHashMap/*<Project,WeakReference<Lookup>>*/ lookupCache = new WeakHashMap();
75
76
    public WebProjectNature() {}
46
    public WebProjectNature() {}
77
78
    public Lookup getLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
79
        WeakReference wr = (WeakReference)lookupCache.get(project);
80
        Lookup lookup = wr != null ? (Lookup)wr.get() : null;
81
        if (lookup == null) {
82
            lookup = new ProjectLookup(project, projectHelper, projectEvaluator, aux);
83
            lookupCache.put(project, new WeakReference(lookup));
84
        }
85
        return lookup;
86
    }
87
    
88
    public Set getCustomizerPanels(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
89
        HashSet l = new HashSet();
90
        if (!isMyProject(aux)) {
91
            return l;
92
        }
93
        ProjectPropertiesPanel web = new WebLocationsPanel.Panel(projectHelper, projectEvaluator, aux);
94
        l.add(web);
95
        l.add(new WebClasspathPanel.Panel(projectHelper, projectEvaluator, aux));
96
        return l;
97
    }
98
    
47
    
99
    public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
48
    public List getExtraTargets(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
100
        ArrayList l = new ArrayList();
49
        ArrayList l = new ArrayList();
101
        if (!isMyProject(aux)) {
50
        if (!LookupProviderImpl.isMyProject(aux)) {
102
            return l;
51
            return l;
103
        }
52
        }
104
        l.add(getExtraTarget());
53
        l.add(getExtraTarget());
Lines 121-129 Link Here
121
        return null;
70
        return null;
122
    }
71
    }
123
72
124
    private static boolean isMyProject(AuxiliaryConfiguration aux) {
73
 
125
        return aux.getConfigurationFragment("web-data", NS_WEB, true) != null; // NOI18N
126
    }
127
    
74
    
128
    public static TargetDescriptor getExtraTarget() {
75
    public static TargetDescriptor getExtraTarget() {
129
        return new TargetDescriptor(WebProjectConstants.COMMAND_REDEPLOY, Arrays.asList(new String[]{"deploy", ".*deploy.*"}),  // NOI18N
76
        return new TargetDescriptor(WebProjectConstants.COMMAND_REDEPLOY, Arrays.asList(new String[]{"deploy", ".*deploy.*"}),  // NOI18N
Lines 131-334 Link Here
131
            NbBundle.getMessage(WebProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N
78
            NbBundle.getMessage(WebProjectNature.class, "ACSD_TargetMappingPanel_Deploy")); // NOI18N
132
    }
79
    }
133
    
80
    
134
    private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
81
 
135
        WebClasspath webcp = new WebClasspath(projectHelper, projectEvaluator, aux, project);
136
        return Lookups.fixed(new Object[] {
137
            new ProjectOpenedHookImpl(webcp),       // register webroots as source classpath
138
            new PrivilegedTemplatesImpl(),          // List of templates in New action popup
139
            new WebModules(project, projectHelper, projectEvaluator), // WebModuleProvider, ClassPathProvider
140
            new WebFreeFormActionProvider(project, projectHelper, aux),   //ActionProvider
141
            new HelpIDFragmentProviderImpl(),
142
        });
143
    }
144
    
145
    private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider {
146
        public String getHelpIDFragment() {
147
            return HELP_ID_FRAGMENT;
148
        }
149
    }
150
    
151
    private static class ProjectOpenedHookImpl extends ProjectOpenedHook {
152
        private final WebClasspath webcp;
153
        public ProjectOpenedHookImpl(WebClasspath wcp) {
154
            this.webcp = wcp;
155
        }
156
        protected void projectOpened() {
157
            webcp.prjOpened();
158
        }
159
        protected void projectClosed() {
160
            webcp.prjClosed();
161
        }
162
    }
163
    
164
    public static final class WebClasspath implements AntProjectListener, PropertyChangeListener {
165
        
166
        private ClassPath registeredCP[] = new ClassPath[0];
167
        private List/*<FileObject>*/ registeredRoots = Collections.EMPTY_LIST;
168
        
169
        private PropertyEvaluator evaluator;
170
        private AuxiliaryConfiguration aux;
171
        private Project project;
172
        
173
        private PropertyChangeSupport pcs;
174
        
175
        private boolean prjClosed = false;
176
        
177
        public WebClasspath(AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux, Project proj) {
178
            this.evaluator = evaluator;
179
            this.aux = aux;
180
            this.project = proj;
181
            helper.addAntProjectListener(this);
182
            evaluator.addPropertyChangeListener(this);
183
            pcs = new PropertyChangeSupport(this);
184
        }
185
        
186
        public void prjOpened() {
187
            registeredRoots = getWebRoots(aux, project, evaluator);
188
            FileObject fos[] = new FileObject[registeredRoots.size()];
189
            ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) registeredRoots.toArray(fos));
190
            registeredCP = new ClassPath[] { cp };
191
            GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP);
192
            prjClosed = false;
193
        }
194
        
195
        public void prjClosed() {
196
            if (!registeredRoots.isEmpty()) {
197
                GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP);
198
            }
199
            registeredRoots = Collections.EMPTY_LIST;
200
            prjClosed = true;
201
        }
202
        
203
        public void configurationXmlChanged(AntProjectEvent ev) {
204
            updateClasspath();
205
        }
206
        
207
        public void propertiesChanged(AntProjectEvent ev) {
208
            // ignore
209
        }
210
        
211
        public void propertyChange(PropertyChangeEvent ev) {
212
            updateClasspath();
213
        }
214
        
215
        public void addPropertyChangeListener(PropertyChangeListener listener) {
216
            pcs.addPropertyChangeListener(listener);
217
        }
218
        
219
        public void removePropertyChangeListener(PropertyChangeListener listener) {
220
            pcs.removePropertyChangeListener(listener);
221
        }
222
        
223
        private synchronized void updateClasspath() {
224
            if (!prjClosed) {
225
                List newRoots = getWebRoots(aux, project, evaluator);
226
                if (!newRoots.equals(registeredRoots)) {
227
                    FileObject fos[] = new FileObject[newRoots.size()];
228
                    ClassPath cp = ClassPathSupport.createClassPath((FileObject[]) newRoots.toArray(fos));
229
                    GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, registeredCP);
230
                    registeredCP = new ClassPath[] { cp };
231
                    registeredRoots = newRoots;
232
                    GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, registeredCP);
233
                    pcs.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, null, null);
234
                }
235
            }
236
        }
237
        
238
        private List/*<FileObject>*/ getWebRoots(AuxiliaryConfiguration aux, Project proj, PropertyEvaluator evaluator) {
239
            Element web = aux.getConfigurationFragment("web-data", WebProjectNature.NS_WEB, true); // NOI18N
240
            if (web == null) {
241
                return null;
242
            }
243
            List webModules = Util.findSubElements(web);
244
            Iterator it = webModules.iterator();
245
            List/*<FileObject>*/ roots = new ArrayList();
246
            while (it.hasNext()) {
247
                Element webModulesEl = (Element) it.next();
248
                assert webModulesEl.getLocalName().equals("web-module") : webModulesEl; // NOI18N
249
                roots.add(FileUtil.toFileObject(getFile(webModulesEl, "doc-root", proj, evaluator))); // NOI18N
250
            }
251
            return roots;
252
        }
253
        
254
        private File getFile(Element parent, String fileElName, Project proj, PropertyEvaluator evaluator) {
255
            Element el = Util.findElement(parent, fileElName, WebProjectNature.NS_WEB);
256
            return Util.resolveFile(evaluator, FileUtil.toFile(proj.getProjectDirectory()), Util.findText(el));
257
        }
258
        
259
    }
260
    
261
    private static final class ProjectLookup extends ProxyLookup implements AntProjectListener {
262
263
        private AntProjectHelper helper;
264
        private PropertyEvaluator evaluator;
265
        private Project project;
266
        private AuxiliaryConfiguration aux;
267
        private boolean isMyProject;
268
        
269
        public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) {
270
            super(new Lookup[0]);
271
            this.project = project;
272
            this.helper = helper;
273
            this.evaluator = evaluator;
274
            this.aux = aux;
275
            this.isMyProject = isMyProject(aux);
276
            updateLookup();
277
            helper.addAntProjectListener(this);
278
        }
279
        
280
        private void updateLookup() {
281
            Lookup l = Lookup.EMPTY;
282
            if (isMyProject) {
283
                l = initLookup(project, helper, evaluator, aux);
284
            }
285
            setLookups(new Lookup[]{l});
286
        }
287
        
288
        public void configurationXmlChanged(AntProjectEvent ev) {
289
            if (isMyProject(aux) != isMyProject) {
290
                isMyProject = !isMyProject;
291
                updateLookup();
292
            }
293
        }
294
        
295
        public void propertiesChanged(AntProjectEvent ev) {
296
            // ignore
297
        }
298
        
299
    }
300
    
301
    private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates {
302
        
303
        private static final String[] PRIVILEGED_NAMES = new String[] {
304
            "Templates/JSP_Servlet/JSP.jsp",
305
            "Templates/JSP_Servlet/Html.html",
306
            "Templates/JSP_Servlet/Servlet.java",
307
            "Templates/Classes/Class.java",
308
        };
309
        
310
        private static final String[] RECOMENDED_TYPES = new String[] {         
311
            "java-classes",         // NOI18N
312
            "java-main-class",      // NOI18N
313
            "java-beans",           // NOI18N
314
            "oasis-XML-catalogs",   // NOI18N
315
            "XML",                  // NOI18N
316
            "wsdl",                 // NOI18N
317
            "ant-script",           // NOI18N
318
            "ant-task",             // NOI18N
319
            "servlet-types",        // NOI18N
320
            "web-types",            // NOI18N
321
            "j2ee-types",           // NOI18N
322
            "junit",                // NOI18N
323
            "simple-files"          // NOI18N
324
        };
325
        
326
        public String[] getPrivilegedTemplates() {
327
            return PRIVILEGED_NAMES;
328
        }
329
330
        public String[] getRecommendedTypes() {
331
            return RECOMENDED_TYPES;
332
        }
333
    }
334
}
82
}
(-)web/freeform/src/org/netbeans/modules/web/freeform/resources/layer.xml (+17 lines)
Lines 35-38 Link Here
35
35
36
        </folder>
36
        </folder>
37
    </folder>
37
    </folder>
38
    <folder name="Projects">
39
        <folder name="org-netbeans-modules-ant-freeform">
40
            <folder name="Lookup">
41
                <file name="org-netbeans-modules-web-freeform-LookupProviderImpl.instance"/>
42
            </folder>
43
            <folder name="Customizer">
44
                <file name="org-netbeans-modules-web-freeform-ui-WebLocationsCategoryProvider.instance"/>
45
                <attr name="org-netbeans-modules-java-freeform-ui-SourceFoldersCategoryProvider.instance/org-netbeans-modules-web-freeform-ui-WebLocationsCategoryProvider.instance" boolvalue="true"/>
46
                <attr name="org-netbeans-modules-web-freeform-ui-WebLocationsCategoryProvider.instance/org-netbeans-modules-java-freeform-ui-ClasspathCategoryProvider.instance" boolvalue="true"/>
47
                
48
                <file name="org-netbeans-modules-web-freeform-ui-WebClasspathCategoryProvider.instance"/>
49
                <attr name="org-netbeans-modules-java-freeform-ui-ClasspathCategoryProvider.instance/org-netbeans-modules-web-freeform-ui-WebClasspathCategoryProvider.instance" boolvalue="true"/>
50
                <attr name="org-netbeans-modules-web-freeform-ui-WebClasspathCategoryProvider.instance/org-netbeans-modules-java-freeform-ui-OutputCategoryProvider.instance" boolvalue="true"/>
51
            </folder>
52
        </folder>
53
    </folder>
54
    
38
</filesystem>
55
</filesystem>
(-)web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathCategoryProvider.java (+79 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.web.freeform.ui;
21
22
import java.util.List;
23
import javax.swing.JComponent;
24
import org.netbeans.api.project.Project;
25
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
26
import org.netbeans.modules.ant.freeform.spi.support.Util;
27
import org.netbeans.modules.web.freeform.LookupProviderImpl;
28
import org.netbeans.modules.web.freeform.WebProjectGenerator;
29
import org.netbeans.spi.project.AuxiliaryConfiguration;
30
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
31
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
32
import org.openide.filesystems.FileUtil;
33
import org.openide.util.Lookup;
34
import org.openide.util.NbBundle;
35
36
/**
37
 *
38
 * @author mkleint
39
 */
40
public class WebClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
41
    
42
    /** Creates a new instance of EjbLocationsCategoryProvider */
43
    public WebClasspathCategoryProvider() {
44
    }
45
    
46
    public Category createCategory(Lookup context) {
47
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
48
        assert aux != null;
49
        if (LookupProviderImpl.isMyProject(aux)) {
50
            Category cat = ProjectCustomizer.Category.create("WebClasspath", //NOI18N
51
                    NbBundle.getMessage(WebClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null);
52
            return cat;
53
        }
54
        return null;
55
    }
56
57
    public JComponent createComponent(Category category, Lookup context) {
58
        Project project = (Project)context.lookup(Project.class);
59
        ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class);
60
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
61
        assert aux != null;
62
        assert acc != null;
63
        assert project != null;
64
        
65
        WebClasspathPanel panel = new WebClasspathPanel(false);
66
        List l = WebProjectGenerator.getWebmodules(acc.getHelper(), aux);
67
        if (l != null){
68
            WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0);
69
            panel.setProjectFolders(Util.getProjectLocation(acc.getHelper(), acc.getEvaluator()),
70
                    FileUtil.toFile(acc.getHelper().getProjectDirectory()));
71
            panel.setClasspath(wm.classpath, acc.getEvaluator());
72
            panel.updateButtons();
73
        }
74
75
        category.setOkButtonListener(panel.getCustomizerOkListener(acc.getHelper()));
76
        return panel;
77
    }
78
79
}
(-)web/freeform/src/org/netbeans/modules/web/freeform/ui/WebClasspathPanel.java (-56 / +15 lines)
Lines 19-38 Link Here
19
19
20
package org.netbeans.modules.web.freeform.ui;
20
package org.netbeans.modules.web.freeform.ui;
21
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
22
import java.io.File;
24
import java.io.File;
23
import java.net.MalformedURLException;
25
import java.net.MalformedURLException;
24
import java.util.Arrays;
25
import java.util.Collection;
26
import java.util.List;
26
import java.util.List;
27
import java.util.StringTokenizer;
28
29
import javax.swing.DefaultListModel;
27
import javax.swing.DefaultListModel;
30
import javax.swing.JComponent;
31
import javax.swing.JFileChooser;
28
import javax.swing.JFileChooser;
32
import javax.swing.filechooser.FileFilter;
29
import javax.swing.filechooser.FileFilter;
33
34
import org.netbeans.api.project.Project;
35
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
36
import org.netbeans.modules.ant.freeform.spi.support.Util;
30
import org.netbeans.modules.ant.freeform.spi.support.Util;
37
import org.netbeans.modules.web.freeform.WebProjectGenerator;
31
import org.netbeans.modules.web.freeform.WebProjectGenerator;
38
import org.netbeans.spi.project.AuxiliaryConfiguration;
32
import org.netbeans.spi.project.AuxiliaryConfiguration;
Lines 40-46 Link Here
40
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
34
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
41
import org.netbeans.spi.project.support.ant.PropertyUtils;
35
import org.netbeans.spi.project.support.ant.PropertyUtils;
42
import org.openide.ErrorManager;
36
import org.openide.ErrorManager;
43
44
import org.openide.filesystems.FileUtil;
37
import org.openide.filesystems.FileUtil;
45
import org.openide.util.HelpCtx;
38
import org.openide.util.HelpCtx;
46
import org.openide.util.NbBundle;
39
import org.openide.util.NbBundle;
Lines 265-271 Link Here
265
        updateButtons();
258
        updateButtons();
266
    }//GEN-LAST:event_moveUpActionPerformed
259
    }//GEN-LAST:event_moveUpActionPerformed
267
260
268
    private void updateButtons() {
261
    void updateButtons() {
269
        int indices[] = classpath.getSelectedIndices();
262
        int indices[] = classpath.getSelectedIndices();
270
        removeClasspath.setEnabled(listModel.getSize() > 0 && indices.length != 0 && indices[0] != 0);
263
        removeClasspath.setEnabled(listModel.getSize() > 0 && indices.length != 0 && indices[0] != 0);
271
        moveUp.setEnabled(indices.length > 0 && indices[0] > 1);
264
        moveUp.setEnabled(indices.length > 0 && indices[0] > 1);
Lines 340-346 Link Here
340
        return sf.toString();
333
        return sf.toString();
341
    }
334
    }
342
    
335
    
343
    private void setClasspath(String classpath, PropertyEvaluator evaluator){
336
    void setClasspath(String classpath, PropertyEvaluator evaluator){
344
        if (classpath == null)
337
        if (classpath == null)
345
            return;
338
            return;
346
        listModel.clear();
339
        listModel.clear();
Lines 356-412 Link Here
356
        }
349
        }
357
    }
350
    }
358
    
351
    
359
    public static class Panel implements ProjectPropertiesPanel{
352
    ActionListener getCustomizerOkListener(final AntProjectHelper projectHelper) {
360
        
353
        return new ActionListener() {
361
        private WebClasspathPanel panel = null;
354
            public void actionPerformed(ActionEvent arg0) {
362
        private AntProjectHelper projectHelper;
355
                AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
363
        private PropertyEvaluator projectEvaluator;
364
        private AuxiliaryConfiguration aux;
365
        
366
        
367
        public Panel(AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
368
            this.projectHelper = projectHelper;
369
            this.projectEvaluator = projectEvaluator;
370
            this.aux = aux;
371
        }
372
    
373
        public void storeValues() {
374
            if (panel == null) {
375
                return;
376
            }
377
            AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
378
            List l = WebProjectGenerator.getWebmodules(projectHelper, aux);
379
            if (l != null){
380
                WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0);
381
                wm.classpath = panel.getClasspath();
382
                WebProjectGenerator.putWebModules(projectHelper, aux, l);
383
            }
384
            panel.updateButtons();
385
        }    
386
387
        public String getDisplayName() {
388
            return NbBundle.getMessage(WebClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath");
389
        }
390
391
        public JComponent getComponent() {
392
            if (panel == null) {
393
                panel = new WebClasspathPanel(false);
394
                List l = WebProjectGenerator.getWebmodules(projectHelper, aux);
356
                List l = WebProjectGenerator.getWebmodules(projectHelper, aux);
395
                if (l != null){
357
                if (l != null){
396
                    WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0);
358
                    WebProjectGenerator.WebModule wm = (WebProjectGenerator.WebModule)l.get(0);
397
                    panel.setProjectFolders(Util.getProjectLocation(projectHelper, projectEvaluator), 
359
                    wm.classpath = getClasspath();
398
                            FileUtil.toFile(projectHelper.getProjectDirectory()));
360
                    WebProjectGenerator.putWebModules(projectHelper, aux, l);
399
                    panel.setClasspath(wm.classpath, projectEvaluator);
400
                    panel.updateButtons();
401
                }
361
                }
362
                //mkleint: why updating buttons on saving??
363
                updateButtons();
402
            }
364
            }
403
            return panel;
365
        };
404
        }
405
        
406
        public int getPreferredPosition() {
407
            return 250; // after Java Sources Classpath, before Output panel
408
        }    
409
    }
366
    }
367
368
  
410
    
369
    
411
    
370
    
412
    // Variables declaration - do not modify//GEN-BEGIN:variables
371
    // Variables declaration - do not modify//GEN-BEGIN:variables
(-)web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsCategoryProvider.java (+65 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package org.netbeans.modules.web.freeform.ui;
21
22
import javax.swing.JComponent;
23
import org.netbeans.api.project.Project;
24
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
25
import org.netbeans.modules.web.freeform.LookupProviderImpl;
26
import org.netbeans.spi.project.AuxiliaryConfiguration;
27
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
28
import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
29
import org.openide.util.Lookup;
30
import org.openide.util.NbBundle;
31
32
/**
33
 *
34
 * @author mkleint
35
 */
36
public class WebLocationsCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
37
    
38
    /** Creates a new instance of EjbLocationsCategoryProvider */
39
    public WebLocationsCategoryProvider() {
40
    }
41
    
42
    public Category createCategory(Lookup context) {
43
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
44
        assert aux != null;
45
        if (LookupProviderImpl.isMyProject(aux)) {
46
            Category cat = ProjectCustomizer.Category.create("WebLocations", //NOI18N
47
                    NbBundle.getMessage(WebLocationsPanel.class, "LBL_ProjectCustomizer_Category_Web"), null, null);
48
            return cat;
49
        }
50
        return null;
51
    }
52
53
    public JComponent createComponent(Category category, Lookup context) {
54
        Project project = (Project)context.lookup(Project.class);
55
        ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class);
56
        AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
57
        assert aux != null;
58
        assert acc != null;
59
        assert project != null;
60
        WebLocationsPanel panel = new WebLocationsPanel(acc.getHelper(), acc.getEvaluator(), aux);
61
        category.setOkButtonListener(panel.getCustomizerOkListener());
62
        return panel;
63
    }
64
65
}
(-)web/freeform/src/org/netbeans/modules/web/freeform/ui/WebLocationsPanel.java (-38 / +9 lines)
Lines 19-32 Link Here
19
19
20
package org.netbeans.modules.web.freeform.ui;
20
package org.netbeans.modules.web.freeform.ui;
21
21
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
22
import java.io.File;
24
import java.io.File;
23
import java.util.ArrayList;
25
import java.util.ArrayList;
24
import java.util.List;
26
import java.util.List;
25
import javax.swing.JComponent;
26
import javax.swing.JFileChooser;
27
import javax.swing.JFileChooser;
27
import org.netbeans.api.project.Project;
28
import org.netbeans.api.queries.CollocationQuery;
28
import org.netbeans.api.queries.CollocationQuery;
29
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel;
30
import org.netbeans.modules.ant.freeform.spi.support.Util;
29
import org.netbeans.modules.ant.freeform.spi.support.Util;
31
import org.netbeans.modules.web.freeform.WebProjectGenerator;
30
import org.netbeans.modules.web.freeform.WebProjectGenerator;
32
import org.openide.filesystems.FileUtil;
31
import org.openide.filesystems.FileUtil;
Lines 361-402 Link Here
361
        return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation);
360
        return Util.relativizeLocation(baseFolder, nbProjectFolder, normalizedLocation);
362
    }
361
    }
363
362
364
    public static class Panel implements ProjectPropertiesPanel {
363
    ActionListener getCustomizerOkListener() {
365
        
364
        return new ActionListener() {
366
        private AntProjectHelper projectHelper;
365
            public void actionPerformed(ActionEvent arg0) {
367
        private PropertyEvaluator projectEvaluator;
366
                AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
368
        private AuxiliaryConfiguration aux;
367
                WebProjectGenerator.putWebSourceFolder(projectHelper, getWebSrcFolder());
369
        private WebLocationsPanel panel =  null;
368
                WebProjectGenerator.putWebModules(projectHelper, aux, getWebModules());
370
        
371
        public Panel(AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) {
372
            this.projectHelper = projectHelper;
373
            this.projectEvaluator = projectEvaluator;
374
            this.aux = aux;
375
        }
376
    
377
        public void storeValues() {
378
            if (panel == null) {
379
                return;
380
            }
381
            AuxiliaryConfiguration aux = Util.getAuxiliaryConfiguration(projectHelper);
382
            WebProjectGenerator.putWebSourceFolder(projectHelper, panel.getWebSrcFolder());
383
            WebProjectGenerator.putWebModules(projectHelper, aux, panel.getWebModules());
384
        }
385
386
        public String getDisplayName() {
387
            return NbBundle.getMessage(WebLocationsPanel.class, "LBL_ProjectCustomizer_Category_Web");
388
        }
389
390
        public JComponent getComponent() {
391
            if (panel == null) {
392
                panel = new WebLocationsPanel(projectHelper, projectEvaluator, aux);
393
            }
369
            }
394
            return panel;
370
        };
395
        }
396
397
        public int getPreferredPosition() {
398
            return 150; // after Java sources panel, befvore Java Sources Classpath panel
399
        }
400
    }
371
    }
401
    
372
    
402
}
373
}

Return to bug 90562