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