View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.impl.rest.panels.resource;
14  
15  import com.eviware.soapui.impl.rest.support.XmlBeansRestParamsTestPropertyHolder;
16  import com.eviware.soapui.impl.rest.support.XmlBeansRestParamsTestPropertyHolder.ParameterStyle;
17  import com.eviware.soapui.impl.rest.support.XmlBeansRestParamsTestPropertyHolder.RestParamProperty;
18  import com.eviware.soapui.model.testsuite.TestPropertyListener;
19  import com.eviware.soapui.support.StringUtils;
20  
21  import javax.swing.table.AbstractTableModel;
22  import javax.swing.table.TableModel;
23  
24  public class RestParamsTableModel extends AbstractTableModel implements TableModel, TestPropertyListener
25  {
26  	private final XmlBeansRestParamsTestPropertyHolder params;
27  
28  	public RestParamsTableModel(XmlBeansRestParamsTestPropertyHolder params)
29  	{
30  		this.params = params;
31  
32        params.addTestPropertyListener( this );
33  	}
34  
35     public int getColumnCount()
36  	{
37  		return 3;
38  	}
39  
40  	@Override
41  	public String getColumnName(int column)
42  	{
43  		switch (column)
44  		{
45  			case 0: return "Name";
46  			case 1: return "Value";
47  			case 2: return "Style";
48  		}
49  		
50  		return null;
51  	}
52  	
53  	@Override
54  	public Class<?> getColumnClass(int columnIndex)
55  	{
56  		return columnIndex < 2 ? String.class : ParameterStyle.class;
57  	}
58  
59  	@Override
60  	public boolean isCellEditable(int rowIndex, int columnIndex)
61  	{
62  		return true;
63  	}
64  
65  	public int getRowCount()
66  	{
67  		return params.getPropertyCount();
68  	}
69  
70  	public Object getValueAt(int rowIndex, int columnIndex)
71  	{
72  		RestParamProperty prop = params.getPropertyAt(rowIndex);
73  
74  		switch( columnIndex)
75  		{
76  		case 0 : return prop.getName();
77  		case 1 : return StringUtils.hasContent(prop.getValue()) ? prop.getValue() : prop.getDefaultValue();
78  		case 2 : return prop.getStyle();
79  		}
80  		
81  		return null;
82  	}
83  
84  
85  	@Override
86  	public void setValueAt(Object value, int rowIndex, int columnIndex)
87  	{
88  		RestParamProperty prop = params.getPropertyAt(rowIndex);
89  		
90  		switch (columnIndex)
91  		{
92  		case 0 : prop.setName( value.toString() ); return;
93  		case 1 : prop.setValue( value.toString() ); return;
94  		case 2 : prop.setStyle( (ParameterStyle) value ); return;
95  		}
96  	}
97  
98  	public RestParamProperty getParameterAt(int selectedRow)
99  	{
100 		return params.getPropertyAt(selectedRow);
101 	}
102 
103    public void propertyAdded( String name )
104    {
105       fireTableDataChanged();
106    }
107 
108    public void propertyRemoved( String name )
109    {
110       fireTableDataChanged();
111    }
112 
113    public void propertyRenamed( String oldName, String newName )
114    {
115       fireTableDataChanged();
116    }
117 
118    public void propertyValueChanged( String name, String oldValue, String newValue )
119    {
120       fireTableCellUpdated( params.getPropertyIndex( name ), 1 );
121    }
122 
123    public void propertyMoved( String name, int oldIndex, int newIndex )
124    {
125       fireTableDataChanged();
126    }
127 }