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

(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModel.java (-44 / +17 lines)
Lines 54-60 Link Here
54
import java.util.Collections;
54
import java.util.Collections;
55
import java.util.HashMap;
55
import java.util.HashMap;
56
import java.util.HashSet;
56
import java.util.HashSet;
57
import java.util.LinkedHashMap;
58
import java.util.List;
57
import java.util.List;
59
import java.util.Map;
58
import java.util.Map;
60
import java.util.Set;
59
import java.util.Set;
Lines 68-74 Link Here
68
import org.openide.WizardDescriptor;
67
import org.openide.WizardDescriptor;
69
import org.openide.awt.ActionReference;
68
import org.openide.awt.ActionReference;
70
import org.openide.filesystems.FileObject;
69
import org.openide.filesystems.FileObject;
71
import org.openide.filesystems.FileSystem;
72
import org.openide.filesystems.FileUtil;
70
import org.openide.filesystems.FileUtil;
73
import org.openide.modules.SpecificationVersion;
71
import org.openide.modules.SpecificationVersion;
74
import org.openide.util.NbBundle;
72
import org.openide.util.NbBundle;
Lines 173-179 Link Here
173
            SpecificationVersion current = getModuleInfo().getDependencyVersion("org.openide.awt");
171
            SpecificationVersion current = getModuleInfo().getDependencyVersion("org.openide.awt");
174
            actionProxy = current == null || current.compareTo(new SpecificationVersion("7.3")) >= 0; // NOI18N
172
            actionProxy = current == null || current.compareTo(new SpecificationVersion("7.3")) >= 0; // NOI18N
175
            actionContext = current == null || current.compareTo(new SpecificationVersion("7.10")) >= 0; // NOI18N
173
            actionContext = current == null || current.compareTo(new SpecificationVersion("7.10")) >= 0; // NOI18N
176
            annotations = current == null || current.compareTo(new SpecificationVersion("7.27")) >= 0; // NOI18N
174
            annotations = current == null || current.compareTo(new SpecificationVersion("7.28")) >= 0; // NOI18N
177
        } catch (IOException ex) {
175
        } catch (IOException ex) {
178
            Logger.getLogger(DataModel.class.getName()).log(Level.INFO, null, ex);
176
            Logger.getLogger(DataModel.class.getName()).log(Level.INFO, null, ex);
179
            actionProxy = false;
177
            actionProxy = false;
Lines 277-302 Link Here
277
            if (globalMenuItemEnabled) {
275
            if (globalMenuItemEnabled) {
278
                refs.add(createActionReference(
276
                refs.add(createActionReference(
279
                    gmiParentMenuPath,
277
                    gmiParentMenuPath,
280
                    gmiSeparatorBefore,
278
                    gmiSeparatorBefore ? Position.toInteger(gmiPosition, getProject(), gmiParentMenuPath, Boolean.TRUE) : -1,
281
                    gmiSeparatorAfter, 
279
                    gmiSeparatorAfter ? Position.toInteger(gmiPosition, getProject(), gmiParentMenuPath, Boolean.FALSE) : -1,
282
                    Position.toInteger(gmiPosition, getProject(), gmiParentMenuPath),
280
                    Position.toInteger(gmiPosition, getProject(), gmiParentMenuPath),
283
                    null
281
                    null
284
                ));
282
                ));
285
                generateAnnotationSeparators(
286
                    gmiParentMenuPath,
287
                    dashedFqClassName,
288
                    gmiSeparatorBefore,
289
                    gmiSeparatorAfter,
290
                    gmiPosition
291
                );
292
            }
283
            }
293
284
294
            // create layer entry for toolbar button
285
            // create layer entry for toolbar button
295
            if (toolbarEnabled) {
286
            if (toolbarEnabled) {
296
                refs.add(createActionReference(
287
                refs.add(createActionReference(
297
                    toolbar,
288
                    toolbar,
298
                    false,
289
                    -1,
299
                    false,
290
                    -1,
300
                    Position.toInteger(toolbarPosition, getProject(), toolbar),
291
                    Position.toInteger(toolbarPosition, getProject(), toolbar),
301
                    null
292
                    null
302
                ));
293
                ));
Lines 309-316 Link Here
309
                    refs.add(
300
                    refs.add(
310
                        createActionReference(
301
                        createActionReference(
311
                            parentPath,
302
                            parentPath,
312
                            false,
303
                            -1,
313
                            false,
304
                            -1,
314
                            -1,
305
                            -1,
315
                            keyStroke
306
                            keyStroke
316
                        )
307
                        )
Lines 322-339 Link Here
322
            if (ftContextEnabled) {
313
            if (ftContextEnabled) {
323
                refs.add(createActionReference(
314
                refs.add(createActionReference(
324
                    ftContextType,
315
                    ftContextType,
325
                    ftContextSeparatorBefore,
316
                    ftContextSeparatorBefore ? Position.toInteger(ftContextPosition, getProject(), toolbar, Boolean.TRUE) : -1,
326
                    ftContextSeparatorAfter,
317
                    ftContextSeparatorAfter ? Position.toInteger(ftContextPosition, getProject(), toolbar, Boolean.FALSE) : -1,
327
                    Position.toInteger(ftContextPosition, getProject(), toolbar),
318
                    Position.toInteger(ftContextPosition, getProject(), toolbar),
328
                    null
319
                    null
329
                ));
320
                ));
330
                generateAnnotationSeparators(
331
                    ftContextType,
332
                    dashedFqClassName,
333
                    ftContextSeparatorBefore,
334
                    ftContextSeparatorAfter,
335
                    ftContextPosition
336
                );
337
            }
321
            }
338
            /*
322
            /*
339
            // create editor context menu item
323
            // create editor context menu item
Lines 478-500 Link Here
478
        }
462
        }
479
    }
463
    }
480
    
464
    
481
    private void generateAnnotationSeparators(
482
        String parentPath,
483
        String dashedPkgName,
484
        boolean before,
485
        boolean after,
486
        Position bounds
487
    ) {
488
        if (before) {
489
            String sepName = dashedPkgName + "-separatorBefore.instance"; // NOI18N
490
            generateSeparator(parentPath, sepName, Position.toInteger(bounds, getProject(), parentPath, Boolean.TRUE));
491
        }
492
        if (after) {
493
            String sepName = dashedPkgName + "-separatorAfter.instance"; // NOI18N
494
            generateSeparator(parentPath, sepName, Position.toInteger(bounds, getProject(), parentPath, Boolean.FALSE));
495
        }
496
        
497
    }
498
    /**
465
    /**
499
     * Just a helper convenient method for cleaner code.
466
     * Just a helper convenient method for cleaner code.
500
     */
467
     */
Lines 667-674 Link Here
667
634
668
    static ActionReference createActionReference(
635
    static ActionReference createActionReference(
669
        final String parentPath, 
636
        final String parentPath, 
670
        boolean beforeSep, 
637
        final int beforeSep, 
671
        boolean afterSep, 
638
        final int afterSep, 
672
        final int position, 
639
        final int position, 
673
        final String name
640
        final String name
674
    ) {
641
    ) {
Lines 681-686 Link Here
681
                if (method.getName().equals("position")) {
648
                if (method.getName().equals("position")) {
682
                    return position;
649
                    return position;
683
                }
650
                }
651
                if (method.getName().equals("separatorBefore")) {
652
                    return beforeSep;
653
                }
654
                if (method.getName().equals("separatorAfter")) {
655
                    return afterSep;
656
                }
684
                if (method.getName().equals("name")) {
657
                if (method.getName().equals("name")) {
685
                    return name == null ? "" : name;
658
                    return name == null ? "" : name;
686
                }
659
                }
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/actionListener.javx (+2 lines)
Lines 27-32 Link Here
27
<#list REFERENCES as r>
27
<#list REFERENCES as r>
28
  @ActionReference(path="${r.path()}"<#if
28
  @ActionReference(path="${r.path()}"<#if
29
  r.position()!=-1>, position=${r.position()?string("0")}</#if><#if 
29
  r.position()!=-1>, position=${r.position()?string("0")}</#if><#if 
30
  r.separatorBefore()!=-1>, separatorBefore=${r.separatorBefore()?string("0")}</#if><#if 
31
  r.separatorAfter()!=-1>, separatorAfter=${r.separatorAfter()?string("0")}</#if><#if 
30
  r.name()?length != 0>, name="${r.name()}"</#if>)<#if r_has_next>,</#if>
32
  r.name()?length != 0>, name="${r.name()}"</#if>)<#if r_has_next>,</#if>
31
</#list>
33
</#list>
32
})
34
})
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/contextAction.javx (+2 lines)
Lines 28-33 Link Here
28
<#list REFERENCES as r>
28
<#list REFERENCES as r>
29
  @ActionReference(path="${r.path()}"<#if
29
  @ActionReference(path="${r.path()}"<#if
30
  r.position()!=-1>, position=${r.position()?string("0")}</#if><#if 
30
  r.position()!=-1>, position=${r.position()?string("0")}</#if><#if 
31
  r.separatorBefore()!=-1>, separatorBefore=${r.separatorBefore()?string("0")}</#if><#if 
32
  r.separatorAfter()!=-1>, separatorAfter=${r.separatorAfter()?string("0")}</#if><#if 
31
  r.name()?length != 0>, name="${r.name()}"</#if>)<#if r_has_next>,</#if>
33
  r.name()?length != 0>, name="${r.name()}"</#if>)<#if r_has_next>,</#if>
32
</#list>
34
</#list>
33
})
35
})
(-)a/apisupport.project/test/unit/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModelTest.java (-23 / +10 lines)
Lines 77-86 Link Here
77
    }
77
    }
78
    
78
    
79
    public void testActionReferenceCreate() throws Exception {
79
    public void testActionReferenceCreate() throws Exception {
80
        ActionReference res = DataModel.createActionReference("mypath/sub", true, false, 100, "myname");
80
        ActionReference res = DataModel.createActionReference("mypath/sub", 30, 130, 100, "myname");
81
        assertEquals("mypath/sub", res.path());
81
        assertEquals("mypath/sub", res.path());
82
        assertEquals(100, res.position());
82
        assertEquals(100, res.position());
83
        assertEquals("myname", res.name());
83
        assertEquals("myname", res.name());
84
        assertEquals("before", 30, res.separatorBefore());
85
        assertEquals("after", 130, res.separatorAfter());
84
    }
86
    }
85
87
86
    public void testDataModelGenarationForAlwaysEnabledActions() throws Exception {
88
    public void testDataModelGenarationForAlwaysEnabledActions() throws Exception {
Lines 129-135 Link Here
129
            Arrays.asList(cmf.getCreatedPaths())
131
            Arrays.asList(cmf.getCreatedPaths())
130
        );
132
        );
131
        assertEquals(
133
        assertEquals(
132
            Arrays.asList(new String[] {"nbproject/project.xml", "src/org/example/module1/resources/layer.xml" }),
134
            Arrays.asList(new String[] {"nbproject/project.xml" }),
133
            Arrays.asList(cmf.getModifiedPaths())
135
            Arrays.asList(cmf.getModifiedPaths())
134
        );
136
        );
135
        
137
        
Lines 157-183 Link Here
157
        if (!text.contains("Loaders/text/xml/Actions")) {
159
        if (!text.contains("Loaders/text/xml/Actions")) {
158
            fail("Context action is generated:\n" + text);
160
            fail("Context action is generated:\n" + text);
159
        }
161
        }
160
        
162
        if (!text.contains("separatorBefore=125")) {
161
        //
163
            fail("separatorBefore shall be there:\n" + text);
162
        // still using layers for separators
164
        }
163
        //
165
        if (!text.contains("separatorAfter=175")) {
164
        
166
            fail("separatorAfter shall be there:\n" + text);
165
        FileObject layerFO = project.getSourceDirectory().getFileObject("org/example/module1/resources/layer.xml");
167
        }
166
        assertNotNull("Layer found", layerFO);
167
        
168
        XMLFileSystem layer = new XMLFileSystem(layerFO.getURL());
169
        FileObject afterSep = layer.findResource("Menu/Help/Tutorials/org-example-module1-BeepAction-separatorAfter.instance");
170
        FileObject beforeSep = layer.findResource("Menu/Help/Tutorials/org-example-module1-BeepAction-separatorBefore.instance");
171
        
172
        assertNotNull("Before sep found", beforeSep);
173
        assertNotNull("After sep found", afterSep);
174
        
175
        assertEquals("Right position before", 125, beforeSep.getAttribute("position"));
176
        assertEquals("Right position after", 175, afterSep.getAttribute("position"));
177
        
178
        
179
        
180
        //fail("OK\n" + text);
181
    }
