Statistics
| Revision:

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

History | View | Annotate | Download (4.57 KB)

1
package org.gvsig.oraclespatial.extension;
2

    
3
import java.awt.geom.Rectangle2D;
4
import java.sql.Types;
5
import java.util.ArrayList;
6

    
7
import jwizardcomponent.FinishAction;
8
import jwizardcomponent.JWizardComponents;
9

    
10

    
11
import org.gvsig.fmap.mapcontext.MapContext;
12
import org.gvsig.fmap.mapcontext.ViewPort;
13
import org.gvsig.oraclespatial.driver.OracleSpatialDriver;
14
import org.gvsig.oraclespatial.driver.OracleSpatialWriter;
15
import org.gvsig.oraclespatial.gui.NewOracleSpatialTableWizard;
16
import org.gvsig.oraclespatial.gui.RepeatedChooseGeometryTypePanel;
17
import org.gvsig.oraclespatial.gui.RepeatedFieldDefinitionPanel;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

    
21
import com.iver.andami.PluginServices;
22
import com.iver.andami.ui.mdiManager.IWindow;
23

    
24

    
25
public class NewOracleSpatialTableFinishAction extends FinishAction {
26
        
27
        private static Logger logger = LoggerFactory.getLogger(NewOracleSpatialTableFinishAction.class.getName());
28
        private NewOracleSpatialTableWizard connectionPanel;
29
        private RepeatedChooseGeometryTypePanel geoTypePanel;
30
        private RepeatedFieldDefinitionPanel fieldsPanel;
31
        private MapContext theMapContext;
32
        private IWindow closeThis;
33
        
34
        
35
        // ...
36
        
37
        public NewOracleSpatialTableFinishAction(
38
                        JWizardComponents wc,
39
                        IWindow closeit,
40
                        NewOracleSpatialTableWizard connPanel,
41
                        MapContext mc) {
42
                
43
                super(wc);
44
                theMapContext = mc;
45
                closeThis = closeit;
46
                connectionPanel = connPanel;
47
                geoTypePanel = (RepeatedChooseGeometryTypePanel) wc.getWizardPanel(0);
48
                fieldsPanel = (RepeatedFieldDefinitionPanel) wc.getWizardPanel(1);
49
        }
50

    
51
        public void performAction() {
52

    
53
                PluginServices.getMDIManager().closeWindow(closeThis);
54
                
55
                ViewPort vp = theMapContext.getViewPort();
56
                
57
                DBLayerDefinition lyr_def = new DBLayerDefinition();
58
                
59
                FieldDescription[] flds = fieldsPanel.getFieldsDescription();
60
                FieldDescription[] flds_new = getValidFields(flds);
61
                
62
                lyr_def.setFieldsDesc(flds_new);
63
                
64
                String table_name = geoTypePanel.getLayerName().toUpperCase();
65
                lyr_def.setTableName(table_name);
66
                String usr = connectionPanel.getServExplorerParams().getUser();
67
                lyr_def.setUser(usr.toUpperCase());
68
                String epsg_code = vp.getProjection().getAbrev();
69
                lyr_def.setSRID_EPSG(epsg_code.substring(5));
70
                
71
                lyr_def.setFieldID(OracleSpatialDriver.ORACLE_ID_FIELD);
72
                lyr_def.setFieldGeometry(OracleSpatialDriver.DEFAULT_GEO_FIELD);
73
                lyr_def.setWhereClause("");
74
                
75
                Rectangle2D extent = vp.getAdjustedExtent();
76
                if (extent == null) {
77
                        int h = vp.getImageHeight();
78
                        int w = vp.getImageWidth();
79
                        extent = new Rectangle2D.Double(0, 0, w, h);
80
                }
81
                IConnection iconn = connectionPanel.getServExplorerParams().getConnection();
82

    
83
                // --------------------------------------------------------------------
84
                // -------------------------------------------------------------------
85
                // --------------------------------------------------------------------
86
                theMapContext.beginAtomicEvent();
87
                
88
                OracleSpatialWriter.createEmptyTable(lyr_def, iconn, extent);
89
                OracleSpatialDriver oracleDrv = new OracleSpatialDriver();
90
                oracleDrv.setData(iconn, lyr_def);
91
                FLyrVect lyr = (FLyrVect) LayerFactory.createDBLayer(
92
                                oracleDrv,
93
                                table_name,
94
                                vp.getProjection());
95

    
96
                lyr.setVisible(true);
97
                theMapContext.getLayers().addLayer(lyr);
98
                theMapContext.endAtomicEvent();
99
                // --------------------------------------------------------------------
100
                // --------------------------------------------------------------------
101
                // --------------------------------------------------------------------
102
                
103
        }
104
        
105
        private boolean validFieldName(FieldDescription f_desc) {
106
                
107
                if ((f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE) == 0)
108
                                || (f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.ORACLE_ID_FIELD) == 0)) {
109
                        return false;
110
                }
111
                return true;
112
        }
113

    
114
        private FieldDescription[] getValidFields(FieldDescription[] ff) {
115
                
116
                // remove GID, ROWID
117
                ArrayList aux = new ArrayList();
118

    
119
                // rowid
120
                FieldDescription row_fld = new FieldDescription();
121
                row_fld.setFieldName(OracleSpatialDriver.ORACLE_ID_FIELD);
122
                row_fld.setFieldType(Types.VARCHAR);
123
                aux.add(row_fld);
124
                
125
                
126
                for (int i=0; i<ff.length; i++) {
127
                        if (validFieldName(ff[i])) {
128
                                aux.add(ff[i]);
129
                        }
130
                }
131
                
132
                
133
                // gid
134
                FieldDescription gid_fld = new FieldDescription();
135
                gid_fld.setFieldName(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE);
136
                gid_fld.setFieldType(Types.INTEGER);
137
                aux.add(gid_fld);
138
                
139
                return (FieldDescription[]) aux.toArray(new FieldDescription[0]);
140
                // -------
141
        }
142

    
143
}