Revision 41773

View differences:

tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/test/java/org/gvsig/app/join/dal/feature/JoinTransformTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

  
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 {Iver T.I.}   {Task}
49
*/
50
 
51
package org.gvsig.app.join.dal.feature;
52

  
53
import java.io.File;
54
import java.net.URL;
55
import java.util.ArrayList;
56
import java.util.Iterator;
57

  
58
import org.gvsig.daltransform.BaseFeatureStoreTransform;
59
import org.gvsig.fmap.dal.DataStoreParameters;
60
import org.gvsig.fmap.dal.exception.DataException;
61
import org.gvsig.fmap.dal.exception.InitializeException;
62
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
63
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
64
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
65
import org.gvsig.fmap.dal.feature.FeatureStore;
66
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
67

  
68
/**
69
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
70
 */
71
public class JoinTransformTest extends BaseFeatureStoreTransform {
72
	private final File dbf = new File("src-test/org/gvsig/app/join/dal/feature/data/join.dbf");
73
	
74
	@Override
75
	public DataStoreParameters getDefaultDataStoreParameters()
76
			throws DataException {		
77
	    DataStoreParameters dbfParameters = null;
78
        dbfParameters = dataManager.createStoreParameters("DBFStoreParameters");
79

  
80
        dbfParameters.setDynValue("dbfFile", dbf);
81

  
82
		return dbfParameters;
83
	}
84

  
85
	@Override
86
	public FeatureStoreTransform getFeatureStoreTransform()
87
			throws DataException, ValidateDataParametersException {
88
		URL url = JoinTransformTest.class.getResource("data/events.dbf");
89
		
90
		FeatureStore store = (FeatureStore) dataManager.createStore(this
91
				.getDefaultDataStoreParameters());
92
		
93
		FeatureStore store2 = (FeatureStore) dataManager.createStore(this
94
				.getDefaultDataStoreParameters2());		
95
		
96
		JoinTransform transform = new JoinTransform();
97
				
98
		ArrayList names = new ArrayList();
99
		Iterator iter = store2.getDefaultFeatureType().iterator();// <FeatureAttributeDescriptor>
100
		while (iter.hasNext()) {
101
			names.add(((FeatureAttributeDescriptor) iter.next()).getName());
102
		}
103
		
104
		transform.initialize(store, store2, 
105
				"NOMBRE", "NOMBRE", 
106
				null, null, 
107
				(String[]) names.toArray(new String[0]));
108
		return transform;
109
	}
110
	
111
	private DataStoreParameters getDefaultDataStoreParameters2() throws InitializeException, ProviderNotRegisteredException{
112
		DataStoreParameters dbfParameters = dataManager.createStoreParameters("DBFStoreParameters");
113
		dbfParameters.setDynValue("dbfFile",dbf);
114
		return dbfParameters;
115
	}
116

  
117
}
118

  
0 119

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/JoinToolExtension.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

  
29
package org.gvsig.app.join;
30

  
31
import java.awt.Component;
32

  
33
import javax.swing.JOptionPane;
34

  
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.andami.PluginServices;
37
import org.gvsig.andami.ui.mdiManager.IWindow;
38
import org.gvsig.app.extension.TableOperations;
39
import org.gvsig.app.join.daltransform.JoinTransformGui;
40
import org.gvsig.daltransform.DataTransformLocator;
41
import org.gvsig.daltransform.swing.DataTransformWizard;
42

  
43

  
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class JoinToolExtension extends TableOperations {
48

  
49
	public void initialize() {
50
		IconThemeHelper.registerIcon("action", "table-create-join", this);
51
	}
52
	
53
	/**
54
	 * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
55
	 */
56
	public void execute(String actionCommand) {
57
		if( "table-create-join".equalsIgnoreCase(actionCommand)) {
58
		    try {
59
		        DataTransformWizard dataTransformWizard = DataTransformLocator.getDataTransformManager().createWizard();
60
	            dataTransformWizard.setDataTransformGui(new JoinTransformGui());
61
		        PluginServices.getMDIManager().addWindow(dataTransformWizard.getWindow());
62
	        } catch (Exception e) {
63
	            
64
	            IWindow iw = PluginServices.getMDIManager().getActiveWindow();
65
	            JOptionPane.showInternalMessageDialog(
66
	                iw instanceof Component ? (Component) iw : null,
67
	                    PluginServices.getText(this, "transform_create_wizard_exception"),
68
	                    PluginServices.getText(this, "feature_transform"),
69
	                    JOptionPane.ERROR_MESSAGE);
70
	        }
71
		}
72
	}		
73
	
74
}
0 75

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/daltransform/JoinTransformGui.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

  
29
package org.gvsig.app.join.daltransform;
30

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

  
35
import javax.swing.JOptionPane;
36

  
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.ui.mdiManager.IWindow;
42
import org.gvsig.app.ApplicationLocator;
43
import org.gvsig.app.join.dal.feature.JoinTransform;
44
import org.gvsig.daltransform.swing.DataTransformGui;
45
import org.gvsig.daltransform.swing.DataTransformWizardPanel;
46
import org.gvsig.fmap.dal.exception.DataException;
47
import org.gvsig.fmap.dal.feature.FeatureStore;
48
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
49
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTypesTablePanel;
50
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel;
51
import org.gvsig.i18n.Messages;
52

  
53

  
54
/**
55
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
56
 */
