Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ClearSelectionExtension.java @ 7738

History | View | Annotate | Download (5.59 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.NotificationManager;
51
import com.iver.andami.plugins.Extension;
52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.fmap.MapContext;
54
import com.iver.cit.gvsig.fmap.MapControl;
55
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
56
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
57
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
58
import com.iver.cit.gvsig.project.documents.table.gui.Table;
59
import com.iver.cit.gvsig.project.documents.view.IProjectView;
60
import com.iver.cit.gvsig.project.documents.view.gui.View;
61

    
62

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

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

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

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

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

    
102
                                                        try {
103
                                                                SelectableDataSource dataSource;
104

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

    
114
                                                }
115
                                        }
116
                                }
117

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

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

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

    
154
                return false;
155
        }
156

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

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