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

(-)a/openide.awt/nbproject/project.properties (+1 lines)
Lines 47-49 Link Here
47
javadoc.apichanges=${basedir}/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
48
48
49
spec.version.base=7.4.0
49
spec.version.base=7.4.0
50
cp.extra=${nb_all}/libs.javacapi/external/javac-api-nb-7.0-b07.jar
(-)a/openide.awt/nbproject/project.xml (+8 lines)
Lines 47-52 Link Here
47
            <code-name-base>org.openide.awt</code-name-base>
47
            <code-name-base>org.openide.awt</code-name-base>
48
            <module-dependencies>
48
            <module-dependencies>
49
                <dependency>
49
                <dependency>
50
                    <code-name-base>org.openide.filesystems</code-name-base>
51
                    <build-prerequisite/>
52
                    <compile-dependency/>
53
                    <run-dependency>
54
                        <specification-version>7.13</specification-version>
55
                    </run-dependency>
56
                </dependency>
57
                <dependency>
50
                    <code-name-base>org.openide.util</code-name-base>
58
                    <code-name-base>org.openide.util</code-name-base>
51
                    <build-prerequisite/>
59
                    <build-prerequisite/>
52
                    <compile-dependency/>
60
                    <compile-dependency/>
(-)a/openide.awt/src/org/netbeans/modules/openide/awt/ActionRegistrationProcessor.java (+88 lines)
Line 0 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.modules.openide.awt;
41
42
import java.util.Set;
43
import javax.annotation.processing.Processor;
44
import javax.annotation.processing.RoundEnvironment;
45
import javax.annotation.processing.SupportedAnnotationTypes;
46
import javax.annotation.processing.SupportedSourceVersion;
47
import javax.lang.model.SourceVersion;
48
import javax.lang.model.element.Element;
49
import javax.lang.model.element.TypeElement;
50
import javax.swing.Action;
51
import org.openide.awt.ActionRegistration;
52
import org.openide.filesystems.annotations.LayerBuilder.File;
53
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
54
import org.openide.filesystems.annotations.LayerGenerationException;
55
import org.openide.util.Utilities;
56
import org.openide.util.lookup.ServiceProvider;
57
58
/**
59
 *
60
 * @author Jaroslav Tulach <jtulach@netbeans.org>
61
 */
62
@ServiceProvider(service=Processor.class)
63
@SupportedSourceVersion(SourceVersion.RELEASE_6)
64
@SupportedAnnotationTypes("org.openide.awt.ActionRegistration")
65
public class ActionRegistrationProcessor extends LayerGeneratingProcessor {
66
    @Override
67
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
68
        for (Element e : roundEnv.getElementsAnnotatedWith(ActionRegistration.class)) {
69
            ActionRegistration ar = e.getAnnotation(ActionRegistration.class);
70
            File action = layer(e).instanceFile("Actions/" + ar.category(), null, Action.class);
71
            action.write();
72
            for (ActionRegistration.Menu menu : ar.menus()) {
73
                layer(e).shadowFile(action.getPath(), "Menu/" + menu.path(), null).position(menu.position()).write();
74
            }
75
            for (ActionRegistration.Toolbar tb : ar.toolbars()) {
76
                layer(e).shadowFile(action.getPath(), "Toolbar/" + tb.path(), null).position(tb.position()).write();
77
            }
78
            for (ActionRegistration.Shortcut cut : ar.shortcuts()) {
79
                String key = cut.key();
80
                if (Utilities.stringToKey(key) == null) {
81
                    throw new LayerGenerationException(key + " is not a valid shortcut name", e);
82
                }
83
                layer(e).shadowFile(action.getPath(), "Shortcut", key).write();
84
            }
85
        }
86
        return true;
87
    }
88
}
(-)a/openide.awt/src/org/openide/awt/ActionRegistration.java (+81 lines)
Line 0 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.openide.awt;
41
42
import java.lang.annotation.ElementType;
43
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
45
import java.lang.annotation.Target;
46
47
/**
48
 *
49
 * @author Jaroslav Tulach <jtulach@netbeans.org>
50
 */
