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

(-)a/form.nb/src/org/netbeans/modules/nbform/wizard/TemplateWizardIterator.java (-343 lines)
Lines 1-343 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.nbform.wizard;
46
47
import com.sun.source.tree.ClassTree;
48
import com.sun.source.tree.ExpressionTree;
49
import com.sun.source.tree.Tree;
50
import java.awt.Component;
51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.Insets;
54
import java.awt.event.FocusAdapter;
55
import java.io.IOException;
56
import java.util.NoSuchElementException;
57
import java.util.ResourceBundle;
58
import java.util.Set;
59
import java.util.logging.Level;
60
import java.util.logging.LogRecord;
61
import java.util.logging.Logger;
62
import javax.lang.model.element.TypeElement;
63
import javax.swing.JComponent;
64
import javax.swing.JLabel;
65
import javax.swing.JTextField;
66
import javax.swing.event.ChangeListener;
67
import org.netbeans.api.java.source.CancellableTask;
68
import org.netbeans.api.java.source.JavaSource;
69
import org.netbeans.api.java.source.TreeMaker;
70
import org.netbeans.api.java.source.TreeUtilities;
71
import org.netbeans.api.java.source.WorkingCopy;
72
import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
73
import org.openide.WizardDescriptor;
74
import org.openide.filesystems.FileObject;
75
import org.openide.loaders.TemplateWizard;
76
import org.openide.util.NbBundle;
77
78
/**
79
 * Special template wizard iterator for BeanForm template - requires to
80
 * specify superclass additionally.
81
 *
82
 * @author Tomas Pavek, Jan Stola
83
 */
84
85
class TemplateWizardIterator implements WizardDescriptor.InstantiatingIterator {
86
    private transient WizardDescriptor wiz;
87
    private transient WizardDescriptor.Panel superclassPanel;
88
    private transient boolean superclassPanelCurrent;
89
    private transient WizardDescriptor.InstantiatingIterator delegateIterator;
90
91
    private boolean specifySuperclass;
92
93
    public static TemplateWizardIterator createForSuperclass() {
94
        return new TemplateWizardIterator(true);
95
    }
96
97
    public static TemplateWizardIterator create() {
98
        return new TemplateWizardIterator(false);
99
    }
100
101
    public TemplateWizardIterator(boolean specifySuperclass) {
102
        delegateIterator = JavaTemplates.createJavaTemplateIterator();
103
        this.specifySuperclass = specifySuperclass;
104
    }
105
106
    @Override
107
    public void initialize(WizardDescriptor wizard) {
108
        wiz = wizard;
109
        delegateIterator.initialize(wizard);
110
        superclassPanelCurrent = false;
111
        if (superclassPanel == null && specifySuperclass) {
112
            superclassPanel = new SuperclassWizardPanel();
113
            
114
            ResourceBundle bundle = NbBundle.getBundle(TemplateWizardIterator.class);
115
            JComponent comp = (JComponent)delegateIterator.current().getComponent();
116
            String[] contentData = (String[])comp.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
117
            String[] newContentData = new String[contentData.length+1];
118
            System.arraycopy(contentData, 0, newContentData, 0, contentData.length);
119
            newContentData[contentData.length] = bundle.getString("CTL_SuperclassTitle"); // NOI18N
120
            comp.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, newContentData); // NOI18N
121
        }    
122
    }
123
124
    @Override
125
    public void uninitialize(WizardDescriptor wizard) {
126
        delegateIterator.uninitialize(wizard);
127
        superclassPanel = null;
128
    }
129
130
    @Override
131
    public Set instantiate() throws IOException, IllegalArgumentException {
132
        Set set = delegateIterator.instantiate();
133
        FileObject template = (FileObject) set.iterator().next();
134
        if (wiz instanceof TemplateWizard) {
135
            Logger logger = Logger.getLogger("org.netbeans.ui.metrics.form"); // NOI18N
136
            LogRecord rec = new LogRecord(Level.INFO, "USG_FORM_CREATED"); // NOI18N
137
            rec.setLoggerName(logger.getName());
138
            rec.setParameters(new Object[] { ((TemplateWizard)wiz).getTemplate().getName() });
139
            logger.log(rec);
140
        }
141
142
        if (specifySuperclass) {
143
            final String className = template.getName();
144
            final String superclassName = 
145
                    ((SuperclassWizardPanel) superclassPanel).getSuperclassName();           
146
            JavaSource js = JavaSource.forFileObject(template);
147
            js.runModificationTask(new CancellableTask<WorkingCopy>() {
148
                @Override
149
                public void cancel() {
150
                }
151
                @Override
152
                public void run(WorkingCopy wcopy) throws Exception {
153
                    wcopy.toPhase(JavaSource.Phase.RESOLVED);
154
   
155
                    for (Tree t: wcopy.getCompilationUnit().getTypeDecls()) {
156
                        if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind()) && className.equals(((ClassTree) t).getSimpleName().toString())) {
157
                            ClassTree orig = (ClassTree) t;
158
                            TreeMaker maker = wcopy.getTreeMaker();
159
                            TypeElement superclassElm = wcopy.getElements().getTypeElement(superclassName);
160
                            ExpressionTree extendsTree = superclassElm != null
161
                                ? maker.QualIdent(superclassElm)
162
                                : maker.Identifier(superclassName);
163
                            ClassTree copy = maker.Class(
164
                                orig.getModifiers(),
165
                                orig.getSimpleName(),
166
                                orig.getTypeParameters(),
167
                                extendsTree,
168
                                orig.getImplementsClause(),
169
                                orig.getMembers());
170
                            wcopy.rewrite(orig, copy);
171
                            break;
172
                        }
173
                    }
174
                }
175
            }).commit();
