Statistics
| Revision:

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

History | View | Annotate | Download (6.63 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 8765 jjdelcerro
 * Revision 1.7.4.4  2006-11-15 00:08:08  jjdelcerro
47
 * *** empty log message ***
48
 *
49
 * Revision 1.13  2006/09/25 16:54:12  caballero
50 7569 caballero
 * invert selection
51
 *
52 8765 jjdelcerro
 * Revision 1.12  2006/09/20 13:17:40  jaume
53 7407 jaume
 * *** empty log message ***
54
 *
55 8765 jjdelcerro
 * Revision 1.11  2006/09/20 10:56:56  sbayarri
56
 * Refactorizaci?n clases View y ProjectView
57 7199 jmvivo
 *
58 8765 jjdelcerro
 * Revision 1.10  2006/09/15 10:40:03  caballero
59
 * extensibilidad de documentos
60
 *
61 7199 jmvivo
 * Revision 1.9  2006/09/11 16:14:15  fjp
62
 * Invertir seleccion. Falta subirlo al branch de la 1.0
63
 *
64
 * Revision 1.8  2006/09/11 06:53:13  fjp
65
 * Antes del parto
66
 *
67
 * Revision 1.7  2006/09/04 16:26:54  fjp
68
 * Seleccionar por pol?gono
69
 *
70
 * Revision 1.6  2006/08/29 07:56:27  cesar
71
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
72
 *
73
 * Revision 1.5  2006/08/29 07:21:08  cesar
74
 * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
75
 *
76
 * Revision 1.4  2006/08/29 07:13:53  cesar
77
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
78
 *
79
 * Revision 1.3  2006/08/18 08:40:04  jmvivo
80
 * Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
81
 *
82
 * Revision 1.2  2006/07/27 06:20:28  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.1  2006/07/26 09:53:05  jaume
86
 * separadas las herramientas de selecci?n del viewControls al ViewSelectionControls
87
 *
88
 *
89
 */
90 6513 jaume
package com.iver.cit.gvsig;
91
92
import org.apache.log4j.Logger;
93
94
import com.iver.andami.PluginServices;
95 7199 jmvivo
import com.iver.andami.messages.NotificationManager;
96 6513 jaume
import com.iver.andami.plugins.Extension;
97 7407 jaume
import com.iver.andami.ui.mdiManager.IWindow;
98 7199 jmvivo
import com.iver.cit.gvsig.fmap.DriverException;
99 6878 cesar
import com.iver.cit.gvsig.fmap.MapContext;
100 6513 jaume
import com.iver.cit.gvsig.fmap.MapControl;
101 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.FBitSet;
102 6513 jaume
import com.iver.cit.gvsig.fmap.layers.FLayer;
103 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.FLayers;
104 6513 jaume
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
105 7199 jmvivo
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
106 6513 jaume
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel;
107
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener;
108
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme;
109 8765 jjdelcerro
import com.iver.cit.gvsig.project.documents.view.IProjectView;
110
import com.iver.cit.gvsig.project.documents.view.gui.View;
111 6513 jaume
112
/**
113 7199 jmvivo
 * Extension that handles the selection tools, selection tools have sense on
114
 * vectorial layers only.
115 7407 jaume
 *
116 6513 jaume
 * @author jaume dominguez faus - jaume.dominguez@iver.es
117 7407 jaume
 *
118 6513 jaume
 */
119
public class ViewSelectionControls extends Extension {
120 7199 jmvivo
        private static Logger logger = Logger.getLogger(ViewControls.class
121
                        .getName());
122 6513 jaume
123
        public void initialize() {
124
                // TODO Auto-generated method stub
125
126
        }
127
128
        public void execute(String actionCommand) {
129 6880 cesar
                View vista = (View) PluginServices.getMDIManager().getActiveWindow();
130 8765 jjdelcerro
                IProjectView model = vista.getModel();
131 6878 cesar
                MapContext mapa = model.getMapContext();
132 6513 jaume
                MapControl mapCtrl = vista.getMapControl();
133
                logger.debug("Comand : " + actionCommand);
134 7199 jmvivo
                if (actionCommand.equals("SELRECT")) {
135 6513 jaume
                        mapCtrl.setTool("rectSelection");
136 7199 jmvivo
                } else if (actionCommand.equals("SELPOINT")) {
137 6513 jaume
                        mapCtrl.setTool("pointSelection");
138 7199 jmvivo
                } else if (actionCommand.equals("SELPOL")) {
139 7011 fjp
                        mapCtrl.setTool("polSelection");
140 7199 jmvivo
                } else if (actionCommand.equals("SELECTIONBYSHAPE")) {
141 6513 jaume
                        SelectionByTheme dlg = new SelectionByTheme();
142 7199 jmvivo
                        // FLayer[] layers = mapa.getLayers().getActives();
143
                        // int count = 0;
144 6513 jaume
                        dlg.setModel(new DefaultSelectionByThemeModel());
145
                        dlg.addSelectionListener(new MySelectionByThemeListener());
146 6880 cesar
                        PluginServices.getMDIManager().addWindow(dlg);
147 7199 jmvivo
                } else if (actionCommand.equals("INVERT_SELECTION")) {
148
                        for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
149
                                FLayer lyr = mapa.getLayers().getActives()[i];
150
                                if (lyr.isAvailable() && lyr instanceof FLyrVect) {
151
                                        FLyrVect lyrVect = (FLyrVect) lyr;
152
                                        SelectableDataSource sds;
153
                                        try {
154
                                                sds = lyrVect.getRecordset();
155
                                                FBitSet selectedRows = sds.getSelection();
156 7569 caballero
                                                selectedRows.flip(0, (int)sds.getRowCount());
157 7199 jmvivo
                                                sds.setSelection(selectedRows);
158
                                        } catch (DriverException e) {
159
                                                e.printStackTrace();
160
                                                NotificationManager.addError(e);
161 7569 caballero
                                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
162
                                                e.printStackTrace();
163
                                                NotificationManager.addError(e);
164 7199 jmvivo
                                        }
165
166
                                }
167
                        }
168 6513 jaume
                }
169
        }
170
171
        public boolean isEnabled() {
172 8765 jjdelcerro
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
173 6513 jaume
                if (f instanceof View) {
174
175
                        View vista = (View) f;
176 8765 jjdelcerro
                        IProjectView model = vista.getModel();
177 6878 cesar
                        MapContext mapa = model.getMapContext();
178 6513 jaume
179
                        for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
180
                                FLayer lyr = mapa.getLayers().getActives()[i];
181 6779 jmvivo
                                if (lyr.isAvailable() && lyr instanceof FLyrVect) {
182 6513 jaume
                                        return true;
183
                                }
184
                        }
185
                        return false;
186
                }
187
                return true;
188
        }
189
190
        public boolean isVisible() {
191 7407 jaume
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
192 6513 jaume
193 6533 jaume
                if (f != null && f instanceof View) {
194 6513 jaume
                        View vista = (View) f;
195 8765 jjdelcerro
                        IProjectView model = vista.getModel();
196 6878 cesar
                        MapContext mapa = model.getMapContext();
197 6513 jaume
198 7407 jaume
                        return hasVectorLayers(mapa.getLayers());
199
200
                }
201
                return false;
202
        }
203
204
        private boolean hasVectorLayers(FLayers layers) {
205
                for (int i = 0; i < layers.getLayersCount(); i++) {
206
                        FLayer lyr =layers.getLayer(i);
207
                        if (lyr instanceof FLayers)
208
                                return hasVectorLayers((FLayers) lyr);
209
210
                        else if (lyr instanceof FLyrVect) {
211
                                return true;
212 6513 jaume
                        }
213
                }
214 6533 jaume
                return false;
215 6513 jaume
        }
216 6533 jaume
}