Revision 34070

View differences:

tags/v2_0_0_Build_2021/extensions/extGeoDB/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
6

  
7
	<modelVersion>4.0.0</modelVersion>
8
	<groupId>org.gvsig</groupId>
9
	<artifactId>org.gvsig.geodb</artifactId>
10
	<packaging>jar</packaging>
11
	<version>2.0-SNAPSHOT</version>
12
	<name>extGeoDB</name>
13
	<description>Connection manager to spatial databases (various simultaneous connections)</description>
14
	<url>http://maven.apache.org</url>
15
	<parent>
16
		<groupId>org.gvsig</groupId>
17
		<artifactId>gvsig-base-extension-pom</artifactId>
18
		<version>2.0-SNAPSHOT</version>
19
	</parent>
20
	<distributionManagement>
21
		<site>
22
			<id>gvsig-repository</id>
23
			<url>${site-repository}/</url>
24
		</site>
25
	</distributionManagement>
26

  
27
	<dependencies>
28
		<dependency>
29
			<groupId>org.gvsig</groupId>
30
			<artifactId>org.gvsig.fmap.dal</artifactId>
31
			<version>2.0-SNAPSHOT</version>
32
		</dependency>
33
		<dependency>
34
			<groupId>org.gvsig</groupId>
35
			<artifactId>org.gvsig.fmap.dal.db</artifactId>
36
			<version>2.0-SNAPSHOT</version>
37
		</dependency>
38
		<dependency>
39
			<groupId>org.gvsig</groupId>
40
			<artifactId>org.gvsig.fmap.dal.db</artifactId>
41
			<version>2.0-SNAPSHOT</version>
42
		</dependency>
43
		<dependency>
44
			<groupId>org.gvsig</groupId>
45
			<artifactId>org.gvsig.fmap.dal.db</artifactId>
46
			<version>2.0-SNAPSHOT</version>
47
			<classifier>store.jdbc</classifier>
48
		</dependency>
49
		<dependency>
50
			<groupId>org.gvsig</groupId>
51
			<artifactId>org.gvsig.fmap.dal.db</artifactId>
52
			<version>2.0-SNAPSHOT</version>
53
			<classifier>store.postgresql</classifier>
54
		</dependency>
55
		<dependency>
56
			<groupId>org.gvsig</groupId>
57
			<artifactId>org.gvsig.fmap.dal.db</artifactId>
58
			<version>2.0-SNAPSHOT</version>
59
			<classifier>store.mysql</classifier>
60
		</dependency>
61
		<dependency>
62
			<groupId>org.gvsig</groupId>
63
			<artifactId>org.gvsig.ui</artifactId>
64
			<version>2.0-SNAPSHOT</version>
65
		</dependency>
66
		<dependency>
67
			<groupId>org.gvsig</groupId>
68
			<artifactId>org.gvsig.app</artifactId>
69
			<version>2.0-SNAPSHOT</version>
70
		</dependency>
71
		<dependency>
72
			<groupId>org.gvsig</groupId>
73
			<artifactId>org.gvsig.about.api</artifactId>
74
			<version>1.0.0-SNAPSHOT</version>
75
		</dependency>
76

  
77
	</dependencies>
78
	<properties>
79
		<build-dir>${basedir}/../build</build-dir>
80
	</properties>
81
	<build>
82
		<sourceDirectory>src</sourceDirectory>
83
		<!-- <testSourceDirectory>src-test</testSourceDirectory> -->
84
		<plugins>
85
			<!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION -->
86
			<plugin>
87
				<groupId>org.apache.maven.plugins</groupId>
88
				<artifactId>maven-surefire-plugin</artifactId>
89
				<configuration>
90
					<skipTests>true</skipTests>
91
				</configuration>
92
			</plugin>
93
		</plugins>
94
	</build>
95
</project>
tags/v2_0_0_Build_2021/extensions/extGeoDB/distribution/distribution.xml
1
<assembly>
2
	<id>distribution</id>
3
	<formats>
4
		<format>dir</format>
5
	</formats>
6
	<fileSets>
7
	<!-- Extructure for the extension -->
8
		<fileSet>
9
			<directory>config</directory>
10
			<outputDirectory>${extension.install.dir.name}
11
			</outputDirectory>
12
		</fileSet>
13
		<fileSet>
14
			<directory>images</directory>
15
			<outputDirectory>/${extension.install.dir.name}/images
16
			</outputDirectory>
17
		</fileSet>
18
	</fileSets>
19
    <files>
20
        <file>
21
            <source>package.info</source>
22
            <outputDirectory>${extension.install.dir.name}
23
            </outputDirectory>
24
        </file>
25
    </files>
26
	<!--
27
		***********************************************************************
28
	-->
29
  <!-- *													   *-->
30
	<!--
31
		***********************************************************************
32
	-->
33
	<dependencySets>
34
		<dependencySet>
35
			<outputDirectory>${extension.install.dir.name}/${library-dir}
36
			</outputDirectory>
37
			<includes>
38
				<include>org.gvsig:org.gvsig.geodb</include>
39
				<include>org.gvsig:org.gvsig.fmap.dal.db</include>
40
				<include>org.gvsig:org.gvsig.fmap.dal.db:jar:store.jdbc</include>
41
			</includes>
42
		</dependencySet>
43
		<dependencySet>
44
			<outputDirectory>${extension.install.dir.name}/${library-dir}
45
			</outputDirectory>
46
			<includes>
47
				<include>org.gvsig:org.gvsig.fmap.dal.db:jar:store.jdbc</include>
48
				<include>commons-dbcp:commons-dbcp</include>
49
				<include>commons-collections:commons-collections</include>
50
				<include>commons-pool:commons-pool</include>
51
			</includes>
52
		</dependencySet>
53
		<dependencySet>
54
			<outputDirectory>${extension.install.dir.name}/${library-dir}
55
			</outputDirectory>
56
			<includes>
