--- a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml Fri Apr 10 14:47:08 2009 +0200 +++ a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml Fri Apr 10 16:52:34 2009 +0200 @@ -312,6 +312,7 @@ + --- a/server/arch.xml Fri Apr 10 14:47:08 2009 +0200 +++ a/server/arch.xml Fri Apr 10 16:52:34 2009 +0200 @@ -85,6 +85,11 @@ By adding property-something attribute you identify an action that will be called as soon as the node is expanded and System.getProperty("something") is non-null. +

+

+ By adding config-something attribute you identify + an action that will be called as soon as the node is expanded and + FileUtil.getConfigFile("something") is non-null.

By adding wizardMessage attribute you tell the --- a/server/src/org/netbeans/modules/server/ui/node/RootNode.java Fri Apr 10 14:47:08 2009 +0200 +++ a/server/src/org/netbeans/modules/server/ui/node/RootNode.java Fri Apr 10 16:52:34 2009 +0200 @@ -107,7 +107,7 @@ } - static void enableActionsDueToProperties() { + static void enableActionsOnExpand() { FileObject fo = FileUtil.getConfigFile("Servers/Actions"); // NOI18N Enumeration en; if (fo != null) { @@ -115,16 +115,29 @@ en = o.getAttributes(); while (en.hasMoreElements()) { String attr = en.nextElement(); + boolean enable = false; 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 - } + enable = true; + } + } else { + final String config = "config-"; // NOI18N + if (attr.startsWith(config)) { + attr = attr.substring(config.length()); + if (FileUtil.getConfigFile(attr) != null) { + enable = true; + } + } + } + + if (enable) { + 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 } } } @@ -208,7 +221,7 @@ } assert EventQueue.isDispatchThread(); actionsPropertiesDone = true; - enableActionsDueToProperties(); + enableActionsOnExpand(); ServerRegistry.getInstance().getProviders(); } } // end of ChildFactory --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ 04d05628cb02 Fri Apr 10 16:52:34 2009 +0200 @@ -0,0 +1,141 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2009 Sun Microsystems, Inc. + */ + +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; +import org.openide.filesystems.FileUtil; +import org.openide.util.HelpCtx; +import org.openide.util.actions.CallableSystemAction; + +/** + * + * @author Jaroslav Tulach + */ +public class RootNodeConfigFileTest extends NbTestCase { + + public RootNodeConfigFileTest(String s) { + super(s); + } + + @Override + protected void setUp() throws Exception { + clearWorkDir(); + } + + + public void testInvokeActionsOnConfigFiles() throws Throwable { + class Work implements Runnable { + int action; + Throwable t; + CntAction a; + CntAction b; + + + 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("position", 99); + afo.setAttribute("config-Kuk/Buk/Huk.instance", "true"); + + b = new CntAction(); + FileObject bfo = fo.createData("A3.instance"); + bfo.setAttribute("instanceCreate", b); + bfo.setAttribute("position", 98); + } catch (IOException ex) { + this.t = ex; + } + } + + private void check1() { + try { + RootNode.enableActionsOnExpand(); + assertEquals("No action called", 0, a.cnt); + assertEquals("No action called2", 0, b.cnt); + + FileObject huk = FileUtil.createData(FileUtil.getConfigRoot(), "Kuk/Buk/Huk.instance"); + + RootNode.enableActionsOnExpand(); + assertEquals("CntAction called", 1, a.cnt); + assertEquals("No Myaction", 0, b.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++; + } + } +} --- a/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java Fri Apr 10 14:47:08 2009 +0200 +++ a/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java Fri Apr 10 16:52:34 2009 +0200 @@ -72,7 +72,8 @@ RootNode rn = RootNode.getInstance(); FileObject fo = FileUtil.getConfigFile("Servers/Actions"); assertNotNull("Folder for actions precreated", fo); - fo.createData(MyAction.class.getName().replace('.', '-') + ".instance"); + FileObject x = fo.createData(MyAction.class.getName().replace('.', '-') + ".instance"); + x.setAttribute("position", 37); Action[] arr = rn.getActions(true); assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length); assertEquals("Last one is separator", null, arr[2]); @@ -106,6 +107,7 @@ FileObject afo = fo.createData("A2.instance"); afo.setAttribute("instanceCreate", a); afo.setAttribute("property-myprop", "true"); + afo.setAttribute("position", 98); } catch (IOException ex) { this.t = ex; } @@ -113,12 +115,12 @@ private void check1() { try { - RootNode.enableActionsDueToProperties(); + RootNode.enableActionsOnExpand(); assertEquals("No action called", 0, a.cnt); assertEquals("No action called2", 0, MyAction.cnt); System.setProperty("myprop", "ahoj"); - RootNode.enableActionsDueToProperties(); + RootNode.enableActionsOnExpand(); assertEquals("CntAction called", 1, a.cnt); assertEquals("No Myaction", 0, MyAction.cnt); } catch (Throwable ex) {