Revision 12481 branches/v10/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropsDialog.java

View differences:

WFSPropsDialog.java
5 5
import java.awt.event.ActionListener;
6 6
import java.net.MalformedURLException;
7 7
import java.net.URL;
8
import java.util.ArrayList;
8 9
import java.util.HashMap;
9 10

  
10 11
import javax.swing.JButton;
......
17 18
import com.iver.andami.PluginServices;
18 19
import com.iver.andami.ui.mdiManager.IWindow;
19 20
import com.iver.andami.ui.mdiManager.WindowInfo;
21
import com.iver.cit.gvsig.ProjectExtension;
20 22
import com.iver.cit.gvsig.fmap.DriverException;
21 23
import com.iver.cit.gvsig.fmap.MapControl;
22 24
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
......
32 34
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
33 35
import com.iver.cit.gvsig.gui.wizards.WizardListener;
34 36
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
37
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
38
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
35 39
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
36 40
import com.iver.cit.gvsig.project.documents.view.gui.View;
37 41

  
......
79 83
 *
80 84
 * $Id$
81 85
 * $Log$
82
 * Revision 1.4.2.13  2007-06-26 09:33:07  jorpiell
86
 * Revision 1.4.2.14  2007-07-05 09:59:33  jorpiell
87
 * When a layer is modified the last project table is deleted
88
 *
89
 * Revision 1.4.2.13  2007/06/26 09:33:07  jorpiell
83 90
 * Refreshing the information tab always a change happens
84 91
 *
85 92
 * Revision 1.4.2.12  2007/01/08 10:09:12  ppiqueras
......
160 167
	private CommandListener m_actionListener = null;
161 168
	private JPanel buttonsPanel = null;
162 169
	boolean applied = false;
163
	
