Revision 33444

View differences:

tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
                      http://maven.apache.org/maven-v4_0_0.xsd">
6

  
7
	<modelVersion>4.0.0</modelVersion>
8
	<groupId>org.gvsig</groupId>
9
	<artifactId>org.gvsig.app.join</artifactId>
10
	<packaging>jar</packaging>
11
	<version>2.0-SNAPSHOT</version>
12
	<name>extDalTransformJoin</name>
13
	<url>http://maven.apache.org</url>
14
	<parent>
15
		<groupId>org.gvsig</groupId>
16
		<artifactId>gvsig-base-extension-pom</artifactId>
17
		<version>2.0-SNAPSHOT</version>
18
	</parent>	
19
	<distributionManagement>
20
		<site>
21
			<id>gvsig-repository</id>
22
			<url>${site-repository}/</url>
23
		</site>
24
	</distributionManagement>
25

  
26
	<dependencies>
27
		<dependency>
28
			<groupId>org.gvsig</groupId>
29
			<artifactId>org.gvsig.app.daltransform</artifactId>
30
			<version>2.0-SNAPSHOT</version>
31
		</dependency>	
32
		<dependency>
33
			<groupId>org.gvsig</groupId>
34
			<artifactId>org.gvsig.andami</artifactId>
35
			<version>2.0-SNAPSHOT</version>
36
		</dependency>
37
		<dependency>
38
			<groupId>org.gvsig</groupId>
39
			<artifactId>org.gvsig.app</artifactId>
40
			<version>2.0-SNAPSHOT</version>
41
		</dependency>		
42
		<dependency>
43
			<groupId>org.gvsig</groupId>
44
			<artifactId>org.gvsig.projection</artifactId>
45
			<version>2.0-SNAPSHOT</version>
46
		</dependency>
47
		<!--TEST-->
48
		<dependency>
49
			<groupId>org.gvsig</groupId>
50
			<artifactId>org.gvsig.app.daltransform</artifactId>
51
			<version>2.0-SNAPSHOT</version>
52
			<classifier>tests</classifier>
53
			<scope>test</scope>
54
		</dependency>
55
		<dependency>
56
			<groupId>org.gvsig</groupId>
57
			<artifactId>org.gvsig.fmap.dal</artifactId>
58
			<version>2.0-SNAPSHOT</version>
59
			<classifier>tests</classifier>
60
			<scope>test</scope>
61
		</dependency>
62
		<dependency>
63
			<groupId>org.gvsig</groupId>
64
			<artifactId>org.gvsig.tools.lib</artifactId>
65
			<classifier>tests</classifier>
66
			<scope>test</scope>
67
		</dependency>		
68
	</dependencies>
69
	<build>
70
		<sourceDirectory>src</sourceDirectory>
71
		<testSourceDirectory>src-test</testSourceDirectory>
72
		<resources>
73
			<resource>
74
				<directory>${basedir}/resources</directory>
75
			</resource>
76
		</resources>
77
		<plugins>			
78
			<plugin>
79
				<groupId>org.apache.maven.plugins</groupId>
80
				<artifactId>maven-jar-plugin</artifactId>
81
				<executions>
82
					<!--
83
						Generates a jar file only with the test classes
84
					-->
85
					<execution>
86
						<goals>
87
							<goal>test-jar</goal>
88
						</goals>
89
						<configuration>
90
							<includes>
91
								<include>**/**</include>												
92
							</includes>
93
							<excludes>
94
								<exclude>NONE</exclude>
95
							</excludes>
96
						</configuration>
97
					</execution>
98
				</executions>
99
			</plugin>
100
			<!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION -->
101
			<plugin>
102
				<groupId>org.apache.maven.plugins</groupId>
103
				<artifactId>maven-surefire-plugin</artifactId>
104
				<configuration>
105
					<skipTests>true</skipTests>
106
				</configuration>
107
			</plugin>
108
		</plugins>
109
	</build>	
110
	
111
	<properties>
112
		<build-dir>${basedir}/../build</build-dir>
113
	</properties>
114
</project>
0 115

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.app.join.JoinTransformLibrary
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/distribution/distribution.xml
1
<assembly>
2
  <id>distribution</id>
3
  <formats>
4
    <format>dir</format>
5
  </formats>
6
  <fileSets>
7
    <fileSet>
8
      <directory>config</directory>
9
	  <outputDirectory>${extension.install.dir.name}</outputDirectory>
10
    </fileSet>    
11
	<fileSet>
12
      <directory>images</directory>
13
	  <outputDirectory>/${extension.install.dir.name}/images</outputDirectory>
14
    </fileSet>
15
  </fileSets>
16
  <files>  
17
    <file>
18
      <source>build.number</source>
19
      <outputDirectory>${extension.install.dir.name}</outputDirectory>
20
    </file>
21
  </files>
22
  	<dependencySets>
23
  		<dependencySet>			
24
  			<outputDirectory>${extension.install.dir.name}/${library-dir}
25
        	</outputDirectory>
26
          	 <includes>
27
           		<include>org.gvsig:org.gvsig.app.join</include>        	 
28
        	</includes>
29
  		</dependencySet>  		
30
	</dependencySets>
31
</assembly>
32

  
0 33

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src-test/org/gvsig/app/join/dal/feature/JoinTransformTest.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 org.gvsig.app.join.dal.feature;
29

  
30
import java.io.File;
31
import java.net.URL;
32
import java.util.ArrayList;
33
import java.util.Iterator;
34

  
35
import org.gvsig.app.daltransform.BaseFeatureStoreTransform;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.exception.InitializeException;
39
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
40
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
42
import org.gvsig.fmap.dal.feature.FeatureStore;
43
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
44
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
45
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider;
46

  
47
/**
48
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
49
 */
