Revision 42838 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/ShowTable.java
ShowTable.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.app.extension; |
25 | 24 |
|
26 | 25 |
import org.gvsig.andami.IconThemeHelper; |
27 | 26 |
import org.gvsig.andami.PluginServices; |
28 | 27 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.app.project.ProjectManager; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.app.ApplicationLocator; |
|
30 |
import org.gvsig.app.ApplicationManager; |
|
31 |
import org.gvsig.app.project.Project; |
|
32 |
import org.gvsig.app.project.documents.DocumentManager; |
|
30 | 33 |
import org.gvsig.app.project.documents.table.TableDocument; |
31 | 34 |
import org.gvsig.app.project.documents.table.TableManager; |
32 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
|
|
33 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
|
|
34 |
import org.gvsig.fmap.dal.feature.FeatureStore;
|
|
35 |
import org.gvsig.app.project.documents.view.ViewDocument;
|
|
36 |
import org.gvsig.app.project.documents.view.ViewManager;
|
|
37 |
import org.gvsig.fmap.mapcontext.MapContext;
|
|
35 | 38 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
36 | 39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 | 40 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
... | ... | |
39 | 42 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
40 | 43 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
41 | 44 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
45 |
import org.gvsig.tools.util.ArrayUtils; |
|
42 | 46 |
|
43 | 47 |
/** |
44 | 48 |
* Extensi?n que abre las tablas asociadas a las vistas. |
45 | 49 |
* |
46 |
* @author Vicente Caballero Navarro |
|
47 | 50 |
*/ |
48 | 51 |
public class ShowTable extends Extension implements LayerCollectionListener { |
49 | 52 |
|
50 |
/** |
|
51 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled() |
|
52 |
*/ |
|
53 |
@Override |
|
53 | 54 |
public boolean isEnabled() { |
54 |
AbstractViewPanel f = |
|
55 |
(AbstractViewPanel) PluginServices.getMDIManager() |
|
56 |
.getActiveWindow(); |
|
57 |
|
|
58 |
if (f == null) { |
|
55 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
56 |
ViewDocument doc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
57 |
if (doc == null) { |
|
59 | 58 |
return false; |
60 | 59 |
} |
61 |
|
|
62 |
FLayer[] selected = |
|
63 |
f.getViewDocument().getMapContext().getLayers().getActives(); |
|
64 |
|
|
65 |
boolean algunaTabla = false; |
|
66 |
|
|
67 |
for (int i = 0; i < selected.length; i++) { |
|
68 |
if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) { |
|
69 |
FLyrVect co = (FLyrVect) selected[i]; |
|
70 |
|
|
71 |
try { |
|
72 |
if (co.getFeatureStore() != null) { |
|
73 |
algunaTabla = true; |
|
74 |
} |
|
75 |
// } catch (ReadException e) { |
|
76 |
// return false; |
|
77 |
} catch (NullPointerException e) { |
|
78 |
return false; |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
return algunaTabla; |
|
60 |
MapContext mapContext = doc.getMapContext(); |
|
61 |
return mapContext.hasActiveVectorLayers(); |
|
84 | 62 |
} |
85 | 63 |
|
86 |
/** |
|
87 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
|
88 |
*/ |
|
64 |
@Override |
|
89 | 65 |
public boolean isVisible() { |
90 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
|
91 |
PluginServices.getMDIManager().getActiveWindow(); |
|
92 |
|
|
93 |
if (f == null) { |
|
66 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
67 |
ViewDocument doc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
68 |
if (doc == null) { |
|
94 | 69 |
return false; |
95 | 70 |
} |
71 |
MapContext mapContext = doc.getMapContext(); |
|
72 |
return mapContext.hasVectorLayers(); |
|
73 |
} |
|
96 | 74 |
|
97 |
//return (f instanceof AbstractViewPanel);
|
|
98 |
if ( f instanceof AbstractViewPanel ){
|
|
99 |
FLayer[] selected =
|
|
100 |
((AbstractViewPanel)f).getViewDocument().getMapContext().getLayers().getActives();
|
|
75 |
@Override
|
|
76 |
public void execute(String command) {
|
|
77 |
this.execute(command, null);
|
|
78 |
}
|
|
101 | 79 |
|
80 |
@Override |
|
81 |
public void execute(String command, Object[] args) { |
|
82 |
if ("layer-show-attributes-table".equalsIgnoreCase(command)) { |
|
83 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
84 |
FLayer[] layers = (FLayer[]) ArrayUtils.get(args, 0); |
|
85 |
if( layers == null ) { |
|
86 |
ViewDocument doc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
87 |
if (doc == null) { |
|
88 |
return; |
|
89 |
} |
|
90 |
MapContext mapContext = doc.getMapContext(); |
|
91 |
layers = mapContext.getLayers().getActives(); |
|
92 |
} |
|
93 |
Project project = application.getCurrentProject(); |
|
94 |
TableManager tableManager = getTableManager(); |
|
102 | 95 |
|
103 |
for (int i = 0; i < selected.length; i++) { |
|
104 |
if (selected[i].isAvailable() && selected[i] instanceof FLyrVect) { |
|
105 |
FLyrVect co = (FLyrVect) selected[i]; |
|
106 |
|
|
107 |
try { |
|
108 |
if (co.getFeatureStore() != null) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
// } catch (ReadException e) { |
|
112 |
// return false; |
|
113 |
} catch (NullPointerException e) { |
|
114 |
return false; |
|
96 |
for (FLayer layer : layers) { |
|
97 |
if (layer instanceof FLyrVect) { |
|
98 |
FLyrVect layerVect = (FLyrVect) layer; |
|
99 |
TableDocument tableDoc = tableManager.getTableDocument(layerVect); |
|
100 |
if (tableDoc == null) { |
|
101 |
tableDoc = (TableDocument) tableManager.createDocument(); |
|
102 |
tableDoc.setName(PluginServices.getText(this, |
|
103 |
"Tabla_de_Atributos") |
|
104 |
+ ": " |
|
105 |
+ layerVect.getName()); |
|
106 |
tableDoc.setStore(layerVect.getFeatureStore()); |
|
107 |
tableDoc.setAssociatedLayer(layerVect); |
|
108 |
layerVect.getParentLayer().addLayerCollectionListener(this); |
|
109 |
project.addDocument(tableDoc); |
|
115 | 110 |
} |
111 |
IWindow tablePanel = tableManager.getMainWindow(tableDoc); |
|
112 |
tableDoc.setModified(true); |
|
113 |
application.getUIManager().addWindow(tablePanel); |
|
116 | 114 |
} |
117 | 115 |
} |
118 | 116 |
} |
119 |
return false; |
|
120 | 117 |
} |
121 | 118 |
|
122 |
/** |
|
123 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String) |
|
124 |
*/ |
|
125 |
public void execute(String s) { |
|
126 |
if ("layer-show-attributes-table".equalsIgnoreCase(s)) { |
|
127 |
AbstractViewPanel vista = (AbstractViewPanel) PluginServices |
|
128 |
.getMDIManager().getActiveWindow(); |
|
129 |
FLayer[] actives = vista.getViewDocument().getMapContext() |
|
130 |
.getLayers().getActives(); |
|
131 |
|
|
132 |
for (int i = 0; i < actives.length; i++) { |
|
133 |
if (actives[i] instanceof FLyrVect) { |
|
134 |
FLyrVect co = (FLyrVect) actives[i]; |
|
135 |
|
|
136 |
ProjectManager projectManager = getProjectManager(); |
|
137 |
TableManager tableManager = getTableManager(); |
|
138 |
|
|
139 |
TableDocument projectTable = tableManager |
|
140 |
.getTableDocument(co); |
|
141 |
FeatureStore fs = ((FLyrVect) actives[i]).getFeatureStore(); |
|
142 |
|
|
143 |
if (projectTable == null) { |
|
144 |
projectTable = (TableDocument) projectManager |
|
145 |
.createDocument( |
|
146 |
TableManager.TYPENAME, |
|
147 |
PluginServices.getText(this, |
|
148 |
"Tabla_de_Atributos") |
|
149 |
+ ": " |
|
150 |
+ actives[i].getName()); |
|
151 |
projectTable.setStore(fs); |
|
152 |
projectTable.setAssociatedLayer(co); |
|
153 |
co.getParentLayer().addLayerCollectionListener(this); |
|
154 |
projectManager.getCurrentProject().add(projectTable); |
|
155 |
} |
|
156 |
|
|
157 |
FeatureTableDocumentPanel featureTableDocumentPanel = (FeatureTableDocumentPanel) projectTable |
|
158 |
.getFactory().getMainWindow(projectTable); |
|
159 |
|
|
160 |
featureTableDocumentPanel.getModel().setModified(true); |
|
161 |
PluginServices.getMDIManager().addWindow( |
|
162 |
featureTableDocumentPanel); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
private ProjectManager getProjectManager() { |
|
169 |
return ProjectManager.getInstance(); |
|
170 |
} |
|
171 |
|
|
172 | 119 |
private TableManager getTableManager() { |
173 |
TableManager tableManager = |
|
174 |
(TableManager) getProjectManager().getDocumentManager( |
|
175 |
TableManager.TYPENAME); |
|
176 |
return tableManager; |
|
120 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
121 |
DocumentManager tableManager = application.getProjectManager().getDocumentManager( |
|
122 |
TableManager.TYPENAME |
|
123 |
); |
|
124 |
return (TableManager) tableManager; |
|
177 | 125 |
} |
178 | 126 |
|
179 |
/** |
|
180 |
* @see org.gvsig.andami.plugins.IExtension#initialize() |
|
181 |
*/ |
|
127 |
@Override |
|
182 | 128 |
public void initialize() { |
183 |
IconThemeHelper.registerIcon("action", "layer-show-attributes-table", this);
|
|
129 |
IconThemeHelper.registerIcon("action", "layer-show-attributes-table", this);
|
|
184 | 130 |
} |
185 | 131 |
|
132 |
@Override |
|
186 | 133 |
public void layerAdded(LayerCollectionEvent e) { |
187 | 134 |
// Nothing to do |
188 | 135 |
} |
189 | 136 |
|
137 |
@Override |
|
190 | 138 |
public void layerMoved(LayerPositionEvent e) { |
191 | 139 |
// Nothing to do |
192 | 140 |
} |
193 | 141 |
|
142 |
@Override |
|
194 | 143 |
public void layerRemoved(LayerCollectionEvent e) { |
195 | 144 |
FLayer layer = e.getAffectedLayer(); |
196 | 145 |
// Just in case we where listening to a group of layers being removed |
... | ... | |
213 | 162 |
} |
214 | 163 |
} |
215 | 164 |
|
165 |
@Override |
|
216 | 166 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
217 | 167 |
// Nothing to do |
218 | 168 |
} |
219 | 169 |
|
170 |
@Override |
|
220 | 171 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
221 | 172 |
// Nothing to do |
222 | 173 |
} |
223 | 174 |
|
175 |
@Override |
|
224 | 176 |
public void layerRemoving(LayerCollectionEvent e) |
225 |
throws CancelationException { |
|
177 |
throws CancelationException {
|
|
226 | 178 |
// Nothing to do |
227 | 179 |
} |
228 | 180 |
|
181 |
@Override |
|
229 | 182 |
public void visibilityChanged(LayerCollectionEvent e) |
230 |
throws CancelationException { |
|
183 |
throws CancelationException {
|
|
231 | 184 |
// Nothing to do |
232 | 185 |
} |
233 | 186 |
} |
Also available in: Unified diff