Statistics
| Revision:

root / trunk / libraries / libDataSource / src / org / gvsig / data / commands / implementation / UpdateAttributeCommand.java @ 20469

History | View | Annotate | Download (1.89 KB)

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

    
3
import org.gvsig.data.commands.ICommand;
4
import org.gvsig.data.vectorial.AttributeManager;
5
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
6

    
7
public class UpdateAttributeCommand extends AbstractAttributeCommand{
8
        private IFeatureAttributeDescriptor oldAttributeDescriptor;
9

    
10
        public UpdateAttributeCommand(AttributeManager attributeManager, IFeatureAttributeDescriptor attributeDescriptor, IFeatureAttributeDescriptor oldAttributeDescriptor) {
11
                super(attributeManager,attributeDescriptor);
12
                this.oldAttributeDescriptor=oldAttributeDescriptor;
13
        }
14

    
15
        public UpdateAttributeCommand(AttributeManager attributeManager, IFeatureAttributeDescriptor attributeDescriptor,IFeatureAttributeDescriptor oldAttributeDescriptor, String description) {
16
                super(attributeManager,attributeDescriptor, description);
17
                this.oldAttributeDescriptor=oldAttributeDescriptor;
18
        }
19

    
20
        public void undo() {
21
                if (attributeManager.contains(new Integer(oldAttributeDescriptor.ordinal()))) {
22
            attributeManager.deleteLastAttribute(new Integer(oldAttributeDescriptor.ordinal()));
23
        } else {
24
            attributeManager.deleteAttribute(new Integer(attributeDescriptor.ordinal()));
25
        }
26

    
27
        attributeManager.restoreAttribute(new Integer(attributeDescriptor.ordinal()));
28
        }
29
        public void redo() {
30
                execute();
31
        }
32

    
33
        public String getType() {
34
                return ICommand.UPDATE;
35
        }
36

    
37
        public void execute() {
38
                if (!attributeManager.contains(new Integer(oldAttributeDescriptor.ordinal()))) {
39
            attributeManager.deleteAttribute(new Integer(oldAttributeDescriptor.ordinal()));
40
            attributeManager.addAttribute(attributeDescriptor);
41
        } else {
42

    
43
            attributeManager.updateAttribute(attributeDescriptor);
44
        }
45
        }
46
        public IFeatureAttributeDescriptor getOldAttributeDescriptor(){
47
                return oldAttributeDescriptor;
48
        }
49

    
50
}