Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / ExploitExtension.java @ 38243

History | View | Annotate | Download (6.29 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
package org.gvsig.editing;
42

    
43
import javax.swing.JOptionPane;
44

    
45
import com.mysql.jdbc.Messages;
46

    
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

    
50
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.NotificationManager;
52
import org.gvsig.andami.plugins.Extension;
53
import org.gvsig.app.ApplicationLocator;
54
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
55
import org.gvsig.editing.gui.cad.tools.ExploitCADTool;
56
import org.gvsig.editing.layers.VectorialLayerEdited;
57
import org.gvsig.fmap.dal.DALLocator;
58
import org.gvsig.fmap.dal.DataManager;
59
import org.gvsig.fmap.dal.DataStoreProviderFactory;
60
import org.gvsig.fmap.dal.exception.DataException;
61
import org.gvsig.tools.dispose.DisposableIterator;
62
import org.gvsig.fmap.dal.feature.Feature;
63
import org.gvsig.fmap.dal.feature.FeatureSelection;
64
import org.gvsig.fmap.dal.feature.FeatureStore;
65
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
66
import org.gvsig.fmap.geom.Geometry;
67
import org.gvsig.fmap.geom.type.GeometryType;
68
import org.gvsig.fmap.mapcontrol.MapControl;
69

    
70

    
71
/**
72
 * Extensi?n que gestiona la simplificaci?n de una geometr?a compuesta en otras m?s sencillas.
73
 *
74
 * @author Vicente Caballero Navarro
75
 */
76
public class ExploitExtension extends Extension {
77
    
78
    private static Logger logger = LoggerFactory.getLogger(ExploitExtension.class);
79
        private DefaultViewPanel view;
80

    
81
        private MapControl mapControl;
82
        private ExploitCADTool exploit;
83

    
84
        /**
85
         * @see org.gvsig.andami.plugins.IExtension#initialize()
86
         */
87
        public void initialize() {
88
                exploit=new ExploitCADTool();
89
                CADExtension.addCADTool("_exploit",exploit);
90

    
91
                registerIcons();
92
        }
93

    
94
        private void registerIcons(){
95
                PluginServices.getIconTheme().registerDefault(
96
                                "edition-geometry-exploit",
97
                                this.getClass().getClassLoader().getResource("images/Exploit.png")
98
                        );
99
        }
100

    
101
        /**
102
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
103
         */
104
        public void execute(String s) {
105
                CADExtension.initFocus();
106
                if (s.equals("_exploit")) {
107
                CADExtension.setCADTool(s,true);
108
        }
109
                CADExtension.getEditionManager().setMapControl(mapControl);
110
                CADExtension.getCADToolAdapter().configureMenu();
111
        }
112

    
113
        /**
114
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
115
         */
116
        public boolean isEnabled() {
117
                DisposableIterator iterator = null;
118
                try {
119
                        if (EditionUtilities.getEditionStatus() ==
120
                            EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
121
                            
122
                                view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow();
123
                                mapControl = view.getMapControl();
124
                                EditionManager em=CADExtension.getEditionManager();
125
                                if (em.getActiveLayerEdited()==null) {
126
                                        return false;
127
                                }
128
                                VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited();
129
//                                FLyrVect lv=(FLyrVect)vle.getLayer();
130
                                if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1) {
131
                                        return false;
132
                                }
133
                                
134
                                FeatureStore store = vle.getFeatureStore();
135
                                return canExploit(store);
136
                                
137
                                /*
138
                                if (!canExploit(store)) {
139
                                    return false;
140
                                }
141
                                */
142
                        
143
                                
144
                                /*
145
                                 * We cannot iterate through selection to get enabled or disbled
146
                                 * 
147
                                iterator = ((FeatureSelection) vle.getFeatureStore()
148
                                                .getSelection()).fastIterator();
149
                                if (iterator.hasNext()){
150
                                        Feature feature = (Feature) iterator.next();
151
                                        if (feature.getDefaultGeometry()!=null &&
152
                                            exploit.isApplicable((feature.getDefaultGeometry()).getType())){
153
                                                return true;
154
                                        }
155
                                }
156
                                */
157
                        }
158
                } catch (Throwable e) {
159
                    logger.info("IsEnabled error. ", e);
160
                    ApplicationLocator.getManager().message("_Unable_to_update_tool_status",
161
                        JOptionPane.ERROR_MESSAGE);
162
                        // NotificationManager.addError(e.getMessage(),e);
163
                } finally {
164
                        if (iterator != null) {
165
                                iterator.dispose();
166
                        }
167
                }
168
                return false;
169
        }
170

    
171
        private boolean canExploit(FeatureStore store) {
172
        DataManager dalmanager = DALLocator.getDataManager();
173
        FeatureStoreProviderFactory factory =
174
            (FeatureStoreProviderFactory) dalmanager.getStoreProviderFactory(store.getProviderName());
175
    
176
        GeometryType geotype = null;
177
        try {
178
            geotype = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType();
179
        } catch (DataException e) {
180
            logger.info("Cant get geom type.", e);
181
            return false;
182
        }
183
        
184
        if (geotype.getType() == Geometry.TYPES.CURVE) {
185
            return true;
186
        }
187
        
188
        if (geotype.isTypeOf(Geometry.TYPES.AGGREGATE)) {
189
            return true;
190
        }
191

    
192
        if (geotype.getType() == Geometry.TYPES.SURFACE) {
193
            if (factory.allowMultipleGeometryTypes() != FeatureStoreProviderFactory.YES) {
194
                return false;
195
            }
196
            return true;
197
        }
198
        
199
        if (geotype.isTypeOf(Geometry.TYPES.GEOMETRY)) {
200
            return true;
201
        }
202
        
203
        return false;
204
        }
205
        /**
206
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
207
         */
208
        public boolean isVisible() {
209
                if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
210
                        return true;
211
                }
212
                return false;
213
        }
214
}