Index: apichanges.xml =================================================================== RCS file: /cvs/openide/awt/apichanges.xml,v retrieving revision 1.8 diff -u -r1.8 apichanges.xml --- apichanges.xml 1 Jul 2006 09:07:24 -0000 1.8 +++ apichanges.xml 14 Feb 2007 11:34:25 -0000 @@ -23,6 +23,23 @@ AWT API + + + Actions.ButtonActionConnector interface added + + + + + + The addition enables to plug in additional logic for action enabling and disabling + based on for example authorization information. The added SPI interface is being + looked up in the default lookup. If there is no implementation the original behaviour + is preserverd. + + + + + DynamicMenuContent interface added Index: arch.xml =================================================================== RCS file: /cvs/openide/awt/arch.xml,v retrieving revision 1.9 diff -u -r1.9 arch.xml --- arch.xml 27 Nov 2006 15:58:11 -0000 1.9 +++ arch.xml 14 Feb 2007 11:34:26 -0000 @@ -676,9 +676,16 @@ --> -

- XXX no answer for lookup-lookup -

+ +

+ Objects implementing + ButtonActionConnector are + looked up. Only the first instance found in the loookup is used to provide an alternative implementation + of connection between Actions and GUI components. If there isn't one + in the lookup the default implementation is used (it means there does + not have to be one). +

+
Index: nbproject/project.properties =================================================================== RCS file: /cvs/openide/awt/nbproject/project.properties,v retrieving revision 1.8 diff -u -r1.8 project.properties --- nbproject/project.properties 16 Aug 2006 06:28:30 -0000 1.8 +++ nbproject/project.properties 14 Feb 2007 11:34:26 -0000 @@ -16,10 +16,12 @@ # Microsystems, Inc. All Rights Reserved. is.autoload=true +javac.compilerargs=-Xlint:unchecked +javac.source=1.5 javadoc.main.page=org/openide/awt/doc-files/api.html javadoc.arch=${basedir}/arch.xml #javadoc.docfiles=${basedir}/api/doc #javadoc.apichanges=${basedir}/api/apichanges.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=6.8.0 +spec.version.base=6.9.0 Index: src/org/openide/awt/Actions.java =================================================================== RCS file: /cvs/openide/awt/src/org/openide/awt/Actions.java,v retrieving revision 1.14 diff -u -r1.14 Actions.java --- src/org/openide/awt/Actions.java 20 Sep 2006 05:38:09 -0000 1.14 +++ src/org/openide/awt/Actions.java 14 Feb 2007 11:34:28 -0000 @@ -40,9 +40,9 @@ import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.Utilities; - import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Collection; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; @@ -52,7 +52,6 @@ import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.Icon; - import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; @@ -143,12 +142,22 @@ } /** Attaches menu item to an action. + * You can supply an alternative implementation + * for this method by implementing method + * {@link ButtonActionConnector#connect(JMenuItem, Action, boolean)} and + * registering an instance of {@link ButtonActionConnector} in the + * default lookup. * @param item menu item * @param action action * @param popup create popup or menu item * @since 3.29 */ public static void connect(JMenuItem item, Action action, boolean popup) { + for (ButtonActionConnector bac : Lookup.getDefault().lookupAll(ButtonActionConnector.class)) { + if (bac.connect(item, action, popup)) { + return; + } + } Bridge b = new MenuBridge(item, action, popup); if (item instanceof Actions.MenuItem) { @@ -246,11 +255,21 @@ * "com/mycompany/myIcon_rollover.gif" for setRolloverIcon. SystemAction has * special support for iconBase - please check {@link SystemAction#iconResource} * for more details. + * You can supply an alternative implementation + * for this method by implementing method + * {@link ButtonActionConnector#connect(AbstractButton, Action)} and + * registering an instance of {@link ButtonActionConnector} in the + * default lookup. * @param button the button * @param action the action * @since 3.29 */ public static void connect(AbstractButton button, Action action) { + for (ButtonActionConnector bac : Lookup.getDefault().lookupAll(ButtonActionConnector.class)) { + if (bac.connect(button, action)) { + return; + } + } Bridge b = new ButtonBridge(button, action); b.updateState(null); } @@ -1301,6 +1320,30 @@ } + /** + * SPI for being able to supply alternative implementation of + * connection between actions and the presenters. The implementations + * of this interface are being looked up in the default lookup. + * If there is no implemenation in the lookup the default implementation + * is used. + * @see org.openide.util.Lookup#getDefault() + */ + public static interface ButtonActionConnector { + /** + * Connects the action to the supplied button. + * @return true if the connection was successful and no + * further actions are needed. If false is returned the + * default connect implementation is called + */ + public boolean connect(AbstractButton button, Action action); + /** + * Connects the action to the supplied JMenuItem. + * @return true if the connection was successful and no + * further actions are needed. If false is returned the + * default connect implementation is called + */ + public boolean connect(JMenuItem item, Action action, boolean popup); + } private static class DisabledButtonFilter extends RGBImageFilter { DisabledButtonFilter() { Index: test/unit/src/org/openide/awt/ActionsTest.java =================================================================== RCS file: /cvs/openide/awt/test/unit/src/org/openide/awt/ActionsTest.java,v retrieving revision 1.3 diff -u -r1.3 ActionsTest.java --- test/unit/src/org/openide/awt/ActionsTest.java 1 Jul 2006 09:07:28 -0000 1.3 +++ test/unit/src/org/openide/awt/ActionsTest.java 14 Feb 2007 11:34:28 -0000 @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Observable; import javax.swing.AbstractAction; +import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; @@ -90,7 +91,7 @@ } protected void setUp() { - MockServices.setServices(new Class[] {TestKeymap.class}); + MockServices.setServices(new Class[] {TestKeymap.class, TestConnector.class}); assertNotNull("Keymap has to be in lookup", Lookup.getDefault().lookup(Keymap.class)); } @@ -330,6 +331,26 @@ f.setVisible(false); } + + /** + * Tests whether the ButtonActionConnector is being called. The testing + * implementation is set to "active" only for this test - so the other + * tests should retain the behaviour like running without the + * ButtonActionConnector. + */ + public void testButtonActionConnector() throws Exception { + TestConnector tc = Lookup.getDefault().lookup(TestConnector.class); + tc.setActive(true); + Action action = new ActionsTest.TestAction(); + JButton button = new JButton(); + Actions.connect(button, action); + assertEquals(1, tc.getConnectCalled()); + JMenuItem jmi = new JMenuItem(); + Actions.connect(jmi, action, false); + assertEquals(3, tc.getConnectCalled()); + tc.setActive(false); + } + protected boolean runInEQ() { return true; @@ -480,6 +501,38 @@ // ignore } + } + + public static final class TestConnector implements Actions.ButtonActionConnector { + + private int called = 0; + private boolean active = false; + + public TestConnector() {} + + public boolean connect(AbstractButton button, Action action) { + if (!active) { + return false; + } + called +=1; + return true; + } + + public boolean connect(JMenuItem item, Action action, boolean popup) { + if (!active) { + return false; + } + called += 2; + return true; + } + + public int getConnectCalled() { + return called; + } + public void setActive(boolean a) { + called = 0; + active = a; + } } }