Revision 38243 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/ExploitExtension.java
ExploitExtension.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package org.gvsig.editing; |
42 | 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 |
|
|
43 | 50 |
import org.gvsig.andami.PluginServices; |
44 | 51 |
import org.gvsig.andami.messages.NotificationManager; |
45 | 52 |
import org.gvsig.andami.plugins.Extension; |
53 |
import org.gvsig.app.ApplicationLocator; |
|
46 | 54 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
47 | 55 |
import org.gvsig.editing.gui.cad.tools.ExploitCADTool; |
48 | 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; |
|
49 | 60 |
import org.gvsig.fmap.dal.exception.DataException; |
50 | 61 |
import org.gvsig.tools.dispose.DisposableIterator; |
51 | 62 |
import org.gvsig.fmap.dal.feature.Feature; |
52 | 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; |
|
53 | 68 |
import org.gvsig.fmap.mapcontrol.MapControl; |
54 | 69 |
|
55 | 70 |
|
... | ... | |
59 | 74 |
* @author Vicente Caballero Navarro |
60 | 75 |
*/ |
61 | 76 |
public class ExploitExtension extends Extension { |
77 |
|
|
78 |
private static Logger logger = LoggerFactory.getLogger(ExploitExtension.class); |
|
62 | 79 |
private DefaultViewPanel view; |
63 | 80 |
|
64 | 81 |
private MapControl mapControl; |
... | ... | |
99 | 116 |
public boolean isEnabled() { |
100 | 117 |
DisposableIterator iterator = null; |
101 | 118 |
try { |
102 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
|
119 |
if (EditionUtilities.getEditionStatus() == |
|
120 |
EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
|
121 |
|
|
103 | 122 |
view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
104 | 123 |
mapControl = view.getMapControl(); |
105 | 124 |
EditionManager em=CADExtension.getEditionManager(); |
... | ... | |
111 | 130 |
if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1) { |
112 | 131 |
return false; |
113 | 132 |
} |
114 |
// ArrayList selectedRows=vle.getSelectedRow(); |
|
115 |
// if (selectedRows.size()<1) { |
|
116 |
// return false; |
|
117 |
// } |
|
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 |
* |
|
118 | 147 |
iterator = ((FeatureSelection) vle.getFeatureStore() |
119 |
.getSelection()).iterator();
|
|
148 |
.getSelection()).fastIterator();
|
|
120 | 149 |
if (iterator.hasNext()){ |
121 | 150 |
Feature feature = (Feature) iterator.next(); |
122 |
if (feature.getDefaultGeometry()!=null && exploit.isApplicable((feature.getDefaultGeometry()).getType())){ |
|
151 |
if (feature.getDefaultGeometry()!=null && |
|
152 |
exploit.isApplicable((feature.getDefaultGeometry()).getType())){ |
|
123 | 153 |
return true; |
124 | 154 |
} |
125 | 155 |
} |
156 |
*/ |
|
126 | 157 |
} |
127 |
} catch (DataException e) { |
|
128 |
NotificationManager.addError(e.getMessage(),e); |
|
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); |
|
129 | 163 |
} finally { |
130 | 164 |
if (iterator != null) { |
131 | 165 |
iterator.dispose(); |
... | ... | |
134 | 168 |
return false; |
135 | 169 |
} |
136 | 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 |
} |
|
137 | 205 |
/** |
138 | 206 |
* @see org.gvsig.andami.plugins.IExtension#isVisible() |
139 | 207 |
*/ |
Also available in: Unified diff