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

(-)a/java.project.ui/apichanges.xml (+12 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="JavaFileWizardIteratorFactory">
111
            <api name="JavaProjectUI"/>
112
            <summary>Allows to extend the New Java File Wizard by project specific panels</summary>
113
            <version major="1" minor="69"/>
114
            <date day="14" month="4" year="2016"/>
115
            <author login="tzezula"/>
116
            <compatibility modification="yes" addition="yes"/>
117
            <description>
118
                Allows to extend the New Java File Wizard by project specific panels.
119
            </description>
120
            <class name="JavaFileWizardIteratorFactory" package="org.netbeans.spi.java.project.support.ui.templates"/>
121
        </change>
110
    <change id="server.is.free">
122
    <change id="server.is.free">
111
            <api name="JavaProjectUI"/>
123
            <api name="JavaProjectUI"/>
112
            <summary>Desktop dependent Java Project Support UI extracted</summary>
124
            <summary>Desktop dependent Java Project Support UI extracted</summary>
(-)a/java.project.ui/manifest.mf (-1 / +1 lines)
Lines 3-9 Link Here
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/ui/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/ui/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/ui/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/ui/Bundle.properties
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
6
OpenIDE-Module-Specification-Version: 1.68
6
OpenIDE-Module-Specification-Version: 1.69
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
8
AutoUpdate-Show-In-Client: false
8
AutoUpdate-Show-In-Client: false
9
9
(-)a/java.project.ui/nbproject/project.properties (-2 / +2 lines)
Lines 43-49 Link Here
43
is.autoload=true
43
is.autoload=true
44
44
45
javac.compilerargs=-Xlint -Xlint:-serial
45
javac.compilerargs=-Xlint -Xlint:-serial
46
javac.source=1.7
46
javac.source=1.8
47
javadoc.overview=${basedir}/overview.html
47
javadoc.overview=${basedir}/overview.html
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
Lines 63-66 Link Here
63
    **/JavadocAndSourceRootDetectionTest.class
63
    **/JavadocAndSourceRootDetectionTest.class
64
64
65
test.config.create.includes=\
65
test.config.create.includes=\
66
    **/CreateProjectTest.class
66
    **/CreateProjectTest.class
(-)a/java.project.ui/src/org/netbeans/modules/java/project/ui/NewJavaFileWizardIterator.java (-21 / +61 lines)
Lines 52-57 Link Here
52
import java.net.URL;
52
import java.net.URL;
53
import java.util.ArrayList;
53
import java.util.ArrayList;
54
import java.util.Arrays;
54
import java.util.Arrays;
55
import java.util.Collection;
55
import java.util.Collections;
56
import java.util.Collections;
56
import java.util.HashMap;
57
import java.util.HashMap;
57
import java.util.HashSet;
58
import java.util.HashSet;
Lines 60-69 Link Here
60
import java.util.Map;
61
import java.util.Map;
61
import java.util.NoSuchElementException;
62
import java.util.NoSuchElementException;
62
import java.util.Objects;
63
import java.util.Objects;
64
import java.util.Optional;
63
import java.util.Set;
65
import java.util.Set;
64
import javax.swing.JComponent;
66
import javax.swing.JComponent;
65
import javax.swing.event.ChangeEvent;
67
import javax.swing.event.ChangeEvent;
66
import javax.swing.event.ChangeListener;
68
import javax.swing.event.ChangeListener;
69
import org.netbeans.api.annotations.common.NonNull;
70
import org.netbeans.api.annotations.common.NullAllowed;
67
import org.netbeans.api.java.classpath.ClassPath;
71
import org.netbeans.api.java.classpath.ClassPath;
68
import org.netbeans.api.java.classpath.JavaClassPathConstants;
72
import org.netbeans.api.java.classpath.JavaClassPathConstants;
69
import org.netbeans.api.java.project.JavaProjectConstants;
73
import org.netbeans.api.java.project.JavaProjectConstants;
Lines 90-95 Link Here
90
import org.openide.loaders.DataObject;
94
import org.openide.loaders.DataObject;
91
import org.openide.util.Exceptions;
95
import org.openide.util.Exceptions;
92
import org.openide.util.NbBundle.Messages;
96
import org.openide.util.NbBundle.Messages;
97
import org.netbeans.spi.java.project.support.ui.templates.JavaFileWizardIteratorFactory;
93
98
94
/**
99
/**
95
 * Wizard to create a new Java file.
100
 * Wizard to create a new Java file.
Lines 161-167 Link Here
161
        return new NewJavaFileWizardIterator(Type.MODULE_INFO);
166
        return new NewJavaFileWizardIterator(Type.MODULE_INFO);
162
    }
167
    }
163
            
168
            
164
    private WizardDescriptor.Panel[] createPanels (WizardDescriptor wizardDescriptor) {
169
    private WizardDescriptor.Panel[] createPanels (
170
            @NonNull final WizardDescriptor wizardDescriptor,
171
            @NonNull final Collection<WizardDescriptor.Iterator<WizardDescriptor>> itOut) {
165
        
172
        
166
        // Ask for Java folders
173
        // Ask for Java folders
167
        Project project = Templates.getProject( wizardDescriptor );
174
        Project project = Templates.getProject( wizardDescriptor );
Lines 178-195 Link Here
178
            };
185
            };
179
        }
186
        }
180
        else {
187
        else {
181
            
188
            final List<WizardDescriptor.Panel<?>> panels = new ArrayList<>();
182
            if (this.type == Type.FILE) {
189
            if (this.type == Type.FILE) {
183
                return new WizardDescriptor.Panel[] {
190
                panels.add(JavaTemplates.createPackageChooser( project, groups ));
184
                    JavaTemplates.createPackageChooser( project, groups ),
185
                };
186
            } else if (type == Type.PKG_INFO) {
191
            } else if (type == Type.PKG_INFO) {
187
                return new WizardDescriptor.Panel[] {
192
                panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PKG_INFO, true));
188
                    new JavaTargetChooserPanel(project, groups, null, Type.PKG_INFO, true),
189
                };
190
            } else if (type == Type.MODULE_INFO) {
193
            } else if (type == Type.MODULE_INFO) {
191
                List<WizardDescriptor.Panel> pnls = new ArrayList<>();
194
                panels.add(new JavaTargetChooserPanel(project, groups, null, Type.MODULE_INFO, false));
192
                pnls.add(new JavaTargetChooserPanel(project, groups, null, Type.MODULE_INFO, false));
193
                Map<FileObject, Set<ClassPathItem>> group2items = new HashMap<>();
195
                Map<FileObject, Set<ClassPathItem>> group2items = new HashMap<>();
194
                for (SourceGroup group : groups) {
196
                for (SourceGroup group : groups) {
195
                    try {
197
                    try {
Lines 211-219 Link Here
211
                    } catch (Exception ex) {}
213
                    } catch (Exception ex) {}
212
                }
214
                }
213
                if (!group2items.isEmpty()) {
215
                if (!group2items.isEmpty()) {
214
                    pnls.add(new MoveToModulePathPanel(group2items));
216
                    panels.add(new MoveToModulePathPanel(group2items));
215
                }
217
                }
216
                return pnls.toArray(new WizardDescriptor.Panel[pnls.size()]);
217
            } else {
218
            } else {
218
                assert type == Type.PACKAGE;
219
                assert type == Type.PACKAGE;
219
                SourceGroup[] groovySourceGroups = sources.getSourceGroups(SOURCE_TYPE_GROOVY);
220
                SourceGroup[] groovySourceGroups = sources.getSourceGroups(SOURCE_TYPE_GROOVY);
Lines 232-243 Link Here
232
                    all.addAll(Arrays.asList(resources));
233
                    all.addAll(Arrays.asList(resources));
233
                    groups = all.toArray(new SourceGroup[all.size()]);
234
                    groups = all.toArray(new SourceGroup[all.size()]);
234
                }
235
                }
235
                return new WizardDescriptor.Panel[] {
236
                panels.add(new JavaTargetChooserPanel(project, groups, null, Type.PACKAGE, false));
236
                    new JavaTargetChooserPanel(project, groups, null, Type.PACKAGE, false),
237
                };
238
            }
237
            }
238
            final JavaFileWizardIteratorFactory templateProvider = project.getLookup().lookup(JavaFileWizardIteratorFactory.class);
239
            if (templateProvider != null) {
240
                final WizardDescriptor.Iterator it = templateProvider.createIterator(Templates.getTemplate(wizardDescriptor ));
241
                if (it != null) {
242
                    itOut.add(it);
243
                    panels.add(it.current());
244
                    while(it.hasNext()) {
245
                        it.nextPanel();
246
                        panels.add(it.current());
247
                    }
248
                }
249
            }
250
            return panels.toArray(new WizardDescriptor.Panel<?>[panels.size()]);
239
        }
251
        }
240
               
241
    }
252
    }
242
253
243
    private static SourceGroup[] checkNotNull (SourceGroup[] groups, Sources sources) {
254
    private static SourceGroup[] checkNotNull (SourceGroup[] groups, Sources sources) {
Lines 284-297 Link Here
284
        if (this.type == Type.PACKAGE) {
295
        if (this.type == Type.PACKAGE) {
285
            targetName = targetName.replace( '.', '/' ); // NOI18N
296
            targetName = targetName.replace( '.', '/' ); // NOI18N
286
            createdFile = FileUtil.createFolder( dir, targetName );
297
            createdFile = FileUtil.createFolder( dir, targetName );
287
        }
298
        } else {
288
        else {
289
            DataObject dTemplate = DataObject.find( template );                
299
            DataObject dTemplate = DataObject.find( template );                
290
            DataObject dobj = dTemplate.createFromTemplate( df, targetName );
300
            DataObject dobj = dTemplate.createFromTemplate( df, targetName );
291
            createdFile = dobj.getPrimaryFile();
301
            createdFile = dobj.getPrimaryFile();
292
        }
302
        }
293
        
303
        final Set<FileObject> res = new HashSet<>();
294
        return Collections.singleton( createdFile );
304
        res.add(createdFile);
305
        asInstantiatingIterator(projectSpecificIterator)
306
                .map((it)->{
307
                    try {
308
                        return it.instantiate();
309
                    } catch (IOException ioe) {
310
                        Exceptions.printStackTrace(ioe);
311
                        return null;
312
                    }
313
                })
314
                .ifPresent(res::addAll);
315
        return Collections.unmodifiableSet(res);
295
    }
316
    }
296
    
317
    
297
    private void moveCPItems(Iterable<ClassPathItem> cpItemsToMove, FileObject folder) {
318
    private void moveCPItems(Iterable<ClassPathItem> cpItemsToMove, FileObject folder) {
Lines 343-358 Link Here
343
            } catch (Exception ex) {}
364
            } catch (Exception ex) {}
344
        }        
365
        }        
345
    }
366
    }
367
368
    @NonNull
369
    private static Optional<WizardDescriptor.InstantiatingIterator<WizardDescriptor>> asInstantiatingIterator(
370
            @NullAllowed final WizardDescriptor.Iterator<WizardDescriptor> it) {
371
        return Optional.ofNullable(it)
372
                .map((p)->{
373
                    return p instanceof WizardDescriptor.InstantiatingIterator ?
374
                            (WizardDescriptor.InstantiatingIterator<WizardDescriptor>) p:
375
                            null;
376
                });
377
    }
346
        
378
        
347
    private transient int index;
379
    private transient int index;
348
    private transient WizardDescriptor.Panel[] panels;
380
    private transient WizardDescriptor.Panel[] panels;
349
    private transient WizardDescriptor wiz;
381
    private transient WizardDescriptor wiz;
382
    private transient WizardDescriptor.Iterator<WizardDescriptor> projectSpecificIterator;
350
    
383
    
351
    @Override
384
    @Override
352
    public void initialize(WizardDescriptor wiz) {
385
    public void initialize(WizardDescriptor wiz) {
353
        this.wiz = wiz;
386
        this.wiz = wiz;
354
        index = 0;
387
        index = 0;
355
        panels = createPanels( wiz );
388
        final List<WizardDescriptor.Iterator<WizardDescriptor>> itOut = new ArrayList<>(1);
389
        panels = createPanels(wiz, itOut);
390
        projectSpecificIterator = itOut.get(0);
391
        asInstantiatingIterator(projectSpecificIterator)
392
                .ifPresent((it)->it.initialize(wiz));
356
        // Make sure list of steps is accurate.
393
        // Make sure list of steps is accurate.
357
        String[] beforeSteps = null;
394
        String[] beforeSteps = null;
358
        Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA);
395
        Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA);
Lines 380-387 Link Here
380
417
381
    @Override
418
    @Override
382
    public void uninitialize (WizardDescriptor wiz) {
419
    public void uninitialize (WizardDescriptor wiz) {
420
        asInstantiatingIterator(projectSpecificIterator)
421
                .ifPresent((it)->it.uninitialize(wiz));
383
        this.wiz = null;
422
        this.wiz = null;
384
        panels = null;
423
        panels = null;
424
        projectSpecificIterator = null;
385
    }
425
    }
386
    
426
    
387
    @Override
427
    @Override
(-)a/java.project.ui/src/org/netbeans/spi/java/project/support/ui/templates/JavaFileWizardIteratorFactory.java (+70 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.java.project.support.ui.templates;
43
44
import org.netbeans.api.annotations.common.CheckForNull;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.openide.WizardDescriptor;
47
import org.openide.WizardDescriptor.Iterator;
48
import org.openide.filesystems.FileObject;
49
50
/**
51
 * Allows to extend the New Java File Wizard by project specific panels.
52
 * The instance of the {@link JavaFileWizardIteratorFactory} placed in the
53
 * project's Lookup is consulted by the New Java File Wizard for additional
54
 * panels.
55
 * @author Tomas Zezula
56
 * @since 1.69
57
 */
58
public interface JavaFileWizardIteratorFactory {
59
    /**
60
     * Creates an {@link Iterator} with project specific panels for given template.
61
     * When the created {@link Iterator} is an instance of the {@link WizardDescriptor.InstantiatingIterator}
62
     * the {@link WizardDescriptor.InstantiatingIterator} life cycle methods such as {@link WizardDescriptor.InstantiatingIterator#instantiate}
63
     * are called on proper places.
64
     * @param template the template to create additional panels for
65
     * @return the {@link Iterator} with additional panels or null when no additional
66
     * panels.
67
     */
68
    @CheckForNull
69
    Iterator<WizardDescriptor> createIterator(@NonNull FileObject template);
70
}

Return to bug 258818