Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.selectiontools.app / org.gvsig.selectiontools.app.mainplugin / src / main / java / org / gvsig / selectiontools / app / extension / SelectAllExtension.java @ 43938

History | View | Annotate | Download (3.8 KB)

1 40556 jjdelcerro
/**
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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
package org.gvsig.selectiontools.app.extension;
25
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31 41264 jjdelcerro
import org.gvsig.app.ApplicationLocator;
32
import org.gvsig.app.ApplicationManager;
33 40435 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
34
import org.gvsig.app.project.documents.view.gui.IView;
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.vectorial.FLyrVect;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
42
/**
43
 * Extension to add support for selecting all the features of a vector layer.
44
 *
45
 */
46
public class SelectAllExtension extends Extension {
47
48
    public void initialize() {
49
            IconThemeHelper.registerIcon("action", "selection-select-all", this);
50
    }
51
52
    public void execute(String actionCommand) {
53
        if (actionCommand.equals("SELALL")) {
54
            IWindow view = PluginServices.getMDIManager().getActiveWindow();
55
            if (view instanceof IView) {
56
                MapControl mc = ((IView) view).getMapControl();
57
                FLayer[] activeLayers =
58
                    mc.getMapContext().getLayers().getActives();
59
60
                FLayer layer;
61
62
                for (int i = 0; i < activeLayers.length; i++) {
63
                    layer = activeLayers[i];
64
65
                    if ((layer.isAvailable()) && (layer instanceof FLyrVect)) {
66
                        FLyrVect lyrVect = (FLyrVect) layer;
67
68
                        try {
69
                            FeatureStore fs = lyrVect.getFeatureStore();
70
                            fs.getFeatureSelection().selectAll();
71
                        } catch (DataException e) {
72
                            NotificationManager.showMessageError("Data exception",
73
                                e);
74
                        }
75
                    }
76
                }
77
            }
78
        }
79
    }
80
81
    public boolean isVisible() {
82 41264 jjdelcerro
        ApplicationManager application = ApplicationLocator.getManager();
83 40435 jjdelcerro
84 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
85
        if (view == null) {
86 40435 jjdelcerro
            return false;
87
        }
88 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
89
        MapContext mapa = document.getMapContext();
90
        return mapa.getLayers().getLayersCount() > 0;
91 40435 jjdelcerro
    }
92
93
    public boolean isEnabled() {
94 41264 jjdelcerro
        ApplicationManager application = ApplicationLocator.getManager();
95 40435 jjdelcerro
96 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
97
        if (view == null) {
98 40435 jjdelcerro
            return false;
99
        }
100 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
101
        return document.getMapContext().hasActiveVectorLayers();
102 40435 jjdelcerro
    }
103
}