01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.gui.action;
20:
21: import java.awt.event.ActionEvent;
22: import java.util.HashSet;
23: import java.util.Set;
24:
25: import org.apache.jmeter.gui.GuiPackage;
26: import org.apache.jmeter.gui.tree.JMeterTreeNode;
27: import org.apache.jorphan.logging.LoggingManager;
28: import org.apache.log.Logger;
29:
30: /**
31: * @version $Revision: 493779 $
32: */
33: public class EnableComponent implements Command {
34: private static final Logger log = LoggingManager
35: .getLoggerForClass();
36:
37: private static Set commands = new HashSet();
38: static {
39: commands.add(ActionNames.ENABLE);
40: commands.add(ActionNames.DISABLE);
41: }
42:
43: /**
44: * @see org.apache.jmeter.gui.action.Command#doAction(ActionEvent)
45: */
46: public void doAction(ActionEvent e) {
47: JMeterTreeNode[] nodes = GuiPackage.getInstance()
48: .getTreeListener().getSelectedNodes();
49:
50: if (e.getActionCommand().equals(ActionNames.ENABLE)) {
51: log.debug("enabling currently selected gui objects");
52: enableComponents(nodes, true);
53: } else if (e.getActionCommand().equals(ActionNames.DISABLE)) {
54: log.debug("disabling currently selected gui objects");
55: enableComponents(nodes, false);
56: }
57: }
58:
59: private void enableComponents(JMeterTreeNode[] nodes, boolean enable) {
60: GuiPackage pack = GuiPackage.getInstance();
61: for (int i = 0; i < nodes.length; i++) {
62: nodes[i].setEnabled(enable);
63: pack.getGui(nodes[i].getTestElement()).setEnabled(enable);
64: }
65: }
66:
67: /**
68: * @see org.apache.jmeter.gui.action.Command#getActionNames()
69: */
70: public Set getActionNames() {
71: return commands;
72: }
73: }
|