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

(-)a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java (-1 / +43 lines)
Lines 40-52 Link Here
40
package org.netbeans.modules.openide.awt;
40
package org.netbeans.modules.openide.awt;
41
41
42
import java.awt.event.ActionListener;
42
import java.awt.event.ActionListener;
43
import java.util.Arrays;
43
import java.util.Map.Entry;
44
import java.util.Set;
44
import java.util.Set;
45
import javax.annotation.processing.Processor;
45
import javax.annotation.processing.Processor;
46
import javax.annotation.processing.RoundEnvironment;
46
import javax.annotation.processing.RoundEnvironment;
47
import javax.annotation.processing.SupportedAnnotationTypes;
47
import javax.annotation.processing.SupportedAnnotationTypes;
48
import javax.annotation.processing.SupportedSourceVersion;
48
import javax.annotation.processing.SupportedSourceVersion;
49
import javax.lang.model.SourceVersion;
49
import javax.lang.model.SourceVersion;
50
import javax.lang.model.element.AnnotationMirror;
51
import javax.lang.model.element.AnnotationValue;
50
import javax.lang.model.element.Element;
52
import javax.lang.model.element.Element;
51
import javax.lang.model.element.ElementKind;
53
import javax.lang.model.element.ElementKind;
52
import javax.lang.model.element.ExecutableElement;
54
import javax.lang.model.element.ExecutableElement;
Lines 55-60 Link Here
55
import javax.lang.model.element.VariableElement;
57
import javax.lang.model.element.VariableElement;
56
import javax.lang.model.type.DeclaredType;
58
import javax.lang.model.type.DeclaredType;
57
import javax.lang.model.util.ElementFilter;
59
import javax.lang.model.util.ElementFilter;
60
import javax.lang.model.util.Elements;
61
import javax.lang.model.util.Types;
62
import org.openide.awt.ActionReference;
63
import org.openide.awt.ActionReference.Meta;
58
import org.openide.awt.ActionRegistration;
64
import org.openide.awt.ActionRegistration;
59
import org.openide.filesystems.annotations.LayerBuilder.File;
65
import org.openide.filesystems.annotations.LayerBuilder.File;
60
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
66
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
Lines 96-101 Link Here
96
            }
102
            }
97
            f.boolvalue("noIconInMenu", !ar.iconInMenu());
103
            f.boolvalue("noIconInMenu", !ar.iconInMenu());
98
            f.write();
104
            f.write();
105
106
            ActionReference ref = e.getAnnotation(ActionReference.class);
107
            if (ref != null) {
108
                String shadid = ref.id().length() == 0 ? id : ref.id();
109
                assert ref.refcategory().length() == 0;
110
                assert ref.refid().length() == 0;
111
                File shad = layer(e).file(ref.path() + "/" + shadid + ".shadow");
112
                shad.stringvalue("originalFile", f.getPath());
113
                shad.write();
114
            }
115
            Elements eu = processingEnv.getElementUtils();
116
            Types tu = processingEnv.getTypeUtils();
117
            for (AnnotationMirror am : e.getAnnotationMirrors()) {
118
                System.err.println("am: " + am);
119
                String s = am.toString().substring(1);
120
                int open = s.indexOf('(');
121
                if (open != -1) {
122
                    s = s.substring(0, open);
123
                }
124
                System.err.println("name: " + s);
125
                TypeElement anno = eu.getTypeElement(s);
126
                Meta meta = anno.getAnnotation(ActionReference.Meta.class);
127
                if (meta == null) {
128
                    continue;
129
                }
130
                System.err.println("me: " + meta);
131
                String path = meta.path();
132
                for (Entry<? extends ExecutableElement, ? extends AnnotationValue> et : am.getElementValues().entrySet()) {
133
                    String v = et.getValue().toString().substring(1);
134
                    v = v.substring(0, v.length() - 1);
135
                    path = path.replace(et.getKey().toString(), v);
136
                }
137
                File shad = layer(e).file(path + "/" + id + ".shadow");
138
                shad.stringvalue("originalFile", f.getPath());
139
                shad.write();
140
            }
99
        }
141
        }
100
        return true;
142
        return true;
101
    }
143
    }