50
public class JoinTransformTest extends BaseFeatureStoreTransform {
51
	private final File dbf = new File("src-test/org/gvsig/app/join/dal/feature/data/join.dbf");
52
	
53
	@Override
54
	public DataStoreParameters getDefaultDataStoreParameters()
55
			throws DataException {		
56
		DBFStoreParameters dbfParameters = null;
57
		dbfParameters = (DBFStoreParameters) dataManager
58
				.createStoreParameters(DBFStoreProvider.NAME);
59

  
60
		dbfParameters.setFile(dbf);
61

  
62
		return dbfParameters;
63
	}
64

  
65
	@Override
66
	public FeatureStoreTransform getFeatureStoreTransform()
67
			throws DataException, ValidateDataParametersException {
68
		URL url = JoinTransformTest.class.getResource("data/events.dbf");
69
		
70
		FeatureStore store = (FeatureStore) dataManager.createStore(this
71
				.getDefaultDataStoreParameters());
72
		
73
		FeatureStore store2 = (FeatureStore) dataManager.createStore(this
74
				.getDefaultDataStoreParameters2());		
75
		
76
		JoinTransform transform = new JoinTransform();
77
				
78
		ArrayList names = new ArrayList();
79
		Iterator iter = store2.getDefaultFeatureType().iterator();// <FeatureAttributeDescriptor>
80
		while (iter.hasNext()) {
81
			names.add(((FeatureAttributeDescriptor) iter.next()).getName());
82
		}
83
		
84
		transform.initialize(store, store2, 
85
				"NOMBRE", "NOMBRE", 
86
				null, null, 
87
				(String[]) names.toArray(new String[0]));
88
		return transform;
89
	}
90
	
91
	private DataStoreParameters getDefaultDataStoreParameters2() throws InitializeException, ProviderNotRegisteredException{
92
		DBFStoreParameters dbfParameters = null;
93
		dbfParameters = (DBFStoreParameters) dataManager
94
				.createStoreParameters(DBFStoreProvider.NAME);
95

  
96
		dbfParameters.setFile(dbf);
97

  
98
		return dbfParameters;
99
	}
100

  
101
}
102

  
0 103

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<libraries library-dir="lib"/>
4
	<depends plugin-name="org.gvsig.app"/>
5
	<depends plugin-name="org.gvsig.app.daltransform"/>
6
	<resourceBundle name="text"/>
7
	<extensions>
8
		<extension class-name="org.gvsig.app.join.RemoveTableUnion"
9
			description="Extensi?n encargada de quitar uniones de las tablas."
10
			active="true">
11
			<menu text="Tabla/quitar_uniones"/>
12
		</extension>
13
		<extension class-name="org.gvsig.app.join.JoinToolExtension"
14
			description="Extensi?n encargada de gestionar las operaciones sobre las tablas."
15
			active="true">
16
			<menu text="Tabla/join" icon="table-join" action-command="JOIN"/>
17
			<tool-bar name="Herramientas" position="12">
18
				<action-tool icon="table-join" action-command="JOIN" tooltip="join" position="1"/>
19
			</tool-bar>
20
		</extension>			
21
	</extensions>
22
	<icon src="gvsig-logo-icon" text="gvSIG"/>
