root / tags / v2_0_0_Build_2047 / extensions / extEditing / src / org / gvsig / editing / ExploitExtension.java @ 38269
History | View | Annotate | Download (6.12 KB)
1 | 5884 | caballero | /* 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 | 29616 | jpiera | package org.gvsig.editing; |
42 | 5884 | caballero | |
43 | 38243 | jldominguez | import javax.swing.JOptionPane; |
44 | |||
45 | import org.slf4j.Logger; |
||
46 | import org.slf4j.LoggerFactory; |
||
47 | |||
48 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
49 | import org.gvsig.andami.plugins.Extension; |
||
50 | 38243 | jldominguez | import org.gvsig.app.ApplicationLocator; |
51 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
52 | 29616 | jpiera | import org.gvsig.editing.gui.cad.tools.ExploitCADTool; |
53 | import org.gvsig.editing.layers.VectorialLayerEdited; |
||
54 | 38243 | jldominguez | import org.gvsig.fmap.dal.DALLocator; |
55 | import org.gvsig.fmap.dal.DataManager; |
||
56 | 24500 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
57 | 24490 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureSelection; |
58 | 38243 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureStore; |
59 | import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
||
60 | import org.gvsig.fmap.geom.Geometry; |
||
61 | import org.gvsig.fmap.geom.type.GeometryType; |
||
62 | 21666 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
63 | 38250 | jldominguez | import org.gvsig.tools.dispose.DisposableIterator; |
64 | 21666 | vcaballero | |
65 | 5884 | caballero | |
66 | /**
|
||
67 | * Extensi?n que gestiona la simplificaci?n de una geometr?a compuesta en otras m?s sencillas.
|
||
68 | *
|
||
69 | * @author Vicente Caballero Navarro
|
||
70 | */
|
||
71 | public class ExploitExtension extends Extension { |
||
72 | 38243 | jldominguez | |
73 | private static Logger logger = LoggerFactory.getLogger(ExploitExtension.class); |
||
74 | 31496 | jjdelcerro | private DefaultViewPanel view;
|
75 | 5884 | caballero | |
76 | private MapControl mapControl;
|
||
77 | private ExploitCADTool exploit;
|
||
78 | |||
79 | /**
|
||
80 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
81 | 5884 | caballero | */
|
82 | public void initialize() { |
||
83 | exploit=new ExploitCADTool();
|
||
84 | CADExtension.addCADTool("_exploit",exploit);
|
||
85 | 15604 | vcaballero | |
86 | 14810 | jmvivo | registerIcons(); |
87 | 5884 | caballero | } |
88 | 15604 | vcaballero | |
89 | 14810 | jmvivo | private void registerIcons(){ |
90 | 15637 | jmvivo | PluginServices.getIconTheme().registerDefault( |
91 | 14810 | jmvivo | "edition-geometry-exploit",
|
92 | this.getClass().getClassLoader().getResource("images/Exploit.png") |
||
93 | ); |
||
94 | } |
||
95 | 5884 | caballero | |
96 | /**
|
||
97 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
98 | 5884 | caballero | */
|
99 | public void execute(String s) { |
||
100 | CADExtension.initFocus(); |
||
101 | if (s.equals("_exploit")) { |
||
102 | CADExtension.setCADTool(s,true);
|
||
103 | } |
||
104 | CADExtension.getEditionManager().setMapControl(mapControl); |
||
105 | CADExtension.getCADToolAdapter().configureMenu(); |
||
106 | } |
||
107 | |||
108 | /**
|
||
109 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
110 | 5884 | caballero | */
|
111 | public boolean isEnabled() { |
||
112 | 27525 | jmvivo | DisposableIterator iterator = null;
|
113 | 22986 | vcaballero | try {
|
114 | 38243 | jldominguez | if (EditionUtilities.getEditionStatus() ==
|
115 | EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) { |
||
116 | |||
117 | 31496 | jjdelcerro | view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
118 | 6604 | caballero | mapControl = view.getMapControl(); |
119 | 5884 | caballero | EditionManager em=CADExtension.getEditionManager(); |
120 | 27525 | jmvivo | if (em.getActiveLayerEdited()==null) { |
121 | 5884 | caballero | return false; |
122 | 27525 | jmvivo | } |
123 | 5884 | caballero | VectorialLayerEdited vle=(VectorialLayerEdited)em.getActiveLayerEdited(); |
124 | 15604 | vcaballero | // FLyrVect lv=(FLyrVect)vle.getLayer();
|
125 | 27525 | jmvivo | if (((FeatureSelection)vle.getFeatureStore().getSelection()).getSize()<1) { |
126 | 5884 | caballero | return false; |
127 | 27525 | jmvivo | } |
128 | 38243 | jldominguez | |
129 | FeatureStore store = vle.getFeatureStore(); |
||
130 | return canExploit(store);
|
||
131 | |||
132 | /*
|
||
133 | if (!canExploit(store)) {
|
||
134 | return false;
|
||
135 | }
|
||
136 | */
|
||
137 | |||
138 | |||
139 | /*
|
||
140 | * We cannot iterate through selection to get enabled or disbled
|
||
141 | *
|
||
142 | 27525 | jmvivo | iterator = ((FeatureSelection) vle.getFeatureStore()
|
143 | 38243 | jldominguez | .getSelection()).fastIterator();
|
144 | 25859 | vcaballero | if (iterator.hasNext()){
|
145 | 27525 | jmvivo | Feature feature = (Feature) iterator.next();
|
146 | 38243 | jldominguez | if (feature.getDefaultGeometry()!=null &&
|
147 | exploit.isApplicable((feature.getDefaultGeometry()).getType())){
|
||
148 | 25859 | vcaballero | return true;
|
149 | }
|
||
150 | 5884 | caballero | }
|
151 | 38243 | jldominguez | */
|
152 | 5884 | caballero | } |
153 | 38243 | jldominguez | } catch (Throwable e) { |
154 | logger.info("IsEnabled error. ", e);
|
||
155 | ApplicationLocator.getManager().message("_Unable_to_update_tool_status",
|
||
156 | JOptionPane.ERROR_MESSAGE);
|
||
157 | // NotificationManager.addError(e.getMessage(),e);
|
||
158 | 27525 | jmvivo | } finally {
|
159 | if (iterator != null) { |
||
160 | iterator.dispose(); |
||
161 | } |
||
162 | 22986 | vcaballero | } |
163 | 5884 | caballero | return false; |
164 | } |
||
165 | |||
166 | 38243 | jldominguez | private boolean canExploit(FeatureStore store) { |
167 | DataManager dalmanager = DALLocator.getDataManager(); |
||
168 | FeatureStoreProviderFactory factory = |
||
169 | (FeatureStoreProviderFactory) dalmanager.getStoreProviderFactory(store.getProviderName()); |
||
170 | |||
171 | GeometryType geotype = null;
|
||
172 | try {
|
||
173 | geotype = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType(); |
||
174 | } catch (DataException e) {
|
||
175 | logger.info("Cant get geom type.", e);
|
||
176 | return false; |
||
177 | } |
||
178 | |||
179 | if (geotype.getType() == Geometry.TYPES.CURVE) {
|
||
180 | return true; |
||
181 | } |
||
182 | |||
183 | if (geotype.isTypeOf(Geometry.TYPES.AGGREGATE)) {
|
||
184 | return true; |
||
185 | } |
||
186 | |||
187 | if (geotype.getType() == Geometry.TYPES.SURFACE) {
|
||
188 | if (factory.allowMultipleGeometryTypes() != FeatureStoreProviderFactory.YES) {
|
||
189 | return false; |
||
190 | } |
||
191 | return true; |
||
192 | } |
||
193 | |||
194 | if (geotype.isTypeOf(Geometry.TYPES.GEOMETRY)) {
|
||
195 | return true; |
||
196 | } |
||
197 | |||
198 | return false; |
||
199 | } |
||
200 | 5884 | caballero | /**
|
201 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isVisible()
|
202 | 5884 | caballero | */
|
203 | public boolean isVisible() { |
||
204 | 27525 | jmvivo | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
205 | 5884 | caballero | return true; |
206 | 27525 | jmvivo | } |
207 | 6604 | caballero | return false; |
208 | 5884 | caballero | } |
209 | } |