1 18 19 package org.apache.jmeter.control.gui; 20 21 import java.awt.BorderLayout ; 22 23 import javax.swing.JCheckBox ; 24 import javax.swing.JLabel ; 25 import javax.swing.JPanel ; 26 import javax.swing.JTextField ; 27 28 import org.apache.jmeter.control.ForeachController; 29 import org.apache.jmeter.gui.util.VerticalPanel; 30 import org.apache.jmeter.testelement.TestElement; 31 import org.apache.jmeter.util.JMeterUtils; 32 33 41 42 public class ForeachControlPanel 43 extends AbstractControllerGui 44 { 45 46 50 private JTextField inputVal; 51 52 56 private JTextField returnVal; 57 58 private JCheckBox useSeparator; 60 61 66 private boolean displayName = true; 67 68 69 private static final String INPUTVAL = "Input Field"; 70 71 72 private static final String RETURNVAL = "Return Field"; 73 74 77 public ForeachControlPanel() 78 { 79 this(true); 80 } 81 82 91 public ForeachControlPanel(boolean displayName) 92 { 93 this.displayName = displayName; 94 init(); 95 } 96 97 105 public void configure(TestElement element) 106 { 107 super.configure(element); 108 inputVal.setText(((ForeachController) element).getInputValString()); 109 returnVal.setText(((ForeachController) element).getReturnValString()); 110 useSeparator.setSelected(((ForeachController) element).getUseSeparator()); 111 } 112 113 114 public TestElement createTestElement() 115 { 116 ForeachController lc = new ForeachController(); 117 modifyTestElement(lc); 118 return lc; 119 } 120 121 122 public void modifyTestElement(TestElement lc) 123 { 124 configureTestElement(lc); 125 if (lc instanceof ForeachController) 126 { 127 if (inputVal.getText().length() > 0) 128 { 129 ((ForeachController) lc).setInputVal(inputVal.getText()); 130 } 131 else 132 { 133 ((ForeachController) lc).setInputVal(""); 134 } 135 if (returnVal.getText().length() > 0) 136 { 137 ((ForeachController) lc).setReturnVal(returnVal.getText()); 138 } 139 else 140 { 141 ((ForeachController) lc).setReturnVal(""); 142 } 143 ((ForeachController) lc).setUseSeparator(useSeparator.isSelected()); 144 } 145 } 146 147 148 public String getLabelResource() 149 { 150 return "foreach_controller_title"; 151 } 152 153 156 private void init() 157 { 158 164 if (displayName) 166 { 167 setLayout(new BorderLayout (0, 5)); 168 setBorder(makeBorder()); 169 add(makeTitlePanel(), BorderLayout.NORTH); 170 171 JPanel mainPanel = new JPanel (new BorderLayout ()); 172 mainPanel.add(createLoopCountPanel(), BorderLayout.NORTH); 173 add(mainPanel, BorderLayout.CENTER); 174 } 175 else 176 { 177 setLayout(new BorderLayout ()); 179 add(createLoopCountPanel(), BorderLayout.NORTH); 180 } 181 } 182 183 189 private JPanel createLoopCountPanel() 190 { 191 VerticalPanel loopPanel = new VerticalPanel(); 193 194 JLabel inputValLabel = 196 new JLabel (JMeterUtils.getResString("foreach_input")); 197 JLabel returnValLabel = 198 new JLabel (JMeterUtils.getResString("foreach_output")); 199 200 JPanel inputValSubPanel = new JPanel (new BorderLayout (5, 0)); 202 inputVal = new JTextField ("", 5); 203 inputVal.setName(INPUTVAL); 204 inputValLabel.setLabelFor(inputVal); 205 inputValSubPanel.add(inputValLabel, BorderLayout.WEST); 206 inputValSubPanel.add(inputVal, BorderLayout.CENTER); 207 208 JPanel returnValSubPanel = new JPanel (new BorderLayout (5, 0)); 210 returnVal = new JTextField ("", 5); 211 returnVal.setName(RETURNVAL); 212 returnValLabel.setLabelFor(returnVal); 213 returnValSubPanel.add(returnValLabel, BorderLayout.WEST); 214 returnValSubPanel.add(returnVal, BorderLayout.CENTER); 215 216 useSeparator = new JCheckBox (JMeterUtils.getResString("foreach_use_separator"),true); 218 219 loopPanel.add(inputValSubPanel); 220 loopPanel.add(returnValSubPanel); 221 loopPanel.add(useSeparator); 222 223 return loopPanel; 224 } 225 226 } 227 | Popular Tags |