51
@Retention(RetentionPolicy.SOURCE)
52
@Target({ ElementType.TYPE, ElementType.METHOD })
53
public @interface ActionRegistration {
54
    String category();
55
56
    String iconbase() default ""; // XXX unused
57
    String displayName(); // XXX unused
58
    boolean noIconInMenu() default false; // XXX unused
59
60
    String actionMapKey() default ""; // XXX unused
61
    Class<?>[] contextTypes() default {}; // XXX unused
62
63
    Menu[] menus() default {};
64
    Toolbar[] toolbars() default {};
65
    Shortcut[] shortcuts() default {};
66
67
    @Target({})
68
    public @interface Menu {
69
        String path();
70
        int position();
71
    }
72
    @Target({})
73
    public @interface Toolbar {
74
        String path();
75
        int position();
76
    }
77
    @Target({})
78
    public @interface Shortcut {
79
        String key();
80
    }
81
}
(-)a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionRegistrationProcessorTest.java (+175 lines)
Line 0 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 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.openide.awt;
43
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
48
import javax.swing.AbstractAction;
49
import javax.swing.Action;
50
import org.netbeans.junit.NbTestCase;
51
import org.openide.awt.ActionRegistration;
52
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileSystem;
54
import org.openide.filesystems.Repository;
55
import org.openide.util.ContextAwareAction;
56
import org.openide.util.Lookup;
57
58
/**
59
 *
60
 * @author Jaroslav Tulach
61
 */
62
public class ActionRegistrationProcessorTest extends NbTestCase implements PropertyChangeListener {
63
    private FileObject folder;
64
    private int changeCounter;
65
    
66
    public ActionRegistrationProcessorTest(String testName) {
67
        super(testName);
68
    }
69
    
70
    @Override
71
    protected void setUp() throws Exception {
72
        FileSystem fs = Repository.getDefault().getDefaultFileSystem();
73
        folder = fs.findResource("Toolbar/Edit/");
74
        assertNotNull("testing layer is loaded: ", folder);
75
76
        myListenerCalled = 0;
77
        myListenerCounter = 0;
78
        MyAction.last = null;
79
    }
80
    
81
    @Override
82
    protected boolean runInEQ() {
83
        return true;
84
    }
85
86
    public void testIconIsCorrect() throws Exception {
87
        // XXX test in no way matches what is being actually registered, rewrite...
88
        myListenerCounter = 0;
89
        Action a = readAction("testIconIsCorrect.instance");
90
        
91
        assertNotNull("Action created", a);
92
        assertEquals("No myListener called", 0, myListenerCounter);
93
        
94
        Object name = a.getValue(a.NAME);
95
        Object mnem = a.getValue(a.MNEMONIC_KEY);
96
        Object smallIcon = a.getValue(a.SMALL_ICON);
97
        //Object icon = a.getValue(a.ICON)
98
            
99
        assertEquals("Right localized name", "Icon &Name Action", name);
100
        assertEquals("Mnemonic is N", Character.valueOf('N'), mnem);
101
        assertNotNull("small icon present", smallIcon);
102
103
        
104
        assertTrue("Always enabled", a.isEnabled());
105
        a.setEnabled(false);
106
        assertTrue("Still Always enabled", a.isEnabled());
107
108
        a.actionPerformed(new ActionEvent(this, 0, "kuk"));
109
110
        assertEquals("Listener invoked", 1, myListenerCounter);
111
        
112
        
113
        assertEquals("No icon in menu", Boolean.TRUE, a.getValue("noIconInMenu"));
114
    }
115
116
    
117
    private static int myListenerCounter;
118
    private static int myListenerCalled;
119
    @ActionRegistration(category="Testing", displayName="#Always",
120
    menus=@ActionRegistration.Menu(path="Edit", position=30),
121
    toolbars=@ActionRegistration.Toolbar(path="Edit", position=30),
122
    shortcuts=@ActionRegistration.Shortcut(key="D-X"))
123
    private static Action myAction() {
124
        myListenerCounter++;
125
        return new MyAction();
126
    }
127
    
128
    private Action readAction(String fileName) throws Exception {
129
        FileObject fo = this.folder.getFileObject(fileName);
130
        assertNotNull("file " + fileName, fo);
131
        
132
        Object obj = fo.getAttribute("instanceCreate");
133
        assertNotNull("File object has not null instanceCreate attribute", obj);
134
        
135
        if (!(obj instanceof Action)) {
136
            fail("Object needs to be action: " + obj);
137
        }
138
        
139
        return (Action)obj;
140
    }
141
142
    public void propertyChange(PropertyChangeEvent evt) {
143
        changeCounter++;
144
    }
145
146
    private static class MyListener implements ActionListener {
147
        public void actionPerformed(ActionEvent e) {
148
            myListenerCalled++;
149
        }
150
    }
151
    private static class MyAction extends AbstractAction {
152
        static MyAction last;
153
154
        MyAction() {
155
            last = this;
156
            setEnabled(false);
157
        }
158
159
        public void actionPerformed(ActionEvent e) {
160
            myListenerCalled++;
161
        }
162
    }
163
    private static class MyContextAction extends MyAction
164
    implements ContextAwareAction {
165
        static int clones;
166
        static Lookup lkp;
167
168
        public Action createContextAwareInstance(Lookup actionContext) {
169
            clones++;
170
            lkp = actionContext;
171
            return new MyContextAction();
172
        }
173
    }
174
175
}
(-)a/utilities/src/org/netbeans/modules/search/FindInFilesAction.java (+8 lines)
Lines 58-63 Link Here
58
import javax.swing.event.ChangeListener;
58
import javax.swing.event.ChangeListener;
59
import org.openide.DialogDisplayer;
59
import org.openide.DialogDisplayer;
60
import org.openide.NotifyDescriptor;
60
import org.openide.NotifyDescriptor;
61
import org.openide.awt.ActionRegistration;
61
import org.openide.util.ContextAwareAction;
62
import org.openide.util.ContextAwareAction;
62
import org.openide.util.Lookup;
63
import org.openide.util.Lookup;
63
import org.openide.util.Mutex;
64
import org.openide.util.Mutex;
Lines 91-96 Link Here
91
 *
