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 / ViewInvertSelection.java @ 41248
History | View | Annotate | Download (3.99 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.DefaultViewPanel; |
32 |
import org.gvsig.fmap.dal.DataStore; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
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.operations.SingleLayer; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
/**
|
42 |
* Extension that handles the selection tools, selection tools have sense on
|
43 |
* vectorial layers only.
|
44 |
*
|
45 |
*/
|
46 |
public class ViewInvertSelection extends Extension { |
47 |
|
48 |
private static final Logger logger = LoggerFactory |
49 |
.getLogger(ViewInvertSelection.class); |
50 |
private DefaultViewPanel vista;
|
51 |
|
52 |
public void initialize() { |
53 |
IconThemeHelper.registerIcon("action", "selection-reverse", this); |
54 |
} |
55 |
|
56 |
public void postInitialize() { |
57 |
} |
58 |
|
59 |
public void execute(String actionCommand) { |
60 |
ApplicationManager application = ApplicationLocator.getManager(); |
61 |
|
62 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class); |
63 |
if (document == null) { |
64 |
return;
|
65 |
} |
66 |
|
67 |
MapContext mapa = document.getMapContext(); |
68 |
|
69 |
if (actionCommand.equalsIgnoreCase("selection-reverse-view")) { |
70 |
FLayer[] actives = mapa.getLayers().getActives();
|
71 |
for (FLayer lyr : actives) {
|
72 |
if (lyr.isAvailable() && lyr instanceof SingleLayer) { |
73 |
SingleLayer lyrSingle = (SingleLayer) lyr; |
74 |
DataStore ds = lyrSingle.getDataStore(); |
75 |
if (ds instanceof FeatureStore) { |
76 |
try {
|
77 |
((FeatureStore) ds).getFeatureSelection().reverse(); |
78 |
document.setModified(true);
|
79 |
} catch (DataException e) {
|
80 |
NotificationManager.addError(e); |
81 |
} |
82 |
} |
83 |
} |
84 |
} |
85 |
} |
86 |
} |
87 |
|
88 |
public boolean isEnabled() { |
89 |
ApplicationManager application = ApplicationLocator.getManager(); |
90 |
|
91 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class); |
92 |
if (document == null) { |
93 |
return false; |
94 |
} |
95 |
return document.getMapContext().hasActiveVectorLayers();
|
96 |
} |
97 |
|
98 |
public boolean isVisible() { |
99 |
ApplicationManager application = ApplicationLocator.getManager(); |
100 |
|
101 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class); |
102 |
if (document == null) { |
103 |
return false; |
104 |
} |
105 |
return document.getMapContext().hasVectorLayers();
|
106 |
} |
107 |
|
108 |
} |