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

(-)apichanges.xml (+17 lines)
Lines 23-28 Link Here
23
<apidef name="awt">AWT API</apidef>
23
<apidef name="awt">AWT API</apidef>
24
</apidefs>
24
</apidefs>
25
<changes>
25
<changes>
26
    <change id="Actions.ButtonActionConnector-added">
27
      <api name="awt"/>
28
      <summary>Actions.ButtonActionConnector interface added</summary>
29
      <version major="6" minor="9"/>
30
      <date day="1" month="2" year="2007"/>
31
      <author login="dstrupl"/>
32
      <compatibility addition="yes" modification="no" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no"/>
33
      <description>
34
          The addition enables to plug in additional logic for action enabling and disabling
35
          based on for example authorization information. The added SPI interface is being
36
          looked up in the default lookup. If there is no implementation the original behaviour
37
          is preserverd.
38
      </description>
39
      <class package="org.openide.awt" name="Actions"/>
40
      <issue number="93519"/>
41
    </change>    
42
26
    <change id="DynamicMenuContent-added">
43
    <change id="DynamicMenuContent-added">
27
      <api name="awt"/>
44
      <api name="awt"/>
28
      <summary>DynamicMenuContent interface added</summary>
45
      <summary>DynamicMenuContent interface added</summary>
(-)arch.xml (-3 / +10 lines)
Lines 676-684 Link Here
676
        </question>
676
        </question>
677
-->
677
-->
678
 <answer id="lookup-lookup">
678
 <answer id="lookup-lookup">
679
  <p>
679
      <api group="lookup" name="ButtonActionConnectorSPI" type="export" category="friend">
680
   XXX no answer for lookup-lookup
680
          <p>
681
  </p>
681
              Objects implementing 
682
              <a href="@org-openide-awt@/org/openide/awt/Actions.html#ButtonActionConnector">ButtonActionConnector</a> are
683
              looked up. Only the first instance found in the loookup is used to provide an alternative implementation
684
              of connection between Actions and GUI components. If there isn't one
685
              in the lookup the default implementation is used (it means there does
686
              not have to be one).
687
          </p>
688
      </api>
682
 </answer>
689
 </answer>
683
690
684
691
(-)nbproject/project.properties (-1 / +3 lines)
Lines 16-25 Link Here
16
# Microsystems, Inc. All Rights Reserved.
16
# Microsystems, Inc. All Rights Reserved.
17
17
18
is.autoload=true
18
is.autoload=true
19
javac.compilerargs=-Xlint:unchecked
20
javac.source=1.5
19
javadoc.main.page=org/openide/awt/doc-files/api.html
21
javadoc.main.page=org/openide/awt/doc-files/api.html
20
javadoc.arch=${basedir}/arch.xml
22
javadoc.arch=${basedir}/arch.xml
21
#javadoc.docfiles=${basedir}/api/doc
23
#javadoc.docfiles=${basedir}/api/doc
22
#javadoc.apichanges=${basedir}/api/apichanges.xml
24
#javadoc.apichanges=${basedir}/api/apichanges.xml
23
javadoc.apichanges=${basedir}/apichanges.xml
25
javadoc.apichanges=${basedir}/apichanges.xml
24
26
25
spec.version.base=6.8.0
27
spec.version.base=6.9.0
(-)src/org/openide/awt/Actions.java (-2 / +45 lines)
Lines 40-48 Link Here
40
import org.openide.util.Lookup;
40
import org.openide.util.Lookup;
41
import org.openide.util.NbBundle;
41
import org.openide.util.NbBundle;
42
import org.openide.util.Utilities;
42
import org.openide.util.Utilities;
43
44
import java.lang.ref.WeakReference;
43
import java.lang.ref.WeakReference;
45
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.Collection;
46
import java.util.Hashtable;
46
import java.util.Hashtable;
47
import java.util.Iterator;
47
import java.util.Iterator;
48
import java.util.Map;
48
import java.util.Map;
Lines 52-58 Link Here
52
import javax.swing.AbstractButton;
52
import javax.swing.AbstractButton;
53
import javax.swing.Action;
53
import javax.swing.Action;
54
import javax.swing.Icon;
54
import javax.swing.Icon;
55
56
import javax.swing.ImageIcon;
55
import javax.swing.ImageIcon;
57
import javax.swing.JCheckBoxMenuItem;
56
import javax.swing.JCheckBoxMenuItem;
58
import javax.swing.JComponent;
57
import javax.swing.JComponent;
Lines 143-154 Link Here
143
    }
