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