Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / commands / implementation / FeatureCommandsRecord.java @ 24496

History | View | Annotate | Download (4.62 KB)

1 24496 jmvivo
package org.gvsig.fmap.dal.feature.impl.commands.implementation;
2 19399 vcaballero
3 24496 jmvivo
import org.gvsig.fmap.dal.exceptions.DataException;
4
import org.gvsig.fmap.dal.feature.*;
5
import org.gvsig.fmap.dal.feature.impl.*;
6
import org.gvsig.fmap.dal.feature.impl.commands.AbstractCommand;
7
import org.gvsig.fmap.dal.feature.impl.commands.AbstractCommandsRecord;
8 19399 vcaballero
9
/**
10
 * Clase en memoria para registrar y gestionar los comandos que vamos
11
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
12
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
13
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
14
 * para rehacer(redos), de esta forma :  Cuando se a?ade un nuevo comando, se
15
 * inserta este a la pila de deshacer(undos) y se borra de la de
16
 * rehacer(redos). Si se realiza un deshacer se desapila este comando de la
17
 * pila deshacer(undos) y se apila en la de rehacer(redos). Y de la misma
18
 * forma cuando se realiza un rehacer se desapila este comando de la pila de
19
 * rehacer(redos) y pasa a la de deshacer(undos).
20
 *
21
 * @author Vicente Caballero Navarro
22
 */
23 21045 jmvivo
public class FeatureCommandsRecord extends AbstractCommandsRecord {
24 19399 vcaballero
        private FeatureManager expansionManager;
25
        private SpatialManager spatialManager;
26 23772 jjdelcerro
        private FeatureTypeManager featureTypeManager;
27
28
        public FeatureCommandsRecord(FeatureManager expansionManager,
29
                        SpatialManager spatialManager, FeatureTypeManager featureTypeManager) {
30 19399 vcaballero
                this.expansionManager=expansionManager;
31
                this.spatialManager=spatialManager;
32 24133 vcaballero
                this.featureTypeManager=featureTypeManager;
33 19399 vcaballero
        }
34
        public void insert(Object obj) {
35 23754 jjdelcerro
                AbstractCommand command = null;
36 21045 jmvivo
                if (obj instanceof Feature){
37
                        Feature feature=(Feature)obj;
38 24133 vcaballero
                        command=new FeatureInsertCommand(expansionManager,spatialManager, feature);
39
                }else if (obj instanceof FeatureType){
40
                        FeatureType type=(FeatureType)obj;
41
                        command=new FeatureTypeInsertCommand(featureTypeManager,type);
42 19399 vcaballero
                }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 23754 jjdelcerro
                AbstractCommand command = null;
50 21045 jmvivo
                if (obj instanceof Feature){
51
                        Feature feature=(Feature)obj;
52 24133 vcaballero
                        command=new FeatureDeleteCommand(expansionManager,spatialManager, feature);
53
                }else if (obj instanceof FeatureType){
54
                        FeatureType type=(FeatureType)obj;
55
                        command=new FeatureTypeDeleteCommand(featureTypeManager,type);
56 19399 vcaballero
                }else{
57
                        throw new RuntimeException("Object not supported by any command");
58
                }
59
                add(command);
60
                command.execute();
61
        }
62 20438 vcaballero
        public void update(Object obj, Object oldObj) {
63 23754 jjdelcerro
                AbstractCommand command = null;
64 21045 jmvivo
                if (obj instanceof Feature){
65
                        Feature feature=(Feature)obj;
66
                        Feature oldFeature=(Feature)oldObj;
67 24133 vcaballero
                        command=new FeatureUpdateCommand(expansionManager,spatialManager, feature, oldFeature);
68
                }else if (obj instanceof FeatureType){
69
                        FeatureType type=(FeatureType)obj;
70
                        FeatureType oldType=(FeatureType)obj;
71
                        command=new FeatureTypeUpdateCommand(featureTypeManager,type,oldType);
72 19399 vcaballero
                }else{
73
                        throw new RuntimeException("Object not supported by any command");
74
                }
75
                add(command);
76
                command.execute();
77
        }
78 23772 jjdelcerro
79 19488 vcaballero
        public void clear() {
80
                super.clear();
81
                expansionManager.clear();
82 24017 jjdelcerro
                featureTypeManager.clear();
83 19488 vcaballero
                spatialManager.clear();
84
        }
85 20419 vcaballero
86 24194 jjdelcerro
        public void deselect(FeatureReferenceSelection selection,
87
                        FeatureReference reference) {
88
                AbstractCommand command = new SelectionCommandSelect(selection,
89
                                reference, false);
90
                add(command);
91
                command.execute();
92
        }
93
94
        public void deselectAll(
95 24346 cordinyana
                        FeatureReferenceSelection selection)
96
            throws DataException {
97 24194 jjdelcerro
                AbstractCommand command = new SelectionCommandSelectAll(selection,
98
                                false);
99
                add(command);
100
                command.execute();
101
        }
102
103
        public void select(FeatureReferenceSelection selection,
104
                        FeatureReference reference) {
105
                AbstractCommand command = new SelectionCommandSelect(selection,
106
                                reference, true);
107
                add(command);
108
                command.execute();
109
        }
110
111
        public void selectAll(
112 24346 cordinyana
                        FeatureReferenceSelection selection)
113
            throws DataException {
114 24194 jjdelcerro
                AbstractCommand command = new SelectionCommandSelectAll(selection, true);
115
                add(command);
116
                command.execute();
117
        }
118
119
        public void selectionReverse(
120
                        FeatureReferenceSelection selection) {
121
                AbstractCommand command = new SelectionCommandReverse(selection);
122
                add(command);
123
                command.execute();
124
        }
125
126 24346 cordinyana
        public void selectionSet(DefaultFeatureStore store,
127
            FeatureReferenceSelection oldSelection,
128 24194 jjdelcerro
                        FeatureReferenceSelection newSelection) {
129 24346 cordinyana
                AbstractCommand command = new SelectionCommandSet(store, oldSelection,
130 24194 jjdelcerro
                                newSelection);
131
                add(command);
132
                command.execute();
133
        }
134
135 19399 vcaballero
}