Revision 18370

View differences:

trunk/extensions/extOracleSpatial/config/text.properties
13 13
intro_tablename=Introduzca nombre de tabla
14 14
nombre_demasiado_largo=Nombre demasiado largo
15 15
nombre_no_valido=Nombre no v?lido
16
new_oracle_spatial_table=Nueva tabla Oracle Spatial
16 17
oracle_spatial=Oracle Spatial
17 18
password=Contrase?a
18 19

  
trunk/extensions/extOracleSpatial/config/text_en.properties
13 13
intro_tablename=Enter table name
14 14
nombre_demasiado_largo=Name is too long
15 15
nombre_no_valido=Invalid name
16
new_oracle_spatial_table=New Oracle Spatial table
16 17
oracle_spatial=Oracle Spatial
17 18
password=Password
trunk/extensions/extOracleSpatial/config/config.xml
4 4
	<depends plugin-name="com.iver.cit.gvsig" />
5 5
	<resourceBundle name="text"/>
6 6
	<extensions>
7
	
7 8
		<extension class-name="es.prodevelop.cit.gvsig.jdbc_spatial.ExportOracleExtension"
8
			description="Support to access Oracle Spatial databases"
9
			active="true">
9
			description="Support to access Oracle Spatial databases" active="true">
10 10

  
11 11
			<menu text="Capa/export_to/oracle_spatial"
12 12
			action-command="EXPORT_TO_ORACLE_SPATIAL"
13
			icon="images/oracle.png"
14
			/>
13
			icon="images/oracle.png" />
14
		</extension>
15
		
16
		<extension class-name="es.prodevelop.cit.gvsig.jdbc_spatial.NewOracleSpatialTableExtension"
17
			description="Support to create new  Oracle Spatial tables" active="true">
18
			<menu text="Vista/new_layer/new_oracle_spatial_table" action-command="NEW_ORACLE_SPATIAL"
19
			icon="images/oracle.png" />
20
		</extension>
15 21

  
16
		</extension>
17 22
	</extensions>
18 23
</plugin-config>
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialDriver.java
4186 4186
            writer.setSRID(oracleSRID);
4187 4187

  
4188 4188
            try {
4189
                writer.initialize(getLyrDef());
4189
            	DBLayerDefinition db_lyr_def = getLyrDef();
4190
            	if (db_lyr_def == null) {
4191
            		logger.warn("Found a null DB layer definition, method initialize of OracleWriter not called.");
4192
            	} else {
4193
            		writer.initialize(getLyrDef());
4194
            	}
4195
                
4190 4196
            } catch (InitializeWriterException e) {
4191 4197
                logger.error("While initializing OS Writer: " + e.getMessage(), e);
4192 4198
            }
......
4198 4204
    }
4199 4205

  
4200 4206
    /**
4201
     * Tells whether the SRS is geodetic or not
4207
     * Tells whether the SRS is geodetic or not-
4202 4208
     * @return whether the SRS is geodetic or not
4203 4209
     */
4204 4210
    public boolean isGeogCS() {
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/fmap/drivers/jdbc/oracle/OracleSpatialWriter.java
145 145
    		return true;
146 146
    	}
147 147
    }
148
    
149
    public static boolean createEmptyTable(
150
    		DBLayerDefinition lyr_def,
151
    		IConnection the_conn,
152
    		Rectangle2D rect) {
153
    	
154
            String srid_epsg = lyr_def.getSRID_EPSG();
155
            boolean with_srid = true;
156
            String _ora_srid = "NULL";
157
            
158
            try {
159
				_ora_srid = OracleSpatialDriver.epsgSridToOracleSrid(srid_epsg);
160
			} catch (Exception e1) {
161
				logger.error("Unknown EPSG code: " + srid_epsg);
162
				with_srid = false;
163
			}
148 164

  
165
            String _sql_rem_meta = OracleSpatialDriver.getRemoveMetadataSql(lyr_def);
166
            String _sql_drop = OracleSpatialDriver.getDropTableSql(lyr_def);
167
            String _sql_creation = OracleSpatialDriver.getTableCreationSql(lyr_def);
168
            String _sql_index = OracleSpatialDriver.getIndexCreationSql(lyr_def);
169

  
170
            String _sql_meta = OracleSpatialDriver.getMetadataUpdateSql(
171
            		lyr_def.getUser(),
172
            		lyr_def.getTableName(),
173
            		_ora_srid, rect, 2, with_srid);
174

  
175
            boolean removed = true;
176

  
177
            try {
178
                java.sql.PreparedStatement ps =
179
                	((ConnectionJDBC) the_conn).getConnection().prepareStatement(_sql_drop);
180
                ps.execute();
181
                ps.close();
182
            }
183
            catch (SQLException ex) {
184
                logger.info("Table did not exist: " + lyr_def.getTableName());
185
                removed = false;
186
            }
187

  
188
            if (removed) {
189
                logger.info("Table existed and was deleted: " + lyr_def.getTableName());
190
            }
191
            
192
            try {
193
                java.sql.PreparedStatement ps = ((ConnectionJDBC) the_conn).getConnection().prepareStatement(_sql_creation);
194
                ps.execute();
195
                ps.close();
196
            }
197
            catch (SQLException ex) {
198
                logger.error("Error while executing SQL for table creation: " +
199
                    ex.getMessage(), ex);
200
                return false;
201
            }
202

  
203
            try {
204
                java.sql.PreparedStatement ps = ((ConnectionJDBC)the_conn).getConnection().prepareStatement(_sql_rem_meta);
205
                ps.execute();
206
                ps.close();
207
            }
208
            catch (SQLException ex) {
209
                logger.error("Error while executing SQL for metadata removal: " +
210
                    ex.getMessage(), ex);
211
            }
212

  
213
            try {
214
                java.sql.PreparedStatement ps = ((ConnectionJDBC)the_conn).getConnection().prepareStatement(_sql_meta);
215
                ps.execute();
216
                ps.close();
217
            }
218
            catch (SQLException ex) {
219
                logger.error(
220
                    "Error while executing SQL for metadata insertion: " +
221
                    ex.getMessage(), ex);
222
                return false;
223
            }
224

  
225
            try {
226
                java.sql.PreparedStatement ps = ((ConnectionJDBC)the_conn).getConnection().prepareStatement(_sql_index);
227
                ps.execute();
228
                ps.close();
229
            }
230
            catch (SQLException ex) {
231
                logger.error("Error while executing SQL for index creation: " +
232
                    ex.getMessage(), ex);
233
                return false;
234
            }
235
            
236
            return true;
237
    }