168
    }
182
169
183
//    XXX: failing test, fix or delete
170
//    XXX: failing test, fix or delete
(-)a/openide.awt/apichanges.xml (-2 / +2 lines)
Lines 53-60 Link Here
53
    <change id="ActionReference">
53
    <change id="ActionReference">
54
        <api name="awt"/>
54
        <api name="awt"/>
55
        <summary>New @ActionReference annotations</summary>
55
        <summary>New @ActionReference annotations</summary>
56
        <version major="7" minor="27"/>
56
        <version major="7" minor="28"/>
57
        <date day="25" month="8" year="2010"/>
57
        <date day="5" month="9" year="2010"/>
58
        <author login="jtulach"/>
58
        <author login="jtulach"/>
59
        <compatibility addition="yes" binary="compatible" deletion="no" semantic="compatible"/>
59
        <compatibility addition="yes" binary="compatible" deletion="no" semantic="compatible"/>
60
        <description>
60
        <description>
(-)a/openide.awt/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.awt
2
OpenIDE-Module: org.openide.awt
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.27
5
OpenIDE-Module-Specification-Version: 7.28
6
6
(-)a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java (+20 lines)
Lines 61-66 Link Here
61
import javax.lang.model.type.TypeMirror;
61
import javax.lang.model.type.TypeMirror;
62
import javax.lang.model.util.ElementFilter;
62
import javax.lang.model.util.ElementFilter;
63
import javax.swing.Action;
63
import javax.swing.Action;
64
import javax.swing.JSeparator;
64
import javax.swing.KeyStroke;
65
import javax.swing.KeyStroke;
65
import org.openide.awt.ActionID;
66
import org.openide.awt.ActionID;
66
import org.openide.awt.ActionReference;
67
import org.openide.awt.ActionReference;
Lines 376-380 Link Here
376
        f.stringvalue("originalFile", "Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance");
