Revision 36723 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/EditionManager.java
EditionManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
1 | 22 |
package org.gvsig.editing; |
2 | 23 |
|
3 | 24 |
import java.awt.BorderLayout; |
... | ... | |
5 | 26 |
import java.awt.ScrollPane; |
6 | 27 |
import java.util.ArrayList; |
7 | 28 |
import java.util.Iterator; |
29 |
import java.util.List; |
|
8 | 30 |
import java.util.logging.Logger; |
9 | 31 |
|
10 | 32 |
import javax.swing.JPanel; |
... | ... | |
45 | 67 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
46 | 68 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
47 | 69 |
|
48 |
|
|
49 | 70 |
/** |
50 |
* @author fjp |
|
51 |
* |
|
71 |
* |
|
52 | 72 |
* El prop?sito de esta clase es centralizar el manejo de la |
53 | 73 |
* edici?n. Aqu? podemos encontrar una lista con todas |
54 | 74 |
* los temas en edici?n, y las propiedades que sean globales |
... | ... | |
61 | 81 |
* Lo principal es una colecci?n de LayerEdited, y cada |
62 | 82 |
* LayerEdited es un wrapper alrededor de un tema que guarda |
63 | 83 |
* las propiedades de la edici?n. |
64 |
* |
|
84 |
*
|
|
65 | 85 |
* Nuevo: Llevar aqu? el control de las tablas en edici?n tambi?n |
66 | 86 |
* y centralizar los listeners interesados en los eventos de edici?n. |
67 |
* |
|
87 |
*
|
|
68 | 88 |
* TODO: Poner todo lo referente al EditionManager dentro de una vista. |
69 | 89 |
* para permitir tener varias vistas con temas en edici?n |
70 |
* |
|
90 |
* |
|
91 |
* @author fjp |
|
71 | 92 |
*/ |
72 |
public class EditionManager implements LayerListener,LayerCollectionListener { |
|
73 |
private ArrayList editedLayers = new ArrayList(); |
|
74 |
private ArrayList editedTables = new ArrayList(); |
|
75 |
//private ArrayList activeLayerEdited = new ArrayList(); |
|
76 |
private MapControl mapCtrl = null; |
|
77 |
private ILayerEdited ile=null; |
|
78 |
//private int idActiveLayer=0; |
|
93 |
public class EditionManager implements LayerListener, LayerCollectionListener { |
|
79 | 94 |
|
95 |
private List<ILayerEdited> editedLayers = new ArrayList<ILayerEdited>(); |
|
96 |
// private ArrayList activeLayerEdited = new ArrayList(); |
|
97 |
private MapControl mapCtrl = null; |
|
98 |
private ILayerEdited ile = null; |
|
80 | 99 |
|
81 |
/** |
|
82 |
* @param lyr |
|
83 |
* @return |
|
84 |
*/ |
|
85 |
public ILayerEdited getLayerEdited(FLayer lyr) |
|
86 |
{ |
|
87 |
ILayerEdited aux = null; |
|
88 |
for (int i=0; i < editedLayers.size(); i++) |
|
89 |
{ |
|
90 |
aux = (ILayerEdited) editedLayers.get(i); |
|
91 |
if (aux.getLayer() == lyr) |
|
92 |
return aux; |
|
93 |
} |
|
94 |
return null; |
|
95 |
} |
|
100 |
// private int idActiveLayer=0; |
|
96 | 101 |
|
97 |
public void visibilityChanged(LayerEvent e) { |
|
98 |
} |
|
102 |
/** |
|
103 |
* @param lyr |
|
104 |
* @return |
|
105 |
*/ |
|
106 |
public ILayerEdited getLayerEdited(FLayer lyr) { |
|
107 |
ILayerEdited aux = null; |
|
108 |
for (int i = 0; i < editedLayers.size(); i++) { |
|
109 |
aux = editedLayers.get(i); |
|
110 |
if (aux.getLayer() == lyr) |
|
111 |
return aux; |
|
112 |
} |
|
113 |
return null; |
|
114 |
} |
|
99 | 115 |
|
100 |
public void activationChanged(LayerEvent e) { |
|
101 |
if (e.getSource().isActive()){ |
|
102 |
ile=getLayerEdited(e.getSource()); |
|
103 |
} |
|
104 |
// IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
|
105 |
// if (window instanceof View){ |
|
106 |
// View view=(View)window; |
|
107 |
// if (e.getSource().isEditing()){ |
|
108 |
// view.showConsole(); |
|
109 |
// }else{ |
|
110 |
// view.hideConsole(); |
|
111 |
// } |
|
112 |
// } |
|
116 |
public void visibilityChanged(LayerEvent e) { |
|
117 |
} |
|
113 | 118 |
|
119 |
public void activationChanged(LayerEvent e) { |
|
120 |
if (e.getSource().isActive()) { |
|
121 |
ile = getLayerEdited(e.getSource()); |
|
122 |
} |
|
123 |
if (ile == null || ile.getLayer().equals(e.getSource())) { |
|
114 | 124 |
|
115 |
if (ile==null || ile.getLayer().equals(e.getSource())){ |
|
125 |
if (ile != null && !ile.getLayer().isActive()) { |
|
126 |
VectorialLayerEdited lastVLE = (VectorialLayerEdited) ile; |
|
127 |
lastVLE.activationLost(e); |
|
128 |
} |
|
129 |
if (e.getSource() instanceof FLyrVect) { |
|
130 |
VectorialLayerEdited vle = null; |
|
131 |
vle = (VectorialLayerEdited) getLayerEdited(e.getSource()); |
|
132 |
ile = vle; |
|
133 |
if (getMapControl() != null && vle != null |
|
134 |
&& vle.getLayer().isActive()) { |
|
135 |
getMapControl().setTool("cadtooladapter"); |
|
136 |
vle.activationGained(e); |
|
137 |
return; |
|
138 |
} |
|
139 |
} |
|
140 |
if (getMapControl() != null) { |
|
141 |
getMapControl().setTool("zoomIn"); |
|
142 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN"); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
116 | 146 |
|
117 |
if (ile!=null && !ile.getLayer().isActive()) { |
|
118 |
VectorialLayerEdited lastVLE = (VectorialLayerEdited)ile; |
|
119 |
lastVLE.activationLost(e); |
|
120 |
} |
|
121 |
if (e.getSource() instanceof FLyrVect) { |
|
122 |
VectorialLayerEdited vle = null; |
|
123 |
vle=(VectorialLayerEdited)getLayerEdited(e.getSource()); |
|
124 |
// for (int i = 0; i < editedLayers.size(); i++) { |
|
125 |
// vle = (VectorialLayerEdited) editedLayers.get(i); |
|
126 |
// if (vle.getLayer().equals(e.getSource())) { |
|
127 |
// idActiveLayer = i; |
|
128 |
ile=vle; |
|
129 |
if (getMapControl()!=null && vle!=null && vle.getLayer().isActive()){ |
|
130 |
getMapControl().setTool("cadtooladapter"); |
|
131 |
vle.activationGained(e); |
|
132 |
return; |
|
133 |
} |
|
134 |
} |
|
135 |
// } |
|
136 |
// idActiveLayer=-1; |
|
137 |
//ile=null; |
|
138 |
if (getMapControl()!=null){ |
|
139 |
getMapControl().setTool("zoomIn"); |
|
140 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN"); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
147 |
public void nameChanged(LayerEvent e) { |
|
148 |
} |
|
144 | 149 |
|
145 |
public void nameChanged(LayerEvent e) { |
|
146 |
} |
|
150 |
public void editionChanged(LayerEvent e) { |
|
151 |
Logger.global.info(e.toString()); |
|
152 |
ILayerEdited lyrEdit = getLayerEdited(e.getSource()); |
|
147 | 153 |
|
148 |
public void editionChanged(LayerEvent e) { |
|
149 |
Logger.global.info(e.toString()); |
|
150 |
ILayerEdited lyrEdit = getLayerEdited(e.getSource()); |
|
154 |
// Si no est? en la lista, comprobamos que est? en edici?n |
|
155 |
// y lo a?adimos |
|
156 |
if ((lyrEdit == null) && e.getSource().isEditing()) { |
|
157 |
lyrEdit = |
|
158 |
FactoryLayerEdited.createLayerEdited(e.getSource(), mapCtrl); |
|
159 |
editedLayers.add(lyrEdit); |
|
160 |
if (getMapControl() != null) { |
|
161 |
getMapControl().setTool("cadtooladapter"); |
|
162 |
CADExtension.setCADTool("_selection", true); |
|
163 |
} |
|
164 |
PluginServices.getMainFrame().setSelectedTool("_selection"); |
|
165 |
// idActiveLayer = editedLayers.size() - 1; |
|
166 |
ile = getLayerEdited(e.getSource()); |
|
167 |
System.out.println("NUEVA CAPA EN EDICION: " |
|
168 |
+ lyrEdit.getLayer().getName()); |
|
151 | 169 |
|
152 |
// Si no est? en la lista, comprobamos que est? en edici?n |
|
153 |
// y lo a?adimos |
|
154 |
if ((lyrEdit == null) && e.getSource().isEditing()) |
|
155 |
{ |
|
156 |
lyrEdit = FactoryLayerEdited.createLayerEdited(e.getSource(), mapCtrl); |
|
157 |
editedLayers.add(lyrEdit); |
|
158 |
if (getMapControl()!=null){ |
|
159 |
getMapControl().setTool("cadtooladapter"); |
|
160 |
CADExtension.setCADTool("_selection",true); |
|
161 |
} |
|
162 |
PluginServices.getMainFrame().setSelectedTool("_selection"); |
|
163 |
//idActiveLayer = editedLayers.size() - 1; |
|
164 |
ile=getLayerEdited(e.getSource()); |
|
165 |
System.out.println("NUEVA CAPA EN EDICION: " + lyrEdit.getLayer().getName()); |
|
166 |
//activationChanged(e); |
|
170 |
// Ponemos el resto de temas desactivados |
|
171 |
if (mapCtrl != null) |
|
172 |
mapCtrl.getMapContext().getLayers().setActive(false); |
|
173 |
// y activamos el nuevo. |
|
174 |
e.getSource().setActive(true); |
|
167 | 175 |
|
168 |
// Ponemos el resto de temas desactivados |
|
169 |
if (mapCtrl != null) |
|
170 |
mapCtrl.getMapContext().getLayers().setActive(false); |
|
171 |
// y activamos el nuevo. |
|
172 |
e.getSource().setActive(true); |
|
176 |
if (e.getSource() instanceof FLyrVect) { |
|
177 |
FLyrVect fLyrVect = (FLyrVect) e.getSource(); |
|
178 |
((VectorialLayerEdited) lyrEdit) |
|
179 |
.setEditionChangeManager(new EditionChangeManager(fLyrVect)); |
|
173 | 180 |
|
174 |
if (e.getSource() instanceof FLyrVect){ |
|
175 |
FLyrVect fLyrVect = (FLyrVect)e.getSource(); |
|
176 |
((VectorialLayerEdited)lyrEdit).setEditionChangeManager(new EditionChangeManager(fLyrVect)); |
|
181 |
addCheckRules(fLyrVect); |
|
182 |
} |
|
183 |
} else { |
|
184 |
for (int i = 0; i < editedLayers.size(); i++) { |
|
185 |
VectorialLayerEdited vle = |
|
186 |
(VectorialLayerEdited) editedLayers.get(i); |
|
187 |
if (vle.equals(lyrEdit)) { |
|
188 |
editedLayers.remove(i); |
|
189 |
ile = null; |
|
190 |
return; |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
177 | 194 |
|
178 |
// VectorialEditableAdapter vea = |
|
179 |
// (VectorialEditableAdapter)fLyrVect.getSource(); |
|
180 |
// vea.addEditionListener(new EditionChangeManager(fLyrVect)); |
|
181 |
addCheckRules(fLyrVect); |
|
182 |
} |
|
183 |
}else{ |
|
184 |
for (int i = 0; i < editedLayers.size(); i++) { |
|
185 |
VectorialLayerEdited vle = (VectorialLayerEdited) editedLayers.get(i); |
|
186 |
if (vle.equals(lyrEdit)) { |
|
187 |
editedLayers.remove(i); |
|
188 |
ile=null; |
|
189 |
//idActiveLayer=-1; |
|
190 |
return; |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
195 |
} |
|
194 | 196 |
|
197 |
/** |
|
198 |
* @return Returns the activeLayerEdited. Null if there isn't any active AND |
|
199 |
* edited |
|
200 |
*/ |
|
201 |
public ILayerEdited getActiveLayerEdited() { |
|
202 |
return ile; |
|
203 |
} |
|
195 | 204 |
|
205 |
/** |
|
206 |
* @return Returns the mapCtrl. |
|
207 |
*/ |
|
208 |
public MapControl getMapControl() { |
|
209 |
return mapCtrl; |
|
210 |
} |
|
196 | 211 |
|
197 |
} |
|
212 |
/** |
|
213 |
* @param mapCtrl |
|
214 |
* The mapCtrl to set. |
|
215 |
*/ |
|
216 |
public void setMapControl(MapControl mapCtrl) { |
|
217 |
if (mapCtrl != null) { |
|
218 |
this.mapCtrl = mapCtrl; |
|
219 |
mapCtrl.getMapContext().getLayers().addLayerListener(this); |
|
220 |
mapCtrl.getMapContext().getLayers() |
|
221 |
.addLayerCollectionListener(this); |
|
222 |
} |
|
223 |
} |
|
198 | 224 |
|
199 |
/** |
|
200 |
* @return Returns the activeLayerEdited. Null if there isn't any active AND edited |
|
201 |
*/ |
|
202 |
public ILayerEdited getActiveLayerEdited() { |
|
203 |
return ile; |
|
204 |
} |
|
225 |
public void layerAdded(LayerCollectionEvent e) { |
|
226 |
// Nothing to do |
|
205 | 227 |
|
206 |
/** |
|
207 |
* @return Returns the mapCtrl. |
|
208 |
*/ |
|
209 |
public MapControl getMapControl() { |
|
210 |
return mapCtrl; |
|
211 |
} |
|
228 |
} |
|
212 | 229 |
|
213 |
/** |
|
214 |
* @param mapCtrl The mapCtrl to set. |
|
215 |
*/ |
|
216 |
public void setMapControl(MapControl mapCtrl) { |
|
217 |
if (mapCtrl != null) |
|
218 |
{ |
|
219 |
this.mapCtrl = mapCtrl; |
|
220 |
mapCtrl.getMapContext().getLayers().addLayerListener(this); |
|
221 |
mapCtrl.getMapContext().getLayers().addLayerCollectionListener(this); |
|
222 |
} |
|
223 |
} |
|
230 |
public void layerMoved(LayerPositionEvent e) { |
|
231 |
// Nothing to do |
|
232 |
} |
|
224 | 233 |
|
225 |
public void layerAdded(LayerCollectionEvent e) { |
|
226 |
// TODO Auto-generated method stub |
|
234 |
public void layerRemoved(LayerCollectionEvent e) { |
|
235 |
VectorialLayerEdited vle = |
|
236 |
(VectorialLayerEdited) getActiveLayerEdited(); |
|
237 |
if (vle != null && vle.getLayer().isActive()) { |
|
238 |
try { |
|
239 |
vle.clearSelection(); |
|
240 |
} catch (DataException e1) { |
|
241 |
NotificationManager.addError(e1); |
|
242 |
} |
|
243 |
editedLayers.remove(vle); |
|
244 |
getMapControl().setTool("zoomIn"); |
|
245 |
FLyrVect lv = (FLyrVect) vle.getLayer(); |
|
246 |
if (e.getAffectedLayer().equals(lv)) { |
|
247 |
IWindow window = |
|
248 |
PluginServices.getMDIManager().getActiveWindow(); |
|
249 |
if (window instanceof DefaultViewPanel) { |
|
250 |
DefaultViewPanel view = (DefaultViewPanel) window; |
|
251 |
view.hideConsole(); |
|
252 |
view.validate(); |
|
253 |
view.repaint(); |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
257 |
PluginServices.getMainFrame().enableControls(); |
|
258 |
} |
|
227 | 259 |
|
228 |
} |
|
260 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
261 |
// Nothing to do |
|
262 |
} |
|
229 | 263 |
|
230 |
public void layerMoved(LayerPositionEvent e) { |
|
231 |
// TODO Auto-generated method stub |
|
264 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
|
265 |
// Nothing to do |
|
266 |
} |
|
232 | 267 |
|
233 |
} |
|
268 |
public void layerRemoving(LayerCollectionEvent e) |
|
269 |
throws CancelationException { |
|
270 |
// Nothing to do |
|
271 |
} |
|
234 | 272 |
|
235 |
public void layerRemoved(LayerCollectionEvent e) { |
|
236 |
VectorialLayerEdited vle=(VectorialLayerEdited)getActiveLayerEdited(); |
|
237 |
if (vle!=null && vle.getLayer().isActive()){ |
|
238 |
//FLayers layers=getMapControl().getMapContext().getLayers(); |
|
239 |
//if (layers.getLayersCount()>0) |
|
240 |
// layers.getLayer(0).setActive(true); |
|
241 |
try { |
|
242 |
vle.clearSelection(); |
|
243 |
} catch (DataException e1) { |
|
244 |
NotificationManager.addError(e1); |
|
245 |
} |
|
246 |
editedLayers.remove(vle); |
|
247 |
getMapControl().setTool("zoomIn"); |
|
248 |
FLyrVect lv=(FLyrVect)vle.getLayer(); |
|
249 |
if (e.getAffectedLayer().equals(lv)){ |
|
250 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
|
251 |
if (window instanceof DefaultViewPanel) { |
|
252 |
DefaultViewPanel view=(DefaultViewPanel)window; |
|
253 |
view.hideConsole(); |
|
254 |
view.validate(); |
|
255 |
view.repaint(); |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
PluginServices.getMainFrame().enableControls(); |
|
260 |
} |
|
273 |
public void activationChanged(LayerCollectionEvent e) |
|
274 |
throws CancelationException { |
|
275 |
// Nothing to do |
|
276 |
} |
|
261 | 277 |
|
262 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
263 |
// TODO Auto-generated method stub |
|
278 |
public void visibilityChanged(LayerCollectionEvent e) |
|
279 |
throws CancelationException { |
|
280 |
// Nothing to do |
|
281 |
} |
|
264 | 282 |
|
265 |
} |
|
283 |
public void drawValueChanged(LayerEvent e) { |
|
284 |
// Nothing to do |
|
285 |
} |
|
266 | 286 |
|
267 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
|
268 |
// TODO Auto-generated method stub |
|
287 |
class CheckMandatoryAttributtes extends AbstractFeatureRule { |
|
269 | 288 |
|
270 |
} |
|
289 |
protected CheckMandatoryAttributtes() { |
|
290 |
super("CheckMandatoryAttributtes", "CheckMandatoryAttributtes"); |
|
291 |
} |
|
271 | 292 |
|
272 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
|
273 |
// TODO Auto-generated method stub |
|
293 |
public void validate(Feature feature, FeatureStore featureStore) |
|
294 |
throws DataException { |
|
295 |
// Comprobar si hay campos obligatorios y presentar formulario |
|
296 |
FeatureType featureType = feature.getType(); |
|
297 |
FeatureAttributeDescriptor[] attributeDescriptors = |
|
298 |
featureType.getAttributeDescriptors(); |
|
299 |
boolean showForm = false; |
|
300 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
|
301 |
FeatureAttributeDescriptor attrDesc = attributeDescriptors[i]; |
|
302 |
if ((attrDesc.isPrimaryKey() || !attrDesc.allowNull()) |
|
303 |
&& feature.get(attrDesc.getName()) == null) { |
|
304 |
showForm = true; |
|
305 |
break; |
|
306 |
} |
|
307 |
} |
|
308 |
if (showForm) { |
|
309 |
askRequiredAttributtes((EditableFeature) feature, featureStore); |
|
310 |
} |
|
311 |
} |
|
274 | 312 |
|
275 |
}
|
|
313 |
}
|
|
276 | 314 |
|
277 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
|
278 |
// TODO Auto-generated method stub |
|
315 |
private void askRequiredAttributtes(final EditableFeature feature, |
|
316 |
final FeatureStore store) |
|
317 |
throws FeatureRuleMandatoryAttributesException { |
|
279 | 318 |
|
280 |
} |
|
319 |
// Comprobar que estamos en el thread de swing y si no excepcion |
|
320 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
321 |
try { |
|
322 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
281 | 323 |
|
282 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
|
283 |
// TODO Auto-generated method stub |
|
324 |
public void run() { |
|
325 |
askRequiredAttributtes(feature, store); |
|
326 |
} |
|
327 |
}); |
|
328 |
} catch (Exception e1) { |
|
329 |
throw new FeatureRuleMandatoryAttributesException(e1, |
|
330 |
store.getFullName()); |
|
331 |
} |
|
332 |
return; |
|
333 |
} |
|
334 |
DynObjectSwingManager dynObjectSwinManager = |
|
335 |
ToolsSwingLocator.getDynObjectSwingManager(); |
|
336 |
final JDynObjectComponent dynObjectComponent; |
|
337 |
try { |
|
338 |
dynObjectComponent = |
|
339 |
dynObjectSwinManager.createJDynObjectComponent( |
|
340 |
feature.getAsDynObject(), true); |
|
341 |
} catch (ServiceException e) { |
|
342 |
throw new FeatureRuleMandatoryAttributesException(e, |
|
343 |
store.getFullName()); |
|
344 |
} |
|
345 |
final JPanel panel = new JPanel(); |
|
284 | 346 |
|
285 |
} |
|
347 |
ButtonsPanel buttonsPanel = |
|
348 |
new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCEL); |
|
349 |
buttonsPanel.addButtonPressedListener(new ButtonsPanelListener() { |
|
286 | 350 |
|
287 |
public void drawValueChanged(LayerEvent e) { |
|
288 |
// TODO Auto-generated method stub |
|
351 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
352 |
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) { |
|
353 |
dynObjectComponent.saveStatus(); |
|
354 |
panel.setVisible(false); |
|
355 |
} |
|
356 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) { |
|
357 |
panel.setVisible(false); |
|
358 |
throw new FeatureRuleMandatoryAttributesException(store |
|
359 |
.getFullName()); |
|
360 |
} |
|
361 |
} |
|
289 | 362 |
|
290 |
} |
|
363 |
}); |
|
364 |
panel.setLayout(new BorderLayout()); |
|
365 |
ScrollPane scrollPanel = new ScrollPane(); |
|
366 |
scrollPanel.add(dynObjectComponent.asJComponent(), BorderLayout.CENTER); |
|
367 |
panel.add(scrollPanel); |
|
368 |
panel.add(buttonsPanel, BorderLayout.SOUTH); |
|
369 |
panel.setPreferredSize(new Dimension(800, 600)); |
|
370 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
371 |
wm.showWindow(panel, "Fill mandatory fields", WindowManager.MODE.DIALOG); |
|
291 | 372 |
|
292 |
class CheckMandatoryAttributtes extends AbstractFeatureRule {
|
|
373 |
}
|
|
293 | 374 |
|
294 |
protected CheckMandatoryAttributtes() { |
|
295 |
super("CheckMandatoryAttributtes", "CheckMandatoryAttributtes"); |
|
296 |
} |
|
375 |
private void addCheckRules(FLyrVect layer) { |
|
376 |
try { |
|
377 |
FeatureType featureType = |
|
378 |
layer.getFeatureStore().getDefaultFeatureType(); |
|
379 |
FeatureRules featureRules = featureType.getRules(); |
|
380 |
for (Iterator it = featureRules.iterator(); it.hasNext();) { |
|
381 |
FeatureRule rule = (FeatureRule) it.next(); |
|
382 |
if (rule instanceof CheckMandatoryAttributtes) { |
|
383 |
return; |
|
384 |
} |
|
385 |
} |
|
386 |
featureRules.add(new CheckMandatoryAttributtes()); |
|
387 |
} catch (DataException e) { |
|
388 |
// TODO Auto-generated catch block |
|
389 |
e.printStackTrace(); |
|
390 |
} |
|
391 |
} |
|
297 | 392 |
|
298 |
public void validate(Feature feature, FeatureStore featureStore) |
|
299 |
throws DataException { |
|
300 |
// Comprobar si hay campos obligatorios y presentar formulario |
|
301 |
FeatureType featureType = feature.getType(); |
|
302 |
FeatureAttributeDescriptor[] attributeDescriptors = featureType.getAttributeDescriptors(); |
|
303 |
boolean showForm = false; |
|
304 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
|
305 |
FeatureAttributeDescriptor attrDesc = attributeDescriptors[i]; |
|
306 |
if ((attrDesc.isPrimaryKey() || !attrDesc.allowNull()) && feature.get(attrDesc.getName())==null){ |
|
307 |
showForm = true; |
|
308 |
break; |
|
309 |
} |
|
310 |
} |
|
311 |
if (showForm){ |
|
312 |
askRequiredAttributtes((EditableFeature)feature, featureStore); |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
} |
|
393 |
public class FeatureRuleMandatoryAttributesException extends |
|
394 |
DataRuntimeException { |
|
317 | 395 |
|
318 |
private void askRequiredAttributtes(final EditableFeature feature, final FeatureStore store) throws FeatureRuleMandatoryAttributesException{ |
|
396 |
private static final long serialVersionUID = -7965533441336164612L; |
|
397 |
private final static String MESSAGE_FORMAT = |
|
398 |
"Can't apply rule in store %(store)s."; |
|
399 |
private final static String MESSAGE_KEY = |
|
400 |
"_FeatureRuleMandatoryAttributesException"; |
|
319 | 401 |
|
320 |
// Comprobar que estamos en el thread de swing y si no excepcion |
|
321 |
if( !SwingUtilities.isEventDispatchThread() ){ |
|
322 |
try { |
|
323 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
324 |
public void run() { |
|
325 |
askRequiredAttributtes(feature, store); |
|
326 |
} |
|
327 |
}); |
|
328 |
} catch (Exception e1) { |
|
329 |
throw new FeatureRuleMandatoryAttributesException(e1, store.getFullName()); |
|
330 |
} |
|
331 |
return; |
|
402 |
public FeatureRuleMandatoryAttributesException(Throwable cause, |
|
403 |
String store) { |
|
404 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
405 |
this.setValue("store", store); |
|
332 | 406 |
} |
333 |
DynObjectSwingManager dynObjectSwinManager = ToolsSwingLocator.getDynObjectSwingManager(); |
|
334 |
final JDynObjectComponent dynObjectComponent; |
|
335 |
try { |
|
336 |
dynObjectComponent = dynObjectSwinManager.createJDynObjectComponent(feature.getAsDynObject(), true); |
|
337 |
} catch (ServiceException e) { |
|
338 |
throw new FeatureRuleMandatoryAttributesException(e, store.getFullName()); |
|
339 |
} |
|
340 |
final JPanel panel = new JPanel(); |
|
341 |
|
|
342 |
ButtonsPanel buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCEL); |
|
343 |
buttonsPanel.addButtonPressedListener(new ButtonsPanelListener(){ |
|
344 | 407 |
|
345 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
346 |
if (e.getButton()==ButtonsPanel.BUTTON_ACCEPT){ |
|
347 |
dynObjectComponent.saveStatus(); |
|
348 |
panel.setVisible(false); |
|
349 |
} |
|
350 |
if (e.getButton()==ButtonsPanel.BUTTON_CANCEL){ |
|
351 |
panel.setVisible(false); |
|
352 |
throw new FeatureRuleMandatoryAttributesException(store.getFullName()); |
|
353 |
} |
|
354 |
} |
|
355 |
|
|
356 |
}); |
|
357 |
panel.setLayout(new BorderLayout()); |
|
358 |
ScrollPane scrollPanel = new ScrollPane(); |
|
359 |
scrollPanel.add(dynObjectComponent.asJComponent(), BorderLayout.CENTER); |
|
360 |
panel.add(scrollPanel); |
|
361 |
panel.add(buttonsPanel, BorderLayout.SOUTH); |
|
362 |
panel.setPreferredSize(new Dimension(800, 600)); |
|
363 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
364 |
wm.showWindow(panel, "Fill mandatory fields", WindowManager.MODE.DIALOG); |
|
408 |
public FeatureRuleMandatoryAttributesException(String store) { |
|
409 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID); |
|
410 |
this.setValue("store", store); |
|
411 |
} |
|
412 |
} |
|
365 | 413 |
|
366 |
|
|
367 |
} |
|
368 |
private void addCheckRules(FLyrVect layer){ |
|
369 |
try { |
|
370 |
FeatureType featureType = layer.getFeatureStore().getDefaultFeatureType(); |
|
371 |
FeatureRules featureRules = featureType.getRules(); |
|
372 |
for (Iterator it = featureRules.iterator();it.hasNext();){ |
|
373 |
FeatureRule rule = (FeatureRule) it.next(); |
|
374 |
if (rule instanceof CheckMandatoryAttributtes) { |
|
375 |
return; |
|
376 |
} |
|
377 |
} |
|
378 |
featureRules.add(new CheckMandatoryAttributtes()); |
|
379 |
} catch (DataException e) { |
|
380 |
// TODO Auto-generated catch block |
|
381 |
e.printStackTrace(); |
|
382 |
} |
|
383 |
} |
|
384 |
|
|
385 |
public class FeatureRuleMandatoryAttributesException extends DataRuntimeException { |
|
386 |
|
|
387 |
/** |
|
388 |
* |
|
389 |
*/ |
|
390 |
private static final long serialVersionUID = -7965533441336164612L; |
|
391 |
private final static String MESSAGE_FORMAT = "Can't apply rule in store %(store)s."; |
|
392 |
private final static String MESSAGE_KEY = "_FeatureRuleMandatoryAttributesException"; |
|
393 |
|
|
394 |
public FeatureRuleMandatoryAttributesException(Throwable cause, String store) { |
|
395 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
396 |
this.setValue("store", store); |
|
397 |
} |
|
398 |
|
|
399 |
public FeatureRuleMandatoryAttributesException(String store) { |
|
400 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID); |
|
401 |
this.setValue("store", store); |
|
402 |
} |
|
403 |
} |
|
404 |
|
|
405 | 414 |
} |
Also available in: Unified diff