Revision 53

View differences:

org.gvsig.wfs.app/trunk/org.gvsig.wfs.app/org.gvsig.wfs.app.mainplugin/src/main/java/org/gvsig/wfs/gui/wizards/WFSWizard.java
1
package org.gvsig.wfs.gui.wizards;
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 */package org.gvsig.wfs.gui.wizards;
2 20

  
3 21
import java.awt.FlowLayout;
4 22
import java.awt.event.KeyAdapter;
......
7 25
import java.io.File;
8 26
import java.io.FileInputStream;
9 27
import java.io.FileNotFoundException;
10
import java.io.FileOutputStream;
11 28
import java.io.IOException;
12 29
import java.net.MalformedURLException;
13 30
import java.net.URL;
......
26 43
import javax.swing.JTabbedPane;
27 44
import javax.swing.event.ChangeEvent;
28 45
import javax.swing.event.ChangeListener;
46
import org.apache.commons.io.IOUtils;
29 47

  
30 48
import org.slf4j.Logger;
31 49
import org.slf4j.LoggerFactory;
32
import org.gvsig.andami.Launcher;
33 50
import org.gvsig.andami.PluginServices;
34 51
import org.gvsig.andami.PluginsLocator;
52
import org.gvsig.andami.PluginsManager;
35 53
import org.gvsig.andami.messages.NotificationManager;
36 54
import org.gvsig.andami.persistence.serverData.ServerDataPersistence;
37 55
import org.gvsig.app.gui.WizardPanel;
......
46 64
import org.gvsig.gui.beans.panelGroup.PanelGroupManager;
47 65
import org.gvsig.gui.beans.swing.JButton;
48 66
import org.gvsig.remoteclient.wfs.WFSProtocolHandlerFactory;
49
import org.gvsig.tools.ToolsLocator;
67
import org.gvsig.tools.dynobject.DynObject;
50 68
import org.gvsig.tools.exception.BaseException;
51
import org.gvsig.tools.persistence.PersistenceManager;
52
import org.gvsig.utils.NotExistInXMLEntity;
53
import org.gvsig.utils.XMLEntity;
54 69
import org.gvsig.utils.swing.jcomboServer.JComboServer;
55 70
import org.gvsig.utils.swing.jcomboServer.ServerData;
71
import org.gvsig.wfs.WFSClientExtension;
56 72
import org.gvsig.wfs.gui.panels.WFSParamsPanel;
57 73

  
58
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
59
 *
60
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
61
 *
62
 * This program is free software; you can redistribute it and/or
63
 * modify it under the terms of the GNU General Public License
64
 * as published by the Free Software Foundation; either version 2
65
 * of the License, or (at your option) any later version.
66
 *
67
 * This program is distributed in the hope that it will be useful,
68
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
70
 * GNU General Public License for more details.
71
 *
72
 * You should have received a copy of the GNU General Public License
73
 * along with this program; if not, write to the Free Software
74
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
75
 *
76
 * For more information, contact:
77
 *
78
 *  Generalitat Valenciana
79
 *   Conselleria d'Infraestructures i Transport
80
 *   Av. Blasco Ib??ez, 50
81
 *   46010 VALENCIA
82
 *   SPAIN
83
 *
84
 *      +34 963862235
85
 *   gvsig@gva.es
86
 *      www.gvsig.gva.es
87
 *
88
 *    or
89
 *
90
 *   IVER T.I. S.A
91
 *   Salamanca 50
92
 *   46005 Valencia
93
 *   Spain
94
 *
95
 *   +34 963163400
96
 *   dac@iver.es
97
 */
98 74

  
99 75
/**
100 76
 * <p>
......
105 81
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
106 82
 */
