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.JOptionPane;
26:
27: import org.apache.jmeter.gui.GuiPackage;
28: import org.apache.jmeter.util.JMeterUtils;
29:
30: public class ExitCommand implements Command {
31:
32: private static Set commands = new HashSet();
33: static {
34: commands.add(ActionNames.EXIT);
35: }
36:
37: /**
38: * Constructor for the ExitCommand object
39: */
40: public ExitCommand() {
41: }
42:
43: /**
44: * Gets the ActionNames attribute of the ExitCommand object
45: *
46: * @return The ActionNames value
47: */
48: public Set getActionNames() {
49: return commands;
50: }
51:
52: /**
53: * Description of the Method
54: *
55: * @param e
56: * Description of Parameter
57: */
58: public void doAction(ActionEvent e) {
59: ActionRouter.getInstance().doActionNow(
60: new ActionEvent(e.getSource(), e.getID(),
61: ActionNames.CHECK_DIRTY));
62: if (GuiPackage.getInstance().isDirty()) {
63: int chosenOption = JOptionPane.showConfirmDialog(GuiPackage
64: .getInstance().getMainFrame(),
65: JMeterUtils.getResString("cancel_exit_to_save"), // $NON-NLS-1$
66: JMeterUtils.getResString("save?"), // $NON-NLS-1$
67: JOptionPane.YES_NO_CANCEL_OPTION,
68: JOptionPane.QUESTION_MESSAGE);
69: if (chosenOption == JOptionPane.NO_OPTION) {
70: System.exit(0);
71: } else if (chosenOption == JOptionPane.YES_OPTION) {
72: ActionRouter.getInstance().doActionNow(
73: new ActionEvent(e.getSource(), e.getID(),
74: ActionNames.SAVE_ALL_AS));
75: if (!GuiPackage.getInstance().isDirty()) {
76: System.exit(0);
77: }
78: }
79: } else {
80: System.exit(0);
81: }
82: }
83: }
|