svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / vectorialdb / DlgConnection.java @ 25065
History | View | Annotate | Download (5.88 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 com.iver.cit.gvsig.vectorialdb; |
45 |
|
46 |
import java.awt.BorderLayout; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.HashMap; |
49 |
|
50 |
import javax.swing.JButton; |
51 |
import javax.swing.JDialog; |
52 |
import javax.swing.JOptionPane; |
53 |
import javax.swing.JPanel; |
54 |
|
55 |
import org.gvsig.fmap.dal.DALLocator; |
56 |
import org.gvsig.fmap.dal.DataManager; |
57 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.utiles.NotExistInXMLEntity; |
61 |
import com.iver.utiles.XMLEntity; |
62 |
|
63 |
public class DlgConnection extends JDialog { |
64 |
|
65 |
private JPanel jContentPane = null; |
66 |
private ConnectionPanel jConnPanel = null; |
67 |
private JButton jBtnOK = null; |
68 |
private JPanel jPanel1 = null; |
69 |
private JButton jBtnCancel = null; |
70 |
private ConnectionSettings connSettings = null; |
71 |
|
72 |
/**
|
73 |
* This is the default constructor
|
74 |
*/
|
75 |
public DlgConnection() {
|
76 |
super();
|
77 |
initialize(); |
78 |
} |
79 |
|
80 |
private void setPreferences() |
81 |
{ |
82 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
83 |
|
84 |
if (xml == null) { |
85 |
xml = new XMLEntity();
|
86 |
} |
87 |
|
88 |
if (!xml.contains("db-connections")) { |
89 |
String[] servers = new String[0]; |
90 |
xml.putProperty("db-connections", servers);
|
91 |
} |
92 |
|
93 |
try {
|
94 |
String[] servers = xml.getStringArrayProperty("db-connections"); |
95 |
HashMap settings = new HashMap(); |
96 |
for (int i = 0; i < servers.length; i++) { |
97 |
ConnectionSettings cs = new ConnectionSettings();
|
98 |
cs.setFromString(servers[i]); |
99 |
settings.put(cs.getName(), cs); |
100 |
} |
101 |
getJConnPanel().setSettings(settings); |
102 |
} catch (NotExistInXMLEntity e) {
|
103 |
} |
104 |
|
105 |
} |
106 |
/**
|
107 |
* This method initializes this
|
108 |
*
|
109 |
* @return void
|
110 |
*/
|
111 |
private void initialize() { |
112 |
this.setSize(320, 332); |
113 |
this.setTitle(PluginServices.getText(this, "database_connection")); |
114 |
this.setContentPane(getJContentPane());
|
115 |
setPreferences(); |
116 |
DataManager dm= DALLocator.getDataManager(); |
117 |
String[] explorers=(String[])dm.getExplorerProviders().toArray(new String[0]); |
118 |
jConnPanel.setDrivers(explorers); |
119 |
} |
120 |
|
121 |
// private String[] getDriverNames(){
|
122 |
// Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
|
123 |
//
|
124 |
// ArrayList ret = new ArrayList();
|
125 |
// String[] driverNames = LayerFactory.getDM().getDriverNames();
|
126 |
//
|
127 |
// for (int i = 0; i < driverNames.length; i++) {
|
128 |
// boolean is = false;
|
129 |
//
|
130 |
// for (int j = 0; j < classes.length; j++) {
|
131 |
// if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
|
132 |
// ret.add(driverNames[i]);
|
133 |
// }
|
134 |
// }
|
135 |
// }
|
136 |
//
|
137 |
// return (String[]) ret.toArray(new String[0]);
|
138 |
//
|
139 |
// }
|
140 |
|
141 |
/**
|
142 |
* This method initializes jContentPane
|
143 |
*
|
144 |
* @return javax.swing.JPanel
|
145 |
*/
|
146 |
private JPanel getJContentPane() { |
147 |
if (jContentPane == null) { |
148 |
jContentPane = new JPanel(); |
149 |
jContentPane.setLayout(new BorderLayout()); |
150 |
jContentPane.add(getJConnPanel(), java.awt.BorderLayout.CENTER); |
151 |
jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH); |
152 |
|
153 |
} |
154 |
return jContentPane;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* This method initializes jPanel
|
159 |
*
|
160 |
* @return javax.swing.JPanel
|
161 |
*/
|
162 |
private ConnectionPanel getJConnPanel() {
|
163 |
if (jConnPanel == null) { |
164 |
jConnPanel = new ConnectionPanel();
|
165 |
} |
166 |
return jConnPanel;
|
167 |
} |
168 |
|
169 |
|
170 |
|
171 |
/**
|
172 |
* This method initializes jPanel1
|
173 |
*
|
174 |
* @return javax.swing.JPanel
|
175 |
*/
|
176 |
private JPanel getJPanel1() { |
177 |
if (jPanel1 == null) { |
178 |
ActionListener okAction = new java.awt.event.ActionListener() { |
179 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
180 |
if (!jConnPanel.done()) {
|
181 |
JOptionPane.showMessageDialog(DlgConnection.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE); |
182 |
return;
|
183 |
} |
184 |
jConnPanel.saveConnectionSettings(); |
185 |
connSettings = jConnPanel.getConnectionSettings(); |
186 |
dispose(); |
187 |
} |
188 |
}; |
189 |
|
190 |
ActionListener cancelAction = new java.awt.event.ActionListener() { |
191 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
192 |
connSettings = null;
|
193 |
dispose(); |
194 |
} |
195 |
}; |
196 |
jPanel1 = new AcceptCancelPanel(okAction, cancelAction);
|
197 |
|
198 |
|
199 |
} |
200 |
return jPanel1;
|
201 |
} |
202 |
|
203 |
|
204 |
public ConnectionSettings getConnSettings() {
|
205 |
return connSettings;
|
206 |
} |
207 |
|
208 |
} // @jve:decl-index=0:visual-constraint="10,10"
|