57
public class JoinTransformGui implements DataTransformGui {
58
    
59
    private static Logger logger = LoggerFactory.getLogger(JoinTransformGui.class);
60
    
61
	private SelectSecondDataStoreWizardPanel secondDataStoreWizard = null;
62
	private SelectParametersWizardPanel parametersWizard = null;
63
	private List<DataTransformWizardPanel> panels = null;	
64
	
65
	public JoinTransformGui() {
66
		super();			
67
	}
68
	
69
	/* (non-Javadoc)
70
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#createFeatureStoreTransform(org.gvsig.fmap.dal.feature.FeatureStore)
71
	 */
72
	public FeatureStoreTransform createFeatureStoreTransform(
73
			FeatureStore featureStore) throws DataException {
74
		JoinTransform transform = new JoinTransform();
75
		transform.initialize(featureStore,
76
				secondDataStoreWizard.getSelectedFeatureStore(),
77
				parametersWizard.getKeyAttr1(),
78
				parametersWizard.getkeyAtrr2(),
79
				parametersWizard.getPrefix1(),
80
				parametersWizard.getPrefix2(),
81
				parametersWizard.getAttributes()
82
		);
83
		return transform;
84
	}
85

  
86

  
87

  
88
    /* (non-Javadoc)
89
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#getDescription()
90
	 */
91
	public String getDescription() {
92
		return PluginServices.getText(this, "join_description");
93
	}
94

  
95
	/* (non-Javadoc)
96
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#createPanels(org.gvsig.app.daltransform.gui.FeatureTransformWizardModel)
97
	 */
98
	public List<DataTransformWizardPanel> createPanels() {
99
		if (panels == null){
100
			parametersWizard = new SelectParametersWizardPanel();
101
			secondDataStoreWizard = new SelectSecondDataStoreWizardPanel(parametersWizard);
102
			panels = new ArrayList<DataTransformWizardPanel>();
103
			panels.add(secondDataStoreWizard);
104
			panels.add(parametersWizard);				
105
		}	
106
		return panels;		
107
	}
108

  
109
	/* (non-Javadoc)
110
	 * @see org.gvsig.app.daltransform.gui.FeatureTransformGui#getName()
111
	 */
112
	public String getName() {
113
		return PluginServices.getText(this, "join_name");
114
	}
115

  
116
	/* (non-Javadoc)
117
	 * @see org.gvsig.app.daltransform.gui.DataTransformGui#getMinDimension()
118
	 */
119
	public Dimension getMinDimension() {
120
		// TODO Auto-generated method stub
121
		return null;
122
	}
123

  
124
    public boolean accept(FeatureStore featureStore) {        
125
        return true;
126
    }
127

  
128
   
129
    
130
    public String toString() {
131
        return getName();
132
    }
133
}
134

  
0 135

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/daltransform/SelectSecondDataStoreWizardPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

  
29
package org.gvsig.app.join.daltransform;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.daltransform.swing.impl.SelectDataStoreWizardPanel;
33
import org.gvsig.fmap.dal.exception.DataException;
34

  
35

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

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

  
57
	/* (non-Javadoc)
58
	 * @see jwizardcomponent.JWizardPanel#next()
59
	 */	
60
	public void nextPanel() {
61
        selectParametersWizardPanel.setSecondFeatureStore(getSelectedFeatureStore());
62
	}
63

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

  
0 75

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/daltransform/SelectParametersWizardPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {Iver T.I.}   {Task}
27
 */
28

  
29
package org.gvsig.app.join.daltransform;
30

  
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.util.ArrayList;
34

  
35
import javax.swing.JOptionPane;
36

  
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.app.ApplicationLocator;
42
import org.gvsig.app.join.utils.TransformUtils;
43
import org.gvsig.daltransform.swing.DataTransformWizardPanel;
44
import org.gvsig.daltransform.swing.impl.AbstractDataTransformWizardPanel;
45
import org.gvsig.daltransform.swing.impl.components.FeatureTypeAttributesCombo;
46
import org.gvsig.daltransform.swing.impl.components.FeatureTypeAttributesList;
47
import org.gvsig.fmap.dal.exception.DataException;
48
import org.gvsig.fmap.dal.exception.ParameterMissingException;
49
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
50
import org.gvsig.fmap.dal.feature.FeatureStore;
51
import org.gvsig.fmap.dal.feature.FeatureType;
52
import org.gvsig.i18n.Messages;
53

  
54

  
55
/**
56
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
57
 */
