root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / commands / CommandCollection.java @ 24496
History | View | Annotate | Download (1.54 KB)
1 |
package org.gvsig.fmap.dal.feature.impl.commands; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.fmap.dal.exceptions.DataException; |
6 |
import org.gvsig.fmap.dal.feature.Command; |
7 |
|
8 |
public class CommandCollection extends AbstractCommand{ |
9 |
private ArrayList commands=new ArrayList(); |
10 |
|
11 |
public CommandCollection(String description){ |
12 |
super(description);
|
13 |
} |
14 |
|
15 |
|
16 |
public boolean isEmpty() { |
17 |
return commands.size()==0; |
18 |
} |
19 |
/**
|
20 |
* @throws EditionCommandException
|
21 |
* @see org.gvsig.fmap.dal.feature.cit.gvsig.fmap.edition.Command#undo()
|
22 |
*/
|
23 |
public void undo() throws DataException { |
24 |
for(int i=commands.size()-1;i>=0;i--){ |
25 |
((AbstractCommand) commands.get(i)).undo(); |
26 |
} |
27 |
} |
28 |
|
29 |
/**
|
30 |
* @throws EditionCommandException
|
31 |
* @see org.gvsig.fmap.dal.feature.cit.gvsig.fmap.edition.Command#redo()
|
32 |
*/
|
33 |
public void redo() throws DataException { |
34 |
for (int i=0;i<commands.size();i++){ |
35 |
((AbstractCommand) commands.get(i)).redo(); |
36 |
} |
37 |
} |
38 |
public void add(Command c){ |
39 |
commands.add(c); |
40 |
} |
41 |
|
42 |
public String getType() { |
43 |
if (commands.size() == 0) { |
44 |
return null; |
45 |
} |
46 |
ArrayList types=new ArrayList(3); |
47 |
for (int i=0;i<commands.size();i++) { |
48 |
String type=((Command)commands.get(i)).getType();
|
49 |
if (!types.contains(type)) {
|
50 |
types.add(type); |
51 |
} |
52 |
} |
53 |
String type=""; |
54 |
type=(String)types.get(0); |
55 |
for (int i=1;i<types.size();i++) { |
56 |
type=type+"-"+(String)types.get(i); |
57 |
} |
58 |
return type;
|
59 |
} |
60 |
public void execute() { |
61 |
for (int i=0;i<commands.size();i++){ |
62 |
((AbstractCommand) commands.get(i)).execute(); |
63 |
} |
64 |
} |
65 |
} |