57
				<include>org.gvsig:org.gvsig.fmap.dal.db:jar:store.postgresql</include>
58
				<include>postgresql:postgresql</include>
59
			</includes>
60
		</dependencySet>
61
		<dependencySet>
62
			<outputDirectory>${extension.install.dir.name}/${library-dir}
63
			</outputDirectory>
64
			<includes>
65
				<include>org.gvsig:org.gvsig.fmap.dal.db:jar:store.mysql</include>
66
				<include>mysql:mysql-connector-java</include>
67
			</includes>
68
		</dependencySet>		
69
	</dependencySets>
70
</assembly>
tags/v2_0_0_Build_2021/extensions/extGeoDB/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Mon Nov 08 09:55:41 CET 2010
3
buildNumber=2021
tags/v2_0_0_Build_2021/extensions/extGeoDB/config/prodevelop.html
1
<html>
2
<body>
3

  
4
<img src="prodevelop-logo.png"><br>
5

  
6
<h2>PRODEVELOP</h2>
7
<br>
8

  
9
<p>EN CONSTRUCCION</p>
10

  
11
</body>
12
</html>
tags/v2_0_0_Build_2021/extensions/extGeoDB/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<libraries library-dir="lib"/>
4
	<depends plugin-name="org.gvsig.app"/>
5
	<resourceBundle name="text"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.geodb.SingleVectorialDBConnectionExtension"
8
			description="Opens DB connections manager"
9
			active="true">
10
			<menu text="Ver/gestor_db" action-command="GESTOR_VECTORIALDB" key="j"
11
				tooltip="abrir_gestor_de_orig_db"
12
				position="3"/>
13
		</extension>
14

  
15
		<extension class-name="org.gvsig.geodb.ExtDB_Spatial"
16
			description="Support to access Spatial databases"
17
			active="true">
18
		</extension>
19
		<extension class-name="org.gvsig.geodb.ExportToDB"
20
			description="Exportar a diversos formatos"
21
			active="true">
22
			<menu text="Capa/export_to/postgis" action-command="POSTGIS"/>
23
			<menu text="Capa/export_to/mysql" action-command="MYSQL"/>
24
		</extension>
25
	</extensions>
26
</plugin-config>
0 27

  
tags/v2_0_0_Build_2021/extensions/extGeoDB/package.info
1
#
2
#Mon Nov 08 09:56:18 CET 2010
3
state=devel
4
name=extGeoDB
5
official=true
6
code=org.gvsig.geodb
7
operating-system=all
8
architecture=all
9
java-version=j1_5
10
gvSIG-version=2.0.0
11
version=2.0-SNAPSHOT
12
type=plugin
13
build=2021
14
description=Connection manager to spatial databases (various simultaneous connections)
15
model-version=1.0.0
tags/v2_0_0_Build_2021/extensions/extGeoDB/src/org/gvsig/geodb/ExtDB_Spatial.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop 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
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package org.gvsig.geodb;
44

  
45
import org.gvsig.andami.plugins.Extension;
46
import org.gvsig.app.ApplicationLocator;
47
import org.gvsig.app.extension.AddLayer;
48
import org.gvsig.geodb.vectorialdb.wizard.WizardDB;
49
import org.gvsig.geodb.vectorialdb.wizard.WizardVectorialDB;
50

  
51

  
52

  
53
/**
54
 * This extension adds the export-to-oracle button.
55
 *
56
 * @author jldominguez
57
 *
58
 */