58
public class SelectParametersWizardPanel extends AbstractDataTransformWizardPanel
59
implements DataTransformWizardPanel, ActionListener{
60
    
61
    private static Logger logger =
62
        LoggerFactory.getLogger(SelectParametersWizardPanel.class);
63
    
64
	private javax.swing.JLabel attributesLabel;
65
	private FeatureTypeAttributesList attributesList;
66
	private javax.swing.JScrollPane attributesScroll;
67
	private FeatureTypeAttributesCombo key1Combo;
68
	private javax.swing.JLabel key1Label;
69
	private FeatureTypeAttributesCombo key2_Combo;
70
	private javax.swing.JLabel key2Label;
71
	private javax.swing.JLabel prefix1Label;
72
	private javax.swing.JTextField prefix1Text;
73
	private javax.swing.JLabel prefix2Label;
74
	private javax.swing.JTextField prefix2Text; 
75
	
76
	private FeatureStore secondFeatStore = null;
77

  
78
	/**
79
	 * @param featureTransformWizardModel
80
	 */
81
	public SelectParametersWizardPanel() {
82
		super();	
83
	}
84
	
85
	   
86
	public void updatePanel() {
87
        initComponents();
88
        initLabels();
89
        try {
90
            updateFeatureStores();
91
        } catch (DataException e) {
92
            logger.error("While updating feature stores", e);
93
        }
94
	}
95
	
96
	private void initLabels(){
97
		key1Label.setText(PluginServices.getText(this,"join_first_key"));
98
		key2Label.setText(PluginServices.getText(this,"join_second_key"));
99
		prefix1Label.setText(PluginServices.getText(this,"join_first_prefix"));
100
		prefix2Label.setText(PluginServices.getText(this,"join_second_prefix"));
101
		attributesLabel.setText(PluginServices.getText(this,"join_select_attributes"));
102
	}
103

  
104
	private void initComponents() {
105
		java.awt.GridBagConstraints gridBagConstraints;
106

  
107
		prefix2Text = new javax.swing.JTextField();
108
		key2_Combo = new FeatureTypeAttributesCombo();
109
		prefix1Text = new javax.swing.JTextField();
110
		key1Label = new javax.swing.JLabel();
111
		
112
		key1Combo = new FeatureTypeAttributesCombo();
113
		// listen to changes in first combo
114
		// we'll update second combo leaving
115
		// fields of same type
116
		key1Combo.addActionListener(this);
117
		
118
		key2Label = new javax.swing.JLabel();
119
		prefix1Label = new javax.swing.JLabel();
120
		prefix2Label = new javax.swing.JLabel();
121
		attributesLabel = new javax.swing.JLabel();
122
		attributesScroll = new javax.swing.JScrollPane();
123
		attributesList = new FeatureTypeAttributesList();
124

  
125
		setLayout(new java.awt.GridBagLayout());
126
		gridBagConstraints = new java.awt.GridBagConstraints();
127
		gridBagConstraints.gridx = 0;
128
		gridBagConstraints.gridy = 7;
129
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130
		gridBagConstraints.weightx = 1.0;
131
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
132
		add(prefix2Text, gridBagConstraints);
133

  
134
		gridBagConstraints = new java.awt.GridBagConstraints();
135
		gridBagConstraints.gridx = 0;
136
		gridBagConstraints.gridy = 3;
137
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
138
		gridBagConstraints.weightx = 1.0;
139
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
140
		add(key2_Combo, gridBagConstraints);
141
		gridBagConstraints = new java.awt.GridBagConstraints();
142
		gridBagConstraints.gridx = 0;
143
		gridBagConstraints.gridy = 5;
144
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145
		gridBagConstraints.weightx = 1.0;
146
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
147
		add(prefix1Text, gridBagConstraints);
148

  
149
		key1Label.setText("jLabel1");
150
		gridBagConstraints = new java.awt.GridBagConstraints();
151
		gridBagConstraints.gridx = 0;
152
		gridBagConstraints.gridy = 0;
153
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
155
		add(key1Label, gridBagConstraints);
156

  
157
		gridBagConstraints = new java.awt.GridBagConstraints();
158
		gridBagConstraints.gridx = 0;
159
		gridBagConstraints.gridy = 1;
160
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161
		gridBagConstraints.weightx = 1.0;
162
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 3, 2);
163
		add(key1Combo, gridBagConstraints);
164

  
165
		key2Label.setText("jLabel2");
166
		gridBagConstraints = new java.awt.GridBagConstraints();
167
		gridBagConstraints.gridx = 0;
168
		gridBagConstraints.gridy = 2;
169
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
171
		add(key2Label, gridBagConstraints);
172

  
173
		prefix1Label.setText("jLabel1");
174
		gridBagConstraints = new java.awt.GridBagConstraints();
175
		gridBagConstraints.gridx = 0;
176
		gridBagConstraints.gridy = 4;
177
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
178
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
179
		add(prefix1Label, gridBagConstraints);
180

  
181
		prefix2Label.setText("jLabel2");
182
		gridBagConstraints = new java.awt.GridBagConstraints();
183
		gridBagConstraints.gridx = 0;
184
		gridBagConstraints.gridy = 6;
185
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
186
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
187
		add(prefix2Label, gridBagConstraints);
188

  
189
		attributesLabel.setText("attributesLabel");
190
		gridBagConstraints = new java.awt.GridBagConstraints();
191
		gridBagConstraints.gridx = 0;
192
		gridBagConstraints.gridy = 8;
193
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
194
		gridBagConstraints.insets = new java.awt.Insets(3, 2, 2, 2);
195
		add(attributesLabel, gridBagConstraints);
196

  
197
		attributesScroll.setViewportView(attributesList);
198

  
199
		gridBagConstraints = new java.awt.GridBagConstraints();
200
		gridBagConstraints.gridx = 0;
201
		gridBagConstraints.gridy = 9;
202
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
203
		gridBagConstraints.weightx = 1.0;
204
		gridBagConstraints.weighty = 1.0;
205
		gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
206
		add(attributesScroll, gridBagConstraints);
207
	}
