KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > ldap > config > gui > LdapConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java,v 1.7 2004/03/05 01:39:07 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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 JavaDoc;
22 import java.awt.CardLayout JavaDoc;
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25
26 import javax.swing.BorderFactory JavaDoc;
27 import javax.swing.ButtonGroup JavaDoc;
28 import javax.swing.JCheckBox JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JRadioButton JavaDoc;
32 import javax.swing.JTextField JavaDoc;
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  * @version $Revision: 1.7 $ Last updated: $Date: 2004/03/05 01:39:07 $
51  */

52 public class LdapConfigGui extends AbstractConfigGui implements ItemListener JavaDoc
53 {
54
55     private JTextField JavaDoc rootdn = new JTextField JavaDoc(20);
56     private JTextField JavaDoc searchbase = new JTextField JavaDoc(20);
57     private JTextField JavaDoc searchfilter = new JTextField JavaDoc(20);
58     private JTextField JavaDoc delete = new JTextField JavaDoc(20);
59     private JTextField JavaDoc add = new JTextField JavaDoc(20);
60     private JTextField JavaDoc modify = new JTextField JavaDoc(20);
61     private JTextField JavaDoc servername = new JTextField JavaDoc(20);
62     private JTextField JavaDoc port = new JTextField JavaDoc(20);
63
64     private JCheckBox JavaDoc user_Defined =
65         new JCheckBox JavaDoc(JMeterUtils.getResString("user_defined_test"));
66     private JRadioButton JavaDoc addTest =
67         new JRadioButton JavaDoc(JMeterUtils.getResString("add_test"));
68     private JRadioButton JavaDoc modifyTest =
69         new JRadioButton JavaDoc(JMeterUtils.getResString("modify_test"));
70     private JRadioButton JavaDoc deleteTest =
71         new JRadioButton JavaDoc(JMeterUtils.getResString("delete_test"));
72     private JRadioButton JavaDoc searchTest =
73         new JRadioButton JavaDoc(JMeterUtils.getResString("search_test"));
74     private ButtonGroup JavaDoc bGroup = new ButtonGroup JavaDoc();
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 JavaDoc cards;
81
82     /**
83      * Default constructor for LdapConfigGui.
84      */

85     public LdapConfigGui()
86     {
87         this(true);
88     }
89
90     public String JavaDoc getLabelResource()
91     {
92         return "ldap_sample_title";
93     }
94
95     /**
96      * A newly created component can be initialized with the contents of
97      * a Test Element object by calling this method. The component is
98      * responsible for querying the Test Element object for the
99      * relevant information to display in its GUI.
100      *
101      * @param element the TestElement to configure
102      */

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 JavaDoc cl = (CardLayout JavaDoc)(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     /* Implements JMeterGUIComponent.createTestElement() */
159     public TestElement createTestElement()
160     {
161         ConfigTestElement element = new ConfigTestElement();
162         modifyTestElement(element);
163         return element;
164     }
165
166     /**
167      * Modifies a given TestElement to mirror the data in the gui components.
168      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
169      */

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     /**
233      * This itemStateChanged listener for changing the card layout for based on\
234      * the test selected in the User defined test case.
235      */

236     public void itemStateChanged(ItemEvent JavaDoc ie)
237     {
238         CardLayout JavaDoc cl = (CardLayout JavaDoc)(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     /**
300      * This will create the servername panel in the LdapConfigGui.
301      */

302     private JPanel JavaDoc createServernamePanel()
303     {
304         JPanel JavaDoc serverPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
305         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
313      * This will create the port panel in the LdapConfigGui.
314      */

315     private JPanel JavaDoc createPortPanel()
316     {
317         JPanel JavaDoc portPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
318         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
326      * This will create the Root distinguised name panel in the LdapConfigGui.
327      */

328     private JPanel JavaDoc createRootdnPanel()
329     {
330         JPanel JavaDoc rootdnPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
331         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
339      * This will create the Search panel in the LdapConfigGui.
340      */

341     private JPanel JavaDoc createSearchPanel()
342     {
343         VerticalPanel searchPanel = new VerticalPanel();
344         JPanel JavaDoc searchBPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
345         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("search_base"));
346         label.setLabelFor(searchbase);
347         searchBPanel.add(label, BorderLayout.WEST);
348         searchBPanel.add(searchbase, BorderLayout.CENTER);
349         JPanel JavaDoc searchFPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
350         JLabel JavaDoc label2 = new JLabel JavaDoc(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     /**
360      * This will create the Delete panel in the LdapConfigGui.
361      */

362     private JPanel JavaDoc createDeletePanel()
363     {
364         VerticalPanel panel = new VerticalPanel();
365         JPanel JavaDoc deletePanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
366         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
375      * This will create the Add test panel in the LdapConfigGui.
376      */

377     private JPanel JavaDoc createAddPanel()
378     {
379         JPanel JavaDoc addPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5,0));
380         JPanel JavaDoc addInnerPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
381         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
391      * This will create the Modify panel in the LdapConfigGui.
392      */

393     private JPanel JavaDoc createModifyPanel()
394     {
395         JPanel JavaDoc modifyPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5,0));
396         JPanel JavaDoc modifyInnerPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
397         JLabel JavaDoc label = new JLabel JavaDoc(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     /**
407      * This will create the user defined test panel for create or modify or
408      * delete or search based on the panel selected in the itemevent in the
409      * LdapConfigGui.
410      */

411     private JPanel JavaDoc testPanel()
412     {
413         cards = new JPanel JavaDoc(new CardLayout JavaDoc());
414         cards.add(new JPanel JavaDoc(),"");
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     /**
424      * This will create the test panel in the LdapConfigGui.
425      */

426     private JPanel JavaDoc createTestPanel()
427     {
428         JPanel JavaDoc testPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
429         testPanel.setBorder(
430             BorderFactory.createTitledBorder(
431                 JMeterUtils.getResString("test_configuration")));
432
433         testPanel.add(new JLabel JavaDoc(JMeterUtils.getResString("test")));
434         JPanel JavaDoc rowPanel = new JPanel JavaDoc();
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     /**
450      * This will initialise all the panel in the LdapConfigGui.
451      */

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 JavaDoc(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