Revision 28890

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/JoinWizardController.java
1
/**
2
 *
3
 */
4
package org.gvsig.project.document.table.gui;
5

  
6
import java.awt.Dimension;
7
import java.awt.event.ItemEvent;
8
import java.awt.event.ItemListener;
9

  
10
import javax.swing.ImageIcon;
11

  
12
import org.gvsig.fmap.dal.exception.DataException;
13
import org.gvsig.fmap.dal.exception.ReadException;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.FeatureStore;
16
import org.gvsig.project.document.table.FeatureTableDocument;
17

  
18
import jwizardcomponent.FinishAction;
19

  
20
import com.iver.andami.PluginServices;
21
import com.iver.andami.messages.NotificationManager;
22
import com.iver.cit.gvsig.TableOperations;
23
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard;
24
import com.iver.cit.gvsig.project.documents.table.FieldSelectionModel;
25

  
26
public class JoinWizardController {
27
	private final TableOperations tableOperations;
28

  
29
	/**
30
	 * @param tableOperations
31
	 */
32
	public JoinWizardController(TableOperations tableOperations) {
33
		this.tableOperations = tableOperations;
34
	}
35

  
36

  
37
	public void runWizard(FeatureTableDocument[] pts) {
38
		// create wizard
39
		ImageIcon logo = PluginServices.getIconTheme().get("table-join");
40
		final SimpleWizard wizard = new SimpleWizard(logo);
41
		wizard.getWindowInfo().setTitle(PluginServices.getText(this, "Table_Join"));
42

  
43
		// create first step (source table)
44
		final TableWizardStep srcTableWzrd = new TableWizardStep(wizard.getWizardComponents(), "Title" );
45
		srcTableWzrd.getHeaderLbl().setText(PluginServices.getText(this,"Source_table_options"));
46
		srcTableWzrd.getTableNameLbl().setText(PluginServices.getText(this,"Source_table_"));
47
		srcTableWzrd.getFieldNameLbl().setText(PluginServices.getText(this,"Field_to_use_for_JOIN_"));
48
		srcTableWzrd.getFieldPrefixLbl().setText(PluginServices.getText(this,"Field_prefix_"));
49
		srcTableWzrd.getTableNameCmb().addItemListener(
50
				new ItemListener() {
51

  
52
					public void itemStateChanged(ItemEvent e) {
53
						if (e.getStateChange()==e.SELECTED) {
54
							FeatureTableDocument pt = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
55

  
56
							srcTableWzrd.setFieldModel(new FieldSelectionModel(
57
									pt.getStore(),
58
									PluginServices.getText(this, "seleccione_campo_enlace"),
59
									-1));
60
							srcTableWzrd.getFieldPrefixTxt().setText(tableOperations.sanitizeFieldName(pt.getName()));
61
						}
62

  
63
					}
64
				}
65
		);
66
		for (int i=0; i<pts.length; i++) {
67
			srcTableWzrd.getTableNameCmb().addItem(pts[i]);
68
		}
69

  
70
		// create second step (target table)
71
		final TableWizardStep targTableWzrd = new TableWizardStep(wizard.getWizardComponents(), "Title" );
72
		targTableWzrd.getHeaderLbl().setText(PluginServices.getText(this,"Target_table_options"));
73
		targTableWzrd.getTableNameLbl().setText(PluginServices.getText(this,"Target_table_"));
74
		targTableWzrd.getFieldNameLbl().setText(PluginServices.getText(this,"Field_to_use_for_JOIN_"));
75
		targTableWzrd.getFieldPrefixLbl().setText(PluginServices.getText(this,"Field_prefix_"));
76
		targTableWzrd.getTableNameCmb().addItemListener(
77
				new ItemListener() {
78

  
79
					public void itemStateChanged(ItemEvent e) {
80
						if (e.getStateChange()==e.SELECTED) {
81
							try {
82
								//tabla
83
								FeatureTableDocument sourcePt = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
84
								FeatureTableDocument targetPt = (FeatureTableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
85
								targTableWzrd.getFieldPrefixTxt().setText(tableOperations.sanitizeFieldName(targetPt.getName()));
86

  
87
								//?ndice del campo
88
								FeatureStore sds = sourcePt.getStore();
89
								String fieldName = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
90
								FeatureAttributeDescriptor fad=sds.getDefaultFeatureType().getAttributeDescriptor(fieldName);
91
//								int fieldIndex = sds.getFieldIndexByName(fieldName);
92
//								if (fieldIndex!=-1) {
93
//									int type = sds.getFieldType(fieldIndex);
94
									targTableWzrd.setFieldModel(new FieldSelectionModel(
95
											targetPt.getStore(),
96
											PluginServices.getText(this, "seleccione_campo_enlace"),
97
											fad.getDataType()));
98
//								}
99
//								else {
100
//									NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields")
101
//											, new Exception());
102
//								}
103
							} catch (ReadException e2) {
104
								NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"),
105
										e2);
106
							} catch (DataException e2) {
107
								NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"),
108
										e2);
109
							}
110
						}
111

  
112
					}
113
				}
114
		);
115
		for (int i=0; i<pts.length; i++) {
116
			targTableWzrd.getTableNameCmb().addItem(pts[i]);
117
		}
118

  
119
		// add steps and configure wizard
120
		wizard.getWizardComponents().addWizardPanel(srcTableWzrd);
121
		wizard.getWizardComponents().addWizardPanel(targTableWzrd);
122
		wizard.getWizardComponents().updateComponents();
123
		wizard.setSize(new Dimension(450, 230));
124
		wizard.getWizardComponents().setFinishAction(new FinishAction(wizard.getWizardComponents()) {
125
			public void performAction() {
126
				FeatureTableDocument sourceProjectTable = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
127
				String field1 = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
128
				String prefix1 = srcTableWzrd.getFieldPrefixTxt().getText();
129
				if (sourceProjectTable==null || field1==null || prefix1 == null) {
130
					NotificationManager.showMessageError(
131
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
132
					return;
133
				}
134
				FeatureTableDocument targetProjectTable = (FeatureTableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
135
				String field2 = (String) targTableWzrd.getFieldNameCmb().getSelectedItem();
136
				String prefix2 = targTableWzrd.getFieldPrefixTxt().getText();
137
				if (targetProjectTable==null || field2==null || prefix2 == null) {
138
					NotificationManager.showMessageError(
139
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
140
					return;
141
				}
142
				tableOperations.execJoin(sourceProjectTable, field1, prefix1, targetProjectTable, field2, prefix2);
143

  
144
				PluginServices.getMDIManager().closeWindow(wizard);
145
			}
146
		}
147
		);
148

  
149
		// show the wizard
150
		PluginServices.getMDIManager().addWindow(wizard);
151
	}
152

  
153
	private class InvalidParameterException extends Exception {
154
	}
155
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/AppGvSigLocator.java
27 27

  
28 28
package org.gvsig;
29 29

  
30
import org.gvsig.app.daltransform.FeatureTransformManager;
31 30
import org.gvsig.tools.ToolsLocator;
32 31
import org.gvsig.tools.locator.BaseLocator;
33 32
import org.gvsig.tools.locator.Locator;
......
41 40

  
42 41
	private static final String APPGVSIG_MANAGER_DESCRIPTION = "Manager of appgvSIG";
43 42
	
44
	public static final String FEATURE_TRANSFORM_MANAGER_NAME = "appgsigLocator.manager.transform";
45
	
46
	public static final String FEATURE_TRANSFORM_MANAGER_DESCRIPTION = "Manager for the feature transforms";
47

  
48 43
	/**
49 44
	 * Unique instance.
50 45
	 */
......
91 86
	public static void registerDefaultAppGvSigManager(Class clazz) {
92 87
		getInstance().registerDefault(APPGVSIG_MANAGER_NAME,
93 88
				APPGVSIG_MANAGER_DESCRIPTION, clazz);
94
	}
95
	
96
	/**
97
	 * Return a reference to FeatureTransformManager.
98
	 *
99
	 * @return a reference to FeatureTransformManager
100
	 * @throws LocatorException
101
	 *             if there is no access to the class or the class cannot be
102
	 *             instantiated
103
	 * @see Locator#get(String)
104
	 */
105
	public static FeatureTransformManager getFeatureTransformManager()
106
			throws LocatorException {
107
		return (FeatureTransformManager) getInstance().get(FEATURE_TRANSFORM_MANAGER_NAME);
108
	}
109

  
110
	/**
111
	 * Registers the Class implementing the FeatureTransformManager interface.
112
	 *
113
	 * @param clazz
114
	 *            implementing the PersistenceManager interface
115
	 */
116
	public static void registerFeatureTransformManager(Class clazz) {
117
		getInstance().register(FEATURE_TRANSFORM_MANAGER_NAME,
118
				FEATURE_TRANSFORM_MANAGER_DESCRIPTION, clazz);
119
	}
120

  
121
	public static void registerDefaultFeatureTransformManager(Class clazz) {
122
		getInstance().registerDefault(FEATURE_TRANSFORM_MANAGER_NAME,
123
				FEATURE_TRANSFORM_MANAGER_DESCRIPTION, clazz);
124
	}
89
	}		
125 90
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/AppGvSigLibrary.java
30 30
 */
31 31
package org.gvsig;
32 32

  
33
import org.gvsig.app.daltransform.impl.DefaultFeatureTransformManager;
34 33
import org.gvsig.imp.DefaultAppGvSigManager;
35 34
import org.gvsig.tools.locator.BaseLibrary;
36 35
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
......
46 45
		super.initialize();
47 46
		AppGvSigLocator
48 47
				.registerDefaultAppGvSigManager(DefaultAppGvSigManager.class);
49
		AppGvSigLocator
50
				.registerDefaultFeatureTransformManager(DefaultFeatureTransformManager.class);
51 48
	}
52 49

  
53 50
	@Override
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/RemoveTableUnion.java
1
package com.iver.cit.gvsig;
2

  
3
import org.gvsig.app.join.dal.feature.JoinTransform;
4
import org.gvsig.fmap.dal.feature.FeatureStore;
5
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
6
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
7
import org.gvsig.project.document.table.FeatureTableDocument;
8
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel;
9

  
10
import com.iver.andami.PluginServices;
11
import com.iver.andami.plugins.Extension;
12
import com.iver.andami.ui.mdiManager.IWindow;
13

  
14
/**
15
 * @author Fernando Gonz?lez Cort?s
16
 */
17
public class RemoveTableUnion extends Extension{
18

  
19
	/**
20
	 * @see com.iver.andami.plugins.IExtension#initialize()
21
	 */
22
	public void initialize() {
23
		// TODO Auto-generated method stub
24

  
25
	}
26

  
27
	/**
28
	 * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
29
	 */
30
	public void execute(String actionCommand) {
31
		FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) PluginServices.getMDIManager().getActiveWindow();
32
		FeatureTableDocument pt = t.getModel();
33
		FeatureStore fs = pt.getStore();
34
		this.removeJoinTransfor(fs);
35

  
36
		//		TODO
37
		//		if (fs instanceof JoinFeatureStore) {
38
		//			DataManager dm = DALLocator.getDataManager();
39
		//			DataStoreParameters originalParams = ((JoinFeatureStoreParameters) fs
40
		//					.getParameters()).getStorePrimary();
41
		//			FeatureStore original = null;
42
		//			try {
43
		//				original = (FeatureStore) dm.createStore(originalParams);
44
		//			} catch (InitializeException e) {
45
		//				NotificationManager.addError(e.getMessage(), e);
46
		//				return;
47
		//			}
48
		//
49
		//			pt.setStore(original);
50
		//			try {
51
		//				fs.dispose();
52
		//			} catch (CloseException e) {
53
		//				NotificationManager.addError(e);
54
		//			}
55
		//			t.setModel(pt);
56
		//
57
		//		}
58

  
59
		//		t.clearSelectedFields();
60
		t.getModel().setModified(true);
61
	}
62

  
63
	public void removeJoinTransfor(FeatureStore store) {
64
		FeatureStoreTransforms transforms = store.getTransforms();
65
		int size = transforms.size();
66
		if (size < 1) {
67
			return;
68
		}
69
		FeatureStoreTransform join = transforms.getTransform(size - 1);
70
		if (join instanceof JoinTransform) {
71
			transforms.remove(join);
72
		} else {
73
			return;
74
		}
75

  
76

  
77

  
78
	}
79

  
80
	public boolean hasJoinTransform(FeatureStore store) {
81

  
82
		FeatureStoreTransforms transforms = store.getTransforms();
83
		int size = transforms.size();
84
		if (size < 1) {
85
			return false;
86
		}
87
		return (transforms.getTransform(size - 1) instanceof JoinTransform);
88

  
89
	}
90

  
91
	/**
92
	 * @see com.iver.andami.plugins.IExtension#isEnabled()
93
	 */
94
	public boolean isEnabled() {
95
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
96

  
97
		if (v == null) {
98
			return false;
99
		}
100

  
101
		if (v.getClass() == FeatureTableDocumentPanel.class) {
102
			FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v;
103
			// FIXME !!!! Asi se hacia antes
104
			//			if (t.getModel().getOriginal() != null){
105
			//				return true;
106
			//			}
107

  
108
			FeatureTableDocument pt = t.getModel();
109
			FeatureStore fs = pt.getStore();
110

  
111
			return this.hasJoinTransform(fs);
112
//			TODO
113
//			if (fs instanceof JoinFeatureStore) {
114
//				return true;
115
//			}
116

  
117
		}
118
		return false;
119
	}
120

  
121
	/**
122
	 * @see com.iver.andami.plugins.IExtension#isVisible()
123
	 */
124
	public boolean isVisible() {
125
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
126

  
127
		if (v == null) {
128
			return false;
129
		}
130

  
131
		if (v instanceof FeatureTableDocumentPanel) {
132
			return true;
133
		} else {
134
			return false;
135
		}
136

  
137
	}
138

  
139
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/FeatureTransformExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package com.iver.cit.gvsig;
29

  
30
import org.gvsig.AppGvSigLocator;
31
import org.gvsig.app.daltransform.FeatureTransformManager;
32
import org.gvsig.app.daltransform.gui.FeatureTransformSelectionAction;
33
import org.gvsig.app.daltransform.gui.FeatureTransformWizardModel;
34
import org.gvsig.app.join.daltransform.JoinTransformGui;
35

  
36
import com.iver.andami.PluginServices;
37
import com.iver.andami.plugins.Extension;
38
import com.iver.andami.ui.wizard.WizardAndami;
39

  
40
/**
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
42
 */
43
public class FeatureTransformExtension extends Extension{
44
	public static final int WIDTH = 315;
45
	public static final int HEIGHT = 600;
46
	
47
	/* (non-Javadoc)
48
	 * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
49
	 */
50
	public void execute(String actionCommand) {
51
		WizardAndami wizard = new WizardAndami(
52
				PluginServices.getIconTheme().get("feature-transform"));
53
		wizard.setSize(HEIGHT, WIDTH);
54
		wizard.getWizardComponents().getFinishButton().setEnabled(false);
55
		wizard.getWindowInfo().setTitle(PluginServices.getText(this, "transform_wizard"));
56
		FeatureTransformWizardModel featureTransformWizardModel = new FeatureTransformWizardModel(wizard);
57
		wizard.getWizardComponents().setFinishAction(new FeatureTransformSelectionAction(featureTransformWizardModel));
58
		PluginServices.getMDIManager().addWindow(wizard);
59
	}	
60

  
61
	/* (non-Javadoc)
62
	 * @see com.iver.andami.plugins.IExtension#initialize()
63
	 */
64
	public void initialize() {
65
		registerIcons();
66
		registerTranformations();
67
	}
68

  
69
	private void registerTranformations(){
70
		FeatureTransformManager transformManager = AppGvSigLocator.getFeatureTransformManager();
71
		transformManager.registerFeatureTransform("join", JoinTransformGui.class);
72
	}
73
	
74
	private void registerIcons(){
75
		PluginServices.getIconTheme().registerDefault(
76
				"feature-transform",
77
				this.getClass().getClassLoader().getResource("images/transform.png")
78
		);
79
	}
80

  
81
	/* (non-Javadoc)
82
	 * @see com.iver.andami.plugins.IExtension#isEnabled()
83
	 */
84
	public boolean isEnabled() {
85
		return true;
86
	}
87

  
88
	/* (non-Javadoc)
89
	 * @see com.iver.andami.plugins.IExtension#isVisible()
90
	 */
91
	public boolean isVisible() {		
92
		return true;
93
	}
94
}
95

  
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/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).
branches/v2_0_0_prep/applications/appgvSIG/config/config.xml
419 419
		<extension class-name="com.iver.cit.gvsig.TableOperations"
420 420
			description="Extensi?n encargada de gestionar las operaciones sobre las tablas."
421 421
			active="true">
422
			<menu text="Tabla/join" icon="table-join" action-command="JOIN"/>
423 422
			<menu text="Tabla/link" icon="table-link" action-command="LINK"/>
424 423
			<tool-bar name="Herramientas" position="12">
425
				<action-tool icon="table-join" action-command="JOIN" tooltip="join" position="1"/>
426 424
				<action-tool icon="table-link" action-command="LINK" tooltip="link" position="2"/>
427 425
			</tool-bar>
428 426
		</extension>
......
535 533
			</tool-bar>
536 534
		</extension>
537 535

  
538
		<extension class-name="com.iver.cit.gvsig.RemoveTableUnion"
539
			description="Extensi?n encargada de quitar uniones de las tablas."
540
			active="true">
541
			<menu text="Tabla/quitar_uniones"/>
542
		</extension>
543

  
544 536
		<extension class-name="com.iver.cit.gvsig.RemoveTableLink"
545 537
			description="Extensi?n encargada de quitar los enlaces de las tablas."
546 538
			active="true">
......
632 624
			priority="999999999">
633 625
			<menu text="Ayuda/acerca_de" />
634 626
		</extension>
635
		
636
		<extension class-name="com.iver.cit.gvsig.FeatureTransformExtension"
637
			description=""
638
			active="true">
639
			<menu text="tools/feature_transform" />
640
		</extension>
641 627

  
642 628
	</extensions>
643 629
	<icon src="gvsig-logo-icon" text="gvSIG"/>

Also available in: Unified diff