Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / DlgConnection.java @ 40557

History | View | Annotate | Download (6.37 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.geodb.vectorialdb;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.event.ActionListener;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.Iterator;
31
import java.util.List;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JDialog;
35
import javax.swing.JOptionPane;
36
import javax.swing.JPanel;
37

    
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.messages.NotificationManager;
40
import org.gvsig.fmap.dal.DALLocator;
41
import org.gvsig.fmap.dal.DataManager;
42
import org.gvsig.fmap.dal.DataServerExplorerParameters;
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
45
import org.gvsig.gui.beans.AcceptCancelPanel;
46
import org.gvsig.utils.NotExistInXMLEntity;
47
import org.gvsig.utils.XMLEntity;
48

    
49

    
50
public class DlgConnection extends JDialog {
51

    
52
    private JPanel jContentPane = null;
53
    private ConnectionPanel jConnPanel = null;
54
    private JButton jBtnOK = null;
55
    private JPanel jPanel1 = null;
56
    private JButton jBtnCancel = null;
57
    private ConnectionSettings connSettings = null;
58

    
59
    /**
60
     * This is the default constructor
61
     */
62
    public DlgConnection() {
63
        super();
64
        initialize();
65
    }
66

    
67
    private void setPreferences()
68
    {
69
        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
70

    
71
        if (xml == null) {
72
            xml = new XMLEntity();
73
        }
74

    
75
        if (!xml.contains("db-connections")) {
76
            String[] servers = new String[0];
77
            xml.putProperty("db-connections", servers);
78
        }
79

    
80
        try {
81
            String[] servers = xml.getStringArrayProperty("db-connections");
82
            HashMap settings = new HashMap();
83
            for (int i = 0; i < servers.length; i++) {
84
                ConnectionSettings cs = new ConnectionSettings();
85
                cs.setFromString(servers[i]);
86
                settings.put(cs.getName(), cs);
87
            }
88
            getJConnPanel().setSettings(settings);
89
        } catch (NotExistInXMLEntity e) {
90
        }
91

    
92
    }
93
    /**
94
     * This method initializes this
95
     *
96
     * @return void
97
     */
98
    private void initialize() {
99
        this.setSize(320, 332);
100
        this.setTitle(PluginServices.getText(this, "database_connection"));
101
        this.setContentPane(getJContentPane());
102
        setPreferences();
103
        DataManager dm= DALLocator.getDataManager();
104
        List explorers = dm.getExplorerProviders();
105
        Iterator iter = explorers.iterator();
106
                DataServerExplorerParameters exParam = null;
107
                String name;
108
                List<String> dbExplores = new ArrayList<String>(explorers.size());
109
                while (iter.hasNext()) {
110
                        name = (String) iter.next();
111
                        try {
112
                                exParam = dm.createServerExplorerParameters(name);
113
                        } catch (DataException e) {
114
                                NotificationManager.addError(e);
115
                        }
116
                        if (exParam instanceof DBServerExplorerParameters) {
117
                                dbExplores.add(name);
118
                        }
119
                }
120

    
121

    
122

    
123
        jConnPanel
124
                                .setDrivers(dbExplores
125
                                .toArray(new String[dbExplores.size()]));
126
    }
127

    
128
//    private String[] getDriverNames(){
129
//        Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
130
//
131
//        ArrayList ret = new ArrayList();
132
//        String[] driverNames = LayerFactory.getDM().getDriverNames();
133
//
134
//        for (int i = 0; i < driverNames.length; i++) {
135
//            boolean is = false;
136
//
137
//            for (int j = 0; j < classes.length; j++) {
138
//                if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
139
//                    ret.add(driverNames[i]);
140
//                }
141
//            }
142
//        }
143
//
144
//        return (String[]) ret.toArray(new String[0]);
145
//
146
//    }
147

    
148
    /**
149
     * This method initializes jContentPane
150
     *
151
     * @return javax.swing.JPanel
152
     */
153
    private JPanel getJContentPane() {
154
        if (jContentPane == null) {
155
            jContentPane = new JPanel();
156
            jContentPane.setLayout(new BorderLayout());
157
            jContentPane.add(getJConnPanel(), java.awt.BorderLayout.CENTER);
158
            jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
159

    
160
        }
161
        return jContentPane;
162
    }
163

    
164
    /**
165
     * This method initializes jPanel
166
     *
167
     * @return javax.swing.JPanel
168
     */
169
    private ConnectionPanel getJConnPanel() {
170
            if (jConnPanel == null) {
171
                    jConnPanel = new ConnectionPanel();
172
            }
173
            return jConnPanel;
174
    }
175

    
176

    
177

    
178
    /**
179
     * This method initializes jPanel1
180
     *
181
     * @return javax.swing.JPanel
182
     */
183
    private JPanel getJPanel1() {
184
            if (jPanel1 == null) {
185
                    ActionListener okAction = new java.awt.event.ActionListener() {
186
                public void actionPerformed(java.awt.event.ActionEvent e) {
187
                        if (!jConnPanel.done()) {
188
                                JOptionPane.showMessageDialog(DlgConnection.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE);
189
                                return;
190
                        }
191
                        jConnPanel.saveConnectionSettings();
192
                    connSettings = jConnPanel.getConnectionSettings();
193
                    dispose();
194
                }
195
                    };
196

    
197
            ActionListener cancelAction = new java.awt.event.ActionListener() {
198
                            public void actionPerformed(java.awt.event.ActionEvent e) {
199
                    connSettings = null;
200
                                    dispose();
201
                            }
202
                    };
203
                    jPanel1 = new AcceptCancelPanel(okAction, cancelAction);
204

    
205

    
206
            }
207
            return jPanel1;
208
    }
209

    
210

    
211
    public ConnectionSettings getConnSettings() {
212
        return connSettings;
213
    }
214

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