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 / export / jdbc / swing / panels / JDBCConnectionPanel.java @ 43925

History | View | Annotate | Download (3.91 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.export.jdbc.swing.panels;
25

    
26
import javax.swing.JComponent;
27
import org.gvsig.export.jdbc.service.ExportJDBCParameters;
28
import org.gvsig.export.swing.JExportProcessPanel;
29
import org.gvsig.export.swing.spi.ExportPanel;
30
import org.gvsig.export.swing.spi.ExportPanelValidationException;
31

    
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
36
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
37
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
38
import org.gvsig.fmap.dal.swing.DALSwingLocator;
39
import org.gvsig.fmap.dal.swing.DataSwingManager;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.i18n.I18nManager;
42

    
43
/**
44
 * @author gvSIG Team
45
 * @version $Id$
46
 * 
47
 */
48
public class JDBCConnectionPanel  
49
        implements ExportPanel 
50
    {
51

    
52
    private static final long serialVersionUID = -3278172717881233447L;
53

    
54
    private static final Logger LOG = LoggerFactory.getLogger(JDBCConnectionPanel.class);
55
    private org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel connectionPanel;
56
    private final ExportJDBCParameters parameters;
57
    private final JExportProcessPanel processPanel;
58

    
59
    public JDBCConnectionPanel(
60
            JExportProcessPanel processPanel, 
61
            ExportJDBCParameters parameters
62
        ) {
63
        this.processPanel = processPanel;
64
        this.parameters = parameters;
65
        initComponents();
66
    }
67

    
68
    private void initComponents() {
69
        DataSwingManager manager = DALSwingLocator.getSwingManager();
70
        this.connectionPanel = manager.createJDBCConnectionPanel();
71
    }
72
    
73
    @Override
74
    public void enterPanel() {
75
        // Default do nothing
76
    }
77
    
78
    public JDBCServerExplorerParameters getServerExplorerParameters() {
79
        return this.connectionPanel.getServerExplorerParameters();
80
    }
81

    
82
    @Override
83
    public String getIdPanel() {
84
        return this.getClass().getCanonicalName();
85
    }
86

    
87
    @Override
88
    public String getTitlePanel() {
89
        I18nManager i18nManager = ToolsLocator.getI18nManager();
90
        return i18nManager.getTranslation("connection_params");
91
    }
92

    
93
    @Override
94
    public void exitPanel() {
95
        this.parameters.setExplorerParameters(this.getServerExplorerParameters());
96
    }
97

    
98
    @Override
99
    public boolean validatePanel() throws ExportPanelValidationException {
100
        DBServerExplorerParameters connection = this.connectionPanel.getServerExplorerParameters();
101
        if( connection==null ) {
102
            return false;
103
        }
104
        try {
105
            connection.validate();
106
            this.parameters.setExplorerParameters(this.getServerExplorerParameters());
107
            return true;
108
        } catch (ValidateDataParametersException ex) {
109
            throw new ExportPanelValidationException(ex.getMessageStack(),ex);
110
        } catch(Exception ex) {
111
            return false;
112
        }
113
    }
114

    
115
    @Override
116
    public JComponent asJComponent() {
117
        return this.connectionPanel.asJComponent();
118
    }
119

    
120
}