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 / command / SelectionCommandSelectAll.java @ 40559

History | View | Annotate | Download (2.96 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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {Implement data selection}
27
 */
28
package org.gvsig.fmap.dal.feature.impl.undo.command;
29

    
30
import org.gvsig.fmap.dal.feature.exception.SelectionStateException;
31
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
32
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection.SelectionData;
33
import org.gvsig.tools.undo.RedoException;
34
import org.gvsig.tools.undo.UndoException;
35
import org.gvsig.tools.undo.command.impl.AbstractCommand;
36

    
37
/**
38
 * Command to allow undo and redo over a select or deselect ALL operation
39
 * performed on a selection.
40
 * 
41
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
42
 */
43
public class SelectionCommandSelectAll extends AbstractCommand {
44

    
45
    private final DefaultFeatureReferenceSelection selection;
46
    private final boolean allSelected;
47
    private SelectionData selectionData;
48

    
49
    public SelectionCommandSelectAll(
50
            DefaultFeatureReferenceSelection selection,
51
            boolean allSelected, String description)
52
            throws SelectionStateException {
53
        super(description);
54
        this.selection = selection;
55
        this.allSelected = allSelected;
56
        try {
57
            this.selectionData = (SelectionData) selection.getData().clone();
58
        } catch (CloneNotSupportedException ex) {
59
            throw new SelectionStateException(ex);
60
        }
61
    }
62

    
63
    public void execute() {
64
        // Nothing to do
65
    }
66

    
67
    public int getType() {
68
        return allSelected ? INSERT : DELETE;
69
    }
70

    
71
    public void undo() throws UndoException {
72
        selection.setData(selectionData);
73
    }
74

    
75
    public void redo() throws RedoException {
76
        try {
77
            // Re-Obtain the state
78
            selectionData = (SelectionData) selection.getData().clone();
79
            if (allSelected) {
80
                selection.selectAll(false);
81
            } else {
82
                selection.deselectAll(false);
83
            }
84
        } catch (Exception ex) {
85
            throw new RedoException(this, ex);
86
        }
87
    }
88
}