59
public class ExtDB_Spatial extends Extension {
60

  
61
//    private DALDbLibrary dbLibrary;
62
//    private DBStoreLibrary dbStoreLibrary;
63
//	private JDBCLibrary jdbcLibrary;
64
//	private PostgreSQLLibrary posgresqlLibrary;
65
//	private MySQLLibrary mysqlLibrary;
66

  
67
	public void initialize() {
68
//    	dbLibrary = new DALDbLibrary();
69
//    	dbStoreLibrary = new DBStoreLibrary();
70
//		jdbcLibrary = new JDBCLibrary();
71
//		posgresqlLibrary = new PostgreSQLLibrary();
72
//		mysqlLibrary = new MySQLLibrary();
73
//
74
//
75
//		dbLibrary.initialize();
76
//		dbStoreLibrary.initialize();
77
//		jdbcLibrary.initialize();
78
//		posgresqlLibrary.initialize();
79
//		mysqlLibrary.initialize();
80

  
81

  
82
    }
83

  
84
    public void execute(String actionCommand) {
85
    }
86

  
87
    public boolean isEnabled() {
88
        return isVisible();
89

  
90
        // return true;
91
    }
92

  
93
    /**
94
     * Is visible when there is one vector layer selected
95
     */
96
    public boolean isVisible() {
97
        return false;
98
    }
99

  
100
	@Override
101
	public void postInitialize() {
102
		super.postInitialize();
103

  
104
//		dbLibrary.postInitialize();
105
//		dbStoreLibrary.postInitialize();
106
//		jdbcLibrary.postInitialize();
107
//		posgresqlLibrary.postInitialize();
108
//		mysqlLibrary.postInitialize();
109

  
110
		ApplicationLocator.getManager().registerAddTableWizard("DB",
111
				"DB Tables", WizardDB.class);
112
    	AddLayer.addWizard(WizardVectorialDB.class);
113
	}
114
}
tags/v2_0_0_Build_2021/extensions/extGeoDB/src/org/gvsig/geodb/ExportToDB.java
1
package org.gvsig.geodb;
2

  
3
import java.awt.Component;
4

  
5
import javax.swing.JComponent;
6
import javax.swing.JOptionPane;
7

  
8
import org.gvsig.andami.PluginServices;
9
import org.gvsig.andami.messages.NotificationManager;
10
import org.gvsig.andami.plugins.Extension;
11
import org.gvsig.app.project.documents.view.ViewDocument;
12
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
13
import org.gvsig.fmap.dal.DALLocator;
14
import org.gvsig.fmap.dal.DataManager;
15
import org.gvsig.fmap.dal.DataTypes;
16
import org.gvsig.fmap.dal.exception.DataException;
17
import org.gvsig.fmap.dal.exception.ReadException;
18
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
19
import org.gvsig.tools.dispose.DisposableIterator;
20
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
21
import org.gvsig.fmap.dal.feature.EditableFeatureType;
22
import org.gvsig.fmap.dal.feature.Feature;
23
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
24
import org.gvsig.fmap.dal.feature.FeatureSelection;
25
import org.gvsig.fmap.dal.feature.FeatureSet;
26
import org.gvsig.fmap.dal.feature.FeatureStore;
27
import org.gvsig.fmap.dal.feature.FeatureType;
28
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
29
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
30
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
31
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
32
import org.gvsig.fmap.dal.store.mysql.MySQLServerExplorer;
33
import org.gvsig.fmap.dal.store.postgresql.PostgreSQLServerExplorer;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.FLayers;
39
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
40
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
41
import org.gvsig.geodb.vectorialdb.ConnectionSettings;
42
import org.gvsig.geodb.vectorialdb.DlgConnection;
43
import org.gvsig.tools.evaluator.AbstractEvaluator;
44
import org.gvsig.tools.evaluator.EvaluatorData;
45
import org.gvsig.tools.evaluator.EvaluatorException;
46
import org.gvsig.utils.PostProcessSupport;
47

  
48

  
49
public class ExportToDB extends Extension {
50
	/**
51
	 * @see org.gvsig.andami.plugins.IExtension#initialize()
52
	 */
53
	public void initialize() {
54
	}
55

  
56
	/**
57
	 * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
58
	 */
59
	public void execute(String actionCommand) {
60
		org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
61
				.getActiveWindow();
62

  
63
		if (f instanceof DefaultViewPanel) {
64
			DefaultViewPanel vista = (DefaultViewPanel) f;
65
			ViewDocument model = vista.getModel();
66
			MapContext mapa = model.getMapContext();
67
			FLayers layers = mapa.getLayers();
68
			FLayer[] actives = layers.getActives();
69
			try {
70
				// NOTA: SI HAY UNA SELECCI?N, SOLO SE SALVAN LOS SELECCIONADOS
71
				for (int i = 0; i < actives.length; i++) {
72
					if (actives[i] instanceof FLyrVect) {
73
						FLyrVect lv = (FLyrVect) actives[i];
74
//						saveToDXF(mapa,lv);
75

  
76

  
77

  
78
						/////////
79

  
80
						long numSelec = ((FeatureSelection)lv.getFeatureStore().getSelection()).getSize();
81
						if (numSelec > 0) {
82
							int resp = JOptionPane.showConfirmDialog(
83
									(Component) PluginServices.getMainFrame(),
84
									PluginServices.getText(this,"se_van_a_guardar_") + numSelec
85
											+ PluginServices.getText(this,"features_desea_continuar"),
86
									PluginServices.getText(this,"export_to"), JOptionPane.YES_NO_OPTION);
87
							if (resp != JOptionPane.YES_OPTION) {
88
								continue;
89
							}
90
						} // if numSelec > 0
91
						// if (actionCommand.equals("SHP")) {
92
						// saveToSHP(mapa, lv);
93
						// }
94
						// if (actionCommand.equals("DXF")) {
95
						// saveToDXF(mapa, lv);
96
						// }
97
						if (actionCommand.equals("POSTGIS")) {
98
							saveToJDBC(mapa, lv, PostgreSQLServerExplorer.NAME);
99
						}
100
						if (actionCommand.equals("MYSQL")) {
101
							saveToJDBC(mapa, lv, MySQLServerExplorer.NAME);
102
						}
103
//						if (actionCommand.equals("GML")) {
104
//							saveToGml(mapa, lv);
105
//						}
106
					} // actives[i]
107
				} // for
108
			} catch (Exception e) {
109
				NotificationManager.showMessageError(e.getMessage(),e);
110
			}
111
		}
112
	}
113

  
114
	public void saveToJDBC(MapContext mapContext, FLyrVect layer,
115
			String explorerName) {
116
		try {
117
			String tableName = JOptionPane.showInputDialog(PluginServices
118
					.getText(this, "intro_tablename"));
119
			if (tableName == null) {
120
				return;
121
			}
122
			FeatureAttributeDescriptor[] pks = layer.getFeatureStore()
123
					.getDefaultFeatureType()
124
					.getPrimaryKey();
125
			String pkName = null;
126
			if (pks == null || pks.length < 1) {
127
				pkName = JOptionPane.showInputDialog(PluginServices.getText(this,"input_pk_field_name"));
128
			}
129

  
130
			tableName = tableName.toLowerCase();
131
			DlgConnection dlg = new DlgConnection();
132
			dlg.setModal(true);
133
			dlg.setVisible(true);
134
			ConnectionSettings cs = dlg.getConnSettings();
135
			if (cs == null) {
136
				return;
137
			}
138

  
139
			DataManager datamanager=DALLocator.getDataManager();
140

  
141
			JDBCServerExplorerParameters explorerParam = (JDBCServerExplorerParameters) datamanager
142
					.createServerExplorerParameters(explorerName);
143

  
144
			explorerParam.setHost(cs.getHost());
145
			if (cs.getPort() != null && cs.getPort().length() > 0) {
146
				explorerParam.setPort(Integer.valueOf(cs.getPort()));
147
			}
148
			explorerParam.setDBName(cs.getDb());
149
			explorerParam.setUser(cs.getUser());
150
			explorerParam.setPassword(cs.getPassw());
151
			if (cs.getSchema() != null && cs.getSchema().length() > 0) {
152
				explorerParam.setSchema(cs.getSchema());
153
			}
154

  
155
			JDBCServerExplorer explorer = (JDBCServerExplorer) datamanager
156
					.createServerExplorer(explorerParam);
157

  
158
			NewFeatureStoreParameters newStoreParams = (NewFeatureStoreParameters) explorer
159
					.getAddParameters();
160

  
161
			((DBStoreParameters) newStoreParams).setTable(tableName);
162

  
163
			if (export(explorer, newStoreParams, null, layer.getFeatureStore(),pkName)) {
164
				openLayer(newStoreParams, tableName, mapContext);
165
			}
166

  
167

  
168

  
169
		} catch (DataException e) {
170
			NotificationManager.addError(e.getMessage(), e);
171
		} catch (ValidateDataParametersException e) {
172
			NotificationManager.addError(e.getMessage(), e);
173
		}
174

  
175
	}
176

  
177

  
178

  
179
	class GeometryTypeEvaluator extends AbstractEvaluator{
180
		private FeatureType featureType=null;
181
		private int type=0;
182
		private FeatureSelection selection;
183
		private boolean hasSelection=false;
184

  
185
		public GeometryTypeEvaluator(FeatureType ft, int t, FeatureSelection selection) {
186
			featureType=ft;
187
			type=t;
188
			this.selection=selection;
189
			hasSelection=selection.getSelectedCount()>0;
190
			this.getFieldsInfo().addFieldValue(
191
					ft.getDefaultGeometryAttributeName());
192
		}
193
		public Object evaluate(EvaluatorData data) throws EvaluatorException {
194
			if (hasSelection){
195
				if (!selection.isSelected((Feature)data)){
196
					return false;
197
				}
198
			}
199
			Geometry geometry=(Geometry) data.getDataValue(featureType.getDefaultGeometryAttributeName());
200
			return new Boolean(geometry.getType()==type);
201
		}
202

  
203
		public String getName() {
204
			return "GeometryTypeEvaluator";
205
		}
206

  
207
	}
208

  
209

  
210

  
211
	private void openLayer(NewFeatureStoreParameters newParams, String name, MapContext mapContext) throws ReadException {
212
		int res = JOptionPane.showConfirmDialog(
213
				(JComponent) PluginServices.getMDIManager().getActiveWindow()
214
				, PluginServices.getText(this, "insertar_en_la_vista_la_capa_creada"),
215
				PluginServices.getText(this,"insertar_capa"),
216
				JOptionPane.YES_NO_OPTION);
217

  
218
		if (res == JOptionPane.YES_OPTION){
219
			PostProcessSupport.executeCalls();
220
			LayerFactory layerFactory=LayerFactory.getInstance();
221
			try {
222
				FLayer newLayer = layerFactory.getInstance().createLayer(
223
						name,newParams);
224

  
225
				mapContext.getLayers().addLayer(newLayer);
226
			} catch (LoadLayerException e) {
227
				throw new ReadException("Load layer",e);
228
			}
229
		}
230

  
231
	}
232

  
233
	private boolean export(JDBCServerExplorer explorer,
234
			NewFeatureStoreParameters params, FeatureSet set,
235
			FeatureStore featureStore, String pkName) {
236
		DisposableIterator it1 = null;
237
		FeatureStore target = null;
238
		try {
239
			EditableFeatureType fType = featureStore.getDefaultFeatureType()
240
					.getEditable();
241
			if (pkName != null) {
242
				EditableFeatureAttributeDescriptor pk = fType.add(pkName,
243
						DataTypes.LONG);
244
				pk.setIsPrimaryKey(true);
245
				pk.setIsAutomatic(true);
246
			}
247

  
248
			params.setDefaultFeatureType(fType);
249
			explorer.add(params.getDataStoreName(),params, true);
250

  
251
			DataManager manager = DALLocator.getDataManager();
252
			target = (FeatureStore) manager
253
					.createStore(params);
254
			FeatureType targetType = target.getDefaultFeatureType();
255

  
256
			target.edit(FeatureStore.MODE_APPEND);
257
			if (set == null) {
258
				set = featureStore.getFeatureSet();
259
			}
260
			it1 = set.iterator();
261
			while (it1.hasNext()) {
262
				Feature feature = (Feature) it1.next();
263
				target.insert(target.createNewFeature(targetType, feature));
264
			}
265
			target.finishEditing();
266
			return true;
267
		} catch (Exception e) {
268
			NotificationManager.showMessageError(e.getLocalizedMessage(),e);
269
			return false;
270
		} finally {
271
			if (it1 != null) {
272
				it1.dispose();
273
			}
274
			set.dispose();
275
			if (target != null) {
276
				target.dispose();
277
			}
278
		}
279

  
280
	}
281
	/**
282
	 * @see org.gvsig.andami.plugins.IExtension#isEnabled()
283
	 */
284
	public boolean isEnabled() {
285
		org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices
286
				.getMDIManager().getActiveWindow();
287

  
288
		if (f == null) {
289
			return false;
290
		}
291

  
292
		if (!(f instanceof DefaultViewPanel)) {
293
			return false;
294
		}
295

  
296
		FLayers layers = ((DefaultViewPanel) f).getMapControl().getMapContext().getLayers();
297
		FLayer[] actives = layers.getActives();
298
		if (actives.length != 1) {
299
			return false;
300
		}
301
		if (!(actives[0] instanceof FLyrVect)) {
302
			return false;
303
		}
304
		return true;
305

  
306
	}
307

  
308
	/**
309
	 * @see org.gvsig.andami.plugins.IExtension#isVisible()
310
	 */
311
	public boolean isVisible() {
312
		org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
313
				.getActiveWindow();
314

  
315
		if (f == null) {
316
			return false;
317
		}
318

  
319
		if (f instanceof DefaultViewPanel) {
320
			return true;
321
		}
322
		return false;
323
	}
324

  
325
//	private int findFileByName(FieldDescription[] fields, String fieldName){
326
//        for (int i=0; i < fields.length; i++)
327
//        {
328
//        	FieldDescription f = fields[i];
329
//        	if (f.getFieldName().equalsIgnoreCase(fieldName))
330
//        	{
331
//        		return i;
332
//        	}
333
//        }
334
//
335
//		return -1;
336
//
337
//	}
338

  
339
}
0 340

  
tags/v2_0_0_Build_2021/extensions/extGeoDB/src/org/gvsig/geodb/SingleVectorialDBConnectionExtension.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop 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
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package org.gvsig.geodb;
44

  
45
import java.util.ArrayList;
46

  
47
import javax.swing.JOptionPane;
48

  
49
import org.apache.log4j.Logger;
50

  
51
import org.gvsig.about.AboutManager;
52
import org.gvsig.about.AboutParticipant;
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.plugins.Extension;
55
import org.gvsig.app.ApplicationLocator;
56
import org.gvsig.app.ApplicationManager;
57
import org.gvsig.geodb.vectorialdb.ConnectionSettings;
58
import org.gvsig.utils.NotExistInXMLEntity;
59
import org.gvsig.utils.XMLEntity;
60

  
61

  
62

  
63
/**
64
 * This extension allows the user to access the single connection manager dialog
65
 *
66
 * @see org.gvsig.fmap.drivers.formats.db.utils.SingleVectorialDBConnectionManager
67
 *
68
 * @author jldominguez
69
 *
70
 */
