KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > Close


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/Close.java,v 1.2.2.1 2005/03/13 17:41:58 sebb Exp $
2
/*
3  * Copyright 2002-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.swing.JOptionPane JavaDoc;
26
27 import org.apache.jmeter.gui.GuiPackage;
28 import org.apache.jmeter.util.JMeterUtils;
29
30 /**
31  * This command clears the existing test plan, allowing the creation of a New
32  * test plan.
33  *
34  * @author <a HREF="mramshaw@alumni.concordia.ca">Martin Ramshaw</a>
35  * Created June 6, 2002
36  * @version $Revision: 1.2.2.1 $ Last updated: $Date: 2005/03/13 17:41:58 $
37  */

38 public class Close implements Command
39 {
40
41     private static Set JavaDoc commands = new HashSet JavaDoc();
42     static {
43         commands.add("close");
44     }
45
46     /**
47      * Constructor for the Close object.
48      */

49     public Close()
50     {
51     }
52
53     /**
54      * Gets the ActionNames attribute of the Close object.
55      *
56      *@return the ActionNames value
57      */

58     public Set JavaDoc getActionNames()
59     {
60         return commands;
61     }
62
63     /**
64      * This method performs the actual command processing.
65      *
66      *@param e the generic UI action event
67      */

68     public void doAction(ActionEvent JavaDoc e)
69     {
70         ActionRouter.getInstance().doActionNow(
71             new ActionEvent JavaDoc(e.getSource(), e.getID(), CheckDirty.CHECK_DIRTY));
72         GuiPackage guiPackage = GuiPackage.getInstance();
73         if (guiPackage.isDirty())
74         {
75             if (JOptionPane
76                 .showConfirmDialog(
77                     GuiPackage.getInstance().getMainFrame(),
78                     JMeterUtils.getResString("cancel_new_to_save"),
79                     JMeterUtils.getResString("Save?"),
80                     JOptionPane.YES_NO_OPTION,
81                     JOptionPane.QUESTION_MESSAGE)
82                 == JOptionPane.YES_OPTION)
83             {
84                 ActionRouter.getInstance().doActionNow(
85                     new ActionEvent JavaDoc(
86                         e.getSource(),
87                         e.getID(),
88                         Save.SAVE));
89             }
90         }
91         guiPackage.getTreeModel().clearTestPlan();
92         guiPackage.getTreeListener().getJTree().setSelectionRow(1);
93
94         // Clear the name of the test plan file
95
Save save =
96             (Save) ActionRouter.getInstance().getAction(
97                 "save",
98                 "org.apache.jmeter.gui.action.Save");
99         save.setTestPlanFile(null);
100
101         ActionRouter.getInstance().actionPerformed(
102             new ActionEvent JavaDoc(e.getSource(), e.getID(), CheckDirty.ADD_ALL));
103     }
104 }
105
Popular Tags