diff -r 713af2d31380 j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/InfoAction.java --- a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/InfoAction.java Mon Apr 06 16:39:42 2009 +0400 +++ b/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/InfoAction.java Mon Apr 06 15:58:04 2009 +0200 @@ -48,6 +48,9 @@ public final class InfoAction implements ActionListener { public void actionPerformed(ActionEvent e) { + if ("noui".equals(e.getActionCommand())) { // NOI18N + return; + } Help h = (Help)Lookup.getDefault().lookup(Help.class); if (h == null) { Toolkit.getDefaultToolkit().beep(); diff -r 713af2d31380 j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml --- a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml Mon Apr 06 16:39:42 2009 +0400 +++ b/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml Mon Apr 06 15:58:04 2009 +0200 @@ -310,6 +310,8 @@ + + diff -r 713af2d31380 server/src/org/netbeans/modules/server/ui/node/RootNode.java --- a/server/src/org/netbeans/modules/server/ui/node/RootNode.java Mon Apr 06 16:39:42 2009 +0400 +++ b/server/src/org/netbeans/modules/server/ui/node/RootNode.java Mon Apr 06 15:58:04 2009 +0200 @@ -41,10 +41,13 @@ package org.netbeans.modules.server.ui.node; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Enumeration; import java.util.List; import javax.swing.Action; import javax.swing.event.ChangeEvent; @@ -53,14 +56,17 @@ import org.netbeans.api.server.ServerInstance; import org.netbeans.modules.server.ServerRegistry; import org.netbeans.spi.server.ServerInstanceProvider; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; +import org.openide.util.Lookup; +import org.openide.util.Mutex; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.Utilities; import org.openide.util.WeakListeners; -import org.openide.util.actions.SystemAction; import org.openide.util.lookup.Lookups; public final class RootNode extends AbstractNode { @@ -100,7 +106,35 @@ return Utilities.actionsForPath("Servers/Actions").toArray(new Action[0]); // NOI18N } - private static class ChildFactory extends org.openide.nodes.ChildFactory implements ChangeListener { + + static void enableActionsDueToProperties() { + FileObject fo = FileUtil.getConfigFile("Servers/Actions"); // NOI18N + Enumeration en; + if (fo != null) { + for (FileObject o : fo.getChildren()) { + en = o.getAttributes(); + while (en.hasMoreElements()) { + String attr = en.nextElement(); + final String prefix = "property-"; // NOI18N + if (attr.startsWith(prefix)) { + attr = attr.substring(prefix.length()); + if (System.getProperty(attr) != null) { + Lookup l = Lookups.forPath("Servers/Actions"); // NOI18N + for (Lookup.Item item : l.lookupResult(Action.class).allItems()) { + if (item.getId().contains(o.getName())) { + Action a = item.getInstance(); + a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N + } + } + } + } + } + } + } + } + + private static class ChildFactory extends org.openide.nodes.ChildFactory + implements ChangeListener, Runnable { private static final Comparator COMPARATOR = new InstanceComparator(); @@ -154,6 +188,8 @@ protected boolean createKeys(List toPopulate) { List fresh = new ArrayList(); + Mutex.EVENT.readAccess(this); + ServerRegistry registry = ServerRegistry.getInstance(); for (ServerInstanceProvider type : registry.getProviders()) { fresh.addAll(type.getInstances()); @@ -165,7 +201,16 @@ return true; } - } + private static boolean actionsPropertiesDone; + public void run() { + if (actionsPropertiesDone) { + return; + } + assert EventQueue.isDispatchThread(); + actionsPropertiesDone = true; + enableActionsDueToProperties(); + } + } // end of ChildFactory private static class InstanceComparator implements Comparator, Serializable { diff -r 713af2d31380 server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java --- a/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java Mon Apr 06 16:39:42 2009 +0400 +++ b/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java Mon Apr 06 15:58:04 2009 +0200 @@ -39,6 +39,11 @@ package org.netbeans.modules.server.ui.node; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.util.Arrays; +import javax.swing.AbstractAction; import javax.swing.Action; import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; @@ -56,13 +61,21 @@ super(s); } + @Override + protected void setUp() throws Exception { + clearWorkDir(); + } + + + public void testGetActions() throws Exception { RootNode rn = RootNode.getInstance(); FileObject fo = FileUtil.getConfigFile("Servers/Actions"); assertNotNull("Folder for actions precreated", fo); fo.createData(MyAction.class.getName().replace('.', '-') + ".instance"); Action[] arr = rn.getActions(true); - assertEquals("Two actions found", 2, arr.length); + assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length); + assertEquals("Last one is separator", null, arr[2]); MyAction a = MyAction.get(MyAction.class); if (a != arr[0] && a != arr[1]) { @@ -70,9 +83,76 @@ } } + public void testInvokeActionsOnProperties() throws Throwable { + class Work implements Runnable { + int action; + Throwable t; + CntAction a; + + + public void run() { + switch (action) { + case 0: setup(); break; + case 1: check1(); break; + default: fail(); + } + } + + private void setup() { + try { + FileObject fo = FileUtil.getConfigFile("Servers/Actions"); + assertNotNull("Folder for actions precreated", fo); + a = new CntAction(); + FileObject afo = fo.createData("A2.instance"); + afo.setAttribute("instanceCreate", a); + afo.setAttribute("property-myprop", "true"); + } catch (IOException ex) { + this.t = ex; + } + } + + private void check1() { + try { + RootNode.enableActionsDueToProperties(); + assertEquals("No action called", 0, a.cnt); + assertEquals("No action called2", 0, MyAction.cnt); + + System.setProperty("myprop", "ahoj"); + RootNode.enableActionsDueToProperties(); + assertEquals("CntAction called", 1, a.cnt); + assertEquals("No Myaction", 0, MyAction.cnt); + } catch (Throwable ex) { + this.t = ex; + } + } + } + + Work w = new Work(); + w.action = 0; + FileUtil.runAtomicAction(w); + w.action = 1; + EventQueue.invokeAndWait(w); + + if (w.t != null) { + throw w.t; + } + } + + public static final class CntAction extends AbstractAction { + int cnt; + + public void actionPerformed(ActionEvent e) { + assertEquals("noui", e.getActionCommand()); + cnt++; + } + } + public static final class MyAction extends CallableSystemAction { + static int cnt; + @Override public void performAction() { + cnt++; } @Override