Revision 28890 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/TableOperations.java

View differences:

TableOperations.java
42 42

  
43 43
import java.awt.Component;
44 44
import java.awt.Dimension;
45
import java.util.ArrayList;
46
import java.util.Iterator;
47 45

  
48 46
import javax.swing.JOptionPane;
49 47

  
50
import org.gvsig.app.join.dal.feature.JoinTransform;
51 48
import org.gvsig.fmap.dal.DALLocator;
52
import org.gvsig.fmap.dal.DataManager;
53 49
import org.gvsig.fmap.dal.DataTypes;
54 50
import org.gvsig.fmap.dal.exception.DataException;
55
import org.gvsig.fmap.dal.exception.ReadException;
56 51
import org.gvsig.fmap.dal.feature.DisposableIterator;
57 52
import org.gvsig.fmap.dal.feature.Feature;
58 53
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
63 58
import org.gvsig.project.document.table.FeatureTableDocument;
64 59
import org.gvsig.project.document.table.FeatureTableDocumentFactory;
65 60
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel;
66
import org.gvsig.project.document.table.gui.JoinWizardController;
67 61
import org.opengis.feature.FeatureCollection;
68 62

  
69 63
import com.iver.andami.PluginServices;
......
93 87
	 * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
94 88
	 */
95 89
	public void execute(String actionCommand) {
96
				ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
97
				com.iver.cit.gvsig.project.Project project=pe.getProject();
98
				FeatureTableDocument[] pts = project.getDocumentsByType(FeatureTableDocumentFactory.registerName)
99
					.toArray(new FeatureTableDocument[0]);
100
				if ("JOIN".equals(actionCommand)) {
101
					JoinWizardController wizardController = new JoinWizardController(
102
					this);
103
			wizardController.runWizard(pts);
104
		}else if ("LINK".equals(actionCommand)) {
90
		ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
91
		com.iver.cit.gvsig.project.Project project=pe.getProject();
92
		FeatureTableDocument[] pts = project.getDocumentsByType(FeatureTableDocumentFactory.registerName)
93
		.toArray(new FeatureTableDocument[0]);
94
		if ("LINK".equals(actionCommand)) {
105 95
			try {
106 96
				final ObjectSelectionStep sourceTable = new ObjectSelectionStep();
107 97
				sourceTable.setModel(new TableSelectionModel(pts,
......
109 99

  
110 100
				final ObjectSelectionStep targetTable = new ObjectSelectionStep();
111 101
				targetTable.setModel(new TableSelectionModel(pts,
112
				        PluginServices.getText(this, "seleccione_tabla_a_enlazar")));
102
						PluginServices.getText(this, "seleccione_tabla_a_enlazar")));
113 103

  
114 104
				final ObjectSelectionStep firstTableField = new ObjectSelectionStep();
115 105
				final ObjectSelectionStep secondTableField = new ObjectSelectionStep();
......
121 111
				wiz.addStep(secondTableField);
122 112

  
123 113
				wiz.addWizardListener(new WizardListener() {
124
						public void cancel(WizardEvent w) {
125
							PluginServices.getMDIManager().closeWindow(wiz);
126
						}
114
					public void cancel(WizardEvent w) {
115
						PluginServices.getMDIManager().closeWindow(wiz);
116
					}
127 117

  
128
						public void finished(WizardEvent w) {
129
							PluginServices.getMDIManager().closeWindow(wiz);
118
					public void finished(WizardEvent w) {
119
						PluginServices.getMDIManager().closeWindow(wiz);
130 120

  
131
							FeatureTableDocument sourceProjectTable = (FeatureTableDocument) sourceTable.getSelected();
132
							FeatureStore sds1 = sourceProjectTable.getStore();
121
						FeatureTableDocument sourceProjectTable = (FeatureTableDocument) sourceTable.getSelected();
122
						FeatureStore sds1 = sourceProjectTable.getStore();
133 123

  
134
							FeatureTableDocument targetProjectTable = (FeatureTableDocument) targetTable.getSelected();
135
							FeatureStore sds2 = targetProjectTable.getStore();
124
						FeatureTableDocument targetProjectTable = (FeatureTableDocument) targetTable.getSelected();
125
						FeatureStore sds2 = targetProjectTable.getStore();
136 126

  
137
							String field1 = (String) firstTableField.getSelected();
138
							String field2 = (String) secondTableField.getSelected();
139
							sourceProjectTable.setLinkTable(sds2.getName(),field1,field2);
140
							((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject().setLinkTable();
127
						String field1 = (String) firstTableField.getSelected();
128
						String field2 = (String) secondTableField.getSelected();
129
						sourceProjectTable.setLinkTable(sds2.getName(),field1,field2);
130
						((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject().setLinkTable();
141 131

  
142
						}
132
					}
143 133

  
144
						public void next(WizardEvent w) {
145
							WizardControl wiz = w.wizard;
146
							wiz.enableBack(true);
147
							wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
134
					public void next(WizardEvent w) {
135
						WizardControl wiz = w.wizard;
136
						wiz.enableBack(true);
137
						wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
148 138

  
149
							if (w.currentStep == 1) {
150
								FeatureTableDocument pt = (FeatureTableDocument) sourceTable.getSelected();
139
						if (w.currentStep == 1) {
140
							FeatureTableDocument pt = (FeatureTableDocument) sourceTable.getSelected();
151 141

  
152
								try {
153
									firstTableField.setModel(new FieldSelectionModel(
154
											pt.getStore(),
155
											PluginServices.getText(this, "seleccione_campo_enlace"),
156
											DataTypes.STRING));
157
								} catch (SelectionException e) {
158
									NotificationManager.addError("Error obteniendo los campos de la tabla",
142
							try {
143
								firstTableField.setModel(new FieldSelectionModel(
144
										pt.getStore(),
145
										PluginServices.getText(this, "seleccione_campo_enlace"),
146
										DataTypes.STRING));
147
							} catch (SelectionException e) {
148
								NotificationManager.addError("Error obteniendo los campos de la tabla",
159 149
										e);
160
								}
161
							} else if (w.currentStep == 3) {
162
								try {
163
									//tabla
164
									FeatureTableDocument pt = (FeatureTableDocument) sourceTable.getSelected();
150
							}
151
						} else if (w.currentStep == 3) {
152
							try {
153
								//tabla
154
								FeatureTableDocument pt = (FeatureTableDocument) sourceTable.getSelected();
165 155

  
166
									//?ndice del campo
167
									FeatureStore fs = pt.getStore();
168
									String fieldName = (String) firstTableField.getSelected();
169
									int type = ((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldName)).getDataType();
156
								//?ndice del campo
157
								FeatureStore fs = pt.getStore();
158
								String fieldName = (String) firstTableField.getSelected();
159
								int type = ((FeatureAttributeDescriptor)fs.getDefaultFeatureType().get(fieldName)).getDataType();
170 160

  
171
									secondTableField.setModel(new FieldSelectionModel(
172
											((FeatureTableDocument) targetTable
173
														.getSelected())
174
														.getStore(),
175
											PluginServices.getText(this, "seleccione_campo_enlace"),
176
											type));
177
								} catch (SelectionException e) {
178
									NotificationManager.addError("Error obteniendo los campos de la tabla",
161
								secondTableField.setModel(new FieldSelectionModel(
162
										((FeatureTableDocument) targetTable
163
												.getSelected())
164
												.getStore(),
165
												PluginServices.getText(this, "seleccione_campo_enlace"),
166
												type));
167
							} catch (SelectionException e) {
168
								NotificationManager.addError("Error obteniendo los campos de la tabla",
179 169
										e);
180
								} catch (DataException e) {
181
									NotificationManager.addError("Error obteniendo los campos de la tabla",
182
											e);
183
								}
170
							} catch (DataException e) {
171
								NotificationManager.addError("Error obteniendo los campos de la tabla",
172
										e);
184 173
							}
185 174
						}
175
					}
186 176

  
187
						public void back(WizardEvent w) {
188
							WizardControl wiz = w.wizard;
189
							wiz.enableBack(true);
190
							wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
191
						}
192
					});
177
					public void back(WizardEvent w) {
178
						WizardControl wiz = w.wizard;
179
						wiz.enableBack(true);
180
						wiz.enableNext(((ObjectSelectionStep) wiz.getCurrentStep()).getSelectedItem() != null);
181
					}
182
				});
193 183
				project.setModified(true);
194 184
				PluginServices.getMDIManager().addWindow(wiz);
195 185
			} catch (SelectionException e) {
196 186
				NotificationManager.addError("Error abriendo el asistente", e);
197 187
			}
198
      	}
188
		}
199 189
	}
200 190

  
201 191
	/**
......
230 220
	private FeatureSet doSet(String expression) throws DataException {
231 221
		FeatureQuery query = featureStore.createFeatureQuery();
232 222
		query
233
				.setFilter(DALLocator.getDataManager().createExpresion(
234
						expression));
223
		.setFilter(DALLocator.getDataManager().createExpresion(
224
				expression));
235 225
		return featureStore.getFeatureSet(query);
236 226
	}
237 227
	/**
......
267 257
				.getSelection();
268 258

  
269 259
				FeatureSelection newSelection = featureStore
270
						.createFeatureSelection();
260
				.createFeatureSelection();
271 261
				iterator = set.iterator();
272 262
				while (iterator.hasNext()) {
273 263
					Feature feature = (Feature) iterator.next();
......
345 335
					}
346 336
				}
347 337
			}
348
*/
349
			return false;
338
		 */
339
		return false;
350 340
		//}
351 341
	}
352 342

  
......
355 345
	 */
356 346
	public void initialize() {
357 347
		registerIcons();
358
//		FIXME
359
//		org.gvsig.fmap.data.feature.joinstore.Register.selfRegister();
348
		//		FIXME
349
		//		org.gvsig.fmap.data.feature.joinstore.Register.selfRegister();
360 350

  
361 351

  
362 352
	}
......
365 355
		PluginServices.getIconTheme().registerDefault(
366 356
				"table-join",
367 357
				this.getClass().getClassLoader().getResource("images/tablejoin.png")
368
			);
358
		);
369 359

  
370 360
		PluginServices.getIconTheme().registerDefault(
371 361
				"table-link",
372 362
				this.getClass().getClassLoader().getResource("images/tablelink.png")
373
			);
363
		);
374 364
	}
375 365

  
376 366
	/**
......
379 369
	public boolean isEnabled() {
380 370
		return true;
381 371
	}
382
	public void execJoin(FeatureTableDocument sourceProjectTable,
383
			String field1, String prefix1,
384
			FeatureTableDocument targetProjectTable, String field2,
385
			String prefix2) {
386 372

  
387
		FeatureStore fs1 = sourceProjectTable.getStore();
388

  
389
		FeatureStore fs2 = targetProjectTable.getStore();
390

  
391
		if (fs1 == fs2) {
392
			NotificationManager
393
					.addInfo("no_es_posible_aplicar_join_sobre_la_misma_fuente");
394
		}
395

  
396
		try {
397
			DataManager dm = DALLocator.getDataManager();
398
			JoinTransform jt = new JoinTransform();
399
			ArrayList<String> fields = new ArrayList<String>();
400
			Iterator iterator2 = fs2.getDefaultFeatureType().iterator();
401
			while (iterator2.hasNext()) {
402
				FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator2
403
						.next();
404
				String name = descriptor.getName();
405
				if (!name.equals(field2)) {
406
					fields.add(name);
407
				}
408
			}
409
			jt.initialize(fs1, fs2, field1, field2, prefix1, prefix2, fields
410
					.toArray(new String[0]));
411
			fs1.getTransforms().add(jt);
412
			// featureStore=fs1;
413

  
414
		} catch (ReadException e) {
415
			NotificationManager.addError("Error leyendo del driver", e);
416
		} catch (DataException e) {
417
			NotificationManager.addError(e);
418
		}
419

  
420
	}
421 373
	/**
422 374
	 * Ensure that field name only has 'safe' characters
423 375
	 * (no spaces, special characters, etc).

Also available in: Unified diff