View | Details | Raw Unified | Return to bug 42428
Collapse All | Expand All

(-)src/core/org/apache/jmeter/gui/action/Save.java (-19 / +21 lines)
Lines 18-34 Link Here
18
18
19
package org.apache.jmeter.gui.action;
19
package org.apache.jmeter.gui.action;
20
20
21
import java.awt.event.ActionEvent;
22
import java.io.File;
23
import java.io.FileOutputStream;
24
import java.util.HashSet;
25
import java.util.Iterator;
26
import java.util.LinkedList;
27
import java.util.Set;
28
29
import javax.swing.JFileChooser;
30
import javax.swing.JOptionPane;
31
32
import org.apache.commons.io.FilenameUtils;
21
import org.apache.commons.io.FilenameUtils;
33
import org.apache.jmeter.exceptions.IllegalUserActionException;
22
import org.apache.jmeter.exceptions.IllegalUserActionException;
34
import org.apache.jmeter.gui.GuiPackage;
23
import org.apache.jmeter.gui.GuiPackage;
Lines 42-47 Link Here
42
import org.apache.jorphan.util.JOrphanUtils;
31
import org.apache.jorphan.util.JOrphanUtils;
43
import org.apache.log.Logger;
32
import org.apache.log.Logger;
44
33
34
import javax.swing.*;
35
import java.awt.event.ActionEvent;
36
import java.io.File;
37
import java.io.FileOutputStream;
38
import java.util.HashSet;
39
import java.util.Iterator;
40
import java.util.LinkedList;
41
import java.util.Set;
42
45
/**
43
/**
46
 * Save the current test plan; implements:
44
 * Save the current test plan; implements:
47
 * Save
45
 * Save
Lines 86-92 Link Here
86
        }
84
        }
87
        if (e.getActionCommand().equals(ActionNames.SAVE_AS)) {
85
        if (e.getActionCommand().equals(ActionNames.SAVE_AS)) {
88
            JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
86
            JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
89
            if (nodes.length > 1){
87
            if (nodes.length > 1) {
90
                JMeterUtils.reportErrorToUser(
88
                JMeterUtils.reportErrorToUser(
91
                        JMeterUtils.getResString("save_as_error"), // $NON-NLS-1$
89
                        JMeterUtils.getResString("save_as_error"), // $NON-NLS-1$
92
                        JMeterUtils.getResString("save_as")); // $NON-NLS-1$
90
                        JMeterUtils.getResString("save_as")); // $NON-NLS-1$
Lines 95-101 Link Here
95
            subTree = GuiPackage.getInstance().getCurrentSubTree();
93
            subTree = GuiPackage.getInstance().getCurrentSubTree();
96
        } else {
94
        } else {
97
            fullSave = true;
95
            fullSave = true;
98
            subTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
96
            HashTree testPlan = GuiPackage.getInstance().getTreeModel().getTestPlan();
97
            HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench();
98
            testPlan.add(workbench);
99
//            subTree = GuiPackage.getInstance().getTreeModel().getTestPlan();
100
            subTree = testPlan;
99
        }
101
        }
100
102
101
        String updateFile = GuiPackage.getInstance().getTestPlanFile();
103
        String updateFile = GuiPackage.getInstance().getTestPlanFile();
Lines 108-126 Link Here
108
            }
110
            }
109
            updateFile = chooser.getSelectedFile().getAbsolutePath();
111
            updateFile = chooser.getSelectedFile().getAbsolutePath();
110
            // Make sure the file ends with proper extension
112
            // Make sure the file ends with proper extension
111
            if(FilenameUtils.getExtension(updateFile).equals("")) {
113
            if (FilenameUtils.getExtension(updateFile).equals("")) {
112
                updateFile = updateFile + JMX_FILE_EXTENSION;
114
                updateFile = updateFile + JMX_FILE_EXTENSION;
113
            }
115
            }
114
            // Check if the user is trying to save to an existing file
116
            // Check if the user is trying to save to an existing file
115
            File f = new File(updateFile);
117
            File f = new File(updateFile);
116
            if(f.exists()) {
118
            if (f.exists()) {
117
                int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
119
                int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
118
                        JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$
120
                        JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$
119
                        JMeterUtils.getResString("save?"),  // $NON-NLS-1$
121
                        JMeterUtils.getResString("save?"),  // $NON-NLS-1$
120
                        JOptionPane.YES_NO_OPTION,
122
                        JOptionPane.YES_NO_OPTION,
121
                        JOptionPane.QUESTION_MESSAGE);
123
                        JOptionPane.QUESTION_MESSAGE);
122
                if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) {
124
                if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) {
123
                    return ; // Do not save, user does not want to overwrite
125
                    return; // Do not save, user does not want to overwrite
124
                }
126
                }
125
            }
127
            }
126
128
Lines 132-138 Link Here
132
        try {
134
        try {
133
            convertSubTree(subTree);
135
            convertSubTree(subTree);
134
        } catch (Exception err) {
136
        } catch (Exception err) {
135
            log.warn("Error converting subtree "+err);
137
            log.warn("Error converting subtree " + err);
136
        }
138
        }
137
139
138
        FileOutputStream ostream = null;
140
        FileOutputStream ostream = null;
Lines 145-154 Link Here
145
            }
147
            }
146
        } catch (Throwable ex) {
148
        } catch (Throwable ex) {
147
            log.error("Error saving tree:", ex);
149
            log.error("Error saving tree:", ex);
148
            if (ex instanceof Error){
150
            if (ex instanceof Error) {
149
                throw (Error) ex;
151
                throw (Error) ex;
150
            }
152
            }
151
            if (ex instanceof RuntimeException){
153
            if (ex instanceof RuntimeException) {
152
                throw (RuntimeException) ex;
154
                throw (RuntimeException) ex;
153
            }
155
            }
154
            throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile, ex);
156
            throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile, ex);
(-)src/core/org/apache/jmeter/gui/tree/JMeterTreeModel.java (-17 / +20 lines)
Lines 18-30 Link Here
18
18
19
package org.apache.jmeter.gui.tree;
19
package org.apache.jmeter.gui.tree;
20
20
21
import java.util.Enumeration;
22
import java.util.Iterator;
23
import java.util.LinkedList;
24
import java.util.List;
25
26
import javax.swing.tree.DefaultTreeModel;
27
28
import org.apache.jmeter.config.gui.AbstractConfigGui;
21
import org.apache.jmeter.config.gui.AbstractConfigGui;
29
import org.apache.jmeter.control.gui.TestPlanGui;
22
import org.apache.jmeter.control.gui.TestPlanGui;
30
import org.apache.jmeter.control.gui.WorkBenchGui;
23
import org.apache.jmeter.control.gui.WorkBenchGui;
Lines 38-54 Link Here
38
import org.apache.jorphan.collections.HashTree;
31
import org.apache.jorphan.collections.HashTree;
39
import org.apache.jorphan.collections.ListedHashTree;
32
import org.apache.jorphan.collections.ListedHashTree;
40
33
34
import javax.swing.tree.DefaultTreeModel;
35
import java.util.Enumeration;
36
import java.util.Iterator;
37
import java.util.LinkedList;
38
import java.util.List;
39
41
public class JMeterTreeModel extends DefaultTreeModel {
40
public class JMeterTreeModel extends DefaultTreeModel {
42
41
43
    private static final long serialVersionUID = 240L;
42
    private static final long serialVersionUID = 240L;
44
43
45
    public JMeterTreeModel(TestElement tp, TestElement wb) {
44
    public JMeterTreeModel(TestElement tp, TestElement wb) {
46
        super(new JMeterTreeNode(wb, null));
45
        super(new JMeterTreeNode(wb, null));
47
        initTree(tp,wb);
46
        initTree(tp, wb);
48
    }
47
    }
49
48
50
    public JMeterTreeModel() {
49
    public JMeterTreeModel() {
51
        this(new TestPlanGui().createTestElement(),new WorkBenchGui().createTestElement());
50
        this(new TestPlanGui().createTestElement(), new WorkBenchGui().createTestElement());
52
//        super(new JMeterTreeNode(new WorkBenchGui().createTestElement(), null));
51
//        super(new JMeterTreeNode(new WorkBenchGui().createTestElement(), null));
53
//        TestElement tp = new TestPlanGui().createTestElement();
52
//        TestElement tp = new TestPlanGui().createTestElement();
54
//        initTree(tp);
53
//        initTree(tp);
Lines 57-68 Link Here
57
    /**
56
    /**
58
     * Hack to allow TreeModel to be used in non-GUI and headless mode.
57
     * Hack to allow TreeModel to be used in non-GUI and headless mode.
59
     *
58
     *
60
     * @deprecated - only for use by JMeter class!
61
     * @param o - dummy
59
     * @param o - dummy
60
     * @deprecated - only for use by JMeter class!
62
     */
