1 18 19 package org.apache.jmeter.control.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Container ; 23 import java.util.Collection ; 24 25 import javax.swing.JCheckBox ; 26 import javax.swing.JLabel ; 27 import javax.swing.JMenu ; 28 import javax.swing.JPanel ; 29 import javax.swing.JPopupMenu ; 30 import javax.swing.JTextArea ; 31 32 import org.apache.jmeter.config.Arguments; 33 import org.apache.jmeter.config.gui.ArgumentsPanel; 34 import org.apache.jmeter.gui.AbstractJMeterGuiComponent; 35 import org.apache.jmeter.gui.util.MenuFactory; 36 import org.apache.jmeter.gui.util.VerticalPanel; 37 import org.apache.jmeter.testelement.AbstractTestElement; 38 import org.apache.jmeter.testelement.TestElement; 39 import org.apache.jmeter.testelement.TestPlan; 40 import org.apache.jmeter.threads.gui.ThreadGroupGui; 41 import org.apache.jmeter.util.JMeterUtils; 42 43 49 public class TestPlanGui extends AbstractJMeterGuiComponent 50 { 51 52 56 private JCheckBox functionalMode; 57 58 private JCheckBox serializedMode; 59 60 61 private ArgumentsPanel argsPanel; 62 63 64 private JTextArea commentPanel; 65 66 69 public TestPlanGui() 70 { 71 init(); 72 } 73 74 86 public JPopupMenu createPopupMenu() 87 { 88 JPopupMenu pop = new JPopupMenu (); 89 JMenu addMenu = new JMenu (JMeterUtils.getResString("Add")); 90 addMenu.add(MenuFactory.makeMenuItem( 91 new ThreadGroupGui().getStaticLabel(), 92 ThreadGroupGui.class.getName(), 93 "Add")); 94 addMenu.add(MenuFactory.makeMenu(MenuFactory.LISTENERS, "Add")); 95 addMenu.add(MenuFactory.makeMenu(MenuFactory.CONFIG_ELEMENTS, "Add")); 96 addMenu.add(MenuFactory.makeMenu(MenuFactory.ASSERTIONS, "Add")); 97 addMenu.add(MenuFactory.makeMenu(MenuFactory.PRE_PROCESSORS, "Add")); 98 addMenu.add(MenuFactory.makeMenu(MenuFactory.POST_PROCESSORS, "Add")); 99 addMenu.add(MenuFactory.makeMenu(MenuFactory.TIMERS, "Add")); 100 pop.add(addMenu); 101 MenuFactory.addFileMenu(pop); 102 return pop; 103 } 104 105 106 public TestElement createTestElement() 107 { 108 TestPlan tp = new TestPlan(); 109 modifyTestElement(tp); 110 return tp; 111 } 112 113 114 public void modifyTestElement(TestElement plan) 115 { 116 super.configureTestElement(plan); 117 if (plan instanceof TestPlan) 118 { 119 TestPlan tp = (TestPlan) plan; 120 tp.setFunctionalMode(functionalMode.isSelected()); 121 tp.setSerialized(serializedMode.isSelected()); 122 tp.setUserDefinedVariables( 123 (Arguments) argsPanel.createTestElement()); 124 tp.setProperty(TestPlan.COMMENTS,commentPanel.getText()); 125 } 126 } 127 128 public String getLabelResource() 129 { 130 return "test_plan"; 131 } 132 133 141 public Collection getMenuCategories() 142 { 143 return null; 144 } 145 146 154 public void configure(TestElement el) 155 { 156 super.configure(el); 157 functionalMode.setSelected( 158 ((AbstractTestElement) el).getPropertyAsBoolean( 159 TestPlan.FUNCTIONAL_MODE)); 160 161 serializedMode.setSelected( 162 ((AbstractTestElement) el).getPropertyAsBoolean( 163 TestPlan.SERIALIZE_THREADGROUPS)); 164 165 if (el.getProperty(TestPlan.USER_DEFINED_VARIABLES) != null) 166 { 167 argsPanel.configure( 168 (Arguments) el 169 .getProperty(TestPlan.USER_DEFINED_VARIABLES) 170 .getObjectValue()); 171 } 172 commentPanel.setText(el.getPropertyAsString(TestPlan.COMMENTS)); 173 } 174 175 180 private JPanel createVariablePanel() 181 { 182 argsPanel = 183 new ArgumentsPanel( 184 JMeterUtils.getResString("user_defined_variables")); 185 186 return argsPanel; 187 } 188 189 private Container createCommentPanel(){ 190 Container panel = makeTitlePanel(); 191 commentPanel = new JTextArea (); 192 JLabel label = new JLabel (JMeterUtils.getResString("testplan_comments")); 193 label.setLabelFor(commentPanel); 194 panel.add(label); 195 panel.add(commentPanel); 196 return panel; 197 } 198 201 private void init() 202 { 203 setLayout(new BorderLayout (10, 10)); 204 setBorder(makeBorder()); 205 206 add(createCommentPanel(), BorderLayout.NORTH); 207 208 add(createVariablePanel(), BorderLayout.CENTER); 209 210 VerticalPanel southPanel = new VerticalPanel(); 211 serializedMode = 212 new JCheckBox (JMeterUtils.getResString("testplan.serialized")); 213 southPanel.add(serializedMode); 214 functionalMode = 215 new JCheckBox (JMeterUtils.getResString("functional_mode")); 216 southPanel.add(functionalMode); 217 JTextArea explain = 218 new JTextArea ( 219 JMeterUtils.getResString("functional_mode_explanation")); 220 explain.setEditable(false); 221 explain.setBackground(this.getBackground()); 222 southPanel.add(explain); 223 224 add(southPanel, BorderLayout.SOUTH); 225 } 226 } 227 | Popular Tags |