1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface.tools.support;
14
15 import java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.List;
20
21 import javax.swing.JPanel;
22 import javax.swing.JScrollPane;
23 import javax.swing.JTable;
24 import javax.swing.table.AbstractTableModel;
25
26 import org.jdesktop.swingx.JXTable;
27
28 import com.eviware.soapui.SoapUI;
29 import com.eviware.soapui.model.iface.Interface;
30 import com.eviware.soapui.support.UISupport;
31 import com.eviware.soapui.support.types.StringToStringMap;
32 import com.eviware.x.form.XForm.ToolkitType;
33 import com.eviware.x.impl.swing.AbstractSwingXFormField;
34
35 /***
36 * Swing JTable for holding Namespace/Package mappings
37 * @author ole.matzura
38 *
39 */
40
41 public class NamespaceTable extends AbstractSwingXFormField<JPanel>
42 {
43 private JXTable table;
44 private JScrollPane scrollPane;
45 private final Interface iface;
46 private NamespaceTableModel namespaceTableModel;
47
48 public NamespaceTable(Interface iface)
49 {
50 super( new JPanel(new BorderLayout()) );
51
52 this.iface = iface;
53
54 namespaceTableModel = new NamespaceTableModel();
55 table = new JXTable( namespaceTableModel );
56 table.setHorizontalScrollEnabled( true );
57 scrollPane = new JScrollPane( table );
58 scrollPane.setPreferredSize( new Dimension( 300, 150 ));
59 getComponent().add( scrollPane, BorderLayout.CENTER );
60 }
61
62 public JPanel getComponent(ToolkitType toolkitType)
63 {
64 if( toolkitType == ToolkitType.SWT )
65 {
66 UISupport.showErrorMessage( "SWT not supported by namespace table");
67 return null;
68 }
69
70 return getComponent();
71 }
72
73 public void setValue(String value)
74 {
75 namespaceTableModel.setMappings( StringToStringMap.fromXml( value ) );
76 }
77
78 public String getValue()
79 {
80 return namespaceTableModel.getMappings().toXml();
81 }
82
83 private class NamespaceTableModel extends AbstractTableModel
84 {
85 private List<String> namespaces = new ArrayList<String>();
86 private List<String> packages;
87
88 public NamespaceTableModel()
89 {
90 try
91 {
92 if( iface != null )
93 namespaces.addAll( iface.getWsdlContext().getDefinedNamespaces());
94 }
95 catch (Exception e)
96 {
97 SoapUI.logError( e );
98 }
99
100 packages = new ArrayList<String>(Arrays.asList(new String[namespaces.size()]));
101 }
102
103 public void setMappings(StringToStringMap mapping)
104 {
105 for( int c = 0; c < namespaces.size(); c++ )
106 {
107 if( mapping.containsKey( namespaces.get( c )))
108 {
109 packages.set( c, mapping.get( namespaces.get( c )));
110 }
111 else
112 {
113 packages.set( c, "" );
114 }
115 }
116
117 fireTableDataChanged();
118 }
119
120 public int getRowCount()
121 {
122 return namespaces.size();
123 }
124
125 public int getColumnCount()
126 {
127 return 2;
128 }
129
130 public Class<?> getColumnClass(int columnIndex)
131 {
132 return String.class;
133 }
134
135 public String getColumnName(int column)
136 {
137 return column == 0 ? "Namespace" : "Package";
138 }
139
140 public boolean isCellEditable(int rowIndex, int columnIndex)
141 {
142 return columnIndex == 1;
143 }
144
145 public void setValueAt(Object aValue, int rowIndex, int columnIndex)
146 {
147 if( columnIndex == 1 )
148 packages.set( rowIndex, aValue.toString() );
149 }
150
151 public Object getValueAt(int rowIndex, int columnIndex)
152 {
153 if( columnIndex == 0 )
154 return namespaces.get( rowIndex );
155 else
156 return packages/get( rowIndex )/package-summary.html">ong> packages.get( rowIndex );
157 }
158
159 public StringToStringMap getMappings()
160 {
161 StringToStringMap result = new StringToStringMap();
162 for( int c = 0; c < namespaces.size(); c++ )
163 {
164 String pkg = packages.get(c);
165 if( pkg != null && pkg.trim().length() > 0 )
166 {
167 result.put( namespaces.get( c ), pkg.trim() );
168 }
169 }
170
171 return result;
172 }
173 }
174
175
176 @Override
177 public boolean isMultiRow()
178 {
179 return true;
180 }
181 }