01: //$Header$
02: /*
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: */
19:
20: package org.apache.jmeter.report.gui.action;
21:
22: import java.awt.event.ActionEvent;
23: import java.util.HashSet;
24: import java.util.Set;
25:
26: import javax.swing.JOptionPane;
27:
28: import org.apache.jmeter.gui.ReportGuiPackage;
29: import org.apache.jmeter.report.gui.action.ReportActionRouter;
30: import org.apache.jmeter.gui.action.Command;
31: import org.apache.jmeter.report.gui.action.ReportSave;
32: import org.apache.jmeter.util.JMeterUtils;
33:
34: /**
35: * @author Peter Lin
36: * @version $Revision: 493793 $ updated on $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
37: */
38: public class ReportExitCommand implements Command {
39:
40: public static final String EXIT = "exit";
41:
42: private static Set commands = new HashSet();
43: static {
44: commands.add(EXIT);
45: }
46:
47: /**
48: * Constructor for the ExitCommand object
49: */
50: public ReportExitCommand() {
51: }
52:
53: /**
54: * Gets the ActionNames attribute of the ExitCommand object
55: *
56: * @return The ActionNames value
57: */
58: public Set getActionNames() {
59: return commands;
60: }
61:
62: /**
63: * Description of the Method
64: *
65: * @param e
66: * Description of Parameter
67: */
68: public void doAction(ActionEvent e) {
69: ReportActionRouter.getInstance().doActionNow(
70: new ActionEvent(e.getSource(), e.getID(),
71: ReportCheckDirty.CHECK_DIRTY));
72: if (ReportGuiPackage.getInstance().isDirty()) {
73: int chosenOption = JOptionPane.showConfirmDialog(
74: ReportGuiPackage.getInstance().getMainFrame(),
75: JMeterUtils.getResString("cancel_exit_to_save"),
76: JMeterUtils.getResString("Save?"),
77: JOptionPane.YES_NO_CANCEL_OPTION,
78: JOptionPane.QUESTION_MESSAGE);
79: if (chosenOption == JOptionPane.NO_OPTION) {
80: System.exit(0);
81: } else if (chosenOption == JOptionPane.YES_OPTION) {
82: ReportActionRouter.getInstance().doActionNow(
83: new ActionEvent(e.getSource(), e.getID(),
84: ReportSave.SAVE_ALL_AS));
85: if (!ReportGuiPackage.getInstance().isDirty()) {
86: System.exit(0);
87: }
88: }
89: } else {
90: System.exit(0);
91: }
92: }
93: }
|