svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.daltransform.app / org.gvsig.daltransform.app.join / src / main / java / org / gvsig / app / join / RemoveTableUnion.java @ 40558
History | View | Annotate | Download (4.41 KB)
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 |
} |