Revision 10626 trunk/extensions/extDataLocator/src/com/iver/gvsig/datalocator/gui/DataSelectionPanel.java

View differences:

DataSelectionPanel.java
45 45

  
46 46
import java.awt.FlowLayout;
47 47
import java.awt.event.ItemListener;
48
import java.io.IOException;
49 48
import java.util.Comparator;
50 49
import java.util.TreeSet;
51 50
import java.util.Vector;
......
61 60
import org.gvsig.gui.beans.swing.JButton;
62 61

  
63 62
import com.hardcode.driverManager.DriverLoadException;
63
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
64 64
import com.hardcode.gdbms.engine.data.DataSource;
65 65
import com.hardcode.gdbms.engine.data.DataSourceFactory;
66 66
import com.hardcode.gdbms.engine.instruction.EvaluationException;
......
74 74
import com.iver.andami.ui.mdiManager.IWindowListener;
75 75
import com.iver.andami.ui.mdiManager.SingletonWindow;
76 76
import com.iver.andami.ui.mdiManager.WindowInfo;
77
import com.iver.cit.gvsig.fmap.DriverException;
77
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
78 78
import com.iver.cit.gvsig.fmap.MapContext;
79 79
import com.iver.cit.gvsig.fmap.layers.CancelationException;
80 80
import com.iver.cit.gvsig.fmap.layers.FBitSet;
......
89 89
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
90 90
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
91 91
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor;
92
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
93 92
import com.iver.gvsig.datalocator.DataLocatorExtension;
94 93

  
95 94
/**
96 95
 * @author jmorell
97 96
 */
98 97
public class DataSelectionPanel extends JPanel implements IWindow, IWindowListener, SingletonWindow {
99
    
98

  
100 99
	/**
101
     * 
100
     *
102 101
     */
103 102
    private static final long serialVersionUID = 1L;
104 103
    private JComboBox jComboBox = null;
......
115 114
	private Value itemToZoom = null;
116 115
	private MapContext mapContext = null;
117 116
	private Preferences prefUsuario = null;
118
	private Vector layersListenerList = new Vector();	
117
	private Vector layersListenerList = new Vector();
119 118
    private Vector vectorialLayers = null;
120 119
	private JCheckBox jChkBoxOpenFirstTime = null;
121 120
	private JPanel jPanelButtons = null;
122
	
121

  
123 122
	/**
124
	 * This method initializes 
125
	 * 
123
	 * This method initializes
124
	 *
126 125
	 */
127
	public DataSelectionPanel(MapContext mapContext) {		
126
	public DataSelectionPanel(MapContext mapContext) {
128 127
		super();
129 128
		this.mapContext = mapContext;
130 129
		prefUsuario = Preferences.userRoot();
......
132 131
        initializeLayerToZoom();
133 132
		initializeFieldToZoomIndex();
134 133
        initialize();
135
        
134

  
136 135
        int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1);
137 136
        if (userOpen == 1)
138 137
        	getJChkBoxOpenFirstTime().setSelected(true);
......
141 140
    	unregisterLayersListener();
142 141
        vectorialLayers = new Vector();
143 142
        LayersIterator iter = DataLocatorExtension.newValidLayersIterator(mapContext.getLayers());
144
        
145 143

  
144

  
146 145
        while (iter.hasNext()) {
147 146
        	vectorialLayers.add(iter.nextLayer());
148 147
        }
149
        
148

  
150 149
        registerLayersListener();
151 150
    }
152
	private void initializeLayerToZoom() {		
151
	private void initializeLayerToZoom() {
153 152
		String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", "");
154 153
        if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0);
155 154
        boolean layerFound = false;
......
162 161
        }
163 162
        if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0);
164 163
        prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
165
        
164

  
166 165
	}
167 166
	private void initializeFieldToZoomIndex() {
168 167
        fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0);
......
175 174
            } else if (ds.getFieldCount() == 0) {
176 175
            	fieldToZoomIndex = -1;
177 176
            }
178
        } catch (DriverException e) {
177
        } catch (ReadDriverException e) {
179 178
        	fieldToZoomIndex = -1;
180 179
            e.printStackTrace();
181
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
182
        	fieldToZoomIndex = -1;
183
            e.printStackTrace();
184
        }
180
		}
185 181
	}
186 182
	/**
187 183
	 * This method initializes this
188
	 * 
184
	 *
189 185
	 * @return void
190 186
	 */
