Revision 11193 trunk/extensions/extSDE/src/com/iver/cit/gvsig/sde/gui/sdewizard/WizardSDE.java
WizardSDE.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 23-abr-2004 |
|
3 |
* |
|
4 |
* To change the template for this generated file go to |
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
6 |
*/ |
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 | 1 |
package com.iver.cit.gvsig.sde.gui.sdewizard; |
48 | 2 |
|
49 | 3 |
import java.awt.BorderLayout; |
4 |
import java.awt.CardLayout; |
|
5 |
import java.awt.FlowLayout; |
|
6 |
import java.sql.SQLException; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.TreeMap; |
|
10 |
import java.util.Vector; |
|
50 | 11 |
|
51 |
import javax.swing.JLabel;
|
|
12 |
import javax.swing.JOptionPane;
|
|
52 | 13 |
import javax.swing.JPanel; |
53 |
import javax.swing.JPasswordField; |
|
54 |
import javax.swing.JTextField; |
|
55 | 14 |
|
56 |
import org.apache.log4j.Logger; |
|
15 |
import org.cresques.cts.IProjection; |
|
16 |
import org.gvsig.gui.beans.swing.JButton; |
|
57 | 17 |
|
18 |
import com.esri.sde.sdk.client.SeConnection; |
|
19 |
import com.esri.sde.sdk.client.SeException; |
|
20 |
import com.esri.sde.sdk.client.SeLayer; |
|
21 |
import com.esri.sde.sdk.client.SeRegisteredColumn; |
|
22 |
import com.esri.sde.sdk.client.SeTable; |
|
58 | 23 |
import com.hardcode.driverManager.DriverLoadException; |
59 | 24 |
import com.iver.andami.PluginServices; |
25 |
import com.iver.andami.messages.NotificationManager; |
|
26 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
|
27 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
|
60 | 28 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
61 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver;
|
|
29 |
import com.iver.cit.gvsig.fmap.drivers.sde.ArcSDELayerDefinition;
|
|
62 | 30 |
import com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeDriver; |
63 | 31 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
64 | 32 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
65 | 33 |
import com.iver.cit.gvsig.gui.WizardPanel; |
66 |
import com.iver.cit.gvsig.gui.wizards.LayerListModel; |
|
67 |
import com.iver.cit.gvsig.gui.wizards.WizardDataSource; |
|
68 |
import com.iver.cit.gvsig.gui.wizards.WizardListener; |
|
69 |
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
|
70 |
|
|
34 |
import com.iver.utiles.NotExistInXMLEntity; |
|
35 |
import com.iver.utiles.XMLEntity; |
|
71 | 36 |
/** |
72 |
* DOCUMENT ME! |
|
73 |
* |
|
74 |
* @author Fernando Gonz?lez Cort?s |
|
37 |
* @author Vicente Caballero Navarro |
|
38 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.DBLayerDefinitionPanel" |
|
39 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.ConnectionPanel" |
|
40 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.FieldSelection" |
|
41 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.ConnectionSettings" |
|
42 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.UniqueFieldSelection" |
|
43 |
* @uml.dependency supplier="com.iver.cit.gvsig.sde.gui.sdewizard.GeomFieldSelection" |
|
75 | 44 |
*/ |
76 |
public class WizardSDE extends WizardPanel { |
|
77 |
private static Logger logger = Logger.getLogger(WizardSDE.class.getName()); |
|
78 |
private int page = 0; |
|
79 |
private boolean conectado = false; |
|
80 |
private javax.swing.JPanel jContentPane = null; |
|
81 |
private javax.swing.JPanel panelPage1 = null; |
|
82 |
private LayerListModel selectedLayersModel = new LayerListModel(); |
|
83 |
private javax.swing.JPanel jPanel1 = null; |
|
84 |
private WizardListenerSupport listenerSupport = new WizardListenerSupport(); |
|
85 |
private WizardDataSource dataSource; |
|
86 |
private JPanel jPanel = null; |
|
87 |
private JLabel jLabel = null; |
|
88 |
private JTextField jTxtUser = null; |
|
89 |
private JLabel jLabel1 = null; |
|
90 |
private JPasswordField jTxtPassword = null; |
|
91 |
private JLabel jLabel2 = null; |
|
92 |
private JTextField jTxtNomTabla = null; |
|
93 |
private JLabel jLabel4 = null; |
|
94 |
private JTextField jTxtSqlWhere = null; |
|
95 |
private JTextField jTxtHost = null; |
|
96 |
private JLabel jLabel5 = null; |
|
97 |
private JLabel jLabel6 = null; |
|
98 |
private JTextField jTxtPort = null; |
|
99 |
private JTextField jTxtSchema = null; |
|
100 |
private JLabel jLabel3 = null; |
|
101 |
private JTextField jTxtEsquema = null; |
|
45 |
public class WizardSDE extends WizardPanel{ |
|
46 |
|
|
102 | 47 |
/** |
48 |
* @uml.property name="pnlWizard" |
|
49 |
*/ |
|
50 |
private JPanel pnlWizard = null; |
|
51 |
/** |
|
52 |
* @uml.property name="jPanel1" |
|
53 |
*/ |
|
54 |
private JPanel jPanel1 = null; |
|
55 |
/** |
|
56 |
* @uml.property name="btnBack" |
|
57 |
*/ |
|
58 |
private JButton btnBack = null; |
|
59 |
/** |
|
60 |
* @uml.property name="btnNext" |
|
61 |
*/ |
|
62 |
private JButton btnNext = null; |
|
63 |
/** |
|
64 |
* @uml.property name="connectionPanel" |
|
65 |
*/ |
|
66 |
private ConnectionPanel connectionPanel = null; |
|
67 |
/** |
|
68 |
* @uml.property name="dbLayerDefinition" |
|
69 |
*/ |
|
70 |
private DBLayerDefinitionPanel dbLayerDefinition = null; |
|
71 |
/** |
|
72 |
* @uml.property name="fieldSelection" |
|
73 |
*/ |
|
74 |
private FieldSelection fieldSelection = null; |
|
75 |
|
|
76 |
private int step = 0; |
|
77 |
private final int nsteps = 5; |
|
78 |
private static final String CONNECTION = "conn"; |
|
79 |
private static final String LAYER_DEFINITION = "layerdef"; |
|
80 |
private static final String FIELD_SELECTION= "fieldsel"; |
|
81 |
/** |
|
82 |
* @uml.property name="driver" |
|
83 |
*/ |
|
84 |
private ArcSdeDriver driver; |
|
85 |
|
|
86 |
/** |
|
87 |
* @uml.property name="geomFieldSelection" |
|
88 |
*/ |
|
89 |
private GeomFieldSelection geomFieldSelection = null; |
|
90 |
/** |
|
91 |
* @uml.property name="uniqueFieldSelection" |
|
92 |
*/ |
|
93 |
private UniqueFieldSelection uniqueFieldSelection = null; |
|
94 |
|
|
95 |
private String[] theTables = null; |
|
96 |
private SeConnection conex = null; |
|
97 |
|
|
98 |
private HashMap settings = new HashMap(); |
|
99 |
/** |
|
103 | 100 |
* This is the default constructor |
104 | 101 |
*/ |
105 | 102 |
public WizardSDE() { |
106 | 103 |
super(); |
107 | 104 |
initialize(); |
108 | 105 |
} |
109 |
|
|
110 | 106 |
/** |
111 | 107 |
* This method initializes this |
108 |
* |
|
109 |
* @return void |
|
112 | 110 |
*/ |
113 |
private void initialize() { |
|
114 |
setTabName("ArcSDE"); |
|
115 |
this.setSize(510, 311); |
|
116 |
this.setLayout(null); |
|
117 |
this.setPreferredSize(new java.awt.Dimension(750, 320)); |
|
118 |
this.setVisible(true); |
|
119 |
this.add(getPanelPage1(), null); |
|
120 |
|
|
121 |
listenerSupport.callStateChanged(true); |
|
122 |
// activarVisualizarBotones(); |
|
111 |
private void initialize() { |
|
112 |
setTabName("SDE"); |
|
113 |
this.setLayout(new BorderLayout()); |
|
114 |
this.setSize(300, 270); |
|
115 |
this.add(getPnlWizard(), java.awt.BorderLayout.CENTER); |
|
116 |
this.add(getJPanel1(), java.awt.BorderLayout.SOUTH); |
|
117 |
connectionPanel.setDrivers(getDriverNames()); |
|
118 |
enableButtons(); |
|
119 |
|
|
120 |
|
|
121 |
XMLEntity xml = PluginServices.getPluginServices(this) |
|
122 |
.getPersistentXML(); |
|
123 |
|
|
124 |
if (xml == null) { |
|
125 |
xml = new XMLEntity(); |
|
126 |
} |
|
127 |
|
|
128 |
if (!xml.contains("esri-sde")) { |
|
129 |
String[] servers = new String[0]; |
|
130 |
xml.putProperty("esri-sde", servers); |
|
131 |
} |
|
132 |
|
|
133 |
try { |
|
134 |
String[] servers = xml.getStringArrayProperty("esri-sde"); |
|
135 |
|
|
136 |
for (int i = 0; i < servers.length; i++) { |
|
137 |
ConnectionSettings cs = new ConnectionSettings(); |
|
138 |
cs.setFromString(servers[i]); |
|
139 |
settings.put(cs.getName(), cs); |
|
140 |
} |
|
141 |
getConnectionPanel().setSettings(settings); |
|
142 |
} catch (NotExistInXMLEntity e) { |
|
143 |
} |
|
144 |
|
|
123 | 145 |
} |
124 | 146 |
|
147 |
private String[] getDriverNames(){ |
|
148 |
Class[] classes = new Class[] { ArcSdeDriver.class }; |
|
125 | 149 |
|
150 |
ArrayList ret = new ArrayList(); |
|
151 |
String[] driverNames = LayerFactory.getDM().getDriverNames(); |
|
126 | 152 |
|
153 |
for (int i = 0; i < driverNames.length; i++) { |
|
127 | 154 |
|
155 |
for (int j = 0; j < classes.length; j++) { |
|
156 |
if (LayerFactory.getDM().isA(driverNames[i], classes[j])) { |
|
157 |
ret.add(driverNames[i]); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
128 | 161 |
|
129 |
|
|
162 |
return (String[]) ret.toArray(new String[0]); |
|
163 |
|
|
164 |
} |
|
165 |
|
|
166 |
private void enableButtons(){ |
|
167 |
getBtnBack().setEnabled(step > 0); |
|
168 |
getBtnNext().setEnabled(step < nsteps - 1); |
|
169 |
} |
|
170 |
|
|
130 | 171 |
/** |
131 |
* This method initializes panelPage1
|
|
132 |
* |
|
133 |
* @return javax.swing.JPanel
|
|
172 |
* This method initializes pnlWizard
|
|
173 |
* @return javax.swing.JPanel
|
|
174 |
* @uml.property name="pnlWizard"
|
|
134 | 175 |
*/ |
135 |
private javax.swing.JPanel getPanelPage1() { |
|
136 |
if (panelPage1 == null) { |
|
137 |
panelPage1 = new javax.swing.JPanel(); |
|
138 |
panelPage1.setLayout(new BorderLayout()); |
|
139 |
panelPage1.setPreferredSize(new java.awt.Dimension(480, 220)); |
|
140 |
panelPage1.setVisible(true); |
|
141 |
panelPage1.setBounds(15, 5, 480, 262); |
|
142 |
panelPage1.add(getJPanel1(), java.awt.BorderLayout.NORTH); |
|
143 |
panelPage1.add(getJPanel(), java.awt.BorderLayout.CENTER); |
|
176 |
private JPanel getPnlWizard() { |
|
177 |
if (pnlWizard == null) { |
|
178 |
pnlWizard = new JPanel(); |
|
179 |
pnlWizard.setLayout(new CardLayout()); |
|
180 |
pnlWizard.add(getConnectionPanel(), CONNECTION); |
|
181 |
pnlWizard.add(getDbLayerDefinition(), LAYER_DEFINITION); |
|
182 |
pnlWizard.add(getFieldSelection(), FIELD_SELECTION); |
|
183 |
pnlWizard.add(getGeomFieldSelection(), getGeomFieldSelection() |
|
184 |
.getName()); |
|
185 |
pnlWizard.add(getUniqueFieldSelection(), getUniqueFieldSelection() |
|
186 |
.getName()); |
|
144 | 187 |
} |
145 |
|
|
146 |
return panelPage1; |
|
188 |
return pnlWizard; |
|
147 | 189 |
} |
148 |
|
|
149 | 190 |
/** |
150 | 191 |
* This method initializes jPanel1 |
151 |
* |
|
152 |
* @return javax.swing.JPanel
|
|
192 |
* @return javax.swing.JPanel
|
|
193 |
* @uml.property name="jPanel1"
|
|
153 | 194 |
*/ |
154 |
private javax.swing.JPanel getJPanel1() {
|
|
195 |
private JPanel getJPanel1() { |
|
155 | 196 |
if (jPanel1 == null) { |
156 |
jLabel6 = new JLabel(); |
|
157 |
jLabel6.setText("Puerto:"); |
|
158 |
jLabel6.setPreferredSize(new java.awt.Dimension(94,15)); |
|
159 |
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
160 |
jLabel5 = new JLabel(); |
|
161 |
jLabel5.setText("Host:"); |
|
162 |
jLabel5.setPreferredSize(new java.awt.Dimension(95,15)); |
|
163 |
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
164 |
jPanel1 = new javax.swing.JPanel(); |
|
165 |
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
166 |
null, PluginServices.getText(this, "Servidor ArcSDE"), |
|
167 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
168 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
169 |
|
|
170 |
jPanel1.add(jLabel5, null); |
|
171 |
jPanel1.add(getJTxtHost(), null); |
|
172 |
|
|
173 |
jPanel1.add(jLabel6, null); |
|
174 |
jPanel1.add(getJTxtPort(), null); |
|
197 |
FlowLayout flowLayout1 = new FlowLayout(FlowLayout.RIGHT); |
|
198 |
jPanel1 = new JPanel(); |
|
199 |
jPanel1.setLayout(flowLayout1); |
|
200 |
jPanel1.setPreferredSize(new java.awt.Dimension(10, 30)); |
|
201 |
flowLayout1.setHgap(5); |
|
202 |
flowLayout1.setVgap(4); |
|
203 |
jPanel1.add(getBtnBack(), null); |
|
204 |
jPanel1.add(getBtnNext(), null); |
|
175 | 205 |
} |
176 |
|
|
177 | 206 |
return jPanel1; |
178 | 207 |
} |
179 |
|
|
180 | 208 |
/** |
181 |
* DOCUMENT ME!
|
|
182 |
* |
|
183 |
* @param listener
|
|
209 |
* This method initializes btnBack
|
|
210 |
* @return javax.swing.JButton
|
|
211 |
* @uml.property name="btnBack"
|
|
184 | 212 |
*/ |
185 |
public void addWizardListener(WizardListener listener) { |
|
186 |
listenerSupport.addWizardListener(listener); |
|
213 |
private JButton getBtnBack() { |
|
214 |
if (btnBack == null) { |
|
215 |
btnBack = new JButton(); |
|
216 |
btnBack.setText(PluginServices.getText(this, "back")); |
|
217 |
//btnBack.setPreferredSize(new java.awt.Dimension(93,18)); |
|
218 |
btnBack.addActionListener(new java.awt.event.ActionListener() { |
|
219 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
220 |
step--; |
|
221 |
enableButtons(); |
|
222 |
((CardLayout) pnlWizard.getLayout()).previous(pnlWizard); |
|
223 |
} |
|
224 |
}); |
|
225 |
} |
|
226 |
return btnBack; |
|
187 | 227 |
} |
188 |
|
|
189 | 228 |
/** |
190 |
* DOCUMENT ME!
|
|
191 |
* |
|
192 |
* @param listener
|
|
229 |
* This method initializes btnNext
|
|
230 |
* @return javax.swing.JButton
|
|
231 |
* @uml.property name="btnNext"
|
|
193 | 232 |
*/ |
194 |
public void removeWizardListener(WizardListener listener) { |
|
195 |
listenerSupport.removeWizardListener(listener); |
|
233 |
private JButton getBtnNext() { |
|
234 |
if (btnNext == null) { |
|
235 |
btnNext = new JButton(); |
|
236 |
btnNext.setText(PluginServices.getText(this, "next")); |
|
237 |
//btnNext.setPreferredSize(new java.awt.Dimension(93,18)); |
|
238 |
btnNext.addActionListener(new java.awt.event.ActionListener() { |
|
239 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
240 |
boolean done = false; |
|
241 |
if (step == 0) |
|
242 |
done = connectionPanel.done(); |
|
243 |
else if (step == 1) |
|
244 |
done = dbLayerDefinition.done(); |
|
245 |
else if (step == 2) |
|
246 |
done = fieldSelection.done(); |
|
247 |
else if (step == 3) |
|
248 |
done = geomFieldSelection.done(); |
|
249 |
if (done) { |
|
250 |
try { |
|
251 |
if (step == 0) { |
|
252 |
//catalog = connectionPanel.getDBName(); |
|
253 |
theTables = getTableNames(); |
|
254 |
dbLayerDefinition.setTables(theTables); |
|
255 |
saveConnection(); |
|
256 |
} else if (step == 1) { |
|
257 |
fieldSelection.setFields(getTableFields()); |
|
258 |
} else if (step == 2) { |
|
259 |
geomFieldSelection.setFields(getTableFields()); |
|
260 |
} else if (step == 3) { |
|
261 |
uniqueFieldSelection.setFields(getTableFields()); |
|
262 |
} |
|
263 |
step++; |
|
264 |
enableButtons(); |
|
265 |
((CardLayout) pnlWizard.getLayout()).next(pnlWizard); |
|
266 |
} catch (SQLException e1) { |
|
267 |
NotificationManager.addError(PluginServices.getText( |
|
268 |
this, "error_conexion"), e1); |
|
269 |
} catch (DriverLoadException e1) { |
|
270 |
NotificationManager.addError( |
|
271 |
"No se pudo cargar el driver", e1); |
|
272 |
} |
|
273 |
} else { |
|
274 |
JOptionPane.showMessageDialog(WizardSDE.this, |
|
275 |
"No estan todos los datos rellenos", "Error", |
|
276 |
JOptionPane.ERROR_MESSAGE); |
|
277 |
|
|
278 |
} |
|
279 |
} |
|
280 |
}); |
|
281 |
} |
|
282 |
return btnNext; |
|
196 | 283 |
} |
197 | 284 |
|
285 |
private void saveConnection() { |
|
286 |
connectionPanel.saveConnectionSettings(); |
|
287 |
} |
|
288 |
|
|
289 |
private String[] getTableNames() throws SQLException, DriverLoadException { |
|
290 |
try { |
|
291 |
conex = new SeConnection(connectionPanel.getHost(), Integer.parseInt(connectionPanel.getPort()), connectionPanel.getDBName(), connectionPanel.getUser(), connectionPanel.getPassword()); |
|
292 |
Vector theLayers = conex.getLayers(); |
|
293 |
TreeMap ret = new TreeMap(); |
|
294 |
for (int i=0; i < theLayers.size(); i++){ |
|
295 |
SeLayer layer = (SeLayer)theLayers.elementAt(i); |
|
296 |
ret.put(layer.getTableName(), layer.getTableName()); |
|
297 |
} |
|
298 |
return (String[]) ret.keySet().toArray(new String[0]); |
|
299 |
}catch (SeException e) { |
|
300 |
e.printStackTrace(); |
|
301 |
return null; |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
private String[] getTableFields() throws SQLException, DriverLoadException{ |
|
306 |
try { |
|
307 |
SeTable table = new SeTable(conex,dbLayerDefinition.getTable()); |
|
308 |
SeRegisteredColumn[] columns=table.getColumnList(); |
|
309 |
String[] fieldNames=new String[columns.length]; |
|
310 |
for (int i=0; i < columns.length; i++){ |
|
311 |
fieldNames[i]=columns[i].getName(); |
|
312 |
} |
|
313 |
return fieldNames; |
|
314 |
} catch (SeException e) { |
|
315 |
e.printStackTrace(); |
|
316 |
} |
|
317 |
return null; |
|
318 |
} |
|
319 |
|
|
198 | 320 |
/** |
199 |
* DOCUMENT ME!
|
|
200 |
* |
|
201 |
* @return
|
|
321 |
* This method initializes connectionPanel
|
|
322 |
* @return com.iver.cit.gvsig.gui.Panels.ConnectionPanel
|
|
323 |
* @uml.property name="connectionPanel"
|
|
202 | 324 |
*/ |
203 |
public WizardDataSource getDataSource() { |
|
204 |
return dataSource; |
|
325 |
private ConnectionPanel getConnectionPanel() { |
|
326 |
if (connectionPanel == null) { |
|
327 |
connectionPanel = new ConnectionPanel(); |
|
328 |
connectionPanel.setName("connectionPanel"); |
|
329 |
connectionPanel.setDrivers(getDriverNames()); |
|
330 |
} |
|
331 |
return connectionPanel; |
|
205 | 332 |
} |
206 |
|
|
207 | 333 |
/** |
208 |
* DOCUMENT ME!
|
|
209 |
* |
|
210 |
* @param source
|
|
334 |
* This method initializes dbLayerDefinition
|
|
335 |
* @return com.iver.cit.gvsig.gui.Panels.dbLayerDefinition
|
|
336 |
* @uml.property name="dbLayerDefinition"
|
|
211 | 337 |
*/ |
212 |
public void setDataSource(WizardDataSource source) { |
|
213 |
dataSource = source; |
|
338 |
private DBLayerDefinitionPanel getDbLayerDefinition() { |
|
339 |
if (dbLayerDefinition == null) { |
|
340 |
dbLayerDefinition = new DBLayerDefinitionPanel(); |
|
341 |
dbLayerDefinition.setName("dbLayerDefinition"); |
|
342 |
} |
|
343 |
return dbLayerDefinition; |
|
214 | 344 |
} |
345 |
/** |
|
346 |
* This method initializes fieldSelection |
|
347 |
* @return com.iver.cit.gvsig.gui.Panels.FieldSelection |
|
348 |
* @uml.property name="fieldSelection" |
|
349 |
*/ |
|
350 |
private FieldSelection getFieldSelection() { |
|
351 |
if (fieldSelection == null) { |
|
352 |
fieldSelection = new FieldSelection(); |
|
353 |
fieldSelection.setName("fieldSelection"); |
|
354 |
} |
|
355 |
return fieldSelection; |
|
356 |
} |
|
215 | 357 |
|
358 |
/** |
|
359 |
* @return |
|
360 |
* @throws DriverLoadException |
|
361 |
* @uml.property name="driver" |
|
362 |
*/ |
|
363 |
public ArcSdeDriver getDriver() throws DriverLoadException{ |
|
364 |
if (driver == null) { |
|
365 |
driver = (ArcSdeDriver) LayerFactory.getDM().getDriver( |
|
366 |
connectionPanel.getDriver()); |
|
367 |
} |
|
216 | 368 |
|
369 |
return driver; |
|
370 |
} |
|
217 | 371 |
|
372 |
public String getConnectionString() throws DriverLoadException{ |
|
373 |
// String connectionString = getDriver().getConnectionStringBeginning() + "//" + connectionPanel.getHost(); |
|
374 |
// |
|
375 |
// if (connectionPanel.getPort().trim().length() > 0) { |
|
376 |
// connectionString += (":" + connectionPanel.getPort()); |
|
377 |
// } else { |
|
378 |
// connectionString += (":" + driver.getDefaultPort()); |
|
379 |
// } |
|
380 |
// |
|
381 |
// connectionString += ("/" + connectionPanel.getDBName()); |
|
382 |
// |
|
383 |
// return connectionString; |
|
384 |
return ""; |
|
385 |
} |
|
218 | 386 |
|
387 |
public String getLayerName(){ |
|
388 |
return dbLayerDefinition.getLayerName(); |
|
389 |
} |
|
219 | 390 |
|
220 |
public String getHost() { |
|
221 |
return getJTxtHost().getText(); |
|
391 |
/** |
|
392 |
* @return ONLY alphanumeric fields. You need to retrieve |
|
393 |
* the geometry fields with getGeometryField(); |
|
394 |
* @throws DriverLoadException |
|
395 |
*/ |
|
396 |
public String[] getFields() throws DriverLoadException{ |
|
397 |
String[] fields = fieldSelection.getFields(); |
|
398 |
String geomField = geomFieldSelection.getField(); |
|
399 |
String[] onlyAlphanumericFields = new String[fields.length-1]; |
|
400 |
int newIndex = 0; |
|
401 |
for (int i = 0; i < fields.length; i++) { |
|
402 |
if (!fields[i].equals(geomField)) |
|
403 |
{ |
|
404 |
onlyAlphanumericFields[newIndex] = fields[i]; |
|
405 |
newIndex++; |
|
406 |
} |
|
407 |
} |
|
408 |
return onlyAlphanumericFields; |
|
222 | 409 |
} |
223 | 410 |
|
224 |
public String getSchema() { |
|
225 |
return getJTxtEsquema().getText(); |
|
226 |
} |
|
227 | 411 |
/** |
228 |
* DOCUMENT ME! |
|
229 |
* |
|
230 |
* @return Nombre de la capa que aparece en el TOC. |
|
412 |
* @return WhereClause (doesn't check if correct) |
|
231 | 413 |
*/ |
232 |
public String getLayerName() { |
|
233 |
return jTxtNomTabla.getText(); |
|
414 |
public String getWhereClause() |
|
415 |
{ |
|
416 |
return dbLayerDefinition.getWhereClause(); |
|
234 | 417 |
} |
418 |
/** |
|
419 |
* @return |
|
420 |
*/ |
|
235 | 421 |
public String getUser() { |
236 |
return jTxtUser.getText();
|
|
422 |
return connectionPanel.getUser();
|
|
237 | 423 |
} |
424 |
/** |
|
425 |
* @return |
|
426 |
*/ |
|
238 | 427 |
public String getPassword() { |
239 |
return jTxtPassword.getText();
|
|
428 |
return connectionPanel.getPassword();
|
|
240 | 429 |
} |
241 |
public String getPort() |
|
242 |
{ |
|
243 |
return jTxtPort.getText(); |
|
244 |
} |
|
245 |
public String getSqlWhere() |
|
246 |
{ |
|
247 |
return jTxtSqlWhere.getText(); |
|
248 |
} |
|
249 |
|
|
250 | 430 |
/** |
251 |
* This method initializes jPanel |
|
252 |
* |
|
253 |
* @return JPanel |
|
254 |
*/ |
|
255 |
private JPanel getJPanel() { |
|
256 |
if (jPanel == null) { |
|
257 |
jPanel = new JPanel(); |
|
258 |
jLabel = new JLabel(); |
|
259 |
jLabel1 = new JLabel(); |
|
260 |
jLabel2 = new JLabel(); |
|
261 |
jLabel4 = new JLabel(); |
|
262 |
jPanel.setLayout(null); |
|
263 |
jLabel.setText("Usuario:"); |
|
264 |
jLabel.setName("jLabel"); |
|
265 |
jLabel.setSize(80, 19); |
|
266 |
jLabel.setLocation(151, 12); |
|
267 |
jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
268 |
jLabel1.setBounds(149, 41, 82, 19); |
|
269 |
jLabel1.setText("Contrase?a:"); |
|
270 |
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
271 |
jLabel2.setBounds(122, 98, 110, 20); |
|
272 |
jLabel2.setText("Nombre de la tabla:"); |
|
273 |
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
274 |
jLabel4.setBounds(125, 130, 106, 22); |
|
275 |
jLabel4.setText("Cl?usula Where:"); |
|
276 |
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
277 |
jPanel.add(jLabel, null); |
|
278 |
jPanel.add(getJTxtUser(), null); |
|
279 |
jPanel.add(jLabel1, null); |
|
280 |
jPanel.add(getJTxtPassword(), null); |
|
281 |
jPanel.add(getJTxtEsquema(), null); |
|
282 |
jPanel.add(jLabel2, null); |
|
283 |
jPanel.add(getJTxtNomTabla(), null); |
|
284 |
jPanel.add(jLabel4, null); |
|
285 |
jPanel.add(getJTxtSqlWhere(), null); |
|
286 |
} |
|
287 |
return jPanel; |
|
431 |
* @return |
|
432 |
*/ |
|
433 |
public String getTable() { |
|
434 |
return dbLayerDefinition.getTable(); |
|
288 | 435 |
} |
436 |
|
|
289 | 437 |
/** |
290 |
* This method initializes jTextField |
|
291 |
* |
|
292 |
* @return javax.swing.JTextField |
|
293 |
*/ |
|
294 |
private JTextField getJTxtUser() { |
|
295 |
if (jTxtUser == null) { |
|
296 |
jTxtUser = new JTextField(); |
|
297 |
jTxtUser.setName("jTextField"); |
|
298 |
jTxtUser.setColumns(0); |
|
299 |
jTxtUser.setBounds(241, 12, 169, 19); |
|
300 |
jTxtUser.setText("sde"); |
|
301 |
jTxtUser.addFocusListener(new java.awt.event.FocusListener() { |
|
302 |
public void focusLost(java.awt.event.FocusEvent e) { |
|
303 |
listenerSupport.callStateChanged(true); |
|
304 |
System.out.println("focusLost()"); // TODO Auto-generated Event stub focusLost() |
|
305 |
} |
|
306 |
public void focusGained(java.awt.event.FocusEvent e) {} |
|
307 |
}); |
|
308 |
} |
|
309 |
return jTxtUser; |
|
438 |
* @return Field ID (Unique Value Field we want to use has key) |
|
439 |
*/ |
|
440 |
public String getFID() { |
|
441 |
return uniqueFieldSelection.getField(); |
|
310 | 442 |
} |
443 |
|
|
444 |
public String getGeomField() |
|
445 |
{ |
|
446 |
return geomFieldSelection.getField(); |
|
447 |
} |
|
448 |
|
|
311 | 449 |
/** |
312 |
* This method initializes jPasswordField |
|
313 |
* |
|
314 |
* @return javax.swing.JPasswordField |
|
315 |
*/ |
|
316 |
private JPasswordField getJTxtPassword() { |
|
317 |
if (jTxtPassword == null) { |
|
318 |
jTxtPassword = new JPasswordField(); |
|
319 |
jTxtPassword.setBounds(241, 39, 169, 20); |
|
320 |
jTxtPassword.addFocusListener(new java.awt.event.FocusListener() { |
|
321 |
public void focusLost(java.awt.event.FocusEvent e) { |
|
322 |
listenerSupport.callStateChanged(true); |
|
323 |
System.out.println("focusLost()"); // TODO Auto-generated Event stub focusLost() |
|
324 |
} |
|
325 |
public void focusGained(java.awt.event.FocusEvent e) {} |
|
326 |
}); |
|
450 |
* This method initializes geomFieldSelection |
|
451 |
* @return com.iver.cit.gvsig.gui.jdbcwizard.GeomFieldSelection |
|
452 |
* @uml.property name="geomFieldSelection" |
|
453 |
*/ |
|
454 |
private GeomFieldSelection getGeomFieldSelection() { |
|
455 |
if (geomFieldSelection == null) { |
|
456 |
geomFieldSelection = new GeomFieldSelection(); |
|
457 |
geomFieldSelection.setName("geomFieldSelection"); |
|
327 | 458 |
} |
328 |
return jTxtPassword;
|
|
459 |
return geomFieldSelection;
|
|
329 | 460 |
} |
330 | 461 |
/** |
331 |
* This method initializes jTextField
|
|
332 |
*
|
|
333 |
* @return javax.swing.JTextField
|
|
334 |
*/
|
|
335 |
private JTextField getJTxtNomTabla() {
|
|
336 |
if (jTxtNomTabla == null) {
|
|
337 |
jTxtNomTabla = new JTextField();
|
|
338 |
jTxtNomTabla.setBounds(241, 99, 169, 20);
|
|
339 |
jTxtNomTabla.setText("provin");
|
|
462 |
* This method initializes uniqueFieldSelection
|
|
463 |
* @return com.iver.cit.gvsig.gui.jdbcwizard.UniqueFieldSelection
|
|
464 |
* @uml.property name="uniqueFieldSelection"
|
|
465 |
*/ |
|
466 |
private UniqueFieldSelection getUniqueFieldSelection() {
|
|
467 |
if (uniqueFieldSelection == null) {
|
|
468 |
uniqueFieldSelection = new UniqueFieldSelection();
|
|
469 |
uniqueFieldSelection.setName("uniqueFieldSelection");
|
|
470 |
uniqueFieldSelection.setWizard(this);
|
|
340 | 471 |
} |
341 |
return jTxtNomTabla;
|
|
472 |
return uniqueFieldSelection;
|
|
342 | 473 |
} |
343 |
/** |
|
344 |
* This method initializes jTextField |
|
345 |
* |
|
346 |
* @return javax.swing.JTextField |
|
347 |
*/ |
|
348 |
private JTextField getJTxtSqlWhere() { |
|
349 |
if (jTxtSqlWhere == null) { |
|
350 |
jTxtSqlWhere = new JTextField(); |
|
351 |
jTxtSqlWhere.setBounds(241, 129, 169, 24); |
|
352 |
} |
|
353 |
return jTxtSqlWhere; |
|
474 |
public void initWizard() { |
|
354 | 475 |
} |
355 | 476 |
|
356 |
/** |
|
357 |
* This method initializes jTextField |
|
358 |
* |
|
359 |
* @return javax.swing.JTextField |
|
360 |
*/ |
|
361 |
private JTextField getJTxtHost() { |
|
362 |
if (jTxtHost == null) { |
|
363 |
jTxtHost = new JTextField(); |
|
364 |
jTxtHost.setText("Alvaro"); |
|
365 |
jTxtHost.setPreferredSize(new java.awt.Dimension(143,20)); |
|
366 |
} |
|
367 |
return jTxtHost; |
|
368 |
} |
|
369 |
|
|
370 |
/** |
|
371 |
* This method initializes jTextField |
|
372 |
* |
|
373 |
* @return javax.swing.JTextField |
|
374 |
*/ |
|
375 |
private JTextField getJTxtPort() { |
|
376 |
if (jTxtPort == null) { |
|
377 |
jTxtPort = new JTextField(); |
|
378 |
jTxtPort.setText("5151"); |
|
379 |
} |
|
380 |
return jTxtPort; |
|
381 |
} |
|
382 |
|
|
383 |
/** |
|
384 |
* This method initializes jTextField |
|
385 |
* |
|
386 |
* @return javax.swing.JTextField |
|
387 |
*/ |
|
388 |
private JTextField getJTxtEsquema() { |
|
389 |
if (jTxtEsquema == null) { |
|
390 |
jTxtEsquema = new JTextField(); |
|
391 |
jTxtEsquema.setBounds(241, 69, 168, 20); |
|
392 |
jTxtEsquema.setText("Sigespa"); |
|
393 |
} |
|
394 |
return jTxtEsquema; |
|
395 |
} |
|
396 |
|
|
397 |
public void initWizard() { |
|
398 |
} |
|
399 |
|
|
400 | 477 |
/* (non-Javadoc) |
401 | 478 |
* @see com.iver.cit.gvsig.gui.WizardPanel#execute() |
402 | 479 |
*/ |
... | ... | |
406 | 483 |
/* (non-Javadoc) |
407 | 484 |
* @see com.iver.cit.gvsig.gui.WizardPanel#getLayer() |
408 | 485 |
*/ |
486 |
|
|
409 | 487 |
public FLayer getLayer() { |
488 |
IProjection proj = null; |
|
410 | 489 |
WizardSDE arcsde_wizard = this; |
411 |
String dbHost = arcsde_wizard.getHost();
|
|
412 |
String port = arcsde_wizard.getPort();
|
|
490 |
String dbHost = connectionPanel.getHost();
|
|
491 |
String port = connectionPanel.getPort();
|
|
413 | 492 |
String user = arcsde_wizard.getUser(); |
414 | 493 |
String pwd = arcsde_wizard.getPassword(); |
415 |
// String layerName = arcsde_wizard.getLayerName(); |
|
416 |
// String fields = StringUtilities.getComaSeparated(wiz.getFields()); |
|
494 |
String layerName = arcsde_wizard.getLayerName(); |
|
417 | 495 |
String tableName = arcsde_wizard.getLayerName(); |
418 |
String schema = arcsde_wizard.getSchema(); |
|
496 |
String schema = connectionPanel.getDBName(); |
|
497 |
String connectionName=connectionPanel.getSettingsName(); |
|
419 | 498 |
String whereClause = ""; |
420 |
String [] fields = null; |
|
421 |
|
|
422 |
// VectorialDatabaseDriver driver; |
|
423 |
// try { |
|
424 |
// driver = (VectorialDatabaseDriver) LayerFactory.getDM().getDriver("ArcSDE driver"); |
|
425 |
ArcSdeDriver driver = new ArcSdeDriver(); |
|
426 |
// ArcSdeDriver drv = (ArcSdeDriver) driver; |
|
427 |
driver.setData(dbHost, Integer.parseInt(port), schema, user, pwd, tableName, fields, whereClause); |
|
428 |
|
|
429 |
return LayerFactory.createDBLayer(driver, tableName, null); |
|
499 |
|
|
500 |
String strEPSG = getMapCtrl().getViewPort() |
|
501 |
.getProjection().getAbrev() |
|
502 |
.substring(5); |
|
503 |
|
|
504 |
ArcSDELayerDefinition lyrDef = new ArcSDELayerDefinition(); |
|
505 |
lyrDef.setHost(dbHost); |
|
506 |
lyrDef.setPort(port); |
|
507 |
lyrDef.setSchema(schema); |
|
508 |
lyrDef.setUser(user); |
|
509 |
lyrDef.setPassword(pwd); |
|
510 |
lyrDef.setName(layerName); |
|
511 |
lyrDef.setTableName(tableName); |
|
512 |
lyrDef.setWhereClause(whereClause); |
|
513 |
lyrDef.setFieldGeometry(arcsde_wizard.getGeomField()); |
|
514 |
lyrDef.setFieldID(arcsde_wizard.getFID()); |
|
515 |
lyrDef.setFieldNames(arcsde_wizard.getFields()); |
|
516 |
lyrDef.setSRID_EPSG(strEPSG); |
|
517 |
lyrDef.setConnectionName(connectionName); |
|
518 |
ArcSdeDriver driver = new ArcSdeDriver(); |
|
519 |
if (dbLayerDefinition.getWorkingArea() != null){ |
|
520 |
driver.setWorkingArea(dbLayerDefinition.getWorkingArea()); |
|
521 |
} |
|
522 |
|
|
523 |
if (driver instanceof ICanReproject){ |
|
524 |
((ICanReproject)driver).setDestProjection(strEPSG); |
|
525 |
} |
|
526 |
driver.setData(null, lyrDef); |
|
527 |
// driver.setData(dbHost, Integer.parseInt(port), schema, user, pwd, tableName, fields, whereClause); |
|
528 |
if (driver instanceof ICanReproject) |
|
529 |
{ |
|
530 |
proj = CRSFactory.getCRS("EPSG:" + ((ICanReproject)driver).getSourceProjection()); |
|
531 |
} |
|
532 |
return LayerFactory.createDBLayer((VectorialDatabaseDriver)driver, tableName, proj); |
|
430 | 533 |
/* } catch (DriverLoadException e) { |
431 | 534 |
// TODO Auto-generated catch block |
432 | 535 |
e.printStackTrace(); |
433 | 536 |
return null; |
434 | 537 |
} */ |
435 |
|
|
538 |
|
|
436 | 539 |
} |
437 | 540 |
} |
438 |
|
|
439 |
// @jve:decl-index=0:visual-constraint="10,10" |
|
440 |
// @jve:visual-info decl-index=0 visual-constraint="16,10" |
|
441 |
// @jve:visual-info decl-index=0 visual-constraint="10,10" |
|
442 |
// @jve:visual-info decl-index=0 visual-constraint="10,10" |
|
443 |
// @jve:visual-info decl-index=0 visual-constraint="10,10" |
Also available in: Unified diff