71
public class SingleVectorialDBConnectionExtension extends Extension {
72
    private static Logger logger = Logger.getLogger(SingleVectorialDBConnectionExtension.class.getName());
73

  
74
    /**
75
     * This method simply loads the connections stored in gvSIG's persistence file
76
     * as closed connections
77
     */
78
    public void initialize() {
79
        loadPersistenceConnections();
80
        registerIcons();
81
    }
82

  
83
    public void postInitialize() {
84
    	super.postInitialize();
85
    	addAboutInfo();
86
    }
87
    
88
	private void addAboutInfo() {
89
		ApplicationManager application = ApplicationLocator.getManager();
90
		
91
		AboutManager about = application.getAbout();
92
        about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
93
            .getResource("prodevelop.html"), 2);
94

  
95
		AboutParticipant participant = about.getDeveloper("PRODEVELOP");
96
		participant.addContribution(
97
			"GeoDB",
98
			"Soporte para pool de conexiones con BBDD", 
99
			2006,1,1, 
100
			2007,12,31
101
		);   	
102
	}
103
	 
104
    private void registerIcons(){
105
    	PluginServices.getIconTheme().register(
106
    			"conn-image",
107
    			this.getClass().getClassLoader().getResource("images/conn.png")
108
    	);
109
    	PluginServices.getIconTheme().register(
110
    			"disconn-image",
111
    			this.getClass().getClassLoader().getResource("images/disconn.png")
112
    	);
113

  
114
    }
