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 @ 44259
History | View | Annotate | Download (7.01 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 42838 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 42838 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 42838 | jjdelcerro | * 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.
|
||
19 | 40558 | jjdelcerro | *
|
20 | 42838 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | import org.gvsig.andami.IconThemeHelper; |
||
26 | import org.gvsig.andami.PluginServices; |
||
27 | import org.gvsig.andami.plugins.Extension; |
||
28 | 42838 | jjdelcerro | 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; |
||
33 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.table.TableDocument; |
34 | import org.gvsig.app.project.documents.table.TableManager; |
||
35 | 42838 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
36 | import org.gvsig.app.project.documents.view.ViewManager; |
||
37 | import org.gvsig.fmap.mapcontext.MapContext; |
||
38 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.CancelationException; |
39 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
40 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
41 | import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
||
42 | import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
||
43 | import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
||
44 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
45 | 42838 | jjdelcerro | import org.gvsig.tools.util.ArrayUtils; |
46 | 40435 | jjdelcerro | |
47 | /**
|
||
48 | * Extensi?n que abre las tablas asociadas a las vistas.
|
||
49 | 42835 | dmartinezizquierdo | *
|
50 | 40435 | jjdelcerro | */
|
51 | public class ShowTable extends Extension implements LayerCollectionListener { |
||
52 | |||
53 | 42838 | jjdelcerro | @Override
|
54 | 40435 | jjdelcerro | public boolean isEnabled() { |
55 | 42838 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
56 | ViewDocument doc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
||
57 | if (doc == null) { |
||
58 | 40435 | jjdelcerro | return false; |
59 | } |
||
60 | 42838 | jjdelcerro | MapContext mapContext = doc.getMapContext(); |
61 | return mapContext.hasActiveVectorLayers();
|
||
62 | 40435 | jjdelcerro | } |
63 | |||
64 | 42838 | jjdelcerro | @Override
|
65 | 40435 | jjdelcerro | public boolean isVisible() { |
66 | 42838 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
67 | ViewDocument doc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
||
68 | if (doc == null) { |
||
69 | 40435 | jjdelcerro | return false; |
70 | } |
||
71 | 42838 | jjdelcerro | MapContext mapContext = doc.getMapContext(); |
72 | return mapContext.hasVectorLayers();
|
||
73 | } |
||
74 | 40435 | jjdelcerro | |
75 | 42838 | jjdelcerro | @Override
|
76 | public void execute(String command) { |
||
77 | this.execute(command, null); |
||
78 | } |
||
79 | 42835 | dmartinezizquierdo | |
80 | 42838 | jjdelcerro | @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(); |
||
95 | 42835 | dmartinezizquierdo | |
96 | 42838 | jjdelcerro | 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); |
||
110 | 42835 | dmartinezizquierdo | } |
111 | 42838 | jjdelcerro | IWindow tablePanel = tableManager.getMainWindow(tableDoc); |
112 | tableDoc.setModified(true);
|
||
113 | application.getUIManager().addWindow(tablePanel); |
||
114 | 42835 | dmartinezizquierdo | } |
115 | } |
||
116 | } |
||
117 | 40435 | jjdelcerro | } |
118 | |||
119 | private TableManager getTableManager() {
|
||
120 | 42838 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
121 | DocumentManager tableManager = application.getProjectManager().getDocumentManager( |
||
122 | TableManager.TYPENAME |
||
123 | ); |
||
124 | return (TableManager) tableManager;
|
||
125 | 40435 | jjdelcerro | } |
126 | |||
127 | 42838 | jjdelcerro | @Override
|
128 | 40435 | jjdelcerro | public void initialize() { |
129 | 42838 | jjdelcerro | IconThemeHelper.registerIcon("action", "layer-show-attributes-table", this); |
130 | 40435 | jjdelcerro | } |
131 | |||
132 | 42838 | jjdelcerro | @Override
|
133 | 40435 | jjdelcerro | public void layerAdded(LayerCollectionEvent e) { |
134 | // Nothing to do
|
||
135 | } |
||
136 | |||
137 | 42838 | jjdelcerro | @Override
|
138 | 40435 | jjdelcerro | public void layerMoved(LayerPositionEvent e) { |
139 | // Nothing to do
|
||
140 | } |
||
141 | |||
142 | 42838 | jjdelcerro | @Override
|
143 | 40435 | jjdelcerro | public void layerRemoved(LayerCollectionEvent e) { |
144 | FLayer layer = e.getAffectedLayer(); |
||
145 | // Just in case we where listening to a group of layers being removed
|
||
146 | // remove us from there
|
||
147 | if (layer instanceof FLayers) { |
||
148 | ((FLayers) layer).removeLayerCollectionListener(this);
|
||
149 | } |
||
150 | // Remove the related table document, if any
|
||
151 | if (layer instanceof FLyrVect) { |
||
152 | getTableManager().removeTableDocument((FLyrVect) layer); |
||
153 | // If the parent layers has not other child layers, for sure there
|
||
154 | // are not related tables opened, don't need to listen
|
||
155 | // LayerCollectionEvents anymore.
|
||
156 | // TODO: remove us also when there are not any child layers with
|
||
157 | // related table documents
|
||
158 | FLayers layers = layer.getParentLayer(); |
||
159 | if (layers != null && layers.getLayersCount() == 0) { |
||
160 | layers.removeLayerCollectionListener(this);
|
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | |||
165 | 42838 | jjdelcerro | @Override
|
166 | 40435 | jjdelcerro | public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
167 | // Nothing to do
|
||
168 | } |
||
169 | |||
170 | 42838 | jjdelcerro | @Override
|
171 | 40435 | jjdelcerro | public void layerMoving(LayerPositionEvent e) throws CancelationException { |
172 | // Nothing to do
|
||
173 | } |
||
174 | |||
175 | 42838 | jjdelcerro | @Override
|
176 | 40435 | jjdelcerro | public void layerRemoving(LayerCollectionEvent e) |
177 | 42838 | jjdelcerro | throws CancelationException {
|
178 | 40435 | jjdelcerro | // Nothing to do
|
179 | } |
||
180 | |||
181 | 42838 | jjdelcerro | @Override
|
182 | 40435 | jjdelcerro | public void visibilityChanged(LayerCollectionEvent e) |
183 | 42838 | jjdelcerro | throws CancelationException {
|
184 | 40435 | jjdelcerro | // Nothing to do
|
185 | } |
||
186 | } |