Revision 9476
branches/v10/applications/appgvSIG/src/com/iver/cit/gvsig/ClearSelectionExtension.java | ||
---|---|---|
52 | 52 |
import com.iver.cit.gvsig.fmap.DriverException; |
53 | 53 |
import com.iver.cit.gvsig.fmap.MapContext; |
54 | 54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
56 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
55 | 57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
56 | 58 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
57 | 59 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
... | ... | |
79 | 81 |
IProjectView model = vista.getModel(); |
80 | 82 |
MapContext mapa = model.getMapContext(); |
81 | 83 |
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 |
* |
|
84 |
FLayers layers = mapa.getLayers(); |
|
85 |
refresh = clearSelectionOfView(layers); |
|
86 | 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 | 87 |
if (refresh) { |
119 | 88 |
mapCtrl.drawMap(false); |
120 | 89 |
} |
... | ... | |
134 | 103 |
} |
135 | 104 |
} |
136 | 105 |
|
106 |
|
|
107 |
private boolean clearSelectionOfView(FLayers layers){ |
|
108 |
boolean refresh=false; |
|
109 |
|
|
110 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
111 |
FLayer lyr =layers.getLayer(i); |
|
112 |
if (lyr instanceof FLayers){ |
|
113 |
refresh = refresh || clearSelectionOfView((FLayers) lyr); |
|
114 |
} else if (lyr instanceof FLyrVect) { |
|
115 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
116 |
if (lyrVect.isActive()) { |
|
117 |
try { |
|
118 |
SelectableDataSource dataSource; |
|
119 |
|
|
120 |
dataSource = ((FLyrVect)lyr).getRecordset(); |
|
121 |
if (dataSource.getSelection().cardinality() != 0) { |
|
122 |
refresh = true; |
|
123 |
} |
|
124 |
dataSource.clearSelection(); |
|
125 |
} catch (DriverException e) { |
|
126 |
e.printStackTrace(); |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
return refresh; |
|
132 |
} |
|
137 | 133 |
/** |
138 | 134 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible() |
139 | 135 |
*/ |
... | ... | |
164 | 160 |
} |
165 | 161 |
if (view instanceof View){ |
166 | 162 |
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 |
} |
|
163 |
return hasVectorLayersWithSelection(mapa.getLayers()); |
|
182 | 164 |
} |
183 | 165 |
if (view instanceof Table){ |
184 | 166 |
return ((Table)view).getSelectedRowIndices().length>0; |
... | ... | |
186 | 168 |
return false; |
187 | 169 |
} |
188 | 170 |
|
171 |
private boolean hasVectorLayersWithSelection(FLayers layers) { |
|
172 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
173 |
FLayer lyr =layers.getLayer(i); |
|
174 |
if (lyr instanceof FLayers){ |
|
175 |
if (hasVectorLayersWithSelection((FLayers) lyr)){ |
|
176 |
return true; |
|
177 |
} |
|
178 |
} else if (lyr instanceof FLyrVect) { |
|
179 |
FLyrVect lyrVect = (FLyrVect) lyr; |
|
180 |
if (lyrVect.isActive()) { |
|
181 |
if (lyrVect.isAvailable()){ |
|
182 |
try { |
|
183 |
if (lyrVect.getRecordset().getSelection().cardinality() > 0) |
|
184 |
return true; |
|
185 |
} catch (DriverException e) { |
|
186 |
e.printStackTrace(); |
|
187 |
NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
return false; |
|
194 |
} |
|
195 |
|
|
189 | 196 |
/** |
190 | 197 |
* @see com.iver.andami.plugins.IExtension#initialize() |
191 | 198 |
*/ |
Also available in: Unified diff