377
        f.stringvalue("originalFile", "Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance");
377
        f.position(ref.position());
378
        f.position(ref.position());
378
        f.write();
379
        f.write();
380
        
381
        if (ref.separatorAfter() != -1) {
382
            if (ref.position() == -1 || ref.position() >= ref.separatorAfter()) {
383
                throw new LayerGenerationException("separatorAfter() must be greater than position()", e);
384
            }
385
            File after = layer(e).file(ref.path() + "/" + name + "-separatorAfter.instance");
386
            after.newvalue("instanceCreate", JSeparator.class.getName());
387
            after.position(ref.separatorAfter());
388
            after.write();
389
        }
390
        if (ref.separatorBefore() != -1) {
391
            if (ref.position() == -1 || ref.position() <= ref.separatorBefore()) {
392
                throw new LayerGenerationException("separatorBefore() must be lower than position()", e);
393
            }
394
            File before = layer(e).file(ref.path() + "/" + name + "-separatorBefore.instance");
395
            before.newvalue("instanceCreate", JSeparator.class.getName());
396
            before.position(ref.separatorBefore());
397
            before.write();
398
        }
379
    }
399
    }
380
}
400
}
(-)a/openide.awt/src/org/openide/awt/ActionReference.java (+10 lines)
Lines 75-78 Link Here
75
     * then it is deduced from associated {@link ActionID}.
