svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.oracle / src / org / gvsig / oracle / extension / ExportOracleExtension.java @ 30231
History | View | Annotate | Download (7.68 KB)
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.oracle.extension; |
44 |
|
45 |
import javax.swing.ImageIcon; |
46 |
|
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.andami.plugins.Extension; |
49 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
50 |
import org.gvsig.andami.ui.wizard.WizardAndami; |
51 |
import org.gvsig.app.extension.About; |
52 |
import org.gvsig.app.project.documents.view.gui.View; |
53 |
import org.gvsig.fmap.dal.store.oracle.OracleLibrary; |
54 |
import org.gvsig.fmap.mapcontext.MapContext; |
55 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
56 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
57 |
import org.gvsig.fmap.mapcontrol.MapControl; |
58 |
import org.gvsig.oracle.gui.NewOracleTableWizard; |
59 |
import org.gvsig.oracle.gui.RepeatedChooseGeometryTypePanel; |
60 |
import org.gvsig.oracle.gui.RepeatedFieldDefinitionPanel; |
61 |
import org.slf4j.Logger; |
62 |
import org.slf4j.LoggerFactory; |
63 |
|
64 |
/**
|
65 |
* This extension adds the export-to-oracle button.
|
66 |
*
|
67 |
* @author jldominguez, vsanjaime
|
68 |
*
|
69 |
*/
|
70 |
public class ExportOracleExtension extends Extension { |
71 |
|
72 |
private static Logger logger = LoggerFactory |
73 |
.getLogger(ExportOracleExtension.class); |
74 |
|
75 |
public static boolean ORACLE_JAR_PRESENT = false; |
76 |
private OracleLibrary oracleSpatialLibrary = null; |
77 |
|
78 |
/**
|
79 |
* initialize
|
80 |
*/
|
81 |
public void initialize() { |
82 |
|
83 |
ORACLE_JAR_PRESENT = isOracleJarPresent(); |
84 |
|
85 |
if (!ORACLE_JAR_PRESENT) {
|
86 |
logger |
87 |
.info("*-----------------------------------------------------------------------*");
|
88 |
logger |
89 |
.info("* Oracle library not found! *");
|
90 |
logger |
91 |
.info("* You need to place the Oracle JDBC library in gvSIG's main LIB folder. *");
|
92 |
logger |
93 |
.info("* Read the Oracle driver user manual for details. *");
|
94 |
logger |
95 |
.info("*-----------------------------------------------------------------------*");
|
96 |
} else {
|
97 |
logger |
98 |
.info("*-----------------------------------------------------------------------*");
|
99 |
logger |
100 |
.info("* Found the Oracle JDBC library! :) *");
|
101 |
logger |
102 |
.info("*-----------------------------------------------------------------------*");
|
103 |
} |
104 |
|
105 |
// about
|
106 |
java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
|
107 |
About claseAbout = (About) PluginServices.getExtension(About.class); |
108 |
claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
|
109 |
|
110 |
oracleSpatialLibrary = new OracleLibrary();
|
111 |
oracleSpatialLibrary.initialize(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Post initialize extension
|
116 |
*/
|
117 |
public void postInitialize() { |
118 |
|
119 |
// postinitialize library
|
120 |
oracleSpatialLibrary.postInitialize(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* execute extension
|
125 |
*/
|
126 |
public void execute(String actionCommand) { |
127 |
|
128 |
if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE") == 0) { |
129 |
FLyrVect lyrv = null;
|
130 |
MapContext mx = null;
|
131 |
|
132 |
try {
|
133 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
134 |
|
135 |
if (w instanceof View) { |
136 |
View v = (View) w; |
137 |
MapControl mc = v.getMapControl(); |
138 |
mx = mc.getMapContext(); |
139 |
|
140 |
FLayer[] lyrs = mx.getLayers().getActives();
|
141 |
|
142 |
if (lyrs.length == 1) { |
143 |
FLayer lyr = lyrs[0];
|
144 |
|
145 |
if (lyr instanceof FLyrVect) { |
146 |
lyrv = (FLyrVect) lyr; |
147 |
|
148 |
ExportToOracle export = new ExportToOracle(); |
149 |
export.toOracle(mx, lyrv);
|
150 |
} |
151 |
} |
152 |
} |
153 |
} catch (Exception ex) { |
154 |
logger |
155 |
.error("Unexpected error while getting active vect layer: "
|
156 |
+ ex.getMessage()); |
157 |
logger.error("Nothing done.");
|
158 |
} |
159 |
} |
160 |
|
161 |
if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) { |
162 |
|
163 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
164 |
if (w instanceof View) { |
165 |
try {
|
166 |
String _file = createResourceUrl(
|
167 |
"images/new_geodb_table.png").getFile();
|
168 |
ImageIcon iicon = new ImageIcon(_file); |
169 |
|
170 |
WizardAndami wizard = new WizardAndami(iicon);
|
171 |
RepeatedChooseGeometryTypePanel panelChoose = new RepeatedChooseGeometryTypePanel(
|
172 |
wizard.getWizardComponents()); |
173 |
RepeatedFieldDefinitionPanel panelFields = new RepeatedFieldDefinitionPanel(
|
174 |
wizard.getWizardComponents()); |
175 |
NewOracleTableWizard connPanel = new NewOracleTableWizard(
|
176 |
wizard.getWizardComponents()); |
177 |
|
178 |
wizard.getWizardComponents().addWizardPanel(panelChoose); |
179 |
wizard.getWizardComponents().addWizardPanel(panelFields); |
180 |
wizard.getWizardComponents().addWizardPanel(connPanel); |
181 |
|
182 |
View theView = (View) w; |
183 |
MapContext mc = theView.getMapControl().getMapContext(); |
184 |
|
185 |
NewOracleTableFinishAction action = new NewOracleTableFinishAction(
|
186 |
wizard.getWizardComponents(), wizard, connPanel, mc); |
187 |
|
188 |
wizard.getWizardComponents().setFinishAction(action); |
189 |
wizard.getWizardComponents().getFinishButton().setEnabled( |
190 |
false);
|
191 |
wizard.getWindowInfo().setWidth(640);
|
192 |
wizard.getWindowInfo().setHeight(350);
|
193 |
wizard.getWindowInfo().setTitle( |
194 |
PluginServices.getText(this, "new_layer")); |
195 |
PluginServices.getMDIManager().addWindow(wizard); |
196 |
|
197 |
} catch (Exception ex) { |
198 |
logger |
199 |
.error("While showing new oracle spatial table wizard: "
|
200 |
+ ex.getMessage()); |
201 |
} |
202 |
} |
203 |
} |
204 |
} |
205 |
|
206 |
/**
|
207 |
*
|
208 |
*/
|
209 |
public boolean isEnabled() { |
210 |
return isVisible();
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* Is visible when there is one vector layer selected
|
215 |
*/
|
216 |
public boolean isVisible() { |
217 |
|
218 |
if (!ORACLE_JAR_PRESENT) {
|
219 |
return false; |
220 |
} |
221 |
|
222 |
try {
|
223 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
224 |
|
225 |
if (w instanceof View) { |
226 |
View v = (View) w; |
227 |
MapControl mc = v.getMapControl(); |
228 |
MapContext mx = mc.getMapContext(); |
229 |
FLayer[] lyrs = mx.getLayers().getActives();
|
230 |
|
231 |
if (lyrs.length == 1) { |
232 |
FLayer lyr = lyrs[0];
|
233 |
|
234 |
if ((lyr instanceof FLyrVect) && (true)) { |
235 |
return true; |
236 |
} |
237 |
} |
238 |
} |
239 |
} catch (Exception ex) { |
240 |
return false; |
241 |
} |
242 |
|
243 |
return false; |
244 |
} |
245 |
|
246 |
/**
|
247 |
* Create resource url
|
248 |
*
|
249 |
* @param path
|
250 |
* @return
|
251 |
*/
|
252 |
private java.net.URL createResourceUrl(String path) { |
253 |
return getClass().getClassLoader().getResource(path);
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* Is there a Oracle jar present
|
258 |
*
|
259 |
* @return
|
260 |
*/
|
261 |
private boolean isOracleJarPresent() { |
262 |
|
263 |
try {
|
264 |
Class rowid_class = Class.forName("oracle.sql.ROWID"); |
265 |
} catch (Exception ex) { |
266 |
logger.error("Unable to instantiate ROWID (oracle jar missing?) : "
|
267 |
+ ex.getMessage()); |
268 |
return false; |
269 |
} |
270 |
return true; |
271 |
} |
272 |
} |