Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / ExportOracleExtension.java @ 14028

History | View | Annotate | Download (6.1 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

    
47
import org.apache.log4j.Logger;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51
import com.iver.andami.ui.mdiManager.IWindow;
52
import com.iver.cit.gvsig.About;
53
import com.iver.cit.gvsig.fmap.MapContext;
54
import com.iver.cit.gvsig.fmap.MapControl;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB;
57
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
58
import com.iver.cit.gvsig.project.documents.view.gui.View;
59
import com.iver.utiles.extensionPoints.ExtensionPoint;
60
import com.iver.utiles.extensionPoints.ExtensionPoints;
61
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
62

    
63

    
64
/**
65
 * This extension adds the export-to-oracle button.
66
 *
67
 * @author jldominguez
68
 *
69
 */
70
public class ExportOracleExtension extends Extension {
71
    private static Logger logger = Logger.getLogger(ExportOracleExtension.class.getName());
72

    
73
    public void initialize() {
74

    
75
        // about
76
        java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
77
        About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class);
78
        claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
79
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
80
        try {
81
                        ((ExtensionPoint)extensionPoints.get("Layers")).addAlias(FLayerVectorialDB.class.getName(), "VectorialDB");
82
                } catch (KeyException e) {
83
                        // TODO Auto-generated catch block
84
                        e.printStackTrace();
85
                }
86
//        System.out.println("A?ado WizardVectorialDB.");
87
//        AddLayer.addWizard(WizardVectorialDB.class);
88
//
89
//        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
90
//
91
////        extensionPoints.add("CatalogLayers", "POSTGIS", new PostgisLayerBuilder());
92
//        extensionPoints.add("Layers", FLayerJDBCVectorial.class.getName(),
93
//                        FLayerJDBCVectorial.class);
94

    
95
//        try {
96
//            ((ExtensionPoint) extensionPoints.get("Layers")).addAlias(FLayerJDBCVectorial.class.getName(),
97
//                "JDBCVectorial");
98
//        }
99
//        catch (KeyException e) {
100
//            // TODO Auto-generated catch block
101
//            e.printStackTrace();
102
//        }
103

    
104
        OraEpsgTableLoader loader = new OraEpsgTableLoader();
105
        if (!loader.createOracleEpsgTable()) {
106
                logger.error("Unable to create ORA_EPSG datasource!");
107
        }
108
    }
109

    
110
    public void execute(String actionCommand) {
111
        if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) {
112
            FLyrVect lyrv = null;
113
            MapContext mx = null;
114

    
115
            try {
116
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
117

    
118
                if (w instanceof View) {
119
                    View v = (View) w;
120
                    MapControl mc = v.getMapControl();
121
                    mx = mc.getMapContext();
122

    
123
                    FLayer[] lyrs = mx.getLayers().getActives();
124

    
125
                    if (lyrs.length == 1) {
126
                        FLayer lyr = lyrs[0];
127

    
128
                        if (lyr instanceof FLyrVect) {
129
                            lyrv = (FLyrVect) lyr;
130

    
131
                            ExportToOracle export = new ExportToOracle();
132
                            export.toOracle(mx, lyrv);
133
                        }
134
                    }
135
                }
136
            }
137
            catch (Exception ex) {
138
                System.err.println(
139
                    "Unexpected error while getting active vect layer: " +
140
                    ex.getMessage());
141
                System.err.println("Nothing done.");
142
            }
143
        }
144
    }
145

    
146
    public boolean isEnabled() {
147
        return isVisible();
148

    
149
        // return true;
150
    }
151

    
152
    /**
153
     * Is visible when there is one vector layer selected
154
     */
155
    public boolean isVisible() {
156
        // return true;
157
        try {
158
            IWindow w = PluginServices.getMDIManager().getActiveWindow();
159

    
160
            if (w instanceof View) {
161
                View v = (View) w;
162
                MapControl mc = v.getMapControl();
163
                MapContext mx = mc.getMapContext();
164
                FLayer[] lyrs = mx.getLayers().getActives();
165

    
166
                if (lyrs.length == 1) {
167
                    FLayer lyr = lyrs[0];
168

    
169
                    if ((lyr instanceof FLyrVect) && (true)) {
170
                        return true;
171
                    }
172
                }
173
            }
174
        }
175
        catch (Exception ex) {
176
            return false;
177
        }
178

    
179
        return false;
180
    }
181

    
182
    private java.net.URL createResourceUrl(String path) {
183
        return getClass().getClassLoader().getResource(path);
184
    }
185
}