107 83
public class WFSWizard extends WizardPanel {
108
    private static Logger                 logger                 = LoggerFactory.getLogger(WFSWizard.class);
109
	private String                        pluginName             = "org.gvsig.wfs.app.mainplugin";
110
	private File                          pluginPersistenceFile  = null;
111
	private File                          serverPropertiesFile   = null;
112
	private ServerDataPersistence         serverDataPersistence  = null;
113
	private String                        serversPropsFile       = "servers.properties";
84
    private static final Logger logger                 = LoggerFactory.getLogger(WFSWizard.class);
85
    private static final String serversPropsFilename       = "servers.properties";
86
    private PluginServices plugin = null;
114 87
	
115 88
    private int page;
116 89
    private boolean connected = false;
......
158 131
     * This method initializes this
159 132
     */
160 133
    private void initialize() {
134
        PluginsManager pluginsManager = PluginsLocator.getManager();
135
        this.plugin = pluginsManager.getPlugin(WFSClientExtension.class);
136

  
161 137
        setTabName(PluginServices.getText(this, "WFS"));
162 138

  
163 139
        serverVersionLabel = new JLabel();
......
204 180
     */
205 181
    private void addHost(String host) {
206 182
        host = host.trim();
207
        ServerDataPersistence persistence =
208
            new ServerDataPersistence(ServerData.SERVER_TYPE_WFS);
209
        persistence.addServerData(new ServerData(host,
210
            ServerData.SERVER_TYPE_WFS));
183
        ServerDataPersistence persistence = getServerDataPersistence();
184
        persistence.addServerData(new ServerData(host, ServerData.SERVER_TYPE_WFS));
211 185
    }
212 186

  
213 187
    /**
......
319 293
            // pressing the 'Enter' key
320 294
            cmbHost.getEditor().getEditorComponent()
321 295
                .addKeyListener(new KeyAdapter() {
322

  
323
                    /*
324
                     * (non-Javadoc)
325
                     * 
326
                     * @see
327
                     * java.awt.event.KeyAdapter#keyReleased(java.awt.event.
328
                     * KeyEvent)
329
                     */
330 296
                    public void keyReleased(KeyEvent e) {
331 297
                        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
332 298
                            getBtnConnect().doClick();
......
338 304
    }
339 305
    
340 306
    /**
341
	 * Gets the list of servers that have been persisted or added in the properties file
342
	 * @return
343
	 */
344
	private ServerDataPersistence getServerDataPersistence() {
345
		if(serverDataPersistence == null) {
346
			PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
307
    * Gets the list of servers that have been persisted or added in the properties file
308
    * @return
309
    */
310
    private ServerDataPersistence getServerDataPersistence() {
311
        DynObject pluginProperties = this.plugin.getPluginProperties();
312
        ServerDataPersistence servers =  (ServerDataPersistence) pluginProperties.getDynValue("servers");
347 313

  
348
			//Lee los servidores de la persistencia
349
			try {
350
				FileInputStream is = new FileInputStream(getPluginPersistenceFile());
351
				serverDataPersistence = (ServerDataPersistence) persistenceManager.getObject(is);
352
			} catch (FileNotFoundException e) {
353
				logger.info("Persistence file not found for WMS plugin", e);
354
			}
314
        if( servers == null || servers.isEmpty() ) {
315
            if( servers == null ) {
316
                servers = new ServerDataPersistence(ServerData.SERVER_TYPE_WFS);
317
                pluginProperties.setDynValue("servers", servers);
318
            }
319
            //Lee los servidores del properties y los mezcla con los que hay en la persistencia
320
            Properties prop = new Properties();
321
            File propFile = new File(this.plugin.getPluginDirectory(),serversPropsFilename);
322
            FileInputStream fis = null;
323
            try {
324
                    fis = new FileInputStream(propFile);
325
                    prop.load(fis);
326
            } catch (FileNotFoundException e) {
327
                    logger.info("Properties file '"+propFile.getAbsolutePath()+"' not found", e);
328
            } catch (IOException e) {
329
                    logger.info("Error reading properties file '"+propFile.getAbsolutePath()+"'.", e);
330
            } finally {
331
                IOUtils.closeQuietly(fis);
332
            }
355 333

  
356
			if(serverDataPersistence == null)
357
				serverDataPersistence = new ServerDataPersistence(ServerData.SERVER_TYPE_WFS);
334
            for (int i = 0; i < prop.size(); i++) {
335
                Object value = prop.get("server[" + i + "]");
336
                servers.addServerData(new ServerData(value.toString(), ServerData.SERVER_TYPE_WFS));
337
            }
358 338

  
359
			//Lee los servidores del properties y los mezcla con los que hay en la persistencia
360
			Properties prop = new Properties();
361
			try {
362
				prop.load(new FileInputStream(getServerPropertiesFile()));
363
			} catch (FileNotFoundException e) {
364
				logger.info("Properties file not found for WMS plugin", e);
365
			} catch (IOException e) {
366
				logger.info("Error reading properties file", e);
367
			}
368

  
369
			boolean newProjectServers = false;
370
			for (int i = 0; i < prop.size(); i++) {
371
				Object value = prop.get("server[" + i + "]");
372
				if(!serverDataPersistence.existsServer(value.toString())) {
373
					serverDataPersistence.addServerData(new ServerData(value.toString(), ServerData.SERVER_TYPE_WFS));
374
					newProjectServers = true;
375
				}
376
			}
377

  
378
			//Si hay servidores nuevos los persiste
379
			if(newProjectServers) {
380
				try {
381
					FileOutputStream os = new FileOutputStream(getPluginPersistenceFile());
382
					persistenceManager.putObject(os, serverDataPersistence);
383
				} catch (FileNotFoundException e) {
384
					logger.info("Persistence file not found for WMS plugin", e);
385
				}
386
			}
387
		}
388

  
389
		return serverDataPersistence;
390
	}
339
        }
340
        return servers;
341
    }
391 342
	
392 343
	/**
393 344
	 * Saves the list of server reading from the <code>ComboBox</code>
394 345
	 */
395
	private void saveServerListFromComboBox() {
396
		PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
397
		ServerDataPersistence persistence = new ServerDataPersistence(ServerData.SERVER_TYPE_WFS);
398
		String urlSelected = getTxtHost().getModel().getSelectedItem().toString();
399
		
400
		boolean isSelectedInModel = false;
401
		for (int i = 0; i < getTxtHost().getItemCount(); i++) {
402
			String url = getTxtHost().getItemAt(i).toString();
403
			persistence.addServerData(new ServerData(url, ServerData.SERVER_TYPE_WMS));
404
			if(url.equals(urlSelected))
405
				isSelectedInModel = true;
406
		}
407
		
408
		if(!isSelectedInModel)
409
			persistence.addServerData(new ServerData(urlSelected, ServerData.SERVER_TYPE_WFS));
410
		
411
		if(getServerDataPersistence().compareTo(persistence) != 0) {
412
			try {
413
				FileOutputStream os = new FileOutputStream(getPluginPersistenceFile());
414
				persistenceManager.putObject(os, persistence);
415
			} catch (FileNotFoundException e) {
416
				logger.info("Persistence file not found for WMS plugin", e);
417
			}
418
		}
419
	}
420
	
421
	/**
422
	 * Gets the persistence file of this plugin
423
	 * @return
424
	 */
425
	private File getPluginPersistenceFile() {
426
		if(pluginPersistenceFile == null) {
427
			File persistenceFolder = new File(Launcher.getAppHomeDir()
428
					+ File.separator + "plugins" + File.separator + pluginName);
429
			
430
			if (!persistenceFolder.exists()) {
431
				persistenceFolder.mkdirs();
432
			}
433
			
434
			pluginPersistenceFile = new File(persistenceFolder.getAbsolutePath() + 
435
				File.separator + 
436
				"plugin-persistence.dat");
437
		}
438
		return pluginPersistenceFile;
439
	}
440
	
441
	/**
442
	 * Gets the file which contains the default list of servers
443
	 * @return
444
	 */
445
	private File getServerPropertiesFile() {
446
		if(serverPropertiesFile == null) {
447
			File pluginFolder = PluginsLocator.getManager().getPluginsFolder();
448
			serverPropertiesFile = new File(pluginFolder.getAbsolutePath() + 
449
					File.separator + 
450
					pluginName + 
451
					File.separator + 
452
					serversPropsFile);
453
		}
454
		return serverPropertiesFile;
455
	}
346
        private void saveServerListFromComboBox() {
347
            ServerDataPersistence persistence = getServerDataPersistence();
348
            String urlSelected = getTxtHost().getModel().getSelectedItem().toString();
456 349

  
350
            boolean isSelectedInModel = false;
351
            for ( int i = 0; i < getTxtHost().getItemCount(); i++ ) {
352
                String url = getTxtHost().getItemAt(i).toString();
353
                persistence.addServerData(new ServerData(url, ServerData.SERVER_TYPE_WMS));
354
                if ( url.equals(urlSelected) ) {
355
                    isSelectedInModel = true;
356
                }
357
            }
358
            if ( !isSelectedInModel ) {
359
                persistence.addServerData(new ServerData(urlSelected, ServerData.SERVER_TYPE_WFS));
360
            }
361
        }
362

  
457 363
    /**
458 364
     * This method initializes btnDetalles
459 365
     * 
org.gvsig.wfs.app/trunk/org.gvsig.wfs.app/org.gvsig.wfs.app.mainplugin/src/main/resources-plugin/plugin-persistence.def
1
<?xml version="1.0"?>
2
<!--
3
Definitions of plugin persistence org.gvsig.editing.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    <class name="org.gvsig.wfs.app.mainplugin">
9
      <description>Persistence definition for the WFS plugin</description>
10
      <fields>
11
        <field name="servers" type="object" classOfValue="org.gvsig.andami.persistence.serverData.ServerDataPersistence" mandatory="false">
12
          <description>List of WFS servers</description>
13
        </field>
14
      </fields>
15
    </class>
16
  </classes>
17
</definitions>  
org.gvsig.wfs.app/trunk/org.gvsig.wfs.app/pom.xml
10 10
    <parent>
11 11
        <groupId>org.gvsig</groupId>
12 12
        <artifactId>org.gvsig.desktop</artifactId>
13
        <version>2.0.28</version>
13
        <version>2.0.33-SNAPSHOT</version>
14 14
    </parent>
15 15
    
16 16
    <url>https://devel.gvsig.org/redmine/projects/gvsig-wfs</url>

Also available in: Unified diff