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