Statistics
| Revision:

root / trunk / libraries / libDataSource / src / org / gvsig / data / commands / implementation / FeatureCommandsRecord.java @ 19399

History | View | Annotate | Download (3.46 KB)

1
package org.gvsig.data.commands.implementation;
2

    
3
import org.gvsig.data.commands.AbstractCommandsRecord;
4
import org.gvsig.data.commands.ICommand;
5
import org.gvsig.data.vectorial.IFeature;
6
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
7
import org.gvsig.data.vectorial.SpatialManager;
8
import org.gvsig.data.vectorial.expansionadapter.AttributeManager;
9
import org.gvsig.data.vectorial.expansionadapter.FeatureManager;
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 AttributeManager attributeManager;
29
        public FeatureCommandsRecord(FeatureManager expansionManager,SpatialManager spatialManager,AttributeManager attributeManager){
30
                this.expansionManager=expansionManager;
31
                this.spatialManager=spatialManager;
32
                this.attributeManager=attributeManager;
33
        }
34
        public void insert(Object obj) {
35
                ICommand command=null;
36
                if (obj instanceof IFeature){
37
                        IFeature feature=(IFeature)obj;
38
                        command=new InsertFeatureCommand(expansionManager,spatialManager, feature);
39
                }else if (obj instanceof IFeatureAttributeDescriptor){
40
                        IFeatureAttributeDescriptor attributeDescriptor=(IFeatureAttributeDescriptor)obj;
41
                        command=new InsertAttributeCommand(attributeManager,attributeDescriptor);
42
                }else{
43
                        throw new RuntimeException("Object not supported by any command");
44
                }
45
                add(command);
46
                command.execute();
47
        }
48
        public void delete(Object obj) {
49
                ICommand command=null;
50
                if (obj instanceof IFeature){
51
                        IFeature feature=(IFeature)obj;
52
                        command=new DeleteFeatureCommand(expansionManager,spatialManager, feature);
53
                }else if (obj instanceof IFeatureAttributeDescriptor){
54
                        IFeatureAttributeDescriptor attributeDescriptor=(IFeatureAttributeDescriptor)obj;
55
                        command=new DeleteAttributeCommand(attributeManager,attributeDescriptor);
56
                }else{
57
                        throw new RuntimeException("Object not supported by any command");
58
                }
59
                add(command);
60
                command.execute();
61
        }
62
        public void update(Object obj, Object oldObj) {
63
                ICommand command=null;
64
                if (obj instanceof IFeature){
65
                        IFeature feature=(IFeature)obj;
66
                        IFeature oldFeature=(IFeature)oldObj;
67
                        command=new UpdateFeatureCommand(expansionManager,spatialManager, feature,oldFeature);
68
                }else if (obj instanceof IFeatureAttributeDescriptor){
69
                        IFeatureAttributeDescriptor attributeDescriptor=(IFeatureAttributeDescriptor)obj;
70
                        IFeatureAttributeDescriptor oldAttributeDescriptor=(IFeatureAttributeDescriptor)oldObj;
71
                        command=new UpdateAttributeCommand(attributeManager,attributeDescriptor,oldAttributeDescriptor);
72
                }else{
73
                        throw new RuntimeException("Object not supported by any command");
74
                }
75
                add(command);
76
                command.execute();
77
        }
78
}