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

(-)a/beans/nbproject/project.xml (+9 lines)
Lines 106-111 Link Here
106
                    <run-dependency>
106
                    <run-dependency>
107
                        <release-version>2</release-version>
107
                        <release-version>2</release-version>
108
                        <specification-version>1.7</specification-version>
108
                        <specification-version>1.7</specification-version>
109
                    </run-dependency>
110
                </dependency>
111
                <dependency>
112
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
113
                    <build-prerequisite/>
114
                    <compile-dependency/>
115
                    <run-dependency>
116
                        <release-version>1</release-version>
117
                        <specification-version>1.8</specification-version>
109
                    </run-dependency>
118
                    </run-dependency>
110
                </dependency>
119
                </dependency>
111
                <dependency>
120
                <dependency>
(-)a/beans/src/org/netbeans/modules/beans/addproperty/AddPropertyCodeGenerator.java (-6 / +12 lines)
Lines 64-69 Link Here
64
import org.netbeans.api.java.source.JavaSource.Phase;
64
import org.netbeans.api.java.source.JavaSource.Phase;
65
import org.netbeans.api.java.source.Task;
65
import org.netbeans.api.java.source.Task;
66
import org.netbeans.api.java.source.WorkingCopy;
66
import org.netbeans.api.java.source.WorkingCopy;
67
import org.netbeans.spi.editor.codegen.CodeGenerator;
67
import org.openide.DialogDisplayer;
68
import org.openide.DialogDisplayer;
68
import org.openide.filesystems.FileObject;
69
import org.openide.filesystems.FileObject;
69
import org.openide.util.Exceptions;
70
import org.openide.util.Exceptions;
Lines 72-81 Link Here
72
import javax.swing.text.StyledDocument;
73
import javax.swing.text.StyledDocument;
73
import org.netbeans.api.java.source.CompilationInfo;
74
import org.netbeans.api.java.source.CompilationInfo;
74
import org.netbeans.modules.editor.indent.api.Reformat;
75
import org.netbeans.modules.editor.indent.api.Reformat;
75
import org.netbeans.modules.java.editor.codegen.CodeGenerator;
76
import org.openide.DialogDescriptor;
76
import org.openide.DialogDescriptor;
77
import org.openide.loaders.DataObject;
77
import org.openide.loaders.DataObject;
78
import org.openide.text.NbDocument;
78
import org.openide.text.NbDocument;
79
import org.openide.util.Lookup;
79
import org.openide.util.NbBundle;
80
import org.openide.util.NbBundle;
80
81
81
/**
82
/**
Lines 84-95 Link Here
84
 */
85
 */
