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 / ViewSelectionControls.java @ 44531

History | View | Annotate | Download (4.24 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.plugins.Extension;
27 41248 jjdelcerro
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
29 40435 jjdelcerro
import org.gvsig.app.project.documents.view.ViewDocument;
30 41248 jjdelcerro
import org.gvsig.app.project.documents.view.gui.IView;
31 44437 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.dal.feature.FeatureType;
33
import org.gvsig.fmap.mapcontext.layers.FLayer;
34
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
35 40435 jjdelcerro
import org.gvsig.fmap.mapcontrol.MapControl;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38
39
/**
40
 * Extension that handles the selection tools, selection tools have sense on
41
 * vectorial layers only.
42
 *
43
 */
44
public class ViewSelectionControls extends Extension {
45 41248 jjdelcerro
46 40435 jjdelcerro
    private static final Logger logger = LoggerFactory
47
            .getLogger(ViewSelectionControls.class);
48
49 41248 jjdelcerro
    public void initialize() {
50
        registerIcons();
51
    }
52 40435 jjdelcerro
53 41248 jjdelcerro
    private void registerIcons() {
54
        IconThemeHelper.registerIcon("action", "selection-select-by-rectangle", this);
55
        IconThemeHelper.registerIcon("action", "selection-select-by-polygon", this);
56
        IconThemeHelper.registerIcon("action", "selection-clear", this);
57
    }
58 40435 jjdelcerro
59 44437 jjdelcerro
    @Override
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 41248 jjdelcerro
            return;
66
        }
67 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
68
        MapControl mapCtrl = view.getMapControl();
69 40435 jjdelcerro
70 41248 jjdelcerro
        if (actionCommand.equalsIgnoreCase("selection-select-by-rectangle-view")) {
71
            mapCtrl.setTool("rectSelection");
72
            document.setModified(true);
73 40435 jjdelcerro
74 41248 jjdelcerro
        } else if (actionCommand.equalsIgnoreCase("selection-select-by-polygon")) {
75
            mapCtrl.setTool("polSelection");
76
            document.setModified(true);
77 40435 jjdelcerro
78 41248 jjdelcerro
        }
79
    }
80
81 44437 jjdelcerro
    @Override
82 41248 jjdelcerro
    public boolean isEnabled() {
83
        ApplicationManager application = ApplicationLocator.getManager();
84
85 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
86
        if (view == null) {
87 41248 jjdelcerro
            return false;
88
        }
89 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
90 44437 jjdelcerro
        if( document == null ) {
91
            return false;
92
        }
93
        boolean hasActiveVectorLayers = false;
94
        for (FLayer layer : document.getMapContext().getLayers()) {
95
            if( layer.isActive() && layer.isAvailable() && layer instanceof FLyrVect ) {
96
                try {
97
                    hasActiveVectorLayers = true;
98
                    FeatureStore store = ((FLyrVect)layer).getFeatureStore();
99
                    if( !store.getFeatureSelection().isAvailable() ) {
100
                        return false;
101
                    }
102
                } catch (Exception ex) {
103
                }
104
            }
105
        }
106
        return hasActiveVectorLayers ;
107 41248 jjdelcerro
    }
108
109 44437 jjdelcerro
    @Override
110 41248 jjdelcerro
    public boolean isVisible() {
111
        ApplicationManager application = ApplicationLocator.getManager();
112
113 41264 jjdelcerro
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
114
        if (view == null) {
115 41248 jjdelcerro
            return false;
116
        }
117 41264 jjdelcerro
        ViewDocument document = view.getViewDocument();
118 41248 jjdelcerro
        return document.getMapContext().hasVectorLayers();
119
    }
120
121 40435 jjdelcerro
}