61
     */
63
    @Deprecated
62
    @Deprecated
64
    public JMeterTreeModel(Object o) {
63
    public JMeterTreeModel(Object o) {
65
        this(new TestPlan(),new WorkBench());
64
        this(new TestPlan(), new WorkBench());
66
//      super(new JMeterTreeNode(new WorkBench(), null));
65
//      super(new JMeterTreeNode(new WorkBench(), null));
67
//      TestElement tp = new TestPlan();
66
//      TestElement tp = new TestPlan();
68
//      initTree(tp, new WorkBench());
67
//      initTree(tp, new WorkBench());
Lines 128-134 Link Here
128
            guicomp.configure(component);
127
            guicomp.configure(component);
129
            guicomp.modifyTestElement(component);
128
            guicomp.modifyTestElement(component);
130
            guiPackage.getCurrentGui(); // put the gui object back
129
            guiPackage.getCurrentGui(); // put the gui object back
131
                                        // to the way it was.
130
            // to the way it was.
132
        }
131
        }
133
        JMeterTreeNode newNode = new JMeterTreeNode(component, this);
132
        JMeterTreeNode newNode = new JMeterTreeNode(component, this);
134
133
Lines 195-203 Link Here
195
        return getCurrentSubTree((JMeterTreeNode) ((JMeterTreeNode) this.getRoot()).getChildAt(0));
