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.io.File;
23: import java.util.HashSet;
24: import java.util.Set;
25: import javax.swing.JOptionPane;
26:
27: import org.apache.jmeter.gui.GuiPackage;
28: import org.apache.jmeter.util.JMeterUtils;
29:
30: /**
31: * Handles the Revert Project command.
32: *
33: */
34: public class RevertProject implements Command {
35: private static Set commands = new HashSet();
36: static {
37: commands.add(ActionNames.REVERT_PROJECT);
38: }
39:
40: public RevertProject() {
41: super ();
42: }
43:
44: public Set getActionNames() {
45: return commands;
46: }
47:
48: public void doAction(ActionEvent e) {
49: // Get the file name of the current project
50: String projectFile = GuiPackage.getInstance().getTestPlanFile();
51: // Check if the user has loaded any file
52: if (projectFile == null) {
53: return;
54: }
55:
56: // Check if the user wants to drop any changes
57: ActionRouter.getInstance().doActionNow(
58: new ActionEvent(e.getSource(), e.getID(),
59: ActionNames.CHECK_DIRTY));
60: GuiPackage guiPackage = GuiPackage.getInstance();
61: if (guiPackage.isDirty()) {
62: // Check if the user wants to revert
63: int response = JOptionPane.showConfirmDialog(GuiPackage
64: .getInstance().getMainFrame(),
65: JMeterUtils.getResString("cancel_revert_project"), // $NON-NLS-1$
66: JMeterUtils.getResString("revert_project?"), // $NON-NLS-1$
67: JOptionPane.YES_NO_OPTION,
68: JOptionPane.QUESTION_MESSAGE);
69: if (response == JOptionPane.YES_OPTION) {
70: // Close the current project
71: Close.closeProject(e);
72: // Reload the project
73: Load.loadProjectFile(e, new File(projectFile), false);
74: }
75: }
76: }
77: }
|