85
public class AddPropertyCodeGenerator implements CodeGenerator {
86
public class AddPropertyCodeGenerator implements CodeGenerator {
86
87
88
    private JTextComponent component;
87
    private String className;
89
    private String className;
88
    private List<String> existingFields;
90
    private List<String> existingFields;
89
    private String[] pcsName;
91
    private String[] pcsName;
90
    private String[] vcsName;
92
    private String[] vcsName;
91
93
92
    public AddPropertyCodeGenerator(String className, List<String> existingFields, String[] pcsName, String[] vcsName) {
94
    public AddPropertyCodeGenerator(JTextComponent component, String className, List<String> existingFields, String[] pcsName, String[] vcsName) {
95
        this.component = component;
93
        this.className = className;
96
        this.className = className;
94
        this.existingFields = existingFields;
97
        this.existingFields = existingFields;
95
        this.pcsName = pcsName;
98
        this.pcsName = pcsName;
Lines 100-106 Link Here
100
        return NbBundle.getMessage(AddPropertyCodeGenerator.class, "DN_AddProperty");
103
        return NbBundle.getMessage(AddPropertyCodeGenerator.class, "DN_AddProperty");
101
    }
104
    }
102
105
103
    public void invoke(JTextComponent component) {
106
    public void invoke() {
104
        Object o = component.getDocument().getProperty(Document.StreamDescriptionProperty);
107
        Object o = component.getDocument().getProperty(Document.StreamDescriptionProperty);
105
108
106
        if (o instanceof DataObject) {
109
        if (o instanceof DataObject) {
Lines 207-218 Link Here
207
210
208
    public static final class Factory implements CodeGenerator.Factory {
211
    public static final class Factory implements CodeGenerator.Factory {
209
212
210
        public Iterable<? extends CodeGenerator> create(CompilationController cc, TreePath path) throws IOException {
213
        public List<? extends CodeGenerator> create(Lookup context) {
214
            JTextComponent component = context.lookup(JTextComponent.class);
215
            CompilationController cc = context.lookup(CompilationController.class);
216
            TreePath path = context.lookup(TreePath.class);
211
            while (path != null && path.getLeaf().getKind() != Kind.CLASS) {
217
            while (path != null && path.getLeaf().getKind() != Kind.CLASS) {
212
                path = path.getParentPath();
218
                path = path.getParentPath();
213
            }
219
            }
214
220
215
            if (path == null) {
221
            if (component == null || cc == null || path == null) {
216
                return Collections.emptyList();
222
                return Collections.emptyList();
217
            }
223
            }
218
            
224
            
Lines 253-259 Link Here
253
            
259
            
254
            String className = ((TypeElement) e).getQualifiedName().toString();
260
            String className = ((TypeElement) e).getQualifiedName().toString();
255
            
261
            
256
            return Collections.singleton(new AddPropertyCodeGenerator( className, existingFields, pcsName,vcsName));
262
            return Collections.singletonList(new AddPropertyCodeGenerator(component, className, existingFields, pcsName,vcsName));
257
        }
263
        }
258
        
264
        
259
        private static TypeMirror resolve(CompilationInfo info, String s) {
265
        private static TypeMirror resolve(CompilationInfo info, String s) {
(-)a/beans/src/org/netbeans/modules/beans/resources/mf-layer.xml (-1 / +1 lines)
Lines 141-147 Link Here
141
    <folder name="Editors">
141
    <folder name="Editors">
142
        <folder name="text">
142
        <folder name="text">
143
            <folder name="x-java">
143
            <folder name="x-java">
144
                <folder name="codegenerators">
144
                <folder name="CodeGenerators">
145
                    <file name="org-netbeans-modules-beans-addproperty-AddPropertyCodeGenerator$Factory.instance">
145
                    <file name="org-netbeans-modules-beans-addproperty-AddPropertyCodeGenerator$Factory.instance">
146
                        <attr name="position" intvalue="600"/>
146
                        <attr name="position" intvalue="600"/>
147
                    </file>
147
                    </file>
(-)a/editor.lib2/apichanges.xml (+18 lines)
Lines 105-110 Link Here
105
105
106
    <changes>
106
    <changes>
107
107
108
        <change id="added-codegen-spi">
109
            <summary>Code Generation SPI added</summary>
110
            <version major="1" minor="8"/>
111
            <date day="30" month="4" year="20087"/>
112
            <author login="dbalek"/>
113
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
114
            <description>
115
                The Code Generation SPI consists of two interfaces.
116
                The <code>CodeGenerator</code> implementations registered for
117
                various mime types serve for creating code snippets and inserting
118
                them into documents on the Insert Code editor action invocation.
119
                The <code>CodeGeneratorContextProvider</code> implementations
120
                registered for the mime types could provide the respective
121
                CodeGenerators with an additional context information. 
122
            </description>
123
            <issue number="134239"/>
124
        </change>
125
108
        <change id="added-HighlightAttributeValue">
126
        <change id="added-HighlightAttributeValue">
109
            <summary>HighlightAttributeValue interface added</summary>
127
            <summary>HighlightAttributeValue interface added</summary>
110
            <version major="1" minor="5"/>
128
            <version major="1" minor="5"/>
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 40-46 Link Here
40
is.autoload=true
40
is.autoload=true
41
javac.source=1.5
41
javac.source=1.5
42
javac.compilerargs=-Xlint:unchecked
42
javac.compilerargs=-Xlint:unchecked
43
spec.version.base=1.7.0
43
spec.version.base=1.8.0
44
44
45
javadoc.arch=${basedir}/arch.xml
45
javadoc.arch=${basedir}/arch.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.lib2/nbproject/project.xml (+1 lines)
Lines 143-148 Link Here
143
            </test-dependencies>
143
            </test-dependencies>
144
            <public-packages>
144
            <public-packages>
145
                <package>org.netbeans.api.editor</package>
145
                <package>org.netbeans.api.editor</package>
146
                <package>org.netbeans.spi.editor.codegen</package>
146
                <package>org.netbeans.spi.editor.highlighting</package>
147
                <package>org.netbeans.spi.editor.highlighting</package>
147
                <package>org.netbeans.spi.editor.highlighting.support</package>
148
                <package>org.netbeans.spi.editor.highlighting.support</package>
148
            </public-packages>
149
            </public-packages>
(-)9387523afe84 (+2 lines)
Added Link Here
1
 org.netbeans.modules.editor.lib2.codegen.GeneratorFactoryClass2LayerFolder
2
 org.netbeans.modules.editor.lib2.codegen.ContextProviderClass2LayerFolder
(-)9387523afe84 (+67 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.editor.lib2.codegen;
42
43
44
import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
45
import org.netbeans.spi.editor.mimelookup.Class2LayerFolder;
46
import org.netbeans.spi.editor.mimelookup.InstanceProvider;
47
48
/**
49
 *
50
 *
51
 * @author Dusan Balek
52
 */
53
public class ContextProviderClass2LayerFolder implements Class2LayerFolder<CodeGeneratorContextProvider> {
54
55
    public Class<CodeGeneratorContextProvider> getClazz() {
56
        return CodeGeneratorContextProvider.class;
57
    }
58
59
    public String getLayerFolderName() {
60
        return "CodeGeneratorContextProviders"; //NOI18N
61
    }
62
63
    public InstanceProvider<CodeGeneratorContextProvider> getInstanceProvider() {
64
        return null;
65
    }
66
67
}
(-)9387523afe84 (+64 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.codegen;
41
42
import org.netbeans.spi.editor.codegen.CodeGenerator.Factory;
43
import org.netbeans.spi.editor.mimelookup.Class2LayerFolder;
44
import org.netbeans.spi.editor.mimelookup.InstanceProvider;
45
46
/**
47
 *
48
 * @author Jan Lahoda
49
 */
50
public class GeneratorFactoryClass2LayerFolder implements Class2LayerFolder<Factory> {
51
52
    public Class<Factory> getClazz() {
53
        return Factory.class;
54
    }
55
56
    public String getLayerFolderName() {
57
        return "CodeGenerators"; //NOI18N
58
    }
59
60
    public InstanceProvider<Factory> getInstanceProvider() {
61
        return null;
62
    }
63
64
}
(-)9387523afe84 (+92 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.spi.editor.codegen;
43
44
import java.util.List;
45
import org.openide.util.Lookup;
46
47
/**
48
 * Interface to be implemented by all generators inserting their code snippets 
49
 * into documents using the Insert Code editor action.
50
 *
51
 * @author Dusan Balek
52
 * @since 1.8
53
 */
54
public interface CodeGenerator {
55
56
    /**
57
     * Gets the generator's name to be displayed in the popup that appears on
58
     * the Insert Code action invocation.
59
     * @return non-null name
60
     * @since 1.8
61
     */
62
    public String getDisplayName();
63
64
    /**
65
     * Invokes the generator to create the code snippet and insert it into a
66
     * document.
67
     * @since 1.8
68
     */
69
    public void invoke();
70
    
71
    /**
72
     * Factory creating code generators.<br/> The factory instances are looked up
73
     * by the {@link org.netbeans.api.editor.mimelookup.MimeLookup} so they
74
     * should be registered in an xml-layer in
75
     * <i>Editors/&lt;mime-type&gt;/CodeGenerators</i> directory.
76
     * @since 1.8
77
     */
78
    public interface Factory {
79
        
80
        /**
81
         * Creates code generators valid for the particular context.
82
         * @param context Contains an instance of
83
         * {@link javax.swing.text.JTextComponent} by default. Additonal content
84
         * could be added by the {@link CodeGeneratorContextProvider} registered
85
         * for the mime type.
86
         * @return the list of created code generators. An empty list should be
87
         * returned if no generator could be created in the particular context.
88
         * @since 1.8
89
         */
90
        public List<? extends CodeGenerator> create(Lookup context);
91
    }
92
}
(-)9387523afe84 (+81 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.editor.codegen;
41
42
import org.openide.util.Lookup;
43
44
/**
45
 * Serves for adding an additonal content to the context which is passed
46
 * as a parameter to the {@link CodeGeneratorFactory#create()} method.<br/> 
47
 * Instances of this interface are looked up by the
48
 * {@link org.netbeans.api.editor.mimelookup.MimeLookup} so they should be
49
 * registered in an xml-layer in
50
 * <i>Editors/&lt;mime-type&gt;/CodeGeneratorContextProviders</i> directory.
51
 *
52
 * @author Dusan Balek
53
 * @since 1.8
54
 */
55
public interface CodeGeneratorContextProvider {
56
57
    /**
58
     * Adds an additional content to the original context and runs the given task
59
     * with the new context as a parameter.
60
     * @param context the original context
61
     * @param task the task to be run
62
     * @since 1.8
63
     */
64
    public void runTaskWithinContext(Lookup context, Task task);
65
    
66
    /**
67
     * Represents the task passed to the {@link #runTaskInContext()} method.
68
     * It is supposed to be implemented by the infrastructure implementor
69
     * (not by the SPI clients).
70
     * @since 1.8
71
     */
72
    public interface Task {
73
        
74
        /**
75
         * Runs the task.
76
         * @param context the task's context
77
         * @since 1.8
78
         */
79
        public void run(Lookup context);
80
    }
81
}
(-)a/editor/src/org/netbeans/modules/editor/NbEditorKit.java (+2 lines)
Lines 83-88 Link Here
83
import org.netbeans.editor.Settings;
83
import org.netbeans.editor.Settings;
84
import org.netbeans.editor.SettingsNames;
84
import org.netbeans.editor.SettingsNames;
85
import org.netbeans.editor.ext.ExtSettingsNames;
85
import org.netbeans.editor.ext.ExtSettingsNames;
86
import org.netbeans.modules.editor.codegen.NbGenerateCodeAction;
86
import org.netbeans.modules.editor.impl.ActionsList;
87
import org.netbeans.modules.editor.impl.ActionsList;
87
import org.netbeans.modules.editor.impl.CustomizableSideBar;
88
import org.netbeans.modules.editor.impl.CustomizableSideBar;
88
import org.netbeans.modules.editor.impl.SearchBar;
89
import org.netbeans.modules.editor.impl.SearchBar;
Lines 191-196 Link Here
191
                                       new ToggleToolbarAction(),
192
                                       new ToggleToolbarAction(),
192
                                       new NbGenerateGoToPopupAction(),
193
                                       new NbGenerateGoToPopupAction(),
193
                                       new GenerateFoldPopupAction(),
194
                                       new GenerateFoldPopupAction(),
195
                                       new NbGenerateCodeAction(),
194
                                       new NavigationHistoryLastEditAction(),
196
                                       new NavigationHistoryLastEditAction(),
195
                                       new NavigationHistoryBackAction(),
197
                                       new NavigationHistoryBackAction(),
196
                                       new NavigationHistoryForwardAction(),
198
                                       new NavigationHistoryForwardAction(),
(-)9387523afe84 (+44 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# Contributor(s):
24
#
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
28
#
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
39
40
generate-code-trimmed=Insert Code
41
desc-generate-code=Insert Code
42
popup-generate-code=Insert Code...
43
generate-code-main-menu-source-item=&Insert Code...
44
LBL_generate_code=Generate
(-)9387523afe84 (+72 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.4" maxVersion="1.4" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
6
      <Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
7
        <LineBorder>
8
          <Color PropertyName="color" blue="40" green="40" red="40" type="rgb"/>
9
        </LineBorder>
10
      </Border>
11
    </Property>
12
  </Properties>
13
  <AuxValues>
14
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
15
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
16
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
17
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
18
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
19
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
20
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="1"/>
21
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
22
  </AuxValues>
23
24
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
25
  <SubComponents>
26
    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
27
      <Properties>
28
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
29
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
30
            <EmptyBorder bottom="4" left="4" right="4" top="2"/>
31
          </Border>
32
        </Property>
33
      </Properties>
34
      <AuxValues>
35
        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
36
      </AuxValues>
37
      <Constraints>
38
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
39
          <BorderConstraints direction="Center"/>
40
        </Constraint>
41
      </Constraints>
42
43
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
44
      <SubComponents>
45
        <Component class="javax.swing.JList" name="jList1">
46
          <Events>
47
            <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="listKeyReleased"/>
48
            <EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseReleased"/>
49
          </Events>
50
        </Component>
51
      </SubComponents>
52
    </Container>
53
    <Component class="javax.swing.JLabel" name="jLabel1">
54
      <Properties>
55
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
56
          <ResourceString bundle="org/netbeans/modules/editor/codegen/Bundle.properties" key="LBL_generate_code" replaceFormat="org.openide.util.NbBundle.getMessage(GenerateCodePanel.class, &quot;{key}&quot;)"/>
57
        </Property>
58
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
59
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
60
            <EmptyBorder bottom="4" left="4" right="4" top="4"/>
61
          </Border>
62
        </Property>
63
        <Property name="opaque" type="boolean" value="true"/>
64
      </Properties>
65
      <Constraints>
66
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
67
          <BorderConstraints direction="First"/>
68
        </Constraint>
69
      </Constraints>
70
    </Component>
71
  </SubComponents>
72
</Form>
(-)9387523afe84 (+186 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.editor.codegen;
43
44
import java.awt.Color;
45
import java.awt.Component;
46
import java.awt.event.KeyEvent;
47
import java.util.List;
48
import javax.swing.DefaultListCellRenderer;
49
import javax.swing.DefaultListModel;
50
import javax.swing.JList;
51
import javax.swing.KeyStroke;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.spi.editor.codegen.CodeGenerator;
54
import org.openide.util.Utilities;
55
56
/**
57
 *
58
 * @author Dusan Balek, Jan Lahoda
59
 */
60
public class GenerateCodePanel extends javax.swing.JPanel {
61
62
    private JTextComponent component;
63
    
64
    /** Creates new form GenerateCodePanel */
65
    public GenerateCodePanel(JTextComponent component, List<? extends CodeGenerator> generators) {
66
        this.component = component;
67
        initComponents();
68
        setFocusable(false);
69
        setNextFocusableComponent(jList1);
70
        setBackground(jList1.getBackground());
71
        jScrollPane1.setBackground(jList1.getBackground());
72
        jList1.setModel(createModel(generators));
73
        jList1.setSelectedIndex(0);
74
        jList1.setVisibleRowCount(generators.size() > 8 ? 8 : generators.size());
75
        jList1.setCellRenderer(new Renderer(jList1));
76
        jList1.grabFocus();
77
    }
78
    
79
    /** This method is called from within the constructor to
80
     * initialize the form.
81
     * WARNING: Do NOT modify this code. The content of this method is
82
     * always regenerated by the Form Editor.
83
     */
84
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
85
    private void initComponents() {
86
87
        jScrollPane1 = new javax.swing.JScrollPane();
88
        jList1 = new javax.swing.JList();
89
        jLabel1 = new javax.swing.JLabel();
90
91
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(64, 64, 64)));
92
        setLayout(new java.awt.BorderLayout());
93
94
        jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 4, 4, 4));
95
96
        jList1.addKeyListener(new java.awt.event.KeyAdapter() {
97
            public void keyReleased(java.awt.event.KeyEvent evt) {
98
                listKeyReleased(evt);
99
            }
100
        });
101
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
102
            public void mouseReleased(java.awt.event.MouseEvent evt) {
103
                listMouseReleased(evt);
104
            }
105
        });
106
        jScrollPane1.setViewportView(jList1);
107
108
        add(jScrollPane1, java.awt.BorderLayout.CENTER);
109
110
        jLabel1.setText(org.openide.util.NbBundle.getMessage(GenerateCodePanel.class, "LBL_generate_code")); // NOI18N
111
        jLabel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4));
112
        jLabel1.setOpaque(true);
113
        add(jLabel1, java.awt.BorderLayout.PAGE_START);
114
    }// </editor-fold>//GEN-END:initComponents
115
116
    private void listMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseReleased
117
        invokeSelected();
118
    }//GEN-LAST:event_listMouseReleased
119
120
    private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
121
        KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
122
        if (ks.getKeyCode() == KeyEvent.VK_ENTER || ks.getKeyCode() == KeyEvent.VK_SPACE)
123
            invokeSelected();
124
    }//GEN-LAST:event_listKeyReleased
125
    
126
    
127
    // Variables declaration - do not modify//GEN-BEGIN:variables
128
    public javax.swing.JLabel jLabel1;
129
    public javax.swing.JList jList1;
130
    public javax.swing.JScrollPane jScrollPane1;
131
    // End of variables declaration//GEN-END:variables
132
    
133
    private DefaultListModel createModel(List<? extends CodeGenerator> generators) {
134
        DefaultListModel model = new DefaultListModel();
135
        for (CodeGenerator generator : generators)
136
            model.addElement(generator);
137
        return model;
138
    }
139
    
140
    private void invokeSelected() {
141
        PopupUtil.hidePopup();
142
        if (Utilities.isMac()) {
143
            // see issue #115106
144
            component.requestFocus();
145
        }
146
        Object value = jList1.getSelectedValue();
147
        if (value instanceof CodeGenerator)
148
            ((CodeGenerator)value).invoke();
149
    }
150
            
151
    private static class Renderer extends DefaultListCellRenderer {
152
        
153
        private static int DARKER_COLOR_COMPONENT = 5;
154
        
155
        private Color fgColor;
156
        private Color bgColor;
157
        private Color bgColorDarker;
158
        private Color bgSelectionColor;
159
        private Color fgSelectionColor;
160
        
161
        public Renderer(JList list) {
162
            setFont(list.getFont());
163
            fgColor = list.getForeground();
164
            bgColor = list.getBackground();
165
            bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
166
                    Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
167
                    Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
168
            bgSelectionColor = list.getSelectionBackground();
169
            fgSelectionColor = list.getSelectionForeground();
170
        }
171
        
172
        @Override
173
        public Component getListCellRendererComponent(JList list, Object value, int index,
174
                boolean isSelected, boolean hasFocus) {
175
            if (isSelected) {
176
                setForeground(fgSelectionColor);
177
                setBackground(bgSelectionColor);
178
            } else {
179
                setForeground(fgColor);
180
                setBackground(index % 2 == 0 ? bgColor : bgColorDarker);
181
            }            
182
            setText(value instanceof CodeGenerator ? ((CodeGenerator)value).getDisplayName() : value.toString());
183
            return this;
184
        }        
185
    }
186
}
(-)9387523afe84 (+174 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.editor.codegen;
42
43
import javax.swing.text.AbstractDocument;
44
import javax.swing.text.Document;
45
import org.netbeans.api.editor.mimelookup.MimePath;
46
import org.netbeans.api.lexer.TokenHierarchy;
47
import org.netbeans.api.lexer.TokenSequence;
48
import org.netbeans.modules.editor.*;
49
import java.awt.Point;
50
import java.awt.Rectangle;
51
import java.awt.event.ActionEvent;
52
import java.util.ArrayList;
53
import java.util.Iterator;
54
import java.util.List;
55
import javax.swing.JMenuItem;
56
import javax.swing.SwingUtilities;
57
import javax.swing.text.BadLocationException;
58
import javax.swing.text.JTextComponent;
59
import org.netbeans.api.editor.mimelookup.MimeLookup;
60
import org.netbeans.editor.BaseAction;
61
import org.netbeans.editor.ext.ExtKit;
62
import org.netbeans.spi.editor.codegen.CodeGenerator;
63
import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
64
import org.openide.util.Lookup;
65
import org.openide.util.NbBundle;
66
import org.openide.util.lookup.Lookups;
67
68
/**
69
 *
70
 * @author Dusan Balek, Jan Lahoda
71
 */
72
public class NbGenerateCodeAction extends BaseAction {
73
74
    public static final String generateCode = "generate-code"; //NOI18N
75
    
76
    public NbGenerateCodeAction(){
77
        super(generateCode);
78
        putValue(ExtKit.TRIMMED_TEXT, NbBundle.getBundle(NbGenerateCodeAction.class).getString("generate-code-trimmed")); //NOI18N
79
        putValue(SHORT_DESCRIPTION, NbBundle.getBundle(NbGenerateCodeAction.class).getString("desc-generate-code")); //NOI18N
80
        putValue(POPUP_MENU_TEXT, NbBundle.getBundle(NbGenerateCodeAction.class).getString("popup-generate-code")); //NOI18N
81
    }
82
    
83
    public void actionPerformed(ActionEvent evt, final JTextComponent target) {
84
        Task task = new Task(getFullMimePath(target.getDocument(), target.getCaretPosition()));
85
        task.run(Lookups.singleton(target));
86
        if (task.codeGenerators.size() > 0) {
87
            int altHeight = -1;
88
            Point where = null;
89
            try {
90
                Rectangle carretRectangle = target.modelToView(target.getCaretPosition());
91
                altHeight = carretRectangle.height;
92
                where = new Point( carretRectangle.x, carretRectangle.y + carretRectangle.height );
93
                SwingUtilities.convertPointToScreen(where, target);
94
            } catch (BadLocationException ble) {
95
            }
96
            if (where == null)
97
                where = new Point(-1, -1);
98
            PopupUtil.showPopup(new GenerateCodePanel(target, task.codeGenerators), null, where.x, where.y, true, altHeight);
99
        } else {
100
            target.getToolkit().beep();
101
        }
102
    }
103
    
104
    private static MimePath getFullMimePath(Document document, int offset) {
105
        String langPath = null;
106
107
        if (document instanceof AbstractDocument) {
108
            AbstractDocument adoc = (AbstractDocument)document;
109
            adoc.readLock();
110
            try {
111
                List<TokenSequence<?>> list = TokenHierarchy.get(document).embeddedTokenSequences(offset, true);
112
                if (list.size() > 1) {
113
                    langPath = list.get(list.size() - 1).languagePath().mimePath();
114
                }
115
            } finally {
116
                adoc.readUnlock();
117
            }
118
        }
119
120
        if (langPath == null) {
121
            langPath = NbEditorUtilities.getMimeType(document);
122
        }
123
124
        if (langPath != null) {
125
            return MimePath.parse(langPath);
126
        } else {
127
            return null;
128
        }
129
    }
130
131
    private static class Task implements CodeGeneratorContextProvider.Task {
132
        private MimePath mimePath;
133
        private Iterator<? extends CodeGeneratorContextProvider> contextProviders;
134
        private List<CodeGenerator> codeGenerators = new ArrayList<CodeGenerator>(); 
135
136
        private Task(MimePath mimePath) {
137
            this.mimePath = mimePath;
138
            contextProviders = MimeLookup.getLookup(mimePath).lookupAll(CodeGeneratorContextProvider.class).iterator();
139
        }
140
141
        public void run(Lookup context) {
142
            if (contextProviders.hasNext()) {
143
                contextProviders.next().runTaskWithinContext(context, this);
144
            } else {
145
                for (CodeGenerator.Factory factory : MimeLookup.getLookup(mimePath).lookupAll(CodeGenerator.Factory.class))
146
                    codeGenerators.addAll(factory.create(context));
147
            }
148
        }
149
    }
150
    
151
    public static final class GlobalAction extends MainMenuAction {
152
153
        private final JMenuItem menuPresenter;
154
        
155
        public GlobalAction() {
156
            super();
157
            this.menuPresenter = new JMenuItem(getMenuItemText());
158
            setMenu();
159
        }
160
        
161
        protected String getMenuItemText() {
162
            return NbBundle.getBundle(GlobalAction.class).getString("generate-code-main-menu-source-item"); //NOI18N
163
        }
164
165
        protected String getActionName() {
166
            return generateCode;
167
        }
168
169
        public JMenuItem getMenuPresenter() {
170
            return menuPresenter;
171
        }
172
        
173
    } // End of GlobalAction class
174
}
(-)9387523afe84 (+274 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.editor.codegen;
43
44
import java.awt.AWTEvent;
45
import java.awt.Component;
46
import java.awt.Container;
47
import java.awt.Frame;
48
import java.awt.Point;
49
import java.awt.Rectangle;
50
import java.awt.Toolkit;
51
import java.awt.event.AWTEventListener;
52
import java.awt.event.ComponentAdapter;
53
import java.awt.event.ComponentEvent;
54
import java.awt.event.FocusListener;
55
import java.awt.event.KeyEvent;
56
import java.awt.event.MouseEvent;
57
import java.awt.event.WindowEvent;
58
import java.awt.event.WindowStateListener;
59
import javax.swing.AbstractAction;
60
import javax.swing.Action;
61
import javax.swing.JComponent;
62
import javax.swing.JDialog;
63
import javax.swing.KeyStroke;
64
import javax.swing.SwingUtilities;
65
import org.openide.windows.WindowManager;
66
67
/**
68
 *
69
 * @author phrebejk
70
 */
71
public final class PopupUtil  {
72
    
73
    // private static MyFocusListener mfl = new MyFocusListener();
74
    
75
    private static final String CLOSE_KEY = "CloseKey"; //NOI18N
76
    private static final Action CLOSE_ACTION = new CloseAction();
77
    private static final KeyStroke ESC_KEY_STROKE = KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ); 
78
        
79
    private static final String POPUP_NAME = "popupComponent"; //NOI18N
80
    private static JDialog popupWindow;
81
    private static HideAWTListener hideListener = new HideAWTListener();
82
    
83
    // Singleton
84
    private PopupUtil() {
85
    }
86
    
87
    
88
    public static void showPopup( JComponent content, String title ) {
89
        showPopup(content, title, -1, -1, false);
90
    }
91
    
92
    public static void showPopup( JComponent content, String title, int x, int y, boolean undecorated ) {
93
        showPopup(content, title, x, y, false, -1 );
94
    }  
95
96
    public static void showPopup( JComponent content, String title, int x, int y, boolean undecorated, int altHeight ) {        
97
        if (popupWindow != null ) {
98
            return; // Content already showing
99
        }
100
                           
101
        Toolkit.getDefaultToolkit().addAWTEventListener(hideListener, AWTEvent.MOUSE_EVENT_MASK);
102
        
103
        // NOT using PopupFactory
104
        // 1. on linux, creates mediumweight popup taht doesn't refresh behind visible glasspane
105
        // 2. on mac, needs an owner frame otherwise hiding tooltip also hides the popup. (linux requires no owner frame to force heavyweight)
106
        // 3. the created window is not focusable window
107
        
108
        popupWindow = new JDialog( getMainWindow() );
109
        popupWindow.setName( POPUP_NAME );
110
        popupWindow.setUndecorated(undecorated);
111
        popupWindow.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put( ESC_KEY_STROKE, CLOSE_KEY );
112
        popupWindow.getRootPane().getActionMap().put( CLOSE_KEY, CLOSE_ACTION );
113
	
114
	//set a11y
115
	String a11yName = content.getAccessibleContext().getAccessibleName();
116
	if(a11yName != null && !a11yName.equals(""))
117
	    popupWindow.getAccessibleContext().setAccessibleName(a11yName);
118
	String a11yDesc = content.getAccessibleContext().getAccessibleDescription();
119
	if(a11yDesc != null && !a11yDesc.equals(""))
120
	    popupWindow.getAccessibleContext().setAccessibleDescription(a11yDesc);
121
	    
122
        if ( title != null ) {
123
            // popupWindow.setTitle( title );
124
        }
125
        // popupWindow.setAlwaysOnTop( true );
126
        popupWindow.getContentPane().add(content);
127
        // popupWindow.addFocusListener( mfl );                        
128
        // content.addFocusListener( mfl );                        
129
                
130
        WindowManager.getDefault().getMainWindow().addWindowStateListener(hideListener);
131
        WindowManager.getDefault().getMainWindow().addComponentListener(hideListener);
132
        resizePopup();
133
        
134
        if (x != (-1)) {
135
            Point p = fitToScreen( x, y, altHeight );
136
            popupWindow.setLocation(p.x, p.y);
137
            
138
        }
139
        
140
        popupWindow.setVisible( true );
141
        // System.out.println("     RFIW ==" + popupWindow.requestFocusInWindow() );
142
        content.requestFocus();
143
        content.requestFocusInWindow();
144
//        System.out.println("     has focus =" + content.hasFocus());
145
//        System.out.println("     has focus =" + popupWindow.hasFocus());
146
//        System.out.println("     window focusable=" + popupWindow.isFocusableWindow());
147
    }
148
    
149
    public static void hidePopup() {
150
        if (popupWindow != null) {
151
//            popupWindow.getContentPane().removeAll();
152
            Toolkit.getDefaultToolkit().removeAWTEventListener(hideListener);
153
            
154
            popupWindow.setVisible( false );
155
            popupWindow.dispose();
156
        }
157
        WindowManager.getDefault().getMainWindow().removeWindowStateListener(hideListener);
158
        WindowManager.getDefault().getMainWindow().removeComponentListener(hideListener);
159
        popupWindow = null;
160
    }
161
162
    
163
    private static void resizePopup() {
164
        popupWindow.pack();
165
        Point point = new Point(0,0);
166
        SwingUtilities.convertPointToScreen(point, getMainWindow());
167
        popupWindow.setLocation( point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2, 
168
                                 point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3);
169
    }
170
    
171
    private static final int X_INSET = 10;
172
    private static final int Y_INSET = X_INSET;
173
    
174
    private static Point fitToScreen( int x, int y, int altHeight ) {
175
        
176
        Rectangle screen = org.openide.util.Utilities.getUsableScreenBounds();
177
                
178
        Point p = new Point( x, y );
179
        
180
        // Adjust the x postition if necessary
181
        if ( ( p.x + popupWindow.getWidth() ) > ( screen.x + screen.width - X_INSET ) ) {
182
            p.x = screen.x + screen.width - X_INSET - popupWindow.getWidth(); 
183
        }
184
        
185
        // Adjust the y position if necessary
186
        if ( ( p.y + popupWindow.getHeight() ) > ( screen.y + screen.height - X_INSET ) ) {
187
            p.y = p.y - popupWindow.getHeight() - altHeight;
188
        }
189
        
190
        return p;     
191
    }
192
193
    
194
    private static Frame getMainWindow() {
195
        return WindowManager.getDefault().getMainWindow();
196
    }
197
    
198
    // Innerclasses ------------------------------------------------------------
199
    
200
    private static class HideAWTListener extends ComponentAdapter implements  AWTEventListener, WindowStateListener {
201
        
202
        public void eventDispatched(java.awt.AWTEvent aWTEvent) {
203
            if (aWTEvent instanceof MouseEvent) {
204
                MouseEvent mv = (MouseEvent)aWTEvent;
205
                if (mv.getID() == MouseEvent.MOUSE_CLICKED && mv.getClickCount() > 0) {
206
                    //#118828
207
                    if (! (aWTEvent.getSource() instanceof Component)) {
208
                        hidePopup();
209
                        return;
210
                    }
211
                    
212
                    Component comp = (Component)aWTEvent.getSource();
213
                    Container par = SwingUtilities.getAncestorNamed(POPUP_NAME, comp); //NOI18N
214
                    // Container barpar = SwingUtilities.getAncestorOfClass(PopupUtil.class, comp);
215
                    // if (par == null && barpar == null) {
216
                    if ( par == null ) {
217
                        hidePopup();
218
                    }
219
                }
220
            }
221
        }
222
223
        public void windowStateChanged(WindowEvent windowEvent) {
224
            if (popupWindow != null ) {
225
                int oldState = windowEvent.getOldState();
226
                int newState = windowEvent.getNewState();
227
            
228
                if (((oldState & Frame.ICONIFIED) == 0) &&
229
                    ((newState & Frame.ICONIFIED) == Frame.ICONIFIED)) {
230
                    hidePopup();
231
//                } else if (((oldState & Frame.ICONIFIED) == Frame.ICONIFIED) && 
232
//                           ((newState & Frame.ICONIFIED) == 0 )) {
233
//                    //TODO remember we showed before and show again? I guess not worth the efford, not part of spec.
234
                }
235
            }
236
237
        }
238
        
239
        public void componentResized(ComponentEvent evt) {
240
            if (popupWindow != null) {
241
                resizePopup();
242
            }
243
        }
244
        
245
        public void componentMoved(ComponentEvent evt) {
246
            if (popupWindow!= null) {
247
                resizePopup();
248
            }
249
        }        
250
        
251
    }
252
    
253
    private static class MyFocusListener implements FocusListener {
254
        
255
        public void focusLost(java.awt.event.FocusEvent e) {
256
            System.out.println( e );
257
        }
258
259
        public void focusGained(java.awt.event.FocusEvent e) {
260
            System.out.println( e );
261
        }
262
                        
263
    }
264
    
265
    private static class CloseAction extends AbstractAction {
266
        
267
        public void actionPerformed(java.awt.event.ActionEvent e) {
268
            hidePopup();
269
        }
270
                
271
                
272
    }
273
    
274
}
(-)a/editor/src/org/netbeans/modules/editor/resources/layer.xml (+3 lines)
Lines 191-196 Link Here
191
                <attr name="position" intvalue="2000"/>
191
                <attr name="position" intvalue="2000"/>
192
            </file>
192
            </file>
193
            
193
            
194
            <file name="org-netbeans-modules-editor-codegen-NbGenerateCodeAction$GlobalAction.instance">
195
                <attr name="position" intvalue="2200"/>
196
            </file>
194
197
195
            <file name="SeparatorBeforeWordMatchInsert.instance">
198
            <file name="SeparatorBeforeWordMatchInsert.instance">
196
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
199
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
(-)a/java.editor/nbproject/project.xml (-1 / +1 lines)
Lines 127-133 Link Here
127
                    <compile-dependency/>
127
                    <compile-dependency/>
128
                    <run-dependency>
128
                    <run-dependency>
129
                        <release-version>1</release-version>
129
                        <release-version>1</release-version>
130
                        <specification-version>1.2</specification-version>
130
                        <specification-version>1.8</specification-version>
131
                    </run-dependency>
131
                    </run-dependency>
132
                </dependency>
132
                </dependency>
133
                <dependency>
133
                <dependency>
(-)a/java.editor/src/META-INF/services/org.netbeans.spi.editor.mimelookup.Class2LayerFolder (-1 lines)
Removed Link Here
1
org.netbeans.modules.java.editor.codegen.Class2Folder
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java (-4 lines)
Lines 59-73 Link Here
59
import org.netbeans.api.java.queries.SourceLevelQuery;
59
import org.netbeans.api.java.queries.SourceLevelQuery;
60
import org.netbeans.api.lexer.TokenHierarchy;
60
import org.netbeans.api.lexer.TokenHierarchy;
61
import org.netbeans.api.lexer.TokenSequence;
61
import org.netbeans.api.lexer.TokenSequence;
62
import org.netbeans.editor.ext.ExtKit.CommentAction;
63
import org.netbeans.editor.ext.ExtKit.PrefixMakerAction;
62
import org.netbeans.editor.ext.ExtKit.PrefixMakerAction;
64
import org.netbeans.editor.ext.ExtKit.UncommentAction;
65
import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
63
import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
66
import org.netbeans.modules.editor.MainMenuAction;
64
import org.netbeans.modules.editor.MainMenuAction;
67
import org.netbeans.modules.editor.NbEditorKit;
65
import org.netbeans.modules.editor.NbEditorKit;
68
import org.netbeans.modules.editor.NbEditorUtilities;
66
import org.netbeans.modules.editor.NbEditorUtilities;
69
import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction;
67
import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction;
70
import org.netbeans.modules.java.editor.codegen.GenerateCodeAction;
71
import org.netbeans.modules.java.editor.imports.FastImportAction;
68
import org.netbeans.modules.java.editor.imports.FastImportAction;
72
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
69
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
73
import org.netbeans.modules.java.editor.overridden.GoToSuperTypeAction;
70
import org.netbeans.modules.java.editor.overridden.GoToSuperTypeAction;
Lines 252-258 Link Here
252
                                   new JavaGotoHelpAction(),
249
                                   new JavaGotoHelpAction(),
253
				   new InstantRenameAction(),
250
				   new InstantRenameAction(),
254
                                   new JavaFixImports(),
251
                                   new JavaFixImports(),
255
                                   new GenerateCodeAction(),
256
                                   new InsertSemicolonAction(true),
252
                                   new InsertSemicolonAction(true),
257
                                   new InsertSemicolonAction(false),
253
                                   new InsertSemicolonAction(false),
258
                                   new SelectCodeElementAction(selectNextElementAction, true),
254
                                   new SelectCodeElementAction(selectNextElementAction, true),
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/Bundle.properties (-5 lines)
Lines 37-50 Link Here
37
# Version 2 license, then the option applies only if the new code is
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
38
# made subject to such option by the copyright holder.
39
39
40
generate-code-trimmed=Insert Code
41
desc-generate-code=Insert Code
42
popup-generate-code=Insert Code...
43
generate-code-main-menu-source-item=&Insert Code...
44
complete-line-newline=Complete Line and Create New Line
40
complete-line-newline=Complete Line and Create New Line
45
complete-line=Complete Line
41
complete-line=Complete Line
46
42
47
LBL_generate_code=Generate
48
LBL_constructor=Constructor...
43
LBL_constructor=Constructor...
49
LBL_generate_constructor=Generate Constructor
44
LBL_generate_constructor=Generate Constructor
50
LBL_super_constructor_select=Select super constructor:
45
LBL_super_constructor_select=Select super constructor:
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/Class2Folder.java (-64 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.editor.codegen;
41
42
import org.netbeans.modules.java.editor.codegen.CodeGenerator.Factory;
43
import org.netbeans.spi.editor.mimelookup.Class2LayerFolder;
44
import org.netbeans.spi.editor.mimelookup.InstanceProvider;
45
46
/**
47
 *
48
 * @author Jan Lahoda
49
 */
50
public class Class2Folder implements Class2LayerFolder<Factory> {
51
52
    public Class<Factory> getClazz() {
53
        return Factory.class;
54
    }
55
56
    public String getLayerFolderName() {
57
        return "codegenerators"; //NOI18N
58
    }
59
60
    public InstanceProvider<Factory> getInstanceProvider() {
61
        return null;
62
    }
63
64
}
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/CodeGenerator.java (-61 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.java.editor.codegen;
43
44
import com.sun.source.util.TreePath;
45
import java.io.IOException;
46
import javax.swing.text.JTextComponent;
47
import org.netbeans.api.java.source.CompilationController;
48
49
/**
50
 *
51
 * @author Dusan Balek
52
 */
53
public interface CodeGenerator {
54
55
    public String getDisplayName();
56
    public void invoke(JTextComponent component);
57
    
58
    public interface Factory {
59
        public Iterable<? extends CodeGenerator> create(CompilationController controller, TreePath path) throws IOException;
60
    }
61
}
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/ConstructorGenerator.java (-15 / +23 lines)
Lines 46-52 Link Here
46
import java.awt.Dialog;
46
import java.awt.Dialog;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.ArrayList;
48
import java.util.ArrayList;
49
import java.util.Collections;
50
import java.util.LinkedHashSet;
49
import java.util.LinkedHashSet;
51
import java.util.List;
50
import java.util.List;
52
import java.util.Set;
51
import java.util.Set;
Lines 70-78 Link Here
70
import org.netbeans.modules.editor.java.Utilities;
69
import org.netbeans.modules.editor.java.Utilities;
71
import org.netbeans.modules.java.editor.codegen.ui.ConstructorPanel;
70
import org.netbeans.modules.java.editor.codegen.ui.ConstructorPanel;
72
import org.netbeans.modules.java.editor.codegen.ui.ElementNode;
71
import org.netbeans.modules.java.editor.codegen.ui.ElementNode;
72
import org.netbeans.spi.editor.codegen.CodeGenerator;
73
import org.openide.DialogDescriptor;
73
import org.openide.DialogDescriptor;
74
import org.openide.DialogDisplayer;
74
import org.openide.DialogDisplayer;
75
import org.openide.util.Exceptions;
75
import org.openide.util.Exceptions;
76
import org.openide.util.Lookup;
76
import org.openide.util.NbBundle;
77
import org.openide.util.NbBundle;
77
78
78
/**
79
/**
Lines 83-99 Link Here
83
84
84
    public static class Factory implements CodeGenerator.Factory {
85
    public static class Factory implements CodeGenerator.Factory {
85
        
86
        
86
        public Factory() {            
87
        public List<? extends CodeGenerator> create(Lookup context) {
87
        }
88
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
88
        
89
            JTextComponent component = context.lookup(JTextComponent.class);
89
        public Iterable<? extends CodeGenerator> create(CompilationController controller, TreePath path) throws IOException {
90
            CompilationController controller = context.lookup(CompilationController.class);
90
            path = Utilities.getPathElementOfKind(Tree.Kind.CLASS, path);
91
            TreePath path = context.lookup(TreePath.class);
91
            if (path == null)
92
            path = path != null ? Utilities.getPathElementOfKind(Tree.Kind.CLASS, path) : null;
92
                return Collections.emptySet();
93
            if (component == null || controller == null || path == null)
93
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
94
                return ret;
95
            try {
96
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
97
            } catch (IOException ioe) {
98
                return ret;
99
            }
94
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
100
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
95
            if (typeElement == null || !typeElement.getKind().isClass() || NestingKind.ANONYMOUS.equals(typeElement.getNestingKind()))
101
            if (typeElement == null || !typeElement.getKind().isClass() || NestingKind.ANONYMOUS.equals(typeElement.getNestingKind()))
96
                return Collections.emptySet();
102
                return ret;
97
            final Set<VariableElement> initializedFields = new LinkedHashSet<VariableElement>();
103
            final Set<VariableElement> initializedFields = new LinkedHashSet<VariableElement>();
98
            final Set<VariableElement> uninitializedFields = new LinkedHashSet<VariableElement>();
104
            final Set<VariableElement> uninitializedFields = new LinkedHashSet<VariableElement>();
99
            final List<ExecutableElement> constructors = new ArrayList<ExecutableElement>();
105
            final List<ExecutableElement> constructors = new ArrayList<ExecutableElement>();
Lines 124-141 Link Here
124
                    fieldDescriptions.add(ElementNode.Description.create(variableElement, null, true, false));
130
                    fieldDescriptions.add(ElementNode.Description.create(variableElement, null, true, false));
125
                fieldsDescription = ElementNode.Description.create(typeElement, fieldDescriptions, false, false);
131
                fieldsDescription = ElementNode.Description.create(typeElement, fieldDescriptions, false, false);
126
            }
132
            }
127
            if (constructorHandle == null && constructorDescription == null && fieldsDescription == null)
133
            if (constructorHandle != null || constructorDescription != null || fieldsDescription != null)
128
                return Collections.emptySet();
134
                ret.add(new ConstructorGenerator(component, constructorHandle, constructorDescription, fieldsDescription));
129
            return Collections.singleton(new ConstructorGenerator(constructorHandle, constructorDescription, fieldsDescription));
135
            return ret;
130
        }
136
        }
131
    }
137
    }
132
138
139
    private JTextComponent component;
133
    private ElementHandle<? extends Element> constructorHandle;
140
    private ElementHandle<? extends Element> constructorHandle;
134
    private ElementNode.Description constructorDescription;
141
    private ElementNode.Description constructorDescription;
135
    private ElementNode.Description fieldsDescription;
142
    private ElementNode.Description fieldsDescription;
136
    
143
    
137
    /** Creates a new instance of ConstructorGenerator */
144
    /** Creates a new instance of ConstructorGenerator */
138
    private ConstructorGenerator(ElementHandle<? extends Element> constructorHandle, ElementNode.Description constructorDescription, ElementNode.Description fieldsDescription) {
145
    private ConstructorGenerator(JTextComponent component, ElementHandle<? extends Element> constructorHandle, ElementNode.Description constructorDescription, ElementNode.Description fieldsDescription) {
146
        this.component = component;
139
        this.constructorHandle = constructorHandle;
147
        this.constructorHandle = constructorHandle;
140
        this.constructorDescription = constructorDescription;
148
        this.constructorDescription = constructorDescription;
141
        this.fieldsDescription = fieldsDescription;
149
        this.fieldsDescription = fieldsDescription;
Lines 145-151 Link Here
145
        return org.openide.util.NbBundle.getMessage(ConstructorGenerator.class, "LBL_constructor"); //NOI18N
153
        return org.openide.util.NbBundle.getMessage(ConstructorGenerator.class, "LBL_constructor"); //NOI18N
146
    }
154
    }
147
155
148
    public void invoke(JTextComponent component) {
156
    public void invoke() {
149
        final List<ElementHandle<? extends Element>> fieldHandles;
157
        final List<ElementHandle<? extends Element>> fieldHandles;
150
        final List<ElementHandle<? extends Element>> constrHandles;
158
        final List<ElementHandle<? extends Element>> constrHandles;
151
        if (constructorDescription != null || fieldsDescription != null) {
159
        if (constructorDescription != null || fieldsDescription != null) {
(-)9387523afe84 (+81 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.java.editor.codegen;
42
43
import com.sun.source.util.TreePath;
44
import java.io.IOException;
45
import javax.swing.text.JTextComponent;
46
import org.netbeans.api.java.source.CompilationController;
47
import org.netbeans.api.java.source.JavaSource;
48
import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
49
import org.openide.util.Lookup;
50
import org.openide.util.lookup.Lookups;
51
import org.openide.util.lookup.ProxyLookup;
52
53
/**
54
 *
55
 * @author Dusan Balek
56
 */
57
public class ContextProvider implements CodeGeneratorContextProvider {
58
59
    public void runTaskWithinContext(final Lookup context, final Task task) {
60
        JTextComponent component = context.lookup(JTextComponent.class);
61
        if (component != null) {
62
            try {
63
                JavaSource js = JavaSource.forDocument(component.getDocument());
64
                if (js != null) {
65
                    final int caretOffset = component.getCaretPosition();
66
                    js.runUserActionTask(new org.netbeans.api.java.source.Task<CompilationController>() {
67
                        public void run(CompilationController controller) throws Exception {
68
                            controller.toPhase(JavaSource.Phase.PARSED);
69
                            TreePath path = controller.getTreeUtilities().pathFor(caretOffset);
70
                            Lookup newContext = new ProxyLookup(context, Lookups.fixed(controller, path));
71
                            task.run(newContext);
72
                        }
73
                    }, true);
74
                    return;
75
                }
76
            } catch (IOException ioe) {
77
            }
78
        }
79
        task.run(context);
80
    }
81
}
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/DelegateMethodGenerator.java (-14 / +24 lines)
Lines 40-45 Link Here
40
 */
40
 */
41
package org.netbeans.modules.java.editor.codegen;
41
package org.netbeans.modules.java.editor.codegen;
42
42
43
import org.netbeans.spi.editor.codegen.CodeGenerator;
43
import com.sun.source.tree.BlockTree;
44
import com.sun.source.tree.BlockTree;
44
import com.sun.source.tree.ClassTree;
45
import com.sun.source.tree.ClassTree;
45
import com.sun.source.tree.ExpressionTree;
46
import com.sun.source.tree.ExpressionTree;
Lines 81-86 Link Here
81
import org.openide.DialogDescriptor;
82
import org.openide.DialogDescriptor;
82
import org.openide.DialogDisplayer;
83
import org.openide.DialogDisplayer;
83
import org.openide.util.Exceptions;
84
import org.openide.util.Exceptions;
85
import org.openide.util.Lookup;
84
import org.openide.util.NbBundle;
86
import org.openide.util.NbBundle;
85
87
86
/**
88
/**
Lines 93-118 Link Here
93
95
94
    public static class Factory implements CodeGenerator.Factory {
96
    public static class Factory implements CodeGenerator.Factory {
95
        
97
        
96
        public Factory() {            
98
        public List<? extends CodeGenerator> create(Lookup context) {
97
        }
99
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
98
        
100
            JTextComponent component = context.lookup(JTextComponent.class);
99
        public Iterable<? extends CodeGenerator> create(CompilationController controller, TreePath path) throws IOException {
101
            CompilationController controller = context.lookup(CompilationController.class);
100
            path = Utilities.getPathElementOfKind(Tree.Kind.CLASS, path);
102
            TreePath path = context.lookup(TreePath.class);
101
            if (path == null)
103
            path = path != null ? Utilities.getPathElementOfKind(Tree.Kind.CLASS, path) : null;
102
                return Collections.emptySet();
104
            if (component == null || controller == null || path == null)
103
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
105
                return ret;
106
            try {
107
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
108
            } catch (IOException ioe) {
109
                return ret;
110
            }
104
            List<ElementNode.Description> descriptions = computeUsableFieldsDescriptions(controller, path);
111
            List<ElementNode.Description> descriptions = computeUsableFieldsDescriptions(controller, path);
105
            if (descriptions.isEmpty())
112
            if (!descriptions.isEmpty()) {
106
                return Collections.emptySet();
113
                Collections.reverse(descriptions);
107
            Collections.reverse(descriptions);
114
                ret.add(new DelegateMethodGenerator(component, ElementNode.Description.create(descriptions)));
108
            return Collections.singleton(new DelegateMethodGenerator(ElementNode.Description.create(descriptions)));
115
            }
116
            return ret;
109
        }
117
        }
110
    }
118
    }
111
119
120
    private JTextComponent component;
112
    private ElementNode.Description description;
121
    private ElementNode.Description description;
113
    
122
    
114
    /** Creates a new instance of DelegateMethodGenerator */
123
    /** Creates a new instance of DelegateMethodGenerator */
115
    private DelegateMethodGenerator(ElementNode.Description description) {
124
    private DelegateMethodGenerator(JTextComponent component, ElementNode.Description description) {
125
        this.component = component;
116
        this.description = description;
126
        this.description = description;
117
    }
127
    }
118
128
Lines 120-126 Link Here
120
        return org.openide.util.NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_method"); //NOI18N
130
        return org.openide.util.NbBundle.getMessage(DelegateMethodGenerator.class, "LBL_delegate_method"); //NOI18N
121
    }
131
    }
122
132
123
    public void invoke(JTextComponent component) {
133
    public void invoke() {
124
        final DelegatePanel panel = new DelegatePanel(component, description);
134
        final DelegatePanel panel = new DelegatePanel(component, description);
125
        DialogDescriptor dialogDescriptor = GeneratorUtils.createDialogDescriptor(panel, NbBundle.getMessage(ConstructorGenerator.class, "LBL_generate_delegate")); //NOI18N
135
        DialogDescriptor dialogDescriptor = GeneratorUtils.createDialogDescriptor(panel, NbBundle.getMessage(ConstructorGenerator.class, "LBL_generate_delegate")); //NOI18N
126
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
136
        Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/EqualsHashCodeGenerator.java (-27 / +31 lines)
Lines 40-45 Link Here
40
 */
40
 */
41
package org.netbeans.modules.java.editor.codegen;
41
package org.netbeans.modules.java.editor.codegen;
42
42
43
import org.netbeans.spi.editor.codegen.CodeGenerator;
43
import com.sun.source.tree.AnnotationTree;
44
import com.sun.source.tree.AnnotationTree;
44
import com.sun.source.tree.BlockTree;
45
import com.sun.source.tree.BlockTree;
45
import com.sun.source.tree.ClassTree;
46
import com.sun.source.tree.ClassTree;
Lines 91-96 Link Here
91
import org.openide.DialogDescriptor;
92
import org.openide.DialogDescriptor;
92
import org.openide.DialogDisplayer;
93
import org.openide.DialogDisplayer;
93
import org.openide.util.Exceptions;
94
import org.openide.util.Exceptions;
95
import org.openide.util.Lookup;
94
import org.openide.util.NbBundle;
96
import org.openide.util.NbBundle;
95
97
96
/**
98
/**
Lines 103-137 Link Here
103
        
105
        
104
    public static class Factory implements CodeGenerator.Factory {
106
    public static class Factory implements CodeGenerator.Factory {
105
        
107
        
106
        public Factory() {
108
        public List<? extends CodeGenerator> create(Lookup context) {
107
        }
109
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
108
        
110
            JTextComponent component = context.lookup(JTextComponent.class);
109
        public Iterable<? extends CodeGenerator> create(CompilationController cc, TreePath path) throws IOException {
111
            CompilationController controller = context.lookup(CompilationController.class);
110
            path = Utilities.getPathElementOfKind(Tree.Kind.CLASS, path);
112
            TreePath path = context.lookup(TreePath.class);
111
            if (path == null)
113
            path = path != null ? Utilities.getPathElementOfKind(Tree.Kind.CLASS, path) : null;
112
                return Collections.emptySet();
114
            if (component == null || controller == null || path == null)
113
            cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
115
                return ret;
114
            
116
            try {
115
            Element elem = cc.getTrees().getElement(path);
117
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
116
            if (elem == null) {
118
                Element elem = controller.getTrees().getElement(path);
117
                return Collections.emptySet();
119
                if (elem != null) {
120
                    EqualsHashCodeGenerator gen = createEqualsHashCodeGenerator(component, controller, elem);
121
                    if (gen != null)
122
                        ret.add(gen);
123
                }
124
            } catch (IOException ioe) {
118
            }
125
            }
119
            EqualsHashCodeGenerator gen = createEqualsHashCodeGenerator(cc, elem);
126
            return ret;
120
            
121
            if (gen == null) {
122
                return Collections.emptySet();
123
            } else {
124
                return Collections.singleton(gen);
125
            }
126
        }
127
        }
127
    }
128
    }
128
129
129
    final ElementNode.Description description;
130
    private JTextComponent component;
130
    final boolean generateEquals;
131
    private ElementNode.Description description;
131
    final boolean generateHashCode;
132
    private boolean generateEquals;
133
    private boolean generateHashCode;
132
    
134
    
133
    /** Creates a new instance of EqualsHashCodeGenerator */
135
    /** Creates a new instance of EqualsHashCodeGenerator */
134
    private EqualsHashCodeGenerator(ElementNode.Description description, boolean generateEquals, boolean generateHashCode) {
136
    private EqualsHashCodeGenerator(JTextComponent component, ElementNode.Description description, boolean generateEquals, boolean generateHashCode) {
137
        this.component = component;
135
        this.description = description;        
138
        this.description = description;        
136
        this.generateEquals = generateEquals;
139
        this.generateEquals = generateEquals;
137
        this.generateHashCode = generateHashCode;
140
        this.generateHashCode = generateHashCode;
Lines 146-152 Link Here
146
        return org.openide.util.NbBundle.getMessage(EqualsHashCodeGenerator.class, "LBL_equals"); //NOI18N
149
        return org.openide.util.NbBundle.getMessage(EqualsHashCodeGenerator.class, "LBL_equals"); //NOI18N
147
    }
150
    }
148
    
151
    
149
    static EqualsHashCodeGenerator createEqualsHashCodeGenerator(CompilationController cc, Element el) throws IOException {
152
    static EqualsHashCodeGenerator createEqualsHashCodeGenerator(JTextComponent component, CompilationController cc, Element el) throws IOException {
150
        if (el.getKind() != ElementKind.CLASS)
153
        if (el.getKind() != ElementKind.CLASS)
151
            return null;
154
            return null;
152
        //#125114: ignore anonymous innerclasses:
155
        //#125114: ignore anonymous innerclasses:
Lines 165-170 Link Here
165
        if (descriptions.isEmpty() || (equalsHashCode[0] != null && equalsHashCode[1] != null))
168
        if (descriptions.isEmpty() || (equalsHashCode[0] != null && equalsHashCode[1] != null))
166
            return null;
169
            return null;
167
        return new EqualsHashCodeGenerator(
170
        return new EqualsHashCodeGenerator(
171
            component,
168
            ElementNode.Description.create(typeElement, descriptions, false, false),
172
            ElementNode.Description.create(typeElement, descriptions, false, false),
169
            equalsHashCode[0] == null,
173
            equalsHashCode[0] == null,
170
            equalsHashCode[1] == null
174
            equalsHashCode[1] == null
Lines 280-291 Link Here
280
                    cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
284
                    cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
281
                    Element e = handle.resolveElement(cc);
285
                    Element e = handle.resolveElement(cc);
282
                    
286
                    
283
                    gen = createEqualsHashCodeGenerator(cc, e);
287
                    gen = createEqualsHashCodeGenerator(component, cc, e);
284
                }
288
                }
285
                
289
                
286
                public void invoke() {
290
                public void invoke() {
287
                    if (gen != null) {
291
                    if (gen != null) {
288
                        gen.invoke(component);
292
                        gen.invoke();
289
                    }
293
                    }
290
                }
294
                }
291
295
Lines 300-306 Link Here
300
        }
304
        }
301
    }
305
    }
302
    
306
    
303
    public void invoke(JTextComponent component) {
307
    public void invoke() {
304
        final EqualsHashCodePanel panel = new EqualsHashCodePanel(description, generateEquals, generateHashCode);
308
        final EqualsHashCodePanel panel = new EqualsHashCodePanel(description, generateEquals, generateHashCode);
305
        String title = NbBundle.getMessage(ConstructorGenerator.class, "LBL_generate_equals_and_hashcode"); //NOI18N
309
        String title = NbBundle.getMessage(ConstructorGenerator.class, "LBL_generate_equals_and_hashcode"); //NOI18N
306
        if( !generateEquals )
310
        if( !generateEquals )
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/GenerateCodeAction.java (-141 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.modules.java.editor.codegen;
42
43
import com.sun.source.util.TreePath;
44
import java.awt.Point;
45
import java.awt.Rectangle;
46
import java.awt.event.ActionEvent;
47
import java.io.IOException;
48
import java.util.ArrayList;
49
import javax.swing.JMenuItem;
50
import javax.swing.SwingUtilities;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.api.editor.mimelookup.MimeLookup;
54
import org.netbeans.api.java.source.Task;
55
import org.netbeans.api.java.source.CompilationController;
56
import org.netbeans.api.java.source.JavaSource;
57
import org.netbeans.editor.BaseAction;
58
import org.netbeans.editor.ext.ExtKit;
59
import org.netbeans.modules.editor.MainMenuAction;
60
import org.netbeans.modules.java.editor.codegen.ui.GenerateCodePanel;
61
import org.netbeans.modules.java.editor.overridden.PopupUtil;
62
import org.openide.util.Exceptions;
63
import org.openide.util.NbBundle;
64
65
/**
66
 *
67
 * @author Dusan Balek, Jan Lahoda
68
 */
69
public class GenerateCodeAction extends BaseAction {
70
71
    public static final String generateCode = "generate-code"; //NOI18N
72
    
73
    public GenerateCodeAction(){
74
        super(generateCode);
75
        putValue(ExtKit.TRIMMED_TEXT, NbBundle.getBundle(GenerateCodeAction.class).getString("generate-code-trimmed")); //NOI18N
76
        putValue(SHORT_DESCRIPTION, NbBundle.getBundle(GenerateCodeAction.class).getString("desc-generate-code")); //NOI18N
77
        putValue(POPUP_MENU_TEXT, NbBundle.getBundle(GenerateCodeAction.class).getString("popup-generate-code")); //NOI18N
78
    }
79
    
80
    public void actionPerformed(ActionEvent evt, final JTextComponent target) {
81
        try {
82
            JavaSource js = JavaSource.forDocument(target.getDocument());
83
            if (js != null) {
84
                final int caretOffset = target.getCaretPosition();
85
                final ArrayList<CodeGenerator> gens = new ArrayList<CodeGenerator>();
86
                js.runUserActionTask(new Task<CompilationController>() {
87
88
                    public void run(CompilationController controller) throws Exception {
89
                        controller.toPhase(JavaSource.Phase.PARSED);
90
                        TreePath path = controller.getTreeUtilities().pathFor(caretOffset);
91
                        for (CodeGenerator.Factory factory : getCodeGeneratorFactories()) {
92
                            for (CodeGenerator gen : factory.create(controller, path))
93
                                gens.add(gen);
94
                        }
95
                    }
96
                }, true);
97
                if (gens.size() > 0) {
98
                    Rectangle carretRectangle = target.modelToView(target.getCaretPosition());
99
                    Point where = new Point( carretRectangle.x, carretRectangle.y + carretRectangle.height );
100
                    SwingUtilities.convertPointToScreen( where, target);
101
                    GenerateCodePanel panel = new GenerateCodePanel(target, gens);
102
                    PopupUtil.showPopup(panel, null, where.x, where.y, true, carretRectangle.height);
103
                } else {
104
                    target.getToolkit().beep();
105
                }
106
            }
107
        } catch (IOException ioe) {
108
            Exceptions.printStackTrace(ioe);
109
        } catch (BadLocationException ble) {
110
            Exceptions.printStackTrace(ble);
111
        }
112
    }
113
    
114
    private Iterable<? extends CodeGenerator.Factory> getCodeGeneratorFactories() {
115
        return MimeLookup.getLookup("text/x-java").lookupAll(CodeGenerator.Factory.class);
116
    }
117
    
118
    public static final class GlobalAction extends MainMenuAction {
119
120
        private final JMenuItem menuPresenter;
121
        
122
        public GlobalAction() {
123
            super();
124
            this.menuPresenter = new JMenuItem(getMenuItemText());
125
            setMenu();
126
        }
127
        
128
        protected String getMenuItemText() {
129
            return NbBundle.getBundle(GlobalAction.class).getString("generate-code-main-menu-source-item"); //NOI18N
130
        }
131
132
        protected String getActionName() {
133
            return generateCode;
134
        }
135
136
        public JMenuItem getMenuPresenter() {
137
            return menuPresenter;
138
        }
139
        
140
    } // End of GlobalAction class
141
}
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/GetterSetterGenerator.java (-13 / +21 lines)
Lines 40-45 Link Here
40
 */
40
 */
41
package org.netbeans.modules.java.editor.codegen;
41
package org.netbeans.modules.java.editor.codegen;
42
42
43
import org.netbeans.spi.editor.codegen.CodeGenerator;
43
import com.sun.source.tree.ClassTree;
44
import com.sun.source.tree.ClassTree;
44
import com.sun.source.tree.Tree;
45
import com.sun.source.tree.Tree;
45
import com.sun.source.util.TreePath;
46
import com.sun.source.util.TreePath;
Lines 71-76 Link Here
71
import org.openide.DialogDescriptor;
72
import org.openide.DialogDescriptor;
72
import org.openide.DialogDisplayer;
73
import org.openide.DialogDisplayer;
73
import org.openide.util.Exceptions;
74
import org.openide.util.Exceptions;
75
import org.openide.util.Lookup;
74
import org.openide.util.NbBundle;
76
import org.openide.util.NbBundle;
75
77
76
/**
78
/**
Lines 82-97 Link Here
82
    public static class Factory implements CodeGenerator.Factory {
84
    public static class Factory implements CodeGenerator.Factory {
83
        
85
        
84
        private static final String ERROR = "<error>"; //NOI18N
86
        private static final String ERROR = "<error>"; //NOI18N
85
        
86
        public Factory() {
87
        }
88
87
89
        public Iterable<? extends CodeGenerator> create(CompilationController controller, TreePath path) throws IOException {
88
        public List<? extends CodeGenerator> create(Lookup context) {
90
            List<CodeGenerator> ret = new ArrayList<CodeGenerator>();
89
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
91
            path = Utilities.getPathElementOfKind(Tree.Kind.CLASS, path);
90
            JTextComponent component = context.lookup(JTextComponent.class);
92
            if (path == null)
91
            CompilationController controller = context.lookup(CompilationController.class);
92
            TreePath path = context.lookup(TreePath.class);
93
            path = path != null ? Utilities.getPathElementOfKind(Tree.Kind.CLASS, path) : null;
94
            if (component == null || controller == null || path == null)
93
                return ret;
95
                return ret;
94
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
96
            try {
97
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
98
            } catch (IOException ioe) {
99
                return ret;
100
            }
95
            Elements elements = controller.getElements();
101
            Elements elements = controller.getElements();
96
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
102
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
97
            if (typeElement == null || !typeElement.getKind().isClass())
103
            if (typeElement == null || !typeElement.getKind().isClass())
Lines 144-174 Link Here
144
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gDescriptions.entrySet())
150
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gDescriptions.entrySet())
145
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
151
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
146
                Collections.reverse(descriptions);
152
                Collections.reverse(descriptions);
147
                ret.add(new GetterSetterGenerator(ElementNode.Description.create(typeElement, descriptions, false, false), GeneratorUtils.GETTERS_ONLY));
153
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(typeElement, descriptions, false, false), GeneratorUtils.GETTERS_ONLY));
148
            }
154
            }
149
            if (!sDescriptions.isEmpty()) {
155
            if (!sDescriptions.isEmpty()) {
150
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
156
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
151
                for (Map.Entry<Element, List<ElementNode.Description>> entry : sDescriptions.entrySet())
157
                for (Map.Entry<Element, List<ElementNode.Description>> entry : sDescriptions.entrySet())
152
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
158
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
153
                Collections.reverse(descriptions);
159
                Collections.reverse(descriptions);
154
                ret.add(new GetterSetterGenerator(ElementNode.Description.create(typeElement, descriptions, false, false), GeneratorUtils.SETTERS_ONLY));
160
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(typeElement, descriptions, false, false), GeneratorUtils.SETTERS_ONLY));
155
            }
161
            }
156
            if (!gsDescriptions.isEmpty()) {
162
            if (!gsDescriptions.isEmpty()) {
157
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
163
                List<ElementNode.Description> descriptions = new ArrayList<ElementNode.Description>();
158
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gsDescriptions.entrySet())
164
                for (Map.Entry<Element, List<ElementNode.Description>> entry : gsDescriptions.entrySet())
159
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
165
                    descriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
160
                Collections.reverse(descriptions);
166
                Collections.reverse(descriptions);
161
                ret.add(new GetterSetterGenerator(ElementNode.Description.create(typeElement, descriptions, false, false), 0));
167
                ret.add(new GetterSetterGenerator(component, ElementNode.Description.create(typeElement, descriptions, false, false), 0));
162
            }
168
            }
163
            return ret;
169
            return ret;
164
        }
170
        }
165
    }
171
    }
166
172
173
    private JTextComponent component;
167
    private ElementNode.Description description;
174
    private ElementNode.Description description;
168
    private int type;
175
    private int type;
169
176
170
    /** Creates a new instance of GetterSetterGenerator */
177
    /** Creates a new instance of GetterSetterGenerator */
171
    private GetterSetterGenerator(ElementNode.Description description, int type) {
178
    private GetterSetterGenerator(JTextComponent component, ElementNode.Description description, int type) {
179
        this.component = component;
172
        this.description = description;
180
        this.description = description;
173
        this.type = type;
181
        this.type = type;
174
    }
182
    }
Lines 181-187 Link Here
181
        return org.openide.util.NbBundle.getMessage(GetterSetterGenerator.class, "LBL_getter_and_setter"); //NOI18N
189
        return org.openide.util.NbBundle.getMessage(GetterSetterGenerator.class, "LBL_getter_and_setter"); //NOI18N
182
    }
190
    }
183
191
184
    public void invoke(JTextComponent component) {
192
    public void invoke() {
185
        final GetterSetterPanel panel = new GetterSetterPanel(description, type);
193
        final GetterSetterPanel panel = new GetterSetterPanel(description, type);
186
        String title;
194
        String title;
187
        if (type == GeneratorUtils.GETTERS_ONLY)
195
        if (type == GeneratorUtils.GETTERS_ONLY)
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/ImplementOverrideMethodGenerator.java (-16 / +23 lines)
Lines 40-52 Link Here
40
 */
40
 */
41
package org.netbeans.modules.java.editor.codegen;
41
package org.netbeans.modules.java.editor.codegen;
42
42
43
import org.netbeans.spi.editor.codegen.CodeGenerator;
43
import com.sun.source.tree.ClassTree;
44
import com.sun.source.tree.ClassTree;
44
import com.sun.source.tree.Tree;
45
import com.sun.source.tree.Tree;
45
import com.sun.source.util.TreePath;
46
import com.sun.source.util.TreePath;
46
import java.awt.Dialog;
47
import java.awt.Dialog;
47
import java.io.IOException;
48
import java.io.IOException;
48
import java.util.ArrayList;
49
import java.util.ArrayList;
49
import java.util.Collections;
50
import java.util.LinkedHashMap;
50
import java.util.LinkedHashMap;
51
import java.util.List;
51
import java.util.List;
52
import java.util.Map;
52
import java.util.Map;
Lines 66-71 Link Here
66
import org.openide.DialogDescriptor;
66
import org.openide.DialogDescriptor;
67
import org.openide.DialogDisplayer;
67
import org.openide.DialogDisplayer;
68
import org.openide.util.Exceptions;
68
import org.openide.util.Exceptions;
69
import org.openide.util.Lookup;
69
import org.openide.util.NbBundle;
70
import org.openide.util.NbBundle;
70
71
71
/**
72
/**
Lines 75-93 Link Here
75
public class ImplementOverrideMethodGenerator implements CodeGenerator {
76
public class ImplementOverrideMethodGenerator implements CodeGenerator {
76
77
77
    public static class Factory implements CodeGenerator.Factory {
78
    public static class Factory implements CodeGenerator.Factory {
78
        
79
79
        public Factory() {            
80
        public List<? extends CodeGenerator> create(Lookup context) {
80
        }
81
            ArrayList<CodeGenerator> ret = new ArrayList<CodeGenerator>();
81
        
82
            JTextComponent component = context.lookup(JTextComponent.class);
82
        public Iterable<? extends CodeGenerator> create(CompilationController controller, TreePath path) throws IOException {
83
            CompilationController controller = context.lookup(CompilationController.class);
83
            List<CodeGenerator> ret = new ArrayList<CodeGenerator>();
84
            TreePath path = context.lookup(TreePath.class);
84
            path = Utilities.getPathElementOfKind(Tree.Kind.CLASS, path);
85
            path = path != null ? Utilities.getPathElementOfKind(Tree.Kind.CLASS, path) : null;
85
            if (path == null)
86
            if (component == null || controller == null || path == null)
86
                return ret;
87
                return ret;
87
            controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
88
            try {
89
                controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
90
            } catch (IOException ioe) {
91
                return ret;
92
            }
88
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
93
            TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
89
            if (typeElement == null || !typeElement.getKind().isClass())
94
            if (typeElement == null || !typeElement.getKind().isClass())
90
                return Collections.emptySet();
95
                return ret;
91
            Map<Element, List<ElementNode.Description>> map = new LinkedHashMap<Element, List<ElementNode.Description>>();
96
            Map<Element, List<ElementNode.Description>> map = new LinkedHashMap<Element, List<ElementNode.Description>>();
92
            for (ExecutableElement method : GeneratorUtils.findUndefs(controller, typeElement)) {
97
            for (ExecutableElement method : GeneratorUtils.findUndefs(controller, typeElement)) {
93
                List<ElementNode.Description> descriptions = map.get(method.getEnclosingElement());
98
                List<ElementNode.Description> descriptions = map.get(method.getEnclosingElement());
Lines 101-107 Link Here
101
            for (Map.Entry<Element, List<ElementNode.Description>> entry : map.entrySet())
106
            for (Map.Entry<Element, List<ElementNode.Description>> entry : map.entrySet())
102
                implementDescriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
107
                implementDescriptions.add(ElementNode.Description.create(entry.getKey(), entry.getValue(), false, false));
103
            if (!implementDescriptions.isEmpty())
108
            if (!implementDescriptions.isEmpty())
104
                ret.add(new ImplementOverrideMethodGenerator(ElementNode.Description.create(implementDescriptions), true));
109
                ret.add(new ImplementOverrideMethodGenerator(component, ElementNode.Description.create(implementDescriptions), true));
105
            map = new LinkedHashMap<Element, List<ElementNode.Description>>();
110
            map = new LinkedHashMap<Element, List<ElementNode.Description>>();
106
            ArrayList<Element> orderedElements = new ArrayList<Element>();
111
            ArrayList<Element> orderedElements = new ArrayList<Element>();
107
            for (ExecutableElement method : GeneratorUtils.findOverridable(controller, typeElement)) {
112
            for (ExecutableElement method : GeneratorUtils.findOverridable(controller, typeElement)) {
Lines 119-134 Link Here
119
            for (Element e : orderedElements)
124
            for (Element e : orderedElements)
120
                overrideDescriptions.add(ElementNode.Description.create(e, map.get( e ), false, false));
125
                overrideDescriptions.add(ElementNode.Description.create(e, map.get( e ), false, false));
121
            if (!overrideDescriptions.isEmpty())
126
            if (!overrideDescriptions.isEmpty())
122
                ret.add(new ImplementOverrideMethodGenerator(ElementNode.Description.create(overrideDescriptions), false));
127
                ret.add(new ImplementOverrideMethodGenerator(component, ElementNode.Description.create(overrideDescriptions), false));
123
            return ret;
128
            return ret;
124
        }
129
        }
125
    }
130
    }
126
    
131
132
    private JTextComponent component;
127
    private ElementNode.Description description;
133
    private ElementNode.Description description;
128
    private boolean isImplement;
134
    private boolean isImplement;
129
    
135
    
130
    /** Creates a new instance of OverrideMethodGenerator */
136
    /** Creates a new instance of OverrideMethodGenerator */
131
    private ImplementOverrideMethodGenerator(ElementNode.Description description, boolean isImplement) {
137
    private ImplementOverrideMethodGenerator(JTextComponent component, ElementNode.Description description, boolean isImplement) {
138
        this.component = component;
132
        this.description = description;
139
        this.description = description;
133
        this.isImplement = isImplement;
140
        this.isImplement = isImplement;
134
    }
141
    }
Lines 137-143 Link Here
137
        return org.openide.util.NbBundle.getMessage(ImplementOverrideMethodGenerator.class, isImplement ? "LBL_implement_method" : "LBL_override_method"); //NOI18N
144
        return org.openide.util.NbBundle.getMessage(ImplementOverrideMethodGenerator.class, isImplement ? "LBL_implement_method" : "LBL_override_method"); //NOI18N
138
    }
145
    }
139
146
140
    public void invoke(JTextComponent component) {
147
    public void invoke() {
141
        final ImplementOverridePanel panel = new ImplementOverridePanel(description, isImplement);
148
        final ImplementOverridePanel panel = new ImplementOverridePanel(description, isImplement);
142
        DialogDescriptor dialogDescriptor = GeneratorUtils.createDialogDescriptor(panel, 
149
        DialogDescriptor dialogDescriptor = GeneratorUtils.createDialogDescriptor(panel, 
143
                NbBundle.getMessage(ConstructorGenerator.class, isImplement ?  "LBL_generate_implement" : "LBL_generate_override")); //NOI18N  //NOI18N
150
                NbBundle.getMessage(ConstructorGenerator.class, isImplement ?  "LBL_generate_implement" : "LBL_generate_override")); //NOI18N  //NOI18N
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/ui/GenerateCodePanel.form (-71 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
6
      <Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
7
        <LineBorder>
8
          <Color PropertyName="color" blue="40" green="40" red="40" type="rgb"/>
9
        </LineBorder>
10
      </Border>
11
    </Property>
12
  </Properties>
13
  <AuxValues>
14
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
15
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
16
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
17
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
18
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
19
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="1"/>
20
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
21
  </AuxValues>
22
23
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
24
  <SubComponents>
25
    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
26
      <Properties>
27
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
28
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
29
            <EmptyBorder bottom="4" left="4" right="4" top="2"/>
30
          </Border>
31
        </Property>
32
      </Properties>
33
      <AuxValues>
34
        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
35
      </AuxValues>
36
      <Constraints>
37
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
38
          <BorderConstraints direction="Center"/>
39
        </Constraint>
40
      </Constraints>
41
42
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
43
      <SubComponents>
44
        <Component class="javax.swing.JList" name="jList1">
45
          <Events>
46
            <EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="listKeyReleased"/>
47
            <EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseReleased"/>
48
          </Events>
49
        </Component>
50
      </SubComponents>
51
    </Container>
52
    <Component class="javax.swing.JLabel" name="jLabel1">
53
      <Properties>
54
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
55
          <ResourceString bundle="org/netbeans/modules/java/editor/codegen/Bundle.properties" key="LBL_generate_code" replaceFormat="org.openide.util.NbBundle.getMessage(CodeGenerator.class, &quot;{key}&quot;)"/>
56
        </Property>
57
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
58
          <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
59
            <EmptyBorder bottom="4" left="4" right="4" top="4"/>
60
          </Border>
61
        </Property>
62
        <Property name="opaque" type="boolean" value="true"/>
63
      </Properties>
64
      <Constraints>
65
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
66
          <BorderConstraints direction="First"/>
67
        </Constraint>
68
      </Constraints>
69
    </Component>
70
  </SubComponents>
71
</Form>
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/ui/GenerateCodePanel.java (-187 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.java.editor.codegen.ui;
43
44
import java.awt.Color;
45
import java.awt.Component;
46
import java.awt.event.KeyEvent;
47
import java.util.List;
48
import javax.swing.DefaultListCellRenderer;
49
import javax.swing.DefaultListModel;
50
import javax.swing.JList;
51
import javax.swing.KeyStroke;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.modules.java.editor.codegen.CodeGenerator;
54
import org.netbeans.modules.java.editor.overridden.PopupUtil;
55
import org.openide.util.Utilities;
56
57
/**
58
 *
59
 * @author Dusan Balek, Jan Lahoda
60
 */
61
public class GenerateCodePanel extends javax.swing.JPanel {
62
63
    private JTextComponent component;
64
    
65
    /** Creates new form GenerateCodePanel */
66
    public GenerateCodePanel(JTextComponent component, List<? extends CodeGenerator> generators) {
67
        this.component = component;
68
        initComponents();
69
        setFocusable(false);
70
        setNextFocusableComponent(jList1);
71
        setBackground(jList1.getBackground());
72
        jScrollPane1.setBackground(jList1.getBackground());
73
        jList1.setModel(createModel(generators));
74
        jList1.setSelectedIndex(0);
75
        jList1.setVisibleRowCount(generators.size() > 8 ? 8 : generators.size());
76
        jList1.setCellRenderer(new Renderer(jList1));
77
        jList1.grabFocus();
78
    }
79
    
80
    /** This method is called from within the constructor to
81
     * initialize the form.
82
     * WARNING: Do NOT modify this code. The content of this method is
83
     * always regenerated by the Form Editor.
84
     */
85
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
86
    private void initComponents() {
87
88
        jScrollPane1 = new javax.swing.JScrollPane();
89
        jList1 = new javax.swing.JList();
90
        jLabel1 = new javax.swing.JLabel();
91
92
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(64, 64, 64)));
93
        setLayout(new java.awt.BorderLayout());
94
95
        jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 4, 4, 4));
96
97
        jList1.addKeyListener(new java.awt.event.KeyAdapter() {
98
            public void keyReleased(java.awt.event.KeyEvent evt) {
99
                listKeyReleased(evt);
100
            }
101
        });
102
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
103
            public void mouseReleased(java.awt.event.MouseEvent evt) {
104
                listMouseReleased(evt);
105
            }
106
        });
107
        jScrollPane1.setViewportView(jList1);
108
109
        add(jScrollPane1, java.awt.BorderLayout.CENTER);
110
111
        jLabel1.setText(org.openide.util.NbBundle.getMessage(CodeGenerator.class, "LBL_generate_code")); // NOI18N
112
        jLabel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4));
113
        jLabel1.setOpaque(true);
114
        add(jLabel1, java.awt.BorderLayout.PAGE_START);
115
    }// </editor-fold>//GEN-END:initComponents
116
117
    private void listMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseReleased
118
        invokeSelected();
119
    }//GEN-LAST:event_listMouseReleased
120
121
    private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
122
        KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
123
        if (ks.getKeyCode() == KeyEvent.VK_ENTER || ks.getKeyCode() == KeyEvent.VK_SPACE)
124
            invokeSelected();
125
    }//GEN-LAST:event_listKeyReleased
126
    
127
    
128
    // Variables declaration - do not modify//GEN-BEGIN:variables
129
    public javax.swing.JLabel jLabel1;
130
    public javax.swing.JList jList1;
131
    public javax.swing.JScrollPane jScrollPane1;
132
    // End of variables declaration//GEN-END:variables
133
    
134
    private DefaultListModel createModel(List<? extends CodeGenerator> generators) {
135
        DefaultListModel model = new DefaultListModel();
136
        for (CodeGenerator generator : generators)
137
            model.addElement(generator);
138
        return model;
139
    }
140
    
141
    private void invokeSelected() {
142
        PopupUtil.hidePopup();
143
        if (Utilities.isMac()) {
144
            // see issue #115106
145
            component.requestFocus();
146
        }
147
        Object value = jList1.getSelectedValue();
148
        if (value instanceof CodeGenerator)
149
            ((CodeGenerator)value).invoke(component);
150
    }
151
            
152
    private static class Renderer extends DefaultListCellRenderer {
153
        
154
        private static int DARKER_COLOR_COMPONENT = 5;
155
        
156
        private Color fgColor;
157
        private Color bgColor;
158
        private Color bgColorDarker;
159
        private Color bgSelectionColor;
160
        private Color fgSelectionColor;
161
        
162
        public Renderer(JList list) {
163
            setFont(list.getFont());
164
            fgColor = list.getForeground();
165
            bgColor = list.getBackground();
166
            bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
167
                    Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
168
                    Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
169
            bgSelectionColor = list.getSelectionBackground();
170
            fgSelectionColor = list.getSelectionForeground();
171
        }
172
        
173
        @Override
174
        public Component getListCellRendererComponent(JList list, Object value, int index,
175
                boolean isSelected, boolean hasFocus) {
176
            if (isSelected) {
177
                setForeground(fgSelectionColor);
178
                setBackground(bgSelectionColor);
179
            } else {
180
                setForeground(fgColor);
181
                setBackground(index % 2 == 0 ? bgColor : bgColorDarker);
182
            }            
183
            setText(value instanceof CodeGenerator ? ((CodeGenerator)value).getDisplayName() : value.toString());
184
            return this;
185
        }        
186
    }
187
}
(-)a/java.editor/src/org/netbeans/modules/java/editor/resources/layer.xml (-2 / +5 lines)
Lines 51-57 Link Here
51
        </folder>
51
        </folder>
52
        <folder name="Source">
52
        <folder name="Source">
53
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.java.editor.resources.Bundle"/>
53
            <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.java.editor.resources.Bundle"/>
54
            <file name="org-netbeans-modules-java-editor-codegen-GenerateCodeAction$GlobalAction.instance"/>
55
            <file name="org-netbeans-modules-editor-java-JavaKit$JavaFixImports$GlobalAction.instance"/>
54
            <file name="org-netbeans-modules-editor-java-JavaKit$JavaFixImports$GlobalAction.instance"/>
56
        </folder>
55
        </folder>
57
    </folder>
56
    </folder>
Lines 285-291 Link Here
285
                    </file>
284
                    </file>
286
                </folder>
285
                </folder>
287
                
286
                
288
                <folder name="codegenerators">
287
                <folder name="CodeGeneratorContextProviders">
288
                    <file name="org-netbeans-modules-java-editor-codegen-ContextProvider.instance"/>
289
                </folder>
290
                
291
                <folder name="CodeGenerators">
289
                    <file name="org-netbeans-modules-java-editor-codegen-ConstructorGenerator$Factory.instance">
292
                    <file name="org-netbeans-modules-java-editor-codegen-ConstructorGenerator$Factory.instance">
290
                        <attr name="position" intvalue="100"/>
293
                        <attr name="position" intvalue="100"/>
291
                    </file>
294
                    </file>
(-)a/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/jelly/GenerateCodeOperator.java (-1 / +1 lines)
Lines 37-43 Link Here
37
import org.netbeans.jellytools.EditorOperator;
37
import org.netbeans.jellytools.EditorOperator;
38
import org.netbeans.jemmy.operators.JDialogOperator;
38
import org.netbeans.jemmy.operators.JDialogOperator;
39
import org.netbeans.jemmy.operators.JListOperator;
39
import org.netbeans.jemmy.operators.JListOperator;
40
import org.netbeans.modules.java.editor.codegen.CodeGenerator;
40
import org.netbeans.spi.editor.codegen.CodeGenerator;
41
import org.netbeans.modules.java.editor.codegen.ConstructorGenerator;
41
import org.netbeans.modules.java.editor.codegen.ConstructorGenerator;
42
import org.netbeans.modules.java.editor.codegen.DelegateMethodGenerator;
42
import org.netbeans.modules.java.editor.codegen.DelegateMethodGenerator;
43
import org.netbeans.modules.java.editor.codegen.EqualsHashCodeGenerator;
43
import org.netbeans.modules.java.editor.codegen.EqualsHashCodeGenerator;

Return to bug 134239