root / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 2557
History | View | Annotate | Download (25.6 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-jun-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.gvsig.datalocator.gui; |
45 |
|
46 |
import java.awt.event.ItemListener; |
47 |
import java.io.IOException; |
48 |
|
49 |
import java.util.Comparator; |
50 |
import java.util.TreeSet; |
51 |
import java.util.Vector; |
52 |
import java.util.prefs.Preferences; |
53 |
|
54 |
import javax.swing.JPanel; |
55 |
|
56 |
import com.hardcode.driverManager.DriverLoadException; |
57 |
import com.hardcode.gdbms.engine.data.DataSource; |
58 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
59 |
import com.hardcode.gdbms.engine.instruction.EvaluationException; |
60 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
61 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
62 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
63 |
import com.hardcode.gdbms.engine.values.NullValue; |
64 |
import com.hardcode.gdbms.engine.values.Value; |
65 |
import com.hardcode.gdbms.parser.ParseException; |
66 |
import com.iver.andami.PluginServices; |
67 |
import com.iver.andami.ui.mdiManager.SingletonView; |
68 |
import com.iver.andami.ui.mdiManager.View; |
69 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
70 |
import com.iver.andami.ui.mdiManager.ViewListener; |
71 |
import com.iver.cit.gvsig.fmap.DriverException; |
72 |
import com.iver.cit.gvsig.fmap.FMap; |
73 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
74 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
75 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
76 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
78 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
79 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
80 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
82 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
83 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
84 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
85 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
86 |
|
87 |
import javax.swing.DefaultComboBoxModel; |
88 |
import javax.swing.JComboBox; |
89 |
import javax.swing.JDialog; |
90 |
import javax.swing.JLabel; |
91 |
import javax.swing.JButton; |
92 |
|
93 |
/**
|
94 |
* @author jmorell
|
95 |
*/
|
96 |
public class DataSelectionPanel extends JPanel implements View, ViewListener, SingletonView { |
97 |
|
98 |
/**
|
99 |
*
|
100 |
*/
|
101 |
private static final long serialVersionUID = 1L; |
102 |
private JComboBox jComboBox = null; |
103 |
private JLabel jLabel = null; // @jve:decl-index=0:visual-constraint="597,16" |
104 |
private JLabel jLabel1 = null; // @jve:decl-index=0:visual-constraint="873,44" |
105 |
private JComboBox jComboBox1 = null; |
106 |
private JLabel jLabel2 = null; // @jve:decl-index=0:visual-constraint="847,16" |
107 |
private JComboBox jComboBox2 = null; |
108 |
private ViewInfo viewInfo = null; |
109 |
private JButton jButton = null; |
110 |
private JButton jButton1 = null; |
111 |
private FLayer layerToZoom = null; |
112 |
private int fieldToZoomIndex = 0; |
113 |
private Value itemToZoom = null; |
114 |
private FMap mapContext = null; |
115 |
private Preferences prefUsuario = null; |
116 |
private LayersListener layersListener = null; |
117 |
private Vector vectorialLayers = null; |
118 |
|
119 |
/**
|
120 |
* This method initializes
|
121 |
*
|
122 |
*/
|
123 |
public DataSelectionPanel(FMap mapContext) {
|
124 |
super();
|
125 |
this.mapContext = mapContext;
|
126 |
initializeVectorialLayers(); |
127 |
initializeLayerToZoom(); |
128 |
initializeFieldToZoomIndex(); |
129 |
initialize(); |
130 |
} |
131 |
private void initializeVectorialLayers() { |
132 |
vectorialLayers = new Vector(); |
133 |
for (int i=0;i<mapContext.getLayers().getLayersCount();i++) { |
134 |
if (mapContext.getLayers().getLayer(i) instanceof FLyrVect) vectorialLayers.add(mapContext.getLayers().getLayer(i)); |
135 |
} |
136 |
} |
137 |
private void initializeLayerToZoom() { |
138 |
prefUsuario = Preferences.userRoot();
|
139 |
String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", ""); |
140 |
if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0); |
141 |
boolean layerFound = false; |
142 |
for (int i=0;i<vectorialLayers.size();i++) { |
143 |
if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
|
144 |
layerFound = true;
|
145 |
layerToZoom = (FLayer)vectorialLayers.get(i); |
146 |
break;
|
147 |
} |
148 |
} |
149 |
if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0); |
150 |
} |
151 |
private void initializeFieldToZoomIndex() { |
152 |
fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0); |
153 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
154 |
DataSource ds;
|
155 |
try {
|
156 |
ds = lyr.getRecordset(); |
157 |
if (fieldToZoomIndex > (ds.getFieldCount()-1)) fieldToZoomIndex = 0; |
158 |
} catch (DriverException e) {
|
159 |
// TODO Auto-generated catch block
|
160 |
e.printStackTrace(); |
161 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
162 |
// TODO Auto-generated catch block
|
163 |
e.printStackTrace(); |
164 |
} |
165 |
} |
166 |
/**
|
167 |
* This method initializes this
|
168 |
*
|
169 |
* @return void
|
170 |
*/
|
171 |
private void initialize() { |
172 |
jLabel2 = new JLabel(); |
173 |
jLabel1 = new JLabel(); |
174 |
jLabel = new JLabel(); |
175 |
this.setLayout(null); |
176 |
this.setSize(286, 161); |
177 |
jLabel.setBounds(6, 6, 43, 23); |
178 |
jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
179 |
jLabel1.setBounds(6, 34, 43, 23); |
180 |
jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
181 |
jLabel2.setBounds(6, 61, 43, 23); |
182 |
jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
183 |
this.add(getJComboBox(), null); |
184 |
this.add(jLabel, null); |
185 |
this.add(jLabel1, null); |
186 |
this.add(getJComboBox1(), null); |
187 |
this.add(jLabel2, null); |
188 |
this.add(getJComboBox2(), null); |
189 |
this.add(getJButton(), null); |
190 |
this.add(getJButton1(), null); |
191 |
layersListener = new LayersListener(mapContext.getLayers());
|
192 |
mapContext.getLayers().addLayerCollectionListener(layersListener); |
193 |
} |
194 |
private String[] getLayerNames() { |
195 |
String[] layerNames = new String[vectorialLayers.size()]; |
196 |
for (int i=0;i<vectorialLayers.size();i++) { |
197 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
198 |
} |
199 |
return layerNames;
|
200 |
} |
201 |
private String[] getFieldNames() { |
202 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
203 |
DataSource ds;
|
204 |
String[] fieldNames = null; |
205 |
try {
|
206 |
ds = lyr.getRecordset(); |
207 |
fieldNames = new String[ds.getFieldCount()]; |
208 |
for (int i = 0; i < ds.getFieldCount(); i++) { |
209 |
fieldNames[i] = ds.getFieldName(i); |
210 |
} |
211 |
} catch (DriverException e) {
|
212 |
// TODO Auto-generated catch block
|
213 |
e.printStackTrace(); |
214 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
215 |
// TODO Auto-generated catch block
|
216 |
e.printStackTrace(); |
217 |
} |
218 |
return fieldNames;
|
219 |
} |
220 |
private Value[] getNewValues() { |
221 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
222 |
DataSource ds;
|
223 |
Value[] newValues = null; |
224 |
try {
|
225 |
ds = lyr.getRecordset(); |
226 |
String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
227 |
ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.CLOSING_AUTOMATIC_MODE); |
228 |
Value[] values = new Value[(int)ds.getRowCount()]; |
229 |
for (int i=0;i<ds.getRowCount();i++) { |
230 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
231 |
values[i] = value; |
232 |
} |
233 |
//Quitar los nombres repetidos y ordenarlos
|
234 |
TreeSet treeSet = new TreeSet(new Comparator() { |
235 |
public int compare(Object o1, Object o2) { |
236 |
Value v1 = (Value) o1; |
237 |
Value v2 = (Value) o2; |
238 |
try {
|
239 |
if (((BooleanValue)v1.less(v2)).getValue()){
|
240 |
return -1; |
241 |
}else if (((BooleanValue)v1.greater(v2)).getValue()){ |
242 |
return 1; |
243 |
}else{
|
244 |
return 0; |
245 |
} |
246 |
} catch (IncompatibleTypesException e) {
|
247 |
throw new RuntimeException(e); |
248 |
} |
249 |
} |
250 |
}); |
251 |
for (int i=0;i<values.length;i++) { |
252 |
treeSet.add(values[i]); |
253 |
} |
254 |
newValues = (Value[])treeSet.toArray(new Value[0]); |
255 |
} catch (DriverException ee) {
|
256 |
// TODO Auto-generated catch block
|
257 |
ee.printStackTrace(); |
258 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
259 |
// TODO Auto-generated catch block
|
260 |
eee.printStackTrace(); |
261 |
} catch (ParseException e) { |
262 |
// TODO Auto-generated catch block
|
263 |
e.printStackTrace(); |
264 |
} catch (DriverLoadException e) {
|
265 |
// TODO Auto-generated catch block
|
266 |
e.printStackTrace(); |
267 |
} catch (SemanticException e) {
|
268 |
// TODO Auto-generated catch block
|
269 |
e.printStackTrace(); |
270 |
} catch (IOException e) { |
271 |
// TODO Auto-generated catch block
|
272 |
e.printStackTrace(); |
273 |
} catch (EvaluationException e) {
|
274 |
// TODO Auto-generated catch block
|
275 |
e.printStackTrace(); |
276 |
} |
277 |
return newValues;
|
278 |
} |
279 |
private class LayersListener implements LayerCollectionListener { |
280 |
public LayersListener(FLayers layers){
|
281 |
} |
282 |
/* (non-Javadoc)
|
283 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
284 |
*/
|
285 |
public void layerAdded(LayerCollectionEvent e) { |
286 |
initializeVectorialLayers(); |
287 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
288 |
jComboBox.removeAllItems(); |
289 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
290 |
jComboBox.setModel(defaultModel); |
291 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
292 |
} |
293 |
/* (non-Javadoc)
|
294 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
295 |
*/
|
296 |
public void layerRemoved(LayerCollectionEvent e) { |
297 |
initializeVectorialLayers(); |
298 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
299 |
if (vectorialLayers.size()>0) { |
300 |
jComboBox.removeAllItems(); |
301 |
String[] layerNames = new String[vectorialLayers.size()]; |
302 |
boolean currentLayerRemoved = true; |
303 |
for (int i=0;i<vectorialLayers.size();i++) { |
304 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
305 |
if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false; |
306 |
} |
307 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames); |
308 |
jComboBox.setModel(defaultModel); |
309 |
if (currentLayerRemoved) {
|
310 |
layerToZoom = ((FLayer)vectorialLayers.get(0));
|
311 |
defaultModel = new DefaultComboBoxModel(getFieldNames()); |
312 |
jComboBox1.setModel(defaultModel); |
313 |
fieldToZoomIndex = 0;
|
314 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
315 |
defaultModel = new DefaultComboBoxModel(getNewValues()); |
316 |
jComboBox2.setModel(defaultModel); |
317 |
itemToZoom = getNewValues()[0];
|
318 |
jComboBox2.setSelectedItem(itemToZoom); |
319 |
} |
320 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
321 |
}else {
|
322 |
if (PluginServices.getMainFrame() == null) |
323 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
324 |
else
|
325 |
PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
326 |
} |
327 |
} |
328 |
/* (non-Javadoc)
|
329 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
330 |
*/
|
331 |
public void layerMoved(LayerPositionEvent e) { |
332 |
// TODO Auto-generated method stub
|
333 |
|
334 |
} |
335 |
/* (non-Javadoc)
|
336 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
337 |
*/
|
338 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
339 |
// TODO Auto-generated method stub
|
340 |
|
341 |
} |
342 |
/* (non-Javadoc)
|
343 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
344 |
*/
|
345 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
346 |
// TODO Auto-generated method stub
|
347 |
|
348 |
} |
349 |
/* (non-Javadoc)
|
350 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
351 |
*/
|
352 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
353 |
// TODO Auto-generated method stub
|
354 |
|
355 |
} |
356 |
/* (non-Javadoc)
|
357 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
358 |
*/
|
359 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
360 |
// TODO Auto-generated method stub
|
361 |
|
362 |
} |
363 |
/* (non-Javadoc)
|
364 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
365 |
*/
|
366 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
367 |
// TODO Auto-generated method stub
|
368 |
|
369 |
} |
370 |
} |
371 |
/* (non-Javadoc)
|
372 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
373 |
*/
|
374 |
public ViewInfo getViewInfo() {
|
375 |
if (viewInfo == null) { |
376 |
viewInfo=new ViewInfo(ViewInfo.MODELESSDIALOG);
|
377 |
viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo")); |
378 |
} |
379 |
return viewInfo;
|
380 |
} |
381 |
/**
|
382 |
* This method initializes jComboBox
|
383 |
*
|
384 |
* @return javax.swing.JComboBox
|
385 |
*/
|
386 |
private JComboBox getJComboBox() { |
387 |
if (jComboBox == null) { |
388 |
jComboBox = new JComboBox(); |
389 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
390 |
jComboBox.setModel(defaultModel); |
391 |
jComboBox.setBounds(54, 6, 218, 23); |
392 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
393 |
ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
|
394 |
jComboBox.addItemListener(changeLayerToZoomItemListener); |
395 |
} |
396 |
return jComboBox;
|
397 |
} |
398 |
private class ChangeLayerToZoomItemListener implements ItemListener { |
399 |
private Vector layers; |
400 |
public ChangeLayerToZoomItemListener(Vector layers) { |
401 |
this.layers = layers;
|
402 |
} |
403 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
404 |
if (jComboBox.getItemCount()>0) { |
405 |
for (int i=0;i<layers.size();i++) { |
406 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
407 |
layerToZoom = (FLayer)layers.get(i); |
408 |
break;
|
409 |
} |
410 |
} |
411 |
fieldToZoomIndex = 0;
|
412 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem()); |
413 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
414 |
jComboBox1.setModel(defaultModel); |
415 |
defaultModel = new DefaultComboBoxModel(getNewValues()); |
416 |
jComboBox2.setModel(defaultModel); |
417 |
jComboBox2.setSelectedIndex(0);
|
418 |
itemToZoom = getNewValues()[0];
|
419 |
} |
420 |
} |
421 |
/**
|
422 |
* @param layers The layers to set.
|
423 |
*/
|
424 |
public void setLayers(Vector layers) { |
425 |
this.layers = layers;
|
426 |
} |
427 |
} |
428 |
/**
|
429 |
* This method initializes jComboBox1
|
430 |
*
|
431 |
* @return javax.swing.JComboBox
|
432 |
*/
|
433 |
private JComboBox getJComboBox1() { |
434 |
if (jComboBox1 == null) { |
435 |
jComboBox1 = new JComboBox(); |
436 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
437 |
jComboBox1.setModel(defaultModel); |
438 |
jComboBox1.setBounds(54, 34, 218, 23); |
439 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
440 |
ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
|
441 |
jComboBox1.addItemListener(changeFieldItemListener); |
442 |
} |
443 |
return jComboBox1;
|
444 |
} |
445 |
private class ChangeFieldItemListener implements ItemListener { |
446 |
public ChangeFieldItemListener(Vector layers) { |
447 |
} |
448 |
public void itemStateChanged(java.awt.event.ItemEvent itemEvent) { |
449 |
String fieldToZoom = ((String)jComboBox1.getSelectedItem()); |
450 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
451 |
DataSource ds;
|
452 |
try {
|
453 |
ds = lyr.getRecordset(); |
454 |
for (int i=0;i<ds.getFieldCount();i++) { |
455 |
String fieldNamei = ds.getFieldName(i);
|
456 |
if (fieldToZoom.equals(fieldNamei)) {
|
457 |
fieldToZoomIndex = i; |
458 |
prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", i);
|
459 |
} |
460 |
} |
461 |
String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
462 |
ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.CLOSING_AUTOMATIC_MODE); |
463 |
Value[] values = new Value[(int)ds.getRowCount()]; |
464 |
for (int i=0;i<ds.getRowCount();i++) { |
465 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
466 |
values[i] = value; |
467 |
} |
468 |
//Quitar los nombres repetidos y ordenarlos
|
469 |
TreeSet treeSet = new TreeSet(new Comparator() { |
470 |
public int compare(Object o1, Object o2) { |
471 |
Value v1 = (Value) o1; |
472 |
Value v2 = (Value) o2; |
473 |
try {
|
474 |
if (((BooleanValue)v1.less(v2)).getValue()){
|
475 |
return -1; |
476 |
}else if (((BooleanValue)v1.greater(v2)).getValue()){ |
477 |
return 1; |
478 |
}else{
|
479 |
return 0; |
480 |
} |
481 |
} catch (IncompatibleTypesException e) {
|
482 |
throw new RuntimeException(e); |
483 |
} |
484 |
} |
485 |
}); |
486 |
for (int i=0;i<values.length;i++) { |
487 |
treeSet.add(values[i]); |
488 |
} |
489 |
Value[] newValues = (Value[])treeSet.toArray(new Value[0]); |
490 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues); |
491 |
jComboBox2.setModel(defaultModel); |
492 |
if (newValues.length>0) jComboBox2.setSelectedIndex(0); |
493 |
if (newValues.length>0) { |
494 |
itemToZoom = newValues[0];
|
495 |
} else {
|
496 |
itemToZoom = null;
|
497 |
} |
498 |
} catch (DriverException ee) {
|
499 |
// TODO Auto-generated catch block
|
500 |
ee.printStackTrace(); |
501 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
502 |
// TODO Auto-generated catch block
|
503 |
eee.printStackTrace(); |
504 |
} catch (ParseException e) { |
505 |
// TODO Auto-generated catch block
|
506 |
e.printStackTrace(); |
507 |
} catch (DriverLoadException e) {
|
508 |
// TODO Auto-generated catch block
|
509 |
e.printStackTrace(); |
510 |
} catch (SemanticException e) {
|
511 |
// TODO Auto-generated catch block
|
512 |
e.printStackTrace(); |
513 |
} catch (IOException e) { |
514 |
// TODO Auto-generated catch block
|
515 |
e.printStackTrace(); |
516 |
} catch (EvaluationException e) {
|
517 |
// TODO Auto-generated catch block
|
518 |
e.printStackTrace(); |
519 |
} |
520 |
} |
521 |
} |
522 |
/**
|
523 |
* This method initializes jComboBox2
|
524 |
*
|
525 |
* @return javax.swing.JComboBox
|
526 |
*/
|
527 |
private JComboBox getJComboBox2() { |
528 |
if (jComboBox2 == null) { |
529 |
jComboBox2 = new JComboBox(); |
530 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues()); |
531 |
jComboBox2.setModel(defaultModel); |
532 |
jComboBox2.setSelectedIndex(-1);
|
533 |
jComboBox2.setBounds(54, 61, 218, 23); |
534 |
ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
|
535 |
jComboBox2.addItemListener(changeItemToZoomItemListener); |
536 |
} |
537 |
return jComboBox2;
|
538 |
} |
539 |
private class ChangeItemToZoomItemListener implements ItemListener { |
540 |
private Vector layers; |
541 |
public ChangeItemToZoomItemListener(Vector layers) { |
542 |
this.layers = layers;
|
543 |
} |
544 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
545 |
for (int i=0;i<layers.size();i++) { |
546 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
547 |
layerToZoom = (FLayer)layers.get(i); |
548 |
break;
|
549 |
} |
550 |
} |
551 |
itemToZoom = ((Value)jComboBox2.getSelectedItem()); |
552 |
} |
553 |
} |
554 |
/**
|
555 |
* This method initializes jButton
|
556 |
*
|
557 |
* @return javax.swing.JButton
|
558 |
*/
|
559 |
private JButton getJButton() { |
560 |
if (jButton == null) { |
561 |
jButton = new JButton(); |
562 |
jButton.setBounds(6, 99, 128, 23); |
563 |
jButton.setText(PluginServices.getText(this,"Zoom")); |
564 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
565 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
566 |
if (jComboBox2.getSelectedIndex()!=-1) { |
567 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
568 |
DataSource ds;
|
569 |
Selectable selectable = (Selectable)layerToZoom; |
570 |
FBitSet fBitSet = selectable.getSelection(); |
571 |
Vector indices = new Vector(); |
572 |
try {
|
573 |
ds = lyr.getRecordset(); |
574 |
for (int i=0;i<ds.getRowCount();i++) { |
575 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
576 |
if (((BooleanValue)itemToZoom.equals(value)).getValue()) {
|
577 |
indices.add(new Integer(i)); |
578 |
fBitSet.set(i); |
579 |
} |
580 |
} |
581 |
} catch (DriverException ee) {
|
582 |
// TODO Auto-generated catch block
|
583 |
ee.printStackTrace(); |
584 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
585 |
// TODO Auto-generated catch block
|
586 |
eee.printStackTrace(); |
587 |
} catch (IncompatibleTypesException eeee) {
|
588 |
// TODO Auto-generated catch block
|
589 |
eeee.printStackTrace(); |
590 |
} |
591 |
selectable.setSelection(fBitSet); |
592 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
593 |
try {
|
594 |
((VectorialData)layerToZoom).process(visitor); |
595 |
} catch (DriverException e1) {
|
596 |
// TODO Auto-generated catch block
|
597 |
e1.printStackTrace(); |
598 |
} catch (VisitException e1) {
|
599 |
// TODO Auto-generated catch block
|
600 |
e1.printStackTrace(); |
601 |
} |
602 |
mapContext.getViewPort().setExtent(visitor.getSelectBound()); |
603 |
selectable.clearSelection(); |
604 |
} else if (itemToZoom == null) { |
605 |
System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom."); |
606 |
} else {
|
607 |
System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom."); |
608 |
} |
609 |
} |
610 |
}); |
611 |
} |
612 |
return jButton;
|
613 |
} |
614 |
/**
|
615 |
* This method initializes jButton1
|
616 |
*
|
617 |
* @return javax.swing.JButton
|
618 |
*/
|
619 |
private JButton getJButton1() { |
620 |
if (jButton1 == null) { |
621 |
jButton1 = new JButton(); |
622 |
jButton1.setBounds(139, 99, 128, 23); |
623 |
jButton1.setText(PluginServices.getText(this,"Salir")); |
624 |
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
625 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
626 |
if (PluginServices.getMainFrame() == null) |
627 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
628 |
else
|
629 |
PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
630 |
} |
631 |
}); |
632 |
} |
633 |
return jButton1;
|
634 |
} |
635 |
/* (non-Javadoc)
|
636 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
637 |
*/
|
638 |
public void viewActivated() { |
639 |
// TODO Auto-generated method stub
|
640 |
|
641 |
} |
642 |
/* (non-Javadoc)
|
643 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
644 |
*/
|
645 |
public void viewClosed() { |
646 |
mapContext.getLayers().removeLayerCollectionListener(layersListener); |
647 |
} |
648 |
/* (non-Javadoc)
|
649 |
* @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
650 |
*/
|
651 |
public Object getViewModel() { |
652 |
// Debe devolver una cadena. Mirar Console del CorePlugin
|
653 |
return "DataSelectionPanel"; |
654 |
} |
655 |
} // @jve:decl-index=0:visual-constraint="10,10"
|