115

  
116
    /**
117
     * The only command available is the one to open the connection manager
118
     * dialog ("GESTOR_JDBC")
119
     */
120
    public void execute(String actionCommand) {
121
//    	FIXME
122
//        if (actionCommand.compareToIgnoreCase("GESTOR_VECTORIALDB") == 0) {
123
//            VectorialDBConnectionManagerDialog dlg = new VectorialDBConnectionManagerDialog();
124
//            dlg.showDialog();
125
////            saveAllToPersistence();
126
//
127
//            return;
128
//        }
129
    }
130

  
131
    public boolean isEnabled() {
132
        return true;
133
    }
134

  
135
    public boolean isVisible() {
136
        return true;
137
    }
138

  
139
    public static void saveAllToPersistence() {
140
        SingleVectorialDBConnectionExtension ext=new SingleVectorialDBConnectionExtension();
141
    	XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML();
142
        xml.putProperty("literalDBName",true);
143
        xml.remove("db-connections");
144

  
145
//        ConnectionWithParams[] all = SingleVectorialDBConnectionManager.instance()
146
//                                                                .getAllConnections();
147
//
148
//        if (all == null) {
149
//        	PluginServices.getPluginServices(ext).setPersistentXML(xml);
150
//            return;
151
//        }
152
//
153
//        for (int i = 0; i < all.length; i++) {
154
//            addToPersistence(all[i],ext);
155
//        }
156
    }
157

  
158
//    private static void addToPersistence(ConnectionWithParams cwp, Extension ext) {
159
//        if (cwp == null) {
160
//            return;
161
//        }
162
//
163
//        ConnectionSettings _cs = new ConnectionSettings();
164
//
165
//        _cs.setHost(cwp.getHost());
166
//        _cs.setPort(cwp.getPort());
167
//        _cs.setDb(cwp.getDb());
168
//        _cs.setDriver(cwp.getDrvName());
169
//        _cs.setUser(cwp.getUser());
170
//        _cs.setName(cwp.getName());
171
//
172
//        String newstr = _cs.toString();
173
//
174
//        XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML();
175
//
176
//        String[] old = null;
177
//
178
//        if (xml.contains("db-connections")) {
179
//            old = xml.getStringArrayProperty("db-connections");
180
//        }
181
//
182
//        ArrayList oldl = stringArrayToArrayList(old);
183
//        oldl.add(newstr);
184
//
185
//        String[] newarr = (String[]) oldl.toArray(new String[0]);
186
//
187
//        xml.remove("db-connections");
188
//        xml.putProperty("db-connections", newarr);
189
//        PluginServices.getPluginServices(ext).setPersistentXML(xml);
190
//    }
191

  
192
    private static ArrayList stringArrayToArrayList(String[] arr) {
193
        ArrayList resp = new ArrayList();
194

  
195
        if ((arr != null) && (arr.length > 0)) {
196
            for (int i = 0; i < arr.length; i++) {
197
                resp.add(arr[i]);
198
            }
199
        }
200

  
201
        return resp;
202
    }
