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

(-)jakarta-jmeter-2.3/src/core/org/apache/jmeter/resources/messages.properties (+2 lines)
Lines 85-90 Link Here
85
cancel=Cancel
85
cancel=Cancel
86
cancel_exit_to_save=There are test items that have not been saved.  Do you wish to save before exiting?
86
cancel_exit_to_save=There are test items that have not been saved.  Do you wish to save before exiting?
87
cancel_new_to_save=There are test items that have not been saved.  Do you wish to save before clearing the test plan?
87
cancel_new_to_save=There are test items that have not been saved.  Do you wish to save before clearing the test plan?
88
case_controller_label=Case Value
89
case_controller_title=Case Controller
88
choose_function=Choose a function
90
choose_function=Choose a function
89
choose_language=Choose Language
91
choose_language=Choose Language
90
clear=Clear
92
clear=Clear
(-)jakarta-jmeter-2.3/src/components/org/apache/jmeter/control/gui/CaseControllerGui.java (+85 lines)
Line 0 Link Here
1
// $Header$
2
/*
3
 * Copyright 2001-2004 The Apache Software Foundation.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   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.control.gui;
20
21
import java.awt.BorderLayout;
22
23
import javax.swing.JLabel;
24
import javax.swing.JPanel;
25
import javax.swing.JTextField;
26
27
import org.apache.jmeter.control.CaseController;
28
import org.apache.jmeter.testelement.TestElement;
29
import org.apache.jmeter.util.JMeterUtils;
30
31
public class CaseControllerGui extends AbstractControllerGui {
32
	private static final String CASE_LABEL = "case_controller_label";
33
34
	private JTextField caseValue;
35
36
	public CaseControllerGui() {
37
		init();
38
	}
39
40
	public TestElement createTestElement() {
41
		CaseController ic = new CaseController();
42
		modifyTestElement(ic);
43
		return ic;
44
	}
45
46
	/**
47
	 * Modifies a given TestElement to mirror the data in the gui components.
48
	 * 
49
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
50
	 */
51
	public void modifyTestElement(TestElement ic) {
52
		configureTestElement(ic);
53
		((CaseController) ic).setSelection(caseValue.getText());
54
	}
55
56
	public void configure(TestElement el) {
57
		super.configure(el);
58
		caseValue.setText(((CaseController) el).getSelection());
59
	}
60
61
	public String getLabelResource() {
62
		return "case_controller_title";
63
	}
64
65
	private void init() {
66
		setLayout(new BorderLayout(0, 5));
67
		setBorder(makeBorder());
68
		add(makeTitlePanel(), BorderLayout.NORTH);
69
70
		JPanel mainPanel = new JPanel(new BorderLayout());
71
		mainPanel.add(createCasePanel(), BorderLayout.NORTH);
72
		add(mainPanel, BorderLayout.CENTER);
73
	}
74
75
	private JPanel createCasePanel() {
76
		JPanel casePanel = new JPanel(new BorderLayout(5, 0));
77
		JLabel selectionLabel = new JLabel(JMeterUtils.getResString(CASE_LABEL));
78
		caseValue = new JTextField("");
79
		selectionLabel.setLabelFor(caseValue);
80
		casePanel.add(selectionLabel, BorderLayout.WEST);
81
		casePanel.add(caseValue, BorderLayout.CENTER);
82
		return casePanel;
83
	}
84
85
}
(-)jakarta-jmeter-2.3/src/components/org/apache/jmeter/control/CaseController.java (+98 lines)
Line 0 Link Here
1
/*
2
 * Copyright 2001-2004 The Apache Software Foundation.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *   http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 * 
16
 */
17
18
package org.apache.jmeter.control;
19
20
import java.io.Serializable;
21
import java.util.List;
22
import java.util.Iterator;
23
import org.apache.jmeter.testelement.TestElement; 
24
import org.apache.jmeter.samplers.AbstractSampler;
25
import org.apache.jmeter.control.GenericController;
26
27
import org.apache.jmeter.testelement.property.StringProperty;
28
29
public class CaseController extends InterleaveControl implements Serializable {
30
	private final static String CASE_VALUE = "CaseController.value";
31
32
	public CaseController() {
33
		super();
34
		this.setStyle(USE_SUB_CONTROLLERS);
35
	}
36
37
	public void reInitialize() {
38
		super.reInitialize();
39
		current = getSelectionAsInt();
40
	}
41
42
	/**
43
	 * @see org.apache.jmeter.control.GenericController#resetCurrent()
44
	 */
45
	protected void resetCurrent() {
46
		int c = getSubControllers().size();
47
		if (c > 0) {
48
			current = getSelectionAsInt();
49
		} else {
50
			current = 0;
51
		}
52
	}
53
54
	/**
55
	 * @see org.apache.jmeter.control.GenericController#incrementCurrent()
56
	 */
57
	protected void incrementCurrent() {
58
		super.incrementCurrent();
59
		current = getSelectionAsInt();
60
	}
61
62
	public void setSelection(String inputValue) {
63
		setProperty(new StringProperty(CASE_VALUE, inputValue));
64
	}
65
66
	private int getSelectionAsInt() {
67
		int ret;
68
		getProperty(CASE_VALUE).recoverRunningVersion(null);
69
		String sel = getSelection();
70
		Iterator iter = getSubControllers().iterator();
71
		int i = 0;
72
		int default_pos = -1;
73
		while(iter.hasNext()) {
74
				String name;
75
		    TestElement el = (TestElement)iter.next();
76
		    if (el instanceof AbstractSampler) {
77
						AbstractSampler s = (AbstractSampler) el;
78
						name = s.getName();
79
				} else {
80
						GenericController c = (GenericController) el;
81
						name = c.getName();
82
				}
83
				if (name.equals(sel)) return i;
84
				if (name.toLowerCase().equals("default")) default_pos = i;
85
				i++;
86
		}
87
		// if selection not found -> return default element if found
88
		if (default_pos != -1) return default_pos;
89
		// no element found -> return non-existing element
90
		setDone(true);
91
		return getSubControllers().size();
92
	}
93
	
94
95
	public String getSelection() {
96
		return getPropertyAsString(CASE_VALUE);
97
	}
98
}

Return to bug 43379