92
 *
92
 * @author  Marian Petras
93
 * @author  Marian Petras
93
 */
94
 */
95
@ActionRegistration(
96
    category="Edit",
97
    iconbase="org/openide/resources/actions/find.gif",
98
    displayName="#LBL_Action_FindInFiles",
99
    menus = @ActionRegistration.Menu(path="Edit", position=2400),
100
    shortcuts = @ActionRegistration.Shortcut(key="DS-F")
101
)
94
public class FindInFilesAction extends CallableSystemAction
102
public class FindInFilesAction extends CallableSystemAction
95
                               implements ContextAwareAction, ChangeListener {
103
                               implements ContextAwareAction, ChangeListener {
96
104
(-)a/utilities/src/org/netbeans/modules/utilities/Layer.xml (-6 lines)
Lines 229-235 Link Here
229
        -->
229
        -->
230
        
230
        
231
        <folder name="Edit">
231
        <folder name="Edit">
232
            <file name="org-netbeans-modules-search-FindInFilesAction.instance"/>
233
            <file name="org-netbeans-modules-search-ReplaceInFilesAction.instance"/>
232
            <file name="org-netbeans-modules-search-ReplaceInFilesAction.instance"/>
234
        </folder> <!-- Edit -->
233
        </folder> <!-- Edit -->
235
234
Lines 256-264 Link Here
256
            <file name="sep-before-reposearch.instance">
255
            <file name="sep-before-reposearch.instance">
257
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
256
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
258
                <attr name="position" intvalue="2300"/>
257
                <attr name="position" intvalue="2300"/>
259
            </file>
260
            <file name="org-netbeans-modules-search-FindInFilesAction.instance">
261
                <attr name="position" intvalue="2400"/>
262
            </file>
258
            </file>
263
            <file name="org-netbeans-modules-search-ReplaceInFilesAction.instance">
259
            <file name="org-netbeans-modules-search-ReplaceInFilesAction.instance">
264
                <attr name="position" intvalue="2500"/>
260
                <attr name="position" intvalue="2500"/>
Lines 303-310 Link Here
303
    	    <attr name="instanceClass" stringvalue="org.netbeans.modules.openfile.OpenFileAction"/>
299
    	    <attr name="instanceClass" stringvalue="org.netbeans.modules.openfile.OpenFileAction"/>
304
	</file>
300
	</file>
305
        -->
301
        -->
306
        <file name="DS-F.shadow">
307
    	    <attr name="originalFile" stringvalue="Actions/Edit/org-netbeans-modules-search-FindInFilesAction.instance"/>
308
	</file>
302
	</file>
309
        <file name="DS-H.shadow">
303
        <file name="DS-H.shadow">
310
    	    <attr name="originalFile" stringvalue="Actions/Edit/org-netbeans-modules-search-ReplaceInFilesAction.instance"/>
304
    	    <attr name="originalFile" stringvalue="Actions/Edit/org-netbeans-modules-search-ReplaceInFilesAction.instance"/>

Return to bug 149136