75
     * then it is deduced from associated {@link ActionID}.
76
     */
76
     */
77
    String name() default "";
77
    String name() default "";
78
    
79
    /** Shall a separator be placed before the action?
80
     * @return position that is lower than {@link #position()}
81
     */
82
    int separatorBefore() default -1;
83
    
84
    /** Shall a separator be placed after the action?
85
     * @return position that is higher than {@link #position()}
86
     */
87
    int separatorAfter() default -1;
78
}
88
}
(-)a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java (-2 / +61 lines)
Lines 53-58 Link Here
53
import javax.swing.AbstractAction;
53
import javax.swing.AbstractAction;
54
import javax.swing.Action;
54
import javax.swing.Action;
55
import javax.swing.ActionMap;
55
import javax.swing.ActionMap;
56
import javax.swing.JSeparator;
56
import org.netbeans.junit.NbTestCase;
57
import org.netbeans.junit.NbTestCase;
57
import org.openide.awt.ActionReference;
58
import org.openide.awt.ActionReference;
58
import org.openide.awt.ActionReferences;
59
import org.openide.awt.ActionReferences;
Lines 143-150 Link Here
143
        @ActionRegistration(displayName="#AlwaysOn")
144
        @ActionRegistration(displayName="#AlwaysOn")
144
        @ActionID(id="my.test.AlwaysByMethod", category="Tools")
145
        @ActionID(id="my.test.AlwaysByMethod", category="Tools")
145
        @ActionReferences({
146
        @ActionReferences({
146
            @ActionReference(path="Kuk/buk", position=1),
147
            @ActionReference(path="Kuk/buk", position=1, separatorAfter=2),
147
            @ActionReference(path="Muk/luk", position=11)
148
            @ActionReference(path="Muk/luk", position=11, separatorBefore=10)
148
        })
149
        })
