001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.action;
020:
021: import java.awt.event.ActionEvent;
022: import java.util.HashSet;
023: import java.util.Set;
024:
025: import javax.swing.JOptionPane;
026:
027: import org.apache.jmeter.gui.GuiPackage;
028: import org.apache.jmeter.util.JMeterUtils;
029:
030: /**
031: * This command clears the existing test plan, allowing the creation of a New
032: * test plan.
033: *
034: * @author <a href="mramshaw@alumni.concordia.ca">Martin Ramshaw</a> Created
035: * June 6, 2002
036: */
037: public class Close implements Command {
038:
039: private static Set commands = new HashSet();
040: static {
041: commands.add(ActionNames.CLOSE);
042: }
043:
044: /**
045: * Constructor for the Close object.
046: */
047: public Close() {
048: }
049:
050: /**
051: * Gets the ActionNames attribute of the Close object.
052: *
053: * @return the ActionNames value
054: */
055: public Set getActionNames() {
056: return commands;
057: }
058:
059: /**
060: * This method performs the actual command processing.
061: *
062: * @param e
063: * the generic UI action event
064: */
065: public void doAction(ActionEvent e) {
066: performAction(e);
067: }
068:
069: /**
070: * Helper routine to allow action to be shared by LOAD.
071: *
072: * @param e event
073: * @return true if Close was not cancelled
074: */
075: static boolean performAction(ActionEvent e) {
076: ActionRouter.getInstance().doActionNow(
077: new ActionEvent(e.getSource(), e.getID(),
078: ActionNames.CHECK_DIRTY));
079: GuiPackage guiPackage = GuiPackage.getInstance();
080: if (guiPackage.isDirty()) {
081: int response;
082: if ((response = JOptionPane.showConfirmDialog(GuiPackage
083: .getInstance().getMainFrame(),
084: JMeterUtils.getResString("cancel_new_to_save"), // $NON-NLS-1$
085: JMeterUtils.getResString("save?"), // $NON-NLS-1$
086: JOptionPane.YES_NO_CANCEL_OPTION,
087: JOptionPane.QUESTION_MESSAGE)) == JOptionPane.YES_OPTION) {
088: ActionRouter.getInstance().doActionNow(
089: new ActionEvent(e.getSource(), e.getID(),
090: ActionNames.SAVE));
091: }
092: if (response == JOptionPane.CLOSED_OPTION
093: || response == JOptionPane.CANCEL_OPTION) {
094: return false; // Don't clear the plan
095: }
096: }
097:
098: closeProject(e);
099: return true;
100: }
101:
102: static void closeProject(ActionEvent e) {
103: GuiPackage guiPackage = GuiPackage.getInstance();
104:
105: guiPackage.getTreeModel().clearTestPlan();
106: guiPackage.getTreeListener().getJTree().setSelectionRow(1);
107:
108: // Clear the name of the test plan file
109: guiPackage.setTestPlanFile(null);
110:
111: ActionRouter.getInstance().actionPerformed(
112: new ActionEvent(e.getSource(), e.getID(),
113: ActionNames.ADD_ALL));
114: }
115: }
|