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

(-)a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml (+1 lines)
Lines 312-317 Link Here
312
                <attr name="position" intvalue="550"/>
312
                <attr name="position" intvalue="550"/>
313
                <attr name="property-com.sun.aas.installRoot" boolvalue="true"/>
313
                <attr name="property-com.sun.aas.installRoot" boolvalue="true"/>
314
                <attr name="property-org.netbeans.modules.tomcat.autoregister.catalinaHome" boolvalue="true"/>
314
                <attr name="property-org.netbeans.modules.tomcat.autoregister.catalinaHome" boolvalue="true"/>
315
                <attr name="config-J2EE/InstalledServers/" boolvalue="true"/>
315
                <attr name="wizardMessage" bundlevalue="org.netbeans.modules.j2ee.sun.ide.Bundle#CTL_InfoWizard"/>
316
                <attr name="wizardMessage" bundlevalue="org.netbeans.modules.j2ee.sun.ide.Bundle#CTL_InfoWizard"/>
316
            </file>
317
            </file>
317
        </folder>
318
        </folder>
(-)a/server/arch.xml (+5 lines)
Lines 85-90 Link Here
85
            By adding <code>property-something</code> attribute you identify
85
            By adding <code>property-something</code> attribute you identify
86
            an action that will be called as soon as the node is expanded and
86
            an action that will be called as soon as the node is expanded and
87
            <code>System.getProperty("something")</code> is non-null.
87
            <code>System.getProperty("something")</code> is non-null.
88
            </p>
89
            <p>
90
            By adding <code>config-something</code> attribute you identify
91
            an action that will be called as soon as the node is expanded and
92
            <code>FileUtil.getConfigFile("something")</code> is non-null.
88
            </p>
93
            </p>
89
            <p>
94
            <p>
90
            By adding <code>wizardMessage</code> attribute you tell the
95
            By adding <code>wizardMessage</code> attribute you tell the
(-)a/server/src/org/netbeans/modules/server/ui/node/RootNode.java (-8 / +21 lines)
Lines 107-113 Link Here
107
    }
107
    }
108
108
109
109
110
    static void enableActionsDueToProperties() {
110
    static void enableActionsOnExpand() {
111
        FileObject fo = FileUtil.getConfigFile("Servers/Actions"); // NOI18N
111
        FileObject fo = FileUtil.getConfigFile("Servers/Actions"); // NOI18N
112
        Enumeration<String> en;
112
        Enumeration<String> en;
113
        if (fo != null) {
113
        if (fo != null) {
Lines 115-130 Link Here
115
                en = o.getAttributes();
115
                en = o.getAttributes();
116
                while (en.hasMoreElements()) {
116
                while (en.hasMoreElements()) {
117
                    String attr = en.nextElement();
117
                    String attr = en.nextElement();
118
                    boolean enable = false;
118
                    final String prefix = "property-"; // NOI18N
119
                    final String prefix = "property-"; // NOI18N
119
                    if (attr.startsWith(prefix)) {
120
                    if (attr.startsWith(prefix)) {
120
                        attr = attr.substring(prefix.length());
121
                        attr = attr.substring(prefix.length());
121
                        if (System.getProperty(attr) != null) {
122
                        if (System.getProperty(attr) != null) {
122
                            Lookup l = Lookups.forPath("Servers/Actions"); // NOI18N
123
                            enable = true;
123
                            for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
124
                        }
124
                                if (item.getId().contains(o.getName())) {
125
                    } else {
125
                                    Action a = item.getInstance();
126
                        final String config = "config-"; // NOI18N
126
                                    a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
127
                        if (attr.startsWith(config)) {
127
                                }
128
                            attr = attr.substring(config.length());
129
                            if (FileUtil.getConfigFile(attr) != null) {
130
                                enable = true;
131
                            }
132
                        }
133
                    }
134
135
                    if (enable) {
136
                        Lookup l = Lookups.forPath("Servers/Actions"); // NOI18N
137
                        for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
138
                            if (item.getId().contains(o.getName())) {
139
                                Action a = item.getInstance();
140
                                a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
128
                            }
141
                            }
129
                        }
142
                        }
130
                    }
143
                    }
Lines 208-214 Link Here
208
            }
221
            }
209
            assert EventQueue.isDispatchThread();
222
            assert EventQueue.isDispatchThread();
210
            actionsPropertiesDone = true;
223
            actionsPropertiesDone = true;
211
            enableActionsDueToProperties();
224
            enableActionsOnExpand();
212
            ServerRegistry.getInstance().getProviders();
225
            ServerRegistry.getInstance().getProviders();
213
        }
226
        }
214
    } // end of ChildFactory
227
    } // end of ChildFactory