164 170

  
165
    public WFSPropsDialog(FLayer layer) {
171

  
172
	public WFSPropsDialog(FLayer layer) {
166 173
		super();
167 174
		initialize(layer);
168 175
	}
169 176

  
170
    private void initialize(FLayer layer) {
177
	private void initialize(FLayer layer) {
171 178
		setLayout(null);		
172
        setFLayer(layer);
173
        wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties());
174
        wfsParamsTabbedPane.addWizardListener(new WizardListener(){
179
		setFLayer(layer);
180
		wfsParamsTabbedPane = getParamsPanel(((FLyrWFS) layer).getProperties());
181
		wfsParamsTabbedPane.addWizardListener(new WizardListener(){
175 182
			public void wizardStateChanged(boolean finishable) {
176 183
				getBtnOk().setEnabled(finishable);
177 184
				getBtnApply().setEnabled(finishable);
......
179 186

  
180 187
			public void error(Exception e) {
181 188
			}
182
        	
183
        })  ;
184
        //wfsParamsTabbedPane.disableDisagregatedLayers();
185
        this.add(wfsParamsTabbedPane);
186
        this.add(getButtonsPanel(), null);
187
    }
188
    
189
    public JPanel getButtonsPanel() {
189

  
190
		})  ;
191
		//wfsParamsTabbedPane.disableDisagregatedLayers();
192
		this.add(wfsParamsTabbedPane);
193
		this.add(getButtonsPanel(), null);
194
	}
195

  
196
	public JPanel getButtonsPanel() {
190 197
		if (buttonsPanel == null) {
191 198
			m_actionListener = new CommandListener(this);
192 199
			buttonsPanel = new JPanel();
193
	        buttonsPanel.setBounds(5, wfsParamsTabbedPane.getHeight(), 471, 40);
200
			buttonsPanel.setBounds(5, wfsParamsTabbedPane.getHeight(), 471, 40);
194 201
			buttonsPanel.setLayout(null);     
195 202
			buttonsPanel.setName("buttonPanel");
196
			
197
	        buttonsPanel.add(getBtnOk(), null);
198
	        buttonsPanel.add(getBtnApply(), null);
199
	        buttonsPanel.add(getBtnCancel(), null);
203

  
204
			buttonsPanel.add(getBtnOk(), null);
205
			buttonsPanel.add(getBtnApply(), null);
206
			buttonsPanel.add(getBtnCancel(), null);
200 207
		}
201 208
		return buttonsPanel;
202 209
	}
203
	
204
    
205
    /**
210

  
211

  
212
	/**
206 213
	 * With getParamsPanel we have access to the map config TabbedPane.
207 214
	 * If this panel doesn't exist yet (which can occur when an existing project is
208 215
	 * recovered) it is been automatically constructed by connecting to the server,
......
231 238
	 * @return WMSParamsPanel
232 239
	 */
233 240
	public WFSParamsPanel getParamsPanel(HashMap info) {
234
	    if (info!=null){
235
	    	URL host = (URL) info.get("host");
236
	    	WFSWizardData dataSource = new WFSWizardData();
237
	    	//dataSource.setHost(host, false);
238
	    	dataSource.setDriver(((FLyrWFS)fLayer).getWfsDriver());
239
	    	WFSParamsPanel toc = new WFSParamsPanel();
240
	    	toc.setStatus((WFSStatus)info.get("status"));
241
	    	toc.setWizardData(dataSource);
242
	    	toc.setListenerSupport(new WizardListenerSupport());
243
	    	toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
244
	    	toc.setLayerName(fLayer.getName());
245
	    	toc.setVisible(true);
246
	    	toc.refreshInfo();
247
	    	applied = false;
248
	    	return toc;	    	
249
	    }
250
	    return null;        
241
		if (info!=null){
242
			URL host = (URL) info.get("host");
243
			WFSWizardData dataSource = new WFSWizardData();
244
			//dataSource.setHost(host, false);
245
			dataSource.setDriver(((FLyrWFS)fLayer).getWfsDriver());
246
			WFSParamsPanel toc = new WFSParamsPanel();
247
			toc.setStatus((WFSStatus)info.get("status"));
248
			toc.setWizardData(dataSource);
249
			toc.setListenerSupport(new WizardListenerSupport());
250
			toc.setSelectedFeature((WFSLayerNode)info.get("wfsLayerNode"));
251
			toc.setLayerName(fLayer.getName());
252
			toc.setVisible(true);
253
			toc.refreshInfo();
254
			applied = false;
255
			return toc;	    	
256
		}
257
		return null;        
251 258
	}
252
	
253
	
259

  
260

  
254 261
	public WindowInfo getWindowInfo() {
255 262
		if (m_ViewInfo == null){
256 263
			m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
......
277 284

  
278 285
	public JButton getBtnOk() {
279 286
		if (btnOk == null) {
280
	        btnOk = new JButton("ok");
281
	        btnOk.setText(PluginServices.getText(this,"ok"));
282
	        btnOk.setActionCommand("OK");
283
	        btnOk.addActionListener(m_actionListener);
284
	        btnOk.setBounds(367, 9, 90, 25);
287
			btnOk = new JButton("ok");
288
			btnOk.setText(PluginServices.getText(this,"ok"));
289
			btnOk.setActionCommand("OK");
290
			btnOk.addActionListener(m_actionListener);
291
			btnOk.setBounds(367, 9, 90, 25);
285 292
		}
286 293
		return btnOk;
287 294
	}
288
	
295

  
289 296
	public JButton getBtnApply() {
290 297
		if (btnApply == null) {
291
	        btnApply = new JButton("apply");
292
	        btnApply.setText(PluginServices.getText(this,"apply"));
293
	        btnApply.setEnabled(false);
294
	        btnApply.setActionCommand("APPLY");
295
	        btnApply.addActionListener(m_actionListener);
296
	        btnApply.setBounds(267, 9, 90, 25);
298
			btnApply = new JButton("apply");
299
			btnApply.setText(PluginServices.getText(this,"apply"));
300
			btnApply.setEnabled(false);
301
			btnApply.setActionCommand("APPLY");
302
			btnApply.addActionListener(m_actionListener);
303
			btnApply.setBounds(267, 9, 90, 25);
297 304
		}
298 305
		return btnApply;
299 306
	}
300
	
307

  
301 308
	public JButton getBtnCancel() {
302 309
		if (btnCancel == null) {
303
	        btnCancel = new JButton("cancel");
304
	        btnCancel.setText(PluginServices.getText(this,"cancel"));
305
	        btnCancel.setActionCommand("CANCEL");
306
	        btnCancel.addActionListener(m_actionListener);
307
	        btnCancel.setBounds(137, 9, 90, 25);
310
			btnCancel = new JButton("cancel");
311
			btnCancel.setText(PluginServices.getText(this,"cancel"));
312
			btnCancel.setActionCommand("CANCEL");
313
			btnCancel.addActionListener(m_actionListener);
314
			btnCancel.setBounds(137, 9, 90, 25);
308 315
		}
309 316
		return btnCancel;
310 317
	}
311
	
318

  
312 319
	public void close() {
313 320
		PluginServices.getMDIManager().closeWindow(this);		
314 321
	}
315
	
316
    /**
317
     * Merge two FLayers in one
318
     * @param group1
319
     * @param group2
320
     * @return
321
     */
322
    private FLayers mergeFLayers(FLayers group1, FLayers group2)
323
    {    	
324
    	FLayer layer;
325
    	for(int i = 0; i < group2.getLayersCount(); i++)
326
    	{
327
    		layer = group2.getLayer( i );
328
    		if(group1.getLayer( layer.getName()) == null ){
329
    			group1.addLayer( layer );
330
    		}
331
    	}
332
    	
333
    	return group1;
334
    }
335
	
322

  
323
	/**
324
	 * Merge two FLayers in one
325
	 * @param group1
326
	 * @param group2
327
	 * @return
328
	 */
329
	private FLayers mergeFLayers(FLayers group1, FLayers group2)
330
	{    	
331
		FLayer layer;
332
		for(int i = 0; i < group2.getLayersCount(); i++)
333
		{
334
			layer = group2.getLayer( i );
335
			if(group1.getLayer( layer.getName()) == null ){
336
				group1.addLayer( layer );
337
			}
338
		}
339

  
340
		return group1;
341
	}
342

  
336 343
	private class CommandListener implements ActionListener {
337 344
		public CommandListener(WFSPropsDialog tp) {
338
			 //m_tp = tp;
345
			//m_tp = tp;
339 346
		}
340
		 
347

  
341 348
		/* (non-Javadoc)
342 349
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
343 350
		 */
......
346 353
				close();
347 354
				return;
348 355
			}else{					
349
				 String layerName = fLayer.getName();
350
				 VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
351
				 FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();						
352
				 try {
353
					 fLayer = wfsParamsTabbedPane.getLayer();
354
					 URL host = new URL(wfsParamsTabbedPane.getData().getHost());
355
					 String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
356
					 fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
357
					 if (fLayer != null){
358
						 ((FLyrWFS)fLayer).setLegend(legend);
359
					 }						 
360
					 
361
				 } catch (MalformedURLException e1) {
362
					 e1.printStackTrace();
363
				 } catch (FieldNotFoundException e1) {
364
					 e1.printStackTrace();
365
				 } catch (DriverException e1) {
366
					 e1.printStackTrace();
367
				 } 
368
			
356
				String layerName = fLayer.getName();
357
				VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
358
				FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();					 
359
				removeProjectTable((FLyrVect)fLayer);				 
360
				try {
361
					fLayer = wfsParamsTabbedPane.getLayer();
362
					URL host = new URL(wfsParamsTabbedPane.getData().getHost());
363
					String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
364
					fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
365
					if (fLayer != null){
366
						((FLyrWFS)fLayer).setLegend(legend);
367
					}						 
368

  
369
				} catch (MalformedURLException e1) {
370
					e1.printStackTrace();
371
				} catch (FieldNotFoundException e1) {
372
					e1.printStackTrace();
373
				} catch (DriverException e1) {
374
					e1.printStackTrace();
375
				} 
376

  
369 377
				if (e.getActionCommand() == "APPLY"){
370 378
					// We can't 'apply' if there is a filter query and it's incorrect
371 379
					if (wfsParamsTabbedPane.getFilterQuery() != null) {					
......
376 384
						applied = true;
377 385
						getBtnApply().setEnabled(!applied);
378 386
						refreshLayouts();						 
379
						 
387

  
380 388
						// If we load another layer, or the same but we've selected others attributes -> notify it to he WFSFilter panel
381 389
						if (getWFSFilterPanelIsAsTabForWFSLayersLoad() || (wfsParamsTabbedPane.getFieldsSelectedOfSameLayerHasChanged())) {
382 390
							setWFSFilterPanelIsAsTabForWFSLayersLoad(false);
383 391
							wfsParamsTabbedPane.resetFieldsSelectedOfSameLayerHasChanged(); // reset that attribute
384 392
						}
385
						 
393

  
386 394
						// Update values associated to the current selected field
387 395
						wfsParamsTabbedPane.updateWFSFilterFieldValues();	
388 396
					}
389 397
					return;				 
390 398
				}
391
				 
399

  
392 400
				if (e.getActionCommand() == "OK") {
393 401
					// We can't 'apply' if there is a filter query and it's incorrect
394 402
					if (wfsParamsTabbedPane.getFilterQuery() != null) {	
395 403
						if (!applied) {
396 404
							if (getBtnApply().isEnabled()){
397
								 
405

  
398 406
								layerName = prepareFlyrWFSLayer();
399
								 
407

  
400 408
								View vista = (View) PluginServices.getMDIManager().getActiveWindow();
401 409
								MapControl mapCtrl = vista.getMapControl();
402 410
								mapCtrl.getMapContext().getLayers().replaceLayer(layerName, fLayer);
......
405 413
							}
406 414
						}	
407 415
						close();
408
						 
416

  
409 417
						// Update all fields and values known about the current layer loaded (and selected)
410 418
						((FLyrWFS)fLayer).setAllFieldsAndValuesKnown(wfsParamsTabbedPane.getAllFieldsAndValuesKnownOfCurrentLayer());
411 419
					}
412 420
				}
413 421
			}
414 422
		}
415
		 
423

  
416 424
		/**
425
		 * It removes the associated project table
426
		 * @param flayer
427
		 * Flayer vercorial
428
		 */
429
		private void removeProjectTable(FLyrVect flayer){
430
			//remove it
431
			ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
432
			ArrayList tables = ext.getProject().getDocumentsByType(ProjectTableFactory.registerName);
433
			for (int i=0 ; i<tables.size() ; i++){
434
				ProjectTable projectTable = (ProjectTable)tables.get(i);
435
				try {
436
					Object obj = projectTable.getAssociatedTable().getRecordset();
437
					if (flayer.getRecordset().equals(projectTable.getAssociatedTable().getRecordset())){
438
						ext.getProject().delDocument(projectTable);
439
					}
440
				} catch (DriverException e) {
441
					//It doens't matter. The table will not deleted
442
				}
443
				
444
			}
445
		}
446

  
447
		/**
417 448
		 * Updates data in the current layer of current active view
418 449
		 * 
419 450
		 * @param currentView The current active view
420 451
		 * @return Te name of the layer
421 452
		 */
422 453
		private String prepareFlyrWFSLayer() {
423
//			 layerName = fLayer.getName();
424
	//	 	 View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
454
//			layerName = fLayer.getName();
455
			//	 	 View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
425 456
			VectorialLegend legend = (VectorialLegend)((FLyrVect)fLayer).getLegend();
426
		 	FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();						
427
		 	try {
428
		 		fLayer = wfsParamsTabbedPane.getLayer();
429
		 		URL host = new URL(wfsParamsTabbedPane.getData().getHost());
430
		 		String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
431
		 		fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
432
		 		if (fLayer != null) {
433
		 			((FLyrWFS)fLayer).setLegend(legend);
434
					
435
		 			 // Update all fields and values known about the current layer loaded (and selected)
436
		 			((FLyrWFS)fLayer).setAllFieldsAndValuesKnown(wfsParamsTabbedPane.getAllFieldsAndValuesKnownOfCurrentLayer());
437
		 		}
457
			FMapWFSDriver driver = wfsParamsTabbedPane.getDriver();						
458
			try {
459
				fLayer = wfsParamsTabbedPane.getLayer();
460
				URL host = new URL(wfsParamsTabbedPane.getData().getHost());
461
				String onlineResource = wfsParamsTabbedPane.getData().getOnlineResource();
462
				fLayer = new FLyrWFSFactory().getFLyrWFS(fLayer,host,onlineResource,driver,true);
463
				if (fLayer != null) {
464
					((FLyrWFS)fLayer).setLegend(legend);
465

  
466
					// Update all fields and values known about the current layer loaded (and selected)
467
					((FLyrWFS)fLayer).setAllFieldsAndValuesKnown(wfsParamsTabbedPane.getAllFieldsAndValuesKnownOfCurrentLayer());
468
				}
438 469
			} catch (MalformedURLException e1) {
439 470
				e1.printStackTrace();
440 471
			} catch (FieldNotFoundException e1) {
......
442 473
			} catch (DriverException e1) {
443 474
				e1.printStackTrace();
444 475
			}
445
			 
476

  
446 477
			return fLayer.getName();
447
		}
478
		}		
479
	}
448 480

  
449
		private boolean loadLayer(FLayer flayer) {
450
			try {
451
				((FLyrWFS)fLayer).load();
452
				
453
				if (((FLyrWFS)fLayer).getNumfeatures() == ((FLyrWFS)fLayer).getWfsDriver().getRowCount()) {
454
					JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
455
						PluginServices.getText(this,"maxFeatures_aviso"));	
456
				}
457
			} catch (Exception e1) {
458
				e1.printStackTrace();
459
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
460
						PluginServices.getText(this,"cantLoad"));
461
				return false;
462
			}
463
			return true;
464
		}
