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  package com.eviware.soapui.impl.rest.panels.resource;
13  
14  import java.awt.BorderLayout;
15  import java.awt.Component;
16  
17  import javax.swing.JScrollPane;
18  import javax.swing.JTable;
19  import javax.swing.ListSelectionModel;
20  
21  import com.eviware.soapui.impl.rest.support.RestParamProperty;
22  import com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder;
23  import com.eviware.soapui.impl.support.actions.ShowOnlineHelpAction;
24  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
25  import com.eviware.soapui.support.UISupport;
26  import com.eviware.soapui.support.components.JXToolBar;
27  
28  public class InstanceRestParamsTable extends RestParamsTable
29  {
30  	private JTable paramsTable;
31  
32  	public InstanceRestParamsTable( RestParamsPropertyHolder params )
33  	{
34  		super( params, false );
35  	}
36  
37  	public JTable getParamsTable()
38  	{
39  		return paramsTable;
40  	}
41  
42  	protected void init( RestParamsPropertyHolder params, boolean showInspector )
43  	{
44  		paramsTableModel = new InstanceRestParamsTableModel( params );
45  		paramsTable = new JTable( paramsTableModel );
46  		paramsTable.setRowHeight( 19 );
47  		paramsTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
48  
49  		add( buildToolbar(), BorderLayout.NORTH );
50  		add( new JScrollPane( paramsTable ), BorderLayout.CENTER );
51  	}
52  
53  	protected Component buildToolbar()
54  	{
55  		JXToolBar toolbar = UISupport.createToolbar();
56  
57  		toolbar.add( UISupport.createToolbarButton( defaultParamsAction, paramsTable.getRowCount() > 0 ) );
58  		toolbar.add( UISupport.createToolbarButton( clearParamsAction, paramsTable.getRowCount() > 0 ) );
59  		toolbar.addSeparator();
60  
61  		insertAdditionalButtons( toolbar );
62  
63  		toolbar.addGlue();
64  
65  		toolbar.add( UISupport.createToolbarButton( new ShowOnlineHelpAction( HelpUrls.WADL_PARAMS_HELP_URL ) ) );
66  
67  		return toolbar;
68  	}
69  
70  	private class InstanceRestParamsTableModel extends RestParamsTableModel
71  	{
72  
73  		public InstanceRestParamsTableModel( RestParamsPropertyHolder params )
74  		{
75  			super( params );
76  		}
77  
78  		@Override
79  		public boolean isCellEditable( int rowIndex, int columnIndex )
80  		{
81  			return columnIndex == 1;
82  		}
83  
84  		public int getColumnCount()
85  		{
86  			return 2;
87  		}
88  
89  		@Override
90  		public String getColumnName( int column )
91  		{
92  			switch( column )
93  			{
94  			case 0 :
95  				return "Name";
96  			case 1 :
97  				return "Value";
98  			}
99  			return null;
100 		}
101 
102 		public Object getValueAt( int rowIndex, int columnIndex )
103 		{
104 			RestParamProperty prop = params.getPropertyAt( rowIndex );
105 
106 			switch( columnIndex )
107 			{
108 			case 0 :
109 				return prop.getName();
110 			case 1 :
111 				return prop.getValue();
112 			}
113 
114 			return null;
115 		}
116 
117 		@Override
118 		public void setValueAt( Object value, int rowIndex, int columnIndex )
119 		{
120 			RestParamProperty prop = params.getPropertyAt( rowIndex );
121 
122 			switch( columnIndex )
123 			{
124 			case 0 :
125 				prop.setName( value.toString() );
126 				return;
127 			case 1 :
128 				prop.setValue( value.toString() );
129 				return;
130 			}
131 		}
132 
133 	}
134 }