(-)7b2eaa138aec (+66 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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 2009 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
import org.openide.awt.ActionReference.Meta;
47
48
/**
49
 *
50
 * @author Jaroslav Tulach <jtulach@netbeans.org>
51
 */
52
@Target(ElementType.TYPE)
53
@Retention(RetentionPolicy.SOURCE)
54
//@Meta(path="${path}")
55
public @interface ActionReference {
56
    String refcategory() default "";
57
    String refid() default "";
58
    String path();
59
    String id() default "";
60
61
    @Target(ElementType.ANNOTATION_TYPE)
62
    @Retention(RetentionPolicy.CLASS)
63
    public @interface Meta {
64
        String path();
65
    }
66
}
(-)a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java (-2 / +28 lines)
Lines 41-51 Link Here
41
41
42
import java.awt.event.ActionEvent;
42
import java.awt.event.ActionEvent;
43
import java.awt.event.ActionListener;
43
import java.awt.event.ActionListener;
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
44
import java.util.Collection;
48
import java.util.Collection;
45
import javax.swing.AbstractAction;
49
import javax.swing.AbstractAction;
46
import javax.swing.Action;
50
import javax.swing.Action;
47
import javax.swing.ActionMap;
51
import javax.swing.ActionMap;
48
import org.netbeans.junit.NbTestCase;
52
import org.netbeans.junit.NbTestCase;
53
import org.openide.awt.ActionReference;
49
import org.openide.awt.ActionRegistration;
54
import org.openide.awt.ActionRegistration;
50
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
56
import org.openide.filesystems.FileUtil;
Lines 102-107 Link Here
102
        id="my-action",
107
        id="my-action",
103
        key="klic"
108
        key="klic"
104
    )
109
    )
110
    @ActionReference(
111
        path="Loaders/text/x-test/Actions"
112
    )
105
    public static final class Callback implements ActionListener {
113
    public static final class Callback implements ActionListener {
106
        static int cnt;
114
        static int cnt;
107
        public void actionPerformed(ActionEvent e) {
115
        public void actionPerformed(ActionEvent e) {
Lines 111-118 Link Here
111
119
112
    public void testCallbackAction() throws Exception {
120
    public void testCallbackAction() throws Exception {
113
        FileObject fo = FileUtil.getConfigFile(
121
        FileObject fo = FileUtil.getConfigFile(
114
            "Actions/Tools/my-action.instance"
122
            "Loaders/text/x-test/Actions/my-action.shadow"
115
        );
123
        );
124
        assertNotNull("Shadow found", fo);
125
        String orig = (String) fo.getAttribute("originalFile");
126
        assertNotNull("reference defined", orig);
127
        
128
        fo = FileUtil.getConfigFile(orig);
116
        assertNotNull("File found", fo);
129
        assertNotNull("File found", fo);
117
        Object obj = fo.getAttribute("instanceCreate");
130
        Object obj = fo.getAttribute("instanceCreate");
118
        assertNotNull("Attribute present", obj);
131
        assertNotNull("Attribute present", obj);
Lines 145-155 Link Here
145
        assertEquals("Global Action called", 200, Callback.cnt);
158
        assertEquals("Global Action called", 200, Callback.cnt);
146
    }
159
    }
147
160
161
    @ActionReference.Meta(path="Loaders/mimeType()/Actions")
162
    @Retention(RetentionPolicy.SOURCE)
163
    @Target(ElementType.TYPE)
164
    public @interface MimeAction {
165
        String mimeType();
166
    }
167
 
148
    @ActionRegistration(
168
    @ActionRegistration(
149
        category="Tools",
169
        category="Tools",
150
        displayName="#OnInt",
170
        displayName="#OnInt",
151
        id="on-int"
171
        id="on-int"
152
    )
172
    )
173
    @MimeAction(mimeType="text/mime")
153
    public static final class Context implements ActionListener {
174
    public static final class Context implements ActionListener {
154
        private final int context;
175
        private final int context;
155
        
176
        
Lines 167-174 Link Here
167
188
168
    public void testContextAction() throws Exception {
189
    public void testContextAction() throws Exception {
169
        FileObject fo = FileUtil.getConfigFile(
190
        FileObject fo = FileUtil.getConfigFile(
170
            "Actions/Tools/on-int.instance"
191
            "Loaders/text/mime/Actions/on-int.shadow"
171
        );
192
        );
193
        assertNotNull("Shadow found", fo);
194
        String orig = (String) fo.getAttribute("originalFile");
195
        assertNotNull("reference defined", orig);
196
197
        fo = FileUtil.getConfigFile(orig);
172
        assertNotNull("File found", fo);
198
        assertNotNull("File found", fo);
173
        Object obj = fo.getAttribute("instanceCreate");
199
        Object obj = fo.getAttribute("instanceCreate");
174
        assertNotNull("Attribute present", obj);
200
        assertNotNull("Attribute present", obj);

Return to bug 166658