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

History | View | Annotate | Download (6.99 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.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureReference;
29
import org.gvsig.fmap.dal.feature.FeatureSelection;
30
import org.gvsig.fmap.dal.feature.FeatureType;
31
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
32
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
33
import org.gvsig.fmap.dal.feature.impl.FeatureManager;
34
import org.gvsig.fmap.dal.feature.impl.FeatureTypeManager;
35
import org.gvsig.fmap.dal.feature.impl.SpatialManager;
36
import org.gvsig.fmap.dal.feature.impl.undo.command.FTypeUpdateCommand;
37
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureDeleteCommand;
38
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureInsertCommand;
39
import org.gvsig.fmap.dal.feature.impl.undo.command.FeatureUpdateCommand;
40
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandReverse;
41
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelect;
42
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSelectAll;
43
import org.gvsig.fmap.dal.feature.impl.undo.command.SelectionCommandSet;
44
import org.gvsig.tools.undo.command.Command;
45
import org.gvsig.tools.undo.command.impl.DefaultUndoRedoCommandStack;
46

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

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

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

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

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

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

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

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

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

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

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

    
155
    public void update(Feature feature, Feature oldFeature) throws DataException {
156
        FeatureUpdateCommand command = new FeatureUpdateCommand(featureStore,
157
               feature, oldFeature,
158
                "_featureUpdate");
159
        add(command);
160
        command.execute();
161
    }
162

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

    
171
}