208
	
209

  
210
	/**
211
	 * @return
212
	 */
213
	public String getKeyAttr1() {
214
		return key1Combo.getSelectedFeatureAttributeDescriptor().getName();
215
	}
216

  
217
	/**
218
	 * @return
219
	 */
220
	public String getkeyAtrr2() {
221
		return key2_Combo.getSelectedFeatureAttributeDescriptor().getName();
222
	}
223

  
224
	/**
225
	 * @return
226
	 */
227
	public String getPrefix1() {
228
		return prefix1Text.getText();
229
	}
230

  
231
	/**
232
	 * @return
233
	 */
234
	public String getPrefix2() {
235
		return prefix2Text.getText();
236
	}
237

  
238
	/**
239
	 * @return
240
	 */
241
	public String[] getAttributes() {
242
		return attributesList.getAttributesName();
243
	}
244
	
245
	
246
	public void setSecondFeatureStore(FeatureStore selectedFeatureStore) {
247
	    secondFeatStore = selectedFeatureStore;
248
	    
249
	}
250
	/**
251
	 * @param selectedFeatureStore
252
	 * @throws DataException 
253
	 */
254
	public void updateFeatureStores() throws DataException {
255
	    
256
	    if (secondFeatStore == null) {
257
	        throw new ParameterMissingException("Second feature store");
258
	    }
259
	    
260
		key1Combo.addFeatureAttributes(getFeatureStore().getDefaultFeatureType());
261
		attributesList.addFeatureAttributes(secondFeatStore.getDefaultFeatureType());
262
		
263
		if (key1Combo.getItemCount() == 0) {
264
		    
265
            String _msg =
266
                Messages.getText("_First_table_has_no_fields");
267
            String _tit = Messages.getText("_Join");
268
            
269
            JOptionPane.showMessageDialog(
270
                this, _msg, _tit,
271
                JOptionPane.ERROR_MESSAGE);
272
            
273
		    getDataTransformWizard().setApplicable(false);
274
        } else {
275
            key1Combo.setSelectedIndex(0);
276
		}
277
	}
278

  
279

  
280
	/**
281
	 * Listen to changes in first combo box (key1)
282
	 */
283
    public void actionPerformed(ActionEvent e) {
284
        
285
        Object src = e.getSource();
286
        if (src == key1Combo
287
            && key1Combo != null
288
            && key2_Combo != null
289
            && secondFeatStore != null) {
290
            
291
            FeatureAttributeDescriptor att =
292
                key1Combo.getSelectedFeatureAttributeDescriptor();
293
            if (att != null) {
294
                
295
                int the_type = att.getType();
296
                key2_Combo.removeAllItems();
297
                FeatureType ft = null;
298
                
299
                try {
300
                    ft = secondFeatStore.getDefaultFeatureType();
301
                } catch (DataException de) {
302
                    logger.info("While getting feat type: " + de.getMessage());
303
                    getDataTransformWizard().setApplicable(false);
304
                    ApplicationLocator.getManager().message(
305
                        Messages.getText("_Error_getting_attributes"),
306
                        JOptionPane.ERROR_MESSAGE);
307
                    return;
308
                }
309
                
310
                ArrayList<Integer> comparable_types =
311
                    TransformUtils.getComparableDataTypes(ft, the_type);
312
                
313
                if (key2_Combo.addFeatureAttributes(ft, comparable_types) == 0) {
314

  
315
                    String _msg =
316
                        Messages.getText("_No_compatible_field_in_second_table");
317
                    String _tit = Messages.getText("_Join");
318
                    
319
                    JOptionPane.showMessageDialog(
320
                        this, _msg, _tit,
321
                        JOptionPane.ERROR_MESSAGE);
322
                    getDataTransformWizard().setApplicable(false);
323
                    
324
                } else {
325
                    getDataTransformWizard().setApplicable(true);
326
                    // JOptionPane.showMessageDialog(this, "(2) OK !!");
327
                }
328
            }
329
        }
330
        
331
    }
332
}
333

  
0 334

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/RemoveTableUnion.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.join;
25

  
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.andami.ui.mdiManager.IWindow;
30
import org.gvsig.app.join.dal.feature.JoinTransform;
31
import org.gvsig.app.project.documents.table.TableDocument;
32
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
35
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
36

  
37

  
38
/**
39
 * @author Fernando Gonz?lez Cort?s
40
 */
