svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extOracleSpatial / src / org / gvsig / oraclespatial / extension / NewOracleSpatialTableExtension.java @ 29579
History | View | Annotate | Download (3.61 KB)
1 |
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 |
20 |
.getLogger(NewOracleSpatialTableExtension.class.getName()); |
21 |
public static boolean ORACLE_JAR_PRESENT = false; |
22 |
|
23 |
/**
|
24 |
* Initialize extension
|
25 |
*/
|
26 |
public void initialize() { |
27 |
// Validate if Oracle Jar is present
|
28 |
ORACLE_JAR_PRESENT = isOracleJarPresent(); |
29 |
} |
30 |
|
31 |
/**
|
32 |
* execute extension process
|
33 |
*
|
34 |
* @param event
|
35 |
* name
|
36 |
*/
|
37 |
public void execute(String actionCommand) { |
38 |
|
39 |
// NEW ORACLE TABLE
|
40 |
if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) { |
41 |
|
42 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
43 |
if (w instanceof View) { |
44 |
try {
|
45 |
String _file = createResourceUrl(
|
46 |
"images/new_geodb_table.png").getFile();
|
47 |
ImageIcon iicon = new ImageIcon(_file); |
48 |
|
49 |
WizardAndami wizard = new WizardAndami(iicon);
|
50 |
RepeatedChooseGeometryTypePanel panelChoose = new RepeatedChooseGeometryTypePanel(
|
51 |
wizard.getWizardComponents()); |
52 |
RepeatedFieldDefinitionPanel panelFields = new RepeatedFieldDefinitionPanel(
|
53 |
wizard.getWizardComponents()); |
54 |
NewOracleSpatialTableWizard connPanel = new NewOracleSpatialTableWizard(
|
55 |
wizard.getWizardComponents()); |
56 |
|
57 |
wizard.getWizardComponents().addWizardPanel(panelChoose); |
58 |
wizard.getWizardComponents().addWizardPanel(panelFields); |
59 |
wizard.getWizardComponents().addWizardPanel(connPanel); |
60 |
|
61 |
View theView = (View) w; |
62 |
MapContext mc = theView.getMapControl().getMapContext(); |
63 |
|
64 |
NewOracleSpatialTableFinishAction action = new NewOracleSpatialTableFinishAction(
|
65 |
wizard.getWizardComponents(), wizard, connPanel, mc); |
66 |
|
67 |
wizard.getWizardComponents().setFinishAction(action); |
68 |
wizard.getWizardComponents().getFinishButton().setEnabled( |
69 |
false);
|
70 |
wizard.getWindowInfo().setWidth(640);
|
71 |
wizard.getWindowInfo().setHeight(350);
|
72 |
wizard.getWindowInfo().setTitle( |
73 |
PluginServices.getText(this, "new_layer")); |
74 |
PluginServices.getMDIManager().addWindow(wizard); |
75 |
|
76 |
} catch (Exception ex) { |
77 |
logger |
78 |
.error("While showing new oracle spatial table wizard: "
|
79 |
+ ex.getMessage()); |
80 |
} |
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
/**
|
86 |
* extension enable
|
87 |
*
|
88 |
* @return
|
89 |
*/
|
90 |
public boolean isEnabled() { |
91 |
|
92 |
if (!ORACLE_JAR_PRESENT)
|
93 |
return false; |
94 |
|
95 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
96 |
return (w instanceof View); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* extension functionalities visible
|
101 |
*
|
102 |
* @return
|
103 |
*/
|
104 |
public boolean isVisible() { |
105 |
return isEnabled();
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Check presence of ojdbc14.jar.
|
110 |
*
|
111 |
* @return
|
112 |
*/
|
113 |
private boolean isOracleJarPresent() { |
114 |
|
115 |
try {
|
116 |
Class rowid_class = Class.forName("oracle.sql.ROWID"); |
117 |
} catch (Exception ex) { |
118 |
logger.error("Unable to instantiate ROWID (oracle jar missing?) : "
|
119 |
+ ex.getMessage()); |
120 |
return false; |
121 |
} |
122 |
return true; |
123 |
} |
124 |
|
125 |
private java.net.URL createResourceUrl(String path) { |
126 |
return getClass().getClassLoader().getResource(path);
|
127 |
} |
128 |
|
129 |
} |