465
	}
466
	 
467 481
	/**
468 482
	 * @see WFSFilterPanel#setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean)
469 483
	 */
470 484
	public void setWFSFilterPanelIsAsTabForWFSLayersLoad(boolean b) {
471 485
		this.wfsParamsTabbedPane.setWFSFilterPanelIsAsTabForWFSLayersLoad(b);
472 486
	}
473
	
487

  
474 488
	/**
475 489
	 * @see WFSFilterPanel#getWFSFilterPanelIsAsTabForWFSLayersLoad()
476 490
	 */
477 491
	public boolean getWFSFilterPanelIsAsTabForWFSLayersLoad() {
478 492
		return this.wfsParamsTabbedPane.getWFSFilterPanelIsAsTabForWFSLayersLoad();
479 493
	}
480
	
494

  
481 495
	/**
482 496
	 * Sets all fielsd and values known of current layer to WFSFilterPanel
483 497
	 */
484 498
	public void updateAllFieldsAndValuesKnownOfCurrentLayerToWFSFilterPanel() {
485 499
		this.wfsParamsTabbedPane.setAllFieldsAndValuesKnownOfCurrentLayer(((FLyrWFS)this.getFLayer()).getAllFieldsAndValuesKnown());
486 500
	}
487
	
501

  
488 502
	/**
489 503
	 * Refresh the layouts
490 504
	 *

Also available in: Unified diff