Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ClearSelectionExtension.java @ 7011

History | View | Annotate | Download (5.61 KB)

1
/*
2
 * Created on 31-may-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.messages.NotificationListener;
51
import com.iver.andami.messages.NotificationManager;
52
import com.iver.andami.plugins.Extension;
53
import com.iver.cit.gvsig.fmap.DriverException;
54
import com.iver.cit.gvsig.fmap.MapContext;
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.layers.FLayer;
57
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
58
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
59
import com.iver.cit.gvsig.gui.Table;
60
import com.iver.cit.gvsig.gui.View;
61
import com.iver.cit.gvsig.project.ProjectTable;
62
import com.iver.cit.gvsig.project.ProjectView;
63

    
64

    
65
/**
66
 * Extensi?n encargada de limpiar la selecci?n.
67
 *
68
 * @author Vicente Caballero Navarro
69
 */
70
public class ClearSelectionExtension extends Extension {
71
        /**
72
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
73
         */
74
        public void execute(String s) {
75
                if (s.compareTo("DEL_SELECTION") == 0) {
76
                        boolean refresh = false;
77
                        com.iver.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow();
78

    
79
                        if (view instanceof View){
80
                                View vista = (View) view;
81
                                ProjectView model = vista.getModel();
82
                                MapContext mapa = model.getMapContext();
83
                                MapControl mapCtrl = vista.getMapControl();
84
                                for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
85
                                        /* JMV: Esto deberia de ser asi (Las capas son 'Selectable' o no)
86
                                         * pero de momento lo cambiamos para que use una capa vectorial
87
                                         *
88

89
                                        if (map.getLayers().getLayer(i) instanceof Selectable) {
90
                                                if (mapa.getLayers().getLayer(i).isActive()) {
91
                                                        Selectable selectable = (Selectable) mapa.getLayers().getLayer(i);
92

93
                                                        if (selectable.getSelection().cardinality() != 0) {
94
                                                                refresh = true;
95
                                                        }
96
                                selectable.clearSelection();
97
                                                }
98
                                        }
99

100
                                        */
101
                                        if (mapa.getLayers().getLayer(i) instanceof FLyrVect) {
102
                                                if (mapa.getLayers().getLayer(i).isActive()) {
103

    
104
                                                        try {
105
                                                                SelectableDataSource dataSource;
106

    
107
                                                                dataSource = ((FLyrVect)mapa.getLayers().getLayer(i)).getRecordset();
108
                                                                if (dataSource.getSelection().cardinality() != 0) {
109
                                                                        refresh = true;
110
                                                                }
111
                                                        dataSource.clearSelection();
112
                                                        } catch (DriverException e) {
113
                                                                e.printStackTrace();
114
                                                        }
115

    
116
                                                }
117
                                        }
118
                                }
119

    
120
                                if (refresh) {
121
                                        mapCtrl.drawMap(false);
122
                                }
123
                        }else if (view instanceof Table){
124
                                Table table = (Table) view;
125
                                ProjectTable model = table.getModel();
126
                                SelectableDataSource dataSource;
127
                                dataSource = model.getModelo().getRecordset();
128
                                if (dataSource.getSelection().cardinality() != 0) {
129
                                        refresh = true;
130
                                }
131
                            dataSource.clearSelection();
132
                            if (refresh) {
133
                                    table.refresh();
134
                                }
135
                        }
136
                }
137
    }
138

    
139
        /**
140
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
141
         */
142
        public boolean isVisible() {
143
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow();
144

    
145
                if (view == null) {
146
                        return false;
147
                }
148
                if (view instanceof View) {
149
                        MapContext mapa = ((View) view).getModel().getMapContext();
150
                        return mapa.getLayers().getLayersCount() > 0;
151
                }
152
                if (view instanceof Table) {
153
                        return true;
154
                }
155

    
156
                return false;
157
        }
158

    
159
        /**
160
         * @see com.iver.andami.plugins.IExtension#isEnabled()
161
         */
162
        public boolean isEnabled() {
163
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow();
164
                if (view == null) {
165
                        return false;
166
                }
167
                if (view instanceof View){
168
                        MapContext mapa = ((View) view).getMapControl().getMapContext();
169
                        for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
170
                                if (mapa.getLayers().getLayer(i) instanceof FLyrVect) {
171
                                        FLyrVect lyrVect = (FLyrVect) mapa.getLayers().getLayer(i); 
172
                                        if (lyrVect.isActive()) {
173
                                                if (lyrVect.isAvailable())
174
                                                        try {
175
                                                                if (lyrVect.getRecordset().getSelection().cardinality() > 0)
176
                                                                        return true;
177
                                                        } catch (DriverException e) {
178
                                                                e.printStackTrace();
179
                                                                NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e);
180
                                                        }
181
                                        }
182
                                }
183
                        }
184
                }
185
                if (view instanceof Table){
186
                        return ((Table)view).getSelectedRowIndices().length>0;
187
                }
188
                return false;
189
        }
190

    
191
        /**
192
         * @see com.iver.andami.plugins.IExtension#initialize()
193
         */
194
        public void initialize() {
195
        }
196
}