svn-gvsig-desktop / 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 @ 40558
History | View | Annotate | Download (7 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.extension; |
25 |
|
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.app.project.ProjectManager; |
30 |
import org.gvsig.app.project.documents.table.TableDocument; |
31 |
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.fmap.mapcontext.layers.CancelationException; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
39 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
40 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
41 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
42 |
|
43 |
/**
|
44 |
* Extensi?n que abre las tablas asociadas a las vistas.
|
45 |
*
|
46 |
* @author Vicente Caballero Navarro
|
47 |
*/
|
48 |
public class ShowTable extends Extension implements LayerCollectionListener { |
49 |
|
50 |
/**
|
51 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
52 |
*/
|
53 |
public boolean isEnabled() { |
54 |
AbstractViewPanel f = |
55 |
(AbstractViewPanel) PluginServices.getMDIManager() |
56 |
.getActiveWindow(); |
57 |
|
58 |
if (f == null) { |
59 |
return false; |
60 |
} |
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;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
88 |
*/
|
89 |
public boolean isVisible() { |
90 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
91 |
PluginServices.getMDIManager().getActiveWindow(); |
92 |
|
93 |
if (f == null) { |
94 |
return false; |
95 |
} |
96 |
|
97 |
return (f instanceof AbstractViewPanel); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
102 |
*/
|
103 |
public void execute(String s) { |
104 |
if ("layer-show-attributes-table".equalsIgnoreCase(s)) { |
105 |
AbstractViewPanel vista = (AbstractViewPanel) PluginServices |
106 |
.getMDIManager().getActiveWindow(); |
107 |
FLayer[] actives = vista.getViewDocument().getMapContext()
|
108 |
.getLayers().getActives(); |
109 |
|
110 |
for (int i = 0; i < actives.length; i++) { |
111 |
if (actives[i] instanceof FLyrVect) { |
112 |
FLyrVect co = (FLyrVect) actives[i]; |
113 |
|
114 |
ProjectManager projectManager = getProjectManager(); |
115 |
TableManager tableManager = getTableManager(); |
116 |
|
117 |
TableDocument projectTable = tableManager |
118 |
.getTableDocument(co); |
119 |
FeatureStore fs = ((FLyrVect) actives[i]).getFeatureStore(); |
120 |
|
121 |
if (projectTable == null) { |
122 |
projectTable = (TableDocument) projectManager |
123 |
.createDocument( |
124 |
TableManager.TYPENAME, |
125 |
PluginServices.getText(this,
|
126 |
"Tabla_de_Atributos")
|
127 |
+ ": "
|
128 |
+ actives[i].getName()); |
129 |
projectTable.setStore(fs); |
130 |
projectTable.setAssociatedLayer(co); |
131 |
co.getParentLayer().addLayerCollectionListener(this);
|
132 |
projectManager.getCurrentProject().add(projectTable); |
133 |
} |
134 |
|
135 |
FeatureTableDocumentPanel featureTableDocumentPanel = (FeatureTableDocumentPanel) projectTable |
136 |
.getFactory().getMainWindow(projectTable); |
137 |
|
138 |
featureTableDocumentPanel.getModel().setModified(true);
|
139 |
PluginServices.getMDIManager().addWindow( |
140 |
featureTableDocumentPanel); |
141 |
} |
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
private ProjectManager getProjectManager() {
|
147 |
return ProjectManager.getInstance();
|
148 |
} |
149 |
|
150 |
private TableManager getTableManager() {
|
151 |
TableManager tableManager = |
152 |
(TableManager) getProjectManager().getDocumentManager( |
153 |
TableManager.TYPENAME); |
154 |
return tableManager;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
159 |
*/
|
160 |
public void initialize() { |
161 |
IconThemeHelper.registerIcon("action", "layer-show-attributes-table", this); |
162 |
} |
163 |
|
164 |
public void layerAdded(LayerCollectionEvent e) { |
165 |
// Nothing to do
|
166 |
} |
167 |
|
168 |
public void layerMoved(LayerPositionEvent e) { |
169 |
// Nothing to do
|
170 |
} |
171 |
|
172 |
public void layerRemoved(LayerCollectionEvent e) { |
173 |
FLayer layer = e.getAffectedLayer(); |
174 |
// Just in case we where listening to a group of layers being removed
|
175 |
// remove us from there
|
176 |
if (layer instanceof FLayers) { |
177 |
((FLayers) layer).removeLayerCollectionListener(this);
|
178 |
} |
179 |
// Remove the related table document, if any
|
180 |
if (layer instanceof FLyrVect) { |
181 |
getTableManager().removeTableDocument((FLyrVect) layer); |
182 |
// If the parent layers has not other child layers, for sure there
|
183 |
// are not related tables opened, don't need to listen
|
184 |
// LayerCollectionEvents anymore.
|
185 |
// TODO: remove us also when there are not any child layers with
|
186 |
// related table documents
|
187 |
FLayers layers = layer.getParentLayer(); |
188 |
if (layers != null && layers.getLayersCount() == 0) { |
189 |
layers.removeLayerCollectionListener(this);
|
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
195 |
// Nothing to do
|
196 |
} |
197 |
|
198 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
199 |
// Nothing to do
|
200 |
} |
201 |
|
202 |
public void layerRemoving(LayerCollectionEvent e) |
203 |
throws CancelationException {
|
204 |
// Nothing to do
|
205 |
} |
206 |
|
207 |
public void visibilityChanged(LayerCollectionEvent e) |
208 |
throws CancelationException {
|
209 |
// Nothing to do
|
210 |
} |
211 |
} |