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.report.gui.action;
20:
21: import java.awt.event.ActionEvent;
22: import java.util.HashSet;
23: import java.util.Set;
24:
25: import javax.swing.JOptionPane;
26:
27: import org.apache.jmeter.gui.ReportGuiPackage;
28: import org.apache.jmeter.gui.action.ActionNames;
29: import org.apache.jmeter.gui.action.Command;
30: import org.apache.jmeter.util.JMeterUtils;
31:
32: /**
33: * This command clears the existing test plan, allowing the creation of a New
34: * test plan.
35: *
36: * @author Peter Lin
37: * @version $Revision: 493793 $ Last updated: $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
38: */
39: public class ReportClose implements Command {
40:
41: private static Set commands = new HashSet();
42: static {
43: commands.add("close");
44: }
45:
46: /**
47: * Constructor for the Close object.
48: */
49: public ReportClose() {
50: }
51:
52: /**
53: * Gets the ActionNames attribute of the Close object.
54: *
55: * @return the ActionNames value
56: */
57: public Set getActionNames() {
58: return commands;
59: }
60:
61: /**
62: * This method performs the actual command processing.
63: *
64: * @param e
65: * the generic UI action event
66: */
67: public void doAction(ActionEvent e) {
68: ReportActionRouter.getInstance().doActionNow(
69: new ActionEvent(e.getSource(), e.getID(),
70: ReportCheckDirty.CHECK_DIRTY));
71: ReportGuiPackage guiPackage = ReportGuiPackage.getInstance();
72: if (guiPackage.isDirty()) {
73: if (JOptionPane.showConfirmDialog(ReportGuiPackage
74: .getInstance().getMainFrame(), JMeterUtils
75: .getResString("cancel_new_to_save"), JMeterUtils
76: .getResString("Save?"), JOptionPane.YES_NO_OPTION,
77: JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
78: ReportActionRouter.getInstance().doActionNow(
79: new ActionEvent(e.getSource(), e.getID(),
80: ActionNames.SAVE));
81: }
82: }
83: guiPackage.getTreeModel().clearTestPlan();
84: guiPackage.getTreeListener().getJTree().setSelectionRow(1);
85:
86: // Clear the name of the test plan file
87: ReportGuiPackage.getInstance().setReportPlanFile(null);
88:
89: ReportActionRouter.getInstance().actionPerformed(
90: new ActionEvent(e.getSource(), e.getID(),
91: ActionNames.ADD_ALL));
92: }
93: }
|