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