194
        return getCurrentSubTree((JMeterTreeNode) ((JMeterTreeNode) this.getRoot()).getChildAt(0));
196
    }
195
    }
197
196
197
    public HashTree getWorkBench() {
198
        return getCurrentSubTree((JMeterTreeNode) ((JMeterTreeNode) this.getRoot()).getChildAt(1));
199
    }
200
198
    /**
201
    /**
199
     * Clear the test plan, and use default node for test plan and workbench.
202
     * Clear the test plan, and use default node for test plan and workbench.
200
     *
203
     * <p/>
201
     * N.B. Should only be called by {@link GuiPackage#clearTestPlan()}
204
     * N.B. Should only be called by {@link GuiPackage#clearTestPlan()}
202
     */
205
     */
203
    public void clearTestPlan() {
206
    public void clearTestPlan() {
Lines 207-213 Link Here
207
210
208
    /**
211
    /**
209
     * Clear the test plan, and use specified node for test plan and default node for workbench
212
     * Clear the test plan, and use specified node for test plan and default node for workbench
210
     *
213
     * <p/>
211
     * N.B. Should only be called by {@link GuiPackage#clearTestPlan(TestElement)}
214
     * N.B. Should only be called by {@link GuiPackage#clearTestPlan(TestElement)}
212
     *
215
     *
213
     * @param testPlan the node to use as the testplan top node
216
     * @param testPlan the node to use as the testplan top node
Lines 216-227 Link Here
216
        // Remove the workbench and testplan nodes
219
        // Remove the workbench and testplan nodes
217
        int children = getChildCount(getRoot());
220
        int children = getChildCount(getRoot());
218
        while (children > 0) {
221
        while (children > 0) {
219
            JMeterTreeNode child = (JMeterTreeNode)getChild(getRoot(), 0);
222
            JMeterTreeNode child = (JMeterTreeNode) getChild(getRoot(), 0);
220
            super.removeNodeFromParent(child);
223
            super.removeNodeFromParent(child);
221
            children = getChildCount(getRoot());
224
            children = getChildCount(getRoot());
222
        }
225
        }
223
        // Init the tree
226
        // Init the tree
224
        initTree(testPlan,new WorkBenchGui().createTestElement()); // Assumes this is only called from GUI mode
227
        initTree(testPlan, new WorkBenchGui().createTestElement()); // Assumes this is only called from GUI mode
225
    }
228
    }
226
229
227
    /**
230
    /**
Lines 238-243 Link Here
238
        // Let others know that the tree content has changed.
241
        // Let others know that the tree content has changed.
239
        // This should not be necessary, but without it, nodes are not shown when the user
242
        // This should not be necessary, but without it, nodes are not shown when the user
240
        // uses the Close menu item
243
        // uses the Close menu item
241
        nodeStructureChanged((JMeterTreeNode)getRoot());
244
        nodeStructureChanged((JMeterTreeNode) getRoot());
242
    }
245
    }
243
}
246
}

Return to bug 42428