203

  
204
    private void loadPersistenceConnections() {
205
        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
206
        boolean literalDBNames;
207

  
208
        if (!xml.contains("literalDBName")){
209
        	// For back compatibility
210
        	literalDBNames = false;
211
        }else{
212
        	// For back compatibility: Normaly always true
213
        	literalDBNames = xml.getBooleanProperty("literalDBName");
214
        }
215

  
216
        if (xml == null) {
217
            xml = new XMLEntity();
218
        }
219

  
220
        if (!xml.contains("db-connections")) {
221
            String[] servers = new String[0];
222
            xml.putProperty("db-connections", servers);
223
        }
224

  
225
        // add drivers to connection manager
226
        String[] servers = null;
227

  
228
        try {
229
            servers = xml.getStringArrayProperty("db-connections");
230
        }
231
        catch (NotExistInXMLEntity e) {
232
            System.err.println(
233
                "Error while getting projects db-connections: " +
234
                e.getMessage());
235

  
236
            return;
237
        }
238

  
239
        for (int i = 0; i < servers.length; i++) {
240
            ConnectionSettings cs = new ConnectionSettings();
241
            boolean params_ok = true;
242
            try {
243
            	cs.setFromString(servers[i]);
244
            	// For back compatibility
245
            	if (!literalDBNames){
246
            		cs.setDb(cs.getDb().toLowerCase());
247
            	}
248
            } catch (Exception ex) {
249
            	logger.error("Found misconfigured connection: " + servers[i]);
250
            	params_ok = false;
251
            }
252
            if (params_ok) {
253
				addDisconnected(cs);
254
			}
255
        }
256

  
257
        PluginServices ps= PluginServices.getPluginServices("com.iver.cit.gvsig.jdbc_spatial");
258
        if (ps==null) {
259
			return;
260
		}
261
        XMLEntity xmlJDBC =ps.getPersistentXML();
262

  
263
        if (xmlJDBC==null || !xmlJDBC.contains("jdbc-connections")) {
264
			return;
265
		}
266

  
267
//      add drivers to connection manager
268
        String[] serversOld = null;
269

  
270
        try {
271
            serversOld = xmlJDBC.getStringArrayProperty("jdbc-connections");
272
        }
273
        catch (NotExistInXMLEntity e) {
274
            System.err.println(
275
                "Error while getting projects jdbc-connections: " +
276
                e.getMessage());
277

  
278
            return;
279
        }
280

  
281
        for (int i = 0; i < serversOld.length; i++) {
282
            ConnectionSettings cs = new ConnectionSettings();
283
            boolean params_ok = true;
284
            try {
285
            	cs.setFromString(serversOld[i]);
286
            	cs.setDb(cs.getDb().toLowerCase());
287
            } catch (Exception ex) {
288
            	logger.error("Found misconfigured connection: " + serversOld[i]);
289
            	params_ok = false;
290
            }
291
            if (params_ok) {
292
				addDisconnected(cs);
293
			}
294
        }
295

  
296

  
297
    }
298

  
299
    private void addDisconnected(ConnectionSettings _cs) {
300
//        try {
301
//            SingleVectorialDBConnectionManager.instance()
302
//                                       .getConnection(_cs.getDriver(),
303
//                _cs.getUser(), null, _cs.getName(), _cs.getHost(),
304
//                _cs.getPort(), _cs.getDb(), false);
305
//        }
306
//        catch (DBException e) {
307
//            System.err.println("While getting connection: " + e.getMessage());
308
//            showConnectionErrorMessage(e.getMessage());
309
//        }
310
    }
311

  
312
    private void showConnectionErrorMessage(String _msg) {
313
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
314
        String title = PluginServices.getText(this, "connection_error");
315
        JOptionPane.showMessageDialog(null, title + msg, title,
316
            JOptionPane.ERROR_MESSAGE);
317
    }
318

  
319
    public void terminate() {
320
    	saveAllToPersistence();
321
//        SingleVectorialDBConnectionManager.instance().closeAllBeforeTerminate();
322
    }
323
}
0 324

  
tags/v2_0_0_Build_2021/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/ConnectionPanel.java
1
package org.gvsig.geodb.vectorialdb;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
5
import java.awt.FlowLayout;
6
import java.awt.Rectangle;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.util.HashMap;
10
import java.util.Iterator;
11

  
12
import javax.swing.DefaultComboBoxModel;
13
import javax.swing.JLabel;
14
import javax.swing.JPanel;
15
import javax.swing.JPasswordField;
16
import javax.swing.JTextField;
17
import javax.swing.SwingConstants;
18

  
19
import org.gvsig.andami.PluginServices;
20
import org.gvsig.fmap.dal.DALLocator;
21
import org.gvsig.fmap.dal.DataManager;
22
import org.gvsig.fmap.dal.exception.InitializeException;
23
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
24
import org.gvsig.fmap.dal.resource.db.DBParameters;
25
import org.gvsig.utils.NotExistInXMLEntity;
26
import org.gvsig.utils.XMLEntity;
27
import org.gvsig.utils.swing.JComboBox;
28
import org.gvsig.utils.swing.wizard.Step;
29
import org.gvsig.utils.swing.wizard.WizardControl;
30

  
31

  
32

  
33
/**
34
 * DOCUMENT ME!
35
 *
36
 * @author Fernando Gonz?lez Cort?s
37
 */
