Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / DlgConnection.java @ 29628

History | View | Annotate | Download (6.66 KB)

1
/*
2
 * Created on 26-oct-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package org.gvsig.geodb.vectorialdb;
45

    
46
import java.awt.BorderLayout;
47
import java.awt.event.ActionListener;
48
import java.util.ArrayList;
49
import java.util.HashMap;
50
import java.util.Iterator;
51
import java.util.List;
52

    
53
import javax.swing.JButton;
54
import javax.swing.JDialog;
55
import javax.swing.JOptionPane;
56
import javax.swing.JPanel;
57

    
58
import org.gvsig.andami.PluginServices;
59
import org.gvsig.andami.messages.NotificationManager;
60
import org.gvsig.fmap.dal.DALLocator;
61
import org.gvsig.fmap.dal.DataManager;
62
import org.gvsig.fmap.dal.DataServerExplorerParameters;
63
import org.gvsig.fmap.dal.exception.DataException;
64
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
65
import org.gvsig.gui.beans.AcceptCancelPanel;
66
import org.gvsig.utils.NotExistInXMLEntity;
67
import org.gvsig.utils.XMLEntity;
68

    
69

    
70
public class DlgConnection extends JDialog {
71

    
72
    private JPanel jContentPane = null;
73
    private ConnectionPanel jConnPanel = null;
74
    private JButton jBtnOK = null;
75
    private JPanel jPanel1 = null;
76
    private JButton jBtnCancel = null;
77
    private ConnectionSettings connSettings = null;
78

    
79
    /**
80
     * This is the default constructor
81
     */
82
    public DlgConnection() {
83
        super();
84
        initialize();
85
    }
86

    
87
    private void setPreferences()
88
    {
89
        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
90

    
91
        if (xml == null) {
92
            xml = new XMLEntity();
93
        }
94

    
95
        if (!xml.contains("db-connections")) {
96
            String[] servers = new String[0];
97
            xml.putProperty("db-connections", servers);
98
        }
99

    
100
        try {
101
            String[] servers = xml.getStringArrayProperty("db-connections");
102
            HashMap settings = new HashMap();
103
            for (int i = 0; i < servers.length; i++) {
104
                ConnectionSettings cs = new ConnectionSettings();
105
                cs.setFromString(servers[i]);
106
                settings.put(cs.getName(), cs);
107
            }
108
            getJConnPanel().setSettings(settings);
109
        } catch (NotExistInXMLEntity e) {
110
        }
111

    
112
    }
113
    /**
114
     * This method initializes this
115
     *
116
     * @return void
117
     */
118
    private void initialize() {
119
        this.setSize(320, 332);
120
        this.setTitle(PluginServices.getText(this, "database_connection"));
121
        this.setContentPane(getJContentPane());
122
        setPreferences();
123
        DataManager dm= DALLocator.getDataManager();
124
        List explorers = dm.getExplorerProviders();
125
        Iterator iter = explorers.iterator();
126
                DataServerExplorerParameters exParam = null;
127
                String name;
128
                List<String> dbExplores = new ArrayList<String>(explorers.size());
129
                while (iter.hasNext()) {
130
                        name = (String) iter.next();
131
                        try {
132
                                exParam = dm.createServerExplorerParameters(name);
133
                        } catch (DataException e) {
134
                                NotificationManager.addError(e);
135
                        }
136
                        if (exParam instanceof DBServerExplorerParameters) {
137
                                dbExplores.add(name);
138
                        }
139
                }
140

    
141

    
142

    
143
        jConnPanel
144
                                .setDrivers(dbExplores
145
                                .toArray(new String[dbExplores.size()]));
146
    }
147

    
148
//    private String[] getDriverNames(){
149
//        Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
150
//
151
//        ArrayList ret = new ArrayList();
152
//        String[] driverNames = LayerFactory.getDM().getDriverNames();
153
//
154
//        for (int i = 0; i < driverNames.length; i++) {
155
//            boolean is = false;
156
//
157
//            for (int j = 0; j < classes.length; j++) {
158
//                if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
159
//                    ret.add(driverNames[i]);
160
//                }
161
//            }
162
//        }
163
//
164
//        return (String[]) ret.toArray(new String[0]);
165
//
166
//    }
167

    
168
    /**
169
     * This method initializes jContentPane
170
     *
171
     * @return javax.swing.JPanel
172
     */
173
    private JPanel getJContentPane() {
174
        if (jContentPane == null) {
175
            jContentPane = new JPanel();
176
            jContentPane.setLayout(new BorderLayout());
177
            jContentPane.add(getJConnPanel(), java.awt.BorderLayout.CENTER);
178
            jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
179

    
180
        }
181
        return jContentPane;
182
    }
183

    
184
    /**
185
     * This method initializes jPanel
186
     *
187
     * @return javax.swing.JPanel
188
     */
189
    private ConnectionPanel getJConnPanel() {
190
            if (jConnPanel == null) {
191
                    jConnPanel = new ConnectionPanel();
192
            }
193
            return jConnPanel;
194
    }
195

    
196

    
197

    
198
    /**
199
     * This method initializes jPanel1
200
     *
201
     * @return javax.swing.JPanel
202
     */
203
    private JPanel getJPanel1() {
204
            if (jPanel1 == null) {
205
                    ActionListener okAction = new java.awt.event.ActionListener() {
206
                public void actionPerformed(java.awt.event.ActionEvent e) {
207
                        if (!jConnPanel.done()) {
208
                                JOptionPane.showMessageDialog(DlgConnection.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE);
209
                                return;
210
                        }
211
                        jConnPanel.saveConnectionSettings();
212
                    connSettings = jConnPanel.getConnectionSettings();
213
                    dispose();
214
                }
215
                    };
216

    
217
            ActionListener cancelAction = new java.awt.event.ActionListener() {
218
                            public void actionPerformed(java.awt.event.ActionEvent e) {
219
                    connSettings = null;
220
                                    dispose();
221
                            }
222
                    };
223
                    jPanel1 = new AcceptCancelPanel(okAction, cancelAction);
224

    
225

    
226
            }
227
            return jPanel1;
228
    }
229

    
230

    
231
    public ConnectionSettings getConnSettings() {
232
        return connSettings;
233
    }
234

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