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 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 41248 | 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 | 41248 | 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 | 41248 | 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 | 41248 | 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 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.app.extension; |
24 | |||
25 | 44600 | omartinez | import java.util.List; |
26 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
27 | import org.gvsig.andami.plugins.Extension; |
||
28 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
29 | import org.gvsig.app.ApplicationManager; |
||
30 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
31 | 41248 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
32 | 40435 | jjdelcerro | 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 | 41264 | jjdelcerro | |
47 | 44600 | omartinez | @Override
|
48 | 41248 | jjdelcerro | public void execute(String s) { |
49 | ApplicationManager application = ApplicationLocator.getManager(); |
||
50 | 40435 | jjdelcerro | |
51 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
52 | if (view == null) { |
||
53 | 41248 | jjdelcerro | return;
|
54 | 40435 | jjdelcerro | } |
55 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
56 | 41248 | jjdelcerro | if (s.equalsIgnoreCase("selection-clear-view")) { |
57 | 41264 | jjdelcerro | MapControl mapCtrl = view.getMapControl(); |
58 | 44600 | omartinez | 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 | 41248 | jjdelcerro | } |
79 | 44600 | omartinez | clearSelectionOfView(layersToDeselect); |
80 | mapCtrl.drawMap(false);
|
||
81 | 41248 | jjdelcerro | document.setModified(true);
|
82 | } |
||
83 | 40435 | jjdelcerro | } |
84 | |||
85 | 44600 | omartinez | 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 | 41248 | jjdelcerro | } |
94 | } |
||
95 | 44600 | omartinez | }; |
96 | 40435 | jjdelcerro | |
97 | 44600 | omartinez | @Override
|
98 | 41248 | jjdelcerro | public boolean isVisible() { |
99 | ApplicationManager application = ApplicationLocator.getManager(); |
||
100 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
101 | if (view == null) { |
||
102 | 41248 | jjdelcerro | return false; |
103 | } |
||
104 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
105 | 41248 | jjdelcerro | MapContext mapa = document.getMapContext(); |
106 | return mapa.getLayers().getLayersCount() > 0; |
||
107 | } |
||
108 | 40435 | jjdelcerro | |
109 | 44600 | omartinez | @Override
|
110 | 41248 | jjdelcerro | public boolean isEnabled() { |
111 | ApplicationManager application = ApplicationLocator.getManager(); |
||
112 | 40435 | jjdelcerro | |
113 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
114 | if (view == null) { |
||
115 | 41248 | jjdelcerro | return false; |
116 | } |
||
117 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
118 | 44437 | jjdelcerro | if( document == null ) { |
119 | return false; |
||
120 | } |
||
121 | 44600 | omartinez | |
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 | 44437 | jjdelcerro | } |
139 | } |
||
140 | 41248 | jjdelcerro | |
141 | 44600 | omartinez | 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 | 41248 | jjdelcerro | } |
150 | 44600 | omartinez | |
151 | 41248 | jjdelcerro | return false; |
152 | } |
||
153 | |||
154 | /**
|
||
155 | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
||
156 | */
|
||
157 | 44600 | omartinez | @Override
|
158 | 41248 | jjdelcerro | public void initialize() { |
159 | IconThemeHelper.registerIcon("action", "edit-clear", this); |
||
160 | } |
||
161 | 40435 | jjdelcerro | } |