Lines 19-24
Link Here
|
19 |
package org.apache.jmeter.gui.action; |
19 |
package org.apache.jmeter.gui.action; |
20 |
|
20 |
|
21 |
import java.awt.event.ActionEvent; |
21 |
import java.awt.event.ActionEvent; |
|
|
22 |
import java.io.File; |
22 |
import java.io.FileOutputStream; |
23 |
import java.io.FileOutputStream; |
23 |
import java.util.HashSet; |
24 |
import java.util.HashSet; |
24 |
import java.util.Iterator; |
25 |
import java.util.Iterator; |
Lines 26-31
Link Here
|
26 |
import java.util.Set; |
27 |
import java.util.Set; |
27 |
|
28 |
|
28 |
import javax.swing.JFileChooser; |
29 |
import javax.swing.JFileChooser; |
|
|
30 |
import javax.swing.JOptionPane; |
29 |
|
31 |
|
30 |
import org.apache.jmeter.exceptions.IllegalUserActionException; |
32 |
import org.apache.jmeter.exceptions.IllegalUserActionException; |
31 |
import org.apache.jmeter.gui.GuiPackage; |
33 |
import org.apache.jmeter.gui.GuiPackage; |
Lines 34-39
Link Here
|
34 |
import org.apache.jmeter.save.OldSaveService; |
36 |
import org.apache.jmeter.save.OldSaveService; |
35 |
import org.apache.jmeter.save.SaveService; |
37 |
import org.apache.jmeter.save.SaveService; |
36 |
import org.apache.jmeter.testelement.TestElement; |
38 |
import org.apache.jmeter.testelement.TestElement; |
|
|
39 |
import org.apache.jmeter.util.JMeterUtils; |
37 |
import org.apache.jorphan.collections.HashTree; |
40 |
import org.apache.jorphan.collections.HashTree; |
38 |
import org.apache.jorphan.logging.LoggingManager; |
41 |
import org.apache.jorphan.logging.LoggingManager; |
39 |
import org.apache.jorphan.util.JOrphanUtils; |
42 |
import org.apache.jorphan.util.JOrphanUtils; |
Lines 48-53
Link Here
|
48 |
public class Save implements Command { |
51 |
public class Save implements Command { |
49 |
private static final Logger log = LoggingManager.getLoggerForClass(); |
52 |
private static final Logger log = LoggingManager.getLoggerForClass(); |
50 |
|
53 |
|
|
|
54 |
public final static String JMX_FILE_EXTENSION = ".jmx"; // $NON-NLS-1$ |
55 |
|
51 |
private static Set commands = new HashSet(); |
56 |
private static Set commands = new HashSet(); |
52 |
static { |
57 |
static { |
53 |
commands.add(ActionNames.SAVE_AS); // Save (Selection) As |
58 |
commands.add(ActionNames.SAVE_AS); // Save (Selection) As |
Lines 85-95
Link Here
|
85 |
if (!ActionNames.SAVE.equals(e.getActionCommand()) || updateFile == null) { |
90 |
if (!ActionNames.SAVE.equals(e.getActionCommand()) || updateFile == null) { |
86 |
JFileChooser chooser = FileDialoger.promptToSaveFile(GuiPackage.getInstance().getTreeListener() |
91 |
JFileChooser chooser = FileDialoger.promptToSaveFile(GuiPackage.getInstance().getTreeListener() |
87 |
.getCurrentNode().getName() |
92 |
.getCurrentNode().getName() |
88 |
+ ".jmx"); // $NON-NLS-1$ |
93 |
+ JMX_FILE_EXTENSION); |
89 |
if (chooser == null) { |
94 |
if (chooser == null) { |
90 |
return; |
95 |
return; |
91 |
} |
96 |
} |
92 |
updateFile = chooser.getSelectedFile().getAbsolutePath(); |
97 |
updateFile = chooser.getSelectedFile().getAbsolutePath(); |
|
|
98 |
// Make sure the file ends with proper extension |
99 |
if(!updateFile.toLowerCase().endsWith(JMX_FILE_EXTENSION)) { |
100 |
updateFile = updateFile + JMX_FILE_EXTENSION; |
101 |
} |
102 |
// Check if the user is trying to save to an existing file |
103 |
if(!e.getActionCommand().equals(ActionNames.SAVE)) { |
104 |
File f = new File(updateFile); |
105 |
if(f.exists()) { |
106 |
int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), |
107 |
JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$ |
108 |
JMeterUtils.getResString("save?"), // $NON-NLS-1$ |
109 |
JOptionPane.YES_NO_OPTION, |
110 |
JOptionPane.QUESTION_MESSAGE); |
111 |
if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) { |
112 |
return ; // Do not save, user does not want to overwrite |
113 |
} |
114 |
} |
115 |
} |
116 |
|
93 |
if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) { |
117 |
if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) { |
94 |
GuiPackage.getInstance().setTestPlanFile(updateFile); |
118 |
GuiPackage.getInstance().setTestPlanFile(updateFile); |
95 |
} |
119 |
} |