238

  
149 239
    public void preProcess() throws StartWriterVisitorException {
150 240
    	
151 241
    	IConnection conn = ((DBLayerDefinition) tableDef).getConnection();
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/NewOracleSpatialTableExtension.java
1
package es.prodevelop.cit.gvsig.jdbc_spatial;
2

  
3
import javax.swing.ImageIcon;
4

  
5
import org.apache.log4j.Logger;
6

  
7
import com.hardcode.driverManager.Driver;
8
import com.hardcode.driverManager.DriverManager;
9
import com.iver.andami.PluginServices;
10
import com.iver.andami.plugins.Extension;
11
import com.iver.andami.ui.mdiManager.IWindow;
12
import com.iver.andami.ui.wizard.WizardAndami;
13
import com.iver.cit.gvsig.fmap.MapContext;
14
import com.iver.cit.gvsig.fmap.edition.IWriteable;
15
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
16
import com.iver.cit.gvsig.project.documents.view.gui.View;
17

  
18
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
19
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.NewOracleSpatialTableWizard;
20
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedChooseGeometryTypePanel;
21
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedFieldDefinitionPanel;
22

  
23
public class NewOracleSpatialTableExtension extends Extension {
24
	
25
    private static Logger logger = Logger.getLogger(NewOracleSpatialTableExtension.class.getName());
26
    public static boolean ORACLE_JAR_PRESENT = false;
27
	
28

  
29
	public void initialize() {
30
		ORACLE_JAR_PRESENT = isOracleJarPresent();
31
	}
32

  
33
	public void execute(String actionCommand) {
34
        if (actionCommand.compareToIgnoreCase("NEW_ORACLE_SPATIAL") == 0) {
35

  
36
       	 IWindow w = PluginServices.getMDIManager().getActiveWindow();
37
       	 if (w instanceof View) {
38
       		 try {
39
       			String _file = createResourceUrl("images/new_geodb_table.png").getFile();
40
       			ImageIcon iicon = new ImageIcon(_file);
41
                
42
       			 DriverManager writerManager = LayerFactory.getDM();
43
       			 WizardAndami wizard = new WizardAndami(iicon);
44
       			 RepeatedChooseGeometryTypePanel panelChoose =
45
       				 new RepeatedChooseGeometryTypePanel(wizard.getWizardComponents());
46
       			 RepeatedFieldDefinitionPanel panelFields =
47
       				 new RepeatedFieldDefinitionPanel(wizard.getWizardComponents());
48
       			 NewOracleSpatialTableWizard connPanel = 
49
       				 new NewOracleSpatialTableWizard(wizard.getWizardComponents());
50

  
51
       			 wizard.getWizardComponents().addWizardPanel(panelChoose);
52
       			 wizard.getWizardComponents().addWizardPanel(panelFields);
53
       			 wizard.getWizardComponents().addWizardPanel(connPanel);
54
       			 
55
       			 Driver driver = writerManager.getDriver(OracleSpatialDriver.NAME);
56
       			 panelFields.setWriter(((IWriteable) driver).getWriter());
57
       			 panelChoose.setDriver(driver);
58

  
59
       			 View theView = (View) w;
60
       			 MapContext mc = theView.getMapControl().getMapContext();
61
       			 
62
       			 NewOracleSpatialTableFinishAction action = 
63
       				 new NewOracleSpatialTableFinishAction(
64
       						 wizard.getWizardComponents(),
65
       						 wizard,
66
       						 connPanel,
67
       						 mc);
68
       			 
69
       			 wizard.getWizardComponents().setFinishAction(action);
70
           		 wizard.getWizardComponents().getFinishButton().setEnabled(false);
71
           		 wizard.getWindowInfo().setWidth(640);
72
           		 wizard.getWindowInfo().setHeight(350);
73
           		 wizard.getWindowInfo().setTitle(PluginServices.getText(this, "new_layer"));
74
           		 PluginServices.getMDIManager().addWindow(wizard);
75
			
76
       		 } catch (Exception ex) {
77
       			 logger.error("While showing new oracle spatial table wizard: " + ex.getMessage());
78
       		 }
79
       	 }
80
       }
81
	}
82

  
83
	public boolean isEnabled() {
84

  
85
		if (!ORACLE_JAR_PRESENT) return false;
86
		
87
		IWindow w = PluginServices.getMDIManager().getActiveWindow();
88
      	return (w instanceof View); 
89
	}
90

  
91
	public boolean isVisible() {
92
		return isEnabled();
93
	}
94
	
95
	/**
96
	 * Check presence of ojdbc14.jar.
97
	 * @return
98
	 */
99
    private boolean isOracleJarPresent() {
100
    	
101
    	try {
102
    		Class rowid_class = Class.forName("oracle.sql.ROWID");
103
    	} catch (Exception ex) {
104
    		logger.error("Unable to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
105
    		return false;
106
    	}
107
		return true;
108
	}	
109
    
110
    private java.net.URL createResourceUrl(String path) {
111
        return getClass().getClassLoader().getResource(path);
112
    }    
113

  
114
}
0 115

  
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/ExportOracleExtension.java
43 43
package es.prodevelop.cit.gvsig.jdbc_spatial;
44 44

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

  
48
import javax.swing.ImageIcon;
49

  
47 50
import org.apache.log4j.Logger;
48 51

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

  
78

  
64 79
/**
65 80
 * This extension adds the export-to-oracle button.
66 81
 *
......
111 126
    	try {
112 127
    		Class rowid_class = Class.forName("oracle.sql.ROWID");
113 128
    	} catch (Exception ex) {
114
    		logger.error("Unbale to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
129
    		logger.error("Unable to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
115 130
    		return false;
116 131
    	}
117 132
		return true;
118 133
	}
119 134

  
120 135
	public void execute(String actionCommand) {
136
		
121 137
        if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) {
122 138
            FLyrVect lyrv = null;
123 139
            MapContext mx = null;
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/NewOracleSpatialTableFinishAction.java
1
package es.prodevelop.cit.gvsig.jdbc_spatial;
2

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

  
7
import org.apache.log4j.Logger;
8

  
9
import com.hardcode.driverManager.Driver;
10
import com.iver.andami.PluginServices;
11
import com.iver.andami.ui.mdiManager.IWindow;
12
import com.iver.cit.gvsig.fmap.MapContext;
13
import com.iver.cit.gvsig.fmap.ViewPort;
14
import com.iver.cit.gvsig.fmap.core.ICanReproject;
15
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
16
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
17
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
18
import com.iver.cit.gvsig.fmap.drivers.IConnection;
19
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
20
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
21
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
22

  
23
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
24
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialWriter;
25
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.NewOracleSpatialTableWizard;
26
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedChooseGeometryTypePanel;
27
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedFieldDefinitionPanel;
28

  
29
import jwizardcomponent.FinishAction;
30
import jwizardcomponent.JWizardComponents;
31

  
32
public class NewOracleSpatialTableFinishAction extends FinishAction {
33
	
34
	private static Logger logger = Logger.getLogger(NewOracleSpatialTableFinishAction.class.getName());
35
	private NewOracleSpatialTableWizard connectionPanel;
36
	private RepeatedChooseGeometryTypePanel geoTypePanel;
37
	private RepeatedFieldDefinitionPanel fieldsPanel;
38
	private MapContext theMapContext;
39
	private IWindow closeThis;
40
	
41
	
42
	// ...
43
	
44
	public NewOracleSpatialTableFinishAction(
45
			JWizardComponents wc,
46
			IWindow closeit,
47
			NewOracleSpatialTableWizard connPanel,
48
			MapContext mc) {
49
		
50
		super(wc);
51
		theMapContext = mc;
52
		closeThis = closeit;
53
		connectionPanel = connPanel;
54
		geoTypePanel = (RepeatedChooseGeometryTypePanel) wc.getWizardPanel(0);
55
		fieldsPanel = (RepeatedFieldDefinitionPanel) wc.getWizardPanel(1);
56
	}
57

  
58
	public void performAction() {
59

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

  
90
		// --------------------------------------------------------------------
91
		// -------------------------------------------------------------------
92
		// --------------------------------------------------------------------
93
		theMapContext.beginAtomicEvent();
94
		
95
		OracleSpatialWriter.createEmptyTable(lyr_def, iconn, extent);
96
		OracleSpatialDriver oracleDrv = new OracleSpatialDriver();
97
		oracleDrv.setData(iconn, lyr_def);
98
		FLyrVect lyr = (FLyrVect) LayerFactory.createDBLayer(
99
				oracleDrv,
100
				table_name,
101
				vp.getProjection());
102

  
103
		lyr.setVisible(true);
104
		theMapContext.getLayers().addLayer(lyr);
105
		theMapContext.endAtomicEvent();
106
		// --------------------------------------------------------------------
107
		// --------------------------------------------------------------------
108
		// --------------------------------------------------------------------
109
		
110
	}
111
	
112
	private boolean validFieldName(FieldDescription f_desc) {
113
		
114
		if ((f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE) == 0)
115
				|| (f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.ORACLE_ID_FIELD) == 0)) {
116
			return false;
117
		}
118
		return true;
119
	}
120

  
121
	private FieldDescription[] getValidFields(FieldDescription[] ff) {
122
		
123
		// remove GID, ROWID
124
		ArrayList aux = new ArrayList();
125

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

  
150
}
0 151

  
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/gui/jdbcwizard/NewOracleSpatialTableWizard.java
1
package es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard;
2

  
3

  
4
import java.awt.Component;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7
import java.awt.event.ItemEvent;
8
import java.awt.event.ItemListener;
9
import java.beans.PropertyChangeEvent;
10
import java.beans.PropertyChangeListener;
11

  
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JComboBox;
15
import javax.swing.JLabel;
16
import javax.swing.JOptionPane;
17

  
18

  
19
import org.apache.log4j.Logger;
20

  
21

  
22
import com.iver.andami.PluginServices;
23
import com.iver.cit.gvsig.SingleVectorialDBConnectionExtension;
24
import com.iver.cit.gvsig.fmap.drivers.DBException;
25
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
26
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager;
27
import com.iver.utiles.swing.JPasswordDlg;
28
import com.prodevelop.cit.gvsig.vectorialdb.wizard.VectorialDBConnectionParamsDialog;
29

  
30

  
31
import jwizardcomponent.JWizardComponents;
32
import jwizardcomponent.JWizardPanel;
33

  
34

  
35
public class NewOracleSpatialTableWizard extends JWizardPanel implements ItemListener, PropertyChangeListener, ActionListener {
36
	
37
	private static Logger logger = Logger.getLogger(NewOracleSpatialTableWizard.class.getName());
38

  
39
	
40
	public NewOracleSpatialTableWizard(JWizardComponents wizardComponents) {
41
		super(wizardComponents);
42
		wizardComponents.addPropertyChangeListener(this);
43
		initialize();
44
	}
45

  
46
	private JLabel chooseConnLabel = null;
47
	private JComboBox datasourceComboBox;
48
	private ConnectionWithParams theConnWithParams = null;
49
	private JButton dbButton;
50

  
51
	/**
52
	 * This method initializes this
53
	 *
54
	 */
55
	private void initialize() {
56
		
57
		datasourceComboBox = getDatasourceComboBox();
58
		loadVectorialDBDatasourcesCombo();
59
		
60
		chooseConnLabel = new JLabel();
61
		chooseConnLabel.setText(PluginServices.getText(this, "choose_connection"));
62
		chooseConnLabel.setBounds(new java.awt.Rectangle(14,9,300,21));
63
		
64
		dbButton = getJdbcButton();
65
        
66
        this.setLayout(null);
67
        this.setSize(new java.awt.Dimension(358,263));
68
        this.add(chooseConnLabel, null);
69
        this.add(datasourceComboBox, null);
70
        this.add(dbButton, null);
71
        getWizardComponents().getFinishButton().setEnabled(false);
72
	}
73

  
74
	public ConnectionWithParams getConnectionWithParams() {
75
		return theConnWithParams;
76
	}
77

  
78
    private JComboBox getDatasourceComboBox() {
79
        if (datasourceComboBox == null) {
80
            datasourceComboBox = new JComboBox();
81
            datasourceComboBox.setBounds(new java.awt.Rectangle(14,32,300,22));
82
            datasourceComboBox.addItemListener(this);
83
        }
84

  
85
        return datasourceComboBox;
86
    }	
87
    
88
    private void loadVectorialDBDatasourcesCombo() {
89
    	
90
        getDatasourceComboBox().removeAllItems();
91
        getDatasourceComboBox().addItem(new ConnectionWithParams());
92
        ConnectionWithParams[] conn =
93
        	SingleVectorialDBConnectionManager.instance().getAllConnections();
94

  
95
        if (conn == null) {
96
            return;
97
        }
98

  
99
        for (int i = 0; i < conn.length; i++) {
100
            getDatasourceComboBox().addItem(conn[i]);
101
        }
102
    }
103

  
104
	public void itemStateChanged(ItemEvent e) {
105
		
106
		Object src = e.getSource();
107
		if (src == datasourceComboBox) {
108
			
109
            Object sel_obj = datasourceComboBox.getSelectedItem();
110

  
111
            if (sel_obj == null) {
112
            	getWizardComponents().getFinishButton().setEnabled(false);
113
            	theConnWithParams = null;
114
                return;
115
            }
116

  
117
            if (!(sel_obj instanceof ConnectionWithParams)) {
118
            	getWizardComponents().getFinishButton().setEnabled(false);
119
            	theConnWithParams = null;
120
                return;
121
            }
122

  
123
            ConnectionWithParams cwp = (ConnectionWithParams) sel_obj; 
124

  
125
            if (cwp.isNull()) {
126
            	getWizardComponents().getFinishButton().setEnabled(false);
127
            	theConnWithParams = null;
128
                return;
129
            }
130

  
131
            if (!cwp.isConnected()) {
132
                if (!tryToConnect(cwp)) {
133
                	getWizardComponents().getFinishButton().setEnabled(false);
134
                	theConnWithParams = null;
135
                	datasourceComboBox.setSelectedIndex(0);
136
                    return;
137
                }
138
            }
139

  
140
            theConnWithParams = cwp;
141
            getWizardComponents().getFinishButton().setEnabled(true);
142
            datasourceComboBox.repaint();
143
		}
144
	}    
145
	
146
    private boolean tryToConnect(ConnectionWithParams _cwp) {
147
        JPasswordDlg dlg = new JPasswordDlg();
148
        dlg.setLocationRelativeTo((Component)PluginServices.getMainFrame());
149
        String strMessage = PluginServices.getText(this, "conectar_jdbc");
150
        String strPassword = PluginServices.getText(this, "password");
151
        dlg.setMessage(strMessage + " [" + _cwp.getDrvName() + ", " +
152
            _cwp.getHost() + ", " + _cwp.getPort() + ", " + _cwp.getDb() +
153
            ", " + _cwp.getUser() + "]. " + strPassword + "?");
154

  
155
        dlg.setVisible(true);
156

  
157
        String clave = dlg.getPassword();
158

  
159
        if (clave == null) {
160
            return false;
161
        }
162

  
163
        try {
164
            _cwp.connect(clave);
165
        }
166
        catch (DBException e) {
167
            showConnectionErrorMessage(e.getMessage());
168

  
169
            return false;
170
        }
171

  
172
        return true;
173
    }	
174
    
175
    private void showConnectionErrorMessage(String _msg) {
176
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
177
        String title = PluginServices.getText(this, "connection_error");
178
        JOptionPane.showMessageDialog(this, title + msg, title,
179
            JOptionPane.ERROR_MESSAGE);
180
    }
181

  
182
	public void propertyChange(PropertyChangeEvent evt) {
183
		
184
		if (evt.getPropertyName().compareToIgnoreCase(JWizardComponents.CURRENT_PANEL_PROPERTY) == 0) {
185
			
186
			if (evt.getNewValue() == this) {
187
				boolean valid_conn = !(theConnWithParams == null);
188
				getWizardComponents().getFinishButton().setEnabled(valid_conn);
189
			}
190
			
191
		}
192
		
193
	}    
194
	
195
	
196
    private ConnectionWithParams addNewConnection() {
197
        ConnectionWithParams resp = null;
198

  
199
        VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog();
200
        newco.showDialog();
201

  
202
        if (newco.isOkPressed()) {
203
            String _drvname = newco.getConnectionDriverName();
204
            String _host = newco.getConnectionServerUrl();
205
            String _port = newco.getConnectionPort();
206
            String _dbname = newco.getConnectionDBName();
207
            String _user = newco.getConnectionUser();
208
            String _pw = newco.getConnectionPassword();
209
            String _conn_usr_name = newco.getConnectionName();
210

  
211
            boolean hasToBeCon = newco.hasToBeConnected();
212

  
213
            try {
214
                resp = SingleVectorialDBConnectionManager.instance()
215
                                                  .getConnection(_drvname,
216
                        _user, _pw, _conn_usr_name, _host, _port, _dbname,
217
                        hasToBeCon);
218
            }
219
            catch (DBException e) {
220
                showConnectionErrorMessage(e.getMessage());
221

  
222
                return null;
223
            }
224
            SingleVectorialDBConnectionExtension.saveAllToPersistence();
225
            return resp;
226
        }
227
        else {
228
            return null;
229
        }
230
    }	
231
    
232
    /**
233
     * This method initializes jdbcButton
234
     *
235
     * @return javax.swing.JButton
236
     */
237
    private JButton getJdbcButton() {
238
        if (dbButton == null) {
239
            dbButton = new JButton();
240
            dbButton.addActionListener(this);
241
            dbButton.setToolTipText(PluginServices.getText(this,
242
                    "add_connection"));
243
            dbButton.setBounds(new java.awt.Rectangle(320, 32, 26, 21));
244

  
245
            String _file = createResourceUrl("images/jdbc.png").getFile();
246
            dbButton.setIcon(new ImageIcon(_file));
247
        }
248

  
249
        return dbButton;
250
    }
251
    
252
    private java.net.URL createResourceUrl(String path) {
253
        return getClass().getClassLoader().getResource(path);
254
    }
255

  
256
	public void actionPerformed(ActionEvent e) {
257
		
258
		Object src = e.getSource();
259
		
260
        if (src == dbButton) {
261
            ConnectionWithParams sel = addNewConnection();
262

  
263
            if (sel != null) {
264
                loadVectorialDBDatasourcesCombo();
265
                getDatasourceComboBox().setSelectedItem(sel);
266
            }
267
        }
268
		
269
	}    
270

  
271
}
0 272

  
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/gui/jdbcwizard/RepeatedFieldDefinitionPanel.java
1
package es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Component;
5
import java.sql.Types;
6
import java.util.ArrayList;
7

  
8
import javax.swing.DefaultCellEditor;
9
import javax.swing.JButton;
10
import javax.swing.JComboBox;
11
import javax.swing.JLabel;
12
import javax.swing.JOptionPane;
13
import javax.swing.JPanel;
14
import javax.swing.JScrollPane;
15
import javax.swing.JTable;
16
import javax.swing.ListSelectionModel;
17
import javax.swing.event.ListSelectionEvent;
18
import javax.swing.event.ListSelectionListener;
19
import javax.swing.table.DefaultTableModel;
20
import javax.swing.table.TableColumn;
21

  
22
import jwizardcomponent.JWizardComponents;
23
import jwizardcomponent.JWizardPanel;
24

  
25
import com.iver.andami.PluginServices;
26
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
27
import com.iver.cit.gvsig.fmap.edition.IWriter;
28

  
29
/**
30
 * @author fjp
31
 *
32
 * Panel para que el usuario seleccione el driver que va a utilizar para
33
 * crear un tema desde cero
34
 *
35
 */
36
public class RepeatedFieldDefinitionPanel extends JWizardPanel {
37

  
38

  
39
	private JLabel jLabel = null;
40
	private JScrollPane jScrollPane = null;
41
	private JTable jTable = null;
42
	private JPanel jPanelEast = null;
43
	private JButton jButtonAddField = null;
44
	private JButton jButtonDeleteField = null;
45
	private int MAX_FIELD_LENGTH = 254;
46

  
47
	private IWriter writer = null;
48

  
49

  
50
	public RepeatedFieldDefinitionPanel(JWizardComponents wizardComponents) {
51
		super(wizardComponents, null);
52
		initialize();
53
		// TODO Auto-generated constructor stub
54
	}
55

  
56

  
57
	/* (non-Javadoc)
58
	 * @see jwizardcomponent.JWizardPanel#next()
59
	 */
60
	public void next() {
61
		DefaultTableModel tm=(DefaultTableModel) jTable.getModel();
62
		boolean valid=true;
63
		for (int i = 0;i<tm.getRowCount();i++) {
64
				String s=(String)tm.getValueAt(i,0);
65
				valid=validate(s);
66
				String size=(String) tm.getValueAt(i,2);
67
				valid=valid && validateInteger(size);
68
				if (!valid){
69
					return;
70
				}
71
				String type = (String) tm.getValueAt(i,1);
72
				int length = Integer.parseInt((String) tm.getValueAt(i,2));
73
				if (type.equals("String") && length > MAX_FIELD_LENGTH) {
74
					JOptionPane.showMessageDialog(this, PluginServices.getText(this, "max_length_is") + ": " + MAX_FIELD_LENGTH+
75
							"\n"+PluginServices.getText(this, "length_of_field")+ " '"+ s + "' " + PluginServices.getText(this, "will_be_truncated"));
76
					tm.setValueAt(String.valueOf(MAX_FIELD_LENGTH),i,2);
77
				}
78

  
79
		}
80

  
81
		// ensure no field name is used more than once
82
		ArrayList fieldNames = new ArrayList();
83
		for (int i = 0; i < jTable.getRowCount(); i++) {
84
			if (fieldNames.contains(tm.getValueAt(i,0))) {
85
				valid = false;
86
				JOptionPane.showMessageDialog(this, PluginServices.getText(this, "two_or_more_fields_with_the_same_name"));
87
				break;
88
			}
89
			fieldNames.add(tm.getValueAt(i, 0));
90
		}
91

  
92
		if (valid)
93
			super.next();
94

  
95
	}
96

  
97
	public void setWriter(IWriter writer) {
98
		this.writer = writer;
99
	}
100

  
101
	public IWriter getWriter() {
102
		return this.writer;
103
	}
104

  
105
	private boolean validateInteger(String size) {
106
		boolean valid=true;
107
		try{
108
		Integer.parseInt(size);
109
		}catch (NumberFormatException e) {
110
			valid=false;
111
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
112
					PluginServices.getText(this,"no_puede_continuar")+"\n"+
113
					PluginServices.getText(this,"size")+" : "+size+"\n"+
114
					PluginServices.getText(this,"incorrect_value"));
115
		}
116
		return valid;
117
	}
118

  
119

  
120
	private boolean validate(String s) {
121
		boolean valid=true;
122
		if (s.equals("")) {
123
			valid=false;
124
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
125
					PluginServices.getText(this,"no_puede_continuar")+"\n"+
126
					PluginServices.getText(this,"the_field_name_is_required"));
127
		}
128
		if (s.indexOf(" ")!=-1) {
129
			valid=false;
130
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
131
					PluginServices.getText(this,"no_puede_continuar")+"\n"+
132
					PluginServices.getText(this,"field")+" : "+s+"\n"+
133
					PluginServices.getText(this,"contiene_espacios_en_blanco"));
134
		}