(-)04d05628cb02 (+141 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.server.ui.node;
41
42
import java.awt.EventQueue;
43
import java.awt.event.ActionEvent;
44
import java.io.IOException;
45
import java.util.Arrays;
46
import javax.swing.AbstractAction;
47
import javax.swing.Action;
48
import org.netbeans.junit.NbTestCase;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileUtil;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.actions.CallableSystemAction;
53
54
/**
55
 *
56
 * @author Jaroslav Tulach <jtulach@netbeans.org>
57
 */
58
public class RootNodeConfigFileTest extends NbTestCase {
59
60
    public RootNodeConfigFileTest(String s) {
61
        super(s);
62
    }
63
64
    @Override
65
    protected void setUp() throws Exception {
66
        clearWorkDir();
67
    }
68
69
70
    public void testInvokeActionsOnConfigFiles() throws Throwable {
71
        class Work implements Runnable {
72
            int action;
73
            Throwable t;
74
            CntAction a;
75
            CntAction b;
76
77
78
            public void run() {
79
                switch (action) {
80
                    case 0: setup(); break;
81
                    case 1: check1(); break;
82
                    default: fail();
83
                }
84
            }
85
86
            private void setup() {
87
                try {
88
                    FileObject fo = FileUtil.getConfigFile("Servers/Actions");
89
                    assertNotNull("Folder for actions precreated", fo);
90
                    a = new CntAction();
91
                    FileObject afo = fo.createData("A2.instance");
92
                    afo.setAttribute("instanceCreate", a);
93
                    afo.setAttribute("position", 99);
94
                    afo.setAttribute("config-Kuk/Buk/Huk.instance", "true");
95
96
                    b = new CntAction();
97
                    FileObject bfo = fo.createData("A3.instance");
98
                    bfo.setAttribute("instanceCreate", b);
99
                    bfo.setAttribute("position", 98);
100
                } catch (IOException ex) {
101
                    this.t = ex;
102
                }
103
            }
104
105
            private void check1() {
106
                try {
107
                    RootNode.enableActionsOnExpand();
108
                    assertEquals("No action called", 0, a.cnt);
109
                    assertEquals("No action called2", 0, b.cnt);
110
111
                    FileObject huk = FileUtil.createData(FileUtil.getConfigRoot(), "Kuk/Buk/Huk.instance");
112
113
                    RootNode.enableActionsOnExpand();
114
                    assertEquals("CntAction called", 1, a.cnt);
115
                    assertEquals("No Myaction", 0, b.cnt);
116
                } catch (Throwable ex) {
117
                    this.t = ex;
118
                }
119
            }
120
        }
121
122
        Work w = new Work();
123
        w.action = 0;
124
        FileUtil.runAtomicAction(w);
125
        w.action = 1;
126
        EventQueue.invokeAndWait(w);
127
128
        if (w.t != null) {
129
            throw w.t;
130
        }
131
    }
132
133
    public static final class CntAction extends AbstractAction {
134
        int cnt;
135
        
136
        public void actionPerformed(ActionEvent e) {
137
            assertEquals("noui", e.getActionCommand());
138
            cnt++;
139
        }
140
    }
141
}
(-)a/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java (-3 / +5 lines)
Lines 72-78 Link Here
72
        RootNode rn = RootNode.getInstance();
72
        RootNode rn = RootNode.getInstance();
73
        FileObject fo = FileUtil.getConfigFile("Servers/Actions");
73
        FileObject fo = FileUtil.getConfigFile("Servers/Actions");
74
        assertNotNull("Folder for actions precreated", fo);
74
        assertNotNull("Folder for actions precreated", fo);
75
        fo.createData(MyAction.class.getName().replace('.', '-') + ".instance");
75
        FileObject x = fo.createData(MyAction.class.getName().replace('.', '-') + ".instance");
76
        x.setAttribute("position", 37);
76
        Action[] arr = rn.getActions(true);
77
        Action[] arr = rn.getActions(true);
77
        assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length);
78
        assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length);
78
        assertEquals("Last one is separator", null, arr[2]);
79
        assertEquals("Last one is separator", null, arr[2]);
Lines 106-111 Link Here
106
                    FileObject afo = fo.createData("A2.instance");
107
                    FileObject afo = fo.createData("A2.instance");
107
                    afo.setAttribute("instanceCreate", a);
108
                    afo.setAttribute("instanceCreate", a);
108
                    afo.setAttribute("property-myprop", "true");
109
                    afo.setAttribute("property-myprop", "true");
110
                    afo.setAttribute("position", 98);
109
                } catch (IOException ex) {
111
                } catch (IOException ex) {
110
                    this.t = ex;
112
                    this.t = ex;
111
                }
113
                }
Lines 113-124 Link Here
113
115
114
            private void check1() {
116
            private void check1() {
115
                try {
117
                try {
116
                    RootNode.enableActionsDueToProperties();
118
                    RootNode.enableActionsOnExpand();
117
                    assertEquals("No action called", 0, a.cnt);
119
                    assertEquals("No action called", 0, a.cnt);
118
                    assertEquals("No action called2", 0, MyAction.cnt);
120
                    assertEquals("No action called2", 0, MyAction.cnt);
119
121
120
                    System.setProperty("myprop", "ahoj");
122
                    System.setProperty("myprop", "ahoj");
121
                    RootNode.enableActionsDueToProperties();
123
                    RootNode.enableActionsOnExpand();
122
                    assertEquals("CntAction called", 1, a.cnt);
124
                    assertEquals("CntAction called", 1, a.cnt);
123
                    assertEquals("No Myaction", 0, MyAction.cnt);
125
                    assertEquals("No Myaction", 0, MyAction.cnt);
124
                } catch (Throwable ex) {
126
                } catch (Throwable ex) {

Return to bug 162275