root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / EditionManager.java @ 24160
History | View | Annotate | Download (7.73 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.logging.Logger; |
5 |
|
6 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
7 |
import com.iver.andami.PluginServices; |
8 |
import com.iver.andami.messages.NotificationManager; |
9 |
import com.iver.andami.ui.mdiManager.IWindow; |
10 |
import com.iver.cit.gvsig.fmap.MapControl; |
11 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
12 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
13 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
15 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
16 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
17 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
18 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
19 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
20 |
import com.iver.cit.gvsig.layers.FactoryLayerEdited; |
21 |
import com.iver.cit.gvsig.layers.ILayerEdited; |
22 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
23 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
24 |
|
25 |
/**
|
26 |
* @author fjp
|
27 |
*
|
28 |
* El prop?sito de esta clase es centralizar el manejo de la
|
29 |
* edici?n. Aqu? podemos encontrar una lista con todas
|
30 |
* los temas en edici?n, y las propiedades que sean globales
|
31 |
* e interesantes a la hora de ponerse a editar.
|
32 |
* Por ejemplo, podemos poner aqu? el Grid que vamos a usar,
|
33 |
* el MapControl que tenemos asociado, etc, etc.
|
34 |
* Tambi?n ser? el responsable de mantener una lista de
|
35 |
* listeners interesados en los eventos de edici?n, y
|
36 |
* de lanzar los eventos que necesitemos.
|
37 |
* Lo principal es una colecci?n de LayerEdited, y cada
|
38 |
* LayerEdited es un wrapper alrededor de un tema que guarda
|
39 |
* las propiedades de la edici?n.
|
40 |
*
|
41 |
* Nuevo: Llevar aqu? el control de las tablas en edici?n tambi?n
|
42 |
* y centralizar los listeners interesados en los eventos de edici?n.
|
43 |
*
|
44 |
* TODO: Poner todo lo referente al EditionManager dentro de una vista.
|
45 |
* para permitir tener varias vistas con temas en edici?n
|
46 |
*
|
47 |
*/
|
48 |
public class EditionManager implements LayerListener,LayerCollectionListener { |
49 |
private ArrayList editedLayers = new ArrayList(); |
50 |
private ArrayList editedTables = new ArrayList(); |
51 |
//private ArrayList activeLayerEdited = new ArrayList();
|
52 |
private MapControl mapCtrl = null; |
53 |
private ILayerEdited ile=null; |
54 |
//private int idActiveLayer=0;
|
55 |
|
56 |
|
57 |
/**
|
58 |
* @param lyr
|
59 |
* @return
|
60 |
*/
|
61 |
public ILayerEdited getLayerEdited(FLayer lyr)
|
62 |
{ |
63 |
ILayerEdited aux = null;
|
64 |
for (int i=0; i < editedLayers.size(); i++) |
65 |
{ |
66 |
aux = (ILayerEdited) editedLayers.get(i); |
67 |
if (aux.getLayer() == lyr)
|
68 |
return aux;
|
69 |
} |
70 |
return null; |
71 |
} |
72 |
|
73 |
public void visibilityChanged(LayerEvent e) { |
74 |
} |
75 |
|
76 |
public void activationChanged(LayerEvent e) { |
77 |
if (e.getSource().isActive()){
|
78 |
ile=getLayerEdited(e.getSource()); |
79 |
} |
80 |
// IWindow window=PluginServices.getMDIManager().getActiveWindow();
|
81 |
// if (window instanceof View){
|
82 |
// View view=(View)window;
|
83 |
// if (e.getSource().isEditing()){
|
84 |
// view.showConsole();
|
85 |
// }else{
|
86 |
// view.hideConsole();
|
87 |
// }
|
88 |
// }
|
89 |
|
90 |
|
91 |
if (ile==null || ile.getLayer().equals(e.getSource())){ |
92 |
|
93 |
if (ile!=null && !ile.getLayer().isActive()) { |
94 |
VectorialLayerEdited lastVLE = (VectorialLayerEdited)ile; |
95 |
lastVLE.activationLost(e); |
96 |
} |
97 |
if (e.getSource() instanceof FLyrVect) { |
98 |
VectorialLayerEdited vle = null;
|
99 |
vle=(VectorialLayerEdited)getLayerEdited(e.getSource()); |
100 |
// for (int i = 0; i < editedLayers.size(); i++) {
|
101 |
// vle = (VectorialLayerEdited) editedLayers.get(i);
|
102 |
// if (vle.getLayer().equals(e.getSource())) {
|
103 |
// idActiveLayer = i;
|
104 |
ile=vle; |
105 |
if (getMapControl()!=null && vle!=null && vle.getLayer().isActive()){ |
106 |
getMapControl().setTool("cadtooladapter");
|
107 |
vle.activationGained(e); |
108 |
return;
|
109 |
} |
110 |
} |
111 |
// }
|
112 |
// idActiveLayer=-1;
|
113 |
//ile=null;
|
114 |
if (getMapControl()!=null){ |
115 |
getMapControl().setTool("zoomIn");
|
116 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
public void nameChanged(LayerEvent e) { |
122 |
} |
123 |
|
124 |
public void editionChanged(LayerEvent e) { |
125 |
Logger.global.info(e.toString());
|
126 |
ILayerEdited lyrEdit = getLayerEdited(e.getSource()); |
127 |
|
128 |
// Si no est? en la lista, comprobamos que est? en edici?n
|
129 |
// y lo a?adimos
|
130 |
if ((lyrEdit == null) && e.getSource().isEditing()) |
131 |
{ |
132 |
lyrEdit = FactoryLayerEdited.createLayerEdited(e.getSource()); |
133 |
editedLayers.add(lyrEdit); |
134 |
if (getMapControl()!=null){ |
135 |
getMapControl().setTool("cadtooladapter");
|
136 |
CADExtension.setCADTool("_selection",true); |
137 |
} |
138 |
PluginServices.getMainFrame().setSelectedTool("_selection");
|
139 |
//idActiveLayer = editedLayers.size() - 1;
|
140 |
ile=getLayerEdited(e.getSource()); |
141 |
System.out.println("NUEVA CAPA EN EDICION: " + lyrEdit.getLayer().getName()); |
142 |
//activationChanged(e);
|
143 |
|
144 |
// Ponemos el resto de temas desactivados
|
145 |
if (mapCtrl != null) |
146 |
mapCtrl.getMapContext().getLayers().setActive(false);
|
147 |
// y activamos el nuevo.
|
148 |
e.getSource().setActive(true);
|
149 |
|
150 |
if (e.getSource() instanceof FLyrVect){ |
151 |
FLyrVect fLyrVect = (FLyrVect)e.getSource(); |
152 |
VectorialEditableAdapter vea = |
153 |
(VectorialEditableAdapter)fLyrVect.getSource(); |
154 |
vea.addEditionListener(new EditionChangeManager(fLyrVect));
|
155 |
} |
156 |
}else{
|
157 |
for (int i = 0; i < editedLayers.size(); i++) { |
158 |
VectorialLayerEdited vle = (VectorialLayerEdited) editedLayers.get(i); |
159 |
if (vle.equals(lyrEdit)) {
|
160 |
editedLayers.remove(i); |
161 |
ile=null;
|
162 |
//idActiveLayer=-1;
|
163 |
return;
|
164 |
} |
165 |
} |
166 |
} |
167 |
|
168 |
|
169 |
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* @return Returns the activeLayerEdited. Null if there isn't any active AND edited
|
174 |
*/
|
175 |
public ILayerEdited getActiveLayerEdited() {
|
176 |
return ile;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* @return Returns the mapCtrl.
|
181 |
*/
|
182 |
public MapControl getMapControl() {
|
183 |
return mapCtrl;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @param mapCtrl The mapCtrl to set.
|
188 |
*/
|
189 |
public void setMapControl(MapControl mapCtrl) { |
190 |
if (mapCtrl != null) |
191 |
{ |
192 |
this.mapCtrl = mapCtrl;
|
193 |
mapCtrl.getMapContext().getLayers().addLayerListener(this);
|
194 |
mapCtrl.getMapContext().getLayers().addLayerCollectionListener(this);
|
195 |
} |
196 |
} |
197 |
|
198 |
public void layerAdded(LayerCollectionEvent e) { |
199 |
// TODO Auto-generated method stub
|
200 |
|
201 |
} |
202 |
|
203 |
public void layerMoved(LayerPositionEvent e) { |
204 |
// TODO Auto-generated method stub
|
205 |
|
206 |
} |
207 |
|
208 |
public void layerRemoved(LayerCollectionEvent e) { |
209 |
VectorialLayerEdited vle=(VectorialLayerEdited)getActiveLayerEdited(); |
210 |
if (vle!=null && vle.getLayer().isActive()){ |
211 |
//FLayers layers=getMapControl().getMapContext().getLayers();
|
212 |
//if (layers.getLayersCount()>0)
|
213 |
// layers.getLayer(0).setActive(true);
|
214 |
try {
|
215 |
vle.clearSelection(VectorialLayerEdited.NOTSAVEPREVIOUS); |
216 |
} catch (ReadDriverException e1) {
|
217 |
NotificationManager.addError(e1); |
218 |
} |
219 |
editedLayers.remove(vle); |
220 |
getMapControl().setTool("zoomIn");
|
221 |
FLyrVect lv=(FLyrVect)vle.getLayer(); |
222 |
if (e.getAffectedLayer().equals(lv)){
|
223 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
224 |
if (window instanceof View) { |
225 |
View view=(View)window; |
226 |
view.hideConsole(); |
227 |
view.validate(); |
228 |
view.repaint(); |
229 |
} |
230 |
} |
231 |
} |
232 |
PluginServices.getMainFrame().enableControls(); |
233 |
} |
234 |
|
235 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
236 |
// TODO Auto-generated method stub
|
237 |
|
238 |
} |
239 |
|
240 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
241 |
// TODO Auto-generated method stub
|
242 |
|
243 |
} |
244 |
|
245 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
246 |
// TODO Auto-generated method stub
|
247 |
|
248 |
} |
249 |
|
250 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
251 |
// TODO Auto-generated method stub
|
252 |
|
253 |
} |
254 |
|
255 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
256 |
// TODO Auto-generated method stub
|
257 |
|
258 |
} |
259 |
|
260 |
/* (non-Javadoc)
|
261 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#drawValueChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
262 |
*/
|
263 |
public void drawValueChanged(LayerEvent e) { |
264 |
// TODO Auto-generated method stub
|
265 |
|
266 |
} |
267 |
|
268 |
|
269 |
|
270 |
} |