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.control.gui; 20 21 import java.awt.BorderLayout; 22 23 import javax.swing.BorderFactory; 24 25 import org.apache.jmeter.config.gui.LoginConfigGui; 26 import org.apache.jmeter.gui.util.VerticalPanel; 27 import org.apache.jmeter.protocol.ldap.config.gui.LdapConfigGui; 28 import org.apache.jmeter.protocol.ldap.sampler.LDAPSampler; 29 import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 30 import org.apache.jmeter.testelement.TestElement; 31 import org.apache.jmeter.util.JMeterUtils; 32 33 public class LdapTestSamplerGui extends AbstractSamplerGui { 34 private LoginConfigGui loginPanel; 35 36 private LdapConfigGui ldapDefaultPanel; 37 38 public LdapTestSamplerGui() { 39 init(); 40 } 41 42 /** 43 * A newly created component can be initialized with the contents of a Test 44 * Element object by calling this method. The component is responsible for 45 * querying the Test Element object for the relevant information to display 46 * in its GUI. 47 * 48 * @param element 49 * the TestElement to configure 50 */ 51 public void configure(TestElement element) { 52 super.configure(element); 53 loginPanel.configure(element); 54 ldapDefaultPanel.configure(element); 55 } 56 57 public TestElement createTestElement() { 58 LDAPSampler sampler = new LDAPSampler(); 59 modifyTestElement(sampler); 60 return sampler; 61 } 62 63 /** 64 * Modifies a given TestElement to mirror the data in the gui components. 65 * 66 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement) 67 */ 68 public void modifyTestElement(TestElement sampler) { 69 sampler.clear(); 70 ((LDAPSampler) sampler).addTestElement(ldapDefaultPanel.createTestElement()); 71 ((LDAPSampler) sampler).addTestElement(loginPanel.createTestElement()); 72 this.configureTestElement(sampler); 73 } 74 75 /** 76 * Implements JMeterGUIComponent.clearGui 77 */ 78 public void clearGui() { 79 super.clearGui(); 80 81 ldapDefaultPanel.clearGui(); 82 loginPanel.clearGui(); 83 } 84 85 public String getLabelResource() { 86 return "ldap_testing_title"; // $NON-NLS-1$ 87 } 88 89 private void init() { 90 setLayout(new BorderLayout(0, 5)); 91 setBorder(makeBorder()); 92 // MAIN PANEL 93 VerticalPanel mainPanel = new VerticalPanel(); 94 loginPanel = new LoginConfigGui(false); 95 ldapDefaultPanel = new LdapConfigGui(false); 96 loginPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("login_config"))); // $NON-NLS-1$ 97 add(makeTitlePanel(), BorderLayout.NORTH); 98 mainPanel.add(loginPanel); 99 mainPanel.add(ldapDefaultPanel); 100 add(mainPanel, BorderLayout.CENTER); 101 } 102 }