41
public class RemoveTableUnion extends Extension{
42

  
43
	/**
44
	 * @see org.gvsig.andami.plugins.IExtension#initialize()
45
	 */
46
	public void initialize() {
47
		IconThemeHelper.registerIcon("action", "table-remove-join", this);
48
	}
49

  
50
	/**
51
	 * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
52
	 */
53
	public void execute(String actionCommand) {
54
		if( "table-remove-join".equalsIgnoreCase(actionCommand)) {
55
			FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) PluginServices.getMDIManager().getActiveWindow();
56
			TableDocument pt = t.getModel();
57
			FeatureStore fs = pt.getStore();
58
			this.removeJoinTransfor(fs);
59
	
60
			//		TODO
61
			//		if (fs instanceof JoinFeatureStore) {
62
			//			DataManager dm = DALLocator.getDataManager();
63
			//			DataStoreParameters originalParams = ((JoinFeatureStoreParameters) fs
64
			//					.getParameters()).getStorePrimary();
65
			//			FeatureStore original = null;
66
			//			try {
67
			//				original = (FeatureStore) dm.createStore(originalParams);
68
			//			} catch (InitializeException e) {
69
			//				NotificationManager.addError(e.getMessage(), e);
70
			//				return;
71
			//			}
72
			//
73
			//			pt.setStore(original);
74
			//			try {
75
			//				fs.dispose();
76
			//			} catch (CloseException e) {
77
			//				NotificationManager.addError(e);
78
			//			}
79
			//			t.setModel(pt);
80
			//
81
			//		}
82
	
83
			//		t.clearSelectedFields();
84
			t.getModel().setModified(true);
85
		}
86
	}
87

  
88
	public void removeJoinTransfor(FeatureStore store) {
89
		FeatureStoreTransforms transforms = store.getTransforms();
90
		int size = transforms.size();
91
		if (size < 1) {
92
			return;
93
		}
94
		FeatureStoreTransform join = transforms.getTransform(size - 1);
95
		if (join instanceof JoinTransform) {
96
			transforms.remove(join);
97
		} else {
98
			return;
99
		}
100

  
101

  
102

  
103
	}
104

  
105
	public boolean hasJoinTransform(FeatureStore store) {
106

  
107
		FeatureStoreTransforms transforms = store.getTransforms();
108
		int size = transforms.size();
109
		if (size < 1) {
110
			return false;
111
		}
112
		return (transforms.getTransform(size - 1) instanceof JoinTransform);
113

  
114
	}
115

  
116
	/**
117
	 * @see org.gvsig.andami.plugins.IExtension#isEnabled()
118
	 */
119
	public boolean isEnabled() {
120
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
121

  
122
		if (v == null) {
123
			return false;
124
		}
125

  
126
		if (v.getClass() == FeatureTableDocumentPanel.class) {
127
			FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v;
128
			// FIXME !!!! Asi se hacia antes
129
			//			if (t.getModel().getOriginal() != null){
130
			//				return true;
131
			//			}
132

  
133
			TableDocument pt = t.getModel();
134
			FeatureStore fs = pt.getStore();
135

  
136
			return this.hasJoinTransform(fs);
137
//			TODO
138
//			if (fs instanceof JoinFeatureStore) {
139
//				return true;
140
//			}
141

  
142
		}
143
		return false;
144
	}
145

  
146
	/**
147
	 * @see org.gvsig.andami.plugins.IExtension#isVisible()
148
	 */
149
	public boolean isVisible() {
150
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
151

  
152
		if (v == null) {
153
			return false;
154
		}
155

  
156
		if (v instanceof FeatureTableDocumentPanel) {
157
			return true;
158
		} else {
159
			return false;
160
		}
161

  
162
	}
163

  
164
}
0 165

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/JoinTransformLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

  
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 {Iver T.I.}   {Task}
49
*/
50
 
51
package org.gvsig.app.join;
52

  
53
import java.util.Locale;
54

  
55
import org.gvsig.app.join.dal.feature.JoinTransform;
56
import org.gvsig.app.join.daltransform.JoinTransformGui;
57
import org.gvsig.daltransform.DataTransformLibrary;
58
import org.gvsig.daltransform.DataTransformLocator;
59
import org.gvsig.daltransform.DataTransformManager;
60
import org.gvsig.fmap.dal.DALLibrary;
61
import org.gvsig.i18n.Messages;
62
import org.gvsig.tools.library.AbstractLibrary;
63
import org.gvsig.tools.library.LibraryException;
64
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
65

  
66
/**
67
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
68
 */