38
public class ConnectionPanel extends JPanel implements Step {
39
    private static String passw = null;
40

  
41
    private JPanel jPanelLabels = null;
42
    private JLabel jLabel = null;
43
    private JTextField txtHost = null;
44
    private JPanel jPanelTexts = null;
45
    private JTextField txtPort = null;
46
    private JLabel jLabel1 = null;
47
    private JLabel jLabel2 = null;
48
    private JTextField txtUser = null;
49
    private JLabel jLabel3 = null;
50
    private JPasswordField txtPassword = null;
51
    private JLabel jLabel4 = null;
52
    private JTextField txtBD = null;
53
    private JLabel jLabel5 = null;
54
    private JComboBox cmbDriver = null;
55
    private JLabel jLabel6 = null;
56
    private org.gvsig.utils.swing.JComboBox cmbName = null;
57
    private HashMap cs = new HashMap();
58

  
59
    private JPanel jPanel = null;
60

  
61
	private JLabel jLabelSchema = null;
62

  
63
	private ConnectionPanel XYZ = null;
64

  
65
	private JPanel jPanel1 = null;
66

  
67
	private JPanel jPanelLabels1 = null;
68

  
69
	private JLabel jLabel61 = null;
70

  
71
	private JLabel jLabel7 = null;
72

  
73
	private JLabel jLabel11 = null;
74

  
75
	private JLabel jLabel21 = null;
76

  
77
	private JLabel jLabel31 = null;
78

  
79
	private JLabel jLabel51 = null;
80

  
81
	private JPanel jPanelTexts1 = null;
82

  
83
	private JComboBox cmbName1 = null;
84

  
85
	private JTextField txtHost1 = null;
86

  
87
	private JTextField txtPort1 = null;
88

  
89
	private JTextField txtUser1 = null;
90

  
91
	private JPasswordField txtPassword1 = null;
92

  
93
	private JTextField txtBD1 = null;
94

  
95
	private JComboBox cmbDriver1 = null;
96

  
97
	private JTextField txtSchema = null;
98

  
99

  
100

  
101
    /**
102
     * This is the default constructor
103
     */
104
    public ConnectionPanel() {
105
        super();
106
        initialize();
107
    }
108

  
109
    /**
110
     * This method initializes this
111
     */
112
    private void initialize() {
113
        this.setLayout(null);
114
        this.setSize(335, 240);
115
        this.add(getJPanel(), null);
116

  
117
        if (passw != null) {
118
			txtPassword.setText(passw);
119
		}
120

  
121
    }
122

  
123
    /**
124
     * This method initializes jPanel
125
     *
126
     * @return javax.swing.JPanel
127
     */
128
    private JPanel getJPanelLabels() {
129
        if (jPanelLabels == null) {
130
            String string = PluginServices.getText(this, "schema") + ":";
131
            jLabelSchema = new JLabel();
132
            jLabelSchema.setName("jLabel4");
133
            jLabelSchema.setHorizontalAlignment(SwingConstants.RIGHT);
134
            jLabelSchema.setHorizontalTextPosition(SwingConstants.RIGHT);
135
            jLabelSchema.setText(string);
136
            jLabelSchema.setPreferredSize(new Dimension(140, 19));
137
            FlowLayout flowLayout3 = new FlowLayout();
138
            flowLayout3.setVgap(15);
139
            jLabel5 = new JLabel();
140
            jLabel4 = new JLabel();
141
            jLabel3 = new JLabel();
142
            jLabel2 = new JLabel();
143
            jLabel1 = new JLabel();
144
            jLabel = new JLabel();
145
            jPanelLabels = new JPanel();
146
            jPanelLabels.setLayout(flowLayout3);
147
            jPanelLabels.setName("jPanelLabels");
148
            jPanelLabels.setPreferredSize(new java.awt.Dimension(150,400));
149
            jLabel.setText(PluginServices.getText(this, "host") + ":");
150
            jLabel.setPreferredSize(new java.awt.Dimension(140,19));
151
            jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
152
            jLabel.setName("jLabel");
153
            jLabel1.setText(PluginServices.getText(this, "puerto")+":");
154
            jLabel1.setPreferredSize(new java.awt.Dimension(140,19));
155
            jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
156
            jLabel1.setName("jLabel1");
157
            jLabel2.setText(PluginServices.getText(this, "usuario")+":");
158
            jLabel2.setName("jLabel2");
159
            jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
160
            jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
161
            jLabel2.setPreferredSize(new java.awt.Dimension(140,19));
162
            jLabel3.setText(PluginServices.getText(this, "password")+":");
163
            jLabel3.setName("jLabel3");
164
            jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
165
            jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
166
            jLabel3.setPreferredSize(new java.awt.Dimension(140,19));
167
            jLabel4.setText(PluginServices.getText(this, "bd")+":");
168
            jLabel4.setName("jLabel4");
169
            jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
170
            jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
171
            jLabel4.setPreferredSize(new java.awt.Dimension(140,19));
172
            jLabel5.setText(PluginServices.getText(this, "driver")+":");
173
            jLabel5.setName("jLabel5");
174
            jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
175
            jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
176
            jLabel5.setPreferredSize(new java.awt.Dimension(140,19));
177
            jPanelLabels.add(getJLabel6(), null);
178
            jPanelLabels.add(jLabel, null);
179
            jPanelLabels.add(jLabel1, null);
180
            jPanelLabels.add(jLabel2, null);
181
            jPanelLabels.add(jLabel3, null);
182
            jPanelLabels.add(jLabel4, null);
183
            jPanelLabels.add(jLabelSchema, null);
184
            jPanelLabels.add(jLabel5, null);
185

  
186
        }
187

  
188
        return jPanelLabels;
189
    }
190

  
191
    /**
192
     * This method initializes txtHost
193
     *
194
     * @return javax.swing.JTextField
195
     */
196
    private JTextField getTxtHost() {
197
        if (txtHost == null) {
198
            txtHost = new JTextField();
199
            txtHost.setPreferredSize(new java.awt.Dimension(170, 19));
200
            txtHost.setName("txtHost");
201
        }
202

  
203
        return txtHost;
204
    }
205

  
206
    /**
207
     * This method initializes jPanel1
208
     *
209
     * @return javax.swing.JPanel
210
     */
211
    private JPanel getJPanelTexts() {
212
        if (jPanelTexts == null) {
213
            FlowLayout flowLayout2 = new FlowLayout(FlowLayout.LEFT);
214
            flowLayout2.setVgap(15);
215
            jPanelTexts = new JPanel();
216
            jPanelTexts.setLayout(flowLayout2);
217
            jPanelTexts.setPreferredSize(new Dimension(200, 300));
218

  
219
            jPanelTexts.setName("jPanelText");
220
            jPanelTexts.add(getCmbName(), null);
221
            jPanelTexts.add(getTxtHost(), null);
222
            jPanelTexts.add(getTxtPort(), null);
223
            jPanelTexts.add(getTxtUser(), null);
224
            jPanelTexts.add(getTxtPassword(), null);
225
            jPanelTexts.add(getTxtBD(), null);
226
            jPanelTexts.add(getTxtSchema(), null);
227
            jPanelTexts.add(getCmbDriver(), null);
228
        }
229

  
230
        return jPanelTexts;
231
    }
232

  
233
    /**
234
     * This method initializes txtPort
235
     *
236
     * @return javax.swing.JTextField
237
     */
238
    private JTextField getTxtPort() {
239
        if (txtPort == null) {
240
            txtPort = new JTextField();
241
            txtPort.setPreferredSize(new java.awt.Dimension(40, 19));
242
            txtPort.setName("txtPort");
243
            txtPort.setText("");
244
            txtPort.setHorizontalAlignment(javax.swing.JTextField.LEFT);
245
        }
246

  
247
        return txtPort;
248
    }
249

  
250
    /**
251
     * This method initializes txtUser
252
     *
253
     * @return javax.swing.JTextField
254
     */
255
    private JTextField getTxtUser() {
256
        if (txtUser == null) {
257
            txtUser = new JTextField();
258
            txtUser.setPreferredSize(new java.awt.Dimension(170, 19));
259
            txtUser.setName("txtUser");
260
        }
261

  
262
        return txtUser;
263
    }
264

  
265
    /**
266
     * This method initializes txtPassword
267
     *
268
     * @return javax.swing.JTextField
269
     */
270
    private JPasswordField getTxtPassword() {
271
        if (txtPassword == null) {
272
            txtPassword = new JPasswordField();
273
            txtPassword.setPreferredSize(new java.awt.Dimension(170, 19));
274
            txtPassword.setName("txtPassword");
275
        }
276

  
277
        return txtPassword;
278
    }
279

  
280
    /**
281
     * This method initializes txtBD
282
     *
283
     * @return javax.swing.JTextField
284
     */
285
    private JTextField getTxtBD() {
286
        if (txtBD == null) {
287
            txtBD = new JTextField();
288
            txtBD.setPreferredSize(new java.awt.Dimension(170, 19));
289
            txtBD.setName("txtBD");
290
        }
291

  
292
        return txtBD;
293
    }
294

  
295
    /**
296
     * DOCUMENT ME!
297
     *
298
     * @return DOCUMENT ME!
299
     */
300
    public String getHost() {
301
        return getTxtHost().getText();
302
    }
303

  
304
    /**
305
     * DOCUMENT ME!
306
     *
307
     * @return DOCUMENT ME!
308
     */
309
    public String getPort() {
310
        return getTxtPort().getText();
311
    }
312

  
313
    /**
314
     * DOCUMENT ME!
315
     *
316
     * @return DOCUMENT ME!
317
     */
318
    public String getUser() {
319
        return getTxtUser().getText();
320
    }
321

  
322
    /**
323
     * DOCUMENT ME!
324
     *
325
     * @return DOCUMENT ME!
326
     */
327
    public String getSettingsName() {
328
        return getCmbName().getSelectedItem().toString();
329
    }
330

  
331
    /**
332
     * DOCUMENT ME!
333
     *
334
     * @return DOCUMENT ME!
335
     */
336
    public String getPassword() {
337
        passw = String.copyValueOf(getTxtPassword().getPassword());
338
        return passw;
339
    }
340

  
341
    /**
342
     * DOCUMENT ME!
343
     *
344
     * @return DOCUMENT ME!
345
     */
346
    public String getDBName() {
347
        return getTxtBD().getText();
348
    }
349

  
350
    /**
351
     * DOCUMENT ME!
352
     *
353
     * @param drivers DOCUMENT ME!
354
     */
355
    public void setDrivers(String[] drivers) {
356
        DefaultComboBoxModel model = new DefaultComboBoxModel();
357

  
358
        for (int i = 0; i < drivers.length; i++) {
359
            model.addElement(drivers[i]);
360
        }
361

  
362
        getCmbDriver().setModel(model);
363

  
364
        //Para que refresque el textbox del puerto
365
        if (drivers.length > 0) {
366
			cmbDriver.setSelectedIndex(0);
367
		}
368

  
369
    }
370

  
371

  
372
    /**
373
     * @return ConnectionSettings based on values in this panel
374
     */
375
    public ConnectionSettings getConnectionSettings()
376
    {
377
        ConnectionSettings cs = new ConnectionSettings();
378
        cs.setDb(getDBName());
379
        cs.setSchema(getSchema());
380
        cs.setDriver(getDriver());
381
        cs.setHost(getHost());
382
        cs.setPort(getPort());
383
        cs.setUser(getUser());
384
        cs.setPassw(getPassword());
385
        cs.setName(getSettingsName());
386
        return cs;
387
    }
388

  
389
    public String getSchema() {
390
		return txtSchema.getText();
391
	}
392

  
393
    /**
394
     * Makes persistent the connection settings of this panel.
395
     */
396
    public void saveConnectionSettings()
397
    {
398
    	ConnectionSettings cs = new ConnectionSettings();
399
        cs.setDb(getDBName());
400
        cs.setSchema(getSchema());
401
        cs.setDriver(getDriver());
402
        cs.setHost(getHost());
403
        cs.setPort(getPort());
404
        cs.setUser(getUser());
405
        cs.setPassw(getPassword());
406
        cs.setName(getSettingsName());
407

  
408
        PluginServices ps = PluginServices.getPluginServices(this);
409
        XMLEntity xml = ps.getPersistentXML();
410

  
411
        try {
412
            String[] connections = xml.getStringArrayProperty("jdbc-connections");
413
            String[] newConnections = new String[connections.length + 1];
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff