Revision 39645

View differences:

tags/v2_0_0_Build_2063/extensions/extGeoDB/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Fri Jan 25 13:04:41 CET 2013
3
buildNumber=2075
tags/v2_0_0_Build_2063/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_2063/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
    <depends plugin-name="org.gvsig.app.document.table.app.mainplugin" />
6
	<resourceBundle name="text"/>
7
	<extensions>
8
		<extension class-name="org.gvsig.geodb.ExtDB_Spatial"
9
			description="Support to access Spatial databases"
10
			active="true">
11
		</extension>		
12
	</extensions>
13
</plugin-config>
0 14

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/config/plugin-persistence.def
1
<?xml version="1.0"?>
2
<!--
3
Definitions of plugin persistence org.gvsig.geodb.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    <class name="org.gvsig.geodb">
9
      <description>plugin persistence org.gvsig.geodb</description>
10
      <fields>
11
        <field name="db_connections" type="map" classOfItems="org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters" mandatory="false">
12
          <description>Connections</description>
13
        </field>
14
      </fields>
15
    </class>
16
  </classes>
17
</definitions>  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/ConnectionSettings.java
1
package org.gvsig.geodb.vectorialdb;
2

  
3
import org.gvsig.fmap.dal.DALLocator;
4
import org.gvsig.fmap.dal.DataManager;
5
import org.gvsig.fmap.dal.exception.InitializeException;
6
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
7
import org.gvsig.fmap.dal.resource.db.DBParameters;
8

  
9

  
10
/**
11
 * @author Fernando Gonz?lez Cort?s
12
 */
13
public class ConnectionSettings {
14
    private String host;
15
    private String port;
16
    private String db;
17
    private String schema;
18
    private String driver;
19
    private String user;
20
    private String name;
21
    private String passw;
22

  
23
    public String getDb() {
24
        return db;
25
    }
26
    public void setDb(String db) {
27
        this.db = db;
28
    }
29
    public String getDriver() {
30
        return driver;
31
    }
32
    public void setDriver(String driver) {
33
        this.driver = driver;
34
    }
35
    public String getHost() {
36
        return host;
37
    }
38
    public void setHost(String host) {
39
        this.host = host;
40
    }
41
    public String getPort() {
42
        return port;
43
    }
44
    public void setPort(String port) {
45
        this.port = port;
46
    }
47
    public String getUser() {
48
        return user;
49
    }
50
    public void setUser(String user) {
51
        this.user = user;
52
    }
53
    public void setName(String name) {
54
        this.name = name;
55
    }
56
    public String getName() {
57
        return name;
58
    }
59

  
60
    public String toString(){
61
        return host+","+port+","+db+","+driver+","+user+","+name;
62
    }
63

  
64
    public void setFromString(String str) {
65
        String[] values = str.split(",");
66
        host = values[0];
67
        port = values[1];
68
        db = values[2];
69
        driver = values[3];
70
        user = values[4];
71
        name = values[5];
72
        if (values.length == 7) {
73
			passw = values[6];
74
		}
75
    }
76
    public String getPassw() {
77
        return passw;
78
    }
79
    public void setPassw(String passw) {
80
        this.passw = passw;
81
    }
82
    public String getConnectionString(){
83
    	DataManager dm=DALLocator.getDataManager();
84
    	try {
85
			DBParameters dsp=(DBParameters)dm.createStoreParameters(getDriver());
86
		} catch (InitializeException e) {
87
			// TODO Auto-generated catch block
88
			e.printStackTrace();
89
		} catch (ProviderNotRegisteredException e) {
90
			// TODO Auto-generated catch block
91
			e.printStackTrace();
92
		}
93

  
94
        String connectionString = "";//vecDriver.getConnectionStringBeginning() + "//" + getHost();
95

  
96
        connectionString += (":" + getPort());
97

  
98
        connectionString += ("/" + getDb());
99

  
100
        return connectionString;
101
    }
102
	public String getSchema() {
103
		return schema;
104
	}
105
	public void setSchema(String schema) {
106
		this.schema = schema;
107
	}
108
}
0 109

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/FieldsListItem.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.vectorialdb.wizard;
44

  
45
import javax.swing.JCheckBox;
46

  
47
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
48

  
49

  
50
/**
51
 * Used to instantiate field list items. Shows the database dependent type name.
52
 *
53
 * @author jldominguez
54
 *
55
 */
