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 javax.swing.JTree;
26:
27: import org.apache.jmeter.gui.GuiPackage;
28:
29: /**
30: * Processes the Collapse All and Expand All options.
31: *
32: */
33: public class CollapseExpand implements Command {
34:
35: private static Set commands = new HashSet();
36: static {
37: commands.add(ActionNames.COLLAPSE_ALL);
38: commands.add(ActionNames.EXPAND_ALL);
39: }
40:
41: /**
42: * Constructor for the Close object.
43: */
44: public CollapseExpand() {
45: }
46:
47: /**
48: * Gets the ActionNames attribute of the Close object.
49: *
50: * @return the ActionNames value
51: */
52: public Set getActionNames() {
53: return commands;
54: }
55:
56: /**
57: * This method performs the actual command processing.
58: *
59: * @param e
60: * the generic UI action event
61: */
62: public void doAction(ActionEvent e) {
63: boolean collapse = ActionNames.COLLAPSE_ALL.equals(e
64: .getActionCommand());
65: GuiPackage guiInstance = GuiPackage.getInstance();
66: JTree jTree = guiInstance.getMainFrame().getTree();
67: if (collapse) {
68: for (int i = jTree.getRowCount() - 1; i >= 0; i--) {
69: jTree.collapseRow(i);
70: }
71: return;
72: }
73: for (int i = 0; i < jTree.getRowCount(); i++) {
74: jTree.expandRow(i);
75: }
76: }
77: }
|