1 18 19 package org.apache.jmeter.protocol.ldap.config.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.CardLayout ; 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 26 import javax.swing.BorderFactory ; 27 import javax.swing.ButtonGroup ; 28 import javax.swing.JCheckBox ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JRadioButton ; 32 import javax.swing.JTextField ; 33 34 import org.apache.jmeter.config.ConfigTestElement; 35 import org.apache.jmeter.config.gui.AbstractConfigGui; 36 import org.apache.jmeter.config.gui.ArgumentsPanel; 37 import org.apache.jmeter.gui.util.VerticalPanel; 38 import org.apache.jmeter.protocol.ldap.sampler.LDAPSampler; 39 import org.apache.jmeter.testelement.TestElement; 40 import org.apache.jmeter.testelement.property.BooleanProperty; 41 import org.apache.jmeter.testelement.property.StringProperty; 42 import org.apache.jmeter.testelement.property.TestElementProperty; 43 import org.apache.jmeter.util.JMeterUtils; 44 45 52 public class LdapConfigGui extends AbstractConfigGui implements ItemListener 53 { 54 55 private JTextField rootdn = new JTextField (20); 56 private JTextField searchbase = new JTextField (20); 57 private JTextField searchfilter = new JTextField (20); 58 private JTextField delete = new JTextField (20); 59 private JTextField add = new JTextField (20); 60 private JTextField modify = new JTextField (20); 61 private JTextField servername = new JTextField (20); 62 private JTextField port = new JTextField (20); 63 64 private JCheckBox user_Defined = 65 new JCheckBox (JMeterUtils.getResString("user_defined_test")); 66 private JRadioButton addTest = 67 new JRadioButton (JMeterUtils.getResString("add_test")); 68 private JRadioButton modifyTest = 69 new JRadioButton (JMeterUtils.getResString("modify_test")); 70 private JRadioButton deleteTest = 71 new JRadioButton (JMeterUtils.getResString("delete_test")); 72 private JRadioButton searchTest = 73 new JRadioButton (JMeterUtils.getResString("search_test")); 74 private ButtonGroup bGroup = new ButtonGroup (); 75 private boolean displayName = true; 76 ArgumentsPanel tableAddPanel = 77 new ArgumentsPanel(JMeterUtils.getResString("add_test")); 78 ArgumentsPanel tableModifyPanel = 79 new ArgumentsPanel(JMeterUtils.getResString("modify_test")); 80 private JPanel cards; 81 82 85 public LdapConfigGui() 86 { 87 this(true); 88 } 89 90 public String getLabelResource() 91 { 92 return "ldap_sample_title"; 93 } 94 95 103 public void configure(TestElement element) 104 { 105 super.configure(element); 106 servername.setText(element.getPropertyAsString(LDAPSampler.SERVERNAME)); 107 port.setText(element.getPropertyAsString(LDAPSampler.PORT)); 108 rootdn.setText(element.getPropertyAsString(LDAPSampler.ROOTDN)); 109 CardLayout cl = (CardLayout )(cards.getLayout()); 110 if (element.getPropertyAsString(LDAPSampler.TEST).equals("add")) 111 { 112 addTest.setSelected(true); 113 add.setText(element.getPropertyAsString(LDAPSampler.BASE_ENTRY_DN)); 114 tableAddPanel.configure( 115 (TestElement) element 116 .getProperty(LDAPSampler.ARGUMENTS) 117 .getObjectValue()); 118 cl.show(cards,"Add"); 119 } 120 else if (element.getPropertyAsString(LDAPSampler.TEST).equals("modify")) 121 { 122 modifyTest.setSelected(true); 123 modify.setText( 124 element.getPropertyAsString(LDAPSampler.BASE_ENTRY_DN)); 125 tableModifyPanel.configure( 126 (TestElement) element 127 .getProperty(LDAPSampler.ARGUMENTS) 128 .getObjectValue()); 129 cl.show(cards,"Modify"); 130 } 131 else if (element.getPropertyAsString(LDAPSampler.TEST).equals("delete")) 132 { 133 deleteTest.setSelected(true); 134 delete.setText(element.getPropertyAsString(LDAPSampler.DELETE)); 135 cl.show(cards,"Delete"); 136 } 137 else if (element.getPropertyAsString(LDAPSampler.TEST).equals("search")) 138 { 139 searchTest.setSelected(true); 140 searchbase.setText( 141 element.getPropertyAsString(LDAPSampler.SEARCHBASE)); 142 searchfilter.setText( 143 element.getPropertyAsString(LDAPSampler.SEARCHFILTER)); 144 cl.show(cards,"Search"); 145 } 146 147 if (element.getPropertyAsBoolean(LDAPSampler.USER_DEFINED)) 148 { 149 user_Defined.setSelected(true); 150 } 151 else 152 { 153 user_Defined.setSelected(false); 154 cl.show(cards,""); 155 } 156 } 157 158 159 public TestElement createTestElement() 160 { 161 ConfigTestElement element = new ConfigTestElement(); 162 modifyTestElement(element); 163 return element; 164 } 165 166 170 public void modifyTestElement(TestElement element) 171 { 172 element.clear(); 173 configureTestElement(element); 174 element.setProperty(LDAPSampler.SERVERNAME,servername.getText()); 175 element.setProperty(LDAPSampler.PORT,port.getText()); 176 element.setProperty(LDAPSampler.ROOTDN,rootdn.getText()); 177 element.setProperty( 178 new BooleanProperty( 179 LDAPSampler.USER_DEFINED, 180 user_Defined.isSelected())); 181 182 if (addTest.isSelected()) 183 { 184 element.setProperty( 185 new StringProperty(LDAPSampler.TEST, LDAPSampler.ADD)); 186 element.setProperty( 187 new StringProperty(LDAPSampler.BASE_ENTRY_DN, add.getText())); 188 element.setProperty( 189 new TestElementProperty( 190 LDAPSampler.ARGUMENTS, 191 tableAddPanel.createTestElement())); 192 } 193 194 if (modifyTest.isSelected()) 195 { 196 element.setProperty( 197 new StringProperty(LDAPSampler.TEST, LDAPSampler.MODIFY)); 198 element.setProperty( 199 new StringProperty( 200 LDAPSampler.BASE_ENTRY_DN, 201 modify.getText())); 202 element.setProperty( 203 new TestElementProperty( 204 LDAPSampler.ARGUMENTS, 205 tableModifyPanel.createTestElement())); 206 } 207 208 if (deleteTest.isSelected()) 209 { 210 element.setProperty( 211 new StringProperty(LDAPSampler.TEST, LDAPSampler.DELETE)); 212 element.setProperty( 213 new StringProperty(LDAPSampler.DELETE, delete.getText())); 214 } 215 216 if (searchTest.isSelected()) 217 { 218 element.setProperty( 219 new StringProperty(LDAPSampler.TEST, LDAPSampler.SEARCHBASE)); 220 element.setProperty( 221 new StringProperty( 222 LDAPSampler.SEARCHBASE, 223 searchbase.getText())); 224 element.setProperty( 225 new StringProperty( 226 LDAPSampler.SEARCHFILTER, 227 searchfilter.getText())); 228 } 229 } 230 231 232 236 public void itemStateChanged(ItemEvent ie) 237 { 238 CardLayout cl = (CardLayout )(cards.getLayout()); 239 if (user_Defined.isSelected()) 240 { 241 if (addTest.isSelected()) 242 { 243 cl.show(cards,"Add"); 244 tableModifyPanel.clear(); 245 searchbase.setText(""); 246 searchfilter.setText(""); 247 delete.setText(""); 248 } 249 else if(deleteTest.isSelected()) 250 { 251 cl.show(cards,"Delete"); 252 tableModifyPanel.clear(); 253 tableAddPanel.clear(); 254 searchbase.setText(""); 255 searchfilter.setText(""); 256 } 257 else if(searchTest.isSelected()) 258 { 259 cl.show(cards,"Search"); 260 delete.setText(""); 261 tableModifyPanel.clear(); 262 tableAddPanel.clear(); 263 } 264 else if(modifyTest.isSelected()) 265 { 266 cl.show(cards,"Modify"); 267 tableAddPanel.clear(); 268 searchbase.setText(""); 269 searchfilter.setText(""); 270 delete.setText(""); 271 } 272 else 273 { 274 cl.show(cards,""); 275 tableAddPanel.clear(); 276 tableModifyPanel.clear(); 277 searchbase.setText(""); 278 searchfilter.setText(""); 279 delete.setText(""); 280 } 281 } 282 else 283 { 284 cl.show(cards,""); 285 tableAddPanel.clear(); 286 tableModifyPanel.clear(); 287 searchbase.setText(""); 288 searchfilter.setText(""); 289 delete.setText(""); 290 } 291 } 292 293 public LdapConfigGui(boolean displayName) 294 { 295 this.displayName = displayName; 296 init(); 297 } 298 299 302 private JPanel createServernamePanel() 303 { 304 JPanel serverPanel = new JPanel (new BorderLayout (5, 0)); 305 JLabel label = new JLabel (JMeterUtils.getResString("servername")); 306 label.setLabelFor(servername); 307 serverPanel.add(label, BorderLayout.WEST); 308 serverPanel.add(servername, BorderLayout.CENTER); 309 return serverPanel; 310 } 311 312 315 private JPanel createPortPanel() 316 { 317 JPanel portPanel = new JPanel (new BorderLayout (5, 0)); 318 JLabel label = new JLabel (JMeterUtils.getResString("port")); 319 label.setLabelFor(port); 320 portPanel.add(label, BorderLayout.WEST); 321 portPanel.add(port, BorderLayout.CENTER); 322 return portPanel; 323 } 324 325 328 private JPanel createRootdnPanel() 329 { 330 JPanel rootdnPanel = new JPanel (new BorderLayout (5, 0)); 331 JLabel label = new JLabel (JMeterUtils.getResString("dn")); 332 label.setLabelFor(rootdn); 333 rootdnPanel.add(label, BorderLayout.WEST); 334 rootdnPanel.add(rootdn, BorderLayout.CENTER); 335 return rootdnPanel; 336 } 337 338 341 private JPanel createSearchPanel() 342 { 343 VerticalPanel searchPanel = new VerticalPanel(); 344 JPanel searchBPanel = new JPanel (new BorderLayout (5, 0)); 345 JLabel label = new JLabel (JMeterUtils.getResString("search_base")); 346 label.setLabelFor(searchbase); 347 searchBPanel.add(label, BorderLayout.WEST); 348 searchBPanel.add(searchbase, BorderLayout.CENTER); 349 JPanel searchFPanel = new JPanel (new BorderLayout (5, 0)); 350 JLabel label2 = new JLabel (JMeterUtils.getResString("search_filter")); 351 label2.setLabelFor(searchfilter); 352 searchFPanel.add(label2, BorderLayout.WEST); 353 searchFPanel.add(searchfilter, BorderLayout.CENTER); 354 searchPanel.add(searchBPanel); 355 searchPanel.add(searchFPanel); 356 return searchPanel; 357 } 358 359 362 private JPanel createDeletePanel() 363 { 364 VerticalPanel panel = new VerticalPanel(); 365 JPanel deletePanel = new JPanel (new BorderLayout (5, 0)); 366 JLabel label = new JLabel (JMeterUtils.getResString("delete")); 367 label.setLabelFor(delete); 368 deletePanel.add(label, BorderLayout.WEST); 369 deletePanel.add(delete, BorderLayout.CENTER); 370 panel.add(deletePanel); 371 return panel; 372 } 373 374 377 private JPanel createAddPanel() 378 { 379 JPanel addPanel = new JPanel (new BorderLayout (5,0)); 380 JPanel addInnerPanel = new JPanel (new BorderLayout (5, 0)); 381 JLabel label = new JLabel (JMeterUtils.getResString("entry_dn")); 382 label.setLabelFor(add); 383 addInnerPanel.add(label, BorderLayout.WEST); 384 addInnerPanel.add(add, BorderLayout.CENTER); 385 addPanel.add(addInnerPanel,BorderLayout.NORTH); 386 addPanel.add(tableAddPanel,BorderLayout.CENTER); 387 return addPanel; 388 } 389 390 393 private JPanel createModifyPanel() 394 { 395 JPanel modifyPanel = new JPanel (new BorderLayout (5,0)); 396 JPanel modifyInnerPanel = new JPanel (new BorderLayout (5, 0)); 397 JLabel label = new JLabel (JMeterUtils.getResString("entry_dn")); 398 label.setLabelFor(modify); 399 modifyInnerPanel.add(label, BorderLayout.WEST); 400 modifyInnerPanel.add(modify, BorderLayout.CENTER); 401 modifyPanel.add(modifyInnerPanel,BorderLayout.NORTH); 402 modifyPanel.add(tableModifyPanel,BorderLayout.CENTER); 403 return modifyPanel; 404 } 405 406 411 private JPanel testPanel() 412 { 413 cards = new JPanel (new CardLayout ()); 414 cards.add(new JPanel (),""); 415 cards.add(createAddPanel(),"Add"); 416 cards.add(createModifyPanel(),"Modify"); 417 cards.add(createDeletePanel(),"Delete"); 418 cards.add(createSearchPanel(),"Search"); 419 return cards; 420 } 421 422 423 426 private JPanel createTestPanel() 427 { 428 JPanel testPanel = new JPanel (new BorderLayout ()); 429 testPanel.setBorder( 430 BorderFactory.createTitledBorder( 431 JMeterUtils.getResString("test_configuration"))); 432 433 testPanel.add(new JLabel (JMeterUtils.getResString("test"))); 434 JPanel rowPanel = new JPanel (); 435 436 rowPanel.add(addTest); 437 bGroup.add(addTest); 438 rowPanel.add(deleteTest); 439 bGroup.add(deleteTest); 440 rowPanel.add(searchTest); 441 bGroup.add(searchTest); 442 rowPanel.add(modifyTest); 443 bGroup.add(modifyTest); 444 testPanel.add(rowPanel,BorderLayout.NORTH); 445 testPanel.add(user_Defined, BorderLayout.CENTER); 446 return testPanel; 447 } 448 449 452 private void init() 453 { 454 user_Defined.addItemListener(this); 455 addTest.addItemListener(this); 456 modifyTest.addItemListener(this); 457 deleteTest.addItemListener(this); 458 searchTest.addItemListener(this); 459 setLayout(new BorderLayout (0, 5)); 460 461 if(displayName) 462 { 463 VerticalPanel mainPanel = new VerticalPanel(); 464 mainPanel.setBorder(makeBorder()); 465 add(makeTitlePanel(),BorderLayout.NORTH); 466 mainPanel.setBorder(makeBorder()); 467 mainPanel.add(createServernamePanel()); 468 mainPanel.add(createPortPanel()); 469 mainPanel.add(createRootdnPanel()); 470 mainPanel.add(createTestPanel()); 471 mainPanel.add(testPanel()); 472 add(mainPanel,BorderLayout.CENTER); 473 } 474 else 475 { 476 VerticalPanel mainPanel = new VerticalPanel(); 477 mainPanel.add(createServernamePanel()); 478 mainPanel.add(createPortPanel()); 479 mainPanel.add(createRootdnPanel()); 480 mainPanel.add(createTestPanel()); 481 mainPanel.add(testPanel()); 482 add(mainPanel,BorderLayout.CENTER); 483 } 484 } 485 } 486 | Popular Tags |