svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / impl / commands / implementation / FeatureCommandsRecord.java @ 23772
History | View | Annotate | Download (3.67 KB)
1 |
package org.gvsig.fmap.data.feature.impl.commands.implementation; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.data.feature.Feature; |
4 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
5 |
import org.gvsig.fmap.data.feature.impl.FeatureManager; |
6 |
import org.gvsig.fmap.data.feature.impl.FeatureTypeManager; |
7 |
import org.gvsig.fmap.data.feature.impl.SpatialManager; |
8 |
import org.gvsig.fmap.data.feature.impl.commands.AbstractCommand; |
9 |
import org.gvsig.fmap.data.feature.impl.commands.AbstractCommandsRecord; |
10 |
|
11 |
/**
|
12 |
* Clase en memoria para registrar y gestionar los comandos que vamos
|
13 |
* realizando. La forma en que ha sido implementada esta clase, en vez de una
|
14 |
* ?nica lista para albergar los comandos de deshacer(undos) y los de
|
15 |
* rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
|
16 |
* para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
|
17 |
* inserta este a la pila de deshacer(undos) y se borra de la de
|
18 |
* rehacer(redos). Si se realiza un deshacer se desapila este comando de la
|
19 |
* pila deshacer(undos) y se apila en la de rehacer(redos). Y de la misma
|
20 |
* forma cuando se realiza un rehacer se desapila este comando de la pila de
|
21 |
* rehacer(redos) y pasa a la de deshacer(undos).
|
22 |
*
|
23 |
* @author Vicente Caballero Navarro
|
24 |
*/
|
25 |
public class FeatureCommandsRecord extends AbstractCommandsRecord { |
26 |
private FeatureManager expansionManager;
|
27 |
private SpatialManager spatialManager;
|
28 |
private FeatureTypeManager featureTypeManager;
|
29 |
|
30 |
public FeatureCommandsRecord(FeatureManager expansionManager,
|
31 |
SpatialManager spatialManager, FeatureTypeManager featureTypeManager) { |
32 |
this.expansionManager=expansionManager;
|
33 |
this.spatialManager=spatialManager;
|
34 |
this.attributeManager=attributeManager;
|
35 |
} |
36 |
public void insert(Object obj) { |
37 |
AbstractCommand command = null;
|
38 |
if (obj instanceof Feature){ |
39 |
Feature feature=(Feature)obj; |
40 |
command=new InsertFeatureCommand(expansionManager,spatialManager, feature);
|
41 |
}else if (obj instanceof FeatureAttributeDescriptor){ |
42 |
FeatureAttributeDescriptor attributeDescriptor=(FeatureAttributeDescriptor)obj; |
43 |
command=new InsertAttributeCommand(attributeManager,attributeDescriptor);
|
44 |
}else{
|
45 |
throw new RuntimeException("Object not supported by any command"); |
46 |
} |
47 |
add(command); |
48 |
command.execute(); |
49 |
} |
50 |
public void delete(Object obj) { |
51 |
AbstractCommand command = null;
|
52 |
if (obj instanceof Feature){ |
53 |
Feature feature=(Feature)obj; |
54 |
command=new DeleteFeatureCommand(expansionManager,spatialManager, feature);
|
55 |
}else if (obj instanceof FeatureAttributeDescriptor){ |
56 |
FeatureAttributeDescriptor attributeDescriptor=(FeatureAttributeDescriptor)obj; |
57 |
command=new DeleteAttributeCommand(attributeManager,attributeDescriptor);
|
58 |
}else{
|
59 |
throw new RuntimeException("Object not supported by any command"); |
60 |
} |
61 |
add(command); |
62 |
command.execute(); |
63 |
} |
64 |
public void update(Object obj, Object oldObj) { |
65 |
AbstractCommand command = null;
|
66 |
if (obj instanceof Feature){ |
67 |
Feature feature=(Feature)obj; |
68 |
Feature oldFeature=(Feature)oldObj; |
69 |
command=new UpdateFeatureCommand(expansionManager,spatialManager, feature, oldFeature);
|
70 |
}else if (obj instanceof FeatureAttributeDescriptor){ |
71 |
FeatureAttributeDescriptor attributeDescriptor=(FeatureAttributeDescriptor)obj; |
72 |
FeatureAttributeDescriptor oldAttributeDescriptor=(FeatureAttributeDescriptor)oldObj; |
73 |
command=new UpdateAttributeCommand(attributeManager,attributeDescriptor, oldAttributeDescriptor);
|
74 |
}else{
|
75 |
throw new RuntimeException("Object not supported by any command"); |
76 |
} |
77 |
add(command); |
78 |
command.execute(); |
79 |
} |
80 |
|
81 |
public void clear() { |
82 |
super.clear();
|
83 |
expansionManager.clear(); |
84 |
attributeManager.clear(); |
85 |
spatialManager.clear(); |
86 |
} |
87 |
|
88 |
} |