Statistics
| Revision:

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 @ 44035

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