176
        }
177
178
        template.setAttribute("justCreatedByNewWizard", Boolean.TRUE); // NOI18N
179
        
180
        return set;
181
    }
182
183
    @Override
184
    public WizardDescriptor.Panel current() {
185
        return superclassPanelCurrent ? superclassPanel : delegateIterator.current();
186
    }
187
188
    @Override
189
    public boolean hasNext() {
190
        return delegateIterator.hasNext() || (!superclassPanelCurrent && superclassPanel != null);
191
    }
192
    
193
    @Override
194
    public boolean hasPrevious() {
195
        return superclassPanelCurrent ? true : delegateIterator.hasPrevious();
196
    }
197
    
198
    @Override
199
    public void nextPanel() {
200
        if (delegateIterator.hasNext()) {
201
            delegateIterator.nextPanel();
202
        } else {
203
            if (superclassPanelCurrent || superclassPanel == null) {
204
                throw new NoSuchElementException();
205
            } else {
206
                superclassPanelCurrent = true;
207
            }
208
        }
209
    }
210
    
211
    @Override
212
    public void previousPanel() {
213
        if (superclassPanelCurrent) {
214
            superclassPanelCurrent = false;
215
        } else {
216
            delegateIterator.previousPanel();
217
        }
218
    }
219
    
220
    @Override
221
    public void addChangeListener(ChangeListener l) {
222
        delegateIterator.addChangeListener(l);
223
    }
224
    
225
    @Override
226
    public String name() {
227
        return superclassPanelCurrent ? "" : delegateIterator.name(); // NOI18N
228
    }
229
    
230
    @Override
231
    public void removeChangeListener(ChangeListener l) {
232
        delegateIterator.removeChangeListener(l);
233
    }
234
235
    // ---------
236
237
    static class SuperclassWizardPanel implements WizardDescriptor.FinishablePanel {
238
239
        private SuperclassPanel panelUI;
240
241
        String getSuperclassName() {
242
            String name = panelUI != null ?
243
                          panelUI.superclassTextField.getText() : null;
244
            return name != null && !"".equals(name) ? name : "java.lang.Object"; // NOI18N
245
        }
246
247
        @Override
248
        public Component getComponent() {
249
            if (panelUI == null)
250
                panelUI = new SuperclassPanel();
251
            return panelUI;
252
        }
253
254
        @Override
255
        public boolean isValid() {
256
            return true;
257
        }
258
259
        @Override
260
        public void readSettings(Object settings) {
261
        }
262
263
        @Override
264
        public void storeSettings(Object settings) {
265
        }
266
267
        @Override
268
        public void addChangeListener(ChangeListener l) {
269
        }
270
271
        @Override
272
        public void removeChangeListener(ChangeListener l) {
273
        }
274
275
        @Override
276
        public org.openide.util.HelpCtx getHelp () {
277
            return new org.openide.util.HelpCtx("gui.creatingforms"); // NOI18N
278
        }
279
        
280
        @Override
281
        public boolean isFinishPanel() {
282
            return true;
283
        }
284
        
285
    }
286
287
    // -------
288
289
    static class SuperclassPanel extends javax.swing.JPanel {
290
291
        SuperclassPanel() {
292
            ResourceBundle bundle = NbBundle.getBundle(TemplateWizardIterator.class);
293
            setName(bundle.getString("CTL_SuperclassTitle")); // NOI18N
294
            putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(1)); //NOI18N
295
            getAccessibleContext()
296
                .setAccessibleDescription(bundle.getString("ACSD_SuperclassPanel")); // NOI18N
297
298
            setLayout(new GridBagLayout());
299
            setBorder(new javax.swing.border.EmptyBorder(8, 8, 8, 8));
300
301
            label1 = new JLabel();
302
            superclassTextField = new JTextField();
303
304
            label1.setLabelFor(superclassTextField);
305
            label1.setText(bundle.getString("CTL_SuperclassName")); // NOI18N
306
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
307
            gridBagConstraints.gridx = 0;
308
            gridBagConstraints.gridy = 0;
309
            gridBagConstraints.anchor = GridBagConstraints.WEST;
310
            gridBagConstraints.insets = new Insets(0, 0, 0, 12);
311
            add(label1, gridBagConstraints);
312
313
            superclassTextField.setText("java.lang.Object"); // NOI18N
314
            superclassTextField.setToolTipText(bundle.getString("CTL_SuperclassName_Hint")); // NOI18N
315
            superclassTextField.getAccessibleContext()
316
                .setAccessibleDescription(bundle.getString("ACSD_SuperclassTextField"));  // NOI18N
317
            superclassTextField.addFocusListener(new FocusAdapter() {
318
                @Override
319
                public void focusGained(java.awt.event.FocusEvent evt) {
320
                    superclassTextField.selectAll();
321
                }
322
            });
323
324
            gridBagConstraints = new GridBagConstraints();
325
            gridBagConstraints.gridx = 1;
326
            gridBagConstraints.gridy = 0;
327
            gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
328
            gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
329
            gridBagConstraints.weightx = 1.0;
330
            gridBagConstraints.weighty = 1.0;
331
            add(superclassTextField, gridBagConstraints);
332
        }
333
334
        @Override
335
        public void addNotify() {
336
            super.addNotify();
337
            superclassTextField.requestFocus();
338
        }
339
340
        private JLabel label1;
341
        private JTextField superclassTextField;
342
    }
343
}
(-)a/form/src/org/netbeans/modules/form/resources/layer.xml (-13 / +13 lines)
Lines 454-460 Link Here
454
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/FormJApplet.html"/>
454
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/FormJApplet.html"/>
455
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/applet.gif"/>
455
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/applet.gif"/>
456
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/javax/swing/beaninfo/images/JAppletColor32.gif"/>
456
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/javax/swing/beaninfo/images/JAppletColor32.gif"/>
457
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
457
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
458
                <attr name="templateCategory" stringvalue="java-forms"/>
458
                <attr name="templateCategory" stringvalue="java-forms"/>
459
            </file>
459
            </file>
460
            <file name="JApplet.form" url="templates/SwingForms/JApplet_form">
460
            <file name="JApplet.form" url="templates/SwingForms/JApplet_form">
Lines 470-476 Link Here
470
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JDialog.html"/>
470
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JDialog.html"/>
471
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
471
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
472
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
472
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
473
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
473
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
474
                <attr name="templateCategory" stringvalue="java-forms"/>
474
                <attr name="templateCategory" stringvalue="java-forms"/>
475
            </file>
475
            </file>
476
            <file name="JDialog.form" url="templates/SwingForms/JDialog_form">
476
            <file name="JDialog.form" url="templates/SwingForms/JDialog_form">
Lines 486-492 Link Here
486
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JFrame.html"/>
486
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JFrame.html"/>
487
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
487
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
488
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
488
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
489
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
489
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
490
                <attr name="templateCategory" stringvalue="java-forms"/>
490
                <attr name="templateCategory" stringvalue="java-forms"/>
491
            </file>
491
            </file>
492
            <file name="JFrame.form" url="templates/SwingForms/JFrame_form">
492
            <file name="JFrame.form" url="templates/SwingForms/JFrame_form">
Lines 502-508 Link Here
502
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JInternalFrame.html"/>
502
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JInternalFrame.html"/>
503
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/internal_frame_16.png"/>
503
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/internal_frame_16.png"/>
504
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/internal_frame_32.png"/>
504
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/internal_frame_32.png"/>
505
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
505
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
506
                <attr name="templateCategory" stringvalue="java-forms"/>
506
                <attr name="templateCategory" stringvalue="java-forms"/>
507
            </file>
507
            </file>
508
            <file name="JInternalFrame.form" url="templates/SwingForms/JInternalFrame_form">
508
            <file name="JInternalFrame.form" url="templates/SwingForms/JInternalFrame_form">
Lines 518-524 Link Here
518
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JPanel.html"/>
518
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/JPanel.html"/>
519
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_16.png"/>
519
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_16.png"/>
520
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_32.png"/>
520
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_32.png"/>
521
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
521
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
522
                <attr name="templateCategory" stringvalue="java-forms"/>
522
                <attr name="templateCategory" stringvalue="java-forms"/>
523
            </file>
523
            </file>
524
            <file name="JPanel.form" url="templates/SwingForms/JPanel_form">
524
            <file name="JPanel.form" url="templates/SwingForms/JPanel_form">
Lines 534-540 Link Here
534
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/BeanForm.html"/>
534
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/BeanForm.html"/>
535
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_16.png"/>
535
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_16.png"/>
536
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_32.png"/>
536
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/panel_32.png"/>
537
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.createForSuperclass"/>
537
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.createForSuperclass"/>
538
                <attr name="templateCategory" stringvalue="java-forms"/>
538
                <attr name="templateCategory" stringvalue="java-forms"/>
539
            </file>
539
            </file>
540
            <file name="BeanForm.form" url="templates/SwingForms/BeanForm_form">
540
            <file name="BeanForm.form" url="templates/SwingForms/BeanForm_form">
Lines 550-556 Link Here
550
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Application.html"/>
550
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Application.html"/>
551
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
551
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
552
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
552
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
553
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
553
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
554
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
554
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
555
            </file>
555
            </file>
556
            <file name="Application.form" url="templates/Dialogs/Application_form">
556
            <file name="Application.form" url="templates/Dialogs/Application_form">
Lines 566-572 Link Here
566
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/MDIApplication.html"/>
566
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/MDIApplication.html"/>
567
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
567
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
568
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
568
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
569
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
569
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
570
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
570
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
571
            </file>