142
    }
144
143
145
    /** Attaches menu item to an action.
144
    /** Attaches menu item to an action.
145
     * You can supply an alternative implementation
146
     * for this method by implementing method
147
     * {@link ButtonActionConnector#connect(JMenuItem, Action, boolean)} and
148
     * registering an instance of {@link ButtonActionConnector} in the
149
     * default lookup.
146
     * @param item menu item
150
     * @param item menu item
147
     * @param action action
151
     * @param action action
148
     * @param popup create popup or menu item
152
     * @param popup create popup or menu item
149
     * @since 3.29
153
     * @since 3.29
150
     */
154
     */
151
    public static void connect(JMenuItem item, Action action, boolean popup) {
155
    public static void connect(JMenuItem item, Action action, boolean popup) {
156
        for (ButtonActionConnector bac : Lookup.getDefault().lookupAll(ButtonActionConnector.class)) {
157
            if (bac.connect(item, action, popup)) {
158
                return;
159
            }
160
        }
152
        Bridge b = new MenuBridge(item, action, popup);
161
        Bridge b = new MenuBridge(item, action, popup);
153
162
154
        if (item instanceof Actions.MenuItem) {
163
        if (item instanceof Actions.MenuItem) {
Lines 246-256 Link Here
246
     * "com/mycompany/myIcon_rollover.gif" for setRolloverIcon. SystemAction has
255
     * "com/mycompany/myIcon_rollover.gif" for setRolloverIcon. SystemAction has
247
     * special support for iconBase - please check {@link SystemAction#iconResource}
256
     * special support for iconBase - please check {@link SystemAction#iconResource}
248
     * for more details.
257
     * for more details.
258
     * You can supply an alternative implementation
259
     * for this method by implementing method
260
     * {@link ButtonActionConnector#connect(AbstractButton, Action)} and
261
     * registering an instance of {@link ButtonActionConnector} in the
262
     * default lookup.
249
     * @param button the button
263
     * @param button the button
250
     * @param action the action
264
     * @param action the action
251
     * @since 3.29
265
     * @since 3.29
252
     */
266
     */
253
    public static void connect(AbstractButton button, Action action) {
267
    public static void connect(AbstractButton button, Action action) {
268
        for (ButtonActionConnector bac : Lookup.getDefault().lookupAll(ButtonActionConnector.class)) {
269
            if (bac.connect(button, action)) {
270
                return;
271
            }
272
        }
254
        Bridge b = new ButtonBridge(button, action);
273
        Bridge b = new ButtonBridge(button, action);
255
        b.updateState(null);
274
        b.updateState(null);
256
    }
275
    }
Lines 1301-1306 Link Here
1301
        
1320
        
1302
    }
1321
    }
1303
1322
1323
    /**
1324
     * SPI for being able to supply alternative implementation of
1325
     * connection between actions and the presenters. The implementations
1326
     * of this interface are being looked up in the default lookup.
1327
     * If there is no implemenation in the lookup the default implementation
1328
     * is used.
1329
     * @see org.openide.util.Lookup#getDefault()
1330
     */
1331
    public static interface ButtonActionConnector {
1332
        /**
1333
         * Connects the action to the supplied button.
1334
         * @return true if the connection was successful and no
1335
         *    further actions are needed. If false is returned the
1336
         *    default connect implementation is called
1337
         */
1338
        public boolean connect(AbstractButton button, Action action);
1339
        /**
1340
         * Connects the action to the supplied JMenuItem.
1341
         * @return true if the connection was successful and no
1342
         *    further actions are needed. If false is returned the
1343
         *    default connect implementation is called
1344
         */
1345
        public boolean connect(JMenuItem item, Action action, boolean popup);
1346
    }
1304
1347
1305
    private static class DisabledButtonFilter extends RGBImageFilter {
1348
    private static class DisabledButtonFilter extends RGBImageFilter {
1306
        DisabledButtonFilter() {
1349
        DisabledButtonFilter() {
(-)test/unit/src/org/openide/awt/ActionsTest.java (-1 / +54 lines)
Lines 28-33 Link Here
28
import java.util.Map;
28
import java.util.Map;
29
import java.util.Observable;
29
import java.util.Observable;
30
import javax.swing.AbstractAction;
30
import javax.swing.AbstractAction;
31
import javax.swing.AbstractButton;
31
import javax.swing.Action;
32
import javax.swing.Action;
32
import javax.swing.Icon;
33
import javax.swing.Icon;
33
import javax.swing.JButton;
34
import javax.swing.JButton;
Lines 90-96 Link Here
90
    }
91
    }
91
    
92
    
92
    protected void setUp() {
93
    protected void setUp() {
93
        MockServices.setServices(new Class[] {TestKeymap.class});
94
        MockServices.setServices(new Class[] {TestKeymap.class, TestConnector.class});
94
        assertNotNull("Keymap has to be in lookup", Lookup.getDefault().lookup(Keymap.class));
95
        assertNotNull("Keymap has to be in lookup", Lookup.getDefault().lookup(Keymap.class));
95
    }
96
    }
96
    
97
    
Lines 330-335 Link Here
330
        
331
        
331
        f.setVisible(false);
332
        f.setVisible(false);
332
    }
333
    }
334
335
    /**
336
     * Tests whether the ButtonActionConnector is being called. The testing
337
     * implementation is set to "active" only for this test - so the other
338
     * tests should retain the behaviour like running without the
339
     * ButtonActionConnector.
340
     */
341
    public void testButtonActionConnector() throws Exception {
342
        TestConnector tc = Lookup.getDefault().lookup(TestConnector.class);
343
        tc.setActive(true);
344
        Action action = new ActionsTest.TestAction();
345
        JButton button = new JButton();
346
        Actions.connect(button, action);
347
        assertEquals(1, tc.getConnectCalled());
348
        JMenuItem jmi = new JMenuItem();
349
        Actions.connect(jmi, action, false);
350
        assertEquals(3, tc.getConnectCalled());
351
        tc.setActive(false);
352
    }
353
    
333
    
354
    
334
    protected boolean runInEQ() {
355
    protected boolean runInEQ() {
335
        return true;
356
        return true;
Lines 480-485 Link Here
480
            // ignore
501
            // ignore
481
        }
502
        }
482
        
503
        
504
    }
505
    
506
    public static final class TestConnector implements Actions.ButtonActionConnector {
507
        
508
        private int called = 0;
509
        private boolean active = false;
510
        
511
        public TestConnector() {}
512
        
513
        public boolean connect(AbstractButton button, Action action) {
514
            if (!active) {
515
                return false;
516
            }
517
            called +=1;
518
            return true;
519
        }
520
521
        public boolean connect(JMenuItem item, Action action, boolean popup) {
522
            if (!active) {
523
                return false;
524
            }
525
            called += 2;
526
            return true;
527
        }
528
        
529
        public int getConnectCalled() {
530
            return called;
531
        }
532
        public void setActive(boolean a) {
533
            called = 0;
534
            active = a;
535
        }
483
    }
536
    }
484
    
537
    
485
}
538
}

Return to bug 93519