root / trunk / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 6877
History | View | Annotate | Download (27.1 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.Value; |
64 |
import com.hardcode.gdbms.parser.ParseException; |
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.andami.plugins.Extension; |
67 |
import com.iver.andami.ui.mdiManager.SingletonView; |
68 |
import com.iver.andami.ui.mdiManager.IWindow; |
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 |
import com.iver.gvsig.datalocator.DataLocatorExtension; |
87 |
|
88 |
import javax.swing.DefaultComboBoxModel; |
89 |
import javax.swing.JComboBox; |
90 |
import javax.swing.JDialog; |
91 |
import javax.swing.JLabel; |
92 |
import javax.swing.JButton; |
93 |
import javax.swing.JCheckBox; |
94 |
|
95 |
/**
|
96 |
* @author jmorell
|
97 |
*/
|
98 |
public class DataSelectionPanel extends JPanel implements IWindow, ViewListener, SingletonView { |
99 |
|
100 |
/**
|
101 |
*
|
102 |
*/
|
103 |
private static final long serialVersionUID = 1L; |
104 |
private JComboBox jComboBox = null; |
105 |
private JLabel jLabel = null; // @jve:decl-index=0:visual-constraint="597,16" |
106 |
private JLabel jLabel1 = null; // @jve:decl-index=0:visual-constraint="873,44" |
107 |
private JComboBox jComboBox1 = null; |
108 |
private JLabel jLabel2 = null; // @jve:decl-index=0:visual-constraint="847,16" |
109 |
private JComboBox jComboBox2 = null; |
110 |
private ViewInfo viewInfo = null; |
111 |
private JButton jButton = null; |
112 |
private JButton jButton1 = null; |
113 |
private FLayer layerToZoom = null; |
114 |
private int fieldToZoomIndex = 0; |
115 |
private Value itemToZoom = null; |
116 |
private FMap mapContext = null; |
117 |
private Preferences prefUsuario = null; |
118 |
private LayersListener layersListener = null; |
119 |
private Vector vectorialLayers = null; |
120 |
private JCheckBox jChkBoxOpenFirstTime = null; |
121 |
|
122 |
/**
|
123 |
* This method initializes
|
124 |
*
|
125 |
*/
|
126 |
public DataSelectionPanel(FMap mapContext) {
|
127 |
super();
|
128 |
this.mapContext = mapContext;
|
129 |
prefUsuario = Preferences.userRoot();
|
130 |
initializeVectorialLayers(); |
131 |
initializeLayerToZoom(); |
132 |
initializeFieldToZoomIndex(); |
133 |
initialize(); |
134 |
|
135 |
int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1); |
136 |
if (userOpen == 1) |
137 |
getJChkBoxOpenFirstTime().setSelected(true);
|
138 |
} |
139 |
private void initializeVectorialLayers() { |
140 |
vectorialLayers = new Vector(); |
141 |
for (int i=0;i<mapContext.getLayers().getLayersCount();i++) { |
142 |
if (mapContext.getLayers().getLayer(i) instanceof FLyrVect) vectorialLayers.add(mapContext.getLayers().getLayer(i)); |
143 |
} |
144 |
} |
145 |
private void initializeLayerToZoom() { |
146 |
String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", ""); |
147 |
if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0); |
148 |
boolean layerFound = false; |
149 |
for (int i=0;i<vectorialLayers.size();i++) { |
150 |
if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
|
151 |
layerFound = true;
|
152 |
layerToZoom = (FLayer)vectorialLayers.get(i); |
153 |
break;
|
154 |
} |
155 |
} |
156 |
if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0); |
157 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
|
158 |
|
159 |
} |
160 |
private void initializeFieldToZoomIndex() { |
161 |
fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0); |
162 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
163 |
DataSource ds;
|
164 |
try {
|
165 |
ds = lyr.getRecordset(); |
166 |
if (fieldToZoomIndex > (ds.getFieldCount()-1)) fieldToZoomIndex = 0; |
167 |
} catch (DriverException e) {
|
168 |
// TODO Auto-generated catch block
|
169 |
e.printStackTrace(); |
170 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
171 |
// TODO Auto-generated catch block
|
172 |
e.printStackTrace(); |
173 |
} |
174 |
} |
175 |
/**
|
176 |
* This method initializes this
|
177 |
*
|
178 |
* @return void
|
179 |
*/
|
180 |
private void initialize() { |
181 |
jLabel2 = new JLabel(); |
182 |
jLabel1 = new JLabel(); |
183 |
jLabel = new JLabel(); |
184 |
this.setLayout(null); |
185 |
this.setSize(286, 161); |
186 |
jLabel.setBounds(6, 6, 43, 23); |
187 |
jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
188 |
jLabel1.setBounds(6, 34, 43, 23); |
189 |
jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
190 |
jLabel2.setBounds(6, 61, 43, 23); |
191 |
jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
192 |
this.add(getJComboBox(), null); |
193 |
this.add(jLabel, null); |
194 |
this.add(jLabel1, null); |
195 |
this.add(getJComboBox1(), null); |
196 |
this.add(jLabel2, null); |
197 |
this.add(getJComboBox2(), null); |
198 |
this.add(getJButton(), null); |
199 |
this.add(getJButton1(), null); |
200 |
this.add(getJChkBoxOpenFirstTime(), null); |
201 |
layersListener = new LayersListener(mapContext.getLayers());
|
202 |
mapContext.getLayers().addLayerCollectionListener(layersListener); |
203 |
} |
204 |
private String[] getLayerNames() { |
205 |
String[] layerNames = new String[vectorialLayers.size()]; |
206 |
for (int i=0;i<vectorialLayers.size();i++) { |
207 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
208 |
} |
209 |
return layerNames;
|
210 |
} |
211 |
private String[] getFieldNames() { |
212 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
213 |
DataSource ds;
|
214 |
String[] fieldNames = null; |
215 |
try {
|
216 |
ds = lyr.getRecordset(); |
217 |
fieldNames = new String[ds.getFieldCount()]; |
218 |
for (int i = 0; i < ds.getFieldCount(); i++) { |
219 |
fieldNames[i] = ds.getFieldName(i); |
220 |
} |
221 |
} catch (DriverException e) {
|
222 |
// TODO Auto-generated catch block
|
223 |
e.printStackTrace(); |
224 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
225 |
// TODO Auto-generated catch block
|
226 |
e.printStackTrace(); |
227 |
} |
228 |
return fieldNames;
|
229 |
} |
230 |
private Value[] getNewValues() { |
231 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
232 |
DataSource ds;
|
233 |
Value[] newValues = null; |
234 |
try {
|
235 |
ds = lyr.getRecordset(); |
236 |
String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
237 |
ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING); |
238 |
Value[] values = new Value[(int)ds.getRowCount()]; |
239 |
for (int i=0;i<ds.getRowCount();i++) { |
240 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
241 |
values[i] = value; |
242 |
} |
243 |
//Quitar los nombres repetidos y ordenarlos
|
244 |
TreeSet treeSet = new TreeSet(new Comparator() { |
245 |
public int compare(Object o1, Object o2) { |
246 |
Value v1 = (Value) o1; |
247 |
Value v2 = (Value) o2; |
248 |
try {
|
249 |
if (((BooleanValue)v1.less(v2)).getValue()){
|
250 |
return -1; |
251 |
}else if (((BooleanValue)v1.greater(v2)).getValue()){ |
252 |
return 1; |
253 |
}else{
|
254 |
return 0; |
255 |
} |
256 |
} catch (IncompatibleTypesException e) {
|
257 |
throw new RuntimeException(e); |
258 |
} |
259 |
} |
260 |
}); |
261 |
for (int i=0;i<values.length;i++) { |
262 |
treeSet.add(values[i]); |
263 |
} |
264 |
newValues = (Value[])treeSet.toArray(new Value[0]); |
265 |
} catch (DriverException ee) {
|
266 |
// TODO Auto-generated catch block
|
267 |
ee.printStackTrace(); |
268 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
269 |
// TODO Auto-generated catch block
|
270 |
eee.printStackTrace(); |
271 |
} catch (ParseException e) { |
272 |
// TODO Auto-generated catch block
|
273 |
e.printStackTrace(); |
274 |
} catch (DriverLoadException e) {
|
275 |
// TODO Auto-generated catch block
|
276 |
e.printStackTrace(); |
277 |
} catch (SemanticException e) {
|
278 |
// TODO Auto-generated catch block
|
279 |
e.printStackTrace(); |
280 |
} catch (IOException e) { |
281 |
// TODO Auto-generated catch block
|
282 |
e.printStackTrace(); |
283 |
} catch (EvaluationException e) {
|
284 |
// TODO Auto-generated catch block
|
285 |
e.printStackTrace(); |
286 |
} |
287 |
return newValues;
|
288 |
} |
289 |
private class LayersListener implements LayerCollectionListener { |
290 |
public LayersListener(FLayers layers){
|
291 |
} |
292 |
/* (non-Javadoc)
|
293 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
294 |
*/
|
295 |
public void layerAdded(LayerCollectionEvent e) { |
296 |
initializeVectorialLayers(); |
297 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
298 |
jComboBox.removeAllItems(); |
299 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
300 |
jComboBox.setModel(defaultModel); |
301 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
302 |
} |
303 |
/* (non-Javadoc)
|
304 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
305 |
*/
|
306 |
public void layerRemoved(LayerCollectionEvent e) { |
307 |
initializeVectorialLayers(); |
308 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
309 |
if (vectorialLayers.size()>0) { |
310 |
jComboBox.removeAllItems(); |
311 |
String[] layerNames = new String[vectorialLayers.size()]; |
312 |
boolean currentLayerRemoved = true; |
313 |
for (int i=0;i<vectorialLayers.size();i++) { |
314 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
315 |
if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false; |
316 |
} |
317 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames); |
318 |
jComboBox.setModel(defaultModel); |
319 |
if (currentLayerRemoved) {
|
320 |
layerToZoom = ((FLayer)vectorialLayers.get(0));
|
321 |
defaultModel = new DefaultComboBoxModel(getFieldNames()); |
322 |
jComboBox1.setModel(defaultModel); |
323 |
fieldToZoomIndex = 0;
|
324 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
325 |
defaultModel = new DefaultComboBoxModel(getNewValues()); |
326 |
jComboBox2.setModel(defaultModel); |
327 |
itemToZoom = getNewValues()[0];
|
328 |
jComboBox2.setSelectedItem(itemToZoom); |
329 |
} |
330 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
331 |
}else {
|
332 |
if (PluginServices.getMainFrame() == null) |
333 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
334 |
else
|
335 |
PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
336 |
} |
337 |
} |
338 |
/* (non-Javadoc)
|
339 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
340 |
*/
|
341 |
public void layerMoved(LayerPositionEvent e) { |
342 |
// TODO Auto-generated method stub
|
343 |
|
344 |
} |
345 |
/* (non-Javadoc)
|
346 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
347 |
*/
|
348 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
349 |
// TODO Auto-generated method stub
|
350 |
|
351 |
} |
352 |
/* (non-Javadoc)
|
353 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
354 |
*/
|
355 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
356 |
// TODO Auto-generated method stub
|
357 |
|
358 |
} |
359 |
/* (non-Javadoc)
|
360 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
361 |
*/
|
362 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
363 |
// TODO Auto-generated method stub
|
364 |
|
365 |
} |
366 |
/* (non-Javadoc)
|
367 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
368 |
*/
|
369 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
370 |
// TODO Auto-generated method stub
|
371 |
|
372 |
} |
373 |
/* (non-Javadoc)
|
374 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
375 |
*/
|
376 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
377 |
// TODO Auto-generated method stub
|
378 |
|
379 |
} |
380 |
} |
381 |
/* (non-Javadoc)
|
382 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
383 |
*/
|
384 |
public ViewInfo getViewInfo() {
|
385 |
if (viewInfo == null) { |
386 |
viewInfo=new ViewInfo(ViewInfo.MODELESSDIALOG | ViewInfo.PALETTE);
|
387 |
viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo")); |
388 |
viewInfo.setHeight(getPreferredSize().height); |
389 |
viewInfo.setWidth(getPreferredSize().width); |
390 |
} |
391 |
return viewInfo;
|
392 |
} |
393 |
/**
|
394 |
* This method initializes jComboBox
|
395 |
*
|
396 |
* @return javax.swing.JComboBox
|
397 |
*/
|
398 |
private JComboBox getJComboBox() { |
399 |
if (jComboBox == null) { |
400 |
jComboBox = new JComboBox(); |
401 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
402 |
jComboBox.setModel(defaultModel); |
403 |
jComboBox.setBounds(54, 6, 218, 23); |
404 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
405 |
ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
|
406 |
jComboBox.addItemListener(changeLayerToZoomItemListener); |
407 |
} |
408 |
return jComboBox;
|
409 |
} |
410 |
private class ChangeLayerToZoomItemListener implements ItemListener { |
411 |
private Vector layers; |
412 |
public ChangeLayerToZoomItemListener(Vector layers) { |
413 |
this.layers = layers;
|
414 |
} |
415 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
416 |
if (jComboBox.getItemCount()>0) { |
417 |
for (int i=0;i<layers.size();i++) { |
418 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
419 |
layerToZoom = (FLayer)layers.get(i); |
420 |
break;
|
421 |
} |
422 |
} |
423 |
fieldToZoomIndex = 0;
|
424 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem()); |
425 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
426 |
jComboBox1.setModel(defaultModel); |
427 |
defaultModel = new DefaultComboBoxModel(getNewValues()); |
428 |
jComboBox2.setModel(defaultModel); |
429 |
jComboBox2.setSelectedIndex(0);
|
430 |
itemToZoom = getNewValues()[0];
|
431 |
} |
432 |
} |
433 |
/**
|
434 |
* @param layers The layers to set.
|
435 |
*/
|
436 |
public void setLayers(Vector layers) { |
437 |
this.layers = layers;
|
438 |
} |
439 |
} |
440 |
/**
|
441 |
* This method initializes jComboBox1
|
442 |
*
|
443 |
* @return javax.swing.JComboBox
|
444 |
*/
|
445 |
private JComboBox getJComboBox1() { |
446 |
if (jComboBox1 == null) { |
447 |
jComboBox1 = new JComboBox(); |
448 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
449 |
jComboBox1.setModel(defaultModel); |
450 |
jComboBox1.setBounds(54, 34, 218, 23); |
451 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
452 |
ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
|
453 |
jComboBox1.addItemListener(changeFieldItemListener); |
454 |
} |
455 |
return jComboBox1;
|
456 |
} |
457 |
private class ChangeFieldItemListener implements ItemListener { |
458 |
public ChangeFieldItemListener(Vector layers) { |
459 |
} |
460 |
public void itemStateChanged(java.awt.event.ItemEvent itemEvent) { |
461 |
String fieldToZoom = ((String)jComboBox1.getSelectedItem()); |
462 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
463 |
DataSource ds;
|
464 |
try {
|
465 |
ds = lyr.getRecordset(); |
466 |
for (int i=0;i<ds.getFieldCount();i++) { |
467 |
String fieldNamei = ds.getFieldName(i);
|
468 |
if (fieldToZoom.equals(fieldNamei)) {
|
469 |
fieldToZoomIndex = i; |
470 |
prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", i);
|
471 |
} |
472 |
} |
473 |
String sql = "select * from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;"; |
474 |
ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING); |
475 |
Value[] values = new Value[(int)ds.getRowCount()]; |
476 |
for (int i=0;i<ds.getRowCount();i++) { |
477 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
478 |
values[i] = value; |
479 |
} |
480 |
//Quitar los nombres repetidos y ordenarlos
|
481 |
TreeSet treeSet = new TreeSet(new Comparator() { |
482 |
public int compare(Object o1, Object o2) { |
483 |
Value v1 = (Value) o1; |
484 |
Value v2 = (Value) o2; |
485 |
try {
|
486 |
if (((BooleanValue)v1.less(v2)).getValue()){
|
487 |
return -1; |
488 |
}else if (((BooleanValue)v1.greater(v2)).getValue()){ |
489 |
return 1; |
490 |
}else{
|
491 |
return 0; |
492 |
} |
493 |
} catch (IncompatibleTypesException e) {
|
494 |
throw new RuntimeException(e); |
495 |
} |
496 |
} |
497 |
}); |
498 |
for (int i=0;i<values.length;i++) { |
499 |
treeSet.add(values[i]); |
500 |
} |
501 |
Value[] newValues = (Value[])treeSet.toArray(new Value[0]); |
502 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues); |
503 |
jComboBox2.setModel(defaultModel); |
504 |
if (newValues.length>0) jComboBox2.setSelectedIndex(0); |
505 |
if (newValues.length>0) { |
506 |
itemToZoom = newValues[0];
|
507 |
} else {
|
508 |
itemToZoom = null;
|
509 |
} |
510 |
} catch (DriverException ee) {
|
511 |
// TODO Auto-generated catch block
|
512 |
ee.printStackTrace(); |
513 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
514 |
// TODO Auto-generated catch block
|
515 |
eee.printStackTrace(); |
516 |
} catch (ParseException e) { |
517 |
// TODO Auto-generated catch block
|
518 |
e.printStackTrace(); |
519 |
} catch (DriverLoadException e) {
|
520 |
// TODO Auto-generated catch block
|
521 |
e.printStackTrace(); |
522 |
} catch (SemanticException e) {
|
523 |
// TODO Auto-generated catch block
|
524 |
e.printStackTrace(); |
525 |
} catch (IOException e) { |
526 |
// TODO Auto-generated catch block
|
527 |
e.printStackTrace(); |
528 |
} catch (EvaluationException e) {
|
529 |
// TODO Auto-generated catch block
|
530 |
e.printStackTrace(); |
531 |
} |
532 |
} |
533 |
} |
534 |
/**
|
535 |
* This method initializes jComboBox2
|
536 |
*
|
537 |
* @return javax.swing.JComboBox
|
538 |
*/
|
539 |
private JComboBox getJComboBox2() { |
540 |
if (jComboBox2 == null) { |
541 |
jComboBox2 = new JComboBox(); |
542 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues()); |
543 |
jComboBox2.setModel(defaultModel); |
544 |
jComboBox2.setSelectedIndex(-1);
|
545 |
jComboBox2.setBounds(54, 61, 218, 23); |
546 |
ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
|
547 |
jComboBox2.addItemListener(changeItemToZoomItemListener); |
548 |
} |
549 |
return jComboBox2;
|
550 |
} |
551 |
private class ChangeItemToZoomItemListener implements ItemListener { |
552 |
private Vector layers; |
553 |
public ChangeItemToZoomItemListener(Vector layers) { |
554 |
this.layers = layers;
|
555 |
} |
556 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
557 |
for (int i=0;i<layers.size();i++) { |
558 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
559 |
layerToZoom = (FLayer)layers.get(i); |
560 |
break;
|
561 |
} |
562 |
} |
563 |
itemToZoom = ((Value)jComboBox2.getSelectedItem()); |
564 |
} |
565 |
} |
566 |
/**
|
567 |
* This method initializes jButton
|
568 |
*
|
569 |
* @return javax.swing.JButton
|
570 |
*/
|
571 |
private JButton getJButton() { |
572 |
if (jButton == null) { |
573 |
jButton = new JButton(); |
574 |
jButton.setBounds(8, 121, 128, 23); |
575 |
jButton.setText(PluginServices.getText(this,"Zoom")); |
576 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
577 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
578 |
if (jComboBox2.getSelectedIndex()!=-1) { |
579 |
AlphanumericData lyr = (AlphanumericData)layerToZoom; |
580 |
DataSource ds;
|
581 |
Vector indices = new Vector(); |
582 |
try {
|
583 |
ds = lyr.getRecordset(); |
584 |
Selectable selectable = (Selectable)ds; |
585 |
FBitSet fBitSet = selectable.getSelection(); |
586 |
|
587 |
for (int i=0;i<ds.getRowCount();i++) { |
588 |
Value value = ds.getFieldValue(i, fieldToZoomIndex); |
589 |
if (((BooleanValue)itemToZoom.equals(value)).getValue()) {
|
590 |
indices.add(new Integer(i)); |
591 |
fBitSet.set(i); |
592 |
} |
593 |
} |
594 |
selectable.setSelection(fBitSet); |
595 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
596 |
((VectorialData)layerToZoom).process(visitor); |
597 |
mapContext.getViewPort().setExtent(visitor.getSelectBound()); |
598 |
selectable.clearSelection(); |
599 |
|
600 |
} catch (DriverException ee) {
|
601 |
// TODO Auto-generated catch block
|
602 |
ee.printStackTrace(); |
603 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
|
604 |
// TODO Auto-generated catch block
|
605 |
eee.printStackTrace(); |
606 |
} catch (IncompatibleTypesException eeee) {
|
607 |
// TODO Auto-generated catch block
|
608 |
eeee.printStackTrace(); |
609 |
} catch (VisitException e2) {
|
610 |
// TODO Auto-generated catch block
|
611 |
e2.printStackTrace(); |
612 |
} |
613 |
} else if (itemToZoom == null) { |
614 |
System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom."); |
615 |
} else {
|
616 |
System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom."); |
617 |
} |
618 |
} |
619 |
}); |
620 |
} |
621 |
return jButton;
|
622 |
} |
623 |
/**
|
624 |
* This method initializes jButton1
|
625 |
*
|
626 |
* @return javax.swing.JButton
|
627 |
*/
|
628 |
private JButton getJButton1() { |
629 |
if (jButton1 == null) { |
630 |
jButton1 = new JButton(); |
631 |
jButton1.setBounds(141, 121, 128, 23); |
632 |
jButton1.setText(PluginServices.getText(this,"Salir")); |
633 |
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
634 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
635 |
if (PluginServices.getMainFrame() == null) |
636 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
637 |
else
|
638 |
PluginServices.getMDIManager().closeView(DataSelectionPanel.this); |
639 |
} |
640 |
}); |
641 |
} |
642 |
return jButton1;
|
643 |
} |
644 |
/* (non-Javadoc)
|
645 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
646 |
*/
|
647 |
public void viewActivated() { |
648 |
// TODO Auto-generated method stub
|
649 |
|
650 |
} |
651 |
/* (non-Javadoc)
|
652 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
653 |
*/
|
654 |
public void viewClosed() { |
655 |
mapContext.getLayers().removeLayerCollectionListener(layersListener); |
656 |
// Guardamos la posici?n en las preferencias del usuario.
|
657 |
ViewInfo vi = PluginServices.getMDIManager().getViewInfo(this);
|
658 |
prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
|
659 |
prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
|
660 |
prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
|
661 |
prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
|
662 |
} |
663 |
/* (non-Javadoc)
|
664 |
* @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
665 |
*/
|
666 |
public Object getViewModel() { |
667 |
// Debe devolver una cadena. Mirar Console del CorePlugin
|
668 |
return "DataSelectionPanel"; |
669 |
} |
670 |
/**
|
671 |
* This method initializes jChkBoxOpenFirstTime
|
672 |
*
|
673 |
* @return javax.swing.JCheckBox
|
674 |
*/
|
675 |
private JCheckBox getJChkBoxOpenFirstTime() { |
676 |
if (jChkBoxOpenFirstTime == null) { |
677 |
jChkBoxOpenFirstTime = new JCheckBox(); |
678 |
jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(71,89,179,23)); |
679 |
jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time")); |
680 |
jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
|
681 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
682 |
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
683 |
if (jChkBoxOpenFirstTime.isSelected())
|
684 |
{ |
685 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1); |
686 |
} |
687 |
else
|
688 |
{ |
689 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0); |
690 |
} |
691 |
} |
692 |
}); |
693 |
} |
694 |
return jChkBoxOpenFirstTime;
|
695 |
} |
696 |
} // @jve:decl-index=0:visual-constraint="10,10"
|