571
            </file>
572
            <file name="MDIApplication.form" url="templates/Dialogs/MDIApplication_form">
572
            <file name="MDIApplication.form" url="templates/Dialogs/MDIApplication_form">
Lines 582-588 Link Here
582
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/OKCancelDialog.html"/>
582
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/OKCancelDialog.html"/>
583
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
583
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
584
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
584
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
585
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
585
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
586
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
586
                <attr name="templateCategory" stringvalue="gui-java-application,java-forms"/>
587
            </file>
587
            </file>
588
            <file name="OkCancelDialog.form" url="templates/Dialogs/OkCancelDialog_form">
588
            <file name="OkCancelDialog.form" url="templates/Dialogs/OkCancelDialog_form">
Lines 608-614 Link Here
608
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/FormApplet.html"/>
608
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/FormApplet.html"/>
609
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/applet.gif"/>
609
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/applet.gif"/>
610
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/javax/swing/beaninfo/images/JAppletColor32.gif"/>
610
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/javax/swing/beaninfo/images/JAppletColor32.gif"/>
611
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
611
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
612
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
612
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
613
            </file>
613
            </file>
614
            <file name="Applet.form" url="templates/AWTForms/Applet_form">
614
            <file name="Applet.form" url="templates/AWTForms/Applet_form">
Lines 624-630 Link Here
624
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Dialog.html"/>
624
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Dialog.html"/>
625
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
625
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_16.png"/>
626
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
626
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/dialog_32.png"/>
627
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
627
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
628
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
628
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
629
            </file>
629
            </file>
630
            <file name="Dialog.form" url="templates/AWTForms/Dialog_form">
630
            <file name="Dialog.form" url="templates/AWTForms/Dialog_form">
Lines 640-646 Link Here
640
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Frame.html"/>
640
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Frame.html"/>
641
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
641
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_16.png"/>
642
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
642
                <attr name="SystemFileSystem.icon32" urlvalue="nbresloc:/org/netbeans/modules/form/resources/palette/frame_32.png"/>
643
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
643
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
644
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
644
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
645
            </file>
645
            </file>
646
            <file name="Frame.form" url="templates/AWTForms/Frame_form">
646
            <file name="Frame.form" url="templates/AWTForms/Frame_form">
Lines 655-661 Link Here
655
                <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
655
                <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
656
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Panel.html"/>
656
                <attr name="instantiatingWizardURL" urlvalue="nbresloc:/org/netbeans/modules/form/resources/Panel.html"/>
657
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/beaninfo/awt/panel.gif"/>
657
                <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/form/beaninfo/awt/panel.gif"/>
658
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.nbform.wizard.TemplateWizardIterator.create"/>
658
                <attr name="instantiatingIterator" methodvalue="org.netbeans.modules.java.source.queries.api.TemplateWizardFactory.create"/>
659
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
659
                <attr name="templateCategory" stringvalue="java-forms,java-awt-forms"/>
660
            </file>
660
            </file>
661
            <file name="Panel.form" url="templates/AWTForms/Panel_form">
661
            <file name="Panel.form" url="templates/AWTForms/Panel_form">