56
public class FieldsListItem extends JCheckBox {
57
    private String name = "[No name]";
58
    private String type = "[No type]";
59

  
60
    public FieldsListItem(FeatureAttributeDescriptor descriptor) {
61

  
62
    	name = descriptor.getName();
63
        type = descriptor.getDataTypeName();
64
        setText(toString());
65
        setSelected(true);
66
    }
67

  
68
    public String toString() {
69
        return name + " [" + type + "]";
70
    }
71

  
72
    public String getName() {
73
        return name;
74
    }
75
}
0 76

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/FieldComboItem.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.vectorialdb.wizard;
44

  
45
import org.cresques.cts.IProjection;
46

  
47

  
48
/**
49
 * Utility class to deal with combo boxes.
50
 * Optionally stores the IProjection of the data in the
51
 * field (if it's a geometry field)
52
 *
53
 * @author jldominguez
54
 *
55
 */
56
public class FieldComboItem {
57
    
58
    private String name = "";
59
    private IProjection proj = null;
60

  
61
    public FieldComboItem(String _name) {
62
        name = _name;
63
    }
64

  
65
    public FieldComboItem(String _name, IProjection _proj) {
66
        name = _name;
67
        proj = _proj;
68
    }
69

  
70
    public String toString() {
71
        return name;
72
    }
73
    
74
    public IProjection getProjection() {
75
        return proj;
76
    }
77
}
0 78

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/VectorialDBConnectionParamsDialog.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.vectorialdb.wizard;
44

  
45
import java.awt.Color;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import java.awt.event.KeyEvent;
49
import java.awt.event.KeyListener;
50
import java.util.Iterator;
51
import java.util.List;
52

  
53
import javax.swing.JButton;
54
import javax.swing.JCheckBox;
55
import javax.swing.JComboBox;
56
import javax.swing.JLabel;
57
import javax.swing.JOptionPane;
58
import javax.swing.JPanel;
59
import javax.swing.JPasswordField;
60
import javax.swing.JTextField;
61

  
62
import org.slf4j.Logger;
63
import org.slf4j.LoggerFactory;
64

  
65
import org.gvsig.andami.PluginServices;
66
import org.gvsig.andami.messages.NotificationManager;
67
import org.gvsig.andami.ui.mdiManager.IWindow;
68
import org.gvsig.andami.ui.mdiManager.WindowInfo;
69
import org.gvsig.fmap.dal.DALLocator;
70
import org.gvsig.fmap.dal.DataManager;
71
import org.gvsig.fmap.dal.DataServerExplorerParameters;
72
import org.gvsig.fmap.dal.exception.DataException;
73
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
74
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
75
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
76
import org.gvsig.gui.beans.Messages;
77
import org.gvsig.tools.service.ServiceException;
78

  
79

  
80

  
81
/**
82
 * Lets the user input the connection parameters.
83
 *
84
 * @author jldominguez
85
 *
86
 */
