Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extOracleSpatial / src / org / gvsig / oraclespatial / extension / ExportOracleExtension.java @ 29455

History | View | Annotate | Download (7.27 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 java.security.KeyException;
46
import java.util.ArrayList;
47

    
48
import javax.swing.ImageIcon;
49

    
50

    
51
import org.gvsig.fmap.mapcontext.MapContext;
52
import org.gvsig.fmap.mapcontext.layers.FLayer;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLayerVectorialDB;
54
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
55
import org.gvsig.fmap.mapcontrol.MapControl;
56
import org.gvsig.oraclespatial.driver.OracleSpatialDriver;
57
import org.gvsig.oraclespatial.gui.NewOracleSpatialTableWizard;
58
import org.gvsig.oraclespatial.gui.RepeatedChooseGeometryTypePanel;
59
import org.gvsig.oraclespatial.gui.RepeatedFieldDefinitionPanel;
60
import org.gvsig.oraclespatial.utils.OraEpsgTableLoader;
61
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
62
import org.gvsig.tools.extensionpoint.impl.DefaultExtensionPointManager;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65

    
66
import com.iver.andami.PluginServices;
67
import com.iver.andami.messages.NotificationManager;
68
import com.iver.andami.plugins.Extension;
69
import com.iver.andami.ui.mdiManager.IWindow;
70
import com.iver.andami.ui.wizard.WizardAndami;
71
import com.iver.cit.gvsig.About;
72
import com.iver.cit.gvsig.project.documents.view.gui.View;
73

    
74

    
75

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

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

    
104
        // about
105
        java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
106
        About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class);
107
        claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
108
        
109
        ExtensionPointManager extmanager = DefaultExtensionPointManager.getManager();
110
        extmanager.get("Layers").addAlias(FLayerVectorialDB.class.getName(), "VectorialDB");
111
        
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
}