Statistics
| Revision:

root / branches / v10 / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / ExtJDBC_Spatial.java @ 13991

History | View | Annotate | Download (5.63 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 com.iver.andami.PluginServices;
46
import com.iver.andami.plugins.Extension;
47
import com.iver.andami.ui.mdiManager.IWindow;
48

    
49
import com.iver.cit.gvsig.About;
50
import com.iver.cit.gvsig.AddLayer;
51
import com.iver.cit.gvsig.fmap.MapContext;
52
import com.iver.cit.gvsig.fmap.MapControl;
53
import com.iver.cit.gvsig.fmap.layers.FLayer;
54
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
55
import com.iver.cit.gvsig.project.documents.view.gui.View;
56

    
57
import com.iver.utiles.extensionPoints.ExtensionPoint;
58
import com.iver.utiles.extensionPoints.ExtensionPoints;
59
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
60

    
61
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
62
import es.prodevelop.cit.gvsig.fmap.layers.FLayerJDBCVectorial;
63
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.WizardJDBC;
64

    
65
import org.apache.log4j.Logger;
66

    
67
import java.security.KeyException;
68

    
69

    
70
/**
71
 * This extension adds the export-to-oracle button.
72
 *
73
 * @author jldominguez
74
 *
75
 */
76
public class ExtJDBC_Spatial extends Extension {
77
    private static Logger logger = Logger.getLogger(ExtJDBC_Spatial.class.getName());
78

    
79
    public void initialize() {
80
        // about
81
        java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
82
        About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class);
83
        claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
84

    
85
        System.out.println("A?ado WizardJDBC.");
86
        AddLayer.addWizard(WizardJDBC.class);
87

    
88
        ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
89

    
90
        extensionPoints.add("CatalogLayers", "POSTGIS", new JDBCLayerBuilder());
91
        extensionPoints.add("Layers", FLayerJDBCVectorial.class.getName(),
92
                        FLayerJDBCVectorial.class);
93

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

    
104
    public void execute(String actionCommand) {
105
        if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) {
106
            OracleSpatialDriver.createOracleEpsgTable();
107

    
108
            FLyrVect lyrv = null;
109
            MapContext mx = null;
110

    
111
            try {
112
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
113

    
114
                if (w instanceof View) {
115
                    View v = (View) w;
116
                    MapControl mc = v.getMapControl();
117
                    mx = mc.getMapContext();
118

    
119
                    FLayer[] lyrs = mx.getLayers().getActives();
120

    
121
                    if (lyrs.length == 1) {
122
                        FLayer lyr = lyrs[0];
123

    
124
                        if (lyr instanceof FLyrVect) {
125
                            lyrv = (FLyrVect) lyr;
126

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

    
142
    public boolean isEnabled() {
143
        return isVisible();
144

    
145
        // return true;
146
    }
147

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

    
156
            if (w instanceof View) {
157
                View v = (View) w;
158
                MapControl mc = v.getMapControl();
159
                MapContext mx = mc.getMapContext();
160
                FLayer[] lyrs = mx.getLayers().getActives();
161

    
162
                if (lyrs.length == 1) {
163
                    FLayer lyr = lyrs[0];
164

    
165
                    if ((lyr instanceof FLyrVect) && (true)) {
166
                        return true;
167
                    }
168
                }
169
            }
170
        }
171
        catch (Exception ex) {
172
            return false;
173
        }
174

    
175
        return false;
176
    }
177

    
178
    private java.net.URL createResourceUrl(String path) {
179
        return getClass().getClassLoader().getResource(path);
180
    }
181
}