svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extDataLocator / src / org / gvsig / datalocator / gui / DataSelectionPanel.java @ 39509
History | View | Annotate | Download (29.2 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 org.gvsig.datalocator.gui; |
45 |
|
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.event.ItemListener; |
48 |
import java.util.Comparator; |
49 |
import java.util.Date; |
50 |
import java.util.TreeSet; |
51 |
import java.util.Vector; |
52 |
import java.util.prefs.Preferences; |
53 |
|
54 |
import javax.swing.DefaultComboBoxModel; |
55 |
import javax.swing.JButton; |
56 |
import javax.swing.JCheckBox; |
57 |
import javax.swing.JComboBox; |
58 |
import javax.swing.JDialog; |
59 |
import javax.swing.JLabel; |
60 |
import javax.swing.JOptionPane; |
61 |
import javax.swing.JPanel; |
62 |
|
63 |
import org.slf4j.Logger; |
64 |
import org.slf4j.LoggerFactory; |
65 |
|
66 |
import org.gvsig.andami.PluginServices; |
67 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
68 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
69 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
70 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
71 |
import org.gvsig.app.ApplicationLocator; |
72 |
import org.gvsig.datalocator.DataLocatorExtension; |
73 |
import org.gvsig.fmap.dal.exception.DataException; |
74 |
import org.gvsig.fmap.dal.feature.Feature; |
75 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
76 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
77 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
78 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
79 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
80 |
import org.gvsig.fmap.geom.primitive.Envelope; |
81 |
import org.gvsig.fmap.mapcontext.MapContext; |
82 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
83 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
84 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
85 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
86 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
87 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
88 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
89 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
90 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
91 |
import org.gvsig.fmap.mapcontext.rendering.strategies.SelectedZoomVisitor; |
92 |
import org.gvsig.tools.dispose.DisposableIterator; |
93 |
import org.gvsig.tools.dispose.DisposeUtils; |
94 |
import org.gvsig.tools.evaluator.Evaluator; |
95 |
import org.gvsig.tools.evaluator.EvaluatorData; |
96 |
import org.gvsig.tools.evaluator.EvaluatorException; |
97 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
98 |
|
99 |
|
100 |
/**
|
101 |
* @author jmorell
|
102 |
*/
|
103 |
public class DataSelectionPanel extends JPanel implements IWindow, IWindowListener, SingletonWindow { |
104 |
|
105 |
private static final long serialVersionUID = 1L; |
106 |
|
107 |
private static final Logger logger = |
108 |
LoggerFactory.getLogger(DataSelectionPanel.class); |
109 |
|
110 |
private JComboBox layerComboBox = null; |
111 |
private JLabel jLabel = null; |
112 |
private JLabel jLabel1 = null; |
113 |
private JComboBox fieldValueComboBox = null; |
114 |
private JLabel jLabel2 = null; |
115 |
private JComboBox fieldNameComboBox = null; |
116 |
private WindowInfo viewInfo = null; |
117 |
private JButton jButton = null; |
118 |
private JButton jButton1 = null; |
119 |
private FLayer layerToZoom = null; |
120 |
private int fieldToZoomIndex = 0; |
121 |
private Object itemToZoom = null; |
122 |
private MapContext mapContext = null; |
123 |
private Preferences prefUsuario = null; |
124 |
private Vector<LayersListener> layersListenerList = new Vector<LayersListener>(); |
125 |
private Vector<FLayer> vectorialLayers = null; |
126 |
private JCheckBox jChkBoxOpenFirstTime = null; |
127 |
private JPanel jPanelButtons = null; |
128 |
|
129 |
/**
|
130 |
* This method initializes
|
131 |
*
|
132 |
*/
|
133 |
public DataSelectionPanel(MapContext mapContext) {
|
134 |
super();
|
135 |
this.mapContext = mapContext;
|
136 |
prefUsuario = Preferences.userRoot();
|
137 |
initializeVectorialLayers(); |
138 |
initializeLayerToZoom(); |
139 |
initializeFieldToZoomIndex(); |
140 |
initialize(); |
141 |
|
142 |
int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1); |
143 |
if (userOpen == 1) |
144 |
getJChkBoxOpenFirstTime().setSelected(true);
|
145 |
} |
146 |
private void initializeVectorialLayers() { |
147 |
unregisterLayersListener(); |
148 |
vectorialLayers = new Vector<FLayer>(); |
149 |
LayersIterator iter = DataLocatorExtension.newValidLayersIterator(mapContext.getLayers()); |
150 |
|
151 |
|
152 |
while (iter.hasNext()) {
|
153 |
vectorialLayers.add(iter.nextLayer()); |
154 |
} |
155 |
|
156 |
registerLayersListener(); |
157 |
} |
158 |
private void initializeLayerToZoom() { |
159 |
String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", ""); |
160 |
if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0); |
161 |
boolean layerFound = false; |
162 |
for (int i=0;i<vectorialLayers.size();i++) { |
163 |
if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
|
164 |
layerFound = true;
|
165 |
layerToZoom = (FLayer)vectorialLayers.get(i); |
166 |
break;
|
167 |
} |
168 |
} |
169 |
if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0); |
170 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
|
171 |
|
172 |
} |
173 |
private void initializeFieldToZoomIndex() { |
174 |
fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0); |
175 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
176 |
FeatureStore featureStore; |
177 |
try {
|
178 |
featureStore = lyr.getFeatureStore(); |
179 |
if (fieldToZoomIndex > (featureStore.getDefaultFeatureType().size()-1)) { |
180 |
fieldToZoomIndex = 0;
|
181 |
} else if (featureStore.getDefaultFeatureType().size() == 0) { |
182 |
fieldToZoomIndex = -1;
|
183 |
} |
184 |
} catch (DataException e) {
|
185 |
fieldToZoomIndex = -1;
|
186 |
e.printStackTrace(); |
187 |
} |
188 |
} |
189 |
/**
|
190 |
* This method initializes this
|
191 |
*
|
192 |
* @return void
|
193 |
*/
|
194 |
private void initialize() { |
195 |
jLabel2 = new JLabel(); |
196 |
jLabel1 = new JLabel(); |
197 |
jLabel = new JLabel(); |
198 |
this.setLayout(null); |
199 |
this.setSize(350, 161); |
200 |
jLabel.setBounds(6, 6, 80, 23); |
201 |
jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
202 |
jLabel1.setBounds(6, 34, 80, 23); |
203 |
jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
204 |
jLabel2.setBounds(6, 61, 80, 23); |
205 |
jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
206 |
this.add(getJComboBox(), null); |
207 |
this.add(jLabel, null); |
208 |
this.add(jLabel1, null); |
209 |
this.add(getJComboBox1(), null); |
210 |
this.add(jLabel2, null); |
211 |
this.add(getJComboBox2(), null); |
212 |
|
213 |
jPanelButtons = new JPanel(); |
214 |
FlowLayout flowLayor = new FlowLayout(FlowLayout.RIGHT); |
215 |
flowLayor.setHgap(5);
|
216 |
|
217 |
jPanelButtons.setLayout(flowLayor); |
218 |
jPanelButtons.setBounds(15,121,335,35); |
219 |
jPanelButtons.add(getJButton(), null);
|
220 |
jPanelButtons.add(getJButton1(), null);
|
221 |
|
222 |
this.add(jPanelButtons);
|
223 |
|
224 |
this.add(getJChkBoxOpenFirstTime(), null); |
225 |
|
226 |
|
227 |
} |
228 |
private void registerLayersListener() { |
229 |
int i,j;
|
230 |
FLayer layer; |
231 |
LayersListener listener; |
232 |
boolean found;
|
233 |
for (i=0;i< vectorialLayers.size();i++) { |
234 |
found = false;
|
235 |
layer = ((FLayer)vectorialLayers.get(i)); |
236 |
for (j=0;j < layersListenerList.size(); j++) { |
237 |
listener = (LayersListener)layersListenerList.get(j); |
238 |
if ( layer.getParentLayer() == listener.getLayerCollection()) {
|
239 |
found = true;
|
240 |
break;
|
241 |
} |
242 |
} |
243 |
if (!found) {
|
244 |
listener = new LayersListener(layer.getParentLayer());
|
245 |
layer.getParentLayer().addLayerCollectionListener(listener); |
246 |
layersListenerList.add(listener); |
247 |
} |
248 |
|
249 |
} |
250 |
} |
251 |
|
252 |
|
253 |
private void unregisterLayersListener() { |
254 |
int i;
|
255 |
LayersListener listener; |
256 |
for (i=0;i<layersListenerList.size();i++) { |
257 |
listener = (LayersListener)layersListenerList.get(i); |
258 |
listener.getLayerCollection().removeLayerCollectionListener(listener); |
259 |
} |
260 |
} |
261 |
|
262 |
private String[] getLayerNames() { |
263 |
String[] layerNames = new String[vectorialLayers.size()]; |
264 |
for (int i=0;i<vectorialLayers.size();i++) { |
265 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
266 |
} |
267 |
return layerNames;
|
268 |
} |
269 |
private String[] getFieldNames() { |
270 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
271 |
FeatureStore featureStore; |
272 |
String[] fieldNames = null; |
273 |
try {
|
274 |
featureStore = lyr.getFeatureStore(); |
275 |
fieldNames = new String[featureStore.getDefaultFeatureType().size()]; |
276 |
for (int i = 0; i < featureStore.getDefaultFeatureType().size(); i++) { |
277 |
fieldNames[i] = ((FeatureAttributeDescriptor)featureStore.getDefaultFeatureType().get(i)).getName(); |
278 |
} |
279 |
} catch (DataException e) {
|
280 |
e.printStackTrace(); |
281 |
} |
282 |
return fieldNames;
|
283 |
} |
284 |
|
285 |
|
286 |
private Object[] getNewValues() { |
287 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
288 |
FeatureStore featureStore; |
289 |
Object[] newValues = null; |
290 |
if (fieldToZoomIndex < 0) |
291 |
return null; |
292 |
FeatureSet set = null;
|
293 |
DisposableIterator features = null;
|
294 |
|
295 |
try {
|
296 |
featureStore = lyr.getFeatureStore(); |
297 |
|
298 |
// String sql = "select " + ((FeatureAttributeDescriptor)featureStore.getDefaultFeatureType().get(fieldToZoomIndex)).getName() + " from " + featureStore.getName() + " where " + featureStore.getFieldName(fieldToZoomIndex) + " is not null;";
|
299 |
FeatureQuery query = featureStore.createFeatureQuery(); |
300 |
String field =
|
301 |
((FeatureAttributeDescriptor) featureStore.getDefaultFeatureType() |
302 |
.get(fieldToZoomIndex)).getName(); |
303 |
Evaluator myEvaluator = new MyEvaluator(field);
|
304 |
query.setFilter(myEvaluator); |
305 |
query.setAttributeNames(new String[] { field }); |
306 |
set = featureStore.getFeatureSet(query); |
307 |
// ds = ds.getDataSourceFactory().executeSQL(sql,
|
308 |
// DataSourceFactory.AUTOMATIC_OPENING);
|
309 |
|
310 |
// Quitar los nombres repetidos y ordenarlos
|
311 |
TreeSet<Object> treeSet = |
312 |
new TreeSet<Object>(new Comparator<Object>() { |
313 |
public int compare(Object o1, Object o2) { |
314 |
if (o1 instanceof Number && o2 instanceof Number) { |
315 |
if (((Number) o1).doubleValue() < ((Number) o2).doubleValue()) |
316 |
return -1; |
317 |
if (((Number) o1).doubleValue() > ((Number) o2).doubleValue()) |
318 |
return 1; |
319 |
} else if (o1 instanceof String |
320 |
&& o2 instanceof String) { |
321 |
return ((String) o1).compareTo((String) o2); |
322 |
} else if (o1 instanceof Date && o2 instanceof Date) { |
323 |
return ((Date) o1).compareTo((Date) o2); |
324 |
} |
325 |
return 0; |
326 |
} |
327 |
}); |
328 |
features = set.iterator(); |
329 |
while (features.hasNext()) {
|
330 |
Feature feature = (Feature) features.next(); |
331 |
Object obj = feature.get(0); |
332 |
treeSet.add(obj); |
333 |
} |
334 |
newValues = (Object[]) treeSet.toArray(new Object[0]); |
335 |
} catch (DataException e) {
|
336 |
e.printStackTrace(); |
337 |
} finally {
|
338 |
if (features != null) { |
339 |
features.dispose(); |
340 |
} |
341 |
if (set != null) { |
342 |
set.dispose(); |
343 |
} |
344 |
} |
345 |
return newValues;
|
346 |
} |
347 |
private class LayersListener implements LayerCollectionListener { |
348 |
private LayerCollection theLayerCollection;
|
349 |
public LayersListener(FLayers layers){
|
350 |
theLayerCollection = layers; |
351 |
} |
352 |
|
353 |
public LayerCollection getLayerCollection() {
|
354 |
return theLayerCollection;
|
355 |
} |
356 |
/* (non-Javadoc)
|
357 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
358 |
*/
|
359 |
public void layerAdded(LayerCollectionEvent e) { |
360 |
initializeVectorialLayers(); |
361 |
((ChangeLayerToZoomItemListener)layerComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
362 |
layerComboBox.removeAllItems(); |
363 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
364 |
layerComboBox.setModel(defaultModel); |
365 |
layerComboBox.setSelectedItem(layerToZoom.getName()); |
366 |
} |
367 |
/* (non-Javadoc)
|
368 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
369 |
*/
|
370 |
public void layerRemoved(LayerCollectionEvent e) { |
371 |
initializeVectorialLayers(); |
372 |
((ChangeLayerToZoomItemListener)layerComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
373 |
if (vectorialLayers.size()>0) { |
374 |
layerComboBox.removeAllItems(); |
375 |
String[] layerNames = new String[vectorialLayers.size()]; |
376 |
boolean currentLayerRemoved = true; |
377 |
for (int i=0;i<vectorialLayers.size();i++) { |
378 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
379 |
if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false; |
380 |
} |
381 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames); |
382 |
layerComboBox.setModel(defaultModel); |
383 |
if (currentLayerRemoved) {
|
384 |
layerToZoom = ((FLayer)vectorialLayers.get(0));
|
385 |
defaultModel = new DefaultComboBoxModel(getFieldNames()); |
386 |
fieldValueComboBox.setModel(defaultModel); |
387 |
fieldToZoomIndex = 0;
|
388 |
fieldValueComboBox.setSelectedIndex(fieldToZoomIndex); |
389 |
Object[] values =getNewValues(); |
390 |
defaultModel = new DefaultComboBoxModel(values); |
391 |
fieldNameComboBox.setModel(defaultModel); |
392 |
if (values != null) { |
393 |
itemToZoom = getNewValues()[0];
|
394 |
fieldNameComboBox.setSelectedItem(itemToZoom); |
395 |
}else {
|
396 |
itemToZoom = null;
|
397 |
} |
398 |
|
399 |
} |
400 |
layerComboBox.setSelectedItem(layerToZoom.getName()); |
401 |
}else {
|
402 |
if (PluginServices.getMainFrame() == null) |
403 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
404 |
else
|
405 |
PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this); |
406 |
} |
407 |
} |
408 |
/* (non-Javadoc)
|
409 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
410 |
*/
|
411 |
public void layerMoved(LayerPositionEvent e) { |
412 |
// TODO Auto-generated method stub
|
413 |
|
414 |
} |
415 |
/* (non-Javadoc)
|
416 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
417 |
*/
|
418 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
419 |
// TODO Auto-generated method stub
|
420 |
|
421 |
} |
422 |
/* (non-Javadoc)
|
423 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
424 |
*/
|
425 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
426 |
// TODO Auto-generated method stub
|
427 |
|
428 |
} |
429 |
/* (non-Javadoc)
|
430 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
431 |
*/
|
432 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
433 |
// TODO Auto-generated method stub
|
434 |
|
435 |
} |
436 |
/* (non-Javadoc)
|
437 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
438 |
*/
|
439 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
440 |
// TODO Auto-generated method stub
|
441 |
|
442 |
} |
443 |
/* (non-Javadoc)
|
444 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
445 |
*/
|
446 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
447 |
// TODO Auto-generated method stub
|
448 |
|
449 |
} |
450 |
} |
451 |
/* (non-Javadoc)
|
452 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
453 |
*/
|
454 |
public WindowInfo getWindowInfo() {
|
455 |
if (viewInfo == null) { |
456 |
viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
|
457 |
viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo")); |
458 |
viewInfo.setHeight(getPreferredSize().height); |
459 |
viewInfo.setWidth(getPreferredSize().width); |
460 |
} |
461 |
return viewInfo;
|
462 |
} |
463 |
/**
|
464 |
* This method initializes jComboBox
|
465 |
*
|
466 |
* @return javax.swing.JComboBox
|
467 |
*/
|
468 |
private JComboBox getJComboBox() { |
469 |
if (layerComboBox == null) { |
470 |
layerComboBox = new JComboBox(); |
471 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
472 |
layerComboBox.setModel(defaultModel); |
473 |
layerComboBox.setBounds(90, 6, 250, 23); |
474 |
layerComboBox.setSelectedItem(layerToZoom.getName()); |
475 |
ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
|
476 |
layerComboBox.addItemListener(changeLayerToZoomItemListener); |
477 |
} |
478 |
return layerComboBox;
|
479 |
} |
480 |
private class ChangeLayerToZoomItemListener implements ItemListener { |
481 |
private Vector<FLayer> layers; |
482 |
public ChangeLayerToZoomItemListener(Vector<FLayer> layers) { |
483 |
this.layers = layers;
|
484 |
} |
485 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
486 |
if (layerComboBox.getItemCount()>0) { |
487 |
for (int i=0;i<layers.size();i++) { |
488 |
if (((FLayer)layers.get(i)).getName().equals((String)layerComboBox.getSelectedItem())) { |
489 |
layerToZoom = (FLayer)layers.get(i); |
490 |
break;
|
491 |
} |
492 |
} |
493 |
fieldToZoomIndex = 0;
|
494 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)layerComboBox.getSelectedItem()); |
495 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
496 |
fieldValueComboBox.setModel(defaultModel); |
497 |
Object[] values =getNewValues(); |
498 |
defaultModel = new DefaultComboBoxModel(values); |
499 |
fieldNameComboBox.setModel(defaultModel); |
500 |
if ( values != null) { |
501 |
fieldNameComboBox.setSelectedIndex(0);
|
502 |
itemToZoom = values[0];
|
503 |
} else {
|
504 |
itemToZoom = null;
|
505 |
} |
506 |
} |
507 |
} |
508 |
/**
|
509 |
* @param layers The layers to set.
|
510 |
*/
|
511 |
public void setLayers(Vector<FLayer> layers) { |
512 |
this.layers = layers;
|
513 |
} |
514 |
} |
515 |
/**
|
516 |
* This method initializes jComboBox1
|
517 |
*
|
518 |
* @return javax.swing.JComboBox
|
519 |
*/
|
520 |
private JComboBox getJComboBox1() { |
521 |
if (fieldValueComboBox == null) { |
522 |
fieldValueComboBox = new JComboBox(); |
523 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
524 |
fieldValueComboBox.setModel(defaultModel); |
525 |
fieldValueComboBox.setBounds(90, 34, 250, 23); |
526 |
fieldValueComboBox.setSelectedIndex(fieldToZoomIndex); |
527 |
ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
|
528 |
fieldValueComboBox.addItemListener(changeFieldItemListener); |
529 |
} |
530 |
return fieldValueComboBox;
|
531 |
} |
532 |
private class ChangeFieldItemListener implements ItemListener { |
533 |
public ChangeFieldItemListener(Vector<FLayer> layers) { |
534 |
} |
535 |
public void itemStateChanged(java.awt.event.ItemEvent itemEvent) { |
536 |
String fieldToZoom = ((String)fieldValueComboBox.getSelectedItem()); |
537 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
538 |
FeatureStore featureStore; |
539 |
FeatureSet set = null;
|
540 |
DisposableIterator features = null;
|
541 |
try {
|
542 |
featureStore = lyr.getFeatureStore(); |
543 |
prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", fieldToZoomIndex);
|
544 |
|
545 |
//Quitar los nombres repetidos y ordenarlos
|
546 |
TreeSet<Object> treeSet = new TreeSet<Object>(new Comparator<Object>() { |
547 |
public int compare(Object o1, Object o2) { |
548 |
if (o1 instanceof Number && o2 instanceof Number){ |
549 |
if (((Number)o1).doubleValue()<((Number)o2).doubleValue()) |
550 |
return -1; |
551 |
if (((Number)o1).doubleValue()>((Number)o2).doubleValue()) |
552 |
return 1; |
553 |
}else if (o1 instanceof String && o2 instanceof String){ |
554 |
return ((String)o1).compareTo((String)o2); |
555 |
}else if (o1 instanceof Date && o2 instanceof Date){ |
556 |
return ((Date)o1).compareTo((Date)o2); |
557 |
} |
558 |
return 0; |
559 |
} |
560 |
}); |
561 |
|
562 |
Evaluator myEvaluator = new MyEvaluator(fieldToZoom);
|
563 |
FeatureQuery query = featureStore.createFeatureQuery(); |
564 |
query.setFilter(myEvaluator); |
565 |
set = featureStore.getFeatureSet(query); |
566 |
features = set.fastIterator(); |
567 |
int index = set.getDefaultFeatureType().getAttributeDescriptor(fieldToZoom).getIndex();
|
568 |
while (features.hasNext()) {
|
569 |
Feature feature = (Feature) features.next(); |
570 |
treeSet.add(feature.get(index)); |
571 |
} |
572 |
Object[] newValues = (Object[])treeSet.toArray(new Object[0]); |
573 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues); |
574 |
fieldNameComboBox.setModel(defaultModel); |
575 |
if (newValues.length>0) fieldNameComboBox.setSelectedIndex(0); |
576 |
if (newValues.length>0) { |
577 |
itemToZoom = newValues[0];
|
578 |
} else {
|
579 |
itemToZoom = null;
|
580 |
} |
581 |
} catch (DataException e) {
|
582 |
e.printStackTrace(); |
583 |
} finally {
|
584 |
if (features != null) { |
585 |
features.dispose(); |
586 |
} |
587 |
if (set != null) { |
588 |
set.dispose(); |
589 |
} |
590 |
} |
591 |
} |
592 |
} |
593 |
/**
|
594 |
* This method initializes jComboBox2
|
595 |
*
|
596 |
* @return javax.swing.JComboBox
|
597 |
*/
|
598 |
private JComboBox getJComboBox2() { |
599 |
if (fieldNameComboBox == null) { |
600 |
fieldNameComboBox = new JComboBox(); |
601 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues()); |
602 |
fieldNameComboBox.setModel(defaultModel); |
603 |
fieldNameComboBox.setSelectedIndex(-1);
|
604 |
fieldNameComboBox.setBounds(90, 61, 250, 23); |
605 |
ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
|
606 |
fieldNameComboBox.addItemListener(changeItemToZoomItemListener); |
607 |
} |
608 |
return fieldNameComboBox;
|
609 |
} |
610 |
private class ChangeItemToZoomItemListener implements ItemListener { |
611 |
private Vector<FLayer> layers; |
612 |
public ChangeItemToZoomItemListener(Vector<FLayer> layers) { |
613 |
this.layers = layers;
|
614 |
} |
615 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
616 |
for (int i=0;i<layers.size();i++) { |
617 |
if (((FLayer)layers.get(i)).getName().equals((String)layerComboBox.getSelectedItem())) { |
618 |
layerToZoom = (FLayer)layers.get(i); |
619 |
break;
|
620 |
} |
621 |
} |
622 |
itemToZoom = ((Object)fieldNameComboBox.getSelectedItem());
|
623 |
} |
624 |
} |
625 |
/**
|
626 |
* This method initializes jButton
|
627 |
*
|
628 |
* @return javax.swing.JButton
|
629 |
*/
|
630 |
private JButton getJButton() { |
631 |
if (jButton == null) { |
632 |
jButton = new JButton(); |
633 |
//jButton.setBounds(8, 121, 128, 23);
|
634 |
jButton.setText(PluginServices.getText(this,"Zoom")); |
635 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
636 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
637 |
if (layerToZoom == null || fieldToZoomIndex < 0 || itemToZoom == null) |
638 |
return;
|
639 |
if (fieldNameComboBox.getSelectedIndex()!=-1) { |
640 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
641 |
FeatureStore featureStore; |
642 |
FeatureSet featureSet = null;
|
643 |
DisposableIterator features = null;
|
644 |
try {
|
645 |
featureStore = lyr.getFeatureStore(); |
646 |
FeatureSelection selection = (FeatureSelection)featureStore.createFeatureSelection(); |
647 |
featureSet = featureStore.getFeatureSet(); |
648 |
features = featureSet.fastIterator(); |
649 |
String fieldToZoom = ((String)fieldValueComboBox.getSelectedItem()); |
650 |
int index = featureSet.getDefaultFeatureType().getAttributeDescriptor(fieldToZoom).getIndex();
|
651 |
|
652 |
while (features.hasNext()) {
|
653 |
Feature feature = (Feature) features.next(); |
654 |
if (itemToZoom.equals(feature.get(index))){
|
655 |
selection.select(feature); |
656 |
} |
657 |
} |
658 |
// featureStore.setSelection(selection);
|
659 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
660 |
selection.accept(visitor); |
661 |
Envelope env_data = visitor.getSelectBound(); |
662 |
|
663 |
if (lyr.getCoordTrans() != null) { |
664 |
env_data = env_data.convert(lyr.getCoordTrans()); |
665 |
} |
666 |
|
667 |
mapContext.getViewPort().setEnvelope(env_data); |
668 |
|
669 |
} catch (Exception e1) { |
670 |
logger.debug("While doing zoom: " + e1.getMessage(), e1);
|
671 |
ApplicationLocator.getManager().message( |
672 |
"While doing zoom: " + e1.getMessage(),
|
673 |
JOptionPane.ERROR_MESSAGE);
|
674 |
|
675 |
} finally {
|
676 |
DisposeUtils.dispose(featureSet); |
677 |
DisposeUtils.dispose(features); |
678 |
} |
679 |
} else if (itemToZoom == null) { |
680 |
logger.debug("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom.");
|
681 |
} else {
|
682 |
logger.debug("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom.");
|
683 |
} |
684 |
} |
685 |
}); |
686 |
} |
687 |
return jButton;
|
688 |
} |
689 |
/**
|
690 |
* This method initializes jButton1
|
691 |
*
|
692 |
* @return javax.swing.JButton
|
693 |
*/
|
694 |
private JButton getJButton1() { |
695 |
if (jButton1 == null) { |
696 |
jButton1 = new JButton(); |
697 |
//jButton1.setBounds(141, 121, 128, 23);
|
698 |
jButton1.setText(PluginServices.getText(this,"Salir")); |
699 |
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
700 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
701 |
if (PluginServices.getMainFrame() == null) |
702 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
703 |
else
|
704 |
PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this); |
705 |
} |
706 |
}); |
707 |
} |
708 |
return jButton1;
|
709 |
} |
710 |
/* (non-Javadoc)
|
711 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
712 |
*/
|
713 |
public void windowActivated() { |
714 |
// TODO Auto-generated method stub
|
715 |
|
716 |
} |
717 |
/* (non-Javadoc)
|
718 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
719 |
*/
|
720 |
public void windowClosed() { |
721 |
unregisterLayersListener(); |
722 |
// Guardamos la posici?n en las preferencias del usuario.
|
723 |
WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(this);
|
724 |
prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
|
725 |
prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
|
726 |
prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
|
727 |
prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
|
728 |
vi.setClosed(true);
|
729 |
} |
730 |
/* (non-Javadoc)
|
731 |
* @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
732 |
*/
|
733 |
public Object getWindowModel() { |
734 |
// Debe devolver una cadena. Mirar Console del CorePlugin
|
735 |
return "DataSelectionPanel"; |
736 |
} |
737 |
/**
|
738 |
* This method initializes jChkBoxOpenFirstTime
|
739 |
*
|
740 |
* @return javax.swing.JCheckBox
|
741 |
*/
|
742 |
private JCheckBox getJChkBoxOpenFirstTime() { |
743 |
if (jChkBoxOpenFirstTime == null) { |
744 |
jChkBoxOpenFirstTime = new JCheckBox(); |
745 |
jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(90,89,179,23)); |
746 |
jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time")); |
747 |
jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
|
748 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
749 |
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
750 |
if (jChkBoxOpenFirstTime.isSelected())
|
751 |
{ |
752 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1); |
753 |
} |
754 |
else
|
755 |
{ |
756 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0); |
757 |
} |
758 |
} |
759 |
}); |
760 |
} |
761 |
return jChkBoxOpenFirstTime;
|
762 |
} |
763 |
public Object getWindowProfile() { |
764 |
return WindowInfo.TOOL_PROFILE;
|
765 |
} |
766 |
class MyEvaluator implements Evaluator{ |
767 |
private String name=null; |
768 |
private EvaluatorFieldsInfo info = null; |
769 |
|
770 |
public MyEvaluator(String name){ |
771 |
this.name=name;
|
772 |
info = new EvaluatorFieldsInfo();
|
773 |
this.info.addFieldValue(name);
|
774 |
} |
775 |
|
776 |
public Object evaluate(EvaluatorData data) |
777 |
throws EvaluatorException {
|
778 |
Feature feature = (Feature) data.getContextValue("feature");
|
779 |
if (feature.get(name)!=null) |
780 |
return new Boolean(true); |
781 |
return new Boolean(false); |
782 |
} |
783 |
|
784 |
public String getSQL() { |
785 |
return name + " is not null"; |
786 |
} |
787 |
|
788 |
public String getDescription() { |
789 |
return "Evaluates if a field is not null"; |
790 |
} |
791 |
|
792 |
public EvaluatorFieldsInfo getFieldsInfo() {
|
793 |
return this.info; |
794 |
} |
795 |
|
796 |
public String getName() { |
797 |
return this.getClass().getName(); |
798 |
} |
799 |
|
800 |
} |
801 |
} // @jve:decl-index=0:visual-constraint="10,10"
|