Revision 34114
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/SingleVectorialDBConnectionExtension.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package org.gvsig.geodb; |
|
44 |
|
|
45 |
import java.util.ArrayList; |
|
46 |
|
|
47 |
import javax.swing.JOptionPane; |
|
48 |
|
|
49 |
import org.apache.log4j.Logger; |
|
50 |
|
|
51 |
import org.gvsig.about.AboutManager; |
|
52 |
import org.gvsig.about.AboutParticipant; |
|
53 |
import org.gvsig.andami.PluginServices; |
|
54 |
import org.gvsig.andami.plugins.Extension; |
|
55 |
import org.gvsig.app.ApplicationLocator; |
|
56 |
import org.gvsig.app.ApplicationManager; |
|
57 |
import org.gvsig.geodb.vectorialdb.ConnectionSettings; |
|
58 |
import org.gvsig.utils.NotExistInXMLEntity; |
|
59 |
import org.gvsig.utils.XMLEntity; |
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
/** |
|
64 |
* This extension allows the user to access the single connection manager dialog |
|
65 |
* |
|
66 |
* @see org.gvsig.fmap.drivers.formats.db.utils.SingleVectorialDBConnectionManager |
|
67 |
* |
|
68 |
* @author jldominguez |
|
69 |
* |
|
70 |
*/ |
|
71 |
public class SingleVectorialDBConnectionExtension extends Extension { |
|
72 |
private static Logger logger = Logger.getLogger(SingleVectorialDBConnectionExtension.class.getName()); |
|
73 |
|
|
74 |
/** |
|
75 |
* This method simply loads the connections stored in gvSIG's persistence file |
|
76 |
* as closed connections |
|
77 |
*/ |
|
78 |
public void initialize() { |
|
79 |
loadPersistenceConnections(); |
|
80 |
registerIcons(); |
|
81 |
} |
|
82 |
|
|
83 |
public void postInitialize() { |
|
84 |
super.postInitialize(); |
|
85 |
addAboutInfo(); |
|
86 |
} |
|
87 |
|
|
88 |
private void addAboutInfo() { |
|
89 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
90 |
|
|
91 |
AboutManager about = application.getAbout(); |
|
92 |
about.addDeveloper("PRODEVELOP", getClass().getClassLoader() |
|
93 |
.getResource("prodevelop.html"), 2); |
|
94 |
|
|
95 |
AboutParticipant participant = about.getDeveloper("PRODEVELOP"); |
|
96 |
participant.addContribution( |
|
97 |
"GeoDB", |
|
98 |
"Soporte para pool de conexiones con BBDD", |
|
99 |
2006,1,1, |
|
100 |
2007,12,31 |
|
101 |
); |
|
102 |
} |
|
103 |
|
|
104 |
private void registerIcons(){ |
|
105 |
PluginServices.getIconTheme().register( |
|
106 |
"conn-image", |
|
107 |
this.getClass().getClassLoader().getResource("images/conn.png") |
|
108 |
); |
|
109 |
PluginServices.getIconTheme().register( |
|
110 |
"disconn-image", |
|
111 |
this.getClass().getClassLoader().getResource("images/disconn.png") |
|
112 |
); |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* The only command available is the one to open the connection manager |
|
118 |
* dialog ("GESTOR_JDBC") |
|
119 |
*/ |
|
120 |
public void execute(String actionCommand) { |
|
121 |
// FIXME |
|
122 |
// if (actionCommand.compareToIgnoreCase("GESTOR_VECTORIALDB") == 0) { |
|
123 |
// VectorialDBConnectionManagerDialog dlg = new VectorialDBConnectionManagerDialog(); |
|
124 |
// dlg.showDialog(); |
|
125 |
//// saveAllToPersistence(); |
|
126 |
// |
|
127 |
// return; |
|
128 |
// } |
|
129 |
} |
|
130 |
|
|
131 |
public boolean isEnabled() { |
|
132 |
return true; |
|
133 |
} |
|
134 |
|
|
135 |
public boolean isVisible() { |
|
136 |
return true; |
|
137 |
} |
|
138 |
|
|
139 |
public static void saveAllToPersistence() { |
|
140 |
SingleVectorialDBConnectionExtension ext=new SingleVectorialDBConnectionExtension(); |
|
141 |
XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML(); |
|
142 |
xml.putProperty("literalDBName",true); |
|
143 |
xml.remove("db-connections"); |
|
144 |
|
|
145 |
// ConnectionWithParams[] all = SingleVectorialDBConnectionManager.instance() |
|
146 |
// .getAllConnections(); |
|
147 |
// |
|
148 |
// if (all == null) { |
|
149 |
// PluginServices.getPluginServices(ext).setPersistentXML(xml); |
|
150 |
// return; |
|
151 |
// } |
|
152 |
// |
|
153 |
// for (int i = 0; i < all.length; i++) { |
|
154 |
// addToPersistence(all[i],ext); |
|
155 |
// } |
|
156 |
} |
|
157 |
|
|
158 |
// private static void addToPersistence(ConnectionWithParams cwp, Extension ext) { |
|
159 |
// if (cwp == null) { |
|
160 |
// return; |
|
161 |
// } |
|
162 |
// |
|
163 |
// ConnectionSettings _cs = new ConnectionSettings(); |
|
164 |
// |
|
165 |
// _cs.setHost(cwp.getHost()); |
|
166 |
// _cs.setPort(cwp.getPort()); |
|
167 |
// _cs.setDb(cwp.getDb()); |
|
168 |
// _cs.setDriver(cwp.getDrvName()); |
|
169 |
// _cs.setUser(cwp.getUser()); |
|
170 |
// _cs.setName(cwp.getName()); |
|
171 |
// |
|
172 |
// String newstr = _cs.toString(); |
|
173 |
// |
|
174 |
// XMLEntity xml = PluginServices.getPluginServices(ext).getPersistentXML(); |
|
175 |
// |
|
176 |
// String[] old = null; |
|
177 |
// |
|
178 |
// if (xml.contains("db-connections")) { |
|
179 |
// old = xml.getStringArrayProperty("db-connections"); |
|
180 |
// } |
|
181 |
// |
|
182 |
// ArrayList oldl = stringArrayToArrayList(old); |
|
183 |
// oldl.add(newstr); |
|
184 |
// |
|
185 |
// String[] newarr = (String[]) oldl.toArray(new String[0]); |
|
186 |
// |
|
187 |
// xml.remove("db-connections"); |
|
188 |
// xml.putProperty("db-connections", newarr); |
|
189 |
// PluginServices.getPluginServices(ext).setPersistentXML(xml); |
|
190 |
// } |
|
191 |
|
|
192 |
private static ArrayList stringArrayToArrayList(String[] arr) { |
|
193 |
ArrayList resp = new ArrayList(); |
|
194 |
|
|
195 |
if ((arr != null) && (arr.length > 0)) { |
|
196 |
for (int i = 0; i < arr.length; i++) { |
|
197 |
resp.add(arr[i]); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
return resp; |
|
202 |
} |
|
203 |
|
|
204 |
private void loadPersistenceConnections() { |
|
205 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML(); |
|
206 |
boolean literalDBNames; |
|
207 |
|
|
208 |
if (!xml.contains("literalDBName")){ |
|
209 |
// For back compatibility |
|
210 |
literalDBNames = false; |
|
211 |
}else{ |
|
212 |
// For back compatibility: Normaly always true |
|
213 |
literalDBNames = xml.getBooleanProperty("literalDBName"); |
|
214 |
} |
|
215 |
|
|
216 |
if (xml == null) { |
|
217 |
xml = new XMLEntity(); |
|
218 |
} |
|
219 |
|
|
220 |
if (!xml.contains("db-connections")) { |
|
221 |
String[] servers = new String[0]; |
|
222 |
xml.putProperty("db-connections", servers); |
|
223 |
} |
|
224 |
|
|
225 |
// add drivers to connection manager |
|
226 |
String[] servers = null; |
|
227 |
|
|
228 |
try { |
|
229 |
servers = xml.getStringArrayProperty("db-connections"); |
|
230 |
} |
|
231 |
catch (NotExistInXMLEntity e) { |
|
232 |
System.err.println( |
|
233 |
"Error while getting projects db-connections: " + |
|
234 |
e.getMessage()); |
|
235 |
|
|
236 |
return; |
|
237 |
} |
|
238 |
|
|
239 |
for (int i = 0; i < servers.length; i++) { |
|
240 |
ConnectionSettings cs = new ConnectionSettings(); |
|
241 |
boolean params_ok = true; |
|
242 |
try { |
|
243 |
cs.setFromString(servers[i]); |
|
244 |
// For back compatibility |
|
245 |
if (!literalDBNames){ |
|
246 |
cs.setDb(cs.getDb().toLowerCase()); |
|
247 |
} |
|
248 |
} catch (Exception ex) { |
|
249 |
logger.error("Found misconfigured connection: " + servers[i]); |
|
250 |
params_ok = false; |
|
251 |
} |
|
252 |
if (params_ok) { |
|
253 |
addDisconnected(cs); |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
PluginServices ps= PluginServices.getPluginServices("com.iver.cit.gvsig.jdbc_spatial"); |
|
258 |
if (ps==null) { |
|
259 |
return; |
|
260 |
} |
|
261 |
XMLEntity xmlJDBC =ps.getPersistentXML(); |
|
262 |
|
|
263 |
if (xmlJDBC==null || !xmlJDBC.contains("jdbc-connections")) { |
|
264 |
return; |
|
265 |
} |
|
266 |
|
|
267 |
// add drivers to connection manager |
|
268 |
String[] serversOld = null; |
|
269 |
|
|
270 |
try { |
|
271 |
serversOld = xmlJDBC.getStringArrayProperty("jdbc-connections"); |
|
272 |
} |
|
273 |
catch (NotExistInXMLEntity e) { |
|
274 |
System.err.println( |
|
275 |
"Error while getting projects jdbc-connections: " + |
|
276 |
e.getMessage()); |
|
277 |
|
|
278 |
return; |
|
279 |
} |
|
280 |
|
|
281 |
for (int i = 0; i < serversOld.length; i++) { |
|
282 |
ConnectionSettings cs = new ConnectionSettings(); |
|
283 |
boolean params_ok = true; |
|
284 |
try { |
|
285 |
cs.setFromString(serversOld[i]); |
|
286 |
cs.setDb(cs.getDb().toLowerCase()); |
|
287 |
} catch (Exception ex) { |
|
288 |
logger.error("Found misconfigured connection: " + serversOld[i]); |
|
289 |
params_ok = false; |
|
290 |
} |
|
291 |
if (params_ok) { |
|
292 |
addDisconnected(cs); |
|
293 |
} |
|
294 |
} |
|
295 |
|
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
private void addDisconnected(ConnectionSettings _cs) { |
|
300 |
// try { |
|
301 |
// SingleVectorialDBConnectionManager.instance() |
|
302 |
// .getConnection(_cs.getDriver(), |
|
303 |
// _cs.getUser(), null, _cs.getName(), _cs.getHost(), |
|
304 |
// _cs.getPort(), _cs.getDb(), false); |
|
305 |
// } |
|
306 |
// catch (DBException e) { |
|
307 |
// System.err.println("While getting connection: " + e.getMessage()); |
|
308 |
// showConnectionErrorMessage(e.getMessage()); |
|
309 |
// } |
|
310 |
} |
|
311 |
|
|
312 |
private void showConnectionErrorMessage(String _msg) { |
|
313 |
String msg = (_msg.length() > 300) ? "" : (": " + _msg); |
|
314 |
String title = PluginServices.getText(this, "connection_error"); |
|
315 |
JOptionPane.showMessageDialog(null, title + msg, title, |
|
316 |
JOptionPane.ERROR_MESSAGE); |
|
317 |
} |
|
318 |
|
|
319 |
public void terminate() { |
|
320 |
saveAllToPersistence(); |
|
321 |
// SingleVectorialDBConnectionManager.instance().closeAllBeforeTerminate(); |
|
322 |
} |
|
323 |
} |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/VectorialDBConnectionTreeLeaf.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package org.gvsig.geodb.vectorialdb.wizard; |
|
44 |
|
|
45 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
46 |
|
|
47 |
import org.apache.log4j.Logger; |
|
48 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* Utility class used to manage the connection tree. |
|
54 |
* @author jldominguez |
|
55 |
* |
|
56 |
*/ |
|
57 |
public class VectorialDBConnectionTreeLeaf extends DefaultMutableTreeNode { |
|
58 |
private static Logger logger = Logger.getLogger(VectorialDBConnectionTreeLeaf.class.getName()); |
|
59 |
private DataServerExplorerParameters connwp; |
|
60 |
|
|
61 |
public VectorialDBConnectionTreeLeaf(DataServerExplorerParameters cwp) { |
|
62 |
connwp = cwp; |
|
63 |
setAllowsChildren(false); |
|
64 |
} |
|
65 |
|
|
66 |
public String toString() { |
|
67 |
return connwp.toString(); |
|
68 |
} |
|
69 |
|
|
70 |
public DataServerExplorerParameters getConnectionWithParams() { |
|
71 |
return connwp; |
|
72 |
} |
|
73 |
} |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/VectorialDBConnectionManagerDialog.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package org.gvsig.geodb.vectorialdb.wizard; |
|
44 |
|
|
45 |
import java.awt.Component; |
|
46 |
import java.awt.event.ActionEvent; |
|
47 |
import java.awt.event.ActionListener; |
|
48 |
import java.util.HashMap; |
|
49 |
|
|
50 |
import javax.swing.JButton; |
|
51 |
import javax.swing.JOptionPane; |
|
52 |
import javax.swing.JPanel; |
|
53 |
import javax.swing.JScrollPane; |
|
54 |
import javax.swing.JTree; |
|
55 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
56 |
import javax.swing.tree.TreeCellRenderer; |
|
57 |
|
|
58 |
import org.apache.log4j.Logger; |
|
59 |
import org.gvsig.andami.PluginServices; |
|
60 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
61 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
62 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
|
63 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
|
64 |
import org.gvsig.utils.swing.JPasswordDlg; |
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
/** |
|
69 |
* Single connection manager main dialog. Lists available connections. Open connections |
|
70 |
* are marked "[C]" before their names. |
|
71 |
* |
|
72 |
* @author jldominguez |
|
73 |
* |
|
74 |
*/ |
|
75 |
public class VectorialDBConnectionManagerDialog extends JPanel implements IWindow, |
|
76 |
ActionListener { |
|
77 |
private static Logger logger = Logger.getLogger(VectorialDBConnectionManagerDialog.class.getName()); |
|
78 |
private JScrollPane connectionsScrollPane = null; |
|
79 |
private JButton closeButton = null; |
|
80 |
private JButton removeButton = null; |
|
81 |
private JButton newButton = null; |
|
82 |
private JTree connectionsTree = null; |
|
83 |
private WindowInfo winfo = new WindowInfo(8); // all false except MODAL |
|
84 |
private JButton connectButton = null; |
|
85 |
private JButton disconnButton = null; |
|
86 |
private JButton editButton = null; |
|
87 |
private TreeCellRenderer connTreeRenderer; |
|
88 |
|
|
89 |
/** |
|
90 |
* This method initializes |
|
91 |
* |
|
92 |
*/ |
|
93 |
public VectorialDBConnectionManagerDialog() { |
|
94 |
super(); |
|
95 |
initialize(); |
|
96 |
} |
|
97 |
|
|
98 |
public void showDialog() { |
|
99 |
PluginServices.getMDIManager().addWindow(this); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* This method initializes this |
|
104 |
* |
|
105 |
*/ |
|
106 |
private void initialize() { |
|
107 |
winfo.setHeight(422 - 42); |
|
108 |
winfo.setWidth(347 + 6); |
|
109 |
winfo.setTitle(PluginServices.getText(this, "gestor_db")); |
|
110 |
|
|
111 |
this.setSize(new java.awt.Dimension(347, 420)); |
|
112 |
this.setLayout(null); |
|
113 |
this.add(getConnectionsScrollPane(), null); |
|
114 |
this.add(getCloseButton(), null); |
|
115 |
this.add(getRemoveButton(), null); |
|
116 |
this.add(getNewButton(), null); |
|
117 |
this.add(getConnectButton(), null); |
|
118 |
this.add(getDisconnButton(), null); |
|
119 |
this.add(getEditButton(), null); |
|
120 |
|
|
121 |
connTreeRenderer = new ConnectionTreeRenderer(); |
|
122 |
refreshTree(); |
|
123 |
} |
|
124 |
|
|
125 |
public WindowInfo getWindowInfo() { |
|
126 |
return winfo; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* This method initializes connectionsScrollPane |
|
131 |
* |
|
132 |
* @return javax.swing.JScrollPane |
|
133 |
*/ |
|
134 |
private JScrollPane getConnectionsScrollPane() { |
|
135 |
if (connectionsScrollPane == null) { |
|
136 |
connectionsScrollPane = new JScrollPane(); |
|
137 |
connectionsScrollPane.setBounds(new java.awt.Rectangle(5, 5, 336, |
|
138 |
336)); |
|
139 |
connectionsScrollPane.setViewportView(getConnectionsTree()); |
|
140 |
} |
|
141 |
|
|
142 |
return connectionsScrollPane; |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* This method initializes closeButton |
|
147 |
* |
|
148 |
* @return javax.swing.JButton |
|
149 |
*/ |
|
150 |
private JButton getCloseButton() { |
|
151 |
if (closeButton == null) { |
|
152 |
closeButton = new JButton(); |
|
153 |
closeButton.addActionListener(this); |
|
154 |
closeButton.setBounds(new java.awt.Rectangle(230, 380, 106, 26)); |
|
155 |
closeButton.setText(PluginServices.getText(this, "aceptar")); |
|
156 |
} |
|
157 |
|
|
158 |
return closeButton; |
|
159 |
} |
|
160 |
|
|
161 |
/** |
|
162 |
* This method initializes removeButton |
|
163 |
* |
|
164 |
* @return javax.swing.JButton |
|
165 |
*/ |
|
166 |
private JButton getRemoveButton() { |
|
167 |
if (removeButton == null) { |
|
168 |
removeButton = new JButton(); |
|
169 |
removeButton.addActionListener(this); |
|
170 |
removeButton.setBounds(new java.awt.Rectangle(120, 350, 106, 26)); |
|
171 |
removeButton.setText(PluginServices.getText(this, "remove")); |
|
172 |
} |
|
173 |
|
|
174 |
return removeButton; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* This method initializes newButton |
|
179 |
* |
|
180 |
* @return javax.swing.JButton |
|
181 |
*/ |
|
182 |
private JButton getNewButton() { |
|
183 |
if (newButton == null) { |
|
184 |
newButton = new JButton(); |
|
185 |
newButton.addActionListener(this); |
|
186 |
newButton.setBounds(new java.awt.Rectangle(10, 350, 106, 26)); |
|
187 |
newButton.setText(PluginServices.getText(this, "add")); |
|
188 |
} |
|
189 |
|
|
190 |
return newButton; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* This method initializes connectionsTree |
|
195 |
* |
|
196 |
* @return javax.swing.JTree |
|
197 |
*/ |
|
198 |
private JTree getConnectionsTree() { |
|
199 |
|
|
200 |
JTree resp = new JTree(getTreeRoot()); |
|
201 |
resp.setRowHeight(20); |
|
202 |
resp.setCellRenderer(connTreeRenderer); |
|
203 |
return resp; |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
private DefaultMutableTreeNode getTreeRoot() { |
|
208 |
DefaultMutableTreeNode root = new DefaultMutableTreeNode(); |
|
209 |
root.setUserObject(new String(PluginServices.getText(this, |
|
210 |
"geodb_connections"))); |
|
211 |
|
|
212 |
HashMap aux_nodes = new HashMap(); |
|
213 |
|
|
214 |
// ConnectionWithParams[] conns = SingleVectorialDBConnectionManager.instance() |
|
215 |
// .getAllConnections(); |
|
216 |
|
|
217 |
// if (conns == null) { |
|
218 |
// return root; |
|
219 |
// } |
|
220 |
|
|
221 |
// DataManager dm=DataManager.getManager(); |
|
222 |
// String[] registers=dm.getRegistersExplorers(); |
|
223 |
// for (int i = 0; i < registers.length; i++) { |
|
224 |
// String key = registers[i]; |
|
225 |
// |
|
226 |
// if (!aux_nodes.containsKey(key)) { |
|
227 |
// aux_nodes.put(key, new ArrayList()); |
|
228 |
// } |
|
229 |
// |
|
230 |
// ArrayList aux = (ArrayList) aux_nodes.get(key); |
|
231 |
// aux.add(registers); |
|
232 |
// } |
|
233 |
// |
|
234 |
// Iterator iter = aux_nodes.keySet().iterator(); |
|
235 |
// while (iter.hasNext()) { |
|
236 |
// String k = (String) iter.next(); |
|
237 |
// VectorialDBConnectionTreeNode node = new VectorialDBConnectionTreeNode(k); |
|
238 |
// ArrayList cc = (ArrayList) aux_nodes.get(k); |
|
239 |
// |
|
240 |
// for (int i = 0; i < cc.size(); i++) { |
|
241 |
// DataServerExplorerParameters conwp=null; |
|
242 |
// for (int j=0;j<((String[])cc.get(i)).length;j++){ |
|
243 |
// try { |
|
244 |
// conwp = (DataServerExplorerParameters) dm.createDataExplorerParameters(((String[])cc.get(i))[j]); |
|
245 |
// VectorialDBConnectionTreeLeaf leaf = new VectorialDBConnectionTreeLeaf(conwp); |
|
246 |
// node.add(leaf); |
|
247 |
// } catch (InitializeException e) { |
|
248 |
// // TODO Auto-generated catch block |
|
249 |
// e.printStackTrace(); |
|
250 |
// } |
|
251 |
// } |
|
252 |
// |
|
253 |
// |
|
254 |
// } |
|
255 |
// |
|
256 |
// root.add(node); |
|
257 |
// } |
|
258 |
|
|
259 |
return root; |
|
260 |
} |
|
261 |
|
|
262 |
private void addConnection(String _drvName, String _port, String _host, |
|
263 |
String _dbName, String _user, String _pw, String _conn_usr_name, |
|
264 |
boolean is_conn) { |
|
265 |
// SingleVectorialDBConnectionManager.instance() |
|
266 |
// .getConnection(_drvName, _user, _pw, |
|
267 |
// _conn_usr_name, _host, _port, _dbName, is_conn); |
|
268 |
refreshTree(); |
|
269 |
} |
|
270 |
|
|
271 |
private void refreshTree() { |
|
272 |
connectionsTree = getConnectionsTree(); |
|
273 |
|
|
274 |
for (int i = 0; i < connectionsTree.getRowCount(); i++) { |
|
275 |
connectionsTree.expandRow(i); |
|
276 |
} |
|
277 |
|
|
278 |
connectionsScrollPane.setViewportView(connectionsTree); |
|
279 |
} |
|
280 |
|
|
281 |
public void actionPerformed(ActionEvent arg0) { |
|
282 |
Object src = arg0.getSource(); |
|
283 |
|
|
284 |
if (src == disconnButton) { |
|
285 |
if (connectionsTree.getSelectionCount() != 1) { |
|
286 |
return; |
|
287 |
} |
|
288 |
|
|
289 |
Object obj = connectionsTree.getSelectionPath() |
|
290 |
.getLastPathComponent(); |
|
291 |
|
|
292 |
if (!(obj instanceof VectorialDBConnectionTreeLeaf)) { |
|
293 |
return; |
|
294 |
} |
|
295 |
|
|
296 |
VectorialDBConnectionTreeLeaf leaf = (VectorialDBConnectionTreeLeaf) obj; |
|
297 |
DataServerExplorerParameters _cwp = leaf.getConnectionWithParams(); |
|
298 |
|
|
299 |
// if (_cwp.isConnected()) { |
|
300 |
// _cwp.disconnect(); |
|
301 |
// refreshTree(); |
|
302 |
// } |
|
303 |
} |
|
304 |
|
|
305 |
if (src == connectButton) { |
|
306 |
if (connectionsTree.getSelectionCount() != 1) { |
|
307 |
return; |
|
308 |
} |
|
309 |
|
|
310 |
Object obj = connectionsTree.getSelectionPath() |
|
311 |
.getLastPathComponent(); |
|
312 |
|
|
313 |
if (!(obj instanceof VectorialDBConnectionTreeLeaf)) { |
|
314 |
return; |
|
315 |
} |
|
316 |
|
|
317 |
VectorialDBConnectionTreeLeaf leaf = (VectorialDBConnectionTreeLeaf) obj; |
|
318 |
DBServerExplorerParameters _cwp = (DBServerExplorerParameters) leaf |
|
319 |
.getConnectionWithParams(); |
|
320 |
|
|
321 |
JPasswordDlg dlg = new JPasswordDlg(); |
|
322 |
dlg.setLocationRelativeTo((Component)PluginServices.getMainFrame()); |
|
323 |
String strMessage = PluginServices.getText(this, "conectar_db"); |
|
324 |
String strPassword = PluginServices.getText(this, "password"); |
|
325 |
dlg.setMessage(strMessage + " [" + //_cwp.getTableName() + ", " + |
|
326 |
_cwp.getHost() + ", " + _cwp.getPort() + ", " |
|
327 |
+ _cwp.getDBName() + |
|
328 |
", " + _cwp.getUser() + "]. " + strPassword + "?"); |
|
329 |
dlg.setVisible(true); |
|
330 |
|
|
331 |
String clave = dlg.getPassword(); |
|
332 |
|
|
333 |
if (clave == null) { |
|
334 |
return; |
|
335 |
} |
|
336 |
|
|
337 |
// try { |
|
338 |
// _cwp.connect(clave); |
|
339 |
refreshTree(); |
|
340 |
// } |
|
341 |
// catch (DBException e) { |
|
342 |
// showConnectionErrorMessage(e.getMessage(), false); |
|
343 |
// } |
|
344 |
} |
|
345 |
|
|
346 |
if (src == closeButton) { |
|
347 |
PluginServices.getMDIManager().closeWindow(this); |
|
348 |
} |
|
349 |
|
|
350 |
if (src == newButton) { |
|
351 |
VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog(); |
|
352 |
newco.showDialog(); |
|
353 |
|
|
354 |
if (newco.isOkPressed()) { |
|
355 |
String _drvname = newco.getConnectionDriverName(); |
|
356 |
String _host = newco.getConnectionServerUrl(); |
|
357 |
String _port = newco.getConnectionPort(); |
|
358 |
String _dbname = newco.getConnectionDBName(); |
|
359 |
String _user = newco.getConnectionUser(); |
|
360 |
String _pw = newco.getConnectionPassword(); |
|
361 |
String _conn_usr_name = newco.getConnectionName(); |
|
362 |
|
|
363 |
boolean hasToBeCon = newco.hasToBeConnected(); |
|
364 |
|
|
365 |
// try { |
|
366 |
addConnection(_drvname, _port, _host, _dbname, _user, _pw, |
|
367 |
_conn_usr_name, hasToBeCon); |
|
368 |
// } |
|
369 |
// catch (DBException e) { |
|
370 |
// showConnectionErrorMessage(e.getMessage(), false); |
|
371 |
// } |
|
372 |
} |
|
373 |
} |
|
374 |
|
|
375 |
if (src == removeButton) { |
|
376 |
if (connectionsTree.getSelectionCount() != 1) { |
|
377 |
return; |
|
378 |
} |
|
379 |
|
|
380 |
Object obj = connectionsTree.getSelectionPath() |
|
381 |
.getLastPathComponent(); |
|
382 |
|
|
383 |
if (!(obj instanceof VectorialDBConnectionTreeLeaf)) { |
|
384 |
return; |
|
385 |
} |
|
386 |
|
|
387 |
int confirm = JOptionPane.showConfirmDialog(this, |
|
388 |
PluginServices.getText(this, "confirm_remove"), |
|
389 |
PluginServices.getText(this, "Remove"), |
|
390 |
JOptionPane.YES_NO_OPTION); |
|
391 |
|
|
392 |
if (confirm != JOptionPane.YES_OPTION) { |
|
393 |
return; |
|
394 |
} |
|
395 |
|
|
396 |
VectorialDBConnectionTreeLeaf leaf = (VectorialDBConnectionTreeLeaf) obj; |
|
397 |
DataServerExplorerParameters _cwp = leaf.getConnectionWithParams(); |
|
398 |
// SingleVectorialDBConnectionManager.instance().closeAndRemove(_cwp); |
|
399 |
refreshTree(); |
|
400 |
} |
|
401 |
|
|
402 |
if (src == editButton) { |
|
403 |
if (connectionsTree.getSelectionCount() != 1) { |
|
404 |
return; |
|
405 |
} |
|
406 |
|
|
407 |
Object obj = connectionsTree.getSelectionPath() |
|
408 |
.getLastPathComponent(); |
|
409 |
|
|
410 |
if (!(obj instanceof VectorialDBConnectionTreeLeaf)) { |
|
411 |
return; |
|
412 |
} |
|
413 |
|
|
414 |
VectorialDBConnectionTreeLeaf leaf = (VectorialDBConnectionTreeLeaf) obj; |
|
415 |
DataServerExplorerParameters old_cwp = leaf.getConnectionWithParams(); |
|
416 |
|
|
417 |
VectorialDBConnectionParamsDialog modifyco = new VectorialDBConnectionParamsDialog(); |
|
418 |
modifyco.loadValues((DBServerExplorerParameters) old_cwp); |
|
419 |
modifyco.showDialog(); |
|
420 |
|
|
421 |
if (modifyco.isOkPressed()) { |
|
422 |
String _drvname = modifyco.getConnectionDriverName(); |
|
423 |
String _host = modifyco.getConnectionServerUrl(); |
|
424 |
String _port = modifyco.getConnectionPort(); |
|
425 |
String _dbname = modifyco.getConnectionDBName(); |
|
426 |
String _user = modifyco.getConnectionUser(); |
|
427 |
String _pw = modifyco.getConnectionPassword(); |
|
428 |
String _conn_usr_name = modifyco.getConnectionName(); |
|
429 |
|
|
430 |
boolean hasToBeCon = modifyco.hasToBeConnected(); |
|
431 |
|
|
432 |
boolean old_was_open = true; |
|
433 |
|
|
434 |
// try { |
|
435 |
// old_was_open = SingleVectorialDBConnectionManager.instance() |
|
436 |
// .closeAndRemove(old_cwp); |
|
437 |
|
|
438 |
addConnection(_drvname, _port, _host, _dbname, _user, _pw, |
|
439 |
_conn_usr_name, hasToBeCon); |
|
440 |
// } |
|
441 |
// catch (DBException e) { |
|
442 |
// showConnectionErrorMessage(e.getMessage(), false); |
|
443 |
// |
|
444 |
// try { |
|
445 |
// addConnection(old_cwp.getDrvName(), old_cwp.getPort(), |
|
446 |
// old_cwp.getHost(), old_cwp.getDb(), |
|
447 |
// old_cwp.getUser(), old_cwp.getPw(), |
|
448 |
// old_cwp.getName(), old_was_open); |
|
449 |
// } |
|
450 |
// catch (DBException e1) { |
|
451 |
// showConnectionErrorMessage(e.getMessage(), true); |
|
452 |
// } |
|
453 |
// } |
|
454 |
} |
|
455 |
} |
|
456 |
} |
|
457 |
|
|
458 |
private void showConnectionErrorMessage(String _msg, boolean reconnect) { |
|
459 |
String msg = (_msg.length() > 300) ? "" : (": " + _msg); |
|
460 |
String title = ""; |
|
461 |
|
|
462 |
if (reconnect) { |
|
463 |
title = PluginServices.getText(this, "reconnection_error"); |
|
464 |
} |
|
465 |
else { |
|
466 |
title = PluginServices.getText(this, "connection_error"); |
|
467 |
} |
|
468 |
|
|
469 |
JOptionPane.showMessageDialog(this, title + msg, title, |
|
470 |
JOptionPane.ERROR_MESSAGE); |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* This method initializes connectButton |
|
475 |
* |
|
476 |
* @return javax.swing.JButton |
|
477 |
*/ |
|
478 |
private JButton getConnectButton() { |
|
479 |
if (connectButton == null) { |
|
480 |
connectButton = new JButton(); |
|
481 |
connectButton.addActionListener(this); |
|
482 |
connectButton.setBounds(new java.awt.Rectangle(10, 380, 106, 26)); |
|
483 |
connectButton.setText(PluginServices.getText(this, "connect")); |
|
484 |
} |
|
485 |
|
|
486 |
return connectButton; |
|
487 |
} |
|
488 |
|
|
489 |
/** |
|
490 |
* This method initializes disconnButton |
|
491 |
* |
|
492 |
* @return javax.swing.JButton |
|
493 |
*/ |
|
494 |
private JButton getDisconnButton() { |
|
495 |
if (disconnButton == null) { |
|
496 |
disconnButton = new JButton(); |
|
497 |
disconnButton.addActionListener(this); |
|
498 |
disconnButton.setBounds(new java.awt.Rectangle(120, 380, 106, 26)); |
|
499 |
disconnButton.setText(PluginServices.getText(this, "disconnect")); |
|
500 |
} |
|
501 |
|
|
502 |
return disconnButton; |
|
503 |
} |
|
504 |
|
|
505 |
/** |
|
506 |
* This method initializes editButton |
|
507 |
* |
|
508 |
* @return javax.swing.JButton |
|
509 |
*/ |
|
510 |
private JButton getEditButton() { |
|
511 |
if (editButton == null) { |
|
512 |
editButton = new JButton(); |
|
513 |
editButton.addActionListener(this); |
|
514 |
editButton.setBounds(new java.awt.Rectangle(230, 350, 106, 26)); |
|
515 |
editButton.setText(PluginServices.getText(this, "edit_settings")); |
|
516 |
} |
|
517 |
|
|
518 |
return editButton; |
|
519 |
} |
|
520 |
public Object getWindowProfile() { |
|
521 |
return WindowInfo.DIALOG_PROFILE; |
|
522 |
} |
|
523 |
|
|
524 |
} // @jve:decl-index=0:visual-constraint="10,10" |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/VectorialDBConnectionTreeNode.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package org.gvsig.geodb.vectorialdb.wizard; |
|
44 |
|
|
45 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
46 |
|
|
47 |
|
|
48 |
/** |
|
49 |
* Utility class used to manage the connection tree. |
|
50 |
* @author jldominguez |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class VectorialDBConnectionTreeNode extends DefaultMutableTreeNode { |
|
54 |
private String label; |
|
55 |
|
|
56 |
public VectorialDBConnectionTreeNode(String drvname) { |
|
57 |
label = drvname; |
|
58 |
setAllowsChildren(true); |
|
59 |
} |
|
60 |
|
|
61 |
public String toString() { |
|
62 |
return label; |
|
63 |
} |
|
64 |
} |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/ConnectionTreeRenderer.java | ||
---|---|---|
1 |
package org.gvsig.geodb.vectorialdb.wizard; |
|
2 |
|
|
3 |
import java.awt.Component; |
|
4 |
|
|
5 |
import javax.swing.ImageIcon; |
|
6 |
import javax.swing.JTree; |
|
7 |
import javax.swing.tree.DefaultTreeCellRenderer; |
|
8 |
|
|
9 |
import org.gvsig.andami.PluginServices; |
|
10 |
|
|
11 |
|
|
12 |
public class ConnectionTreeRenderer extends DefaultTreeCellRenderer { |
|
13 |
|
|
14 |
// private ImageIcon connImage = new ImageIcon(createResourceUrl("images/conn.png")); |
|
15 |
private ImageIcon connImage = PluginServices.getIconTheme().get("conn-image"); |
|
16 |
// private ImageIcon disconnImage = new ImageIcon(createResourceUrl("images/disconn.png")); |
|
17 |
private ImageIcon disconnImage = PluginServices.getIconTheme().get("disconn-image"); |
|
18 |
|
|
19 |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
20 |
boolean selected, boolean expanded, boolean leaf, int row, |
|
21 |
boolean hasFocus) { |
|
22 |
|
|
23 |
if (value instanceof VectorialDBConnectionTreeLeaf) { |
|
24 |
VectorialDBConnectionTreeLeaf jdbc = (VectorialDBConnectionTreeLeaf) value; |
|
25 |
if (jdbc.getConnectionWithParams()!=null) { |
|
26 |
setLeafIcon(connImage); |
|
27 |
} else { |
|
28 |
setLeafIcon(disconnImage); |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
return super.getTreeCellRendererComponent( |
|
33 |
tree, |
|
34 |
value, |
|
35 |
selected, |
|
36 |
expanded, |
|
37 |
leaf, |
|
38 |
row, |
|
39 |
hasFocus); |
|
40 |
} |
|
41 |
|
|
42 |
private java.net.URL createResourceUrl(String path) { |
|
43 |
return getClass().getClassLoader().getResource(path); |
|
44 |
} |
|
45 |
|
|
46 |
} |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/WizardDB.java | ||
---|---|---|
34 | 34 |
import java.util.ArrayList; |
35 | 35 |
import java.util.Iterator; |
36 | 36 |
import java.util.List; |
37 |
import java.util.Map; |
|
38 |
import java.util.Map.Entry; |
|
37 | 39 |
|
38 | 40 |
import javax.swing.DefaultListModel; |
39 | 41 |
import javax.swing.ImageIcon; |
... | ... | |
45 | 47 |
import javax.swing.event.ListSelectionEvent; |
46 | 48 |
import javax.swing.event.ListSelectionListener; |
47 | 49 |
|
50 |
import org.apache.commons.collections.map.HashedMap; |
|
48 | 51 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.PluginsLocator; |
|
53 |
import org.gvsig.andami.PluginsManager; |
|
49 | 54 |
import org.gvsig.andami.messages.NotificationManager; |
50 | 55 |
import org.gvsig.app.ApplicationLocator; |
51 | 56 |
import org.gvsig.app.ApplicationManager; |
... | ... | |
67 | 72 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
68 | 73 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
69 | 74 |
import org.gvsig.fmap.mapcontrol.MapControl; |
70 |
import org.gvsig.geodb.SingleVectorialDBConnectionExtension;
|
|
75 |
import org.gvsig.geodb.ExtDB_Spatial;
|
|
71 | 76 |
import org.gvsig.gui.beans.swing.JButton; |
77 |
import org.gvsig.tools.dynobject.DynObject; |
|
72 | 78 |
import org.slf4j.Logger; |
73 | 79 |
import org.slf4j.LoggerFactory; |
74 | 80 |
|
... | ... | |
76 | 82 |
public class WizardDB extends WizardPanel implements ActionListener, |
77 | 83 |
ListSelectionListener { |
78 | 84 |
|
79 |
private static final String WIZARD_TAB_NAME = "DB"; |
|
85 |
/** |
|
86 |
* |
|
87 |
*/ |
|
88 |
private static final long serialVersionUID = -7045762275505941695L; |
|
89 |
private static final String WIZARD_TAB_NAME = "DB"; |
|
80 | 90 |
private static Logger logger = LoggerFactory.getLogger(WizardDB.class |
81 | 91 |
.getName()); |
82 | 92 |
|
... | ... | |
121 | 131 |
} |
122 | 132 |
|
123 | 133 |
|
134 |
@SuppressWarnings("rawtypes") |
|
124 | 135 |
private void loadVectorialDBDatasourcesCombo(MyExplorer sel) { |
125 |
getDatasourceComboBox().removeAllItems(); |
|
126 |
DataManager dm = DALLocator.getDataManager(); |
|
127 |
List names = dm.getStoreProviders(); |
|
128 |
if (sel != null) { |
|
129 |
getDatasourceComboBox().addItem(sel); |
|
130 |
} |
|
131 |
|
|
132 |
if (names == null) { |
|
133 |
return; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
PluginsManager manager = PluginsLocator.getManager(); |
|
138 |
DynObject values = manager.getPlugin(ExtDB_Spatial.class).getPluginProperties(); |
|
139 |
Map connections = (Map) values.getDynValue("db_connections"); |
|
140 |
if (connections != null){ |
|
141 |
Iterator it = connections.entrySet().iterator(); |
|
142 |
getDatasourceComboBox().removeAllItems(); |
|
143 |
while (it.hasNext()){ |
|
144 |
Map.Entry entry = (Entry) it.next(); |
|
145 |
MyExplorer myExplorer = new MyExplorer(); |
|
146 |
myExplorer.setDbExplorerParameters((DBServerExplorerParameters) entry.getValue()); |
|
147 |
myExplorer.setName((String) entry.getKey()); |
|
148 |
getDatasourceComboBox().addItem(myExplorer); |
|
149 |
if(sel!=null && sel.getName().equalsIgnoreCase(myExplorer.getName())){ |
|
150 |
getDatasourceComboBox().setSelectedItem(myExplorer); |
|
151 |
} |
|
152 |
} |
|
153 |
} else { |
|
154 |
connections = new HashedMap(); |
|
155 |
values.setDynValue("db_connections", connections); |
|
156 |
} |
|
136 | 157 |
} |
137 | 158 |
|
138 | 159 |
public void initWizard() { |
139 | 160 |
} |
140 | 161 |
|
141 | 162 |
public void execute() { |
142 |
SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
143 |
|
|
144 | 163 |
TablesListItem[] tables = getSelectedTables(); |
145 | 164 |
|
146 | 165 |
DataManager man = DALLocator.getDataManager(); |
147 |
FeatureStore store, storeToAdd;
|
|
148 |
|
|
166 |
FeatureStore store; |
|
167 |
|
|
149 | 168 |
String docName; |
150 | 169 |
TableDocument document; |
151 |
// Project project = ((ProjectExtension) PluginServices |
|
152 |
// .getExtension(ProjectExtension.class)).getProject(); |
|
153 | 170 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
154 | 171 |
|
155 | 172 |
ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
... | ... | |
171 | 188 |
|
172 | 189 |
docName = userTableSettingsPanel.getUserLayerName(); |
173 | 190 |
try { |
174 |
store = (FeatureStore) man.createStore(storeParams);
|
|
191 |
store = (FeatureStore) man.openStore(storeParams.getDataStoreName(), storeParams);
|
|
175 | 192 |
} catch (Exception e) { |
176 | 193 |
NotificationManager.addError(e); |
177 | 194 |
return; |
178 | 195 |
} |
179 | 196 |
|
180 | 197 |
try { |
181 |
storeToAdd = (FeatureStore) appGvSIGMan.pepareOpenDataSource(
|
|
198 |
appGvSIGMan.pepareOpenDataSource( |
|
182 | 199 |
store, context); |
183 | 200 |
} catch (Exception e) { |
184 | 201 |
NotificationManager.addError(e); |
... | ... | |
186 | 203 |
return; |
187 | 204 |
} |
188 | 205 |
|
189 |
|
|
190 |
// document = ProjectFactory.createTable(docName, store); |
|
191 |
|
|
192 | 206 |
document = (TableDocument) ProjectManager.getInstance().createDocument(TableManager.TYPENAME, docName); |
193 | 207 |
document.setStore(store); |
194 | 208 |
project.add(document); |
... | ... | |
228 | 242 |
|
229 | 243 |
} |
230 | 244 |
|
231 |
protected TablesListItem[] getSelectedTables() { |
|
245 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
246 |
protected TablesListItem[] getSelectedTables() { |
|
232 | 247 |
int count = tablesList.getModel().getSize(); |
233 | 248 |
ArrayList resp = new ArrayList(); |
234 | 249 |
|
... | ... | |
352 | 367 |
Object src = arg0.getSource(); |
353 | 368 |
|
354 | 369 |
if (src == datasourceComboBox) { |
355 |
Object sel_obj = datasourceComboBox.getSelectedItem();
|
|
370 |
MyExplorer sel_obj = (MyExplorer)datasourceComboBox.getSelectedItem();
|
|
356 | 371 |
|
357 | 372 |
if (sel_obj == null) { |
358 | 373 |
return; |
359 | 374 |
} |
360 | 375 |
getDatasourceComboBox().repaint(); |
361 |
return; |
|
362 |
} |
|
376 |
dbExplorerParameters = sel_obj.getDbSeverExplorerParameters(); |
|
363 | 377 |
|
364 |
if (src == dbButton) { |
|
378 |
} else if (src == dbButton) {
|
|
365 | 379 |
MyExplorer sel = addNewConnection(); |
366 | 380 |
|
367 | 381 |
if (sel != null) { |
... | ... | |
370 | 384 |
getDatasourceComboBox().setSelectedItem(sel); |
371 | 385 |
|
372 | 386 |
} |
373 |
updateTableList(dbExplorerParameters); |
|
374 | 387 |
} |
388 |
|
|
389 |
updateTableList(dbExplorerParameters); |
|
375 | 390 |
} |
376 | 391 |
|
377 |
private MyExplorer addNewConnection() { |
|
392 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
393 |
private MyExplorer addNewConnection() { |
|
378 | 394 |
MyExplorer myExplorer = new MyExplorer(); |
379 | 395 |
DBServerExplorerParameters resp = null; |
380 | 396 |
|
... | ... | |
388 | 404 |
showConnectionErrorMessage(e.getMessage()); |
389 | 405 |
return null; |
390 | 406 |
} |
391 |
SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
407 |
PluginsManager manager = PluginsLocator.getManager(); |
|
408 |
DynObject values = manager.getPlugin(ExtDB_Spatial.class).getPluginProperties(); |
|
409 |
Map connections = (Map) values.getDynValue("db_connections"); |
|
410 |
if(connections == null){ |
|
411 |
connections = new HashedMap(); |
|
412 |
values.setDynValue("db_connections", connections); |
|
413 |
} |
|
414 |
connections.put(newco.getConnectionName(), resp); |
|
415 |
|
|
416 |
// SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
392 | 417 |
myExplorer.setDbExplorerParameters(resp); |
393 | 418 |
myExplorer.setName(newco.getConnectionName()); |
394 | 419 |
return myExplorer; |
... | ... | |
402 | 427 |
return new TablesListItem(dbExplorer, param, this); |
403 | 428 |
} |
404 | 429 |
|
405 |
private void updateTableList( |
|
430 |
@SuppressWarnings("rawtypes") |
|
431 |
private void updateTableList( |
|
406 | 432 |
DBServerExplorerParameters dbSeverExplorerParameters2) { |
407 | 433 |
if (dbSeverExplorerParameters2 == null) { |
408 | 434 |
return; |
... | ... | |
410 | 436 |
DataManager dm = DALLocator.getDataManager(); |
411 | 437 |
DBServerExplorer dbExplorer; |
412 | 438 |
try { |
413 |
dbExplorer = (DBServerExplorer) dm |
|
414 |
.createServerExplorer(dbSeverExplorerParameters2); |
|
439 |
dbExplorer = (DBServerExplorer) dm.openServerExplorer(dbSeverExplorerParameters2.getExplorerName(), dbSeverExplorerParameters2); |
|
415 | 440 |
|
416 | 441 |
// TODO: use the mode to filter tables with geometries when opening |
417 | 442 |
// a view document |
... | ... | |
421 | 446 |
|
422 | 447 |
Iterator iter = parameters.iterator(); |
423 | 448 |
DBStoreParameters param; |
449 |
int count = 0; |
|
424 | 450 |
while (iter.hasNext()) { |
425 | 451 |
param = (DBStoreParameters) iter.next(); |
426 | 452 |
lmodel.addElement(createTabeListItem(dbExplorer, param)); |
453 |
count++; |
|
427 | 454 |
} |
428 | 455 |
|
429 | 456 |
getTablesList().setModel(lmodel); |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/WizardVectorialDB.java | ||
---|---|---|
70 | 70 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
71 | 71 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
72 | 72 |
import org.gvsig.fmap.mapcontrol.MapControl; |
73 |
import org.gvsig.geodb.SingleVectorialDBConnectionExtension; |
|
74 | 73 |
import org.slf4j.Logger; |
75 | 74 |
import org.slf4j.LoggerFactory; |
76 | 75 |
|
... | ... | |
84 | 83 |
* |
85 | 84 |
*/ |
86 | 85 |
public class WizardVectorialDB extends WizardDB { |
86 |
/** |
|
87 |
* |
|
88 |
*/ |
|
89 |
private static final long serialVersionUID = -5002685263220038989L; |
|
90 |
|
|
87 | 91 |
private static Logger logger = LoggerFactory |
88 | 92 |
.getLogger(WizardVectorialDB.class.getName()); |
89 | 93 |
|
... | ... | |
169 | 173 |
} |
170 | 174 |
|
171 | 175 |
public void execute() { |
172 |
SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
173 |
|
|
174 | 176 |
MapControl mapControl = this.getMapCtrl(); |
175 | 177 |
IProjection proj = null; |
176 | 178 |
TablesListItem[] tables = getSelectedTables(); |
branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/ExtDB_Spatial.java | ||
---|---|---|
42 | 42 |
*/ |
43 | 43 |
package org.gvsig.geodb; |
44 | 44 |
|
45 |
import org.gvsig.about.AboutManager; |
|
46 |
import org.gvsig.about.AboutParticipant; |
|
45 | 47 |
import org.gvsig.andami.plugins.Extension; |
46 | 48 |
import org.gvsig.app.ApplicationLocator; |
49 |
import org.gvsig.app.ApplicationManager; |
|
47 | 50 |
import org.gvsig.app.extension.AddLayer; |
48 | 51 |
import org.gvsig.geodb.vectorialdb.wizard.WizardDB; |
49 | 52 |
import org.gvsig.geodb.vectorialdb.wizard.WizardVectorialDB; |
... | ... | |
58 | 61 |
*/ |
59 | 62 |
public class ExtDB_Spatial extends Extension { |
60 | 63 |
|
61 |
// private DALDbLibrary dbLibrary; |
|
62 |
// private DBStoreLibrary dbStoreLibrary; |
|
63 |
// private JDBCLibrary jdbcLibrary; |
|
64 |
// private PostgreSQLLibrary posgresqlLibrary; |
|
65 |
// private MySQLLibrary mysqlLibrary; |
|
66 |
|
|
67 | 64 |
public void initialize() { |
68 |
// dbLibrary = new DALDbLibrary(); |
|
69 |
// dbStoreLibrary = new DBStoreLibrary(); |
|
70 |
// jdbcLibrary = new JDBCLibrary(); |
|
71 |
// posgresqlLibrary = new PostgreSQLLibrary(); |
|
72 |
// mysqlLibrary = new MySQLLibrary(); |
|
73 |
// |
|
74 |
// |
|
75 |
// dbLibrary.initialize(); |
|
76 |
// dbStoreLibrary.initialize(); |
|
77 |
// jdbcLibrary.initialize(); |
|
78 |
// posgresqlLibrary.initialize(); |
|
79 |
// mysqlLibrary.initialize(); |
|
80 |
|
|
81 |
|
|
65 |
//do nothing |
|
82 | 66 |
} |
83 | 67 |
|
84 | 68 |
public void execute(String actionCommand) { |
69 |
//do nothing |
|
85 | 70 |
} |
86 | 71 |
|
87 | 72 |
public boolean isEnabled() { |
... | ... | |
100 | 85 |
@Override |
101 | 86 |
public void postInitialize() { |
102 | 87 |
super.postInitialize(); |
88 |
addAboutInfo(); |
|
103 | 89 |
|
104 |
// dbLibrary.postInitialize(); |
|
105 |
// dbStoreLibrary.postInitialize(); |
|
106 |
// jdbcLibrary.postInitialize(); |
|
107 |
// posgresqlLibrary.postInitialize(); |
|
108 |
// mysqlLibrary.postInitialize(); |
|
109 |
|
|
110 | 90 |
ApplicationLocator.getManager().registerAddTableWizard("DB", |
111 | 91 |
"DB Tables", WizardDB.class); |
112 | 92 |
AddLayer.addWizard(WizardVectorialDB.class); |
113 | 93 |
} |
94 |
|
|
95 |
private void addAboutInfo() { |
|
96 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
97 |
|
|
98 |
AboutManager about = application.getAbout(); |
|
99 |
about.addDeveloper("PRODEVELOP", getClass().getClassLoader() |
|
100 |
.getResource("prodevelop.html"), 2); |
|
101 |
|
|
102 |
AboutParticipant participant = about.getDeveloper("PRODEVELOP"); |
|
103 |
participant.addContribution( |
|
104 |
"GeoDB", |
|
105 |
"Soporte para pool de conexiones con BBDD", |
|
106 |
2006,1,1, |
|
107 |
2007,12,31 |
|
108 |
); |
|
109 |
} |
|
110 |
|
|
114 | 111 |
} |
branches/v2_0_0_prep/extensions/extGeoDB/config/config.xml | ||
---|---|---|
4 | 4 |
<depends plugin-name="org.gvsig.app"/> |
5 | 5 |
<resourceBundle name="text"/> |
6 | 6 |
<extensions> |
7 |
<extension class-name="org.gvsig.geodb.SingleVectorialDBConnectionExtension" |
|
8 |
description="Opens DB connections manager" |
|
9 |
active="true"> |
|
10 |
<menu text="Ver/gestor_db" action-command="GESTOR_VECTORIALDB" key="j" |
|
11 |
tooltip="abrir_gestor_de_orig_db" |
|
12 |
position="3"/> |
|
13 |
</extension> |
|
14 |
|
|
15 | 7 |
<extension class-name="org.gvsig.geodb.ExtDB_Spatial" |
16 | 8 |
description="Support to access Spatial databases" |
17 | 9 |
active="true"> |
branches/v2_0_0_prep/extensions/extGeoDB/config/plugin-persistence.def | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- |
|
3 |
Definitions of plugin persistence org.gvsig.geodb. |
|
4 |
--> |
|
5 |
<definitions> |
|
6 |
<version>1.0.0</version> |
|
7 |
<classes> |
|
8 |
<class name="org.gvsig.geodb"> |
|
9 |
<description>plugin persistence org.gvsig.geodb</description> |
|
10 |
<fields> |
|
11 |
<field name="db_connections" type="map" classOfItems="org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters" mandatory="false"> |
|
12 |
<description>Connections</description> |
|
13 |
</field> |
|
14 |
</fields> |
|
15 |
</class> |
|
16 |
</classes> |
|
17 |
</definitions> |
branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/impl/DefaultPluginsManager.java | ||
---|---|---|
1 | 1 |
package org.gvsig.andami.impl; |
2 | 2 |
|
3 |
import java.io.File; |
|
3 | 4 |
import java.util.ArrayList; |
4 | 5 |
import java.util.Enumeration; |
5 | 6 |
import java.util.Iterator; |
... | ... | |
11 | 12 |
import org.gvsig.andami.config.generate.AndamiConfig; |
12 | 13 |
import org.gvsig.andami.config.generate.Plugin; |
13 | 14 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
15 |
import org.gvsig.andami.plugins.Extension; |
|
14 | 16 |
import org.gvsig.andami.plugins.IExtension; |
17 |
import org.gvsig.andami.plugins.PluginClassLoader; |
|
15 | 18 |
|
16 | 19 |
public class DefaultPluginsManager implements PluginsManager{ |
17 | 20 |
|
... | ... | |
28 | 31 |
return PluginServices.getExtensions(); |
29 | 32 |
} |
30 | 33 |
|
31 |
public PluginServices getPlugin(Class<PluginServices> plugin) { |
|
32 |
return PluginServices.getPluginServices(plugin); |
|
34 |
@SuppressWarnings("rawtypes") |
|
35 |
/** |
|
36 |
* Return the associated pluginServices to the extension class passed as parameter. |
|
37 |
* |
|
38 |
*/ |
|
39 |
public PluginServices getPlugin(Class<?> extension) { |
|
40 |
String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName(); |
|
41 |
return this.getPlugin(pluginName); |
|
33 | 42 |
} |
34 | 43 |
|
35 | 44 |
public PluginServices getPlugin(String pluginName) { |
36 |
return PluginServices.getPluginServices(pluginName);
|
|
45 |
return Launcher.getPluginServices(pluginName);
|
|
37 | 46 |
} |
38 | 47 |
|
39 | 48 |
@SuppressWarnings("unchecked") |
... | ... | |
53 | 62 |
PluginServices.setExclusiveUIExtension(extension); |
54 | 63 |
} |
55 | 64 |
|
65 |
public File getPluginsDirectory() { |
|
66 |
return new File(Launcher.getAndamiConfig().getPluginsDirectory()); |
|
67 |
} |
|
68 |
|
|
56 | 69 |
} |
branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/Launcher.java | ||
---|---|---|
99 | 99 |
import org.gvsig.andami.config.generate.Plugin; |
Also available in: Unified diff