135
		if (this.writer != null && this.writer.getCapability("FieldNameMaxLength") != null) {
136
			String value = writer.getCapability("FieldNameMaxLength");
137
			int intValue;
138
			try {
139
				intValue = Integer.parseInt(value);
140
			} catch (NumberFormatException e) {
141
				intValue = 0;
142
			}
143
			if (intValue > 0 && s.length() > intValue) {
144
				valid=false;
145
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
146
						PluginServices.getText(this,"no_puede_continuar")+"\n"+
147
						PluginServices.getText(this,"field")+" : "+s+"\n"+
148
						PluginServices.getText(this,"too_long_name")+"\n"+
149
						PluginServices.getText(this,"maximun_name_size")+" : "+intValue+"\n"
150
						);
151
			}
152
		}
153
		return valid;
154
	}
155

  
156

  
157
	/**
158
	 * This method initializes this
159
	 *
160
	 */
161
	private void initialize() {
162
        jLabel = new JLabel();
163
        jLabel.setText(PluginServices.getText(this,"define_fields"));
164
        this.setLayout(new BorderLayout(5,5));
165
        this.setSize(new java.awt.Dimension(499,232));
166
        this.add(jLabel, java.awt.BorderLayout.NORTH);
167
        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
168
        this.add(getJPanelEast(), java.awt.BorderLayout.EAST);
169
	}
