svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ClearSelectionExtension.java @ 40596
History | View | Annotate | Download (5.15 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 |
|
25 |
package org.gvsig.app.extension; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.gvsig.app.project.documents.AbstractDocument; |
32 |
import org.gvsig.app.project.documents.view.ViewDocument; |
33 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.exception.ReadException; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.mapcontext.MapContext; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
40 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
41 |
import org.gvsig.fmap.mapcontrol.MapControl; |
42 |
|
43 |
|
44 |
|
45 |
/**
|
46 |
* Extensi?n encargada de limpiar la selecci?n.
|
47 |
*
|
48 |
* @author Vicente Caballero Navarro
|
49 |
*/
|
50 |
public class ClearSelectionExtension extends Extension { |
51 |
/**
|
52 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
53 |
*/
|
54 |
public void execute(String s) { |
55 |
if (s.equalsIgnoreCase("selection-clear-view") ) { |
56 |
boolean refresh = false; |
57 |
org.gvsig.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow(); |
58 |
|
59 |
if (view instanceof AbstractViewPanel){ |
60 |
AbstractViewPanel vista = (AbstractViewPanel) view; |
61 |
ViewDocument model = vista.getModel(); |
62 |
MapContext mapa = model.getMapContext(); |
63 |
MapControl mapCtrl = vista.getMapControl(); |
64 |
FLayers layers = mapa.getLayers(); |
65 |
refresh = clearSelectionOfView(layers); |
66 |
|
67 |
if (refresh) {
|
68 |
mapCtrl.drawMap(false);
|
69 |
} |
70 |
((AbstractDocument)vista.getModel()).setModified(true); |
71 |
} |
72 |
} |
73 |
} |
74 |
|
75 |
|
76 |
private boolean clearSelectionOfView(FLayers layers){ |
77 |
boolean refresh=false; |
78 |
|
79 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
80 |
FLayer lyr =layers.getLayer(i); |
81 |
if (lyr instanceof FLayers){ |
82 |
refresh = refresh || clearSelectionOfView((FLayers) lyr); |
83 |
} else if (lyr instanceof FLyrVect) { |
84 |
FLyrVect lyrVect = (FLyrVect) lyr; |
85 |
if (lyrVect.isActive()) {
|
86 |
try {
|
87 |
FeatureStore featureStore; |
88 |
|
89 |
featureStore = ((FLyrVect)lyr).getFeatureStore(); |
90 |
if (featureStore.getFeatureSelection().getSize() != 0) { |
91 |
refresh = true;
|
92 |
} |
93 |
featureStore.getFeatureSelection().deselectAll(); |
94 |
} catch (ReadException e) {
|
95 |
e.printStackTrace(); |
96 |
} catch (DataException e) {
|
97 |
// TODO Auto-generated catch block
|
98 |
e.printStackTrace(); |
99 |
} |
100 |
} |
101 |
} |
102 |
} |
103 |
return refresh;
|
104 |
} |
105 |
/**
|
106 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
107 |
*/
|
108 |
public boolean isVisible() { |
109 |
org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
110 |
|
111 |
if (view == null) { |
112 |
return false; |
113 |
} |
114 |
if (view instanceof AbstractViewPanel) { |
115 |
MapContext mapa = ((AbstractViewPanel) view).getModel().getMapContext(); |
116 |
return mapa.getLayers().getLayersCount() > 0; |
117 |
} |
118 |
|
119 |
return false; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
124 |
*/
|
125 |
public boolean isEnabled() { |
126 |
org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
127 |
if (view == null) { |
128 |
return false; |
129 |
} |
130 |
if (view instanceof AbstractViewPanel){ |
131 |
MapContext mapa = ((AbstractViewPanel) view).getMapControl().getMapContext(); |
132 |
return hasVectorLayersWithSelection(mapa.getLayers());
|
133 |
} |
134 |
return false; |
135 |
} |
136 |
|
137 |
private boolean hasVectorLayersWithSelection(FLayers layers) { |
138 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
139 |
FLayer lyr =layers.getLayer(i); |
140 |
if (lyr instanceof FLayers){ |
141 |
if (hasVectorLayersWithSelection((FLayers) lyr)){
|
142 |
return true; |
143 |
} |
144 |
} else if (lyr instanceof FLyrVect) { |
145 |
FLyrVect lyrVect = (FLyrVect) lyr; |
146 |
if (lyrVect.isActive()) {
|
147 |
if (lyrVect.isAvailable()){
|
148 |
try {
|
149 |
if (lyrVect.getFeatureStore().getFeatureSelection()
|
150 |
.getSize() > 0) {
|
151 |
return true; |
152 |
} |
153 |
} catch (DataException e) {
|
154 |
e.printStackTrace(); |
155 |
NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
156 |
} |
157 |
} |
158 |
} |
159 |
} |
160 |
} |
161 |
return false; |
162 |
} |
163 |
|
164 |
/**
|
165 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
166 |
*/
|
167 |
public void initialize() { |
168 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
169 |
} |
170 |
} |