69
public class JoinTransformLibrary extends AbstractLibrary {
70

  
71
    @Override
72
    public void doRegistration() {
73
        registerAsImplementationOf(JoinTransformLibrary.class);
74
        require(DALLibrary.class);
75
        require(DataTransformLibrary.class);
76

  
77
    }
78

  
79
	@Override
80
	protected void doInitialize() throws LibraryException {
81
		
82
	}
83

  
84
	@Override
85
	protected void doPostInitialize() throws LibraryException {
86
		// Validate there is any implementation registered.
87
		DataTransformManager dataTransformManager = DataTransformLocator.getDataTransformManager();
88
		if (dataTransformManager == null) {
89
			throw new ReferenceNotRegisteredException(
90
					DataTransformLocator.DATA_TRANSFORM_MANAGER_NAME, DataTransformLocator.getInstance());
91
		}	
92
		dataTransformManager.registerDataTransform("join", JoinTransformGui.class);		
93
		
94
		JoinTransform.registerPersistent();
95
	}
96

  
97
}
98

  
0 99

  
tags/org.gvsig.desktop-2.0.63/org.gvsig.desktop.plugin/org.gvsig.daltransform.app/org.gvsig.daltransform.app.join/src/main/java/org/gvsig/app/join/dal/feature/JoinTransform.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.join.dal.feature;
25

  
26
import java.util.ArrayList;
27
import java.util.Arrays;
28
import java.util.HashMap;
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.Map.Entry;
33

  
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform;
36
import org.gvsig.fmap.dal.feature.EditableFeature;
37
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
38
import org.gvsig.fmap.dal.feature.EditableFeatureType;
39
import org.gvsig.fmap.dal.feature.Feature;
40
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
41
import org.gvsig.fmap.dal.feature.FeatureQuery;
42
import org.gvsig.fmap.dal.feature.FeatureSet;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.feature.FeatureType;
45
import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException;
46
import org.gvsig.tools.ToolsLocator;
47
import org.gvsig.tools.dispose.DisposableIterator;
48
import org.gvsig.tools.dynobject.DynStruct;
49
import org.gvsig.tools.evaluator.Evaluator;
50
import org.gvsig.tools.evaluator.EvaluatorData;
51
import org.gvsig.tools.evaluator.EvaluatorException;
52
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
53
import org.gvsig.tools.persistence.PersistenceManager;
54
import org.gvsig.tools.persistence.PersistentState;
55
import org.gvsig.tools.persistence.exception.PersistenceException;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58

  
59
public class JoinTransform extends AbstractFeatureStoreTransform {
60

  
61
	private static Logger logger = LoggerFactory.getLogger(JoinTransform.class);
62
	
63
    public static final String PERSISTENCE_DEFINITION_NAME = "JoinTransform";
64
    
65
    /**
66
     * Store from which the join transform will get the additional attributes
67
     */
68
    private FeatureStore store2;
69

  
70
    /**
71
     * name of the key attr in store1 that will be used to match features in
72
     * store2
73
     */
74
    private String keyAttr1;
75

  
76
    /**
77
     * name of the key attr in store2 that will be used to match features in
78
     * store1
79
     */
80
    private String keyAttr2;
81

  
82
    /**
83
     * names of the attributes to join from store2 to store1
84
     */
85
    private String[] attrs;
86

  
87
    /**
88
     * Attribute names may change after transformation a prefix is applied.
89
     * This map keeps correspondence between store1 original names
90
     * and their transformed counterparts.
91
     */
92
    private Map<String,String> store1NamesMap;
93

  
94
    /**
95
     * Attribute names may change after transformation if they are repeated in
96
     * both stores or if a prefix is applied. This map keeps correspondence
97
     * between store2 original names and their transformed counterparts.
98
     */
99
    private Map<String,String> store2NamesMap;
100

  
101
    private JoinTransformEvaluator evaluator = null;
102

  
103
    private FeatureType originalFeatureType;
104

  
105
    private String[] attrsForQuery;
106

  
107
    private String prefix1;
108

  
109
    private String prefix2;
110

  
111
    /**
112
     * A default constructor
113
     */
114
    public JoinTransform() {
115
        store1NamesMap = new HashMap<String,String>();
116
        store2NamesMap = new HashMap<String,String>();
117
    }
118

  
119
    /**
120
     * Initializes all the necessary data for this transform
121
     *
122
     * @param store1
123
     *            store whose default feature type is the target of this
124
     *            transform
125
     *
126
     * @param store2
127
     *            store whose default feature type will provide the new
128
     *            attributes to join
129
     *
130
     * @param keyAttr1
131
     *            key attribute in store1 that matches keyAttr2 in store2
132
     *            (foreign key), used for joining both stores.
133
     *
134
     * @param keyAttr2
135
     *            key attribute in store2 that matches keyAttr1 in store2
136
     *            (foreign key), used for joining both stores.
137
     *
138
     * @param attrs
139
     *            names of the attributes in store2 that will be joined to
140
     *            store1.
141
     */
142
    public void initialize(FeatureStore store1, FeatureStore store2,
143
        String keyAttr1, String keyAttr2, String prefix1, String prefix2,
144
        String[] attrs)
145
    throws DataException {
146

  
147
        if (store1 == store2) {
148
            throw new IllegalArgumentException("store1 == store2");
149
        }
150

  
151
        // Initialize needed data
152
        this.setFeatureStore(store1);
153
        this.store2 = store2;
154
        this.keyAttr1 = keyAttr1;
155
        this.keyAttr2 = keyAttr2;
156
        this.prefix1 = prefix1; // TODO
157
        this.prefix2 = prefix2; // TODO
158
        this.attrs = attrs;
159

  
160
        // calculate this transform resulting feature type
161
        // by adding all specified attrs from store2 to store1's default
162
        // feature type
163
        // FIXME for more than one FTypes ??
164
        this.originalFeatureType = this.getFeatureStore()
165
        .getDefaultFeatureType();
166

  
167
        // keep index of geometry and att desc ==============
168
        int orig_geom_field_index =
169
            this.originalFeatureType.getDefaultGeometryAttributeIndex();
170
        FeatureAttributeDescriptor orig_geom_field_att = 
171
            this.originalFeatureType.getDefaultGeometryAttribute();
172
        
173
        // Create the feature type and copy the store 1 type        
174
        EditableFeatureType editableFeatureType = this.getFeatureStore().getDefaultFeatureType().getEditable();
175
        FeatureAttributeDescriptor[] featureAttributeDescriptors = editableFeatureType.getAttributeDescriptors();
176
        for (int i=0 ; i<featureAttributeDescriptors.length ; i++){ 
177
            editableFeatureType.remove(featureAttributeDescriptors[i].getName());           
178
        }    
179
        addFeatureType(editableFeatureType, featureAttributeDescriptors, prefix1, store1NamesMap);
180

  
181
        // =========== set the new geom field name and restore geometry values
182
        if (orig_geom_field_index >= 0) {
183
            EditableFeatureAttributeDescriptor ed_att = null;
184
            ed_att = (EditableFeatureAttributeDescriptor)
185
                editableFeatureType.getAttributeDescriptor(orig_geom_field_index);
186
            ed_att.setSRS(orig_geom_field_att.getSRS());
187
            ed_att.setObjectClass(orig_geom_field_att.getObjectClass());
188
            ed_att.setGeometryType(orig_geom_field_att.getGeomType());
189
            ed_att.setDefaultValue(orig_geom_field_att.getDefaultValue());
190

  
191
            String new_geom_field_name = ed_att.getName();
192
            editableFeatureType.setDefaultGeometryAttributeName(new_geom_field_name);
193
        }
194
        // =====================================================================
195

  
196
        // Add the store 2 fields    
197
        FeatureType featureType2 = store2.getDefaultFeatureType();
198

  
199
        // Add the fields       
200
        for (int i = 0; i < attrs.length; i++) {
201
            addFeatureType(editableFeatureType, featureType2.getAttributeDescriptor(attrs[i]), prefix2, store2NamesMap);        
202
        }
203

  
204
        if (this.store2NamesMap.containsKey(keyAttr2)) {
205
            this.attrsForQuery = this.attrs;
206
        } else {
207
            List<String> list = new ArrayList<String>(this.attrs.length + 1);
208
            list.addAll(Arrays.asList(this.attrs));
209
            list.add(keyAttr2);
210
            this.attrsForQuery = (String[]) list.toArray(new String[] {});
211
        }
212

  
213
        // assign calculated feature type as this transform's feature type
214
        FeatureType[] types = new FeatureType[] { editableFeatureType.getNotEditableCopy() };
215
        setFeatureTypes(Arrays.asList(types), types[0]);
216
    }
217

  
218
    private void addFeatureType(EditableFeatureType targetFeatureType, FeatureAttributeDescriptor[] featureAttributeDescriptors,
219
        String prefix, Map<String, String> storeMap) throws DataException{
220

  
221
        for (int i=0 ; i<featureAttributeDescriptors.length ; i++){         
222
            addFeatureType(targetFeatureType, featureAttributeDescriptors[i], prefix, storeMap);
223
        }
224
    }
225

  
226
    private void addFeatureType(EditableFeatureType targetFeatureType, FeatureAttributeDescriptor featureAttributeDescriptor,
227
        String prefix, Map<String, String> storeMap) throws DataException{
228

  
229
        String attName = featureAttributeDescriptor.getName();
230
        if ((prefix != null) && (!prefix.equals(""))){
231
            attName = prefix + "_" + attName;
232
        }
233

  
234
        // If an attribute already exists, calculate an alternate name and add it to our type
235
        int j = 0;
236
        while (targetFeatureType.getIndex(attName) >= 0) {
237
            attName = targetFeatureType.getAttributeDescriptor(attName).getName() + "_" + ++j;
238
        }
239

  
240
        EditableFeatureAttributeDescriptor editableFeatureAttributeDescriptor = 
241
            targetFeatureType.add(attName, featureAttributeDescriptor.getType(),
242
                featureAttributeDescriptor.getSize());
243
        editableFeatureAttributeDescriptor.setPrecision(featureAttributeDescriptor.getPrecision());
244

  
245
        // keep correspondence between original name and transformed name
246
        storeMap.put(featureAttributeDescriptor.getName(), attName);
247
    } 
248

  
249
    /**
250
     *
251
     *
252
     * @param source
253
     *
254
     * @param target
255
     *
256
     * @throws DataException
257
     */
258
    public void applyTransform(Feature source, EditableFeature target)
259
    throws DataException {
260

  
261
        // copy the data from store1 into the resulting feature
262
        this.copySourceToTarget(source, target);
263

  
264
        // ask store2 for the specified attributes, filtering by the key
265
        // attribute value
266
        // from the source feature
267
        JoinTransformEvaluator eval = this.getEvaluator();
268
        eval.updateValue(source.get(this.keyAttr1));
269

  
270
        FeatureQuery query = store2.createFeatureQuery();
271
        query.setAttributeNames(attrsForQuery);
272
        query.setFilter(eval);
273
        FeatureSet set = null;
274
        DisposableIterator itFeat = null;
275

  
276
        try {
277

  
278
            set = store2.getFeatureSet(query);
279
            // In this join implementation, we will take only the first matching
280
            // feature found in store2
281

  
282
            Feature feat;
283

  
284

  
285
            itFeat = set.iterator();
286
            if (itFeat.hasNext()) {
287
                feat = (Feature) itFeat.next();
288

  
289
                // copy all attributes from joined feature to target
290
                this.copyJoinToTarget(feat, target);
291
            }
292
        } finally {
293
            if (itFeat != null) {
294
                itFeat.dispose();
295
            }
296
            if (set != null) {
297
                set.dispose();
298
            }
299
        }
300
    }
301

  
302
    /**
303
     * @param feat
304
     * @param target
305
     */
306
    private void copyJoinToTarget(Feature join, EditableFeature target) {
307
        Iterator<Entry<String, String>> iter = store2NamesMap.entrySet()
308
        .iterator();
309
        Entry<String, String> entry;
310
        FeatureType trgType = target.getType();
311
        FeatureAttributeDescriptor attr;
312
        while (iter.hasNext()) {
313
            entry = iter.next();
314
            attr = trgType.getAttributeDescriptor((String) entry.getValue());
315
            if (attr != null) {
316
                target.set(attr.getIndex(), join.get((String) entry.getKey()));
317
            }
318
        }
319
    }
320

  
321
    /**
322
     * @param source
323
     * @param target
324
     */
325
    private void copySourceToTarget(Feature source, EditableFeature target) {
326
        FeatureAttributeDescriptor attr, attrTrg;
327
        FeatureType ftSrc = source.getType();
328
        FeatureType ftTrg = target.getType();
329

  
330

  
331
        for (int i = 0; i < source.getType().size(); i++) {
332
            attr = ftSrc.getAttributeDescriptor(i);
333
            attrTrg = ftTrg.getAttributeDescriptor(store1NamesMap.get(attr.getName()));
334
            if (attrTrg != null) {
335
                try {
336
                    target.set(attrTrg.getIndex(), source.get(i));
337
                } catch ( SetReadOnlyAttributeException e1) {
338
                    // Ignore, do nothing
339
                    
340
                } catch (IllegalArgumentException e) {
341
                    attrTrg = ftTrg.getAttributeDescriptor(attr.getName());
342
                    target.set(attrTrg.getIndex(), attrTrg.getDefaultValue());
343
                }
344

  
345
            }
346
        }
347

  
348
    }
349

  
350
    private JoinTransformEvaluator getEvaluator() {
351
        if (this.evaluator == null){
352
        	FeatureType ft2 = null;
353
        	try {
354
				ft2 = this.store2.getDefaultFeatureType();
355
			} catch (DataException e) {
356
				logger.error("While getting feat type.", e);
357
			}
358
        	FeatureAttributeDescriptor att2 = ft2.getAttributeDescriptor(keyAttr2);
359
        	boolean is_num = att2.getDataType().isNumeric();
360
            this.evaluator = new JoinTransformEvaluator(keyAttr2, is_num);
361
        }
362
        return evaluator;
363

  
364
    }
365

  
366
    private class JoinTransformEvaluator implements Evaluator {
367

  
368
        private String attribute;
369
        private boolean isNumeric = false;
370
        private Object value;
371
        private String sql;
372
        private EvaluatorFieldsInfo info = null;
373

  
374
        //		private int attributeIndex;
375

  
376
        public JoinTransformEvaluator(String attribute, boolean is_numeric) {
377
            this.attribute = attribute;
378
            this.isNumeric = is_numeric;
379
            this.value = null;
380
            this.info = new EvaluatorFieldsInfo();
381

  
382
            //			this.attributeIndex = attrIndex;
383
        }
384

  
385
        public void updateValue(Object value) {
386
            this.value = value;
387
            String qt = this.isNumeric ? "" : "'";
388
            this.sql = this.attribute + " = " + qt + this.value + qt;
389
            this.info = new EvaluatorFieldsInfo();
390
            this.info.addMatchFieldValue(this.attribute, value);
391
        }
392

  
393
        public Object evaluate(EvaluatorData arg0) throws EvaluatorException {
394
            Object curValue = arg0.getDataValue(attribute);
395
            if (curValue == null) {
396
                return value == null;
397
            }
398
            return curValue.equals(value);
399
        }
400

  
401
        public String getSQL() {
402
            return this.sql;
403
        }
404

  
405
        public String getDescription() {
406
            return "Evaluates join transform match";
407
        }
408

  
409
        public String getName() {
410
            return "JoinTransformEvaluator";
411
        }
412

  
413
        public EvaluatorFieldsInfo getFieldsInfo() {
414
            return this.info;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff