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 @ 45739

History | View | Annotate | Download (7.13 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature.impl.undo;
25

    
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.EditableFeature;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.dal.feature.FeatureReference;
30
import org.gvsig.fmap.dal.feature.FeatureSelection;
31
import org.gvsig.fmap.dal.feature.FeatureType;
32
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
33
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
34
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureManager;
35
import org.gvsig.fmap.dal.feature.impl.editing.memory.FeatureTypeManager;
36
import org.gvsig.fmap.dal.feature.impl.editing.memory.SpatialManager;
37
import org.gvsig.fmap.dal.feature.impl.undo.command.FTypeUpdateCommand;
38
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureDeleteCommand;
39
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureInsertCommand;
40
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureUpdateCommand;
41
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandReverse;
42
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelect;
43
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelectAll;
44
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSet;
45
import org.gvsig.tools.undo.command.Command;
46
import org.gvsig.tools.undo.command.impl.DefaultUndoRedoCommandStack;
47

    
48
/**
49
 * Clase en memoria para registrar y gestionar los comandos que vamos
50
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
51
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
52
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
53
 * para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
54
 * inserta este a la pila de deshacer(undos) y se borra de la de rehacer(redos).
55
 * Si se realiza un deshacer se desapila este comando de la pila deshacer(undos)
56
 * y se apila en la de rehacer(redos). Y de la misma forma cuando se realiza un
57
 * rehacer se desapila este comando de la pila de rehacer(redos) y pasa a la de
58
 * deshacer(undos).
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class DefaultFeatureCommandsStack extends DefaultUndoRedoCommandStack
63
        implements FeatureCommandsStack {
64
    private FeatureManager expansionManager;
65
    private SpatialManager spatialManager;
66
    private FeatureTypeManager featureTypeManager;
67
    private DefaultFeatureStore featureStore;
68

    
69
    public DefaultFeatureCommandsStack(DefaultFeatureStore featureStore,
70
        FeatureManager expansionManager, SpatialManager spatialManager, 
71
        FeatureTypeManager featureTypeManager) {
72
        this.featureStore = featureStore;
73
        this.expansionManager = expansionManager;
74
        this.spatialManager = spatialManager;
75
        this.featureTypeManager = featureTypeManager;
76
    }
77

    
78
    public void clear() {
79
        super.clear();
80
        expansionManager.clear();
81
        featureTypeManager.clear();
82
        spatialManager.clear();
83
    }
84

    
85
    public void deselect(DefaultFeatureReferenceSelection selection,
86
            FeatureReference reference) {
87
        SelectionCommandSelect command = new SelectionCommandSelect(selection,
88
                reference, false, "_selectionDeselect");
89
        add(command);
90
    }
91

    
92
    public void deselectAll(DefaultFeatureReferenceSelection selection)
93
            throws DataException {
94
        if (isSameLastCommand("_selectionDeselectAll")){
95
                return;
96
        }
97
            SelectionCommandSelectAll command = new SelectionCommandSelectAll(
98
                selection, false, "_selectionDeselectAll");
99
        add(command);
100
    }
101
    
102
    private boolean isSameLastCommand(String description){
103
            if (getUndoInfos().size() > 0){
104
                    Command lastCommand = getNextUndoCommand();
105
                    if (lastCommand.getDescription().equals(description)){
106
                            return true;
107
                    }
108
            }
109
            return false;
110
    }
111

    
112
    public void select(DefaultFeatureReferenceSelection selection,
113
            FeatureReference reference) {
114
        SelectionCommandSelect command = new SelectionCommandSelect(selection,
115
                reference, true, "_selectionSelect");
116
        add(command);
117
    }
118

    
119
    public void selectAll(DefaultFeatureReferenceSelection selection)
120
            throws DataException {
121
             if (isSameLastCommand("_selectionSelectAll")){
122
                 return;
123
         }
124
            SelectionCommandSelectAll command = new SelectionCommandSelectAll(
125
                selection, true, "_selectionSelectAll");
126
        add(command);
127
    }
128

    
129
    public void selectionReverse(DefaultFeatureReferenceSelection selection) {
130
        SelectionCommandReverse command = new SelectionCommandReverse(
131
                selection, "_selectionReverse");
132
        add(command);
133
    }
134

    
135
    public void selectionSet(DefaultFeatureStore store,
136
            FeatureSelection oldSelection, FeatureSelection newSelection) {
137
        SelectionCommandSet command = new SelectionCommandSet(store,
138
                oldSelection, newSelection, "_selectionSet");
139
        add(command);
140
    }
141

    
142
    public void delete(Feature feature) throws DataException {
143
        FeatureDeleteCommand command = new FeatureDeleteCommand(featureStore,
144
                feature, "_featureDelete");
145
        add(command);
146
        command.execute();
147
    }
148

    
149
    @Override
150
    public void insert(EditableFeature feature) throws DataException {
151
        FeatureInsertCommand command = new FeatureInsertCommand(featureStore,
152
                feature, "_featureInsert");
153
        add(command);
154
        command.execute();
155
    }
156

    
157
    @Override
158
    public void update(EditableFeature feature, Feature oldFeature) throws DataException {
159
        FeatureUpdateCommand command = new FeatureUpdateCommand(featureStore,
160
               feature, oldFeature,
161
                "_featureUpdate");
162
        add(command);
163
        command.execute();
164
    }
165

    
166
    public void update(FeatureType featureType, FeatureType oldFeatureType) {
167
        FTypeUpdateCommand command = new FTypeUpdateCommand(
168
                featureTypeManager, featureType, oldFeatureType,
169
                "_typeUpdate");
170
        add(command);
171
        command.execute();
172
    }
173

    
174
}