149
        public static ActionListener factory() {
150
        public static ActionListener factory() {
150
            created++;
151
            created++;
Lines 178-183 Link Here
178
            assertNotNull("Shadow created", shad);
179
            assertNotNull("Shadow created", shad);
179
            assertEquals("Right position", 1, shad.getAttribute("position"));
180
            assertEquals("Right position", 1, shad.getAttribute("position"));
180
            assertEquals("Proper link", fo.getPath(), shad.getAttribute("originalFile"));
181
            assertEquals("Proper link", fo.getPath(), shad.getAttribute("originalFile"));
182
            FileObject sep = FileUtil.getConfigFile(
183
                "Kuk/buk/my-test-AlwaysByMethod-separatorAfter.instance"
184
            );
185
            assertNotNull("Separator generated", sep);
186
            assertEquals("Position 2", 2, sep.getAttribute("position"));
187
            Object instSep = sep.getAttribute("instanceCreate");
188
            assertTrue("Right instance " + instSep, instSep instanceof JSeparator);
181
        }
189
        }
182
        {
190
        {
183
            FileObject shad = FileUtil.getConfigFile(
191
            FileObject shad = FileUtil.getConfigFile(
Lines 186-191 Link Here
186
            assertNotNull("Shadow created", shad);
194
            assertNotNull("Shadow created", shad);
187
            assertEquals("Right position", 11, shad.getAttribute("position"));
195
            assertEquals("Right position", 11, shad.getAttribute("position"));
188
            assertEquals("Proper link", fo.getPath(), shad.getAttribute("originalFile"));
196
            assertEquals("Proper link", fo.getPath(), shad.getAttribute("originalFile"));
197
            FileObject sep = FileUtil.getConfigFile(
198
                "Muk/luk/my-test-AlwaysByMethod-separatorBefore.instance"
199
            );
200
            assertNotNull("Separator generated", sep);
201
            assertEquals("Position ten", 10, sep.getAttribute("position"));
202
            Object instSep = sep.getAttribute("instanceCreate");
203
            assertTrue("Right instance " + instSep, instSep instanceof JSeparator);
189
        }
204
        }
190
        
205
        
191
    }
206
    }
Lines 714-717 Link Here
714
        assertEquals(null, fo.getAttribute("position"));
729
        assertEquals(null, fo.getAttribute("position"));
715
    }
730
    }
716
731
732
    public void testSeparatorBeforeIsBefore() throws IOException {
733
        clearWorkDir();
734
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
735
            "import org.openide.awt.ActionRegistration;\n" +
736
            "import org.openide.awt.ActionReference;\n" +
737
            "import org.openide.awt.ActionID;\n" +
738
            "import org.openide.util.actions.Presenter;\n" +
739
            "import java.awt.event.*;\n" +
740
            "import java.util.List;\n" +
741
            "import javax.swing.*;\n" +
742
            "@ActionID(category=\"Tools\",id=\"my.action\")" +
743
            "@ActionRegistration(displayName=\"AAA\", key=\"K\") " +
744
            "@ActionReference(path=\"manka\", position=11, separatorBefore=13)" +
745
            "public class A implements ActionListener {\n" +
746
            "    public void actionPerformed(ActionEvent e) {}" +
747
            "}\n"
748
        );
749
        ByteArrayOutputStream os = new ByteArrayOutputStream();
750
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
751
        assertFalse("Compilation has to fail:\n" + os, r);
752
    }
753
    
754
    public void testSeparatorAfterIsAfter() throws IOException {
755
        clearWorkDir();
756
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
757
            "import org.openide.awt.ActionRegistration;\n" +
758
            "import org.openide.awt.ActionReference;\n" +
759
            "import org.openide.awt.ActionID;\n" +
760
            "import org.openide.util.actions.Presenter;\n" +
761
            "import java.awt.event.*;\n" +
762
            "import java.util.List;\n" +
763
            "import javax.swing.*;\n" +
764
            "@ActionID(category=\"Tools\",id=\"my.action\")" +
765
            "@ActionRegistration(displayName=\"AAA\", key=\"K\") " +
766
            "@ActionReference(path=\"manka\", position=11, separatorAfter=7)" +
767
            "public class A implements ActionListener {\n" +
768
            "    public void actionPerformed(ActionEvent e) {}" +
769
            "}\n"
770
        );
771
        ByteArrayOutputStream os = new ByteArrayOutputStream();
772
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
773
        assertFalse("Compilation has to fail:\n" + os, r);
774
    }
775
    
717
}
776
}

Return to bug 189848