svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extDalTransformJoin / src / org / gvsig / app / join / JoinToolExtension.java @ 28897
History | View | Annotate | Download (4.69 KB)
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 java.awt.Component; |
31 |
import java.awt.Dimension; |
32 |
import java.util.ArrayList; |
33 |
import java.util.Iterator; |
34 |
|
35 |
import javax.swing.JOptionPane; |
36 |
|
37 |
import org.gvsig.app.join.dal.feature.JoinTransform; |
38 |
import org.gvsig.fmap.dal.DALLocator; |
39 |
import org.gvsig.fmap.dal.DataManager; |
40 |
import org.gvsig.fmap.dal.DataTypes; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.ReadException; |
43 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
44 |
import org.gvsig.fmap.dal.feature.Feature; |
45 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
46 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
47 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
48 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
50 |
import org.gvsig.project.document.table.FeatureTableDocument; |
51 |
import org.gvsig.project.document.table.FeatureTableDocumentFactory; |
52 |
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
53 |
import org.gvsig.project.document.table.gui.JoinWizardController; |
54 |
import org.opengis.feature.FeatureCollection; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.andami.messages.NotificationManager; |
58 |
import com.iver.andami.plugins.Extension; |
59 |
import com.iver.andami.ui.mdiManager.IWindow; |
60 |
import com.iver.cit.gvsig.ProjectExtension; |
61 |
import com.iver.cit.gvsig.TableOperations; |
62 |
import com.iver.cit.gvsig.gui.filter.ExpressionListener; |
63 |
import com.iver.cit.gvsig.project.documents.gui.AndamiWizard; |
64 |
import com.iver.cit.gvsig.project.documents.gui.ObjectSelectionStep; |
65 |
import com.iver.cit.gvsig.project.documents.table.FieldSelectionModel; |
66 |
import com.iver.cit.gvsig.project.documents.table.TableSelectionModel; |
67 |
import com.iver.utiles.swing.objectSelection.SelectionException; |
68 |
import com.iver.utiles.swing.wizard.WizardControl; |
69 |
import com.iver.utiles.swing.wizard.WizardEvent; |
70 |
import com.iver.utiles.swing.wizard.WizardListener; |
71 |
|
72 |
/**
|
73 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
74 |
*/
|
75 |
public class JoinToolExtension extends TableOperations { |
76 |
private FeatureStore featureStore = null; |
77 |
|
78 |
/**
|
79 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
80 |
*/
|
81 |
public void execute(String actionCommand) { |
82 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
83 |
com.iver.cit.gvsig.project.Project project=pe.getProject(); |
84 |
FeatureTableDocument[] pts = project.getDocumentsByType(FeatureTableDocumentFactory.registerName)
|
85 |
.toArray(new FeatureTableDocument[0]); |
86 |
|
87 |
JoinWizardController wizardController = new JoinWizardController(this); |
88 |
wizardController.runWizard(pts); |
89 |
} |
90 |
|
91 |
public void execJoin(FeatureTableDocument sourceProjectTable, |
92 |
String field1, String prefix1, |
93 |
FeatureTableDocument targetProjectTable, String field2,
|
94 |
String prefix2) {
|
95 |
|
96 |
FeatureStore fs1 = sourceProjectTable.getStore(); |
97 |
|
98 |
FeatureStore fs2 = targetProjectTable.getStore(); |
99 |
|
100 |
if (fs1 == fs2) {
|
101 |
NotificationManager |
102 |
.addInfo("no_es_posible_aplicar_join_sobre_la_misma_fuente");
|
103 |
} |
104 |
|
105 |
try {
|
106 |
DataManager dm = DALLocator.getDataManager(); |
107 |
JoinTransform jt = new JoinTransform();
|
108 |
ArrayList<String> fields = new ArrayList<String>(); |
109 |
Iterator iterator2 = fs2.getDefaultFeatureType().iterator();
|
110 |
while (iterator2.hasNext()) {
|
111 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator2 |
112 |
.next(); |
113 |
String name = descriptor.getName();
|
114 |
if (!name.equals(field2)) {
|
115 |
fields.add(name); |
116 |
} |
117 |
} |
118 |
jt.initialize(fs1, fs2, field1, field2, prefix1, prefix2, fields |
119 |
.toArray(new String[0])); |
120 |
fs1.getTransforms().add(jt); |
121 |
// featureStore=fs1;
|
122 |
|
123 |
} catch (ReadException e) {
|
124 |
NotificationManager.addError("Error leyendo del driver", e);
|
125 |
} catch (DataException e) {
|
126 |
NotificationManager.addError(e); |
127 |
} |
128 |
|
129 |
} |
130 |
|
131 |
|
132 |
} |