170

  
171

  
172
	/**
173
	 * This method initializes jScrollPane
174
	 *
175
	 * @return javax.swing.JScrollPane
176
	 */
177
	private JScrollPane getJScrollPane() {
178
		if (jScrollPane == null) {
179
			jScrollPane = new JScrollPane();
180
			jScrollPane.setViewportView(getJTable());
181
		}
182
		return jScrollPane;
183
	}
184

  
185

  
186
	/**
187
	 * This method initializes jTable
188
	 *
189
	 * @return javax.swing.JTable
190
	 */
191
	private JTable getJTable() {
192
		if (jTable == null) {
193
			jTable = new JTable();
194

  
195
			DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
196
			tm.addColumn(PluginServices.getText(this,"field"));
197

  
198

  
199
			// TableColumn fieldTypeColumn = new TableColumn(1);
200
			// fieldTypeColumn.setHeaderValue("Type");
201
			// jTable.addColumn(fieldTypeColumn);
202
			tm.addColumn(PluginServices.getText(this,"type"));
203
			// MIRAR EL C?DIGO DEL BOT?N DE A?ADIR CAMPO PARA VER EL CellEditor con comboBox
204

  
205

  
206

  
207
			/* TableColumn fieldLengthColumn = new TableColumn(2);
208
			fieldLengthColumn.setHeaderValue("Length");
209
			// fieldLengthColumn.setCellRenderer(new DefaultTableCellRenderer());
210
			jTable.addColumn(fieldLengthColumn); */
211
			tm.addColumn(PluginServices.getText(this,"length"));
212

  
213
//			Ask to be notified of selection changes.
214
			ListSelectionModel rowSM = jTable.getSelectionModel();
215
			rowSM.addListSelectionListener(new ListSelectionListener() {
216
			    public void valueChanged(ListSelectionEvent e) {
217
			        //Ignore extra messages.
218
			        if (e.getValueIsAdjusting()) return;
219

  
220
			        ListSelectionModel lsm =
221
			            (ListSelectionModel)e.getSource();
222
			        if (lsm.isSelectionEmpty()) {
223
			            //no rows are selected
224
			        	jButtonDeleteField.setEnabled(false);
225
			        } else {
226
			            // int selectedRow = lsm.getMinSelectionIndex();
227
			            //selectedRow is selected
228
			        	jButtonDeleteField.setEnabled(true);
229
			        }
230
			    }
231
			});
232
			jTable.getColumn(PluginServices.getText(this,"field")).setWidth(180);
233

  
234

  
235
		}
236
		return jTable;
237
	}
238

  
239

  
240
	/**
241
	 * This method initializes jPanelWest
242
	 *
243
	 * @return javax.swing.JPanel
244
	 */
245
	private JPanel getJPanelEast() {
246
		if (jPanelEast == null) {
247
			jPanelEast = new JPanel();
248
			jPanelEast.setLayout(null);
249
			jPanelEast.setPreferredSize(new java.awt.Dimension(170,100));
250
			jPanelEast.add(getJButtonAddField(), null);
251
			jPanelEast.add(getJButtonDeleteField(), null);
252
		}
253
		return jPanelEast;
254
	}
255

  
256

  
257
	/**
258
	 * This method initializes jButtonAddField
259
	 *
260
	 * @return javax.swing.JButton
261
	 */
262
	private JButton getJButtonAddField() {
263
		if (jButtonAddField == null) {
264
			jButtonAddField = new JButton();
265
			jButtonAddField.setText(PluginServices.getText(this,"add_field"));
266
			jButtonAddField.setLocation(new java.awt.Point(7,5));
267
			jButtonAddField.setSize(new java.awt.Dimension(145,23));
268
			jButtonAddField.setPreferredSize(new java.awt.Dimension(100,26));
269
			jButtonAddField.addActionListener(new java.awt.event.ActionListener() {
270
				public void actionPerformed(java.awt.event.ActionEvent e) {
271
					DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
272

  
273
					// Figure out a suitable field name
274
					ArrayList fieldNames = new ArrayList();
275
					for (int i = 0; i < jTable.getRowCount(); i++) {
276
						fieldNames.add(tm.getValueAt(i, 0));
277
					}
278
					String[] currentFieldNames = (String[]) fieldNames.toArray(new String[0]);
279
					String newField = PluginServices.getText(this, "field").replaceAll(" +", "_");
280
					int index=0;
281
					for (int i = 0; i < currentFieldNames.length; i++) {
282
						if (currentFieldNames[i].startsWith(newField)) {
283
							try {
284
								index = Integer.parseInt(currentFieldNames[i].replaceAll(newField,""));
285
							} catch (Exception ex) { /* we don't care */}
286
						}
287
					}
288
					String newFieldName = newField+(++index);
289

  
290

  
291
					// Add a new row
292
					Object[] newRow = new Object[tm.getColumnCount()];
293
					newRow[0] = newFieldName;
294
					newRow[1] = "String";
295
					newRow[2] = "20";
296
					tm.addRow(newRow);
297

  
298
					// Esto lo a?ado aqu? porque si no tiene registros, no hace caso. (Por eso no
299
					// lo pongo en getJTable()
300
					TableColumn typeColumn = jTable.getColumnModel().getColumn(1);
301
					JComboBox comboBox = new JComboBox();
302
					comboBox.addItem("Boolean");
303
					comboBox.addItem("Date");
304
					comboBox.addItem("Integer");
305
					comboBox.addItem("Double");
306
					comboBox.addItem("String");
307
					typeColumn.setCellEditor(new DefaultCellEditor(comboBox));
308

  
309
					TableColumn widthColumn = jTable.getColumnModel().getColumn(2);
310

  
311
					// tm.setValueAt("NewField", tm.getRowCount()-1, 0);
312
				}
313
			});
314

  
315
		}
316
		return jButtonAddField;
317
	}
318

  
319

  
320
	/**
321
	 * This method initializes jButton
322
	 *
323
	 * @return javax.swing.JButton
324
	 */
325
	private JButton getJButtonDeleteField() {
326
		if (jButtonDeleteField == null) {
327
			jButtonDeleteField = new JButton();
328
			jButtonDeleteField.setText(PluginServices.getText(this,"delete_field"));
329
			jButtonDeleteField.setLocation(new java.awt.Point(7,33));
330
			jButtonDeleteField.setSize(new java.awt.Dimension(145,23));
331
			jButtonDeleteField.setEnabled(false);
332
			jButtonDeleteField.addActionListener(new java.awt.event.ActionListener() {
333
				public void actionPerformed(java.awt.event.ActionEvent e) {
334
					int[] selecteds = jTable.getSelectedRows();
335
					DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
336

  
337
					for (int i=selecteds.length-1; i >=0; i--)
338
						tm.removeRow(selecteds[i]);
339
				}
340
			});
341
		}
342
		return jButtonDeleteField;
343
	}
344

  
345

  
346
	/**
347
	 * Convierte lo que hay en la tabla en una definici?n de campos
348
	 * adecuada para crear un LayerDefinition
349
	 * @return
350
	 */
351
	public FieldDescription[] getFieldsDescription() {
352
		DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
353
		FieldDescription[] fieldsDesc = new FieldDescription[tm.getRowCount()];
354

  
355
		for (int i=0; i < tm.getRowCount(); i++)
356
		{
357
			fieldsDesc[i] = new FieldDescription();
358
			fieldsDesc[i].setFieldName((String) tm.getValueAt(i,0));
359
			String strType = (String) tm.getValueAt(i,1);
360
			if (strType.equals("String"))
361
				fieldsDesc[i].setFieldType(Types.VARCHAR);
362
			if (strType.equals("Double"))
363
				fieldsDesc[i].setFieldType(Types.DOUBLE);
364
			if (strType.equals("Integer"))
365
				fieldsDesc[i].setFieldType(Types.INTEGER);
366
			if (strType.equals("Boolean"))
367
				fieldsDesc[i].setFieldType(Types.BOOLEAN);
368
			if (strType.equals("Date"))
369
				fieldsDesc[i].setFieldType(Types.DATE);
370
			int fieldLength = Integer.parseInt((String) tm.getValueAt(i,2));
371
			fieldsDesc[i].setFieldLength(fieldLength);
372

  
373
			// TODO: HACERLO BIEN
374
			if (strType.equals("Double"))
375
				fieldsDesc[i].setFieldDecimalCount(5);
376

  
377
		}
378

  
379
		return fieldsDesc;
380
	}
