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