Revision 41486
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc/JDBCServerExplorer.java | ||
---|---|---|
186 | 186 |
} |
187 | 187 |
} |
188 | 188 |
|
189 |
public NewDataStoreParameters getAddParameters() throws DataException {
|
|
189 |
public DataStoreParameters getOpenParameters() throws DataException {
|
|
190 | 190 |
JDBCServerExplorerParameters parameters = getJDBCParameters(); |
191 |
JDBCStoreParameters params = new JDBCStoreParameters(); |
|
192 |
params.setHost(parameters.getHost()); |
|
193 |
params.setPort(parameters.getPort()); |
|
194 |
params.setDBName(parameters.getDBName()); |
|
195 |
params.setUser(parameters.getUser()); |
|
196 |
params.setPassword(parameters.getPassword()); |
|
197 |
params.setCatalog(parameters.getCatalog()); |
|
198 |
params.setSchema(parameters.getSchema()); |
|
199 |
params.setJDBCDriverClassName(parameters.getJDBCDriverClassName()); |
|
200 |
params.setUrl(parameters.getUrl()); |
|
201 |
return params; |
|
202 |
} |
|
203 |
|
|
204 |
public NewDataStoreParameters getAddParameters() throws DataException { |
|
205 |
JDBCServerExplorerParameters parameters = getJDBCParameters(); |
|
191 | 206 |
JDBCNewStoreParameters params = new JDBCNewStoreParameters(); |
192 | 207 |
params.setHost(parameters.getHost()); |
193 | 208 |
params.setPort(parameters.getPort()); |
... | ... | |
379 | 394 |
return NAME; |
380 | 395 |
} |
381 | 396 |
|
382 |
protected String getStoreName() {
|
|
397 |
public String getStoreName() {
|
|
383 | 398 |
return JDBCStoreProvider.NAME; |
384 | 399 |
} |
385 | 400 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.api/src/main/java/org/gvsig/exportto/ExporttoServiceException.java | ||
---|---|---|
40 | 40 |
"An error has been produced exporting a store"; |
41 | 41 |
|
42 | 42 |
private static final String KEY = "_ExporttoServiceException"; |
43 |
private Feature feature = null;
|
|
43 |
protected Feature feature = null;
|
|
44 | 44 |
|
45 | 45 |
/** |
46 | 46 |
* Creates a new {@link ExporttoServiceException}. |
... | ... | |
52 | 52 |
super(MESSAGE, cause, KEY, serialVersionUID); |
53 | 53 |
} |
54 | 54 |
|
55 |
protected ExporttoServiceException(String message, Throwable cause, String key, long code) { |
|
56 |
super(message, cause, key, code); |
|
57 |
} |
|
58 |
|
|
55 | 59 |
public ExporttoServiceException(Throwable cause, Feature feature) { |
56 | 60 |
super(MESSAGE, cause, KEY, serialVersionUID); |
57 | 61 |
this.feature = feature; |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.spi/src/main/java/org/gvsig/exportto/swing/spi/ExporttoSwingProviderPanel.java | ||
---|---|---|
24 | 24 |
package org.gvsig.exportto.swing.spi; |
25 | 25 |
|
26 | 26 |
import javax.swing.JPanel; |
27 |
import org.gvsig.tools.swing.api.Component; |
|
27 | 28 |
|
28 | 29 |
/** |
29 | 30 |
* The panels returned by a {@link ExporttoSwingProvider} have to |
... | ... | |
33 | 34 |
* @version $Id$ |
34 | 35 |
* |
35 | 36 |
*/ |
36 |
public abstract class ExporttoSwingProviderPanel extends JPanel {
|
|
37 |
public interface ExporttoSwingProviderPanel extends Component {
|
|
37 | 38 |
|
38 |
private static final long serialVersionUID = -342762576886358109L; |
|
39 |
|
|
40 | 39 |
/** |
41 | 40 |
* @return |
42 | 41 |
* the panel title that will be displayed with |
43 | 42 |
* this panel. |
44 | 43 |
*/ |
45 |
public abstract String getPanelTitle();
|
|
44 |
public String getPanelTitle(); |
|
46 | 45 |
|
47 | 46 |
/** |
48 | 47 |
* Checks if the panel is valid. If is not valid and throws |
... | ... | |
57 | 56 |
* @throws ExporttoPanelValidationException |
58 | 57 |
* if there is any erro that has to be shown to the user. |
59 | 58 |
*/ |
60 |
public abstract boolean isValidPanel() |
|
61 |
throws ExporttoPanelValidationException; |
|
59 |
public boolean isValidPanel() throws ExporttoPanelValidationException; |
|
62 | 60 |
|
63 | 61 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/exportto/swing/impl/wizard/DefaultWizardContainer.java | ||
---|---|---|
61 | 61 |
if (!this.exporttoSwingProviderPanel.isValidPanel()) { |
62 | 62 |
throw new NotContinueWizardException( |
63 | 63 |
Messages.getText("_Invalid_values_in_form"), |
64 |
exporttoSwingProviderPanel, |
|
64 |
exporttoSwingProviderPanel.asJComponent(),
|
|
65 | 65 |
false); |
66 | 66 |
} |
67 | 67 |
} catch (ExporttoPanelValidationException e) { |
68 | 68 |
LOG.info("Invalid form values."); |
69 | 69 |
throw new NotContinueWizardException( |
70 | 70 |
Messages.getText("_Invalid_values_in_form"), |
71 |
e, exporttoSwingProviderPanel); |
|
71 |
e, exporttoSwingProviderPanel.asJComponent());
|
|
72 | 72 |
} |
73 | 73 |
} |
74 | 74 |
|
... | ... | |
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
public JPanel getJPanel() { |
85 |
return exporttoSwingProviderPanel;
|
|
85 |
return (JPanel) exporttoSwingProviderPanel.asJComponent();
|
|
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.file/src/main/java/org/gvsig/exportto/swing/prov/file/panel/SelectFileOptionPanel.java | ||
---|---|---|
26 | 26 |
import java.awt.BorderLayout; |
27 | 27 |
import java.awt.Component; |
28 | 28 |
import java.io.File; |
29 |
import javax.swing.JComponent; |
|
29 | 30 |
|
30 | 31 |
import javax.swing.JOptionPane; |
31 | 32 |
import javax.swing.JPanel; |
... | ... | |
41 | 42 |
* @version $Id$ |
42 | 43 |
* |
43 | 44 |
*/ |
44 |
public class SelectFileOptionPanel extends ExporttoSwingProviderPanel { |
|
45 |
public class SelectFileOptionPanel extends JPanel implements ExporttoSwingProviderPanel {
|
|
45 | 46 |
|
46 | 47 |
private static final long serialVersionUID = -7417782279157857962L; |
47 | 48 |
private JPanel optionsPanel; |
... | ... | |
112 | 113 |
public JPanel getOptionsPanel() { |
113 | 114 |
return optionsPanel; |
114 | 115 |
} |
116 |
|
|
117 |
public JComponent asJComponent() { |
|
118 |
return this; |
|
119 |
} |
|
115 | 120 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/AbstractExporttoJDBCProvider.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.prov.jdbc; |
25 | 25 |
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.List; |
|
26 | 28 |
import org.cresques.cts.IProjection; |
27 |
import org.slf4j.Logger; |
|
28 |
import org.slf4j.LoggerFactory; |
|
29 |
|
|
30 | 29 |
import org.gvsig.exportto.ExporttoService; |
30 |
import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel; |
|
31 | 31 |
import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel; |
32 | 32 |
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel; |
33 | 33 |
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel; |
34 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
|
35 | 34 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
36 | 35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 | 36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
38 |
import org.gvsig.geodb.vectorialdb.ConnectionSettings; |
|
37 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
|
38 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
39 | 39 |
import org.gvsig.tools.service.spi.AbstractProvider; |
40 | 40 |
import org.gvsig.tools.service.spi.ProviderServices; |
41 |
import org.slf4j.Logger; |
|
42 |
import org.slf4j.LoggerFactory; |
|
41 | 43 |
|
42 | 44 |
/** |
43 | 45 |
* Exporto provider which gets Exporto from a file. |
... | ... | |
46 | 48 |
* @version $Id$ |
47 | 49 |
*/ |
48 | 50 |
public abstract class AbstractExporttoJDBCProvider extends AbstractProvider |
49 |
implements ExporttoSwingProvider {
|
|
51 |
implements ExporttoJDBCProvider {
|
|
50 | 52 |
|
51 | 53 |
private static Logger logger = LoggerFactory.getLogger( |
52 | 54 |
AbstractExporttoJDBCProvider.class); |
53 | 55 |
|
54 |
protected SelectTableNamePanel selectTableNamePanel = null; |
|
55 |
protected SelectPkPanel selectPkPanel = null; |
|
56 |
protected JDBCConnectionPanel jdbcConnectionPanel = null; |
|
56 |
protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>(); |
|
57 | 57 |
|
58 |
protected FeatureStore featureStore;
|
|
58 |
protected FeatureStore sourceStore;
|
|
59 | 59 |
protected IProjection projection; |
60 |
private final JDBCConnectionPanel connectionPanel; |
|
61 |
private final SelectPkPanel selectPkPanel; |
|
62 |
private final SelectTableNamePanel selectTableNamePanel; |
|
63 |
private final CheckGeometriesPanel checkGeometriesPanel; |
|
60 | 64 |
|
61 |
/** |
|
62 |
* Constructor. |
|
63 |
* |
|
64 |
* @param providerServices |
|
65 |
* the services for the provider |
|
66 |
* @param file |
|
67 |
* to get the Exporto from |
|
68 |
*/ |
|
65 |
|
|
69 | 66 |
public AbstractExporttoJDBCProvider(ProviderServices providerServices, |
70 |
FeatureStore featureStore, IProjection projection) {
|
|
67 |
FeatureStore sourceStore, IProjection projection) {
|
|
71 | 68 |
super(providerServices); |
72 |
this.featureStore = featureStore;
|
|
69 |
this.sourceStore = sourceStore;
|
|
73 | 70 |
this.projection = projection; |
74 | 71 |
|
75 |
selectTableNamePanel = new SelectTableNamePanel(); |
|
76 |
|
|
77 | 72 |
FeatureType ftype = null; |
78 | 73 |
try { |
79 |
ftype = featureStore.getDefaultFeatureType();
|
|
74 |
ftype = sourceStore.getDefaultFeatureType();
|
|
80 | 75 |
} catch (Exception exc) { |
81 |
logger.error("While getting feature type.", exc); |
|
76 |
logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc); |
|
77 |
|
|
82 | 78 |
} |
83 |
selectPkPanel = new SelectPkPanel(ftype); |
|
84 |
jdbcConnectionPanel = new JDBCConnectionPanel(); |
|
79 |
this.connectionPanel = new JDBCConnectionPanel(this); |
|
80 |
this.selectTableNamePanel = new SelectTableNamePanel(this); |
|
81 |
this.selectPkPanel = new SelectPkPanel(this,ftype); |
|
82 |
this.checkGeometriesPanel = new CheckGeometriesPanel(this); |
|
83 |
|
|
84 |
this.panels.add(this.connectionPanel); |
|
85 |
this.panels.add(this.selectTableNamePanel); |
|
86 |
this.panels.add(this.selectPkPanel); |
|
87 |
this.panels.add(this.checkGeometriesPanel); |
|
85 | 88 |
} |
86 | 89 |
|
87 | 90 |
public int getPanelCount() { |
88 |
return 3;
|
|
91 |
return this.panels.size();
|
|
89 | 92 |
} |
90 | 93 |
|
91 | 94 |
public ExporttoSwingProviderPanel getPanelAt(int index) { |
92 |
switch (index) { |
|
93 |
case 0: |
|
94 |
return selectTableNamePanel; |
|
95 |
case 1: |
|
96 |
return selectPkPanel; |
|
97 |
case 2: |
|
98 |
return jdbcConnectionPanel; |
|
99 |
} |
|
100 |
return null; |
|
95 |
return this.panels.get(index); |
|
101 | 96 |
} |
102 | 97 |
|
103 | 98 |
public ExporttoService createExporttoService() { |
104 |
ConnectionSettings connectionSettings = |
|
105 |
jdbcConnectionPanel.getConnectionSettings(); |
|
99 |
JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters(); |
|
100 |
explorerParameters.setSchema(this.getSchema()); |
|
101 |
return new ExporrtoJDBCService( |
|
102 |
sourceStore, |
|
103 |
explorerParameters, |
|
104 |
this.getTableName(), |
|
105 |
this.getPrimaryKey(), |
|
106 |
this.projection, |
|
107 |
this.canCreatetable(), |
|
108 |
this.getGeometryChecks(), |
|
109 |
this.getGeometryChecksAction() |
|
110 |
); |
|
111 |
} |
|
106 | 112 |
|
107 |
int port = -1; |
|
108 |
if (connectionSettings.getPort() != null |
|
109 |
&& connectionSettings.getPort().length() > 0) { |
|
110 |
port = Integer.valueOf(connectionSettings.getPort()); |
|
111 |
} |
|
113 |
public JDBCServerExplorerParameters getExplorerParameters() { |
|
114 |
return this.connectionPanel.getServerExplorerParameters(); |
|
115 |
} |
|
116 |
|
|
117 |
public String getSchema() { |
|
118 |
return this.selectTableNamePanel.getSchema(); |
|
119 |
} |
|
112 | 120 |
|
113 |
String schema = null; |
|
114 |
if (connectionSettings.getSchema() != null |
|
115 |
&& connectionSettings.getSchema().length() > 0) { |
|
116 |
schema = connectionSettings.getSchema(); |
|
117 |
} |
|
121 |
public String getTableName() { |
|
122 |
return this.selectTableNamePanel.getTableName(); |
|
123 |
} |
|
118 | 124 |
|
119 |
return new ExporrtoJDBCService(featureStore, |
|
120 |
connectionSettings.getDb(), schema, selectTableNamePanel.getText(), |
|
121 |
selectPkPanel.getText(), connectionSettings.getUser(), |
|
122 |
connectionSettings.getPassw(), connectionSettings.getHost(), port, |
|
123 |
getExplorerName(), getStoreName(), this.projection); |
|
125 |
public boolean canCreatetable() { |
|
126 |
return this.selectTableNamePanel.canCreateTable(); |
|
124 | 127 |
} |
125 | 128 |
|
126 |
public abstract String getStoreName(); |
|
129 |
public String getPrimaryKey() { |
|
130 |
return this.selectPkPanel.getPrimaryKeyName(); |
|
131 |
} |
|
127 | 132 |
|
128 |
public abstract String getExplorerName(); |
|
133 |
public int getGeometryChecks() { |
|
134 |
return this.checkGeometriesPanel.getGeometryChecks(); |
|
135 |
} |
|
136 |
|
|
137 |
public int getGeometryChecksAction() { |
|
138 |
return this.checkGeometriesPanel.getGeometryChecksAction(); |
|
139 |
} |
|
140 |
|
|
141 |
public String getExplorerName() { |
|
142 |
return this.connectionPanel.getServerExplorerParameters().getExplorerName(); |
|
143 |
} |
|
144 |
|
|
129 | 145 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/ExporrtoJDBCService.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.exportto.swing.prov.jdbc; |
25 | 24 |
|
26 |
import java.util.Iterator; |
|
27 |
|
|
28 | 25 |
import org.cresques.cts.ICoordTrans; |
29 | 26 |
import org.cresques.cts.IProjection; |
30 |
|
|
31 | 27 |
import org.gvsig.exportto.ExporttoService; |
32 | 28 |
import org.gvsig.exportto.ExporttoServiceException; |
33 | 29 |
import org.gvsig.exportto.ExporttoServiceFinishAction; |
34 | 30 |
import org.gvsig.fmap.dal.DALLocator; |
35 | 31 |
import org.gvsig.fmap.dal.DataManager; |
36 | 32 |
import org.gvsig.fmap.dal.DataTypes; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
|
38 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
39 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
40 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
41 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
42 | 33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
43 | 34 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
44 | 35 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
... | ... | |
48 | 39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
49 | 40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
50 | 41 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
51 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
|
52 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
|
53 | 42 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
54 | 43 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
55 | 44 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
56 | 45 |
import org.gvsig.fmap.geom.Geometry; |
57 | 46 |
import org.gvsig.tools.dispose.DisposableIterator; |
58 |
import org.gvsig.tools.service.ServiceException; |
|
59 | 47 |
import org.gvsig.tools.task.AbstractMonitorableTask; |
60 | 48 |
|
61 | 49 |
/** |
62 | 50 |
* @author gvSIG Team |
63 | 51 |
* @version $Id$ |
64 |
*
|
|
52 |
* |
|
65 | 53 |
*/ |
66 | 54 |
public class ExporrtoJDBCService extends AbstractMonitorableTask implements |
67 |
ExporttoService { |
|
55 |
ExporttoService {
|
|
68 | 56 |
|
69 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
|
57 |
public static final int CHECK_NONE = 0; |
|
58 |
public static final int CHECK_IF_CORRUPT = 1; |
|
59 |
public static final int CHECK_IF_VALID = 2; |
|
70 | 60 |
|
71 |
private String dbName = null; |
|
72 |
private String schema = null; |
|
73 |
private String tableName = null; |
|
74 |
private String pkField = null; |
|
75 |
private String userName = null; |
|
76 |
private String password = null; |
|
77 |
private String host = null; |
|
78 |
private int port = -1; |
|
79 |
private String explorerName = null; |
|
80 |
private String storeName = null; |
|
61 |
public static final int ACTION_SET_GEOMETRY_TO_NULL = 0; |
|
62 |
public static final int ACTION_SKIP_FEATURE = 1; |
|
63 |
public static final int ACTION_ABORT = 2; |
|
81 | 64 |
|
82 |
private NewFeatureStoreParameters newFeatureStoreParameters; |
|
83 |
private JDBCServerExplorer explorer; |
|
84 |
private FeatureStore featureStore; |
|
85 |
private IProjection targetProjection; |
|
65 |
private final FeatureStore source; |
|
66 |
private final JDBCServerExplorerParameters explorerParameters; |
|
67 |
private final String tableName; |
|
68 |
private final String pkname; |
|
69 |
private final int geometryChecks; |
|
70 |
private final int geometryChecksAction; |
|
71 |
private final IProjection tarjetProjection; |
|
72 |
private final boolean canCreateTable; |
|
86 | 73 |
|
87 | 74 |
private ExporttoServiceFinishAction exporttoServiceFinishAction = null; |
88 | 75 |
|
89 |
/** |
|
90 |
* @param taskName |
|
91 |
* @throws ServiceException |
|
92 |
*/ |
|
93 |
protected ExporrtoJDBCService(FeatureStore featureStore, String dbName, |
|
94 |
String schema, String tableName, String pkField, String userName, |
|
95 |
String password, String host, int port, String explorerName, |
|
96 |
String storeName, IProjection target_projetion) { |
|
97 |
super("Export to JDBC"); |
|
98 |
this.featureStore = featureStore; |
|
99 |
this.dbName = dbName; |
|
100 |
this.schema = schema; |
|
101 |
this.tableName = tableName; |
|
102 |
this.pkField = pkField; |
|
103 |
this.userName = userName; |
|
104 |
this.password = password; |
|
105 |
this.host = host; |
|
106 |
this.port = port; |
|
107 |
this.storeName = storeName; |
|
108 |
this.explorerName = explorerName; |
|
109 |
this.targetProjection = target_projetion; |
|
76 |
public ExporrtoJDBCService(FeatureStore source, |
|
77 |
JDBCServerExplorerParameters explorerParameters, |
|
78 |
String tablename, |
|
79 |
String primaryKeyName, |
|
80 |
IProjection tarjetProjection, |
|
81 |
boolean canCreatetable, |
|
82 |
int geometryChecks, |
|
83 |
int geometryChecksAction) { |
|
84 |
this.source = source; |
|
85 |
this.explorerParameters = explorerParameters; |
|
86 |
this.tableName = tablename; |
|
87 |
this.pkname = primaryKeyName; |
|
88 |
this.tarjetProjection = tarjetProjection; |
|
89 |
this.canCreateTable = canCreatetable; |
|
90 |
this.geometryChecks = geometryChecks; |
|
91 |
this.geometryChecksAction = geometryChecksAction; |
|
110 | 92 |
} |
111 | 93 |
|
112 |
public void export(FeatureSet featureSet) throws ExporttoServiceException {
|
|
94 |
protected void createTable(JDBCServerExplorer explorer) throws Exception {
|
|
113 | 95 |
|
114 |
initializeParams(featureSet); |
|
96 |
FeatureType targetFeatureType ; |
|
97 |
EditableFeatureType targetEditableFeatureType ; |
|
115 | 98 |
|
116 |
DisposableIterator it1 = null; |
|
99 |
targetFeatureType = source.getDefaultFeatureType().getCopy(); |
|
100 |
targetEditableFeatureType = targetFeatureType.getEditable(); |
|
101 |
|
|
102 |
if (this.pkname != null) { |
|
103 |
EditableFeatureAttributeDescriptor pk |
|
104 |
= targetEditableFeatureType.add(this.pkname, DataTypes.LONG); |
|
105 |
pk.setIsPrimaryKey(true); |
|
106 |
pk.setIsAutomatic(true); |
|
107 |
} |
|
108 |
|
|
109 |
// ====================================================== |
|
110 |
// Reprojection: set SRS of geometry field to target SRS |
|
111 |
EditableFeatureAttributeDescriptor attrdescriptor |
|
112 |
= (EditableFeatureAttributeDescriptor) targetEditableFeatureType.getDefaultGeometryAttribute(); |
|
113 |
if (attrdescriptor != null) { |
|
114 |
attrdescriptor.setSRS(this.tarjetProjection); |
|
115 |
} |
|
116 |
|
|
117 |
// ====================================== |
|
118 |
NewFeatureStoreParameters createTableParams = (NewFeatureStoreParameters) explorer.getAddParameters(); |
|
119 |
|
|
120 |
createTableParams.setDefaultFeatureType(targetEditableFeatureType); |
|
121 |
|
|
122 |
explorer.add(explorer.getStoreName(), createTableParams, true); |
|
123 |
} |
|
124 |
|
|
125 |
private static class InvalidGeometryException extends ExporttoServiceException { |
|
126 |
|
|
127 |
public InvalidGeometryException(Feature feature, String checkMessage) { |
|
128 |
super(checkMessage, null, checkMessage, 0); |
|
129 |
this.feature = feature; |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
public void export(FeatureSet featureSet) throws ExporttoServiceException { |
|
134 |
Geometry.ValidationStatus geometryCheck; |
|
135 |
|
|
136 |
DisposableIterator it = null; |
|
137 |
EditableFeature targetFeature = null; |
|
117 | 138 |
FeatureStore target = null; |
118 | 139 |
|
119 |
EditableFeatureType ef_type = null; |
|
120 |
FeatureType f_type = null; |
|
121 |
EditableFeature edit_feat = null; |
|
122 | 140 |
try { |
123 |
f_type = featureStore.getDefaultFeatureType(); |
|
124 |
f_type = f_type.getCopy(); |
|
125 |
ef_type = f_type.getEditable(); |
|
126 |
|
|
127 |
if (pkField != null) { |
|
128 |
EditableFeatureAttributeDescriptor pk = |
|
129 |
ef_type.add(pkField, DataTypes.LONG); |
|
130 |
pk.setIsPrimaryKey(true); |
|
131 |
pk.setIsAutomatic(true); |
|
132 |
} |
|
133 | 141 |
|
134 |
// ======================================== |
|
135 |
// Reprojection: set SRS of geometry field to |
|
136 |
// target SRS |
|
137 |
EditableFeatureAttributeDescriptor eatt = |
|
138 |
(EditableFeatureAttributeDescriptor) |
|
139 |
ef_type.getDefaultGeometryAttribute(); |
|
140 |
if (eatt != null) { |
|
141 |
eatt.setSRS(this.targetProjection); |
|
142 |
} |
|
143 | 142 |
// ====================================== |
144 |
|
|
145 |
newFeatureStoreParameters.setDefaultFeatureType(ef_type); |
|
146 |
explorer.add(storeName, newFeatureStoreParameters, true); |
|
147 |
|
|
148 |
// ====================================== |
|
149 | 143 |
// Reprojection |
150 |
FeatureAttributeDescriptor geo_att = f_type.getDefaultGeometryAttribute();
|
|
144 |
FeatureAttributeDescriptor geo_att = source.getDefaultFeatureType().getDefaultGeometryAttribute();
|
|
151 | 145 |
IProjection sourceProjection = null; |
152 | 146 |
ICoordTrans coord_trans = null; |
147 |
Geometry reproj_geom = null; |
|
153 | 148 |
if (geo_att != null) { |
154 | 149 |
sourceProjection = geo_att.getSRS(); |
155 | 150 |
// this comparison is perhaps too preventive |
156 | 151 |
// we could have two instances of same projection |
157 | 152 |
// so we would do more computations than needed |
158 |
if (sourceProjection != this.targetProjection) {
|
|
159 |
coord_trans = sourceProjection.getCT(this.targetProjection);
|
|
153 |
if (sourceProjection != this.tarjetProjection) {
|
|
154 |
coord_trans = sourceProjection.getCT(this.tarjetProjection);
|
|
160 | 155 |
} |
161 | 156 |
} |
162 | 157 |
// ============================================ |
163 | 158 |
|
164 |
target = |
|
165 |
(FeatureStore) DATA_MANAGER.openStore( |
|
166 |
storeName, |
|
167 |
newFeatureStoreParameters); |
|
168 | 159 |
|
169 |
FeatureType targetType = target.getDefaultFeatureType();
|
|
160 |
DataManager dataManager = DALLocator.getDataManager();
|
|
170 | 161 |
|
162 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
|
163 |
this.explorerParameters.getExplorerName(), |
|
164 |
this.explorerParameters |
|
165 |
); |
|
166 |
|
|
167 |
if (this.canCreateTable) { |
|
168 |
this.createTable(explorer); |
|
169 |
} |
|
170 |
|
|
171 |
JDBCStoreParameters openParams = (JDBCStoreParameters) explorer.getOpenParameters(); |
|
172 |
openParams.setTable(this.tableName); |
|
173 |
openParams.setCRS(this.tarjetProjection); |
|
174 |
openParams.setDefaultGeometryField( |
|
175 |
source.getDefaultFeatureType().getDefaultGeometryAttributeName() |
|
176 |
); |
|
177 |
target = (FeatureStore) explorer.open(openParams); |
|
178 |
|
|
179 |
FeatureType targetFeatureType = target.getDefaultFeatureType(); |
|
180 |
|
|
171 | 181 |
target.edit(FeatureStore.MODE_APPEND); |
172 | 182 |
|
173 |
taskStatus.setRangeOfValues(0, featureSet.getSize()); |
|
174 | 183 |
int featureCount = 1; |
175 |
it1 = featureSet.fastIterator(); |
|
176 |
|
|
177 |
Geometry reproj_geom = null; |
|
178 |
|
|
179 |
while (it1.hasNext()) { |
|
180 |
Feature feature = (Feature) it1.next(); |
|
181 |
edit_feat = target.createNewFeature(targetType, feature); |
|
184 |
taskStatus.setRangeOfValues(0, featureSet.getSize()); |
|
185 |
|
|
186 |
it = featureSet.fastIterator(); |
|
187 |
while (it.hasNext()) { |
|
188 |
Feature feature = (Feature) it.next(); |
|
189 |
targetFeature = target.createNewFeature(targetFeatureType, feature); |
|
190 |
|
|
191 |
Geometry geometry = targetFeature.getDefaultGeometry(); |
|
192 |
switch (this.geometryChecks) { |
|
193 |
case CHECK_IF_CORRUPT: |
|
194 |
geometryCheck = geometry.getValidationStatus(); |
|
195 |
if (geometryCheck.getStatusCode() == Geometry.ValidationStatus.CURRUPTED) { |
|
196 |
switch (this.geometryChecksAction) { |
|
197 |
case ACTION_SET_GEOMETRY_TO_NULL: |
|
198 |
targetFeature.setDefaultGeometry(null); |
|
199 |
break; |
|
200 |
case ACTION_SKIP_FEATURE: |
|
201 |
continue; |
|
202 |
case ACTION_ABORT: |
|
203 |
default: |
|
204 |
throw new InvalidGeometryException(targetFeature, geometryCheck.getMessage()); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
break; |
|
209 |
|
|
210 |
case CHECK_IF_VALID: |
|
211 |
geometryCheck = geometry.getValidationStatus(); |
|
212 |
if (!geometryCheck.isValid()) { |
|
213 |
switch (this.geometryChecksAction) { |
|
214 |
case ACTION_SET_GEOMETRY_TO_NULL: |
|
215 |
targetFeature.setDefaultGeometry(null); |
|
216 |
break; |
|
217 |
case ACTION_SKIP_FEATURE: |
|
218 |
continue; |
|
219 |
case ACTION_ABORT: |
|
220 |
default: |
|
221 |
throw new InvalidGeometryException(targetFeature, geometryCheck.getMessage()); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
break; |
|
226 |
case CHECK_NONE: |
|
227 |
default: |
|
228 |
break; |
|
229 |
} |
|
230 |
|
|
182 | 231 |
// ================================================ |
183 | 232 |
// Reprojection |
184 | 233 |
if (geo_att != null && coord_trans != null) { |
185 |
reproj_geom = edit_feat.getDefaultGeometry();
|
|
234 |
reproj_geom = targetFeature.getDefaultGeometry();
|
|
186 | 235 |
reproj_geom = reproj_geom.cloneGeometry(); |
187 | 236 |
reproj_geom.reProject(coord_trans); |
188 |
edit_feat.setDefaultGeometry(reproj_geom);
|
|
237 |
targetFeature.setDefaultGeometry(reproj_geom);
|
|
189 | 238 |
} |
190 | 239 |
// ================================================ |
191 |
target.insert(edit_feat);
|
|
240 |
target.insert(targetFeature);
|
|
192 | 241 |
this.taskStatus.setCurValue(featureCount); |
193 | 242 |
|
194 | 243 |
if (this.taskStatus.isCancellationRequested()) { |
... | ... | |
196 | 245 |
} |
197 | 246 |
featureCount++; |
198 | 247 |
} |
199 |
edit_feat = null;
|
|
248 |
targetFeature = null;
|
|
200 | 249 |
target.finishEditing(); |
201 | 250 |
|
202 |
/* |
|
203 |
* Creating normal parameters (not "new store parameters") |
|
204 |
* to add layer |
|
205 |
*/ |
|
206 |
String storename = newFeatureStoreParameters.getDataStoreName(); |
|
207 |
JDBCStoreParameters params = getParams(explorer, tableName, schema, storename); |
|
208 |
|
|
209 |
if (geo_att != null) { |
|
210 |
params.setCRS(targetProjection); |
|
211 |
params.setDefaultGeometryField(targetType.getDefaultGeometryAttributeName()); |
|
212 |
} |
|
213 |
|
|
214 | 251 |
if (exporttoServiceFinishAction != null) { |
215 | 252 |
exporttoServiceFinishAction.finished( |
216 |
tableName + " (" + storename + ")",
|
|
217 |
params);
|
|
253 |
this.tableName + " (" + explorer.getStoreName() + ")",
|
|
254 |
openParams);
|
|
218 | 255 |
} |
219 | 256 |
|
220 | 257 |
} catch (Exception e) { |
221 | 258 |
taskStatus.message(e.getMessage()); |
222 |
throw new ExporttoServiceException(e,edit_feat); |
|
259 |
throw new ExporttoServiceException(e, targetFeature); |
|
260 |
|
|
223 | 261 |
} finally { |
224 |
if (it1 != null) {
|
|
225 |
it1.dispose();
|
|
262 |
if (it != null) { |
|
263 |
it.dispose(); |
|
226 | 264 |
} |
227 | 265 |
featureSet.dispose(); |
228 | 266 |
if (target != null) { |
... | ... | |
233 | 271 |
} |
234 | 272 |
} |
235 | 273 |
|
236 |
private JDBCStoreParameters getParams( |
|
237 |
JDBCServerExplorer explo, |
|
238 |
String tab, String sche, String storename) throws DataException { |
|
239 |
|
|
240 |
Iterator iter = explo.list().iterator(); |
|
241 |
JDBCStoreParameters item = null; |
|
242 |
while (iter.hasNext()) { |
|
243 |
item = (JDBCStoreParameters) iter.next(); |
|
244 |
if (item.getTable().compareTo(tab) == 0 |
|
245 |
&& |
|
246 |
(sche == null || item.getSchema().compareTo(sche) == 0)) { |
|
247 |
return item; |
|
248 |
} |
|
249 |
} |
|
250 |
throw new OpenException(storename, new Exception("Table not found: " + tab)); |
|
251 |
} |
|
252 |
|
|
253 |
private void initializeParams(FeatureSet featureSet) |
|
254 |
throws ExporttoServiceException { |
|
255 |
JDBCServerExplorerParameters explorerParam; |
|
256 |
try { |
|
257 |
explorerParam = |
|
258 |
(JDBCServerExplorerParameters) DATA_MANAGER |
|
259 |
.createServerExplorerParameters(explorerName); |
|
260 |
|
|
261 |
explorerParam.setHost(host); |
|
262 |
if (port > -1) { |
|
263 |
explorerParam.setPort(port); |
|
264 |
} |
|
265 |
explorerParam.setDBName(dbName); |
|
266 |
explorerParam.setUser(userName); |
|
267 |
explorerParam.setPassword(password); |
|
268 |
if (schema != null && schema.length() > 0) { |
|
269 |
explorerParam.setSchema(schema); |
|
270 |
} |
|
271 |
|
|
272 |
explorer = |
|
273 |
(JDBCServerExplorer) DATA_MANAGER.openServerExplorer( |
|
274 |
explorerName, explorerParam); |
|
275 |
|
|
276 |
newFeatureStoreParameters = |
|
277 |
(NewFeatureStoreParameters) explorer.getAddParameters(); |
|
278 |
|
|
279 |
((DBStoreParameters) newFeatureStoreParameters).setTable(tableName); |
|
280 |
((DBStoreParameters) newFeatureStoreParameters) |
|
281 |
.setDefaultGeometryField(featureSet.getDefaultFeatureType() |
|
282 |
.getDefaultGeometryAttributeName()); |
|
283 |
|
|
284 |
} catch (InitializeException e) { |
|
285 |
throw new ExporttoServiceException(e); |
|
286 |
} catch (ProviderNotRegisteredException e) { |
|
287 |
throw new ExporttoServiceException(e); |
|
288 |
} catch (ValidateDataParametersException e) { |
|
289 |
throw new ExporttoServiceException(e); |
|
290 |
} catch (DataException e) { |
|
291 |
throw new ExporttoServiceException(e); |
|
292 |
} |
|
293 |
} |
|
294 |
|
|
295 | 274 |
public void setFinishAction( |
296 |
ExporttoServiceFinishAction exporttoServiceFinishAction) { |
|
275 |
ExporttoServiceFinishAction exporttoServiceFinishAction) {
|
|
297 | 276 |
this.exporttoServiceFinishAction = exporttoServiceFinishAction; |
298 | 277 |
} |
299 | 278 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/panel/AbstractSelectTextPanel.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.exportto.swing.prov.jdbc.panel; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
|
|
28 |
import javax.swing.JTextField; |
|
29 |
|
|
30 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author gvSIG Team |
|
34 |
* @version $Id$ |
|
35 |
* |
|
36 |
*/ |
|
37 |
public abstract class AbstractSelectTextPanel extends |
|
38 |
ExporttoSwingProviderPanel { |
|
39 |
|
|
40 |
private static final long serialVersionUID = -6179384073023096591L; |
|
41 |
|
|
42 |
protected JTextField textField = null; |
|
43 |
|
|
44 |
public AbstractSelectTextPanel() { |
|
45 |
super(); |
|
46 |
initializeComponents(); |
|
47 |
} |
|
48 |
|
|
49 |
protected void initializeComponents() { |
|
50 |
this.setLayout(new BorderLayout()); |
|
51 |
textField = new JTextField(); |
|
52 |
add(textField, BorderLayout.NORTH); |
|
53 |
} |
|
54 |
|
|
55 |
public String getText() { |
|
56 |
String field = textField.getText(); |
|
57 |
if ((field == null) || (field.equals(""))) { |
|
58 |
return null; |
|
59 |
} |
|
60 |
return field; |
|
61 |
} |
|
62 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/panel/JDBCConnectionPanel.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.prov.jdbc.panel; |
25 | 25 |
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.List; |
|
26 |
import javax.swing.JComponent; |
|
27 |
import javax.swing.JPanel; |
|
28 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCProvider; |
|
30 | 29 |
|
31 | 30 |
import org.slf4j.Logger; |
32 | 31 |
import org.slf4j.LoggerFactory; |
33 | 32 |
|
34 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
|
35 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
|
36 | 33 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
37 | 34 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
38 |
import org.gvsig.fmap.dal.DALLocator; |
|
39 |
import org.gvsig.fmap.dal.DataManager; |
|
40 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
|
35 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
42 | 36 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
43 |
import org.gvsig.geodb.vectorialdb.ConnectionPanel; |
|
44 |
import org.gvsig.geodb.vectorialdb.ConnectionSettings; |
|
37 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
38 |
import org.gvsig.tools.ToolsLocator; |
|
39 |
import org.gvsig.tools.i18n.I18nManager; |
|
45 | 40 |
|
46 | 41 |
/** |
47 | 42 |
* @author gvSIG Team |
48 | 43 |
* @version $Id$ |
49 | 44 |
* |
50 | 45 |
*/ |
51 |
public class JDBCConnectionPanel extends ExporttoSwingProviderPanel { |
|
46 |
public class JDBCConnectionPanel extends JPanel implements ExporttoSwingProviderPanel {
|
|
52 | 47 |
|
53 | 48 |
private static final long serialVersionUID = -3278172717881233447L; |
54 | 49 |
|
55 |
private static final Logger LOG = LoggerFactory |
|
56 |
.getLogger(JDBCConnectionPanel.class); |
|
50 |
private static final Logger LOG = LoggerFactory.getLogger(JDBCConnectionPanel.class); |
|
51 |
private DBConnectionPanel connectionPanel = null; |
|
52 |
private final ExporttoJDBCProvider provider; |
|
57 | 53 |
|
58 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
|
59 |
private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER = |
|
60 |
ExporttoSwingLocator.getSwingManager(); |
|
61 | 54 |
|
62 |
private org.gvsig.geodb.vectorialdb.ConnectionPanel connectionPanel = null; |
|
63 |
|
|
64 |
public JDBCConnectionPanel() { |
|
65 |
super(); |
|
66 |
initializeComponents(); |
|
55 |
public JDBCConnectionPanel(ExporttoJDBCProvider provider) { |
|
56 |
this.provider = provider; |
|
57 |
initComponents(); |
|
67 | 58 |
} |
68 | 59 |
|
69 |
private void initializeComponents() { |
|
70 |
this.setLayout(new BorderLayout()); |
|
71 |
connectionPanel = new ConnectionPanel(); |
|
72 |
add(connectionPanel, BorderLayout.CENTER); |
|
73 |
initialiceExplorers(); |
|
60 |
private void initComponents() { |
|
61 |
this.connectionPanel = new DBConnectionPanel(); |
|
74 | 62 |
} |
75 | 63 |
|
76 |
@SuppressWarnings("rawtypes") |
|
77 |
private void initialiceExplorers() { |
|
78 |
List explorers = DATA_MANAGER.getExplorerProviders(); |
|
79 |
Iterator iter = explorers.iterator(); |
|
80 |
DataServerExplorerParameters exParam = null; |
|
81 |
String name; |
|
82 |
List<String> dbExplores = new ArrayList<String>(explorers.size()); |
|
83 |
while (iter.hasNext()) { |
|
84 |
name = (String) iter.next(); |
|
85 |
try { |
|
86 |
exParam = DATA_MANAGER.createServerExplorerParameters(name); |
|
87 |
} catch (DataException e) { |
|
88 |
LOG.error("Error initilializing the explorer", e); |
|
89 |
} |
|
90 |
if (exParam instanceof DBServerExplorerParameters) { |
|
91 |
dbExplores.add(name); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
connectionPanel.setDrivers(dbExplores.toArray(new String[dbExplores |
|
96 |
.size()])); |
|
64 |
public JDBCServerExplorerParameters getServerExplorerParameters() { |
|
65 |
return this.connectionPanel.getServerExplorerParameters(); |
|
97 | 66 |
} |
98 |
|
|
99 |
@Override |
|
67 |
|
|
100 | 68 |
public String getPanelTitle() { |
101 |
return EXPORTTO_SWING_MANAGER.getTranslation("connection_params"); |
|
69 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
70 |
return i18nManager.getTranslation("connection_params"); |
|
102 | 71 |
} |
103 |
|
|
104 |
@Override |
|
72 |
|
|
105 | 73 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
106 |
// ConnectionSettings connectionSettings = getConnectionSettings(); |
|
107 |
// Check parameters... |
|
108 |
return true; |
|
74 |
DBServerExplorerParameters connection = this.connectionPanel.getConnection(); |
|
75 |
try { |
|
76 |
connection.validate(); |
|
77 |
return true; |
|
78 |
} catch (ValidateDataParametersException ex) { |
|
79 |
throw new ExporttoPanelValidationException(ex.getMessageStack(),ex); |
|
80 |
} catch(Exception ex) { |
|
81 |
return false; |
|
82 |
} |
|
109 | 83 |
} |
110 | 84 |
|
111 |
public ConnectionSettings getConnectionSettings() {
|
|
112 |
return connectionPanel.getConnectionSettings();
|
|
85 |
public JComponent asJComponent() {
|
|
86 |
return this.connectionPanel;
|
|
113 | 87 |
} |
114 | 88 |
|
115 | 89 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/panel/SelectTableNamePanel.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.exportto.swing.prov.jdbc.panel; |
25 | 24 |
|
26 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
|
27 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import javax.swing.DefaultListModel; |
|
31 |
import javax.swing.JComponent; |
|
32 |
import javax.swing.JOptionPane; |
|
33 |
import org.apache.commons.lang3.StringUtils; |
|
34 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCProvider; |
|
28 | 35 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
36 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
|
37 |
import org.gvsig.fmap.dal.DALLocator; |
|
38 |
import org.gvsig.fmap.dal.DataManager; |
|
39 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
|
40 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
41 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
42 |
import org.gvsig.tools.ToolsLocator; |
|
43 |
import org.gvsig.tools.i18n.I18nManager; |
|
44 |
import org.slf4j.Logger; |
|
45 |
import org.slf4j.LoggerFactory; |
|
29 | 46 |
|
30 | 47 |
/** |
31 | 48 |
* @author gvSIG Team |
32 | 49 |
* @version $Id$ |
33 |
*
|
|
50 |
* |
|
34 | 51 |
*/ |
35 |
public class SelectTableNamePanel extends AbstractSelectTextPanel {
|
|
52 |
public class SelectTableNamePanel extends SelectTableNamePanelLayout implements ExporttoSwingProviderPanel {
|
|
36 | 53 |
|
54 |
private static final Logger logger = LoggerFactory.getLogger(SelectTableNamePanel.class); |
|
55 |
|
|
37 | 56 |
private static final long serialVersionUID = 6269512983586358017L; |
57 |
private final ExporttoJDBCProvider provider; |
|
38 | 58 |
|
39 |
private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER = |
|
40 |
ExporttoSwingLocator.getSwingManager(); |
|
59 |
private static class TableItem { |
|
41 | 60 |
|
42 |
@Override |
|
61 |
private JDBCStoreParameters params; |
|
62 |
private String label; |
|
63 |
|
|
64 |
public TableItem(String label, JDBCStoreParameters params) { |
|
65 |
this.params = params; |
|
66 |
this.label = label; |
|
67 |
} |
|
68 |
|
|
69 |
public TableItem(JDBCStoreParameters params) { |
|
70 |
this(params.getSchema() + "." + params.getTable(), params); |
|
71 |
} |
|
72 |
|
|
73 |
public String toString() { |
|
74 |
return this.label; |
|
75 |
} |
|
76 |
|
|
77 |
public JDBCStoreParameters getParams() { |
|
78 |
return this.params; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
public SelectTableNamePanel(ExporttoJDBCProvider provider) { |
|
83 |
this.provider = provider; |
|
84 |
} |
|
85 |
|
|
86 |
private void initComponents() { |
|
87 |
this.rdoCreateTable.addActionListener(new ActionListener() { |
|
88 |
public void actionPerformed(ActionEvent e) { |
|
89 |
onChangeRadioSelecion(); |
|
90 |
} |
|
91 |
}); |
|
92 |
this.rdoInsert.addActionListener(new ActionListener() { |
|
93 |
public void actionPerformed(ActionEvent e) { |
|
94 |
onChangeRadioSelecion(); |
|
95 |
} |
|
96 |
}); |
|
97 |
this.fillTablesList(); |
|
98 |
} |
|
99 |
|
|
100 |
public boolean canCreateTable() { |
|
101 |
return this.rdoCreateTable.isSelected(); |
|
102 |
} |
|
103 |
|
|
104 |
public String getSchema() { |
|
105 |
if (this.canCreateTable()) { |
|
106 |
return StringUtils.defaultIfBlank(this.txtSchema.getText(), null); |
|
107 |
} |
|
108 |
JDBCStoreParameters table = (JDBCStoreParameters) this.lstTables.getSelectedValue(); |
|
109 |
if( table == null ) { |
|
110 |
return null; |
|
111 |
} |
|
112 |
return table.getSchema(); |
|
113 |
} |
|
114 |
|
|
115 |
public String getTableName() { |
|
116 |
if (this.canCreateTable()) { |
|
117 |
return StringUtils.defaultIfBlank(this.txtSchema.getText(), null); |
|
118 |
} |
|
119 |
JDBCStoreParameters table = (JDBCStoreParameters) this.lstTables.getSelectedValue(); |
|
120 |
if( table == null ) { |
|
121 |
return null; |
|
122 |
} |
|
123 |
return table.getTable(); |
|
124 |
} |
|
125 |
|
|
43 | 126 |
public String getPanelTitle() { |
44 |
return EXPORTTO_SWING_MANAGER.getTranslation("intro_tablename"); |
|
127 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
128 |
return i18nManager.getTranslation("intro_tablename"); |
|
45 | 129 |
} |
46 | 130 |
|
47 |
@Override |
|
48 | 131 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
49 |
if (getText() == null || getText().equals("")) {
|
|
132 |
if (this.getTableName() == null) {
|
|
50 | 133 |
throw new ExporttoPanelValidationException( |
51 |
"The table cannot be empty"); |
|
134 |
"The table cannot be empty");
|
|
52 | 135 |
} |
136 |
if (this.getSchema() == null) { |
|
137 |
throw new ExporttoPanelValidationException( |
|
138 |
"The schema cannot be empty"); |
|
139 |
} |
|
53 | 140 |
return true; |
54 | 141 |
} |
142 |
|
|
143 |
public JComponent asJComponent() { |
|
144 |
return this; |
|
145 |
} |
|
146 |
|
|
147 |
public void onChangeRadioSelecion() { |
|
148 |
if (this.rdoCreateTable.isSelected()) { |
|
149 |
this.txtSchema.setEnabled(true); |
|
150 |
this.txtTableName.setEnabled(true); |
|
151 |
this.lstTables.setEnabled(false); |
|
152 |
} else { |
|
153 |
this.txtSchema.setEnabled(false); |
|
154 |
this.txtTableName.setEnabled(false); |
|
155 |
this.lstTables.setEnabled(true); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
private void fillTablesList() { |
|
160 |
JDBCServerExplorerParameters explorerParameters = this.provider.getExplorerParameters(); |
|
161 |
if (explorerParameters == null) { |
|
162 |
return; |
|
163 |
} |
|
164 |
DefaultListModel lmodel = new DefaultListModel(); |
|
165 |
DataManager dataManager = DALLocator.getDataManager(); |
|
166 |
try { |
|
167 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
|
168 |
explorerParameters.getExplorerName(), |
|
169 |
explorerParameters |
|
170 |
); |
|
171 |
List<JDBCStoreParameters> tables = explorer.list(); |
|
172 |
Iterator<JDBCStoreParameters> it = tables.iterator(); |
|
173 |
while (it.hasNext()) { |
|
174 |
JDBCStoreParameters table = it.next(); |
|
175 |
lmodel.addElement(new TableItem(table)); |
|
176 |
} |
|
177 |
} catch (Exception ex) { |
|
178 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
179 |
logger.warn("Can't retrive the list of tables of "+explorerParameters.toString(),ex); |
|
180 |
JOptionPane.showMessageDialog( |
|
181 |
this, |
|
182 |
i18nManager.getTranslation("_Cant_retrive_tables_information"), |
|
183 |
i18nManager.getTranslation("_Warning"), |
|
184 |
JOptionPane.WARNING_MESSAGE |
|
185 |
); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
55 | 189 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/panel/SelectPkPanel.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.prov.jdbc.panel; |
25 | 25 |
|
26 |
import java.awt.BorderLayout; |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import javax.swing.JComponent; |
|
29 |
import org.apache.commons.lang3.StringUtils; |
|
30 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCProvider; |
|
27 | 31 |
|
28 |
import javax.swing.JLabel; |
|
29 |
import javax.swing.JPanel; |
|
30 |
import javax.swing.JTextField; |
|
31 |
|
|
32 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
|
33 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
|
34 | 32 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
33 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
|
35 | 34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
36 | 35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
36 |
import org.gvsig.tools.ToolsLocator; |
|
37 |
import org.gvsig.tools.i18n.I18nManager; |
|
37 | 38 |
|
38 | 39 |
/** |
39 | 40 |
* @author gvSIG Team |
40 | 41 |
* @version $Id$ |
41 | 42 |
* |
42 | 43 |
*/ |
43 |
public class SelectPkPanel extends AbstractSelectTextPanel {
|
|
44 |
public class SelectPkPanel extends SelectPkPanelLayout implements ExporttoSwingProviderPanel {
|
|
44 | 45 |
|
45 | 46 |
private static final long serialVersionUID = 2652404227373508779L; |
46 |
|
|
47 |
private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER = |
|
48 |
ExporttoSwingLocator.getSwingManager(); |
|
49 | 47 |
|
50 | 48 |
private FeatureType featType = null; |
49 |
private ExporttoJDBCProvider provider; |
|
51 | 50 |
|
52 |
public SelectPkPanel() { |
|
53 |
super();
|
|
51 |
public SelectPkPanel(ExporttoJDBCProvider provider) {
|
|
52 |
this.provider = provider;
|
|
54 | 53 |
} |
55 | 54 |
|
56 |
public SelectPkPanel(FeatureType ft) { |
|
57 |
super();
|
|
55 |
public SelectPkPanel(ExporttoJDBCProvider provider,FeatureType ft) {
|
|
56 |
this(provider);
|
|
58 | 57 |
featType = ft; |
59 | 58 |
} |
60 | 59 |
|
61 |
protected void initializeComponents() { |
|
62 |
this.setLayout(new BorderLayout()); |
|
60 |
protected void initComponents() { |
|
61 |
this.chkCreatePrimaryKey.addActionListener(new ActionListener() { |
|
62 |
public void actionPerformed(ActionEvent e) { |
|
63 |
onChangeCreatePrimaryKey(); |
|
64 |
} |
|
65 |
}); |
|
66 |
this.translateControls(); |
|
67 |
} |
|
68 |
|
|
69 |
private void onChangeCreatePrimaryKey() { |
|
70 |
this.txtPrimaryKeyName.setEnabled(this.chkCreatePrimaryKey.isSelected()); |
|
71 |
} |
|
72 |
|
|
73 |
protected void translateControls() { |
|
74 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
63 | 75 |
|
64 |
JPanel topPanel = new JPanel(new BorderLayout()); |
|
65 |
textField = new JTextField(); |
|
66 |
|
|
67 |
String msg = EXPORTTO_SWING_MANAGER.getTranslation( |
|
68 |
"_Enter_new_field_name_for_primary_key_or_blank_to_not_add_primary_key"); |
|
69 |
topPanel.add(new JLabel(msg + ":"), BorderLayout.NORTH); |
|
70 |
topPanel.add(textField, BorderLayout.CENTER); |
|
71 |
// ============================================== |
|
72 |
add(topPanel, BorderLayout.NORTH); |
|
73 | 76 |
} |
74 | 77 |
|
75 |
public String getText() { |
|
76 |
String field = textField.getText(); |
|
77 |
if ((field == null) || (field.trim().equals(""))) { |
|
78 |
public String getPrimaryKeyName() { |
|
79 |
if( !this.chkCreatePrimaryKey.isSelected() ) { |
|
78 | 80 |
return null; |
79 | 81 |
} |
80 |
return field; |
|
82 |
String pkname = this.txtPrimaryKeyName.getText(); |
|
83 |
if( StringUtils.isBlank(pkname) ) { |
|
84 |
return null; |
|
85 |
} |
|
86 |
return pkname.trim(); |
|
81 | 87 |
} |
82 |
|
|
83 | 88 |
|
84 |
@Override |
|
85 | 89 |
public String getPanelTitle() { |
86 |
return EXPORTTO_SWING_MANAGER.getTranslation("_Primary_key"); |
|
90 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
91 |
return i18nManager.getTranslation("_Primary_key"); |
|
87 | 92 |
} |
88 | 93 |
|
89 |
@Override |
|
90 | 94 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
91 |
String txt = this.getText(); |
|
92 |
if (isFieldName(txt, featType)) { |
|
95 |
String pkname = this.getPrimaryKeyName(); |
|
96 |
if (isFieldName(pkname, this.featType)) { |
|
97 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
93 | 98 |
throw new ExporttoPanelValidationException( |
94 |
EXPORTTO_SWING_MANAGER.getTranslation( |
|
95 |
"_Field_name_already_exists")); |
|
99 |
i18nManager.getTranslation("_Field_name_already_exists")); |
|
96 | 100 |
} |
97 | 101 |
return true; |
98 | 102 |
} |
99 | 103 |
|
100 |
private boolean isFieldName(String txt, FeatureType ft) { |
|
101 |
|
|
102 |
if (ft == null || txt == null) { |
|
104 |
private boolean isFieldName(String name, FeatureType ft) { |
|
105 |
if (ft == null || name == null) { |
|
103 | 106 |
return false; |
104 | 107 |
} |
105 |
|
|
106 | 108 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors(); |
107 | 109 |
for (int i=0; i<atts.length; i++) { |
108 |
if (atts[i].getName().equals(txt)) {
|
|
110 |
if (atts[i].getName().equalsIgnoreCase(name)) {
|
|
109 | 111 |
return true; |
110 | 112 |
} |
111 | 113 |
} |
112 | 114 |
return false; |
113 | 115 |
} |
116 |
|
|
117 |
public JComponent asJComponent() { |
|
118 |
return this; |
|
119 |
} |
|
114 | 120 |
|
115 | 121 |
|
116 |
|
|
117 |
|
|
118 | 122 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.postgresql/src/main/java/org/gvsig/exportto/swing/prov/postgresql/ExporttoPostgreSQLProvider.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
* Constructor. |
44 |
* |
|
45 |
* @param providerServices |
|
46 |
* the services for the provider |
|
47 |
* @param file |
|
48 |
* to get the Exporto from |
|
49 | 44 |
*/ |
50 | 45 |
public ExporttoPostgreSQLProvider(ProviderServices providerServices, |
51 | 46 |
FeatureStore featureStore, IProjection projection) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.generic/src/main/java/org/gvsig/exportto/swing/prov/generic/panel/AbstractExporttoGenericPanel.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.exportto.swing.prov.generic.panel; |
25 | 25 |
|
26 |
import javax.swing.JComponent; |
|
27 |
import javax.swing.JPanel; |
|
26 | 28 |
import org.gvsig.exportto.swing.ExporttoSwingLocator; |
27 | 29 |
import org.gvsig.exportto.swing.ExporttoSwingManager; |
28 | 30 |
import org.gvsig.exportto.swing.prov.generic.ExporttoGenericProvider; |
... | ... | |
33 | 35 |
* @version $Id$ |
34 | 36 |
* |
35 | 37 |
*/ |
36 |
public abstract class AbstractExporttoGenericPanel extends |
|
38 |
public abstract class AbstractExporttoGenericPanel extends JPanel implements
|
|
37 | 39 |
ExporttoSwingProviderPanel { |
38 | 40 |
|
39 | 41 |
private static final long serialVersionUID = -7994157431819798158L; |
... | ... | |
47 | 49 |
super(); |
48 | 50 |
this.exporttoGenericProvider = exporttoGenericProvider; |
49 | 51 |
} |
52 |
|
|
53 |
public JComponent asJComponent() { |
|
54 |
return this; |
|
55 |
} |
|
56 |
|
|
57 |
|
|
50 | 58 |
} |
Also available in: Unified diff