Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / undo / DefaultFeatureCommandsStack.java @ 40435

History | View | Annotate | Download (6.03 KB)

1
package org.gvsig.fmap.dal.feature.impl.undo;
2

    
3
import org.gvsig.fmap.dal.exception.DataException;
4
import org.gvsig.fmap.dal.feature.Feature;
5
import org.gvsig.fmap.dal.feature.FeatureReference;
6
import org.gvsig.fmap.dal.feature.FeatureSelection;
7
import org.gvsig.fmap.dal.feature.FeatureType;
8
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
9
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
10
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
11
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager;
12
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
13
import org.gvsig.fmap.dal.feature.impl.undo.command.FTypeUpdateCommand;
14
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureDeleteCommand;
15
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureInsertCommand;
16
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureUpdateCommand;
17
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandReverse;
18
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelect;
19
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelectAll;
20
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSet;
21
import org.gvsig.tools.undo.command.Command;
22
import org.gvsig.tools.undo.command.impl.DefaultUndoRedoCommandStack;
23

    
24
/**
25
 * Clase en memoria para registrar y gestionar los comandos que vamos
26
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
27
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
28
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
29
 * para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
30
 * inserta este a la pila de deshacer(undos) y se borra de la de rehacer(redos).
31
 * Si se realiza un deshacer se desapila este comando de la pila deshacer(undos)
32
 * y se apila en la de rehacer(redos). Y de la misma forma cuando se realiza un
33
 * rehacer se desapila este comando de la pila de rehacer(redos) y pasa a la de
34
 * deshacer(undos).
35
 *
36
 * @author Vicente Caballero Navarro
37
 */
38
public class DefaultFeatureCommandsStack extends DefaultUndoRedoCommandStack
39
        implements FeatureCommandsStack {
40
    private FeatureManager expansionManager;
41
    private SpatialManager spatialManager;
42
    private FeatureTypeManager featureTypeManager;
43
    private DefaultFeatureStore featureStore;
44

    
45
    public DefaultFeatureCommandsStack(DefaultFeatureStore featureStore,
46
        FeatureManager expansionManager, SpatialManager spatialManager, 
47
        FeatureTypeManager featureTypeManager) {
48
        this.featureStore = featureStore;
49
        this.expansionManager = expansionManager;
50
        this.spatialManager = spatialManager;
51
        this.featureTypeManager = featureTypeManager;
52
    }
53

    
54
    public void clear() {
55
        super.clear();
56
        expansionManager.clear();
57
        featureTypeManager.clear();
58
        spatialManager.clear();
59
    }
60

    
61
    public void deselect(DefaultFeatureReferenceSelection selection,
62
            FeatureReference reference) {
63
        SelectionCommandSelect command = new SelectionCommandSelect(selection,
64
                reference, false, "_selectionDeselect");
65
        add(command);
66
    }
67

    
68
    public void deselectAll(DefaultFeatureReferenceSelection selection)
69
            throws DataException {
70
        if (isSameLastCommand("_selectionDeselectAll")){
71
                return;
72
        }
73
            SelectionCommandSelectAll command = new SelectionCommandSelectAll(
74
                selection, false, "_selectionDeselectAll");
75
        add(command);
76
    }
77
    
78
    private boolean isSameLastCommand(String description){
79
            if (getUndoInfos().size() > 0){
80
                    Command lastCommand = getNextUndoCommand();
81
                    if (lastCommand.getDescription().equals(description)){
82
                            return true;
83
                    }
84
            }
85
            return false;
86
    }
87

    
88
    public void select(DefaultFeatureReferenceSelection selection,
89
            FeatureReference reference) {
90
        SelectionCommandSelect command = new SelectionCommandSelect(selection,
91
                reference, true, "_selectionSelect");
92
        add(command);
93
    }
94

    
95
    public void selectAll(DefaultFeatureReferenceSelection selection)
96
            throws DataException {
97
             if (isSameLastCommand("_selectionSelectAll")){
98
                 return;
99
         }
100
            SelectionCommandSelectAll command = new SelectionCommandSelectAll(
101
                selection, true, "_selectionSelectAll");
102
        add(command);
103
    }
104

    
105
    public void selectionReverse(DefaultFeatureReferenceSelection selection) {
106
        SelectionCommandReverse command = new SelectionCommandReverse(
107
                selection, "_selectionReverse");
108
        add(command);
109
    }
110

    
111
    public void selectionSet(DefaultFeatureStore store,
112
            FeatureSelection oldSelection, FeatureSelection newSelection) {
113
        SelectionCommandSet command = new SelectionCommandSet(store,
114
                oldSelection, newSelection, "_selectionSet");
115
        add(command);
116
    }
117

    
118
    public void delete(Feature feature) throws DataException {
119
        FeatureDeleteCommand command = new FeatureDeleteCommand(featureStore,
120
                feature, "_featureDelete");
121
        add(command);
122
        command.execute();
123
    }
124

    
125
    public void insert(Feature feature) throws DataException {
126
        FeatureInsertCommand command = new FeatureInsertCommand(featureStore,
127
                feature, "_featureInsert");
128
        add(command);
129
        command.execute();
130
    }
131

    
132
    public void update(Feature feature, Feature oldFeature) throws DataException {
133
        FeatureUpdateCommand command = new FeatureUpdateCommand(featureStore,
134
               feature, oldFeature,
135
                "_featureUpdate");
136
        add(command);
137
        command.execute();
138
    }
139

    
140
    public void update(FeatureType featureType, FeatureType oldFeatureType) {
141
        FTypeUpdateCommand command = new FTypeUpdateCommand(
142
                featureTypeManager, featureType, oldFeatureType,
143
                "_typeUpdate");
144
        add(command);
145
        command.execute();
146
    }
147

    
148
}