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 @ 44600
History | View | Annotate | Download (5.81 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 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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import java.util.List; |
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.plugins.Extension; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
|
40 |
/**
|
41 |
* Extensi?n encargada de limpiar la selecci?n.
|
42 |
*
|
43 |
*/
|
44 |
public class ClearSelectionExtension extends Extension { |
45 |
|
46 |
|
47 |
@Override
|
48 |
public void execute(String s) { |
49 |
ApplicationManager application = ApplicationLocator.getManager(); |
50 |
|
51 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
52 |
if (view == null) { |
53 |
return;
|
54 |
} |
55 |
ViewDocument document = view.getViewDocument(); |
56 |
if (s.equalsIgnoreCase("selection-clear-view")) { |
57 |
MapControl mapCtrl = view.getMapControl(); |
58 |
FLayers layers = document.getMapContext().getLayers(); |
59 |
List<FLayer> activeLayers = layers.getLayers(
|
60 |
FLayers.LAYER_ACTIVE |
61 |
.and(FLayers.LAYER_AVALAIBLE) |
62 |
.and(FLayers.LAYER_FLYRVECT) |
63 |
); |
64 |
List<FLayer> layersToDeselect;
|
65 |
if (activeLayers.size() >= 1) { |
66 |
layersToDeselect = layers.getLayers( |
67 |
FLayers.LAYER_ACTIVE |
68 |
.and(FLayers.LAYER_AVALAIBLE) |
69 |
.and(FLayers.LAYER_FLYRVECT) |
70 |
.and(FLayers.LAYER_SELECTION_EMPTY.negate()) |
71 |
); |
72 |
} else {
|
73 |
layersToDeselect = layers.getLayers( |
74 |
FLayers.LAYER_AVALAIBLE |
75 |
.and(FLayers.LAYER_FLYRVECT) |
76 |
.and(FLayers.LAYER_SELECTION_EMPTY.negate()) |
77 |
); |
78 |
} |
79 |
clearSelectionOfView(layersToDeselect); |
80 |
mapCtrl.drawMap(false);
|
81 |
document.setModified(true);
|
82 |
} |
83 |
} |
84 |
|
85 |
private void clearSelectionOfView(List<FLayer> layers) { |
86 |
for (FLayer layer : layers) {
|
87 |
FeatureStore featureStore; |
88 |
featureStore = ((FLyrVect) layer).getFeatureStore(); |
89 |
try {
|
90 |
featureStore.getFeatureSelection().deselectAll(); |
91 |
} catch (DataException ex) {
|
92 |
ex.printStackTrace(); |
93 |
} |
94 |
} |
95 |
}; |
96 |
|
97 |
@Override
|
98 |
public boolean isVisible() { |
99 |
ApplicationManager application = ApplicationLocator.getManager(); |
100 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
101 |
if (view == null) { |
102 |
return false; |
103 |
} |
104 |
ViewDocument document = view.getViewDocument(); |
105 |
MapContext mapa = document.getMapContext(); |
106 |
return mapa.getLayers().getLayersCount() > 0; |
107 |
} |
108 |
|
109 |
@Override
|
110 |
public boolean isEnabled() { |
111 |
ApplicationManager application = ApplicationLocator.getManager(); |
112 |
|
113 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
114 |
if (view == null) { |
115 |
return false; |
116 |
} |
117 |
ViewDocument document = view.getViewDocument(); |
118 |
if( document == null ) { |
119 |
return false; |
120 |
} |
121 |
|
122 |
FLayers layers = document.getMapContext().getLayers(); |
123 |
List<FLayer> activeLayers = layers.getLayers(
|
124 |
FLayers.LAYER_ACTIVE |
125 |
); |
126 |
// if has active layers, at least one of them has to have selection
|
127 |
if (activeLayers.size()>=1) { |
128 |
List<FLayer> activeLayersWithSelection = layers.getLayers(
|
129 |
FLayers.LAYER_ACTIVE |
130 |
.and(FLayers.LAYER_AVALAIBLE) |
131 |
.and(FLayers.LAYER_FLYRVECT) |
132 |
.and(FLayers.LAYER_SELECTION_EMPTY.negate()) |
133 |
); |
134 |
if (activeLayersWithSelection.size()>=1) { |
135 |
return true; |
136 |
} else{
|
137 |
return false; |
138 |
} |
139 |
} |
140 |
|
141 |
List<FLayer> selectionLayers = layers.getLayers(
|
142 |
FLayers.LAYER_AVALAIBLE |
143 |
.and(FLayers.LAYER_FLYRVECT) |
144 |
.and(FLayers.LAYER_SELECTION_EMPTY.negate()) |
145 |
); |
146 |
// if there are not active layers, at least one of all has to have selection
|
147 |
if (selectionLayers.size() >= 1) { |
148 |
return true; |
149 |
} |
150 |
|
151 |
return false; |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
156 |
*/
|
157 |
@Override
|
158 |
public void initialize() { |
159 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
160 |
} |
161 |
} |