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 @ 44276
History | View | Annotate | Download (5.69 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 org.gvsig.andami.IconThemeHelper; |
26 |
import org.gvsig.andami.messages.NotificationManager; |
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.exception.ReadException; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.mapcontext.MapContext; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
40 |
|
41 |
/**
|
42 |
* Extensi?n encargada de limpiar la selecci?n.
|
43 |
*
|
44 |
*/
|
45 |
public class ClearSelectionExtension extends Extension { |
46 |
|
47 |
|
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 |
MapContext mapa = document.getMapContext(); |
58 |
MapControl mapCtrl = view.getMapControl(); |
59 |
FLayers layers = mapa.getLayers(); |
60 |
boolean refresh = clearSelectionOfView(layers);
|
61 |
if (refresh) {
|
62 |
mapCtrl.drawMap(false);
|
63 |
} |
64 |
document.setModified(true);
|
65 |
} |
66 |
} |
67 |
|
68 |
private boolean clearSelectionOfView(FLayers layers) { |
69 |
boolean refresh = false; |
70 |
|
71 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
72 |
FLayer lyr = layers.getLayer(i); |
73 |
if (lyr instanceof FLayers) { |
74 |
refresh = refresh || clearSelectionOfView((FLayers) lyr); |
75 |
} else if (lyr instanceof FLyrVect) { |
76 |
FLyrVect lyrVect = (FLyrVect) lyr; |
77 |
if (lyrVect.isActive()) {
|
78 |
try {
|
79 |
FeatureStore featureStore; |
80 |
|
81 |
featureStore = ((FLyrVect) lyr).getFeatureStore(); |
82 |
if (!featureStore.getFeatureSelection().isEmpty()) {
|
83 |
refresh = true;
|
84 |
} |
85 |
featureStore.getFeatureSelection().deselectAll(); |
86 |
} catch (ReadException e) {
|
87 |
e.printStackTrace(); |
88 |
} catch (DataException e) {
|
89 |
// TODO Auto-generated catch block
|
90 |
e.printStackTrace(); |
91 |
} |
92 |
} |
93 |
} |
94 |
} |
95 |
return refresh;
|
96 |
} |
97 |
|
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 |
public boolean isEnabled() { |
110 |
ApplicationManager application = ApplicationLocator.getManager(); |
111 |
|
112 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
113 |
if (view == null) { |
114 |
return false; |
115 |
} |
116 |
ViewDocument document = view.getViewDocument(); |
117 |
MapContext mapa = document.getMapContext(); |
118 |
return hasVectorLayersWithSelection(mapa.getLayers());
|
119 |
} |
120 |
|
121 |
private boolean hasVectorLayersWithSelection(FLayers layers) { |
122 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
123 |
FLayer lyr = layers.getLayer(i); |
124 |
if (lyr instanceof FLayers) { |
125 |
if (hasVectorLayersWithSelection((FLayers) lyr)) {
|
126 |
return true; |
127 |
} |
128 |
} else if (lyr instanceof FLyrVect) { |
129 |
FLyrVect lyrVect = (FLyrVect) lyr; |
130 |
if (lyrVect.isActive()) {
|
131 |
if (lyrVect.isAvailable()) {
|
132 |
try {
|
133 |
if (!lyrVect.getFeatureStore().getFeatureSelection().isEmpty()) {
|
134 |
return true; |
135 |
} |
136 |
} catch (DataException e) {
|
137 |
e.printStackTrace(); |
138 |
NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto", e); |
139 |
} |
140 |
} |
141 |
} |
142 |
} |
143 |
} |
144 |
return false; |
145 |
} |
146 |
|
147 |
/**
|
148 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
149 |
*/
|
150 |
public void initialize() { |
151 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
152 |
} |
153 |
} |