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

(-)a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/InfoAction.java (+3 lines)
Lines 48-53 Link Here
48
48
49
public final class InfoAction implements ActionListener {
49
public final class InfoAction implements ActionListener {
50
    public void actionPerformed(ActionEvent e) {
50
    public void actionPerformed(ActionEvent e) {
51
        if ("noui".equals(e.getActionCommand())) { // NOI18N
52
            return;
53
        }
51
        Help h = (Help)Lookup.getDefault().lookup(Help.class);
54
        Help h = (Help)Lookup.getDefault().lookup(Help.class);
52
        if (h == null) {
55
        if (h == null) {
53
            Toolkit.getDefaultToolkit().beep();
56
            Toolkit.getDefaultToolkit().beep();
(-)a/j2ee.sun.appsrv81/src/org/netbeans/modules/j2ee/sun/ide/j2ee/layer.xml (+2 lines)
Lines 310-315 Link Here
310
            <file name="org-netbeans-modules-j2ee-sun-ide-InfoAction.shadow">
310
            <file name="org-netbeans-modules-j2ee-sun-ide-InfoAction.shadow">
311
                <attr name="originalFile" stringvalue="Actions/Help/org-netbeans-modules-j2ee-sun-ide-InfoAction.instance"/>
311
                <attr name="originalFile" stringvalue="Actions/Help/org-netbeans-modules-j2ee-sun-ide-InfoAction.instance"/>
312
                <attr name="position" intvalue="550"/>
312
                <attr name="position" intvalue="550"/>
313
                <attr name="property-com.sun.aas.installRoot" boolvalue="true"/>
314
                <attr name="property-org.netbeans.modules.tomcat.autoregister.catalinaHome" boolvalue="true"/>
313
            </file>
315
            </file>
314
        </folder>
316
        </folder>
315
    </folder>
317
    </folder>
(-)a/server/src/org/netbeans/modules/server/ui/node/RootNode.java (-3 / +48 lines)
Lines 41-50 Link Here
41
41
42
package org.netbeans.modules.server.ui.node;
42
package org.netbeans.modules.server.ui.node;
43
43
44
import java.awt.EventQueue;
45
import java.awt.event.ActionEvent;
44
import java.io.Serializable;
46
import java.io.Serializable;
45
import java.util.ArrayList;
47
import java.util.ArrayList;
46
import java.util.Collections;
48
import java.util.Collections;
47
import java.util.Comparator;
49
import java.util.Comparator;
50
import java.util.Enumeration;
48
import java.util.List;
51
import java.util.List;
49
import javax.swing.Action;
52
import javax.swing.Action;
50
import javax.swing.event.ChangeEvent;
53
import javax.swing.event.ChangeEvent;
Lines 53-66 Link Here
53
import org.netbeans.api.server.ServerInstance;
56
import org.netbeans.api.server.ServerInstance;
54
import org.netbeans.modules.server.ServerRegistry;
57
import org.netbeans.modules.server.ServerRegistry;
55
import org.netbeans.spi.server.ServerInstanceProvider;
58
import org.netbeans.spi.server.ServerInstanceProvider;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
56
import org.openide.nodes.AbstractNode;
61
import org.openide.nodes.AbstractNode;
57
import org.openide.nodes.Children;
62
import org.openide.nodes.Children;
58
import org.openide.nodes.Node;
63
import org.openide.nodes.Node;
64
import org.openide.util.Lookup;
65
import org.openide.util.Mutex;
59
import org.openide.util.NbBundle;
66
import org.openide.util.NbBundle;
60
import org.openide.util.RequestProcessor;
67
import org.openide.util.RequestProcessor;
61
import org.openide.util.Utilities;
68
import org.openide.util.Utilities;
62
import org.openide.util.WeakListeners;
69
import org.openide.util.WeakListeners;
63
import org.openide.util.actions.SystemAction;
64
import org.openide.util.lookup.Lookups;
70
import org.openide.util.lookup.Lookups;
65
71
66
public final class RootNode extends AbstractNode {
72
public final class RootNode extends AbstractNode {
Lines 100-106 Link Here
100
        return Utilities.actionsForPath("Servers/Actions").toArray(new Action[0]); // NOI18N
106
        return Utilities.actionsForPath("Servers/Actions").toArray(new Action[0]); // NOI18N
101
    }
107
    }
102
108
103
    private static class ChildFactory extends org.openide.nodes.ChildFactory<ServerInstance> implements ChangeListener {
109
110
    static void enableActionsDueToProperties() {
111
        FileObject fo = FileUtil.getConfigFile("Servers/Actions"); // NOI18N
112
        Enumeration<String> en;
113
        if (fo != null) {
114
            for (FileObject o : fo.getChildren()) {
115
                en = o.getAttributes();
116
                while (en.hasMoreElements()) {
117
                    String attr = en.nextElement();
118
                    final String prefix = "property-"; // NOI18N
119
                    if (attr.startsWith(prefix)) {
120
                        attr = attr.substring(prefix.length());
121
                        if (System.getProperty(attr) != null) {
122
                            Lookup l = Lookups.forPath("Servers/Actions"); // NOI18N
123
                            for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
124
                                if (item.getId().contains(o.getName())) {
125
                                    Action a = item.getInstance();
126
                                    a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
127
                                }
128
                            }
129
                        }
130
                    }
131
                }
132
            }
133
        }
134
    }
135
136
    private static class ChildFactory extends org.openide.nodes.ChildFactory<ServerInstance> 
137
    implements ChangeListener, Runnable {
104
138
105
        private static final Comparator<ServerInstance> COMPARATOR = new InstanceComparator();
139
        private static final Comparator<ServerInstance> COMPARATOR = new InstanceComparator();
106
140
Lines 154-159 Link Here
154
        protected boolean createKeys(List<ServerInstance> toPopulate) {
188
        protected boolean createKeys(List<ServerInstance> toPopulate) {
155
            List<ServerInstance> fresh = new ArrayList<ServerInstance>();
189
            List<ServerInstance> fresh = new ArrayList<ServerInstance>();
156
190
191
            Mutex.EVENT.readAccess(this);
192
157
            ServerRegistry registry = ServerRegistry.getInstance();
193
            ServerRegistry registry = ServerRegistry.getInstance();
158
            for (ServerInstanceProvider type : registry.getProviders()) {
194
            for (ServerInstanceProvider type : registry.getProviders()) {
159
                fresh.addAll(type.getInstances());
195
                fresh.addAll(type.getInstances());
Lines 165-171 Link Here
165
            return true;
201
            return true;
166
        }
202
        }
167
203
168
    }
204
        private static boolean actionsPropertiesDone;
205
        public void run() {
206
            if (actionsPropertiesDone) {
207
                return;
208
            }
209
            assert EventQueue.isDispatchThread();
210
            actionsPropertiesDone = true;
211
            enableActionsDueToProperties();
212
        }
213
    } // end of ChildFactory
169
214
170
    private static class InstanceComparator implements Comparator<ServerInstance>, Serializable {
215
    private static class InstanceComparator implements Comparator<ServerInstance>, Serializable {
171
216
(-)a/server/test/unit/src/org/netbeans/modules/server/ui/node/RootNodeTest.java (-1 / +81 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.server.ui.node;
40
package org.netbeans.modules.server.ui.node;
41
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;
42
import javax.swing.Action;
47
import javax.swing.Action;
43
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.junit.NbTestCase;
44
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileObject;
Lines 56-68 Link Here
56
        super(s);
61
        super(s);
57
    }
62
    }
58
63
64
    @Override
65
    protected void setUp() throws Exception {
66
        clearWorkDir();
67
    }
68
69
70
59
    public void testGetActions() throws Exception {
71
    public void testGetActions() throws Exception {
60
        RootNode rn = RootNode.getInstance();
72
        RootNode rn = RootNode.getInstance();
61
        FileObject fo = FileUtil.getConfigFile("Servers/Actions");
73
        FileObject fo = FileUtil.getConfigFile("Servers/Actions");
62
        assertNotNull("Folder for actions precreated", fo);
74
        assertNotNull("Folder for actions precreated", fo);
63
        fo.createData(MyAction.class.getName().replace('.', '-') + ".instance");
75
        fo.createData(MyAction.class.getName().replace('.', '-') + ".instance");
64
        Action[] arr = rn.getActions(true);
76
        Action[] arr = rn.getActions(true);
65
        assertEquals("Two actions found", 2, arr.length);
77
        assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length);
78
        assertEquals("Last one is separator", null, arr[2]);
66
        MyAction a = MyAction.get(MyAction.class);
79
        MyAction a = MyAction.get(MyAction.class);
67
80
68
        if (a != arr[0] && a != arr[1]) {
81
        if (a != arr[0] && a != arr[1]) {
Lines 70-78 Link Here
70
        }
83
        }
71
    }
84
    }
72
85
86
    public void testInvokeActionsOnProperties() throws Throwable {
87
        class Work implements Runnable {
88
            int action;
89
            Throwable t;
90
            CntAction a;
91
92
93
            public void run() {
94
                switch (action) {
95
                    case 0: setup(); break;
96
                    case 1: check1(); break;
97
                    default: fail();
98
                }
99
            }
100
101
            private void setup() {
102
                try {
103
                    FileObject fo = FileUtil.getConfigFile("Servers/Actions");
104
                    assertNotNull("Folder for actions precreated", fo);
105
                    a = new CntAction();
106
                    FileObject afo = fo.createData("A2.instance");
107
                    afo.setAttribute("instanceCreate", a);
108
                    afo.setAttribute("property-myprop", "true");
109
                } catch (IOException ex) {
110
                    this.t = ex;
111
                }
112
            }
113
114
            private void check1() {
115
                try {
116
                    RootNode.enableActionsDueToProperties();
117
                    assertEquals("No action called", 0, a.cnt);
118
                    assertEquals("No action called2", 0, MyAction.cnt);
119
120
                    System.setProperty("myprop", "ahoj");
121
                    RootNode.enableActionsDueToProperties();
122
                    assertEquals("CntAction called", 1, a.cnt);
123
                    assertEquals("No Myaction", 0, MyAction.cnt);
124
                } catch (Throwable ex) {
125
                    this.t = ex;
126
                }
127
            }
128
        }
129
130
        Work w = new Work();
131
        w.action = 0;
132
        FileUtil.runAtomicAction(w);
133
        w.action = 1;
134
        EventQueue.invokeAndWait(w);
135
136
        if (w.t != null) {
137
            throw w.t;
138
        }
139
    }
140
141
    public static final class CntAction extends AbstractAction {
142
        int cnt;
143
        
144
        public void actionPerformed(ActionEvent e) {
145
            assertEquals("noui", e.getActionCommand());
146
            cnt++;
147
        }
148
    }
149
73
    public static final class MyAction extends CallableSystemAction {
150
    public static final class MyAction extends CallableSystemAction {
151
        static int cnt;
152
74
        @Override
153
        @Override
75
        public void performAction() {
154
        public void performAction() {
155
            cnt++;
76
        }
156
        }
77
157
78
        @Override
158
        @Override

Return to bug 161664