root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / commands / implementation / SelectionCommandSelectAll.java @ 24496
History | View | Annotate | Download (2.95 KB)
1 | 24346 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Gobernment (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 {DiSiD Technologies} {Implement data selection}
|
||
26 | */
|
||
27 | 24496 | jmvivo | package org.gvsig.fmap.dal.feature.impl.commands.implementation; |
28 | 24194 | jjdelcerro | |
29 | 24496 | jmvivo | import org.gvsig.fmap.dal.exceptions.DataException; |
30 | import org.gvsig.fmap.dal.feature.FeatureReferenceSelection; |
||
31 | import org.gvsig.fmap.dal.feature.exceptions.SelectionStateException; |
||
32 | import org.gvsig.fmap.dal.feature.impl.commands.AbstractCommand; |
||
33 | 24346 | cordinyana | import org.gvsig.tools.persistence.PersistenceException; |
34 | import org.gvsig.tools.persistence.PersistentState; |
||
35 | 24194 | jjdelcerro | |
36 | 24346 | cordinyana | /**
|
37 | * Command to allow undo and redo over a select or deselect ALL operation
|
||
38 | * performed on a selection.
|
||
39 | *
|
||
40 | * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
||
41 | */
|
||
42 | 24194 | jjdelcerro | public class SelectionCommandSelectAll extends AbstractCommand { |
43 | |||
44 | 24346 | cordinyana | private final FeatureReferenceSelection selection; |
45 | private final boolean allSelected; |
||
46 | private PersistentState state;
|
||
47 | 24194 | jjdelcerro | |
48 | 24346 | cordinyana | public SelectionCommandSelectAll(FeatureReferenceSelection selection,
|
49 | boolean allSelected) throws SelectionStateException { |
||
50 | this.selection = selection;
|
||
51 | this.allSelected = allSelected;
|
||
52 | try {
|
||
53 | state = selection.getState(); |
||
54 | } catch (PersistenceException ex) {
|
||
55 | throw new SelectionStateException(ex); |
||
56 | } |
||
57 | } |
||
58 | 24194 | jjdelcerro | |
59 | 24346 | cordinyana | public void execute() { |
60 | // Nothing to do
|
||
61 | } |
||
62 | 24194 | jjdelcerro | |
63 | 24346 | cordinyana | public String getType() { |
64 | return allSelected ? "selectionSelectAll" : "selectionDeselectAll"; |
||
65 | } |
||
66 | 24194 | jjdelcerro | |
67 | 24346 | cordinyana | public void undo() throws DataException { |
68 | 24347 | cordinyana | if (state != null) { |
69 | try {
|
||
70 | selection.setState(state); |
||
71 | } catch (PersistenceException ex) {
|
||
72 | throw new SelectionStateException(ex); |
||
73 | } |
||
74 | 24346 | cordinyana | } |
75 | } |
||
76 | 24194 | jjdelcerro | |
77 | 24346 | cordinyana | public void redo() throws DataException { |
78 | 24347 | cordinyana | // Re-Obtain the state, just in case
|
79 | 24346 | cordinyana | try {
|
80 | state = selection.getState(); |
||
81 | } catch (PersistenceException ex) {
|
||
82 | throw new SelectionStateException(ex); |
||
83 | } |
||
84 | if (allSelected) {
|
||
85 | selection.selectAll(); |
||
86 | } else {
|
||
87 | selection.deselectAll(); |
||
88 | } |
||
89 | } |
||
90 | } |