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

History | View | Annotate | Download (4.63 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 java.util.List;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.messages.NotificationManager;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.ApplicationManager;
31
import org.gvsig.app.project.documents.view.ViewDocument;
32
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
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
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
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

    
51
    private static final Logger LOGGER = LoggerFactory
52
            .getLogger(ViewInvertSelection.class);
53
    private DefaultViewPanel vista;
54

    
55
    @Override
56
    public void initialize() {
57
        IconThemeHelper.registerIcon("action", "selection-reverse", this);
58
    }
59

    
60
    @Override
61
    public void postInitialize() {
62
    }
63

    
64
    @Override
65
    public void execute(String actionCommand) {
66
        ApplicationManager application = ApplicationLocator.getManager();
67

    
68
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
69
        if (view == null) {
70
            return ;
71
        }
72
        ViewDocument document = view.getViewDocument();
73

    
74
        MapContext mapa = document.getMapContext();
75

    
76
        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

    
95
    @Override
96
    public boolean isEnabled() {
97
        ApplicationManager application = ApplicationLocator.getManager();
98

    
99
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
100
        if (view == null) {
101
            return false;
102
        }
103
        ViewDocument document = view.getViewDocument();
104
        if( document == null ) {
105
            return false;
106
        }
107
        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
        }
115
        return false;
116
    }
117

    
118
    @Override
119
    public boolean isVisible() {
120
        ApplicationManager application = ApplicationLocator.getManager();
121

    
122
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
123
        if (view == null) {
124
            return false;
125
        }
126
        ViewDocument document = view.getViewDocument();
127
        return document.getMapContext().hasVectorLayers();
128
    }
129

    
130
}