root / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / address / AddressComposedPanel.java @ 27756
History | View | Annotate | Download (20.5 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 |
* 2008 Prodevelop S.L. main developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.gui.address; |
29 |
|
30 |
import java.awt.Color; |
31 |
import java.io.File; |
32 |
import java.util.ArrayList; |
33 |
import java.util.Iterator; |
34 |
import java.util.List; |
35 |
import java.util.Vector; |
36 |
|
37 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JComboBox; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JScrollPane; |
42 |
import javax.swing.JTabbedPane; |
43 |
import javax.swing.JTable; |
44 |
import javax.swing.table.DefaultTableCellRenderer; |
45 |
import javax.swing.table.DefaultTableModel; |
46 |
import javax.swing.table.TableColumn; |
47 |
|
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.feature.Feature; |
50 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
51 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
52 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
53 |
import org.gvsig.geocoding.Address; |
54 |
import org.gvsig.geocoding.AddressComponent; |
55 |
import org.gvsig.geocoding.ComposeAddress; |
56 |
import org.gvsig.geocoding.Literal; |
57 |
import org.gvsig.geocoding.RelationsComponent; |
58 |
import org.gvsig.geocoding.extension.GeocoController; |
59 |
import org.gvsig.geocoding.gui.newpattern.ComboDesc; |
60 |
import org.gvsig.geocoding.utils.GeocoUtils; |
61 |
import org.slf4j.Logger; |
62 |
import org.slf4j.LoggerFactory; |
63 |
|
64 |
import com.iver.andami.PluginServices; |
65 |
|
66 |
/**
|
67 |
* Address composed panel
|
68 |
*
|
69 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
70 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
71 |
*/
|
72 |
public class AddressComposedPanel extends AbstractAddressPanel { |
73 |
|
74 |
private static final long serialVersionUID = 1L; |
75 |
private Logger log = LoggerFactory.getLogger(AddressComposedPanel.class); |
76 |
|
77 |
private GeocoController control = null; |
78 |
|
79 |
private JLabel jLabTypeBetween; |
80 |
private JLabel jLabTypeCross; |
81 |
private JPanel jPanAddressBetween; |
82 |
private JPanel jPanAddressCross; |
83 |
private JPanel jPanBetween; |
84 |
private JPanel jPanCross; |
85 |
private JScrollPane jScrollAddressBetween; |
86 |
private JScrollPane jScrollAddressCross; |
87 |
private JTabbedPane jTabbedComposed; |
88 |
private JTable jTableAddressBetween; |
89 |
private JTable jTableAddressCross; |
90 |
private JLabel jLabIdCross; |
91 |
private JPanel jPanIdCross; |
92 |
private JComboBox jComboIdCross; |
93 |
private JLabel jLabIdBetween; |
94 |
private JPanel jPanIdBetween; |
95 |
private JComboBox jComboIdBetween; |
96 |
|
97 |
private boolean iscross = true; |
98 |
|
99 |
/**
|
100 |
* Constructor
|
101 |
*/
|
102 |
public AddressComposedPanel(GeocoController control, Literal literal) {
|
103 |
|
104 |
this.control = control;
|
105 |
initComponents(); |
106 |
|
107 |
setImages(); |
108 |
setMesages(); |
109 |
|
110 |
// create table model
|
111 |
|
112 |
if (control.getGmodel().isSimple()) {
|
113 |
createSimpleTablesModels(literal); |
114 |
} else {
|
115 |
List<FeatureAttributeDescriptor> descs = control.getGmodel()
|
116 |
.getListDescriptorSelectedTable(); |
117 |
createTableTablesModels(literal, descs); |
118 |
jComboIdCross.setModel(createFieldsComboModel(descs)); |
119 |
jComboIdBetween.setModel(createFieldsComboModel(descs)); |
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Set images in the panel
|
125 |
*/
|
126 |
private void setImages() { |
127 |
String baseDir = PluginServices.getPluginServices(this) |
128 |
.getClassLoader().getBaseDir(); |
129 |
|
130 |
jLabTypeCross |
131 |
.setIcon(new ImageIcon(baseDir + File.separator + "images" |
132 |
+ File.separator + "new" + File.separator |
133 |
+ "composedcross.png"));
|
134 |
jLabTypeBetween.setIcon(new ImageIcon(baseDir + File.separator |
135 |
+ "images" + File.separator + "new" + File.separator |
136 |
+ "composedbetween.png"));
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* Set strings in the panel
|
141 |
*/
|
142 |
private void setMesages() { |
143 |
PluginServices ps = PluginServices.getPluginServices(this);
|
144 |
|
145 |
String element = ps.getText("xelement"); |
146 |
|
147 |
DefaultTableModel cmodel = (DefaultTableModel) jTableAddressCross |
148 |
.getModel(); |
149 |
String value1 = ps.getText("xvalue1"); |
150 |
String value2 = ps.getText("xvalue2"); |
151 |
Object[] headers = { element, value1, value2 }; |
152 |
cmodel.setColumnIdentifiers(headers); |
153 |
jTableAddressCross.setModel(cmodel); |
154 |
|
155 |
DefaultTableModel bmodel = (DefaultTableModel) jTableAddressBetween |
156 |
.getModel(); |
157 |
String value11 = ps.getText("xmainvalue"); |
158 |
String value22 = ps.getText("xvalue2"); |
159 |
String value33 = ps.getText("xvalue3"); |
160 |
Object[] bheaders = { element, value11, value22, value33 }; |
161 |
bmodel.setColumnIdentifiers(bheaders); |
162 |
jTableAddressBetween.setModel(bmodel); |
163 |
|
164 |
// tabs
|
165 |
String titleCross = ps.getText("xcross"); |
166 |
jTabbedComposed.setTitleAt(0, titleCross);
|
167 |
String titleBetween = ps.getText("xbetween"); |
168 |
jTabbedComposed.setTitleAt(1, titleBetween);
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Initialize components
|
173 |
*/
|
174 |
private void initComponents() { |
175 |
java.awt.GridBagConstraints gridBagConstraints; |
176 |
|
177 |
jTabbedComposed = new javax.swing.JTabbedPane();
|
178 |
jPanCross = new javax.swing.JPanel();
|
179 |
jLabTypeCross = new javax.swing.JLabel();
|
180 |
jPanAddressCross = new javax.swing.JPanel();
|
181 |
jScrollAddressCross = new javax.swing.JScrollPane();
|
182 |
jTableAddressCross = new javax.swing.JTable();
|
183 |
jPanBetween = new javax.swing.JPanel();
|
184 |
jLabTypeBetween = new javax.swing.JLabel();
|
185 |
jPanAddressBetween = new javax.swing.JPanel();
|
186 |
jScrollAddressBetween = new javax.swing.JScrollPane();
|
187 |
jTableAddressBetween = new javax.swing.JTable();
|
188 |
jLabIdCross = new JLabel(); |
189 |
jComboIdCross = new JComboBox(); |
190 |
jPanIdCross = new JPanel(); |
191 |
jLabIdBetween = new JLabel(); |
192 |
jComboIdBetween = new JComboBox(); |
193 |
jPanIdBetween = new JPanel(); |
194 |
|
195 |
setLayout(new java.awt.GridBagLayout());
|
196 |
|
197 |
jPanCross.setLayout(new java.awt.GridBagLayout());
|
198 |
|
199 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
200 |
gridBagConstraints.gridx = 0;
|
201 |
gridBagConstraints.gridy = 0;
|
202 |
gridBagConstraints.insets = new java.awt.Insets(3, 15, 5, 10); |
203 |
jPanCross.add(jLabTypeCross, gridBagConstraints); |
204 |
|
205 |
jPanAddressCross.setLayout(new java.awt.GridBagLayout());
|
206 |
|
207 |
jPanIdCross.setLayout(new java.awt.GridBagLayout());
|
208 |
|
209 |
if (!control.getGmodel().isSimple()) {
|
210 |
jLabIdCross.setText("Field ID");
|
211 |
jLabIdCross |
212 |
.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
213 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
214 |
gridBagConstraints.gridx = 0;
|
215 |
gridBagConstraints.gridy = 0;
|
216 |
gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 5); |
217 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
218 |
gridBagConstraints.weightx = 1.0;
|
219 |
jPanIdCross.add(jLabIdCross, gridBagConstraints); |
220 |
|
221 |
jComboIdCross.setModel(new javax.swing.DefaultComboBoxModel(
|
222 |
new String[] { "" })); |
223 |
jComboIdCross.setMinimumSize(new java.awt.Dimension(200, 20)); |
224 |
jComboIdCross.setName("jComboId");
|
225 |
|
226 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
227 |
gridBagConstraints.gridx = 1;
|
228 |
gridBagConstraints.gridy = 0;
|
229 |
gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4); |
230 |
jPanIdCross.add(jComboIdCross, gridBagConstraints); |
231 |
|
232 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
233 |
gridBagConstraints.gridx = 0;
|
234 |
gridBagConstraints.gridy = 0;
|
235 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
236 |
gridBagConstraints.weightx = 1.0;
|
237 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); |
238 |
jPanAddressCross.add(jPanIdCross, gridBagConstraints); |
239 |
} |
240 |
|
241 |
jTableAddressCross.setModel(new javax.swing.table.DefaultTableModel(
|
242 |
new Object[][] { { null, null, null }, { null, null, null }, |
243 |
{ null, null, null } }, new String[] { "Elements", |
244 |
"Values address 1 ", "Values address 2" }) { |
245 |
Class[] types = new Class[] { java.lang.String.class, |
246 |
java.lang.String.class, java.lang.String.class }; |
247 |
boolean[] canEdit = new boolean[] { false, true, true }; |
248 |
|
249 |
public Class getColumnClass(int columnIndex) { |
250 |
return types[columnIndex];
|
251 |
} |
252 |
|
253 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
254 |
return canEdit[columnIndex];
|
255 |
} |
256 |
}); |
257 |
|
258 |
jScrollAddressCross.setViewportView(jTableAddressCross); |
259 |
|
260 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
261 |
gridBagConstraints.gridx = 0;
|
262 |
gridBagConstraints.gridy = 2;
|
263 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
264 |
gridBagConstraints.weightx = 1.0;
|
265 |
gridBagConstraints.weighty = 1.0;
|
266 |
jPanAddressCross.add(jScrollAddressCross, gridBagConstraints); |
267 |
|
268 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
269 |
gridBagConstraints.gridx = 1;
|
270 |
gridBagConstraints.gridy = 0;
|
271 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
272 |
gridBagConstraints.weightx = 1.0;
|
273 |
gridBagConstraints.weighty = 1.0;
|
274 |
gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 10); |
275 |
jPanCross.add(jPanAddressCross, gridBagConstraints); |
276 |
|
277 |
jTabbedComposed.addTab("tab1", jPanCross);
|
278 |
|
279 |
jPanBetween.setLayout(new java.awt.GridBagLayout());
|
280 |
|
281 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
282 |
gridBagConstraints.gridx = 0;
|
283 |
gridBagConstraints.gridy = 0;
|
284 |
gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 10); |
285 |
jPanBetween.add(jLabTypeBetween, gridBagConstraints); |
286 |
|
287 |
jPanAddressBetween.setLayout(new java.awt.GridBagLayout());
|
288 |
|
289 |
jPanIdBetween.setLayout(new java.awt.GridBagLayout());
|
290 |
|
291 |
if (!control.getGmodel().isSimple()) {
|
292 |
jLabIdBetween.setText("Field ID");
|
293 |
jLabIdBetween |
294 |
.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
295 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
296 |
gridBagConstraints.gridx = 0;
|
297 |
gridBagConstraints.gridy = 0;
|
298 |
gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 5); |
299 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
300 |
gridBagConstraints.weightx = 1.0;
|
301 |
jPanIdBetween.add(jLabIdBetween, gridBagConstraints); |
302 |
|
303 |
jComboIdBetween.setModel(new javax.swing.DefaultComboBoxModel(
|
304 |
new String[] { "" })); |
305 |
jComboIdBetween.setMinimumSize(new java.awt.Dimension(200, 20)); |
306 |
jComboIdBetween.setName("jComboId");
|
307 |
|
308 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
309 |
gridBagConstraints.gridx = 1;
|
310 |
gridBagConstraints.gridy = 0;
|
311 |
gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4); |
312 |
jPanIdBetween.add(jComboIdBetween, gridBagConstraints); |
313 |
|
314 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
315 |
gridBagConstraints.gridx = 0;
|
316 |
gridBagConstraints.gridy = 0;
|
317 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
318 |
gridBagConstraints.weightx = 1.0;
|
319 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); |
320 |
jPanAddressBetween.add(jPanIdBetween, gridBagConstraints); |
321 |
} |
322 |
|
323 |
jTableAddressBetween |
324 |
.setModel(new javax.swing.table.DefaultTableModel(
|
325 |
new Object[][] { { null, null, null, null }, |
326 |
{ null, null, null, null }, |
327 |
{ null, null, null, null } }, new String[] { |
328 |
"Elements", "Values main address", |
329 |
"Values address 2", "values address 3" }) { |
330 |
Class[] types = new Class[] { java.lang.String.class, |
331 |
java.lang.String.class, java.lang.String.class, |
332 |
java.lang.String.class }; |
333 |
boolean[] canEdit = new boolean[] { false, true, true, true }; |
334 |
|
335 |
public Class getColumnClass(int columnIndex) { |
336 |
return types[columnIndex];
|
337 |
} |
338 |
|
339 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
340 |
return canEdit[columnIndex];
|
341 |
} |
342 |
}); |
343 |
|
344 |
jScrollAddressBetween.setViewportView(jTableAddressBetween); |
345 |
|
346 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
347 |
gridBagConstraints.gridx = 0;
|
348 |
gridBagConstraints.gridy = 1;
|
349 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
350 |
gridBagConstraints.weightx = 1.0;
|
351 |
gridBagConstraints.weighty = 1.0;
|
352 |
jPanAddressBetween.add(jScrollAddressBetween, gridBagConstraints); |
353 |
|
354 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
355 |
gridBagConstraints.gridx = 1;
|
356 |
gridBagConstraints.gridy = 0;
|
357 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
358 |
gridBagConstraints.weightx = 1.0;
|
359 |
gridBagConstraints.weighty = 1.0;
|
360 |
gridBagConstraints.insets = new java.awt.Insets(10, 15, 10, 10); |
361 |
jPanBetween.add(jPanAddressBetween, gridBagConstraints); |
362 |
|
363 |
jTabbedComposed.addTab("tab2", jPanBetween);
|
364 |
|
365 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
366 |
gridBagConstraints.gridx = 0;
|
367 |
gridBagConstraints.gridy = 0;
|
368 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
369 |
gridBagConstraints.weightx = 1.0;
|
370 |
gridBagConstraints.weighty = 1.0;
|
371 |
add(jTabbedComposed, gridBagConstraints); |
372 |
} |
373 |
|
374 |
/**
|
375 |
* Create a simple tables models from literal components
|
376 |
*
|
377 |
* @param lit
|
378 |
*/
|
379 |
private void createSimpleTablesModels(Literal lit) { |
380 |
|
381 |
DefaultTableCellRenderer render = new DefaultTableCellRenderer(); |
382 |
render.setBackground(new Color(255, 253, 224)); |
383 |
|
384 |
// Cross tab
|
385 |
DefaultTableModel modelcross = (DefaultTableModel) jTableAddressCross |
386 |
.getModel(); |
387 |
TableColumn colcross0 = jTableAddressCross.getColumnModel()
|
388 |
.getColumn(0);
|
389 |
colcross0.setCellRenderer(render); |
390 |
|
391 |
// fill elements
|
392 |
super.clearTableModel(modelcross);
|
393 |
|
394 |
for (Object obj : lit) { |
395 |
RelationsComponent comp = (RelationsComponent) obj; |
396 |
String key = comp.getKeyElement();
|
397 |
Object[] row = { key, "", "" }; |
398 |
modelcross.addRow(row); |
399 |
} |
400 |
jTableAddressCross.setModel(modelcross); |
401 |
|
402 |
// Between tab
|
403 |
DefaultTableModel modelbetween = (DefaultTableModel) jTableAddressBetween |
404 |
.getModel(); |
405 |
// first column
|
406 |
TableColumn colbetween0 = jTableAddressBetween.getColumnModel()
|
407 |
.getColumn(0);
|
408 |
colbetween0.setCellRenderer(render); |
409 |
|
410 |
// fill elements
|
411 |
super.clearTableModel(modelbetween);
|
412 |
|
413 |
for (Object obj : lit) { |
414 |
RelationsComponent comp = (RelationsComponent) obj; |
415 |
String key = comp.getKeyElement();
|
416 |
Object[] row = { key, "", "", "" }; |
417 |
modelbetween.addRow(row); |
418 |
} |
419 |
jTableAddressBetween.setModel(modelbetween); |
420 |
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* Create a table tables models from literal components
|
425 |
*
|
426 |
* @param lit
|
427 |
*/
|
428 |
private void createTableTablesModels(Literal lit, |
429 |
List<FeatureAttributeDescriptor> descs) {
|
430 |
|
431 |
DefaultTableCellRenderer render = new DefaultTableCellRenderer(); |
432 |
render.setBackground(new Color(255, 253, 224)); |
433 |
|
434 |
// Croos tab
|
435 |
DefaultTableModel modelcross = (DefaultTableModel) jTableAddressCross |
436 |
.getModel(); |
437 |
|
438 |
// first column
|
439 |
TableColumn columncross0 = jTableAddressCross.getColumnModel()
|
440 |
.getColumn(0);
|
441 |
columncross0.setCellRenderer(render); |
442 |
|
443 |
// fill elements
|
444 |
super.clearTableModel(modelcross);
|
445 |
|
446 |
// Put combos in the column 1
|
447 |
super.putCombosInTable(jTableAddressCross, descs, 1); |
448 |
|
449 |
// Put combos in the column 2
|
450 |
super.putCombosInTable(jTableAddressCross, descs, 2); |
451 |
|
452 |
// put the elements in the column 0
|
453 |
for (Object obj : lit) { |
454 |
RelationsComponent comp = (RelationsComponent) obj; |
455 |
// key
|
456 |
String key = comp.getKeyElement();
|
457 |
|
458 |
// insert
|
459 |
Object[] row = { key, "", "" }; |
460 |
modelcross.addRow(row); |
461 |
} |
462 |
jTableAddressCross.setModel(modelcross); |
463 |
|
464 |
// Between tab
|
465 |
DefaultTableModel modelbetween = (DefaultTableModel) jTableAddressBetween |
466 |
.getModel(); |
467 |
|
468 |
// first column
|
469 |
TableColumn columnbetween0 = jTableAddressBetween.getColumnModel()
|
470 |
.getColumn(0);
|
471 |
columnbetween0.setCellRenderer(render); |
472 |
|
473 |
// fill elements
|
474 |
super.clearTableModel(modelbetween);
|
475 |
|
476 |
// Put combos in the column 1
|
477 |
super.putCombosInTable(jTableAddressBetween, descs, 1); |
478 |
|
479 |
// Put combos in the column 2
|
480 |
super.putCombosInTable(jTableAddressBetween, descs, 2); |
481 |
|
482 |
// Put combos in the column 3
|
483 |
super.putCombosInTable(jTableAddressBetween, descs, 3); |
484 |
|
485 |
// put the elements in the column 0
|
486 |
for (Object obj : lit) { |
487 |
RelationsComponent comp = (RelationsComponent) obj; |
488 |
// key
|
489 |
String key = comp.getKeyElement();
|
490 |
|
491 |
// insert
|
492 |
Object[] row = { key, "", "", "" }; |
493 |
modelbetween.addRow(row); |
494 |
} |
495 |
jTableAddressBetween.setModel(modelbetween); |
496 |
} |
497 |
|
498 |
/**
|
499 |
* get address from user interface
|
500 |
*
|
501 |
* @param model
|
502 |
* @return
|
503 |
*/
|
504 |
public Address getSimpleAddress() {
|
505 |
|
506 |
jTableAddressCross.validate(); |
507 |
jTableAddressBetween.validate(); |
508 |
jTableAddressCross.setRowSelectionInterval(0, 0); |
509 |
jTableAddressBetween.setRowSelectionInterval(0, 0); |
510 |
int n = jTabbedComposed.getSelectedIndex();
|
511 |
DefaultTableModel model = null; |
512 |
if (n == 0) { |
513 |
jTableAddressCross.setRowSelectionInterval(0, 0); |
514 |
model = (DefaultTableModel) jTableAddressCross.getModel();
|
515 |
} |
516 |
if (n == 1) { |
517 |
jTableAddressBetween.setRowSelectionInterval(0, 0); |
518 |
model = (DefaultTableModel) jTableAddressBetween.getModel();
|
519 |
} |
520 |
|
521 |
ComposeAddress address = new ComposeAddress();
|
522 |
Literal mainLiteral = new Literal();
|
523 |
Literal literal2 = new Literal();
|
524 |
Literal literal3 = new Literal();
|
525 |
List<Literal> intersectionLiterals = new ArrayList<Literal>(); |
526 |
Vector vec = model.getDataVector();
|
527 |
// get main and secon address
|
528 |
for (int i = 0; i < vec.size(); i++) { |
529 |
Vector vecc = (Vector) vec.elementAt(i); |
530 |
String key = (String) vecc.elementAt(0); |
531 |
String value = (String) vecc.elementAt(1); |
532 |
String value2 = (String) vecc.elementAt(2); |
533 |
mainLiteral.add(new AddressComponent(key, value));
|
534 |
literal2.add(new AddressComponent(key, value2));
|
535 |
} |
536 |
address.setMainLiteral(mainLiteral); |
537 |
intersectionLiterals.add(literal2); |
538 |
// get third address if exist
|
539 |
int num = ((Vector) vec.elementAt(0)).size(); |
540 |
if (num == 4) { |
541 |
for (int i = 0; i < vec.size(); i++) { |
542 |
Vector vecc = (Vector) vec.elementAt(i); |
543 |
String key = (String) vecc.elementAt(0); |
544 |
String value3 = (String) vecc.elementAt(3); |
545 |
literal3.add(new AddressComponent(key, value3));
|
546 |
} |
547 |
intersectionLiterals.add(literal3); |
548 |
} |
549 |
|
550 |
address.setIntersectionLiteral(intersectionLiterals); |
551 |
|
552 |
return address;
|
553 |
} |
554 |
|
555 |
/**
|
556 |
* Get the addres from table
|
557 |
*
|
558 |
* @param model
|
559 |
* @param row
|
560 |
* @return
|
561 |
*/
|
562 |
public Address getTableAddress(DefaultTableModel model, int row) { |
563 |
|
564 |
jTableAddressCross.validate(); |
565 |
jTableAddressCross.setRowSelectionInterval(0, 0); |
566 |
jTableAddressBetween.validate(); |
567 |
jTableAddressBetween.setRowSelectionInterval(0, 0); |
568 |
|
569 |
// save in the gmodel the descriptor of identifier field
|
570 |
int n = jTabbedComposed.getSelectedIndex();
|
571 |
if (n == 0) { |
572 |
ComboDesc desc = (ComboDesc) jComboIdCross.getModel() |
573 |
.getSelectedItem(); |
574 |
control.getGmodel().setIdMasiveTable(desc.getDescriptor()); |
575 |
} else {
|
576 |
ComboDesc desc = (ComboDesc) jComboIdBetween.getModel() |
577 |
.getSelectedItem(); |
578 |
control.getGmodel().setIdMasiveTable(desc.getDescriptor()); |
579 |
} |
580 |
|
581 |
// Get store from Gmodel and the feature
|
582 |
FeatureStore store = control.getGmodel().getSelectedTableStore(); |
583 |
FeatureSet features = null;
|
584 |
Feature feature = null;
|
585 |
try {
|
586 |
features = store.getFeatureSet(); |
587 |
Iterator<Feature> it = features.iterator(row);
|
588 |
feature = it.next(); |
589 |
} catch (DataException e) {
|
590 |
log.error("Get the feature of FeatureStore", e);
|
591 |
} |
592 |
|
593 |
// Create the address
|
594 |
ComposeAddress address = new ComposeAddress();
|
595 |
Literal mainLiteral = new Literal();
|
596 |
Literal literal2 = new Literal();
|
597 |
Literal literal3 = new Literal();
|
598 |
List<Literal> intersectionLiterals = new ArrayList<Literal>(); |
599 |
Vector vec = model.getDataVector();
|
600 |
|
601 |
for (int i = 0; i < vec.size(); i++) { |
602 |
Vector vecc = (Vector) vec.elementAt(i); |
603 |
String key = (String) vecc.elementAt(0); |
604 |
ComboDesc cdesc1 = (ComboDesc) vecc.elementAt(1);
|
605 |
ComboDesc cdesc2 = (ComboDesc) vecc.elementAt(2);
|
606 |
FeatureAttributeDescriptor desc1 = cdesc1.getDescriptor(); |
607 |
FeatureAttributeDescriptor desc2 = cdesc2.getDescriptor(); |
608 |
String fieldName1 = desc1.getName();
|
609 |
String fieldName2 = desc2.getName();
|
610 |
Object obj1 = feature.get(fieldName1);
|
611 |
Object obj2 = feature.get(fieldName2);
|
612 |
String value1 = obj1.toString();
|
613 |
String value2 = obj2.toString();
|
614 |
mainLiteral.add(new AddressComponent(key, value1));
|
615 |
literal2.add(new AddressComponent(key, value2));
|
616 |
} |
617 |
|
618 |
address.setMainLiteral(mainLiteral); |
619 |
intersectionLiterals.add(literal2); |
620 |
|
621 |
// get third address if exist
|
622 |
int num = ((Vector) vec.elementAt(0)).size(); |
623 |
if (num == 4) { |
624 |
for (int i = 0; i < vec.size(); i++) { |
625 |
Vector vecc = (Vector) vec.elementAt(i); |
626 |
String key = (String) vecc.elementAt(0); |
627 |
ComboDesc cdesc3 = (ComboDesc) vecc.elementAt(3);
|
628 |
FeatureAttributeDescriptor desc3 = cdesc3.getDescriptor(); |
629 |
String fieldName3 = desc3.getName();
|
630 |
Object obj3 = feature.get(fieldName3);
|
631 |
String value3 = obj3.toString();
|
632 |
literal3.add(new AddressComponent(key, value3));
|
633 |
} |
634 |
intersectionLiterals.add(literal3); |
635 |
} |
636 |
address.setIntersectionLiteral(intersectionLiterals); |
637 |
|
638 |
return address;
|
639 |
} |
640 |
|
641 |
} |