Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / ExportOracleExtension.java @ 18370

History | View | Annotate | Download (7.41 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 es.prodevelop.cit.gvsig.jdbc_spatial;
44

    
45
import java.security.KeyException;
46
import java.util.ArrayList;
47

    
48
import javax.swing.ImageIcon;
49

    
50
import org.apache.log4j.Logger;
51

    
52
import com.hardcode.driverManager.Driver;
53
import com.hardcode.driverManager.DriverLoadException;
54
import com.hardcode.driverManager.DriverManager;
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.messages.NotificationManager;
57
import com.iver.andami.plugins.Extension;
58
import com.iver.andami.ui.mdiManager.IWindow;
59
import com.iver.andami.ui.wizard.WizardAndami;
60
import com.iver.cit.gvsig.About;
61
import com.iver.cit.gvsig.fmap.MapContext;
62
import com.iver.cit.gvsig.fmap.MapControl;
63
import com.iver.cit.gvsig.fmap.edition.IWriteable;
64
import com.iver.cit.gvsig.fmap.layers.FLayer;
65
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB;
66
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
67
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
68
import com.iver.cit.gvsig.project.documents.view.gui.View;
69
import com.iver.utiles.extensionPoints.ExtensionPoint;
70
import com.iver.utiles.extensionPoints.ExtensionPoints;
71
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
72

    
73
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
74
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.NewOracleSpatialTableWizard;
75
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedChooseGeometryTypePanel;
76
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedFieldDefinitionPanel;
77

    
78

    
79
/**
80
 * This extension adds the export-to-oracle button.
81
 *
82
 * @author jldominguez
83
 *
84
 */
85
public class ExportOracleExtension extends Extension {
86
        
87
    private static Logger logger = Logger.getLogger(ExportOracleExtension.class.getName());
88
    
89
    public static boolean ORACLE_JAR_PRESENT = false;
90

    
91
    public void initialize() {
92
            
93
            ORACLE_JAR_PRESENT = isOracleJarPresent();
94
            
95
            if (!ORACLE_JAR_PRESENT) {
96
                    logger.info("*-----------------------------------------------------------------------*");
97
                    logger.info("* Oracle library not found!                                             *");
98
                    logger.info("* You need to place the Oracle JDBC library in gvSIG's main LIB folder. *");
99
                    logger.info("* Read the Oracle driver user manual for details.                       *");
100
                    logger.info("*-----------------------------------------------------------------------*");
101
            } else {
102
                    logger.info("*-----------------------------------------------------------------------*");
103
                    logger.info("* Found the Oracle JDBC library! :)                                     *");
104
                    logger.info("*-----------------------------------------------------------------------*");
105
            }
106

    
107
        // about
108
        java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
109
        About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class);
110
        claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
111
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
112
        try {
113
                        ((ExtensionPoint)extensionPoints.get("Layers")).addAlias(FLayerVectorialDB.class.getName(), "VectorialDB");
114
                } catch (KeyException e) {
115
                        logger.error("While adding alias to extension point: " + e.getMessage());
116
                }
117

    
118
        OraEpsgTableLoader loader = new OraEpsgTableLoader();
119
        if (!loader.createOracleEpsgTable()) {
120
                logger.error("Unable to create ORA_EPSG datasource!");
121
        }
122
    }
123

    
124
    private boolean isOracleJarPresent() {
125
            
126
            try {
127
                    Class rowid_class = Class.forName("oracle.sql.ROWID");
128
            } catch (Exception ex) {
129
                    logger.error("Unable to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
130
                    return false;
131
            }
132
                return true;
133
        }
134

    
135
        public void execute(String actionCommand) {
136
                
137
        if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) {
138
            FLyrVect lyrv = null;
139
            MapContext mx = null;
140

    
141
            try {
142
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
143

    
144
                if (w instanceof View) {
145
                    View v = (View) w;
146
                    MapControl mc = v.getMapControl();
147
                    mx = mc.getMapContext();
148

    
149
                    FLayer[] lyrs = mx.getLayers().getActives();
150

    
151
                    if (lyrs.length == 1) {
152
                        FLayer lyr = lyrs[0];
153

    
154
                        if (lyr instanceof FLyrVect) {
155
                            lyrv = (FLyrVect) lyr;
156

    
157
                            ExportToOracle export = new ExportToOracle();
158
                            export.toOracle(mx, lyrv);
159
                        }
160
                    }
161
                }
162
            }
163
            catch (Exception ex) {
164
                    logger.error(
165
                    "Unexpected error while getting active vect layer: " +
166
                    ex.getMessage());
167
                    logger.error("Nothing done.");
168
            }
169
        }
170
    }
171

    
172
    public boolean isEnabled() {
173
        return isVisible();
174
    }
175

    
176
    /**
177
     * Is visible when there is one vector layer selected
178
     */
179
    public boolean isVisible() {
180
       
181
            if (!ORACLE_JAR_PRESENT) {
182
                    return false;
183
            }
184
            // if (true) return true;
185
            
186
        try {
187
            IWindow w = PluginServices.getMDIManager().getActiveWindow();
188

    
189
            if (w instanceof View) {
190
                View v = (View) w;
191
                MapControl mc = v.getMapControl();
192
                MapContext mx = mc.getMapContext();
193
                FLayer[] lyrs = mx.getLayers().getActives();
194

    
195
                if (lyrs.length == 1) {
196
                    FLayer lyr = lyrs[0];
197

    
198
                    if ((lyr instanceof FLyrVect) && (true)) {
199
                        return true;
200
                    }
201
                }
202
            }
203
        } catch (Exception ex) {
204
            return false;
205
        }
206

    
207
        return false;
208
    }
209

    
210
    private java.net.URL createResourceUrl(String path) {
211
        return getClass().getClassLoader().getResource(path);
212
    }
213
}