87
public class VectorialDBConnectionParamsDialog extends JPanel implements IWindow,
88
    ActionListener, KeyListener {
89

  
90
    private static final long serialVersionUID = -5493563028200403559L;
91

  
92
    private static final Logger LOG = LoggerFactory
93
        .getLogger(VectorialDBConnectionParamsDialog.class);
94

  
95
    private WindowInfo winfo = new WindowInfo(8); // MODAL only
96
    private JButton cancelButton = null;
97
    private JButton okButton = null;
98
    private JButton advancedButton = null;
99
    private JPanel paramsPanel = null;
100
    private JComboBox driverComboBox = null;
101
    private JTextField portTextField = null;
102
    private JTextField dbTextField = null;
103
    private JTextField userTextField = null;
104
    private JPasswordField passwordField = null;
105
    private JLabel driverLabel = null;
106
    private JLabel portLabel = null;
107
    private JLabel dbLabel = null;
108
    private JLabel dbLabelWarning = null;
109
    private JLabel userLabel = null;
110
    private JLabel pwLabel = null;
111
    private boolean okPressed = false;
112
    private JTextField urlTextField = null;
113
    private JLabel urlLabel = null;
114
    private JCheckBox connectedCheckBox = null;
115
    private JLabel connectedLabel = null;
116
    private JLabel connNameLabel = null;
117
    private JTextField connNameTextField = null;
118

  
119
    private DBServerExplorerParameters params = null;
120

  
121
    /**
122
     * This method initializes
123
     *
124
     */
125
    public VectorialDBConnectionParamsDialog() {
126
        super();
127
        initialize();
128
    }
129

  
130
    public void showDialog() {
131
        PluginServices.getMDIManager().addWindow(this);
132
    }
133

  
134
    /**
135
     * This method initializes this
136
     *
137
     */
138
    private void initialize() {
139
        winfo.setWidth(370);
140
        winfo.setHeight(317 - 25);
141
        winfo.setTitle(PluginServices.getText(this, "_Connection_parameters"));
142

  
143
        this.setSize(new java.awt.Dimension(360, 329));
144
        this.setLayout(null);
145
        this.add(getCancelButton(), null);
146
        this.add(getOkButton(), null);
147
        this.add(getAdvancedButton(), null);
148
        this.add(getParamsPanel(), null);
149
    }
150

  
151
    public WindowInfo getWindowInfo() {
152
        return winfo;
153
    }
154

  
155
    /**
156
     * This method initializes cancelButton
157
     *
158
     * @return javax.swing.JButton
159
     */
160
    private JButton getCancelButton() {
161
        if (cancelButton == null) {
162
            cancelButton = new JButton();
163
            cancelButton.setText(PluginServices.getText(this, "cancel"));
164
            cancelButton.addActionListener(this);
165
            cancelButton.setBounds(new java.awt.Rectangle(124, 292, 90, 26));
166
        }
167

  
168
        return cancelButton;
169
    }
170

  
171
    /**
172
     * This method initializes okButton
173
     *
174
     * @return javax.swing.JButton
175
     */
176
    private JButton getOkButton() {
177
        if (okButton == null) {
178
            okButton = new JButton();
179
            okButton.setText(PluginServices.getText(this, "ok"));
180
            okButton.addActionListener(this);
181
            okButton.setBounds(new java.awt.Rectangle(30, 292, 90, 26));
182
        }
183

  
184
        return okButton;
185
    }
186

  
187
	/**
188
	 * This method initializes okButton
189
	 *
190
	 * @return javax.swing.JButton
191
	 */
192
	private JButton getAdvancedButton() {
193
		if (advancedButton == null) {
194
			advancedButton = new JButton();
195
			advancedButton.setText(PluginServices.getText(this, "advanced"));
196
			advancedButton.addActionListener(this);
197
			advancedButton.setBounds(new java.awt.Rectangle(218, 292, 90, 26));
198
		}
199

  
200
		return advancedButton;
201
	}
202

  
203
	/**
204
	 * This method initializes paramsPanel
205
	 *
206
	 * @return javax.swing.JPanel
207
	 */
208
    private JPanel getParamsPanel() {
209
        if (paramsPanel == null) {
210
            connNameLabel = new JLabel();
211
            connNameLabel.setBounds(new java.awt.Rectangle(10, 30, 141, 21));
212
            connNameLabel.setText(PluginServices.getText(this, "_Connection_name") +
213
                ":");
214
            connectedLabel = new JLabel();
215
            connectedLabel.setBounds(new java.awt.Rectangle(10, 247, 141, 21));
216
            connectedLabel.setText(PluginServices.getText(this, "_Connected") +
217
                ":");
218
            urlLabel = new JLabel();
219
            urlLabel.setBounds(new java.awt.Rectangle(10, 80, 141, 21));
220
            urlLabel.setText(PluginServices.getText(this, "_Host") + ":");
221
            pwLabel = new JLabel();
222
            pwLabel.setBounds(new java.awt.Rectangle(10, 222, 141, 21));
223
            pwLabel.setText(PluginServices.getText(this, "_Password") + ":");
224
            userLabel = new JLabel();
225
            userLabel.setBounds(new java.awt.Rectangle(10, 197, 141, 21));
226
            userLabel.setText(PluginServices.getText(this, "_User") + ":");
227
            dbLabel = new JLabel();
228
            dbLabel.setBounds(new java.awt.Rectangle(10, 130, 141, 21));
229
            dbLabel.setText(PluginServices.getText(this, "_Database") +
230
                ":");
231
            dbLabelWarning = new JLabel();
232
            dbLabelWarning.setBounds(new java.awt.Rectangle(10, 155, 310, 41));
233
            dbLabelWarning.setText(PluginServices.getText(this, "warning_you_must_input_the_exact_name_this_difference_between_capital_letters_and_small_letters")
234
                );
235

  
236
            portLabel = new JLabel();
237
            portLabel.setBounds(new java.awt.Rectangle(10, 105, 141, 21));
238
            portLabel.setText(PluginServices.getText(this, "_Port") + ":");
239
            driverLabel = new JLabel();
240
            driverLabel.setBounds(new java.awt.Rectangle(10, 55, 141, 21));
241
            driverLabel.setText(PluginServices.getText(this, "_Driver_type") + ":");
242
            paramsPanel = new JPanel();
243
            paramsPanel.setBounds(new java.awt.Rectangle(10, 10, 336, 273));
244
            paramsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
245
                    null, PluginServices.getText(this, "_Connection_parameters"),
246
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
247
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
248
            paramsPanel.setLayout(null);
249
            paramsPanel.add(getPortTextField(), null);
250
            paramsPanel.add(getDriverComboBox(), null);
251
            paramsPanel.add(getDbTextField(), null);
252
            paramsPanel.add(getUserTextField(), null);
253
            paramsPanel.add(getPasswordField(), null);
254
            paramsPanel.add(driverLabel, null);
255
            paramsPanel.add(portLabel, null);
256
            paramsPanel.add(dbLabel, null);
257
            paramsPanel.add(dbLabelWarning, null);
258
            paramsPanel.add(userLabel, null);
259
            paramsPanel.add(pwLabel, null);
260
            paramsPanel.add(getUrlTextArea(), null);
261
            paramsPanel.add(urlLabel, null);
262
            paramsPanel.add(getConnectedCheckBox(), null);
263
            paramsPanel.add(connectedLabel, null);
264
            paramsPanel.add(connNameLabel, null);
265
            paramsPanel.add(getConnNameTextField(), null);
266
        }
267

  
268
        return paramsPanel;
269
    }
270

  
271
    /**
272
     * This method initializes driverComboBox
273
     *
274
     * @return javax.swing.JComboBox
275
     */
276
    private JComboBox getDriverComboBox() {
277
        if (driverComboBox == null) {
278
            driverComboBox = new JComboBox();
279
            driverComboBox.addActionListener(this);
280
            DataManager dm = DALLocator.getDataManager();
281
            List<String> explorers = dm.getExplorerProviders();
282
            Iterator<String> iter = explorers.iterator();
283
            String expName;
284

  
285
            DataServerExplorerParameters params;
286
            while (iter.hasNext()) {
287
            	expName = iter.next();
288
				try {
289
					params = dm.createServerExplorerParameters(expName);
290
				} catch (DataException e) {
291
					NotificationManager.addWarning(PluginServices.getText(null,
292
							"DataExplorer_parameters_error")
293
							+ ": " + expName, e);
294
					continue;
295
				}
296
				if (params instanceof DBServerExplorerParameters) {
297
					DBServerExplorerParameters dbParams = (DBServerExplorerParameters) params;
298
					driverComboBox.addItem(new DriverComboBoxItem(
299
							dbParams));
300
				}
301

  
302
            }
303

  
304
            driverComboBox.setBounds(new java.awt.Rectangle(155, 55, 166, 21));
305

  
306
        }
307

  
308
        return driverComboBox;
309
    }
310

  
311
    private class DriverComboBoxItem {
312
    	private DBServerExplorerParameters params;
313

  
314
    	public DriverComboBoxItem(DBServerExplorerParameters dbParams) {
315
			this.params = dbParams;
316
		}
317

  
318
		public String toString() {
319
			// FIXME
320
    		return params.getExplorerName();
321
    	}
322
    }
323

  
324
    /**
325
     * This method initializes portTextField
326
     *
327
     * @return javax.swing.JTextField
328
     */
329
    private JTextField getPortTextField() {
330
        if (portTextField == null) {
331
            portTextField = new JTextField();
332
            portTextField.addKeyListener(this);
333
            portTextField.setBounds(new java.awt.Rectangle(155, 105, 166, 21));
334
        }
335

  
336
        return portTextField;
337
    }
338

  
339
    /**
340
     * This method initializes dbTextField
341
     *
342
     * @return javax.swing.JTextField
343
     */
344
    private JTextField getDbTextField() {
345
        if (dbTextField == null) {
346
            dbTextField = new JTextField();
347
            dbTextField.addKeyListener(this);
348
            dbTextField.setBounds(new java.awt.Rectangle(155, 130, 166, 21));
349
        }
350

  
351
        return dbTextField;
352
    }
353

  
354
    /**
355
     * This method initializes userTextField
356
     *
357
     * @return javax.swing.JTextField
358
     */
359
    private JTextField getUserTextField() {
360
        if (userTextField == null) {
361
            userTextField = new JTextField();
362
            userTextField.addKeyListener(this);
363
            userTextField.setBounds(new java.awt.Rectangle(155, 197, 166, 21));
364
        }
365

  
366
        return userTextField;
367
    }
368

  
369
    /**
370
     * This method initializes passwordField
371
     *
372
     * @return javax.swing.JPasswordField
373
     */
374
    private JPasswordField getPasswordField() {
375
        if (passwordField == null) {
376
            passwordField = new JPasswordField();
377
            passwordField.addKeyListener(this);
378
            passwordField.setBounds(new java.awt.Rectangle(155, 222, 166, 21));
379
        }
380

  
381
        return passwordField;
382
    }
383

  
384
//    private String[] getDriverNames() {
385
//        Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
386
//
387
//        ArrayList ret = new ArrayList();
388
//        String[] driverNames = LayerFactory.getDM().getDriverNames();
389
//
390
//        for (int i = 0; i < driverNames.length; i++) {
391
//            for (int j = 0; j < classes.length; j++) {
392
//                if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
393
//                    ret.add(driverNames[i]);
394
//                }
395
//            }
396
//        }
397
//
398
//        return (String[]) ret.toArray(new String[0]);
399
//    }
400

  
401
    public void actionPerformed(ActionEvent arg0) {
402
        Object src = arg0.getSource();
403

  
404
        if (src == connectedCheckBox) {
405
            if (connectedCheckBox.isSelected()) {
406
                passwordField.setEnabled(true);
407
                passwordField.setBackground(Color.WHITE);
408
            }
409
            else {
410
                passwordField.setText("");
411
                passwordField.setEnabled(false);
412
                passwordField.setBackground(Color.LIGHT_GRAY);
413
            }
414
        }
415

  
416
        if (src == okButton) {
417
            DBServerExplorerParameters myParams = getParameters();
418
            try {
419
                myParams.validate();
420

  
421
                okPressed = true;
422
                PluginServices.getMDIManager().closeWindow(this);
423
            } catch (Exception e) {
424
                // There are errors in the parameters, maybe more required ones.
425
                // Warn the user and open the advanced parameters panel
426
                JOptionPane
427
                    .showMessageDialog(this, Messages
428
                        .getText("more_provider_parameters_needed_message"),
429
                        Messages
430
                            .getText("more_provider_parameters_needed_title"),
431
                        JOptionPane.WARNING_MESSAGE);
432
                showAdvancedParametersPanel();
433
            }
434

  
435
            return;
436
        }
437

  
438
        if (src == cancelButton) {
439
            okPressed = false;
440
            PluginServices.getMDIManager().closeWindow(this);
441

  
442
            return;
443
        }
444

  
445
        if (src == advancedButton) {
446
            showAdvancedParametersPanel();
447

  
448
			return;
449
		}
450

  
451
        if (src == driverComboBox) {
452
        	DBServerExplorerParameters params = ((DriverComboBoxItem) driverComboBox
453
					.getSelectedItem()).params;
454
        		try {
455
				params.validate();
456
			} catch (ValidateDataParametersException e) {
457
			}
458

  
459
//            try {
460
//            	DataManager dm=DataManager.getManager();
461
//                featureStore = (FeatureStore) dm.createDataStore()LayerFactory.getDM()
462
//                                                           .getDriver(driverName);
463
			if (params.getPort() != null) {
464
				portTextField.setText(params.getPort() + "");
465
			} else {
466
				portTextField.setText("");
467
			}
468
//            }
469
//            catch (DriverLoadException e1) {
470
//                portTextField.setText("");
471
//            }
472

  
473
            return;
474
        }
475
    }
476

  
477
    /**
478
     * @param myParams
479
     */
480
    private void showAdvancedParametersPanel() {
481
        DBServerExplorerParameters myParams = getParameters();
482
        try {
483
            myParams.validate();
484
        } catch (Exception e) {
485
            // ignore... only for fill default values
486
        }
487
        try {
488
            DynObjectEditor editor = new DynObjectEditor(myParams);
489
            editor.editObject(true);
490
            refreshFormParameters();
491
        } catch (ServiceException ex) {
492
            LOG.error("Error creating a Swing component for the DynObject: "
493
                + myParams, ex);
494
        }
495
    }
496

  
497
    private void refreshFormParameters() {
498
        DBServerExplorerParameters myParams = internalGetParameters();
499
        getDbTextField().setText(myParams.getDBName());
500
        getPasswordField().setText(myParams.getPassword());
501
        Integer port = myParams.getPort();
502
        getPortTextField().setText(port == null ? "" : port.toString());
503
        getUrlTextArea().setText(myParams.getHost());
504
        getUserTextField().setText(myParams.getUser());
505
        this.updateUI();
506
    }
507

  
508
    public boolean isOkPressed() {
509
        return okPressed;
510
    }
511

  
512
    public boolean hasToBeConnected() {
513
        return connectedCheckBox.isSelected();
514
    }
515

  
516
    public String getConnectionDriverName() {
517
        return ((DriverComboBoxItem) driverComboBox.getSelectedItem()).params
518
				.getExplorerName();
519
    }
520

  
521
    public String getConnectionServerUrl() {
522
        return urlTextField.getText();
523
    }
524

  
525
    public String getConnectionPort() {
526
        return portTextField.getText();
527
    }
528

  
529
    public String getConnectionDBName() {
530
        return dbTextField.getText();
531
    }
532

  
533
    public String getConnectionUser() {
534
        return userTextField.getText();
535
    }
536

  
537
    public String getConnectionPassword() {
538
        String resp = new String(passwordField.getPassword());
539

  
540
        return resp;
541
    }
542

  
543
    private JTextField getUrlTextArea() {
544
        if (urlTextField == null) {
545
            urlTextField = new JTextField();
546
            urlTextField.addKeyListener(this);
547
            urlTextField.setBounds(new java.awt.Rectangle(155, 80, 166, 21));
548
        }
549

  
550
        return urlTextField;
551
    }
552

  
553
    /**
554
     * This method initializes connectedCheckBox
555
     *
556
     * @return javax.swing.JCheckBox
557
     */
558
    private JCheckBox getConnectedCheckBox() {
559
        if (connectedCheckBox == null) {
560
            connectedCheckBox = new JCheckBox();
561
            connectedCheckBox.setSelected(true);
562
            connectedCheckBox.addActionListener(this);
563
            connectedCheckBox.setBounds(new java.awt.Rectangle(155, 247, 26, 21));
564
        }
565

  
566
        return connectedCheckBox;
567
    }
568

  
569
    public String getConnectionName() {
570
        return getConnNameTextField().getText();
571
    }
572

  
573
    /**
574
     * This method initializes connNameTextField
575
     *
576
     * @return javax.swing.JTextField
577
     */
578
    private JTextField getConnNameTextField() {
579
        if (connNameTextField == null) {
580
            connNameTextField = new JTextField();
581
            connNameTextField.addKeyListener(this);
582
            connNameTextField.setBounds(new java.awt.Rectangle(155, 30, 166, 21));
583
        }
584

  
585
        return connNameTextField;
586
    }
587

  
588
    public void keyPressed(KeyEvent e) {
589
    }
590

  
591
    public void keyReleased(KeyEvent e) {
592
        if (e.getKeyChar() != '\n') {
593
            return;
594
        }
595

  
596
        Object src = e.getSource();
597

  
598
        if (src == passwordField) {
599
            ActionEvent aevt = new ActionEvent(okButton,
600
                    ActionEvent.ACTION_PERFORMED, "");
601
            actionPerformed(aevt);
602
        }
603
        else {
604
            if (src instanceof JTextField) {
605
                ((JTextField) src).transferFocus();
606
            }
607
        }
608
    }
609

  
610
    public void keyTyped(KeyEvent e) {
611
	}
612

  
613
    public void loadValues(DBServerExplorerParameters cwp) {
614
    	if (cwp.getPort() != null){
615
    		getPortTextField().setText(cwp.getPort().toString());
616
    	} else{
617
    		getPortTextField().setText("");
618
    	}
619
        selectThisInDriverCombo(cwp.getExplorerName());
620
        getDbTextField().setText(cwp.getDBName());
621
        getUserTextField().setText(cwp.getUser());
622

  
623
        if (cwp.getPassword() == null) {
624
            getPasswordField().setText("");
625
        }
626
        else {
627
            getPasswordField().setText(cwp.getPassword());
628
        }
629

  
630
        getUrlTextArea().setText(cwp.getHost());
631

  
632
        // boolean connected = false;
633
        //
634
//        try {
635
//            connected = (cwp.getConnection() != null) &&
636
//                (!cwp.getConnection().isClosed());
637
//        }
638
//        catch (DBException e) {
639
        // LOG.error("While checking connection: " + e.getMessage());
640
//            connected = false;
641
//        }
642

  
643
//        getConnectedCheckBox().setSelected(connected);
644
		getConnNameTextField().setText(cwp.getExplorerName());
645
    }
646

  
647
    private void selectThisInDriverCombo(String drvName) {
648
        int size = getDriverComboBox().getItemCount();
649
        int curSel = getDriverComboBox().getSelectedIndex();
650

  
651
        for (int i = 0; i < size; i++) {
652
            DriverComboBoxItem item = (DriverComboBoxItem) getDriverComboBox()
653
					.getItemAt(i);
654

  
655
            if (item.params.getExplorerName().compareToIgnoreCase(drvName) == 0) {
656
                getDriverComboBox().setSelectedIndex(i);
657
                if (curSel != i) {
658
					this.params = null;
659
				}
660

  
661
                return;
662
            }
663
        }
664
    }
665

  
666
	public Object getWindowProfile() {
667
		return WindowInfo.DIALOG_PROFILE;
668
	}
669

  
670
	public DBServerExplorerParameters getParameters(){
671

  
672
        DBServerExplorerParameters params = internalGetParameters();
673

  
674
		String _host = getConnectionServerUrl();
675
		String _port = getConnectionPort();
676
		String _dbname = getConnectionDBName();
677
		String _user = getConnectionUser();
678
		String _pw = getConnectionPassword();
679

  
680
		params.setHost(_host);
681
		if (_port.trim().length() != 0) {
682
			try {
683
				params.setPort(Integer.parseInt(_port));
684
			} catch (NumberFormatException e) {
685
				NotificationManager.addError("Invalid port", e);
686
			}
687
		}
688
		params.setDBName(_dbname);
689
		params.setUser(_user);
690
		params.setPassword(_pw);
691

  
692
		return params;
693
	}
694

  
695
    private DBServerExplorerParameters internalGetParameters() {
696
        if (params == null) {
697
            DriverComboBoxItem item =
698
                (DriverComboBoxItem) getDriverComboBox().getItemAt(
699
                    getDriverComboBox().getSelectedIndex());
700
            params = (DBServerExplorerParameters) item.params.getCopy();
701

  
702
        }
703

  
704
        return params;
705
    }
706

  
707
} //  @jve:decl-index=0:visual-constraint="10,10"
0 708

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/TablesListItem.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.vectorialdb.wizard;
44

  
45
import java.util.ArrayList;
46
import java.util.Iterator;
47

  
48
import javax.swing.JCheckBox;
49

  
50
import org.cresques.cts.IProjection;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53

  
54
import org.gvsig.andami.messages.NotificationManager;
55
import org.gvsig.app.addlayer.AddLayerDialog;
56
import org.gvsig.fmap.dal.exception.DataException;
57
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
58
import org.gvsig.fmap.dal.feature.FeatureType;
59
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer;
60
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
61
import org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters;
62

  
63

  
64

  
65
/**
66
 * Utility class that represents a table list item as a selectable check box.
67
 *
68
 * @author jldominguez
69
 *
70
 */
