1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. 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.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 /** 46 * This class LdapConfigGui is user interface gui for getting all the 47 * configuration values from the user. 48 * 49 * Created Apr 29 2003 11:45 AM 50 * 51 */ 52 public class LdapConfigGui extends AbstractConfigGui implements ItemListener { 53 54 private JTextField rootdn = new JTextField(20); 55 56 private JTextField searchbase = new JTextField(20); 57 58 private JTextField searchfilter = new JTextField(20); 59 60 private JTextField delete = new JTextField(20); 61 62 private JTextField add = new JTextField(20); 63 64 private JTextField modify = new JTextField(20); 65 66 private JTextField servername = new JTextField(20); 67 68 private JTextField port = new JTextField(20); 69 70 private JCheckBox user_Defined = new JCheckBox(JMeterUtils.getResString("user_defined_test")); // $NON-NLS-1$ 71 72 private JRadioButton addTest = new JRadioButton(JMeterUtils.getResString("add_test")); // $NON-NLS-1$ 73 74 private JRadioButton modifyTest = new JRadioButton(JMeterUtils.getResString("modify_test")); // $NON-NLS-1$ 75 76 private JRadioButton deleteTest = new JRadioButton(JMeterUtils.getResString("delete_test")); // $NON-NLS-1$ 77 78 private JRadioButton searchTest = new JRadioButton(JMeterUtils.getResString("search_test")); // $NON-NLS-1$ 79 80 private ButtonGroup bGroup = new ButtonGroup(); 81 82 private boolean displayName = true; 83 84 ArgumentsPanel tableAddPanel = new ArgumentsPanel(JMeterUtils.getResString("add_test")); // $NON-NLS-1$ 85 86 ArgumentsPanel tableModifyPanel = new ArgumentsPanel(JMeterUtils.getResString("modify_test")); // $NON-NLS-1$ 87 88 private JPanel cards; 89 90 /** 91 * Default constructor for LdapConfigGui. 92 */ 93 public LdapConfigGui() { 94 this(true); 95 } 96 97 public String getLabelResource() { 98 return "ldap_sample_title"; // $NON-NLS-1$ 99 } 100 101 /** 102 * A newly created component can be initialized with the contents of a Test 103 * Element object by calling this method. The component is responsible for 104 * querying the Test Element object for the relevant information to display 105 * in its GUI. 106 * 107 * @param element 108 * the TestElement to configure 109 */ 110 public void configure(TestElement element) { 111 super.configure(element); 112 servername.setText(element.getPropertyAsString(LDAPSampler.SERVERNAME)); 113 port.setText(element.getPropertyAsString(LDAPSampler.PORT)); 114 rootdn.setText(element.getPropertyAsString(LDAPSampler.ROOTDN)); 115 CardLayout cl = (CardLayout) (cards.getLayout()); 116 final String testType = element.getPropertyAsString(LDAPSampler.TEST); 117 if (testType.equals(LDAPSampler.ADD)) { 118 addTest.setSelected(true); 119 add.setText(element.getPropertyAsString(LDAPSampler.BASE_ENTRY_DN)); 120 tableAddPanel.configure((TestElement) element.getProperty(LDAPSampler.ARGUMENTS).getObjectValue()); 121 cl.show(cards, "Add"); 122 } else if (testType.equals(LDAPSampler.MODIFY)) { 123 modifyTest.setSelected(true); 124 modify.setText(element.getPropertyAsString(LDAPSampler.BASE_ENTRY_DN)); 125 tableModifyPanel.configure((TestElement) element.getProperty(LDAPSampler.ARGUMENTS).getObjectValue()); 126 cl.show(cards, "Modify"); 127 } else if (testType.equals(LDAPSampler.DELETE)) { 128 deleteTest.setSelected(true); 129 delete.setText(element.getPropertyAsString(LDAPSampler.DELETE)); 130 cl.show(cards, "Delete"); 131 } else if (testType.equals(LDAPSampler.SEARCHBASE)) { 132 searchTest.setSelected(true); 133 searchbase.setText(element.getPropertyAsString(LDAPSampler.SEARCHBASE)); 134 searchfilter.setText(element.getPropertyAsString(LDAPSampler.SEARCHFILTER)); 135 cl.show(cards, "Search"); 136 } 137 138 if (element.getPropertyAsBoolean(LDAPSampler.USER_DEFINED)) { 139 user_Defined.setSelected(true); 140 } else { 141 user_Defined.setSelected(false); 142 cl.show(cards, ""); // $NON-NLS-1$ 143 } 144 } 145 146 /* Implements JMeterGUIComponent.createTestElement() */ 147 public TestElement createTestElement() { 148 ConfigTestElement element = new ConfigTestElement(); 149 modifyTestElement(element); 150 return element; 151 } 152 153 /** 154 * Modifies a given TestElement to mirror the data in the gui components. 155 * 156 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement) 157 */ 158 public void modifyTestElement(TestElement element) { 159 element.clear(); 160 configureTestElement(element); 161 element.setProperty(LDAPSampler.SERVERNAME, servername.getText()); 162 element.setProperty(LDAPSampler.PORT, port.getText()); 163 element.setProperty(LDAPSampler.ROOTDN, rootdn.getText()); 164 element.setProperty(new BooleanProperty(LDAPSampler.USER_DEFINED, user_Defined.isSelected())); 165 166 if (addTest.isSelected()) { 167 element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.ADD)); 168 element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, add.getText())); 169 element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableAddPanel.createTestElement())); 170 } 171 172 if (modifyTest.isSelected()) { 173 element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.MODIFY)); 174 element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, modify.getText())); 175 element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableModifyPanel.createTestElement())); 176 } 177 178 if (deleteTest.isSelected()) { 179 element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.DELETE)); 180 element.setProperty(new StringProperty(LDAPSampler.DELETE, delete.getText())); 181 } 182 183 if (searchTest.isSelected()) { 184 element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.SEARCHBASE)); 185 element.setProperty(new StringProperty(LDAPSampler.SEARCHBASE, searchbase.getText())); 186 element.setProperty(new StringProperty(LDAPSampler.SEARCHFILTER, searchfilter.getText())); 187 } 188 } 189 190 /** 191 * Implements JMeterGUIComponent.clearGui 192 */ 193 public void clearGui() { 194 super.clearGui(); 195 196 rootdn.setText(""); //$NON-NLS-1$ 197 searchbase.setText(""); //$NON-NLS-1$ 198 searchfilter.setText(""); //$NON-NLS-1$ 199 delete.setText(""); //$NON-NLS-1$ 200 add.setText(""); //$NON-NLS-1$ 201 modify.setText(""); //$NON-NLS-1$ 202 servername.setText(""); //$NON-NLS-1$ 203 port.setText(""); //$NON-NLS-1$ 204 user_Defined.setSelected(false); 205 addTest.setSelected(true); 206 modifyTest.setSelected(false); 207 deleteTest.setSelected(false); 208 searchTest.setSelected(false); 209 } 210 211 /** 212 * This itemStateChanged listener for changing the card layout for based on\ 213 * the test selected in the User defined test case. 214 */ 215 public void itemStateChanged(ItemEvent ie) { 216 CardLayout cl = (CardLayout) (cards.getLayout()); 217 if (user_Defined.isSelected()) { 218 if (addTest.isSelected()) { 219 cl.show(cards, "Add"); 220 tableModifyPanel.clear(); 221 modify.setText(""); // $NON-NLS-1$ 222 searchbase.setText(""); // $NON-NLS-1$ 223 searchfilter.setText(""); // $NON-NLS-1$ 224 delete.setText(""); 225 } else if (deleteTest.isSelected()) { 226 cl.show(cards, "Delete"); 227 tableModifyPanel.clear(); 228 modify.setText(""); // $NON-NLS-1$ 229 tableAddPanel.clear(); 230 add.setText(""); // $NON-NLS-1$ 231 searchbase.setText(""); // $NON-NLS-1$ 232 searchfilter.setText(""); // $NON-NLS-1$ 233 } else if (searchTest.isSelected()) { 234 cl.show(cards, "Search"); 235 delete.setText(""); // $NON-NLS-1$ 236 tableModifyPanel.clear(); 237 modify.setText(""); // $NON-NLS-1$ 238 tableAddPanel.clear(); 239 add.setText(""); // $NON-NLS-1$ 240 } else if (modifyTest.isSelected()) { 241 cl.show(cards, "Modify"); 242 tableAddPanel.clear(); 243 add.setText(""); // $NON-NLS-1$ 244 searchbase.setText(""); // $NON-NLS-1$ 245 searchfilter.setText(""); // $NON-NLS-1$ 246 delete.setText(""); 247 } else { 248 cl.show(cards, ""); // $NON-NLS-1$ 249 tableAddPanel.clear(); 250 add.setText(""); // $NON-NLS-1$ 251 tableModifyPanel.clear(); 252 modify.setText(""); // $NON-NLS-1$ 253 searchbase.setText(""); // $NON-NLS-1$ 254 searchfilter.setText(""); // $NON-NLS-1$ 255 delete.setText(""); // $NON-NLS-1$ 256 } 257 } else { 258 cl.show(cards, ""); // $NON-NLS-1$ 259 tableAddPanel.clear(); 260 add.setText(""); // $NON-NLS-1$ 261 tableModifyPanel.clear(); 262 modify.setText(""); // $NON-NLS-1$ 263 searchbase.setText(""); // $NON-NLS-1$ 264 searchfilter.setText(""); // $NON-NLS-1$ 265 delete.setText(""); // $NON-NLS-1$ 266 } 267 } 268 269 public LdapConfigGui(boolean displayName) { 270 this.displayName = displayName; 271 init(); 272 } 273 274 /** 275 * This will create the servername panel in the LdapConfigGui. 276 */ 277 private JPanel createServernamePanel() { 278 JPanel serverPanel = new JPanel(new BorderLayout(5, 0)); 279 JLabel label = new JLabel(JMeterUtils.getResString("servername")); // $NON-NLS-1$ 280 label.setLabelFor(servername); 281 serverPanel.add(label, BorderLayout.WEST); 282 serverPanel.add(servername, BorderLayout.CENTER); 283 return serverPanel; 284 } 285 286 /** 287 * This will create the port panel in the LdapConfigGui. 288 */ 289 private JPanel createPortPanel() { 290 JPanel portPanel = new JPanel(new BorderLayout(5, 0)); 291 JLabel label = new JLabel(JMeterUtils.getResString("port")); // $NON-NLS-1$ 292 label.setLabelFor(port); 293 portPanel.add(label, BorderLayout.WEST); 294 portPanel.add(port, BorderLayout.CENTER); 295 return portPanel; 296 } 297 298 /** 299 * This will create the Root distinguised name panel in the LdapConfigGui. 300 */ 301 private JPanel createRootdnPanel() { 302 JPanel rootdnPanel = new JPanel(new BorderLayout(5, 0)); 303 JLabel label = new JLabel(JMeterUtils.getResString("dn")); // $NON-NLS-1$ 304 label.setLabelFor(rootdn); 305 rootdnPanel.add(label, BorderLayout.WEST); 306 rootdnPanel.add(rootdn, BorderLayout.CENTER); 307 return rootdnPanel; 308 } 309 310 /** 311 * This will create the Search panel in the LdapConfigGui. 312 */ 313 private JPanel createSearchPanel() { 314 VerticalPanel searchPanel = new VerticalPanel(); 315 JPanel searchBPanel = new JPanel(new BorderLayout(5, 0)); 316 JLabel label = new JLabel(JMeterUtils.getResString("search_base")); // $NON-NLS-1$ 317 label.setLabelFor(searchbase); 318 searchBPanel.add(label, BorderLayout.WEST); 319 searchBPanel.add(searchbase, BorderLayout.CENTER); 320 JPanel searchFPanel = new JPanel(new BorderLayout(5, 0)); 321 JLabel label2 = new JLabel(JMeterUtils.getResString("search_filter")); // $NON-NLS-1$ 322 label2.setLabelFor(searchfilter); 323 searchFPanel.add(label2, BorderLayout.WEST); 324 searchFPanel.add(searchfilter, BorderLayout.CENTER); 325 searchPanel.add(searchBPanel); 326 searchPanel.add(searchFPanel); 327 return searchPanel; 328 } 329 330 /** 331 * This will create the Delete panel in the LdapConfigGui. 332 */ 333 private JPanel createDeletePanel() { 334 VerticalPanel panel = new VerticalPanel(); 335 JPanel deletePanel = new JPanel(new BorderLayout(5, 0)); 336 JLabel label = new JLabel(JMeterUtils.getResString("delete")); // $NON-NLS-1$ 337 label.setLabelFor(delete); 338 deletePanel.add(label, BorderLayout.WEST); 339 deletePanel.add(delete, BorderLayout.CENTER); 340 panel.add(deletePanel); 341 return panel; 342 } 343 344 /** 345 * This will create the Add test panel in the LdapConfigGui. 346 */ 347 private JPanel createAddPanel() { 348 JPanel addPanel = new JPanel(new BorderLayout(5, 0)); 349 JPanel addInnerPanel = new JPanel(new BorderLayout(5, 0)); 350 JLabel label = new JLabel(JMeterUtils.getResString("entry_dn")); // $NON-NLS-1$ 351 label.setLabelFor(add); 352 addInnerPanel.add(label, BorderLayout.WEST); 353 addInnerPanel.add(add, BorderLayout.CENTER); 354 addPanel.add(addInnerPanel, BorderLayout.NORTH); 355 addPanel.add(tableAddPanel, BorderLayout.CENTER); 356 return addPanel; 357 } 358 359 /** 360 * This will create the Modify panel in the LdapConfigGui. 361 */ 362 private JPanel createModifyPanel() { 363 JPanel modifyPanel = new JPanel(new BorderLayout(5, 0)); 364 JPanel modifyInnerPanel = new JPanel(new BorderLayout(5, 0)); 365 JLabel label = new JLabel(JMeterUtils.getResString("entry_dn")); // $NON-NLS-1$ 366 label.setLabelFor(modify); 367 modifyInnerPanel.add(label, BorderLayout.WEST); 368 modifyInnerPanel.add(modify, BorderLayout.CENTER); 369 modifyPanel.add(modifyInnerPanel, BorderLayout.NORTH); 370 modifyPanel.add(tableModifyPanel, BorderLayout.CENTER); 371 return modifyPanel; 372 } 373 374 /** 375 * This will create the user defined test panel for create or modify or 376 * delete or search based on the panel selected in the itemevent in the 377 * LdapConfigGui. 378 */ 379 private JPanel testPanel() { 380 cards = new JPanel(new CardLayout()); 381 cards.add(new JPanel(), ""); 382 cards.add(createAddPanel(), "Add"); 383 cards.add(createModifyPanel(), "Modify"); 384 cards.add(createDeletePanel(), "Delete"); 385 cards.add(createSearchPanel(), "Search"); 386 return cards; 387 } 388 389 /** 390 * This will create the test panel in the LdapConfigGui. 391 */ 392 private JPanel createTestPanel() { 393 JPanel testPanel = new JPanel(new BorderLayout()); 394 testPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("test_configuration"))); // $NON-NLS-1$ 395 396 testPanel.add(new JLabel(JMeterUtils.getResString("test"))); // $NON-NLS-1$ 397 JPanel rowPanel = new JPanel(); 398 399 rowPanel.add(addTest); 400 bGroup.add(addTest); 401 rowPanel.add(deleteTest); 402 bGroup.add(deleteTest); 403 rowPanel.add(searchTest); 404 bGroup.add(searchTest); 405 rowPanel.add(modifyTest); 406 bGroup.add(modifyTest); 407 testPanel.add(rowPanel, BorderLayout.NORTH); 408 testPanel.add(user_Defined, BorderLayout.CENTER); 409 return testPanel; 410 } 411 412 /** 413 * This will initialise all the panel in the LdapConfigGui. 414 */ 415 private void init() { 416 setLayout(new BorderLayout(0, 5)); 417 418 if (displayName) { 419 setBorder(makeBorder()); 420 add(makeTitlePanel(), BorderLayout.NORTH); 421 } 422 VerticalPanel mainPanel = new VerticalPanel(); 423 mainPanel.add(createServernamePanel()); 424 mainPanel.add(createPortPanel()); 425 mainPanel.add(createRootdnPanel()); 426 mainPanel.add(createTestPanel()); 427 mainPanel.add(testPanel()); 428 add(mainPanel, BorderLayout.CENTER); 429 430 user_Defined.addItemListener(this); 431 addTest.addItemListener(this); 432 modifyTest.addItemListener(this); 433 deleteTest.addItemListener(this); 434 searchTest.addItemListener(this); 435 } 436 }