Statistics
| Revision:

root / tags / v2_0_0_Build_2051 / extensions / org.gvsig.selectiontools.app / org.gvsig.selectiontools.app.extension / src / main / java / org / gvsig / selectiontools / app / extension / SelectAllExtension.java @ 38759

History | View | Annotate | Download (4.49 KB)

1
package org.gvsig.selectiontools.app.extension;
2

    
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

    
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.messages.NotificationManager;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.andami.ui.mdiManager.IWindow;
30
import org.gvsig.app.project.documents.view.ViewDocument;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.mapcontext.MapContext;
35
import org.gvsig.fmap.mapcontext.layers.FLayer;
36
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
37
import org.gvsig.fmap.mapcontrol.MapControl;
38

    
39
/**
40
 * <p>
41
 * Extension to add support for selecting all the features of a vector layer.
42
 * </p>
43
 * 
44
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
45
 */
46
public class SelectAllExtension extends Extension {
47

    
48
    /*
49
     * @see com.iver.andami.plugins.IExtension#initialize()
50
     */
51
    public void initialize() {
52
            IconThemeHelper.registerIcon("action", "selection-select-all", this);
53
    }
54

    
55
    /*
56
     * (non-Javadoc)
57
     * 
58
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
59
     */
60
    public void execute(String actionCommand) {
61
        if (actionCommand.equals("SELALL")) {
62
            IWindow view = PluginServices.getMDIManager().getActiveWindow();
63
            if (view instanceof IView) {
64
                MapControl mc = ((IView) view).getMapControl();
65
                FLayer[] activeLayers =
66
                    mc.getMapContext().getLayers().getActives();
67

    
68
                FLayer layer;
69

    
70
                for (int i = 0; i < activeLayers.length; i++) {
71
                    layer = activeLayers[i];
72

    
73
                    if ((layer.isAvailable()) && (layer instanceof FLyrVect)) {
74
                        FLyrVect lyrVect = (FLyrVect) layer;
75

    
76
                        try {
77
                            FeatureStore fs = lyrVect.getFeatureStore();
78
                            fs.getFeatureSelection().selectAll();
79
                        } catch (DataException e) {
80
                            NotificationManager.showMessageError("Data exception",
81
                                e);
82
                        }
83
                    }
84
                }
85
            }
86
        }
87
    }
88

    
89
    /*
90
     * @see com.iver.andami.plugins.IExtension#isVisible()
91
     */
92
    public boolean isVisible() {
93
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
94

    
95
        if (f == null) {
96
            return false;
97
        }
98

    
99
        if (f instanceof IView) {
100
            IView vista = (IView) f;
101
            ViewDocument viewDocument = vista.getViewDocument(); // .getModel();
102
            MapContext mapa = viewDocument.getMapContext();
103

    
104
            return mapa.getLayers().getLayersCount() > 0;
105
        }
106

    
107
        return false;
108
    }
109

    
110
    /*
111
     * @see com.iver.andami.plugins.IExtension#isEnabled()
112
     */
113
    public boolean isEnabled() {
114
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
115

    
116
        if (f == null) {
117
            return false;
118
        }
119

    
120
        if (f instanceof IView) {
121
            IView vista = (IView) f;
122
            ViewDocument viewDocument = vista.getViewDocument();
123
            MapContext mapa = viewDocument.getMapContext();
124

    
125
            FLayer layers[] = mapa.getLayers().getActives();
126
            FLayer layer;
127

    
128
            for (int i = 0; i < layers.length; i++) {
129
                layer = layers[i];
130

    
131
                if ((layer instanceof FLyrVect) && (layer.isAvailable())
132
                    && (layer.isActive()))
133
                    return true;
134
            }
135
        }
136

    
137
        return false;
138
    }
139
}