1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.panels.teststeps.support;
13
14 import javax.swing.table.AbstractTableModel;
15
16 import com.eviware.soapui.impl.wsdl.MutableTestPropertyHolder;
17 import com.eviware.soapui.model.TestPropertyHolder;
18 import com.eviware.soapui.model.testsuite.TestProperty;
19 import com.eviware.soapui.support.UISupport;
20 import com.eviware.soapui.support.types.StringList;
21
22 public class DefaultPropertyTableHolderModel extends AbstractTableModel implements PropertyHolderTableModel
23 {
24 private StringList names = new StringList();
25 private final TestPropertyHolder holder;
26
27 public DefaultPropertyTableHolderModel( TestPropertyHolder holder )
28 {
29 this.holder = holder;
30 names = new StringList(getPropertyNames());
31 }
32
33 public String [] getPropertyNames()
34 {
35 return holder.getPropertyNames();
36 }
37
38 public int getRowCount()
39 {
40 return names.size();
41 }
42
43 public int getColumnCount()
44 {
45 return 2;
46 }
47
48 @Override
49 public void fireTableDataChanged()
50 {
51 names = new StringList(getPropertyNames());
52 super.fireTableDataChanged();
53 }
54
55 public String getColumnName( int columnIndex )
56 {
57 switch( columnIndex )
58 {
59 case 0 :
60 return "Name";
61 case 1 :
62 return "Value";
63 }
64
65 return null;
66 }
67
68 public boolean isCellEditable( int rowIndex, int columnIndex )
69 {
70 if( columnIndex == 0 )
71 {
72 return holder instanceof MutableTestPropertyHolder;
73 }
74
75 return !holder.getProperty( names.get( rowIndex ) ).isReadOnly();
76 }
77
78 public void setValueAt( Object aValue, int rowIndex, int columnIndex )
79 {
80 TestProperty property = holder.getProperty( names.get( rowIndex ) );
81 switch( columnIndex )
82 {
83 case 0 :
84 {
85 if( holder instanceof MutableTestPropertyHolder )
86 {
87 TestProperty prop = holder.getProperty( aValue.toString() );
88 if( prop != null && prop != property )
89 {
90 UISupport.showErrorMessage( "Property name exists!" );
91 return;
92 }
93 ( ( MutableTestPropertyHolder )holder ).renameProperty( property.getName(), aValue.toString() );
94 }
95 break;
96 }
97 case 1 :
98 {
99 property.setValue( aValue.toString() );
100 break;
101 }
102 }
103 }
104
105 @Override
106 public Class<?> getColumnClass( int columnIndex )
107 {
108 return String.class;
109 }
110
111 public TestProperty getPropertyAtRow( int rowIndex )
112 {
113 return holder.getProperty( names.get( rowIndex ) );
114 }
115
116 public Object getValueAt( int rowIndex, int columnIndex )
117 {
118 TestProperty property = holder.getProperty( names.get( rowIndex ) );
119 if( property == null )
120 return null;
121
122 switch( columnIndex )
123 {
124 case 0 :
125 return property.getName();
126 case 1 :
127 return property.getValue();
128 }
129
130 return null;
131 }
132 }