(-)a/java.source.queries/apichanges.xml (+15 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="adding-TemplateWizardFactory">
112
             <api name="general"/>
113
             <summary>Adding TemplateWizardFactory and TemplateWizardProvider</summary>
114
             <version major="1" minor="3"/>
115
             <date day="25" month="9" year="2011"/>
116
             <author login="jhorvath"/>
117
             <compatibility binary="compatible" modification="yes" semantic="compatible" source="compatible"/>
118
             <description>
119
                 Adding TemplateWizardFactory and TemplateWizardProvider to allow template wizards 
120
                 to have a single entry point in JDev and NetBeans.
121
             </description>
122
             <class package="org.netbeans.modules.java.source.queries.api" name="TemplateWizardFactory"/>
123
             <class package="org.netbeans.modules.java.source.queries.spi" name="TemplateWizardProvider"/>
124
             <issue number="202516"/>
125
        </change>
111
        <change id="getMethodSpan-includeComments">
126
        <change id="getMethodSpan-includeComments">
112
             <api name="general"/>
127
             <api name="general"/>
113
             <summary>Removed includeComments parameter from Queries.getMethodSpan</summary>
128
             <summary>Removed includeComments parameter from Queries.getMethodSpan</summary>
(-)a/java.source.queries/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.java.source.queries
2
OpenIDE-Module: org.netbeans.modules.java.source.queries
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/queries/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/queries/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.2
4
OpenIDE-Module-Specification-Version: 1.3
5
OpenIDE-Module-Needs: org.netbeans.modules.java.source.queries.spi.QueriesController
5
OpenIDE-Module-Needs: org.netbeans.modules.java.source.queries.spi.QueriesController
6
Netigso-Export-Package: org.netbeans.modules.java.source.queries.api,org.netbeans.modules.java.source.queries.spi
6
Netigso-Export-Package: org.netbeans.modules.java.source.queries.api,org.netbeans.modules.java.source.queries.spi
(-)a/java.source.queries/nbproject/project.xml (+8 lines)
Lines 15-20 Link Here
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
18
                    <code-name-base>org.openide.dialogs</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>7.23</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
18
                    <code-name-base>org.openide.util</code-name-base>
26
                    <code-name-base>org.openide.util</code-name-base>
19
                    <build-prerequisite/>
27
                    <build-prerequisite/>
20
                    <compile-dependency/>
28
                    <compile-dependency/>
(-)a/java.source.queries/src/org/netbeans/modules/java/source/queries/api/TemplateWizardFactory.java (+84 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 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 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.queries.api;
43
44
import org.netbeans.modules.java.source.queries.spi.TemplateWizardProvider;
45
import org.openide.WizardDescriptor;
46
import org.openide.util.Lookup;
47
48
/**
49
 *
50
 * @author jhorvath
51
 */
52
public class TemplateWizardFactory {
53
    static TemplateWizardProvider provider = null;
54
    
55
    private TemplateWizardFactory () {
56
    }
57
    
58
    /**
59
     * Returns an {@link WizardDescriptor.InstantiatingIterator} for template wizard
60
     * @return an {@link WizardDescriptor.InstantiatingIterator} 
61
     */
62
    public static WizardDescriptor.InstantiatingIterator<WizardDescriptor> create() {
63
        return getProvider().createWizard();
64
    }
65
    
66
    /**
67
     * Returns an {@link WizardDescriptor.InstantiatingIterator} for template wizard,
68
     * with editable superclass
69
     * @return an {@link WizardDescriptor.InstantiatingIterator} 
70
     */
71
    public static WizardDescriptor.InstantiatingIterator<WizardDescriptor> createForSuperClass() {
72
        return getProvider().createWizardForSuperClass();
73
    }
74
    
75
    private static TemplateWizardProvider getProvider() {
76
        if (provider == null) {
77
            provider = Lookup.getDefault().lookup(TemplateWizardProvider.class);
78
            if (provider == null) {
79
                throw new IllegalStateException("No TemplateWizardProvider found in the Lookup");    //NOI18N
80
            }
81
        }
82
        return provider;
83
    }
84
}
(-)a/java.source.queries/src/org/netbeans/modules/java/source/queries/spi/TemplateWizardProvider.java (+65 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 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 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.queries.spi;
43
44
import org.openide.WizardDescriptor;
45
46
/**
47
 *
48
 * @author jhorvath
49
 */
50
public interface TemplateWizardProvider {
51
    
52
    /**
53
     * Returns an {@link WizardDescriptor.InstantiatingIterator} for template wizard
54
     * @return an {@link WizardDescriptor.InstantiatingIterator} 
55
     */
56
    public WizardDescriptor.InstantiatingIterator<WizardDescriptor> createWizard();
57
    
58
    /**
59
     * Returns an {@link WizardDescriptor.InstantiatingIterator} for template wizard,
60
     * with editable superclass
61
     * @return an {@link WizardDescriptor.InstantiatingIterator} 
62
     */
63
    public WizardDescriptor.InstantiatingIterator<WizardDescriptor> createWizardForSuperClass();
64
    
65
}
(-)a/java.source.queriesimpl/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.java.source.queriesimpl
2
OpenIDE-Module: org.netbeans.modules.java.source.queriesimpl
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/queriesimpl/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/queriesimpl/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.1
4
OpenIDE-Module-Specification-Version: 1.2
5
OpenIDE-Module-Provides: org.netbeans.modules.java.source.queries.spi.QueriesController
5
OpenIDE-Module-Provides: org.netbeans.modules.java.source.queries.spi.QueriesController
6
6
(-)a/java.source.queriesimpl/nbproject/project.xml (-3 / +44 lines)
Lines 6-11 Link Here
6
            <code-name-base>org.netbeans.modules.java.source.queriesimpl</code-name-base>
6
            <code-name-base>org.netbeans.modules.java.source.queriesimpl</code-name-base>
7
            <module-dependencies>
7
            <module-dependencies>
8
                <dependency>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.10</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
9
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
18
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
10
                    <build-prerequisite/>
19
                    <build-prerequisite/>
11
                    <compile-dependency/>
20
                    <compile-dependency/>
Lines 14-25 Link Here
14
                    </run-dependency>
23
                    </run-dependency>
15
                </dependency>
24
                </dependency>
16
                <dependency>
25
                <dependency>
17
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
26
                    <code-name-base>org.netbeans.modules.java.project</code-name-base>
18
                    <build-prerequisite/>
27
                    <build-prerequisite/>
19
                    <compile-dependency/>
28
                    <compile-dependency/>
20
                    <run-dependency>
29
                    <run-dependency>
21
                        <release-version>1</release-version>
30
                        <release-version>1</release-version>
22
                        <specification-version>1.10</specification-version>
31
                        <specification-version>1.42</specification-version>
23
                    </run-dependency>
32
                    </run-dependency>
24
                </dependency>
33
                </dependency>
25
                <dependency>
34
                <dependency>
Lines 35-41 Link Here
35
                    <build-prerequisite/>
44
                    <build-prerequisite/>
36
                    <compile-dependency/>
45
                    <compile-dependency/>
37
                    <run-dependency>
46
                    <run-dependency>
38
                        <specification-version>1.0</specification-version>
47
                        <specification-version>1.3</specification-version>
39
                    </run-dependency>
48
                    </run-dependency>
40
                </dependency>
49
                </dependency>
41
                <dependency>
50
                <dependency>
Lines 48-53 Link Here
48
                    </run-dependency>
57
                    </run-dependency>
49
                </dependency>
58
                </dependency>
50
                <dependency>
59
                <dependency>
60
                    <code-name-base>org.openide.dialogs</code-name-base>
61
                    <build-prerequisite/>
62
                    <compile-dependency/>
63
                    <run-dependency>
64
                        <specification-version>7.23</specification-version>
65
                    </run-dependency>
66
                </dependency>
67
                <dependency>
51
                    <code-name-base>org.openide.filesystems</code-name-base>
68
                    <code-name-base>org.openide.filesystems</code-name-base>
52
                    <build-prerequisite/>
69
                    <build-prerequisite/>
53
                    <compile-dependency/>
70
                    <compile-dependency/>
Lines 56-61 Link Here
56
                    </run-dependency>
73
                    </run-dependency>
57
                </dependency>
74
                </dependency>
58
                <dependency>
75
                <dependency>
76
                    <code-name-base>org.openide.loaders</code-name-base>
77
                    <build-prerequisite/>
78
                    <compile-dependency/>
79
                    <run-dependency>
80
                        <specification-version>7.32</specification-version>
81
                    </run-dependency>
82
                </dependency>
83
                <dependency>
84
                    <code-name-base>org.openide.nodes</code-name-base>
85
                    <build-prerequisite/>
86
                    <compile-dependency/>
87
                    <run-dependency>
88
                        <specification-version>7.25</specification-version>
89
                    </run-dependency>
90
                </dependency>
91
                <dependency>
92
                    <code-name-base>org.openide.util</code-name-base>
93
                    <build-prerequisite/>
94
                    <compile-dependency/>
95
                    <run-dependency>
96
                        <specification-version>8.18</specification-version>
97
                    </run-dependency>
98
                </dependency>
99
                <dependency>
59
                    <code-name-base>org.openide.util.lookup</code-name-base>
100
                    <code-name-base>org.openide.util.lookup</code-name-base>
60
                    <build-prerequisite/>
101
                    <build-prerequisite/>
61
                    <compile-dependency/>
102
                    <compile-dependency/>
(-)a/java.source.queriesimpl/src/org/netbeans/modules/java/source/queriesimpl/Bundle.properties (+6 lines)
Lines 1-2 Link Here
1
OpenIDE-Module-Display-Category=Java
1
OpenIDE-Module-Display-Category=Java
2
OpenIDE-Module-Name=Java Source Queries Implementation
2
OpenIDE-Module-Name=Java Source Queries Implementation
3
4
CTL_SuperclassTitle=Form Superclass
5
CTL_SuperclassName=Superclass:
6
CTL_SuperclassName_Hint=Fully qualified name of the superclass of the new form
7
ACSD_SuperclassPanel=N/A
8
ACSD_SuperclassTextField=N/A
(-)a/java.source.queriesimpl/src/org/netbeans/modules/java/source/queriesimpl/NbTemplateWizardProviderImpl.java (+66 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 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 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.queriesimpl;
43
44
import org.netbeans.modules.java.source.queries.spi.TemplateWizardProvider;
45
import org.openide.WizardDescriptor;
46
import org.openide.util.lookup.ServiceProvider;
47
48
/**
49
 *
50
 * @author jhorvath
51
 */
52
@ServiceProvider(service=TemplateWizardProvider.class, position=200)
53
public class NbTemplateWizardProviderImpl implements TemplateWizardProvider {
54
55
    
56
    @Override
57
    public WizardDescriptor.InstantiatingIterator createWizard() {
58
        return TemplateWizardIterator.create();
59
    }
60
61
    @Override
62
    public WizardDescriptor.InstantiatingIterator createWizardForSuperClass() {
63
        return TemplateWizardIterator.createForSuperclass();
64
    }
65
    
66
}
(-)a/java.source.queriesimpl/src/org/netbeans/modules/java/source/queriesimpl/TemplateWizardIterator.java (+345 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.java.source.queriesimpl;
46
47
import com.sun.source.tree.ClassTree;
48
import com.sun.source.tree.ExpressionTree;
49
import com.sun.source.tree.Tree;
50
import java.awt.Component;
51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.Insets;
54
import java.awt.event.FocusAdapter;
55
import java.io.IOException;
56
import java.util.NoSuchElementException;
57
import java.util.ResourceBundle;
58
import java.util.Set;
59
import java.util.logging.Level;
60
import java.util.logging.LogRecord;
61
import java.util.logging.Logger;
62
import javax.lang.model.element.TypeElement;
63
import javax.swing.JComponent;
64
import javax.swing.JLabel;
65
import javax.swing.JTextField;
66
import javax.swing.event.ChangeListener;
67
import org.netbeans.api.java.source.CancellableTask;
68
import org.netbeans.api.java.source.JavaSource;
69
import org.netbeans.api.java.source.TreeMaker;
70
import org.netbeans.api.java.source.TreeUtilities;
71
import org.netbeans.api.java.source.WorkingCopy;
72
import org.netbeans.modules.java.source.queries.spi.TemplateWizardProvider;
73
import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
74
import org.openide.WizardDescriptor;
75
import org.openide.filesystems.FileObject;
76
import org.openide.loaders.TemplateWizard;
77
import org.openide.util.NbBundle;
78
import org.openide.util.lookup.ServiceProvider;
79
80
/**
81
 * Special template wizard iterator for BeanForm template - requires to
82
 * specify superclass additionally.
83
 *
84
 * @author Tomas Pavek, Jan Stola
85
 */
86
87
public class TemplateWizardIterator implements WizardDescriptor.InstantiatingIterator {
88
    private transient WizardDescriptor wiz;
89
    private transient WizardDescriptor.Panel superclassPanel;
90
    private transient boolean superclassPanelCurrent;
91
    private transient WizardDescriptor.InstantiatingIterator delegateIterator;
92
93
    private boolean specifySuperclass;
94
95
    public static TemplateWizardIterator createForSuperclass() {
96
        return new TemplateWizardIterator(true);
97
    }
98
99
    public static TemplateWizardIterator create() {
100
        return new TemplateWizardIterator(false);
101
    }
102
103
    public TemplateWizardIterator(boolean specifySuperclass) {
104
        delegateIterator = JavaTemplates.createJavaTemplateIterator();
105
        this.specifySuperclass = specifySuperclass;
106
    }
107
108
    @Override
109
    public void initialize(WizardDescriptor wizard) {
110
        wiz = wizard;
111
        delegateIterator.initialize(wizard);
112
        superclassPanelCurrent = false;
113
        if (superclassPanel == null && specifySuperclass) {
114
            superclassPanel = new SuperclassWizardPanel();
115
            
116
            ResourceBundle bundle = NbBundle.getBundle(TemplateWizardIterator.class);
117
            JComponent comp = (JComponent)delegateIterator.current().getComponent();
118
            String[] contentData = (String[])comp.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
119
            String[] newContentData = new String[contentData.length+1];
120
            System.arraycopy(contentData, 0, newContentData, 0, contentData.length);
121
            newContentData[contentData.length] = bundle.getString("CTL_SuperclassTitle"); // NOI18N
122
            comp.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, newContentData); // NOI18N
123
        }    
124
    }
125
126
    @Override
127
    public void uninitialize(WizardDescriptor wizard) {
128
        delegateIterator.uninitialize(wizard);
129
        superclassPanel = null;
130
    }
131
132
    @Override
133
    public Set instantiate() throws IOException, IllegalArgumentException {
134
        Set set = delegateIterator.instantiate();
135
        FileObject template = (FileObject) set.iterator().next();
136
        if (wiz instanceof TemplateWizard) {
137
            Logger logger = Logger.getLogger("org.netbeans.ui.metrics.form"); // NOI18N
138
            LogRecord rec = new LogRecord(Level.INFO, "USG_FORM_CREATED"); // NOI18N
139
            rec.setLoggerName(logger.getName());
140
            rec.setParameters(new Object[] { ((TemplateWizard)wiz).getTemplate().getName() });
141
            logger.log(rec);
142
        }
143
144
        if (specifySuperclass) {
145
            final String className = template.getName();
146
            final String superclassName = 
147
                    ((SuperclassWizardPanel) superclassPanel).getSuperclassName();           
148
            JavaSource js = JavaSource.forFileObject(template);
149
            js.runModificationTask(new CancellableTask<WorkingCopy>() {
150
                @Override
151
                public void cancel() {
152
                }
153
                @Override
154
                public void run(WorkingCopy wcopy) throws Exception {
155
                    wcopy.toPhase(JavaSource.Phase.RESOLVED);
156
   
157
                    for (Tree t: wcopy.getCompilationUnit().getTypeDecls()) {
158
                        if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind()) && className.equals(((ClassTree) t).getSimpleName().toString())) {
159
                            ClassTree orig = (ClassTree) t;
160
                            TreeMaker maker = wcopy.getTreeMaker();
161
                            TypeElement superclassElm = wcopy.getElements().getTypeElement(superclassName);
162
                            ExpressionTree extendsTree = superclassElm != null
163
                                ? maker.QualIdent(superclassElm)
164
                                : maker.Identifier(superclassName);
165
                            ClassTree copy = maker.Class(
166
                                orig.getModifiers(),
167
                                orig.getSimpleName(),
168
                                orig.getTypeParameters(),
169
                                extendsTree,
170
                                orig.getImplementsClause(),
171
                                orig.getMembers());
172
                            wcopy.rewrite(orig, copy);
173
                            break;
174
                        }
175
                    }
176
                }
177
            }).commit();
178
        }
179
180
        template.setAttribute("justCreatedByNewWizard", Boolean.TRUE); // NOI18N
181
        
182
        return set;
183
    }
184
185
    @Override
186
    public WizardDescriptor.Panel current() {
187
        return superclassPanelCurrent ? superclassPanel : delegateIterator.current();
188
    }
189
190
    @Override
191
    public boolean hasNext() {
192
        return delegateIterator.hasNext() || (!superclassPanelCurrent && superclassPanel != null);
193
    }
194
    
195
    @Override
196
    public boolean hasPrevious() {
197
        return superclassPanelCurrent ? true : delegateIterator.hasPrevious();
198
    }
199
    
200
    @Override
201
    public void nextPanel() {
202
        if (delegateIterator.hasNext()) {
203
            delegateIterator.nextPanel();
204
        } else {
205
            if (superclassPanelCurrent || superclassPanel == null) {
206
                throw new NoSuchElementException();
207
            } else {
208
                superclassPanelCurrent = true;
209
            }
210
        }
211
    }
212
    
213
    @Override
214
    public void previousPanel() {
215
        if (superclassPanelCurrent) {
216
            superclassPanelCurrent = false;
217
        } else {
218
            delegateIterator.previousPanel();
219
        }
220
    }
221
    
222
    @Override
223
    public void addChangeListener(ChangeListener l) {
224
        delegateIterator.addChangeListener(l);
225
    }
226
    
227
    @Override
228
    public String name() {
229
        return superclassPanelCurrent ? "" : delegateIterator.name(); // NOI18N
230
    }
231
    
232
    @Override
233
    public void removeChangeListener(ChangeListener l) {
234
        delegateIterator.removeChangeListener(l);
235
    }
236
237
    // ---------
238
239
    static class SuperclassWizardPanel implements WizardDescriptor.FinishablePanel {
240
241
        private SuperclassPanel panelUI;
242
243
        String getSuperclassName() {
244
            String name = panelUI != null ?
245
                          panelUI.superclassTextField.getText() : null;
246
            return name != null && !"".equals(name) ? name : "java.lang.Object"; // NOI18N
247
        }
248
249
        @Override
250
        public Component getComponent() {
251
            if (panelUI == null)
252
                panelUI = new SuperclassPanel();
253
            return panelUI;
254
        }
255
256
        @Override
257
        public boolean isValid() {
258
            return true;
259
        }
260
261
        @Override
262
        public void readSettings(Object settings) {
263
        }
264
265
        @Override
266
        public void storeSettings(Object settings) {
267
        }
268
269
        @Override
270
        public void addChangeListener(ChangeListener l) {
271
        }
272
273
        @Override
274
        public void removeChangeListener(ChangeListener l) {
275
        }
276
277
        @Override
278
        public org.openide.util.HelpCtx getHelp () {
279
            return new org.openide.util.HelpCtx("gui.creatingforms"); // NOI18N
280
        }
281
        
282
        @Override
283
        public boolean isFinishPanel() {
284
            return true;
285
        }
286
        
287
    }
288
289
    // -------
290
291
    static class SuperclassPanel extends javax.swing.JPanel {
292
293
        SuperclassPanel() {
294
            ResourceBundle bundle = NbBundle.getBundle(TemplateWizardIterator.class);
295
            setName(bundle.getString("CTL_SuperclassTitle")); // NOI18N
296
            putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(1)); //NOI18N
297
            getAccessibleContext()
298
                .setAccessibleDescription(bundle.getString("ACSD_SuperclassPanel")); // NOI18N
299
300
            setLayout(new GridBagLayout());
301
            setBorder(new javax.swing.border.EmptyBorder(8, 8, 8, 8));
302
303
            label1 = new JLabel();
304
            superclassTextField = new JTextField();
305
306
            label1.setLabelFor(superclassTextField);
307
            label1.setText(bundle.getString("CTL_SuperclassName")); // NOI18N
308
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
309
            gridBagConstraints.gridx = 0;
310
            gridBagConstraints.gridy = 0;
311
            gridBagConstraints.anchor = GridBagConstraints.WEST;
312
            gridBagConstraints.insets = new Insets(0, 0, 0, 12);
313
            add(label1, gridBagConstraints);
314
315
            superclassTextField.setText("java.lang.Object"); // NOI18N
316
            superclassTextField.setToolTipText(bundle.getString("CTL_SuperclassName_Hint")); // NOI18N
317
            superclassTextField.getAccessibleContext()
318
                .setAccessibleDescription(bundle.getString("ACSD_SuperclassTextField"));  // NOI18N
319
            superclassTextField.addFocusListener(new FocusAdapter() {
320
                @Override
321
                public void focusGained(java.awt.event.FocusEvent evt) {
322
                    superclassTextField.selectAll();
323
                }
324
            });
325
326
            gridBagConstraints = new GridBagConstraints();
327
            gridBagConstraints.gridx = 1;
328
            gridBagConstraints.gridy = 0;
329
            gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
330
            gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
331
            gridBagConstraints.weightx = 1.0;
332
            gridBagConstraints.weighty = 1.0;
333
            add(superclassTextField, gridBagConstraints);
334
        }
335
336
        @Override
337
        public void addNotify() {
338
            super.addNotify();
339
            superclassTextField.requestFocus();
340
        }
341
342
        private JLabel label1;
343
        private JTextField superclassTextField;
344
    }
345
}

Return to bug 184168