1
2
3
4
5
6
7
8
9
10
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 }
106
107 public void propertyRemoved( String name )
108 {
109 }
110
111 public void propertyRenamed( String oldName, String newName )
112 {
113 }
114
115 public void propertyValueChanged( String name, String oldValue, String newValue )
116 {
117 fireTableCellUpdated( params.getPropertyIndex( name ), 1 );
118 }
119
120 public void propertyMoved( String name, int oldIndex, int newIndex )
121 {
122 }
123 }