381

  
382

  
383

  
384
}  //  @jve:decl-index=0:visual-constraint="10,10"
0 385

  
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/gui/jdbcwizard/OracleConnectionChooserPanel.java
42 42
 */
43 43
package es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard;
44 44

  
45
import com.iver.andami.PluginServices;
46
import com.iver.andami.ui.mdiManager.IWindow;
47
import com.iver.andami.ui.mdiManager.WindowInfo;
48

  
49
import com.iver.cit.gvsig.fmap.drivers.DBException;
50
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
51
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager;
52

  
53
import com.iver.utiles.swing.JPasswordDlg;
54
import com.prodevelop.cit.gvsig.vectorialdb.wizard.VectorialDBConnectionParamsDialog;
55

  
56
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
57

  
58 45
import java.awt.Component;
59 46
import java.awt.event.ActionEvent;
60 47
import java.awt.event.ActionListener;
61
import java.awt.event.ItemEvent;
62
import java.awt.event.ItemListener;
63 48
import java.awt.event.KeyEvent;
64 49
import java.awt.event.KeyListener;
65 50

  
66
import java.sql.SQLException;
67

  
68 51
import javax.swing.ImageIcon;
69 52
import javax.swing.JButton;
70 53
import javax.swing.JComboBox;
71
import javax.swing.JLabel;
72 54
import javax.swing.JOptionPane;
73 55
import javax.swing.JPanel;
74 56

  
75 57
import org.apache.log4j.Logger;
76 58

  
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.ui.mdiManager.IWindow;
61
import com.iver.andami.ui.mdiManager.WindowInfo;
62
import com.iver.cit.gvsig.fmap.drivers.DBException;
63
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams;
64
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager;
65
import com.iver.utiles.swing.JPasswordDlg;
66
import com.prodevelop.cit.gvsig.vectorialdb.wizard.VectorialDBConnectionParamsDialog;
77 67

  
68
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver;
69

  
70

  
78 71
/**
79 72
 * This dialog lets the user choose an available connection.
80 73
 *
......
360 353
            jdbcButton.setToolTipText(PluginServices.getText(this,
361 354
                    "add_connection"));
362 355
            jdbcButton.setBounds(new java.awt.Rectangle(381 - 26, 15, 26, 21));
363
            String _file = createResourceUrl("images/jdbc.ico").getFile();
356
            String _file = createResourceUrl("images/jdbc.png").getFile();
364 357
            jdbcButton.setIcon(new ImageIcon(_file));
365 358
        }
366 359

  
trunk/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/gui/jdbcwizard/RepeatedChooseGeometryTypePanel.java
1
package es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard;
2

  
3
import javax.swing.ButtonGroup;
4
import javax.swing.ImageIcon;
5
import javax.swing.JLabel;
6
import javax.swing.JPanel;
7
import javax.swing.JRadioButton;
8
import javax.swing.JTextField;
9
import javax.swing.event.CaretEvent;
10
import javax.swing.event.CaretListener;
11

  
12
import jwizardcomponent.JWizardComponents;
13
import jwizardcomponent.JWizardPanel;
14

  
15
import com.hardcode.driverManager.Driver;
16
import com.iver.andami.PluginServices;
17
import com.iver.cit.gvsig.fmap.core.FShape;
18
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
19
import com.iver.cit.gvsig.fmap.edition.IWriteable;
20

  
21
/**
22
 * @author fjp
23
 *
24
 * Panel para que el usuario seleccione el driver que va a utilizar para
25
 * crear un tema desde cero.
26
 *
27
 */
28
public class RepeatedChooseGeometryTypePanel extends JWizardPanel {
29

  
30
	private JLabel lblSelecGeometryType = null;
31
	private JPanel jPanelGeometryTypeOptions = null;
32
	private JRadioButton jRadioButtonPoint = null;
33
	private JRadioButton jRadioButtonLine = null;
34
	private JRadioButton jRadioButtonPolygon = null;
35
	private JRadioButton jRadioButtonMulti = null;
36
	private JRadioButton jRadioButtonMultiPoint = null;
37
	private JTextField jTextFieldLayerName = null;
38
	private JLabel jLabelLayerName = null;
39
	private String driverName;
40

  
41
	private class MyInputEventListener implements CaretListener
42
	{
43
		public void caretUpdate(CaretEvent arg0) {
44
			if (jTextFieldLayerName.getText().length() > 0)
45
				setNextButtonEnabled(true);
46
			else
47
				setNextButtonEnabled(false);
48

  
49
		}
50

  
51
	}
52

  
53
	public RepeatedChooseGeometryTypePanel(JWizardComponents wizardComponents) {
54
		super(wizardComponents);
55
		initialize();
56
		// TODO Auto-generated constructor stub
57
	}
58

  
59
	/**
60
	 * This method initializes this
61
	 *
62
	 */
63
	private void initialize() {
64
        jLabelLayerName = new JLabel();
65
        jLabelLayerName.setBounds(new java.awt.Rectangle(14,9,321,22));
66
        jLabelLayerName.setText(PluginServices.getText(this,"enter_layer_name"));
67
        lblSelecGeometryType = new JLabel();
68
        lblSelecGeometryType.setText(PluginServices.getText(this,"select_geometry_type"));
69
        lblSelecGeometryType.setBounds(new java.awt.Rectangle(13,63,329,15));
70
        this.setLayout(null);
71
        this.setSize(new java.awt.Dimension(358,263));
72
        this.add(lblSelecGeometryType, null);
73
        this.add(getJPanelGeometryTypeOptions(), null);
74
        this.add(getJTextFieldLayerName(), null);
75
        this.add(jLabelLayerName, null);
76

  
77
	}
78

  
79
	/**
80
	 * This method initializes jPanelGeometryTypeOptions
81
	 *
82
	 * @return javax.swing.JPanel
83
	 */
84
	private JPanel getJPanelGeometryTypeOptions() {
85
		if (jPanelGeometryTypeOptions == null) {
86
			jPanelGeometryTypeOptions = new JPanel();
87
			jPanelGeometryTypeOptions.setLayout(null);
88
			jPanelGeometryTypeOptions.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"Geometry_types"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
89
			jPanelGeometryTypeOptions.setPreferredSize(new java.awt.Dimension(300,400));
90
			jPanelGeometryTypeOptions.setBounds(new java.awt.Rectangle(14,82,326,172));
91
			jPanelGeometryTypeOptions.add(getJRadioButtonPoint(), null);
92
			jPanelGeometryTypeOptions.add(getJRadioButtonLine(), null);
93
			jPanelGeometryTypeOptions.add(getJRadioButtonPolygon(), null);
94
			jPanelGeometryTypeOptions.add(getJRadioButtonMulti(), null);
95
			jPanelGeometryTypeOptions.add(getJRadioButtonMultiPoint(), null);
96

  
97
		    //Group the radio buttons.
98
		    ButtonGroup group = new ButtonGroup();
99
		    group.add(getJRadioButtonPoint());
100
		    group.add(getJRadioButtonLine());
101
		    group.add(getJRadioButtonPolygon());
102
		    group.add(getJRadioButtonMulti());
103
		    group.add(getJRadioButtonMultiPoint());
104

  
105
		}
106
		return jPanelGeometryTypeOptions;
107
	}
108

  
109
	/**
110
	 * This method initializes jRadioButtonPoint
111
	 *
112
	 * @return javax.swing.JRadioButton
113
	 */
114
	private JRadioButton getJRadioButtonPoint() {
115
		if (jRadioButtonPoint == null) {
116
			jRadioButtonPoint = new JRadioButton();
117
			jRadioButtonPoint.setText(PluginServices.getText(this,"point_type"));
118
			jRadioButtonPoint.setBounds(new java.awt.Rectangle(19,31,297,23));
119
		}
120
		return jRadioButtonPoint;
121
	}
122

  
123
	/**
124
	 * This method initializes jRadioButtonLine
125
	 *
126
	 * @return javax.swing.JRadioButton
127
	 */
128
	private JRadioButton getJRadioButtonLine() {
129
		if (jRadioButtonLine == null) {
130
			jRadioButtonLine = new JRadioButton();
131
			jRadioButtonLine.setText(PluginServices.getText(this,"line_type"));
132
			jRadioButtonLine.setSelected(true);
133
			jRadioButtonLine.setBounds(new java.awt.Rectangle(19,81,297,23));
134
		}
135
		return jRadioButtonLine;
136
	}
137

  
138
	/**
139
	 * This method initializes jRadioButtonPolygon
140
	 *
141
	 * @return javax.swing.JRadioButton
142
	 */
143
	private JRadioButton getJRadioButtonPolygon() {
144
		if (jRadioButtonPolygon == null) {
145
			jRadioButtonPolygon = new JRadioButton();
146
			jRadioButtonPolygon.setText(PluginServices.getText(this,"polygon_type"));
147
			jRadioButtonPolygon.setBounds(new java.awt.Rectangle(19,106,297,23));
148
		}
149
		return jRadioButtonPolygon;
150
	}
151

  
152
	/**
153
	 * This method initializes jRadioButtonMulti
154
	 *
155
	 * @return javax.swing.JRadioButton
156
	 */
157
	private JRadioButton getJRadioButtonMulti() {
158
		if (jRadioButtonMulti == null) {
159
			jRadioButtonMulti = new JRadioButton();
160
			jRadioButtonMulti.setText(PluginServices.getText(this,"multi_type"));
161
			jRadioButtonMulti.setBounds(new java.awt.Rectangle(19,131,297,23));
162
		}
163
		return jRadioButtonMulti;
164
	}
165

  
166
	/**
167
	 * This method initializes jRadioButton
168
	 *
169
	 * @return javax.swing.JRadioButton
170
	 */
171
	private JRadioButton getJRadioButtonMultiPoint() {
172
		if (jRadioButtonMultiPoint == null) {
173
			jRadioButtonMultiPoint = new JRadioButton();
174
			jRadioButtonMultiPoint.setText(PluginServices.getText(this,"multipoint_type"));
175
			jRadioButtonMultiPoint.setBounds(new java.awt.Rectangle(19,56,297,23));
176
		}
177
		return jRadioButtonMultiPoint;
178
	}
179

  
180
	/**
181
	 * En funci?n de qu? tipo de driver sea, habilitamos o deshabilitamos
182
	 * las opciones. Por ejemplo, si es de tipo shp, deshabilitamos
183
	 * multi_type
184
	 * @param writer
185
	 */
186
	public void setDriver(Driver driver) {
187
		// En funci?n de qu? tipo de driver sea, habilitamos o deshabilitamos
188
		// las opciones. Por ejemplo, si es de tipo shp, deshabilitamos
189
		// multi_type
190
		IWriteable aux = (IWriteable) driver;
191
		ISpatialWriter writer = (ISpatialWriter) aux.getWriter(); 
192
		
193
		driverName = driver.getName();
194
		getJRadioButtonPoint().setEnabled(writer.canWriteGeometry(FShape.POINT));
195
		getJRadioButtonMultiPoint().setEnabled(writer.canWriteGeometry(FShape.MULTIPOINT));
196
		getJRadioButtonLine().setEnabled(writer.canWriteGeometry(FShape.LINE));
197
		getJRadioButtonPolygon().setEnabled(writer.canWriteGeometry(FShape.POLYGON));
198
		getJRadioButtonMulti().setEnabled(writer.canWriteGeometry(FShape.MULTI));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff