View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.components;
14  
15  import javax.swing.ComboBoxModel;
16  import javax.swing.JCheckBox;
17  import javax.swing.JComboBox;
18  import javax.swing.JComponent;
19  import javax.swing.JPasswordField;
20  import javax.swing.JTextArea;
21  import javax.swing.JTextField;
22  
23  import com.jgoodies.binding.PresentationModel;
24  import com.jgoodies.binding.adapter.Bindings;
25  import com.jgoodies.binding.list.SelectionInList;
26  
27  public class SimpleBindingForm extends SimpleForm
28  {
29  	private final PresentationModel<?> pm;
30  
31  	public SimpleBindingForm( PresentationModel<?> pm )
32  	{
33  		this.pm = pm;
34  	}
35  
36  	public JTextField appendTextField( String propertyName, String label, String tooltip )
37  	{
38  		JTextField textField = super.appendTextField( label, tooltip );
39  		Bindings.bind( textField, pm.getModel( propertyName ) );
40  		return textField;
41  	}
42  
43  	public JTextArea appendTextArea( String propertyName, String label, String tooltip )
44  	{
45  		JTextArea textArea = super.appendTextArea( label, tooltip );
46  		Bindings.bind( textArea, pm.getModel( propertyName ) );
47  		return textArea;
48  	}
49  
50  	public JPasswordField appendPasswordField( String propertyName, String label, String tooltip )
51  	{
52  		JPasswordField textField = super.appendPasswordField( label, tooltip );
53  		Bindings.bind( textField, pm.getModel( propertyName ) );
54  		return textField;
55  	}
56  
57  	public JCheckBox appendCheckBox( String propertyName, String label, String tooltip )
58  	{
59  		JCheckBox checkBox = super.appendCheckBox( label, tooltip, false );
60  		Bindings.bind( checkBox, pm.getModel( propertyName ) );
61  		return checkBox;
62  	}
63  
64  	public void appendComponent( String propertyName, String label, JComponent component )
65  	{
66  		super.append( label, component );
67  		Bindings.bind( component, propertyName, pm.getModel( propertyName ) );
68  	}
69  
70  	public JComboBox appendComboBox( String propertyName, String label, Object[] values, String tooltip )
71  	{
72  		JComboBox comboBox = super.appendComboBox( label, values, tooltip );
73  		Bindings.bind( comboBox, new SelectionInList<Object>( values, pm.getModel( propertyName ) ) );
74  		return comboBox;
75  	}
76  
77  	public JComboBox appendComboBox( String propertyName, String label, ComboBoxModel model, String tooltip )
78  	{
79  		JComboBox comboBox = super.appendComboBox( label, model, tooltip );
80  		Bindings.bind( comboBox, new SelectionInList<Object>( model, pm.getModel( propertyName ) ) );
81  		return comboBox;
82  	}
83  
84  }