svn-gvsig-desktop / tags / v1_0_2_Build_897 / extensions / extCAD / src / com / iver / cit / gvsig / EditionManager.java @ 10444
History | View | Annotate | Download (7.2 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 |
} |
79 |
IWindow window=PluginServices.getMDIManager().getActiveWindow(); |
80 |
if (window instanceof View){ |
81 |
View view=(View)window; |
82 |
if (e.getSource().isEditing()){
|
83 |
view.showConsole(); |
84 |
}else{
|
85 |
view.hideConsole(); |
86 |
} |
87 |
} |
88 |
if (ile==null || ile.getLayer().equals(e.getSource())){ |
89 |
|
90 |
if (ile!=null && !ile.getLayer().isActive()) { |
91 |
VectorialLayerEdited lastVLE = (VectorialLayerEdited)ile; |
92 |
lastVLE.activationLost(e); |
93 |
} |
94 |
if (e.getSource() instanceof FLyrVect) { |
95 |
VectorialLayerEdited vle = null;
|
96 |
vle=(VectorialLayerEdited)getLayerEdited(e.getSource()); |
97 |
// for (int i = 0; i < editedLayers.size(); i++) {
|
98 |
// vle = (VectorialLayerEdited) editedLayers.get(i);
|
99 |
// if (vle.getLayer().equals(e.getSource())) {
|
100 |
// idActiveLayer = i;
|
101 |
ile=vle; |
102 |
if (getMapControl()!=null && vle!=null && vle.getLayer().isActive()){ |
103 |
getMapControl().setTool("cadtooladapter");
|
104 |
vle.activationGained(e); |
105 |
return;
|
106 |
} |
107 |
} |
108 |
// }
|
109 |
// idActiveLayer=-1;
|
110 |
//ile=null;
|
111 |
if (getMapControl()!=null){ |
112 |
getMapControl().setTool("zoomIn");
|
113 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
114 |
} |
115 |
} |
116 |
} |
117 |
|
118 |
public void nameChanged(LayerEvent e) { |
119 |
} |
120 |
|
121 |
public void editionChanged(LayerEvent e) { |
122 |
Logger.global.info(e.toString());
|
123 |
ILayerEdited lyrEdit = getLayerEdited(e.getSource()); |
124 |
|
125 |
// Si no est? en la lista, comprobamos que est? en edici?n
|
126 |
// y lo a?adimos
|
127 |
if ((lyrEdit == null) && e.getSource().isEditing()) |
128 |
{ |
129 |
lyrEdit = FactoryLayerEdited.createLayerEdited(e.getSource()); |
130 |
editedLayers.add(lyrEdit); |
131 |
if (getMapControl()!=null){ |
132 |
getMapControl().setTool("cadtooladapter");
|
133 |
CADExtension.setCADTool("_selection",true); |
134 |
} |
135 |
PluginServices.getMainFrame().setSelectedTool("_selection");
|
136 |
//idActiveLayer = editedLayers.size() - 1;
|
137 |
ile=getLayerEdited(e.getSource()); |
138 |
System.out.println("NUEVA CAPA EN EDICION: " + lyrEdit.getLayer().getName()); |
139 |
//activationChanged(e);
|
140 |
|
141 |
// Ponemos el resto de temas desactivados
|
142 |
if (mapCtrl != null) |
143 |
mapCtrl.getMapContext().getLayers().setActive(false);
|
144 |
// y activamos el nuevo.
|
145 |
e.getSource().setActive(true);
|
146 |
|
147 |
if (e.getSource() instanceof FLyrVect){ |
148 |
FLyrVect fLyrVect = (FLyrVect)e.getSource(); |
149 |
VectorialEditableAdapter vea = |
150 |
(VectorialEditableAdapter)fLyrVect.getSource(); |
151 |
vea.addEditionListener(new EditionChangeManager(fLyrVect));
|
152 |
} |
153 |
}else{
|
154 |
for (int i = 0; i < editedLayers.size(); i++) { |
155 |
VectorialLayerEdited vle = (VectorialLayerEdited) editedLayers.get(i); |
156 |
if (vle.equals(lyrEdit)) {
|
157 |
editedLayers.remove(i); |
158 |
ile=null;
|
159 |
//idActiveLayer=-1;
|
160 |
return;
|
161 |
} |
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* @return Returns the activeLayerEdited. Null if there isn't any active AND edited
|
171 |
*/
|
172 |
public ILayerEdited getActiveLayerEdited() {
|
173 |
return ile;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* @return Returns the mapCtrl.
|
178 |
*/
|
179 |
public MapControl getMapControl() {
|
180 |
return mapCtrl;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* @param mapCtrl The mapCtrl to set.
|
185 |
*/
|
186 |
public void setMapControl(MapControl mapCtrl) { |
187 |
if (mapCtrl != null) |
188 |
{ |
189 |
this.mapCtrl = mapCtrl;
|
190 |
mapCtrl.getMapContext().getLayers().addLayerListener(this);
|
191 |
mapCtrl.getMapContext().getLayers().addLayerCollectionListener(this);
|
192 |
} |
193 |
} |
194 |
|
195 |
public void layerAdded(LayerCollectionEvent e) { |
196 |
// TODO Auto-generated method stub
|
197 |
|
198 |
} |
199 |
|
200 |
public void layerMoved(LayerPositionEvent e) { |
201 |
// TODO Auto-generated method stub
|
202 |
|
203 |
} |
204 |
|
205 |
public void layerRemoved(LayerCollectionEvent e) { |
206 |
VectorialLayerEdited vle=(VectorialLayerEdited)getActiveLayerEdited(); |
207 |
if (vle!=null){ |
208 |
//FLayers layers=getMapControl().getMapContext().getLayers();
|
209 |
//if (layers.getLayersCount()>0)
|
210 |
// layers.getLayer(0).setActive(true);
|
211 |
vle.clearSelection(); |
212 |
editedLayers.remove(vle); |
213 |
getMapControl().setTool("zoomIn");
|
214 |
FLyrVect lv=(FLyrVect)vle.getLayer(); |
215 |
if (e.getAffectedLayer().equals(lv)){
|
216 |
View view=(View)PluginServices.getMDIManager().getActiveWindow(); |
217 |
view.hideConsole(); |
218 |
view.validate(); |
219 |
view.repaint(); |
220 |
} |
221 |
PluginServices.getMainFrame().enableControls(); |
222 |
} |
223 |
|
224 |
} |
225 |
|
226 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
227 |
// TODO Auto-generated method stub
|
228 |
|
229 |
} |
230 |
|
231 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
232 |
// TODO Auto-generated method stub
|
233 |
|
234 |
} |
235 |
|
236 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
237 |
// TODO Auto-generated method stub
|
238 |
|
239 |
} |
240 |
|
241 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
242 |
// TODO Auto-generated method stub
|
243 |
|
244 |
} |
245 |
|
246 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
247 |
// TODO Auto-generated method stub
|
248 |
|
249 |
} |
250 |
|
251 |
|
252 |
|
253 |
} |