svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extOracleSpatial / src / org / gvsig / oraclespatial / extension / NewOracleSpatialTableExtension.java @ 29455
History | View | Annotate | Download (3.95 KB)
1 |
package org.gvsig.oraclespatial.extension; |
---|---|
2 |
|
3 |
import javax.swing.ImageIcon; |
4 |
|
5 |
import org.gvsig.fmap.mapcontext.MapContext; |
6 |
import org.gvsig.oraclespatial.driver.OracleSpatialDriver; |
7 |
import org.gvsig.oraclespatial.gui.NewOracleSpatialTableWizard; |
8 |
import org.gvsig.oraclespatial.gui.RepeatedChooseGeometryTypePanel; |
9 |
import org.gvsig.oraclespatial.gui.RepeatedFieldDefinitionPanel; |
10 |
import org.slf4j.Logger; |
11 |
import org.slf4j.LoggerFactory; |
12 |
|
13 |
|
14 |
import com.iver.andami.PluginServices; |
15 |
import com.iver.andami.plugins.Extension; |
16 |
import com.iver.andami.ui.mdiManager.IWindow; |
17 |
import com.iver.andami.ui.wizard.WizardAndami; |
18 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
19 |
|
20 |
|
21 |
public class NewOracleSpatialTableExtension extends Extension { |
22 |
|
23 |
private static Logger logger = LoggerFactory.getLogger(NewOracleSpatialTableExtension.class.getName()); |
24 |
public static boolean ORACLE_JAR_PRESENT = false; |
25 |
|
26 |
|
27 |
public void initialize() { |
28 |
ORACLE_JAR_PRESENT = isOracleJarPresent(); |
29 |
} |
30 |
|
31 |
public void execute(String actionCommand) { |
32 |
if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) { |
33 |
|
34 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
35 |
if (w instanceof View) { |
36 |
try {
|
37 |
String _file = createResourceUrl("images/new_geodb_table.png").getFile(); |
38 |
ImageIcon iicon = new ImageIcon(_file); |
39 |
|
40 |
DriverManager writerManager = LayerFactory.getDM();
|
41 |
WizardAndami wizard = new WizardAndami(iicon);
|
42 |
RepeatedChooseGeometryTypePanel panelChoose = |
43 |
new RepeatedChooseGeometryTypePanel(wizard.getWizardComponents());
|
44 |
RepeatedFieldDefinitionPanel panelFields = |
45 |
new RepeatedFieldDefinitionPanel(wizard.getWizardComponents());
|
46 |
NewOracleSpatialTableWizard connPanel = |
47 |
new NewOracleSpatialTableWizard(wizard.getWizardComponents());
|
48 |
|
49 |
wizard.getWizardComponents().addWizardPanel(panelChoose); |
50 |
wizard.getWizardComponents().addWizardPanel(panelFields); |
51 |
wizard.getWizardComponents().addWizardPanel(connPanel); |
52 |
|
53 |
Driver driver = writerManager.getDriver(OracleSpatialDriver.NAME);
|
54 |
panelFields.setWriter(((IWriteable) driver).getWriter()); |
55 |
panelChoose.setDriver(driver); |
56 |
|
57 |
View theView = (View) w; |
58 |
MapContext mc = theView.getMapControl().getMapContext(); |
59 |
|
60 |
NewOracleSpatialTableFinishAction action = |
61 |
new NewOracleSpatialTableFinishAction(
|
62 |
wizard.getWizardComponents(), |
63 |
wizard, |
64 |
connPanel, |
65 |
mc); |
66 |
|
67 |
wizard.getWizardComponents().setFinishAction(action); |
68 |
wizard.getWizardComponents().getFinishButton().setEnabled(false);
|
69 |
wizard.getWindowInfo().setWidth(640);
|
70 |
wizard.getWindowInfo().setHeight(350);
|
71 |
wizard.getWindowInfo().setTitle(PluginServices.getText(this, "new_layer")); |
72 |
PluginServices.getMDIManager().addWindow(wizard); |
73 |
|
74 |
} catch (Exception ex) { |
75 |
logger.error("While showing new oracle spatial table wizard: " + ex.getMessage());
|
76 |
} |
77 |
} |
78 |
} |
79 |
} |
80 |
|
81 |
public boolean isEnabled() { |
82 |
|
83 |
if (!ORACLE_JAR_PRESENT) return false; |
84 |
|
85 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
86 |
return (w instanceof View); |
87 |
} |
88 |
|
89 |
public boolean isVisible() { |
90 |
return isEnabled();
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Check presence of ojdbc14.jar.
|
95 |
* @return
|
96 |
*/
|
97 |
private boolean isOracleJarPresent() { |
98 |
|
99 |
try {
|
100 |
Class rowid_class = Class.forName("oracle.sql.ROWID"); |
101 |
} catch (Exception ex) { |
102 |
logger.error("Unable to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
|
103 |
return false; |
104 |
} |
105 |
return true; |
106 |
} |
107 |
|
108 |
private java.net.URL createResourceUrl(String path) { |
109 |
return getClass().getClassLoader().getResource(path);
|
110 |
} |
111 |
|
112 |
} |