71
public class TablesListItem extends JCheckBox {
72
    
73
    private static Logger logger = LoggerFactory.getLogger(TablesListItem.class);
74
    
75
    protected String tableName = "";
76
    protected String schemaName = "";
77
    
78
    private UserSelectedFieldsPanel selectedFieldsPanel = null;
79
    protected WizardDB parent = null;
80
    private boolean activated = false;
81
    // private CRSSelectPanel jPanelProj;
82
	protected DBStoreParameters parameters;
83
	protected DBServerExplorer explorer;
84
	protected UserTableSettingsPanel tableSettingsPanel = null;
85

  
86
    public TablesListItem(DBServerExplorer explorer,
87
			DBStoreParameters param,
88
			WizardDB _parent) {
89
        
90
        tableName = param.getTable();
91
        schemaName = getSchema(param);
92
        
93
        setText(toString());
94
        this.parameters = param;
95
        this.explorer=explorer;
96
        parent = _parent;
97
    }
98
    
99

  
100

  
101
    /**
102
     * @param param
103
     * @return
104
     */
105
    private String getSchema(DBStoreParameters dynobj) {
106
        
107
        String resp = null;
108
        try {
109
            resp = (String) dynobj.getDynValue(
110
                JDBCConnectionParameters.SCHEMA_PARAMTER_NAME);
111
        } catch (Exception ex) {
112
            // logger.info("did not find schema in DB parameters.");
113
        }
114
        return resp;
115
    }
116

  
117
    public void activate() {
118
        activated = true;
119
        selectedFieldsPanel.loadValues();
120
        tableSettingsPanel.loadValues();
121
    }
122

  
123
    public boolean isActivated() {
124
        return activated;
125
    }
126

  
127
    /**
128
     * Tells whether this item prevents the wizard from being in a valid final state.
129
     * @return whether this item prevents the wizard from being in a valid final state.
130
     */
131
    public boolean disturbsWizardValidity() {
132
        if (isSelected()) {
133
            return (!hasValidValues());
134
        }
135
        else {
136
            return false;
137
        }
138
    }
139

  
140
    private boolean hasValidValues() {
141
        return tableSettingsPanel.hasValidValues();
142
    }
143

  
144
    public String toString() {
145
        if (schemaName == null || schemaName.length() == 0) {
146
            return tableName;
147
        } else {
148
            return schemaName + "." + tableName;
149
        }
150
        
151
    }
152

  
153
    public String getTableName() {
154
        return tableName;
155
    }
156

  
157
    public void setEnabledPanels(boolean b) {
158
        selectedFieldsPanel.enableControls(b);
159
        tableSettingsPanel.enableAlphaControls(b);
160
        tableSettingsPanel.enableSpatialControls(b);
161

  
162
    }
163

  
164
    public UserSelectedFieldsPanel getUserSelectedFieldsPanel() {
165
        if (selectedFieldsPanel == null) {
166
        	FeatureType ft=null;
167
			try {
168
				ft = explorer.getFeatureType(parameters);
169
			} catch (DataException e) {
170
				NotificationManager.addError(e);
171
				return null;
172
			}
173
			ArrayList<FeatureAttributeDescriptor> attList = new ArrayList<FeatureAttributeDescriptor>();
174

  
175
			Iterator<FeatureAttributeDescriptor> iter = ft.iterator();
176
			while (iter.hasNext()) {
177
				attList.add(iter.next());
178
			}
179

  
180
        	FeatureAttributeDescriptor[] allf = attList
181
					.toArray(new FeatureAttributeDescriptor[0]);
182

  
183

  
184
            selectedFieldsPanel = new UserSelectedFieldsPanel(allf, false,
185
                    parent);
186
        }
187

  
188
        return selectedFieldsPanel;
189
    }
190

  
191
    public UserTableSettingsPanel getUserTableSettingsPanel() {
192
		if (tableSettingsPanel == null) {
193

  
194
			String[] ids = new String[0];
195
			FeatureType ft = null;
196

  
197
			try {
198
				ft = explorer.getFeatureType(parameters);
199
			} catch (DataException e) {
200
				NotificationManager.addError(e);
201
				return null;
202
			}
203

  
204
			ArrayList auxAll = new ArrayList();
205
			ArrayList auxId = new ArrayList();
206
			Iterator iter = ft.iterator();
207
			while (iter.hasNext()) {
208
				FeatureAttributeDescriptor dbattr = (FeatureAttributeDescriptor) iter
209
						.next();
210
				if (dbattr.isPrimaryKey()) {
211
					auxId.add(dbattr.getName());
212
				}
213
				auxAll.add(dbattr.getName());
214

  
215
			}
216

  
217
			if (auxId.size() > 0) {
218
				StringBuilder strb = new StringBuilder();
219
				strb.append('{');
220
				for (int i = 0; i < auxId.size()-1; i++) {
221
					strb.append(auxId.get(i));
222
					strb.append(',');
223
				}
224
				strb.append(auxId.get(auxId.size() - 1));
225

  
226
				strb.append('}');
227
				if (auxId.size() == 1) {
228
					auxAll.remove(auxId.get(0));
229
				}
230
				auxAll.add(0, strb.toString());
231
			}
232
			ids = (String[]) auxAll.toArray(new String[auxAll.size()]);
233
			int ids_size = ids.length;
234
			FieldComboItem[] ids_ci = new FieldComboItem[ids_size];
235

  
236
			for (int i = 0; i < ids_size; i++) {
237
				ids_ci[i] = new FieldComboItem(ids[i]);
238
			}
239

  
240

  
241

  
242
			tableSettingsPanel = new UserTableSettingsPanel(ids_ci, tableName,
243
					true, parent, getParameters());
244
		}
245

  
246
		return tableSettingsPanel;
247
	}
248

  
249

  
250
    public IProjection currentProjection(String espView,
251
			FieldComboItem[] ids_ci, FieldComboItem[] geos_ci) {
252
		IProjection proj = AddLayerDialog.getLastProjection();
253
		try {
254
			ArrayList list = new ArrayList(1);
255
			list.add(espView);
256
			FeatureType ft = null;
257
			try {
258
				ft = explorer.getFeatureType(parameters);
259
			} catch (DataException e) {
260
				// TODO Auto-generated catch block
261
				e.printStackTrace();
262
			}
263
		} catch (Exception e) {
264
			NotificationManager.addInfo("Incorrect projection", e);
265
		}
266
		return proj;
267
	}
268

  
269
    public DBStoreParameters getParameters() {
270
    	return parameters;
271
    }
272
}
0 273

  
tags/v2_0_0_Build_2063/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/MyExplorer.java
1

  
2
/* gvSIG. Geographic Information System of the Valencian Government
3
*
4
* Copyright (C) 2007-2008 Infrastructures and Transports Department
5
* of the Valencian Government (CIT)
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
* MA  02110-1301, USA.
21
*
22
*/
23

  
24
/*
25
* AUTHORS (In addition to CIT):
26
* ${year} IVER T.I. S.A.   {{Task}}
27
*/
28

  
29
package org.gvsig.geodb.vectorialdb.wizard;
30

  
31
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
32

  
33

  
34
/**
35
 * DOCUMENT ME!
36
 *
37
 * @author Vicente Caballero Navarro
38
 */
39
public class MyExplorer {
40
    private DBServerExplorerParameters dbExplorerParameters;
41
    private String name;
42

  
43
    /**
44
     * DOCUMENT ME!
45
     *
46
     * @return DOCUMENT ME!
47
     */
48
    public DBServerExplorerParameters getDbSeverExplorerParameters() {
49
        return dbExplorerParameters;
50
    }
51

  
52
    /**
53
     * DOCUMENT ME!
54
     *
55
     * @param dbExplorerParameters DOCUMENT ME!
56
     */
57
    public void setDbExplorerParameters(
58
        DBServerExplorerParameters dbExplorerParameters) {
59
        this.dbExplorerParameters = dbExplorerParameters;
60
    }
61

  
62
    /**
63
     * DOCUMENT ME!
64
     *
65
     * @return DOCUMENT ME!
66
     */
67
    public String getName() {
68
        return name;
69
    }
70

  
71
    /**
72
     * DOCUMENT ME!
73
     *
74
     * @param name DOCUMENT ME!
75
     */
76
    public void setName(String name) {
77
        this.name = name;
78
    }
79

  
80
	public String toString() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff