Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / impl / commands / implementation / UpdateAttributeCommand.java @ 23754

History | View | Annotate | Download (1.91 KB)

1
package org.gvsig.fmap.data.feature.impl.commands.implementation;
2

    
3
import org.gvsig.fmap.data.feature.Command;
4
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
5
import org.gvsig.fmap.data.feature.impl.AttributeManager;
6

    
7
public class UpdateAttributeCommand extends AttributeCommand{
8
        private FeatureAttributeDescriptor oldAttributeDescriptor;
9

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

    
15
        public UpdateAttributeCommand(AttributeManager attributeManager, FeatureAttributeDescriptor attributeDescriptor,FeatureAttributeDescriptor 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 Command.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 FeatureAttributeDescriptor getOldAttributeDescriptor(){
47
                return oldAttributeDescriptor;
48
        }
49

    
50
}