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 @ 44601
History | View | Annotate | Download (4.63 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40435 | 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 | 40435 | 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 | 40435 | 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 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | 44601 | omartinez | import java.util.List; |
26 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
27 | import org.gvsig.andami.messages.NotificationManager; |
||
28 | import org.gvsig.andami.plugins.Extension; |
||
29 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
30 | import org.gvsig.app.ApplicationManager; |
||
31 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
32 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
33 | 41264 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
34 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
37 | import org.gvsig.fmap.mapcontext.MapContext; |
||
38 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
39 | 44601 | omartinez | import org.gvsig.fmap.mapcontext.layers.FLayers; |
40 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
41 | import org.slf4j.Logger; |
||
42 | import org.slf4j.LoggerFactory; |
||
43 | |||
44 | /**
|
||
45 | * Extension that handles the selection tools, selection tools have sense on
|
||
46 | * vectorial layers only.
|
||
47 | *
|
||
48 | */
|
||
49 | public class ViewInvertSelection extends Extension { |
||
50 | 41248 | jjdelcerro | |
51 | 44601 | omartinez | private static final Logger LOGGER = LoggerFactory |
52 | 40435 | jjdelcerro | .getLogger(ViewInvertSelection.class); |
53 | 41248 | jjdelcerro | private DefaultViewPanel vista;
|
54 | 40435 | jjdelcerro | |
55 | 44601 | omartinez | @Override
|
56 | 41248 | jjdelcerro | public void initialize() { |
57 | IconThemeHelper.registerIcon("action", "selection-reverse", this); |
||
58 | } |
||
59 | 40435 | jjdelcerro | |
60 | 44601 | omartinez | @Override
|
61 | 41248 | jjdelcerro | public void postInitialize() { |
62 | } |
||
63 | 40435 | jjdelcerro | |
64 | 44601 | omartinez | @Override
|
65 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
66 | ApplicationManager application = ApplicationLocator.getManager(); |
||
67 | 40435 | jjdelcerro | |
68 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
69 | if (view == null) { |
||
70 | return ;
|
||
71 | 41248 | jjdelcerro | } |
72 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
73 | 40435 | jjdelcerro | |
74 | 41248 | jjdelcerro | MapContext mapa = document.getMapContext(); |
75 | 40435 | jjdelcerro | |
76 | 41248 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-reverse-view")) { |
77 | FLayer[] actives = mapa.getLayers().getActives();
|
||
78 | for (FLayer lyr : actives) {
|
||
79 | if (lyr.isAvailable() && lyr instanceof SingleLayer) { |
||
80 | SingleLayer lyrSingle = (SingleLayer) lyr; |
||
81 | DataStore ds = lyrSingle.getDataStore(); |
||
82 | if (ds instanceof FeatureStore) { |
||
83 | try {
|
||
84 | ((FeatureStore) ds).getFeatureSelection().reverse(); |
||
85 | document.setModified(true);
|
||
86 | } catch (DataException e) {
|
||
87 | NotificationManager.addError(e); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | 40435 | jjdelcerro | |
95 | 44437 | jjdelcerro | @Override
|
96 | 41248 | jjdelcerro | public boolean isEnabled() { |
97 | ApplicationManager application = ApplicationLocator.getManager(); |
||
98 | 40435 | jjdelcerro | |
99 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
100 | if (view == null) { |
||
101 | 41248 | jjdelcerro | return false; |
102 | } |
||
103 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
104 | 44437 | jjdelcerro | if( document == null ) { |
105 | return false; |
||
106 | } |
||
107 | 44601 | omartinez | List<FLayer> layers = document.getMapContext().getLayers().getLayers(
|
108 | FLayers.LAYER_ACTIVE |
||
109 | .and(FLayers.LAYER_AVALAIBLE) |
||
110 | .and(FLayers.LAYER_SELECTION_AVAILABLE) |
||
111 | ); |
||
112 | if (layers.size()>=1) { |
||
113 | return true; |
||
114 | 44437 | jjdelcerro | } |
115 | 44601 | omartinez | return false; |
116 | 41248 | jjdelcerro | } |
117 | 40435 | jjdelcerro | |
118 | 44601 | omartinez | @Override
|
119 | 41248 | jjdelcerro | public boolean isVisible() { |
120 | ApplicationManager application = ApplicationLocator.getManager(); |
||
121 | 40435 | jjdelcerro | |
122 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
123 | if (view == null) { |
||
124 | 41248 | jjdelcerro | return false; |
125 | } |
||
126 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
127 | 41248 | jjdelcerro | return document.getMapContext().hasVectorLayers();
|
128 | } |
||
129 | |||
130 | 40435 | jjdelcerro | } |