root / branches / v2_0_0_prep / extensions / extDalTransformJoin / src / org / gvsig / app / join / daltransform / SelectParametersWizardPanel.java @ 38552
History | View | Annotate | Download (10.6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.app.join.daltransform; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.util.ArrayList; |
33 |
|
34 |
import javax.swing.JOptionPane; |
35 |
|
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.app.ApplicationLocator; |
41 |
import org.gvsig.app.join.utils.TransformUtils; |
42 |
import org.gvsig.daltransform.swing.DataTransformWizardPanel; |
43 |
import org.gvsig.daltransform.swing.impl.AbstractDataTransformWizardPanel; |
44 |
import org.gvsig.daltransform.swing.impl.components.FeatureTypeAttributesCombo; |
45 |
import org.gvsig.daltransform.swing.impl.components.FeatureTypeAttributesList; |
46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 |
import org.gvsig.fmap.dal.feature.FeatureType; |
50 |
import org.gvsig.i18n.Messages; |
51 |
|
52 |
|
53 |
/**
|
54 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
55 |
*/
|
56 |
public class SelectParametersWizardPanel extends AbstractDataTransformWizardPanel |
57 |
implements DataTransformWizardPanel, ActionListener{ |
58 |
|
59 |
private static Logger logger = |
60 |
LoggerFactory.getLogger(SelectParametersWizardPanel.class); |
61 |
|
62 |
private javax.swing.JLabel attributesLabel;
|
63 |
private FeatureTypeAttributesList attributesList;
|
64 |
private javax.swing.JScrollPane attributesScroll;
|
65 |
private FeatureTypeAttributesCombo key1Combo;
|
66 |
private javax.swing.JLabel key1Label;
|
67 |
private FeatureTypeAttributesCombo key2_Combo;
|
68 |
private javax.swing.JLabel key2Label;
|
69 |
private javax.swing.JLabel prefix1Label;
|
70 |
private javax.swing.JTextField prefix1Text;
|
71 |
private javax.swing.JLabel prefix2Label;
|
72 |
private javax.swing.JTextField prefix2Text;
|
73 |
|
74 |
private FeatureStore secondFeatStore = null; |
75 |
|
76 |
/**
|
77 |
* @param featureTransformWizardModel
|
78 |
*/
|
79 |
public SelectParametersWizardPanel() {
|
80 |
super();
|
81 |
initComponents(); |
82 |
initLabels(); |
83 |
} |
84 |
|
85 |
private void initLabels(){ |
86 |
key1Label.setText(PluginServices.getText(this,"join_first_key")); |
87 |
key2Label.setText(PluginServices.getText(this,"join_second_key")); |
88 |
prefix1Label.setText(PluginServices.getText(this,"join_first_prefix")); |
89 |
prefix2Label.setText(PluginServices.getText(this,"join_second_prefix")); |
90 |
attributesLabel.setText(PluginServices.getText(this,"join_select_attributes")); |
91 |
} |
92 |
|
93 |
private void initComponents() { |
94 |
java.awt.GridBagConstraints gridBagConstraints; |
95 |
|
96 |
prefix2Text = new javax.swing.JTextField();
|
97 |
key2_Combo = new FeatureTypeAttributesCombo();
|
98 |
prefix1Text = new javax.swing.JTextField();
|
99 |
key1Label = new javax.swing.JLabel();
|
100 |
|
101 |
key1Combo = new FeatureTypeAttributesCombo();
|
102 |
// listen to changes in first combo
|
103 |
// we'll update second combo leaving
|
104 |
// fields of same type
|
105 |
key1Combo.addActionListener(this);
|
106 |
|
107 |
key2Label = new javax.swing.JLabel();
|
108 |
prefix1Label = new javax.swing.JLabel();
|
109 |
prefix2Label = new javax.swing.JLabel();
|
110 |
attributesLabel = new javax.swing.JLabel();
|
111 |
attributesScroll = new javax.swing.JScrollPane();
|
112 |
attributesList = new FeatureTypeAttributesList();
|
113 |
|
114 |
setLayout(new java.awt.GridBagLayout());
|
115 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
116 |
gridBagConstraints.gridx = 0;
|
117 |
gridBagConstraints.gridy = 7;
|
118 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
119 |
gridBagConstraints.weightx = 1.0;
|
120 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2); |
121 |
add(prefix2Text, gridBagConstraints); |
122 |
|
123 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
124 |
gridBagConstraints.gridx = 0;
|
125 |
gridBagConstraints.gridy = 3;
|
126 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
127 |
gridBagConstraints.weightx = 1.0;
|
128 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2); |
129 |
add(key2_Combo, gridBagConstraints); |
130 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
131 |
gridBagConstraints.gridx = 0;
|
132 |
gridBagConstraints.gridy = 5;
|
133 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
134 |
gridBagConstraints.weightx = 1.0;
|
135 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2); |
136 |
add(prefix1Text, gridBagConstraints); |
137 |
|
138 |
key1Label.setText("jLabel1");
|
139 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
140 |
gridBagConstraints.gridx = 0;
|
141 |
gridBagConstraints.gridy = 0;
|
142 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
143 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
144 |
add(key1Label, gridBagConstraints); |
145 |
|
146 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
147 |
gridBagConstraints.gridx = 0;
|
148 |
gridBagConstraints.gridy = 1;
|
149 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
150 |
gridBagConstraints.weightx = 1.0;
|
151 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2); |
152 |
add(key1Combo, gridBagConstraints); |
153 |
|
154 |
key2Label.setText("jLabel2");
|
155 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
156 |
gridBagConstraints.gridx = 0;
|
157 |
gridBagConstraints.gridy = 2;
|
158 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
159 |
gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2); |
160 |
add(key2Label, gridBagConstraints); |
161 |
|
162 |
prefix1Label.setText("jLabel1");
|
163 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
164 |
gridBagConstraints.gridx = 0;
|
165 |
gridBagConstraints.gridy = 4;
|
166 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
167 |
gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2); |
168 |
add(prefix1Label, gridBagConstraints); |
169 |
|
170 |
prefix2Label.setText("jLabel2");
|
171 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
172 |
gridBagConstraints.gridx = 0;
|
173 |
gridBagConstraints.gridy = 6;
|
174 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
175 |
gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2); |
176 |
add(prefix2Label, gridBagConstraints); |
177 |
|
178 |
attributesLabel.setText("attributesLabel");
|
179 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
180 |
gridBagConstraints.gridx = 0;
|
181 |
gridBagConstraints.gridy = 8;
|
182 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
183 |
gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2); |
184 |
add(attributesLabel, gridBagConstraints); |
185 |
|
186 |
attributesScroll.setViewportView(attributesList); |
187 |
|
188 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
189 |
gridBagConstraints.gridx = 0;
|
190 |
gridBagConstraints.gridy = 9;
|
191 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
192 |
gridBagConstraints.weightx = 1.0;
|
193 |
gridBagConstraints.weighty = 1.0;
|
194 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
195 |
add(attributesScroll, gridBagConstraints); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* @return
|
200 |
*/
|
201 |
public String getKeyAttr1() { |
202 |
return key1Combo.getSelectedFeatureAttributeDescriptor().getName();
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* @return
|
207 |
*/
|
208 |
public String getkeyAtrr2() { |
209 |
return key2_Combo.getSelectedFeatureAttributeDescriptor().getName();
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* @return
|
214 |
*/
|
215 |
public String getPrefix1() { |
216 |
return prefix1Text.getText();
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* @return
|
221 |
*/
|
222 |
public String getPrefix2() { |
223 |
return prefix2Text.getText();
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* @return
|
228 |
*/
|
229 |
public String[] getAttributes() { |
230 |
return attributesList.getAttributesName();
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* @param selectedFeatureStore
|
235 |
* @throws DataException
|
236 |
*/
|
237 |
public void updateFeatureStores(FeatureStore selectedFeatureStore) throws DataException { |
238 |
secondFeatStore = selectedFeatureStore; |
239 |
key1Combo.addFeatureAttributes(getFeatureStore().getDefaultFeatureType()); |
240 |
attributesList.addFeatureAttributes(selectedFeatureStore.getDefaultFeatureType()); |
241 |
|
242 |
if (key1Combo.getItemCount() == 0) { |
243 |
|
244 |
String _msg =
|
245 |
Messages.getText("_First_table_has_no_fields");
|
246 |
String _tit = Messages.getText("_Join"); |
247 |
|
248 |
JOptionPane.showMessageDialog(
|
249 |
this, _msg, _tit,
|
250 |
JOptionPane.ERROR_MESSAGE);
|
251 |
|
252 |
getDataTransformWizard().setApplicable(false);
|
253 |
} else {
|
254 |
key1Combo.setSelectedIndex(0);
|
255 |
} |
256 |
} |
257 |
|
258 |
|
259 |
/**
|
260 |
* Listen to changes in first combo box (key1)
|
261 |
*/
|
262 |
public void actionPerformed(ActionEvent e) { |
263 |
|
264 |
Object src = e.getSource();
|
265 |
if (src == key1Combo
|
266 |
&& key1Combo != null
|
267 |
&& key2_Combo != null
|
268 |
&& secondFeatStore != null) {
|
269 |
|
270 |
FeatureAttributeDescriptor att = |
271 |
key1Combo.getSelectedFeatureAttributeDescriptor(); |
272 |
if (att != null) { |
273 |
|
274 |
int the_type = att.getType();
|
275 |
key2_Combo.removeAllItems(); |
276 |
FeatureType ft = null;
|
277 |
|
278 |
try {
|
279 |
ft = secondFeatStore.getDefaultFeatureType(); |
280 |
} catch (DataException de) {
|
281 |
logger.info("While getting feat type: " + de.getMessage());
|
282 |
getDataTransformWizard().setApplicable(false);
|
283 |
ApplicationLocator.getManager().message( |
284 |
Messages.getText("_Error_getting_attributes"),
|
285 |
JOptionPane.ERROR_MESSAGE);
|
286 |
return;
|
287 |
} |
288 |
|
289 |
ArrayList<Integer> comparable_types = |
290 |
TransformUtils.getComparableDataTypes(ft, the_type); |
291 |
|
292 |
if (key2_Combo.addFeatureAttributes(ft, comparable_types) == 0) { |
293 |
getDataTransformWizard().setApplicable(false);
|
294 |
|
295 |
String _msg =
|
296 |
Messages.getText("_No_compatible_field_in_second_table");
|
297 |
String _tit = Messages.getText("_Join"); |
298 |
|
299 |
JOptionPane.showMessageDialog(
|
300 |
this, _msg, _tit,
|
301 |
JOptionPane.ERROR_MESSAGE);
|
302 |
} else {
|
303 |
getDataTransformWizard().setApplicable(true);
|
304 |
// JOptionPane.showMessageDialog(this, "(2) OK !!");
|
305 |
} |
306 |
} |
307 |
} |
308 |
|
309 |
} |
310 |
} |
311 |
|