Statistics
| Revision:

svn-gvsig-desktop / 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 / BaseExporttoJDBCProvider.java @ 41492

History | View | Annotate | Download (6.39 KB)

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;
25

    
26
import java.util.ArrayList;
27
import java.util.List;
28
import java.util.logging.Level;
29
import javax.swing.DefaultListModel;
30
import org.cresques.cts.IProjection;
31
import org.gvsig.exportto.ExporttoService;
32
import org.gvsig.exportto.swing.prov.jdbc.panel.CheckGeometriesPanel;
33
import org.gvsig.exportto.swing.prov.jdbc.panel.JDBCConnectionPanel;
34
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectPkPanel;
35
import org.gvsig.exportto.swing.prov.jdbc.panel.SelectTableNamePanel;
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.exception.InitializeException;
40
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
41
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
42
import org.gvsig.fmap.dal.feature.FeatureStore;
43
import org.gvsig.fmap.dal.feature.FeatureType;
44
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer;
45
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
46
import org.gvsig.tools.service.spi.AbstractProvider;
47
import org.gvsig.tools.service.spi.ProviderServices;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

    
51
/**
52
 * Exporto provider which gets Exporto from a file.
53
 *
54
 * @author gvSIG Team
55
 * @version $Id$
56
 */
57
public class BaseExporttoJDBCProvider extends AbstractProvider
58
        implements ExporttoJDBCProvider {
59

    
60
    private static Logger logger = LoggerFactory.getLogger(
61
            BaseExporttoJDBCProvider.class);
62

    
63
    protected List<ExporttoSwingProviderPanel> panels = new ArrayList<ExporttoSwingProviderPanel>();
64

    
65
    protected FeatureStore sourceStore;
66
    protected IProjection projection;
67
    private final JDBCConnectionPanel connectionPanel;
68
    private final SelectPkPanel selectPkPanel;
69
    private final SelectTableNamePanel selectTableNamePanel;
70
    private final CheckGeometriesPanel checkGeometriesPanel;
71

    
72
    private String storeName = null;
73

    
74
    public BaseExporttoJDBCProvider(ProviderServices providerServices,
75
            FeatureStore sourceStore, IProjection projection) {
76
        super(providerServices);
77
        this.sourceStore = sourceStore;
78
        this.projection = projection;
79

    
80
        FeatureType ftype = null;
81
        try {
82
            ftype = sourceStore.getDefaultFeatureType();
83
        } catch (Exception exc) {
84
            logger.warn("Can't retrieve the feature type to use in the export to JDBC panel.", exc);
85

    
86
        }
87
        this.connectionPanel = new JDBCConnectionPanel(this);
88
        this.selectTableNamePanel = new SelectTableNamePanel(this);
89
        this.selectPkPanel = new SelectPkPanel(this);
90
        this.checkGeometriesPanel = new CheckGeometriesPanel(this);
91

    
92
        this.panels.add(this.connectionPanel);
93
        this.panels.add(this.selectTableNamePanel);
94
        this.panels.add(this.selectPkPanel);
95
        this.panels.add(this.checkGeometriesPanel);
96
    }
97

    
98
    public int getPanelCount() {
99
        return this.panels.size();
100
    }
101

    
102
    public ExporttoSwingProviderPanel getPanelAt(int index) {
103
        return this.panels.get(index);
104
    }
105

    
106
    public FeatureStore getSource() {
107
        return this.sourceStore;
108
    }
109

    
110
    public ExporttoService createExporttoService() {
111
        JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
112
        explorerParameters.setSchema(this.getSchema());
113
        return new ExporrtoJDBCService(
114
                sourceStore,
115
                explorerParameters,
116
                this.getTableName(),
117
                this.getPrimaryKey(),
118
                this.projection,
119
                this.canCreatetable(),
120
                this.getGeometryChecks(),
121
                this.getGeometryChecksAction(),
122
                this.getTryToFixGeometry()
123
        );
124
    }
125

    
126
    public JDBCServerExplorerParameters getExplorerParameters() {
127
        return this.connectionPanel.getServerExplorerParameters();
128
    }
129

    
130
    public String getSchema() {
131
        return this.selectTableNamePanel.getSchema();
132
    }
133

    
134
    public String getTableName() {
135
        return this.selectTableNamePanel.getTableName();
136
    }
137

    
138
    public boolean canCreatetable() {
139
        return this.selectTableNamePanel.canCreateTable();
140
    }
141

    
142
    public String getPrimaryKey() {
143
        return this.selectPkPanel.getPrimaryKeyName();
144
    }
145

    
146
    public int getGeometryChecks() {
147
        return this.checkGeometriesPanel.getGeometryChecks();
148
    }
149

    
150
    public int getGeometryChecksAction() {
151
        return this.checkGeometriesPanel.getGeometryChecksAction();
152
    }
153

    
154
    public boolean getTryToFixGeometry() {
155
        return this.checkGeometriesPanel.getTryToFixGeometry();
156
    }
157

    
158
    public String getExplorerName() {
159
        return this.connectionPanel.getServerExplorerParameters().getExplorerName();
160
    }
161

    
162
    public String getStoreName() {
163
        if ( this.storeName == null ) {
164
            try {
165
                JDBCServerExplorerParameters explorerParameters = this.getExplorerParameters();
166
                if ( explorerParameters == null ) {
167
                    return null;
168
                }
169
                DataManager dataManager = DALLocator.getDataManager();
170

    
171
                JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer(
172
                        explorerParameters.getExplorerName(),
173
                        explorerParameters
174
                );
175
                this.storeName = explorer.getStoreName();
176
            } catch (Exception ex) {
177
                return null;
178
            }
179
        }
180
        return this.storeName;
181
    }
182

    
183
}