191 187
	private void initialize() {
......
206 202
        this.add(getJComboBox1(), null);
207 203
        this.add(jLabel2, null);
208 204
        this.add(getJComboBox2(), null);
209
        
205

  
210 206
        jPanelButtons = new JPanel();
211 207
        FlowLayout flowLayor = new FlowLayout(FlowLayout.RIGHT);
212
        flowLayor.setHgap(5);        
213
        
208
        flowLayor.setHgap(5);
209

  
214 210
        jPanelButtons.setLayout(flowLayor);
215 211
        jPanelButtons.setBounds(15,121,335,35);
216 212
        jPanelButtons.add(getJButton(), null);
217
        jPanelButtons.add(getJButton1(), null);       
218
        
213
        jPanelButtons.add(getJButton1(), null);
214

  
219 215
        this.add(jPanelButtons);
220
        
216

  
221 217
        this.add(getJChkBoxOpenFirstTime(), null);
222 218

  
223
        
219

  
224 220
	}
225 221
	private void registerLayersListener() {
226
		int i,j;		
222
		int i,j;
227 223
		FLayer layer;
228 224
		LayersListener listener;
229 225
		boolean found;
230 226
		for (i=0;i< vectorialLayers.size();i++) {
231 227
			found = false;
232 228
			layer = ((FLayer)vectorialLayers.get(i));
233
			for (j=0;j < layersListenerList.size(); j++) {				
229
			for (j=0;j < layersListenerList.size(); j++) {
234 230
				listener = (LayersListener)layersListenerList.get(j);
235 231
				if ( layer.getParentLayer() == listener.getLayerCollection()) {
236 232
					found = true;
......
240 236
			if (!found) {
241 237
				listener = new LayersListener(layer.getParentLayer());
242 238
				layer.getParentLayer().addLayerCollectionListener(listener);
243
				layersListenerList.add(listener);				
239
				layersListenerList.add(listener);
244 240
			}
245
				
241

  
246 242
		}
247 243
	}
248
	
249
	
244

  
245

  
250 246
	private void unregisterLayersListener() {
251 247
		int i;
252 248
		LayersListener listener;
......
255 251
			listener.getLayerCollection().removeLayerCollectionListener(listener);
256 252
		}
257 253
	}
258
	
254

  
259 255
	private String[] getLayerNames() {
260 256
		String[] layerNames = new String[vectorialLayers.size()];
261 257
	    for (int i=0;i<vectorialLayers.size();i++) {
......
273 269
			for (int i = 0; i < ds.getFieldCount(); i++) {
274 270
				fieldNames[i] = ds.getFieldName(i);
275 271
			}
276
        } catch (DriverException e) {
277
            // TODO Auto-generated catch block
278
            e.printStackTrace();
279
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
280
            // TODO Auto-generated catch block
281
            e.printStackTrace();
282
        }
272
        } catch (ReadDriverException e) {
273
			// TODO Auto-generated catch block
274
			e.printStackTrace();
275
		}
283 276
		return fieldNames;
284 277
	}
285 278
	private Value[] getNewValues() {
286 279
		AlphanumericData lyr = (AlphanumericData)layerToZoom;
287 280
		DataSource ds;
288 281
		Value[] newValues = null;
289
		if (fieldToZoomIndex < 0) 
282
		if (fieldToZoomIndex < 0)
290 283
			return null;
291 284
		try {
292 285
            ds = lyr.getRecordset();
293 286
            String sql = "select " + ds.getFieldName(fieldToZoomIndex) + " from " + ds.getName() + " where " + ds.getFieldName(fieldToZoomIndex) + " is not null;";
294
            ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);           
295
			
287
            ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
288

  
296 289
			//Quitar los nombres repetidos y ordenarlos
297 290
			TreeSet treeSet = new TreeSet(new Comparator() {
298 291
                public int compare(Object o1, Object o2) {
......
316 309
			    treeSet.add(value);
317 310
			}
318 311
			newValues = (Value[])treeSet.toArray(new Value[0]);
319
        } catch (DriverException ee) {
320
            // TODO Auto-generated catch block
321
            ee.printStackTrace();
322
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
323
            // TODO Auto-generated catch block
324
            eee.printStackTrace();
325 312
        } catch (ParseException e) {
326 313
            // TODO Auto-generated catch block
327 314
            e.printStackTrace();
......
331 318
        } catch (SemanticException e) {
332 319
            // TODO Auto-generated catch block
333 320
            e.printStackTrace();
334
        } catch (IOException e) {
335
            // TODO Auto-generated catch block
336
            e.printStackTrace();
337 321
        } catch (EvaluationException e) {
338 322
            // TODO Auto-generated catch block
339 323
            e.printStackTrace();
340
        }
324
        } catch (ReadDriverException e) {
325
			// TODO Auto-generated catch block
326
			e.printStackTrace();
327
		}
341 328
        return newValues;
342 329
	}
343 330
	private class LayersListener implements LayerCollectionListener {
......
345 332
	    public LayersListener(FLayers layers){
346 333
	    	theLayerCollection = layers;
347 334
	    }
348
	    
335

  
349 336
	    public LayerCollection getLayerCollection() {
350 337
	    	return theLayerCollection;
351 338
	    }
352 339
        /* (non-Javadoc)
353 340
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
354 341
         */
355
        public void layerAdded(LayerCollectionEvent e) {        	
342
        public void layerAdded(LayerCollectionEvent e) {
356 343
            initializeVectorialLayers();
357 344
            ((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
358 345
            jComboBox.removeAllItems();
......
391 378
	    			}else {
392 379
	    				itemToZoom = null;
393 380
	    			}
394
	    			
381

  
395 382
			    }
396 383
			    jComboBox.setSelectedItem(layerToZoom.getName());
397 384
		    }else {
......
406 393
         */
407 394
        public void layerMoved(LayerPositionEvent e) {
408 395
            // TODO Auto-generated method stub
409
            
396

  
410 397
        }
411 398
        /* (non-Javadoc)
412 399
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
413 400
         */
414 401
        public void layerAdding(LayerCollectionEvent e) throws CancelationException {
415 402
            // TODO Auto-generated method stub
416
            
403

  
417 404
        }
418 405
        /* (non-Javadoc)
419 406
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
420 407
         */
421 408
        public void layerMoving(LayerPositionEvent e) throws CancelationException {
422 409
            // TODO Auto-generated method stub
423
            
410

  
424 411
        }
425 412
        /* (non-Javadoc)
426 413
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
427 414
         */
428 415
        public void layerRemoving(LayerCollectionEvent e) throws CancelationException {
429 416
            // TODO Auto-generated method stub
430
            
417

  
431 418
        }
432 419
        /* (non-Javadoc)
433 420
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
434 421
         */
435 422
        public void activationChanged(LayerCollectionEvent e) throws CancelationException {
436 423
            // TODO Auto-generated method stub
437
            
424

  
438 425
        }
439 426
        /* (non-Javadoc)
440 427
         * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
441 428
         */
442 429
        public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {
443 430
            // TODO Auto-generated method stub
444
            
431

  
445 432
        }
446 433
	}
447 434
    /* (non-Javadoc)
......
457 444
        return viewInfo;
458 445
    }
459 446
	/**
460
	 * This method initializes jComboBox	
461
	 * 	
462
	 * @return javax.swing.JComboBox	
463
	 */    
447
	 * This method initializes jComboBox
448
	 *
449
	 * @return javax.swing.JComboBox
450
	 */
464 451
	private JComboBox getJComboBox() {
465 452
		if (jComboBox == null) {
466 453
			jComboBox = new JComboBox();
......
490 477
				prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem());
491 478
    		    DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames());
492 479
    		    jComboBox1.setModel(defaultModel);
493
    		    Value[] values =getNewValues();    		    	
480
    		    Value[] values =getNewValues();
494 481
    		    defaultModel = new DefaultComboBoxModel(values);
495 482
    			jComboBox2.setModel(defaultModel);
496 483
    			if ( values != null) {
......
509 496
        }
510 497
	}
511 498
	/**
512
	 * This method initializes jComboBox1	
513
	 * 	
514
	 * @return javax.swing.JComboBox	
515
	 */    
499
	 * This method initializes jComboBox1
500
	 *
501
	 * @return javax.swing.JComboBox
502
	 */
516 503
	private JComboBox getJComboBox1() {
517 504
		if (jComboBox1 == null) {
518 505
			jComboBox1 = new JComboBox();
......
528 515
	private class ChangeFieldItemListener implements ItemListener {
529 516
	    public ChangeFieldItemListener(Vector layers) {
530 517
	    }
531
		public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {    
518
		public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {
532 519
			String fieldToZoom = ((String)jComboBox1.getSelectedItem());
533 520
			AlphanumericData lyr = (AlphanumericData)layerToZoom;
534 521
			DataSource ds;
......
578 565
                } else {
579 566
                    itemToZoom = null;
580 567
                }
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 568
            } catch (ParseException e) {
588 569
                // TODO Auto-generated catch block
589 570
                e.printStackTrace();
......
593 574
            } catch (SemanticException e) {
594 575
                // TODO Auto-generated catch block
595 576
                e.printStackTrace();
596
            } catch (IOException e) {
577
            }catch (EvaluationException e) {
597 578
                // TODO Auto-generated catch block
598 579
                e.printStackTrace();
599
            } catch (EvaluationException e) {
600
                // TODO Auto-generated catch block
601
                e.printStackTrace();
602
            }
580
            } catch (ReadDriverException e) {
581
				// TODO Auto-generated catch block
582
				e.printStackTrace();
583
			}
603 584
		}
604 585
	}
605 586
	/**
606
	 * This method initializes jComboBox2	
607
	 * 	
608
	 * @return javax.swing.JComboBox	
609
	 */    
587
	 * This method initializes jComboBox2
588
	 *
589
	 * @return javax.swing.JComboBox
590
	 */
610 591
	private JComboBox getJComboBox2() {
611 592
		if (jComboBox2 == null) {
612 593
			jComboBox2 = new JComboBox();
......
624 605
	    public ChangeItemToZoomItemListener(Vector layers) {
625 606
	        this.layers = layers;
626 607
	    }
627
		public void itemStateChanged(java.awt.event.ItemEvent e) {    
608
		public void itemStateChanged(java.awt.event.ItemEvent e) {
628 609
            for (int i=0;i<layers.size();i++) {
629 610
                if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) {
630 611
                    layerToZoom = (FLayer)layers.get(i);
......
635 616
		}
636 617
	}
637 618
	/**
638
	 * This method initializes jButton	
639
	 * 	
640
	 * @return javax.swing.JButton	
641
	 */    
619
	 * This method initializes jButton
620
	 *
621
	 * @return javax.swing.JButton
622
	 */
642 623
	private JButton getJButton() {
643 624
		if (jButton == null) {
644 625
			jButton = new JButton();
645 626
			//jButton.setBounds(8, 121, 128, 23);
646 627
			jButton.setText(PluginServices.getText(this,"Zoom"));
647
			jButton.addActionListener(new java.awt.event.ActionListener() { 
628
			jButton.addActionListener(new java.awt.event.ActionListener() {
648 629
				public void actionPerformed(java.awt.event.ActionEvent e) {
649 630
					if (layerToZoom == null || fieldToZoomIndex < 0 || itemToZoom == null)
650 631
						return;
......
670 651
				            mapContext.getViewPort().setExtent(visitor.getSelectBound());
671 652
				            selectable.clearSelection();
672 653

  
673
			            } catch (DriverException ee) {
674
			                // TODO Auto-generated catch block
675
			                ee.printStackTrace();
676
			            } catch (com.hardcode.gdbms.engine.data.driver.DriverException eee) {
677
			                // TODO Auto-generated catch block
678
			                eee.printStackTrace();
679 654
			            } catch (IncompatibleTypesException eeee) {
680 655
	                        // TODO Auto-generated catch block
681 656
	                        eeee.printStackTrace();
682
	                    } catch (VisitException e2) {
657
	                    } catch (ReadDriverException e1) {
683 658
							// TODO Auto-generated catch block
684
							e2.printStackTrace();
659
							e1.printStackTrace();
660
						} catch (VisitorException e1) {
661
							// TODO Auto-generated catch block
662
							e1.printStackTrace();
685 663
						}
686 664
                    } else if (itemToZoom == null) {
687 665
                        System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom.");
......
694 672
		return jButton;
695 673
	}
696 674
	/**
697
	 * This method initializes jButton1	
698
	 * 	
699
	 * @return javax.swing.JButton	
700
	 */    
675
	 * This method initializes jButton1
676
	 *
677
	 * @return javax.swing.JButton
678
	 */
701 679
	private JButton getJButton1() {
702 680
		if (jButton1 == null) {
703 681
			jButton1 = new JButton();
704
			//jButton1.setBounds(141, 121, 128, 23);			
682
			//jButton1.setBounds(141, 121, 128, 23);
705 683
			jButton1.setText(PluginServices.getText(this,"Salir"));
706
			jButton1.addActionListener(new java.awt.event.ActionListener() { 
707
				public void actionPerformed(java.awt.event.ActionEvent e) {    
684
			jButton1.addActionListener(new java.awt.event.ActionListener() {
685
				public void actionPerformed(java.awt.event.ActionEvent e) {
708 686
	            	if (PluginServices.getMainFrame() == null)
709 687
	            		((JDialog) (getParent().getParent().getParent().getParent())).dispose();
710 688
	            	else
......
719 697
     */
720 698
    public void windowActivated() {
721 699
        // TODO Auto-generated method stub
722
        
700

  
723 701
    }
724 702
    /* (non-Javadoc)
725 703
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
......
741 719
        return "DataSelectionPanel";
742 720
    }
743 721
	/**
744
	 * This method initializes jChkBoxOpenFirstTime	
745
	 * 	
746
	 * @return javax.swing.JCheckBox	
722
	 * This method initializes jChkBoxOpenFirstTime
723
	 *
724
	 * @return javax.swing.JCheckBox
747 725
	 */
748 726
	private JCheckBox getJChkBoxOpenFirstTime() {
749 727
		if (jChkBoxOpenFirstTime == null) {

Also available in: Unified diff