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