23
</plugin-config>
0 24

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/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 jwizardcomponent.FinishAction;
13

  
14
import org.gvsig.andami.PluginServices;
15
import org.gvsig.andami.messages.NotificationManager;
16
import org.gvsig.app.gui.simpleWizard.SimpleWizard;
17
import org.gvsig.app.join.JoinToolExtension;
18
import org.gvsig.app.project.documents.table.TableDocument;
19
import org.gvsig.app.project.documents.table.FieldSelectionModel;
20
import org.gvsig.app.project.documents.table.gui.TableWizardStep;
21
import org.gvsig.fmap.dal.exception.DataException;
22
import org.gvsig.fmap.dal.exception.ReadException;
23
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
24
import org.gvsig.fmap.dal.feature.FeatureStore;
25

  
26

  
27
public class JoinWizardController {
28
	private final JoinToolExtension tableOperations;
29

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

  
37

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

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

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

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

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

  
71
		// create second step (target table)
72
		final TableWizardStep targTableWzrd = new TableWizardStep(wizard.getWizardComponents(), "Title" );
73
		targTableWzrd.getHeaderLbl().setText(PluginServices.getText(this,"Target_table_options"));
74
		targTableWzrd.getTableNameLbl().setText(PluginServices.getText(this,"Target_table_"));
75
		targTableWzrd.getFieldNameLbl().setText(PluginServices.getText(this,"Field_to_use_for_JOIN_"));
76
		targTableWzrd.getFieldPrefixLbl().setText(PluginServices.getText(this,"Field_prefix_"));
77
		targTableWzrd.getTableNameCmb().addItemListener(
78
			new ItemListener() {
79
				public void itemStateChanged(ItemEvent e) {
80
					if (e.getStateChange()==e.SELECTED) 
81
						setTrgtWzrdFieldType(srcTableWzrd, targTableWzrd);
82
				}
83
			}
84
		);
85
		srcTableWzrd.getFieldNameCmb().addItemListener(new ItemListener() {
86
			public void itemStateChanged(ItemEvent e) {
87
				if (e.getStateChange()==e.SELECTED)
88
					setTrgtWzrdFieldType(srcTableWzrd,targTableWzrd);
89
			}
90
		});
91
		for (int i=0; i<pts.length; i++) {
92
			targTableWzrd.getTableNameCmb().addItem(pts[i]);
93
		}
94

  
95
		// add steps and configure wizard
96
		wizard.getWizardComponents().addWizardPanel(srcTableWzrd);
97
		wizard.getWizardComponents().addWizardPanel(targTableWzrd);
98
		wizard.getWizardComponents().updateComponents();
99
		wizard.setSize(new Dimension(450, 230));
100
		wizard.getWizardComponents().setFinishAction(new FinishAction(wizard.getWizardComponents()) {
101
			public void performAction() {
102
				TableDocument sourceProjectTable = (TableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
103
				String field1 = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
104
				String prefix1 = srcTableWzrd.getFieldPrefixTxt().getText();
105
				if (sourceProjectTable==null || field1==null || prefix1 == null) {
106
					NotificationManager.showMessageError(
107
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
108
					return;
109
				}
110
				TableDocument targetProjectTable = (TableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
111
				String field2 = (String) targTableWzrd.getFieldNameCmb().getSelectedItem();
112
				String prefix2 = targTableWzrd.getFieldPrefixTxt().getText();
113
				if (targetProjectTable==null || field2==null || prefix2 == null) {
114
					NotificationManager.showMessageError(
115
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
116
					return;
117
				}
118
				tableOperations.execJoin(sourceProjectTable, field1, prefix1, targetProjectTable, field2, prefix2);
119

  
120
				PluginServices.getMDIManager().closeWindow(wizard);
121
			}
122
		}
123
		);
124

  
125
		// show the wizard
126
		PluginServices.getMDIManager().addWindow(wizard);
127
	}
128
	
129
	private void setTrgtWzrdFieldType(TableWizardStep srcTableWzrd,TableWizardStep targTableWzrd) {
130
		try {
131
			//tabla
132
			TableDocument sourcePt = (TableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
133
			TableDocument targetPt = (TableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
134
			targTableWzrd.getFieldPrefixTxt().setText(tableOperations.sanitizeFieldName(targetPt.getName()));
135

  
136
			//?ndice del campo
137
			FeatureStore sds = sourcePt.getStore();
138
			String fieldName = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
139
			FeatureAttributeDescriptor fad=sds.getDefaultFeatureType().getAttributeDescriptor(fieldName);
140
//			int fieldIndex = sds.getFieldIndexByName(fieldName);
141
//			if (fieldIndex!=-1) {
142
//				int type = sds.getFieldType(fieldIndex);
143
				targTableWzrd.setFieldModel(new FieldSelectionModel(
144
						targetPt.getStore(),
145
						PluginServices.getText(this, "seleccione_campo_enlace"),
146
						fad.getType()));
147
//			}
148
//			else {
149
//				NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields")
150
//						, new Exception());
151
//			}
152
		} catch (ReadException e2) {
153
			NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"),
154
					e2);
155
		} catch (DataException e2) {
156
			NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"),
157
					e2);
158
		}
159
	}
160

  
161
	private class InvalidParameterException extends Exception {
162
	}
163
}
0 164

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/daltransform/SelectSecondDataStoreWizardPanel.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 org.gvsig.app.join.daltransform;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.app.daltransform.gui.impl.SelectDataStoreWizardPanel;
32
import org.gvsig.fmap.dal.exception.DataException;
33

  
34

  
35
/**
36
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
37
 */
38
public class SelectSecondDataStoreWizardPanel extends SelectDataStoreWizardPanel{
39
	private SelectParametersWizardPanel selectParametersWizardPanel = null;
40
	
41
	/**
42
	 * @param featureTransformWizardModel
43
	 */
44
	public SelectSecondDataStoreWizardPanel(SelectParametersWizardPanel selectParametersWizardPanel) {
45
		super();	
46
		this.selectParametersWizardPanel = selectParametersWizardPanel;
47
	}
48

  
49
	/* (non-Javadoc)
50
	 * @see org.gvsig.app.daltransform.gui.SelectDataStoreWizard#getPanelTitle()
51
	 */	
52
	public String getPanelTitle() {
53
		return PluginServices.getText(this, "transform_second_datastore_selection");
54
	}
55

  
56
	/* (non-Javadoc)
57
	 * @see jwizardcomponent.JWizardPanel#next()
58
	 */	
59
	public void nextPanel() {
60
		try {
61
			selectParametersWizardPanel.updateFeatureStores(getSelectedFeatureStore());
62
		} catch (DataException e) {
63
			logger.error("Error updating the params panel", e);
64
		}
65
				
66
	}
67

  
68
	/* (non-Javadoc)
69
	 * @see org.gvsig.app.daltransform.gui.SelectDataStoreWizard#update()
70
	 */
71
	public void updatePanel() {
72
		removeFeatureStore(getDataTransformWizard().getFeatureStore());
73
		super.updatePanel();
74
	}
75
	
76
	
77
}
78

  
0 79

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/daltransform/SelectParametersWizardPanel.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 org.gvsig.app.join.daltransform;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.app.daltransform.gui.DataTransformWizardPanel;
32
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeAttributesCombo;
33
import org.gvsig.app.daltransform.gui.components.impl.FeatureTypeAttributesList;
34
import org.gvsig.app.daltransform.gui.impl.AbstractDataTransformWizardPanel;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37

  
38

  
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class SelectParametersWizardPanel extends AbstractDataTransformWizardPanel implements DataTransformWizardPanel{
43
	private javax.swing.JLabel attributesLabel;
44
	private FeatureTypeAttributesList attributesList;
45
	private javax.swing.JScrollPane attributesScroll;
46
	private FeatureTypeAttributesCombo key1Combo;
47
	private javax.swing.JLabel key1Label;
48
	private FeatureTypeAttributesCombo key2Combo;
49
	private javax.swing.JLabel key2Label;
50
	private javax.swing.JLabel prefix1Label;
51
	private javax.swing.JTextField prefix1Text;
52
	private javax.swing.JLabel prefix2Label;
53
	private javax.swing.JTextField prefix2Text; 
54

  
55
	/**
56
	 * @param featureTransformWizardModel
57
	 */
58
	public SelectParametersWizardPanel() {
59
		super();	
60
		initComponents();
61
		initLabels();
62
	}
63
	
64
	private void initLabels(){
65
		key1Label.setText(PluginServices.getText(this,"join_first_key"));
66
		key2Label.setText(PluginServices.getText(this,"join_second_key"));
67
		prefix1Label.setText(PluginServices.getText(this,"join_first_prefix"));
68
		prefix2Label.setText(PluginServices.getText(this,"join_second_prefix"));
69
		attributesLabel.setText(PluginServices.getText(this,"join_select_attributes"));
70
	}
71

  
72
	private void initComponents() {
73
		java.awt.GridBagConstraints gridBagConstraints;
74

  
75
		prefix2Text = new javax.swing.JTextField();
76
		key2Combo = new FeatureTypeAttributesCombo();
77
		prefix1Text = new javax.swing.JTextField();
78
		key1Label = new javax.swing.JLabel();
79
		key1Combo = new FeatureTypeAttributesCombo();
80
		key2Label = new javax.swing.JLabel();
81
		prefix1Label = new javax.swing.JLabel();
82
		prefix2Label = new javax.swing.JLabel();
83
		attributesLabel = new javax.swing.JLabel();
84
		attributesScroll = new javax.swing.JScrollPane();
85
		attributesList = new FeatureTypeAttributesList();
86

  
87
		setLayout(new java.awt.GridBagLayout());
88
		gridBagConstraints = new java.awt.GridBagConstraints();
89
		gridBagConstraints.gridx = 0;
90
		gridBagConstraints.gridy = 7;
91
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
92
		gridBagConstraints.weightx = 1.0;
93
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
94
		add(prefix2Text, gridBagConstraints);
95

  
96
		gridBagConstraints = new java.awt.GridBagConstraints();
97
		gridBagConstraints.gridx = 0;
98
		gridBagConstraints.gridy = 3;
99
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100
		gridBagConstraints.weightx = 1.0;
101
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
102
		add(key2Combo, gridBagConstraints);
103
		gridBagConstraints = new java.awt.GridBagConstraints();
104
		gridBagConstraints.gridx = 0;
105
		gridBagConstraints.gridy = 5;
106
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
107
		gridBagConstraints.weightx = 1.0;
108
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
109
		add(prefix1Text, gridBagConstraints);
110

  
111
		key1Label.setText("jLabel1");
112
		gridBagConstraints = new java.awt.GridBagConstraints();
113
		gridBagConstraints.gridx = 0;
114
		gridBagConstraints.gridy = 0;
115
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
117
		add(key1Label, gridBagConstraints);
118

  
119
		gridBagConstraints = new java.awt.GridBagConstraints();
120
		gridBagConstraints.gridx = 0;
121
		gridBagConstraints.gridy = 1;
122
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
123
		gridBagConstraints.weightx = 1.0;
124
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
125
		add(key1Combo, gridBagConstraints);
126

  
127
		key2Label.setText("jLabel2");
128
		gridBagConstraints = new java.awt.GridBagConstraints();
129
		gridBagConstraints.gridx = 0;
130
		gridBagConstraints.gridy = 2;
131
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
133
		add(key2Label, gridBagConstraints);
134

  
135
		prefix1Label.setText("jLabel1");
136
		gridBagConstraints = new java.awt.GridBagConstraints();
137
		gridBagConstraints.gridx = 0;
138
		gridBagConstraints.gridy = 4;
139
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
141
		add(prefix1Label, gridBagConstraints);
142

  
143
		prefix2Label.setText("jLabel2");
144
		gridBagConstraints = new java.awt.GridBagConstraints();
145
		gridBagConstraints.gridx = 0;
146
		gridBagConstraints.gridy = 6;
147
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
149
		add(prefix2Label, gridBagConstraints);
150

  
151
		attributesLabel.setText("attributesLabel");
152
		gridBagConstraints = new java.awt.GridBagConstraints();
153
		gridBagConstraints.gridx = 0;
154
		gridBagConstraints.gridy = 8;
155
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
157
		add(attributesLabel, gridBagConstraints);
158

  
159
		attributesScroll.setViewportView(attributesList);
160

  
161
		gridBagConstraints = new java.awt.GridBagConstraints();
162
		gridBagConstraints.gridx = 0;
163
		gridBagConstraints.gridy = 9;
164
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165
		gridBagConstraints.weightx = 1.0;
166
		gridBagConstraints.weighty = 1.0;
167
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
168
		add(attributesScroll, gridBagConstraints);
169
	}
170

  
171
	/**
172
	 * @return
173
	 */
174
	public String getKeyAttr1() {
175
		return key1Combo.getSelectedFeatureAttributeDescriptor().getName();
176
	}
177

  
178
	/**
179
	 * @return
180
	 */
181
	public String getkeyAtrr2() {
182
		return key2Combo.getSelectedFeatureAttributeDescriptor().getName();
183
	}
184

  
185
	/**
186
	 * @return
187
	 */
188
	public String getPrefix1() {
189
		return prefix1Text.getText();
190
	}
191

  
192
	/**
193
	 * @return
194
	 */
195
	public String getPrefix2() {
196
		return prefix2Text.getText();
197
	}
198

  
199
	/**
200
	 * @return
201
	 */
202
	public String[] getAttributes() {
203
		return attributesList.getAttributesName();
204
	}
205
	
206
	/**
207
	 * @param selectedFeatureStore
208
	 * @throws DataException 
209
	 */
210
	public void updateFeatureStores(FeatureStore selectedFeatureStore) throws DataException {
211
		key1Combo.addFeatureAttributes(getFeatureStore().getDefaultFeatureType());
212
		key2Combo.addFeatureAttributes(selectedFeatureStore.getDefaultFeatureType());
213
		attributesList.addFeatureAttributes(selectedFeatureStore.getDefaultFeatureType());
214
	}
215
}
216

  
0 217

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/daltransform/JoinTransformGui.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 org.gvsig.app.join.daltransform;
29

  
30
import java.awt.Dimension;
31
import java.util.ArrayList;
32
import java.util.List;
33

  
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.app.daltransform.gui.DataTransformGui;
36
import org.gvsig.app.daltransform.gui.DataTransformWizardPanel;
37
import org.gvsig.app.join.dal.feature.JoinTransform;
38
import org.gvsig.fmap.dal.exception.DataException;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
41

  
42

  
43
/**
44
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
45
 */
46
public class JoinTransformGui implements DataTransformGui {
47
	private SelectSecondDataStoreWizardPanel secondDataStoreWizard = null;
48
	private SelectParametersWizardPanel parametersWizard = null;
49
	private List<DataTransformWizardPanel> panels = null;	
50
	
51
	public JoinTransformGui() {
52
		super();			
53
	}
54
	
55
	/* (non-Javadoc)
56
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#createFeatureStoreTransform(org.gvsig.fmap.dal.feature.FeatureStore)
57
	 */
58
	public FeatureStoreTransform createFeatureStoreTransform(
59
			FeatureStore featureStore) throws DataException {
60
		JoinTransform transform = new JoinTransform();
61
		transform.initialize(featureStore,
62
				secondDataStoreWizard.getSelectedFeatureStore(),
63
				parametersWizard.getKeyAttr1(),
64
				parametersWizard.getkeyAtrr2(),
65
				parametersWizard.getPrefix1(),
66
				parametersWizard.getPrefix2(),
67
				parametersWizard.getAttributes()
68
		);
69
		return transform;
70
	}
71

  
72
	/* (non-Javadoc)
73
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#getDescription()
74
	 */
75
	public String getDescription() {
76
		return PluginServices.getText(this, "join_description");
77
	}
78

  
79
	/* (non-Javadoc)
80
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#createPanels(org.gvsig.app.daltransform.gui.FeatureTransformWizardModel)
81
	 */
82
	public List<DataTransformWizardPanel> createPanels() {
83
		if (panels == null){
84
			parametersWizard = new SelectParametersWizardPanel();
85
			secondDataStoreWizard = new SelectSecondDataStoreWizardPanel(parametersWizard);
86
			panels = new ArrayList<DataTransformWizardPanel>();
87
			panels.add(secondDataStoreWizard);
88
			panels.add(parametersWizard);				
89
		}	
90
		return panels;		
91
	}
92

  
93
	/* (non-Javadoc)
94
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#getName()
95
	 */
96
	public String getName() {
97
		return PluginServices.getText(this, "join_name");
98
	}
99

  
100
	/* (non-Javadoc)
101
	 * @see org.gvsig.app.daltransform.gui.DataTransformGui#getMinDimension()
102
	 */
103
	public Dimension getMinDimension() {
104
		// TODO Auto-generated method stub
105
		return null;
106
	}
107

  
108
}
109

  
0 110

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/RemoveTableUnion.java
1
package org.gvsig.app.join;
2

  
3
import org.gvsig.andami.PluginServices;
4
import org.gvsig.andami.plugins.Extension;
5
import org.gvsig.andami.ui.mdiManager.IWindow;
6
import org.gvsig.app.join.dal.feature.JoinTransform;
7
import org.gvsig.app.project.documents.table.TableDocument;
8
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
11
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
12

  
13

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

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

  
25
	}
26

  
27
	/**
28
	 * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
29
	 */
30
	public void execute(String actionCommand) {
31
		FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) PluginServices.getMDIManager().getActiveWindow();
32
		TableDocument 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 org.gvsig.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
			TableDocument 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 org.gvsig.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
}
0 140

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/JoinTransformLibrary.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 org.gvsig.app.join;
29

  
30
import org.gvsig.app.daltransform.DataTransformLocator;
31
import org.gvsig.app.daltransform.DataTransformManager;
32
import org.gvsig.app.join.dal.feature.JoinTransform;
33
import org.gvsig.app.join.daltransform.JoinTransformGui;
34
import org.gvsig.fmap.dal.impl.DALDefaultImplLibrary;
35
import org.gvsig.tools.library.AbstractLibrary;
36
import org.gvsig.tools.library.LibraryException;
37
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
38

  
39
/**
40
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
41
 */
42
public class JoinTransformLibrary extends AbstractLibrary {
43

  
44
	@Override
45
	protected void doInitialize() throws LibraryException {
46
		// TODO Auto-generated method stub
47
		
48
	}
49

  
50
	@Override
51
	protected void doPostInitialize() throws LibraryException {
52
		new DALDefaultImplLibrary().postInitialize();
53
		
54
		// Validate there is any implementation registered.
55
		DataTransformManager dataTransformManager = DataTransformLocator.getDataTransformManager();
56
		if (dataTransformManager == null) {
57
			throw new ReferenceNotRegisteredException(
58
					DataTransformLocator.DATA_TRANSFORM_MANAGER_NAME, DataTransformLocator.getInstance());
59
		}	
60
		dataTransformManager.registerDataTransform("join", JoinTransformGui.class);		
61
		
62
		JoinTransform.registerPersistent();
63
	}
64

  
65
}
66

  
0 67

  
tags/v2_0_0_Build_2011/extensions/extDalTransformJoin/src/org/gvsig/app/join/dal/feature/JoinTransform.java
1
package org.gvsig.app.join.dal.feature;
2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.HashMap;
6
import java.util.Iterator;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Map.Entry;
10

  
11
import org.gvsig.fmap.dal.exception.DataException;
12
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform;
13
import org.gvsig.fmap.dal.feature.EditableFeature;
14
import org.gvsig.fmap.dal.feature.EditableFeatureType;
15
import org.gvsig.fmap.dal.feature.Feature;
16
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
17
import org.gvsig.fmap.dal.feature.FeatureQuery;
18
import org.gvsig.fmap.dal.feature.FeatureSet;
19
import org.gvsig.fmap.dal.feature.FeatureStore;
20
import org.gvsig.fmap.dal.feature.FeatureType;
21
import org.gvsig.tools.ToolsLocator;
22
import org.gvsig.tools.dispose.DisposableIterator;
23
import org.gvsig.tools.dynobject.DynStruct;
24
import org.gvsig.tools.evaluator.Evaluator;
25
import org.gvsig.tools.evaluator.EvaluatorData;
26
import org.gvsig.tools.evaluator.EvaluatorException;
27
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
28
import org.gvsig.tools.persistence.PersistenceManager;
29
import org.gvsig.tools.persistence.PersistentState;
30
import org.gvsig.tools.persistence.exception.PersistenceException;
31

  
32
public class JoinTransform extends AbstractFeatureStoreTransform {
33

  
34
	/**
35
	 * Store from which the join transform will get the additional attributes
36
	 */
37
	private FeatureStore store2;
38

  
39
	/**
40
	 * name of the key attr in store1 that will be used to match features in
41
	 * store2
42
	 */
43
	private String keyAttr1;
44

  
45
	/**
46
	 * name of the key attr in store2 that will be used to match features in
47
	 * store1
48
	 */
49
	private String keyAttr2;
50

  
51
	/**
52
	 * names of the attributes to join from store2 to store1
53
	 */
54
	private String[] attrs;
55

  
56
	/**
57
	 * Attribute names may change after transformation if they are repeated in
58
	 * both stores. This map keeps correspondence between store2 original names
59
	 * and their transformed counterparts.
60
	 */
61
	private Map<String,String> targetNamesMap;
62

  
63
	private JoinTransformEvaluator evaluator = null;
64

  
65
	private FeatureType originalFeatureType;
66

  
67
	private String[] attrsForQuery;
68

  
69
	private String prefix1;
70

  
71
	private String prefix2;
72

  
73
	/**
74
	 * A default constructor
75
	 */
76
	public JoinTransform() {
77
		targetNamesMap = new HashMap<String,String>();
78
	}
79

  
80
	/**
81
	 * Initializes all the necessary data for this transform
82
	 *
83
	 * @param store1
84
	 *            store whose default feature type is the target of this
85
	 *            transform
86
	 *
87
	 * @param store2
88
	 *            store whose default feature type will provide the new
89
	 *            attributes to join
90
	 *
91
	 * @param keyAttr1
92
	 *            key attribute in store1 that matches keyAttr2 in store2
93
	 *            (foreign key), used for joining both stores.
94
	 *
95
	 * @param keyAttr2
96
	 *            key attribute in store2 that matches keyAttr1 in store2
97
	 *            (foreign key), used for joining both stores.
98
	 *
99
	 * @param attrs
100
	 *            names of the attributes in store2 that will be joined to
101
	 *            store1.
102
	 */
103
	public void initialize(FeatureStore store1, FeatureStore store2,
104
			String keyAttr1, String keyAttr2, String prefix1, String prefix2,
105
			String[] attrs)
106
	throws DataException {
107

  
108
		if (store1 == store2) {
109
			throw new IllegalArgumentException("store1 == store2");
110
		}
111

  
112
		// Initialize needed data
113
		this.setFeatureStore(store1);
114
		this.store2 = store2;
115
		this.keyAttr1 = keyAttr1;
116
		this.keyAttr2 = keyAttr2;
117
		this.prefix1 = prefix1; // TODO
118
		this.prefix2 = prefix2; // TODO
119
		this.attrs = attrs;
120

  
121
		// calculate this transform resulting feature type
122
		// by adding all specified attrs from store2 to store1's default
123
		// feature type
124
		// FIXME for more than one FTypes ??
125
		this.originalFeatureType = this.getFeatureStore()
126
		.getDefaultFeatureType();
127

  
128
		// TODO tener en cuenta prefix1
129
		EditableFeatureType type = this.getFeatureStore().getDefaultFeatureType().getEditable();
130

  
131
		FeatureType type2 = store2.getDefaultFeatureType();
132

  
133
		// TODO tener en cuenta prefix2
134
		for (int i = 0; i < attrs.length; i++) {
135
			String name = attrs[i];
136

  
137
			// If an attribute already exists with the same name in store1's
138
			// default feature type,
139
			// calculate an alternate name and add it to our type
140
			int j = 0;
141
			while (type.getIndex(name) >= 0) {
142
				name = attrs[i] + "_" + ++j;
143
			}
144
			type.add(name,
145
					type2.getAttributeDescriptor(attrs[i]).getType());
146

  
147
			// keep correspondence between original name and transformed name
148
			this.targetNamesMap.put(attrs[i], name);
149
		}
150
		if (this.targetNamesMap.containsKey(keyAttr2)) {
151
			this.attrsForQuery = this.attrs;
152
		} else {
153
			List<String> list = new ArrayList<String>(this.attrs.length + 1);
154
			list.addAll(Arrays.asList(this.attrs));
155
			list.add(keyAttr2);
156
			this.attrsForQuery = (String[]) list.toArray(new String[] {});
157
		}
158

  
159
		// assign calculated feature type as this transform's feature type
160
		FeatureType[] types = new FeatureType[] { type.getNotEditableCopy() };
161
		setFeatureTypes(Arrays.asList(types), types[0]);
162
	}
163

  
164
	/**
165
	 *
166
	 *
167
	 * @param source
168
	 *
169
	 * @param target
170
	 *
171
	 * @throws DataException
172
	 */
173
	public void applyTransform(Feature source, EditableFeature target)
174
	throws DataException {
175

  
176
		// copy the data from store1 into the resulting feature
177
		this.copySourceToTarget(source, target);
178

  
179
		// ask store2 for the specified attributes, filtering by the key
180
		// attribute value
181
		// from the source feature
182
		JoinTransformEvaluator eval = this.getEvaluator();
183
		eval.updateValue(source.get(this.keyAttr1));
184

  
185
		FeatureQuery query = store2.createFeatureQuery();
186
		query.setAttributeNames(attrsForQuery);
187
		query.setFilter(eval);
188
		FeatureSet set = null;
189
		DisposableIterator itFeat = null;
190

  
191
		try {
192

  
193
			set = store2.getFeatureSet(query);
194
			// In this join implementation, we will take only the first matching
195
			// feature found in store2
196

  
197
			Feature feat;
198

  
199

  
200
			itFeat = set.iterator();
201
			if (itFeat.hasNext()) {
202
				feat = (Feature) itFeat.next();
203

  
204
				// copy all attributes from joined feature to target
205
				this.copyJoinToTarget(feat, target);
206
			}
207
		} finally {
208
			if (itFeat != null) {
209
				itFeat.dispose();
210
			}
211
			if (set != null) {
212
				set.dispose();
213
			}
214
		}
215
	}
216

  
217
	/**
218
	 * @param feat
219
	 * @param target
220
	 */
221
	private void copyJoinToTarget(Feature join, EditableFeature target) {
222
		Iterator<Entry<String, String>> iter = targetNamesMap.entrySet()
223
		.iterator();
224
		Entry<String, String> entry;
225
		FeatureType trgType = target.getType();
226
		FeatureAttributeDescriptor attr;
227
		while (iter.hasNext()) {
228
			entry = iter.next();
229
			attr = trgType.getAttributeDescriptor((String) entry.getValue());
230
			if (attr != null) {
231
				target.set(attr.getIndex(), join.get((String) entry.getKey()));
232
			}
233
		}
234

  
235

  
236
	}
237

  
238
	/**
239
	 * @param source
240
	 * @param target
241
	 */
242
	private void copySourceToTarget(Feature source, EditableFeature target) {
243
		FeatureAttributeDescriptor attr, attrTrg;
244
		FeatureType ftSrc = source.getType();
245
		FeatureType ftTrg = target.getType();
246

  
247

  
248
		for (int i = 0; i < source.getType().size(); i++) {
249
			attr = ftSrc.getAttributeDescriptor(i);
250
			attrTrg = ftTrg.getAttributeDescriptor(attr.getName());
251
			if (attrTrg != null) {
252
				try {
253
					target.set(attrTrg.getIndex(), source.get(i));
254
				} catch (IllegalArgumentException e) {
255
					attrTrg = ftTrg.getAttributeDescriptor(attr.getName());
256
					target.set(attrTrg.getIndex(), attrTrg.getDefaultValue());
257
				}
258

  
259
			}
260
		}
261

  
262
	}
263

  
264
	private JoinTransformEvaluator getEvaluator() {
265
		if (this.evaluator == null){
266
			this.evaluator = new JoinTransformEvaluator(keyAttr2);
267
		}
268
		return evaluator;
269

  
270
	}
271

  
272
	private class JoinTransformEvaluator implements Evaluator {
273

  
274
		private String attribute;
275
		private Object value;
276
		private String sql;
277
		private EvaluatorFieldsInfo info = null;
278

  
279
		//		private int attributeIndex;
280

  
281
		public JoinTransformEvaluator(String attribute) {
282
			this.attribute = attribute;
283
			this.value = null;
284
			this.info = new EvaluatorFieldsInfo();
285

  
286
			//			this.attributeIndex = attrIndex;
287
		}
288

  
289
		public void updateValue(Object value) {
290
			this.value = value;
291
			this.sql = this.attribute + "= '" + this.value + "'";
292
			this.info = new EvaluatorFieldsInfo();
293
			this.info.addMatchFieldValue(this.attribute, value);
294
		}
295

  
296
		public Object evaluate(EvaluatorData arg0) throws EvaluatorException {
297
			Object curValue = arg0.getDataValue(attribute);
298
			if (curValue == null) {
299
				return value == null;
300
			}
301
			return curValue.equals(value);
302
		}
303

  
304
		public String getSQL() {
305
			return this.sql;
306
		}
307

  
308
		public String getDescription() {
309
			return "Evaluates join transform match";
310
		}
311

  
312
		public String getName() {
313
			return "JoinTransformEvaluator";
314
		}
315

  
316
		public EvaluatorFieldsInfo getFieldsInfo() {
317
			return this.info;
318
		}
319

  
320
	}	
321

  
322
	@SuppressWarnings("unchecked")
323
	public FeatureType getSourceFeatureTypeFrom(FeatureType arg0) {
324
		EditableFeatureType orgType = originalFeatureType.getEditable();
325
		
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff