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