Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / ViewSelectionControls.java @ 8745

History | View | Annotate | Download (6.49 KB)

1 6513 jaume
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
42
/* CVS MESSAGES:
43 7199 jmvivo
 *
44
 * $Id$
45
 * $Log$
46 7569 caballero
 * Revision 1.7.4.3  2006-09-25 16:08:30  caballero
47
 * invert selection
48
 *
49
 * Revision 1.7.4.2  2006/09/20 13:22:30  jaume
50 7407 jaume
 * *** empty log message ***
51
 *
52
 * Revision 1.7.4.1  2006/09/12 07:22:07  jmvivo
53 7199 jmvivo
 * A?adido comando InvertSelection. Portados cambios desde la rama HEAD.
54
 *
55
 * Revision 1.9  2006/09/11 16:14:15  fjp
56
 * Invertir seleccion. Falta subirlo al branch de la 1.0
57
 *
58
 * Revision 1.8  2006/09/11 06:53:13  fjp
59
 * Antes del parto
60
 *
61
 * Revision 1.7  2006/09/04 16:26:54  fjp
62
 * Seleccionar por pol?gono
63
 *
64
 * Revision 1.6  2006/08/29 07:56:27  cesar
65
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
66
 *
67
 * Revision 1.5  2006/08/29 07:21:08  cesar
68
 * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
69
 *
70
 * Revision 1.4  2006/08/29 07:13:53  cesar
71
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
72
 *
73
 * Revision 1.3  2006/08/18 08:40:04  jmvivo
74
 * Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
75
 *
76
 * Revision 1.2  2006/07/27 06:20:28  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.1  2006/07/26 09:53:05  jaume
80
 * separadas las herramientas de selecci?n del viewControls al ViewSelectionControls
81
 *
82
 *
83
 */
84 6513 jaume
package com.iver.cit.gvsig;
85
86
import org.apache.log4j.Logger;
87
88
import com.iver.andami.PluginServices;
89 7199 jmvivo
import com.iver.andami.messages.NotificationManager;
90 6513 jaume
import com.iver.andami.plugins.Extension;
91 7407 jaume
import com.iver.andami.ui.mdiManager.IWindow;
92 7199 jmvivo
import com.iver.cit.gvsig.fmap.DriverException;
93 6878 cesar
import com.iver.cit.gvsig.fmap.MapContext;
94 6513 jaume
import com.iver.cit.gvsig.fmap.MapControl;
95 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.FBitSet;
96 6513 jaume
import com.iver.cit.gvsig.fmap.layers.FLayer;
97 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.FLayers;
98 6513 jaume
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
99 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
100 6513 jaume
import com.iver.cit.gvsig.gui.View;
101
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel;
102
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener;
103
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme;
104
import com.iver.cit.gvsig.project.ProjectView;
105
106
/**
107 7199 jmvivo
 * Extension that handles the selection tools, selection tools have sense on
108
 * vectorial layers only.
109 7407 jaume
 *
110 6513 jaume
 * @author jaume dominguez faus - jaume.dominguez@iver.es
111 7407 jaume
 *
112 6513 jaume
 */
113
public class ViewSelectionControls extends Extension {
114 7199 jmvivo
        private static Logger logger = Logger.getLogger(ViewControls.class
115
                        .getName());
116 6513 jaume
117
        public void initialize() {
118
                // TODO Auto-generated method stub
119
120
        }
121
122
        public void execute(String actionCommand) {
123 6880 cesar
                View vista = (View) PluginServices.getMDIManager().getActiveWindow();
124 6513 jaume
                ProjectView model = vista.getModel();
125 6878 cesar
                MapContext mapa = model.getMapContext();
126 6513 jaume
                MapControl mapCtrl = vista.getMapControl();
127
                logger.debug("Comand : " + actionCommand);
128 7199 jmvivo
                if (actionCommand.equals("SELRECT")) {
129 6513 jaume
                        mapCtrl.setTool("rectSelection");
130 7199 jmvivo
                } else if (actionCommand.equals("SELPOINT")) {
131 6513 jaume
                        mapCtrl.setTool("pointSelection");
132 7199 jmvivo
                } else if (actionCommand.equals("SELPOL")) {
133 7011 fjp
                        mapCtrl.setTool("polSelection");
134 7199 jmvivo
                } else if (actionCommand.equals("SELECTIONBYSHAPE")) {
135 6513 jaume
                        SelectionByTheme dlg = new SelectionByTheme();
136 7199 jmvivo
                        // FLayer[] layers = mapa.getLayers().getActives();
137
                        // int count = 0;
138 6513 jaume
                        dlg.setModel(new DefaultSelectionByThemeModel());
139
                        dlg.addSelectionListener(new MySelectionByThemeListener());
140 6880 cesar
                        PluginServices.getMDIManager().addWindow(dlg);
141 7199 jmvivo
                } else if (actionCommand.equals("INVERT_SELECTION")) {
142
                        for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
143
                                FLayer lyr = mapa.getLayers().getActives()[i];
144
                                if (lyr.isAvailable() && lyr instanceof FLyrVect) {
145
                                        FLyrVect lyrVect = (FLyrVect) lyr;
146
                                        SelectableDataSource sds;
147
                                        try {
148
                                                sds = lyrVect.getRecordset();
149
                                                FBitSet selectedRows = sds.getSelection();
150 7569 caballero
                                                selectedRows.flip(0, (int)sds.getRowCount());
151 7199 jmvivo
                                                sds.setSelection(selectedRows);
152
                                        } catch (DriverException e) {
153
                                                e.printStackTrace();
154
                                                NotificationManager.addError(e);
155 7569 caballero
                                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
156
                                                e.printStackTrace();
157
                                                NotificationManager.addError(e);
158 7199 jmvivo
                                        }
159
160
                                }
161
                        }
162 6513 jaume
                }
163
        }
164
165
        public boolean isEnabled() {
166 7199 jmvivo
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
167
                                .getMDIManager().getActiveWindow();
168 6513 jaume
                if (f instanceof View) {
169
170
                        View vista = (View) f;
171
                        ProjectView model = vista.getModel();
172 6878 cesar
                        MapContext mapa = model.getMapContext();
173 6513 jaume
174
                        for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
175
                                FLayer lyr = mapa.getLayers().getActives()[i];
176 6779 jmvivo
                                if (lyr.isAvailable() && lyr instanceof FLyrVect) {
177 6513 jaume
                                        return true;
178
                                }
179
                        }
180
                        return false;
181
                }
182
                return true;
183
        }
184
185
        public boolean isVisible() {
186 7407 jaume
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
187 6513 jaume
188 6533 jaume
                if (f != null && f instanceof View) {
189 6513 jaume
                        View vista = (View) f;
190
                        ProjectView model = vista.getModel();
191 6878 cesar
                        MapContext mapa = model.getMapContext();
192 6513 jaume
193 7407 jaume
                        return hasVectorLayers(mapa.getLayers());
194
195
                }
196
                return false;
197
        }
198
199
        private boolean hasVectorLayers(FLayers layers) {
200
                for (int i = 0; i < layers.getLayersCount(); i++) {
201
                        FLayer lyr =layers.getLayer(i);
202
                        if (lyr instanceof FLayers)
203
                                return hasVectorLayers((FLayers) lyr);
204
205
                        else if (lyr instanceof FLyrVect) {
206
                                return true;
207 6513 jaume
                        }
208
                }
209 6533 jaume
                return false;
210 6513 jaume
        }
211 6533 jaume
}