Revision 21296

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/data/commands/CommandCollection.java
1
package org.gvsig.data.commands;
2

  
3
import java.util.ArrayList;
4

  
5
public class CommandCollection extends AbstractCommand{
6
	ArrayList commands=new ArrayList();
7
	public boolean isEmpty() {
8
		return commands.size()==0;
9
	}
10
	/**
11
	 * @throws EditionCommandException
12
	 * @see com.iver.cit.gvsig.fmap.edition.Command#undo()
13
	 */
14
	public void undo() {
15
	for(int i=commands.size()-1;i>=0;i--){
16
		((Command)commands.get(i)).undo();
17
	}
18
	}
19

  
20
	/**
21
	 * @throws EditionCommandException
22
	 * @see com.iver.cit.gvsig.fmap.edition.Command#redo()
23
	 */
24
	public void redo() {
25
		for (int i=0;i<commands.size();i++){
26
			((Command)commands.get(i)).redo();
27
		}
28
	}
29
	public void add(Command c){
30
		commands.add(c);
31
	}
32

  
33
	public String getType() {
34
		if (commands.size() == 0)
35
			return null;
36
		ArrayList types=new ArrayList(3);
37
		for (int i=0;i<commands.size();i++) {
38
			String type=((Command)commands.get(i)).getType();
39
			if (!types.contains(type))
40
				types.add(type);
41
		}
42
		String type="";
43
		type=(String)types.get(0);
44
		for (int i=1;i<types.size();i++) {
45
			type=type+"-"+(String)types.get(i);
46
		}
47
		return type;
48
	}
49
	public void execute() {
50
		for (int i=0;i<commands.size();i++){
51
			((Command)commands.get(i)).execute();
52
		}
53
	}
54
}
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/data/commands/CommandsRecord.java
58 58
	public List getCommandsAttributeDeleted();
59 59
	public List getCommandsAttributeUpdated();
60 60
	public List getCommandsAttributeInserted();
61
	public void startComplex();
62
	public void endComplex(String description);
61 63
}
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/data/commands/AbstractCommandsRecord.java
6 6

  
7 7
import org.gvsig.data.commands.implementation.AttributeCommand;
8 8
import org.gvsig.data.commands.implementation.FeatureCommand;
9
import org.gvsig.util.observer.DefaultObservable;
9 10
import org.gvsig.util.observer.Observer;
10
import org.gvsig.util.observer.DefaultObservable;
11 11

  
12 12
/**
13 13
 * Clase en memoria para registrar y gestionar los comandos que vamos
......
29 29
	private boolean refresh=true;
30 30
	private int undosCount=0;
31 31
	private DefaultObservable observable=new DefaultObservable();
32
	private boolean complex=false;
33
	private CommandCollection collection=null;
32 34
//	private ComplexObservable observable=new ComplexObservable();
33 35
	/* (non-Javadoc)
34 36
	 * @see org.gvsig.data.commands.CommandsRecord#add(org.gvsig.data.commands.Command)
35 37
	 */
36 38
	public void add(Command command){
37
		undos.add(command);
38
		redos.clear();
39
		refresh=true;
40
		observable.notifyObservers(this,new CommandNotification(command,CommandNotification.ADD));
39
		if (complex){
40
			collection.add(command);
41
		}else{
42
			undos.add(command);
43
			redos.clear();
44
			refresh=true;
45
			observable.notifyObservers(this,new CommandNotification(command,CommandNotification.ADD));
46
		}
41 47
	}
42 48

  
43 49
	/* (non-Javadoc)
......
250 256
		return commands;
251 257
	}
252 258

  
259
	public void endComplex(String description) {
260
		if (collection.isEmpty()) {
261
        	complex = false;
262
        	return;
263
        }
264
		complex=false;
265
		collection.setDescription(description);
266
		undos.add(collection);
267
		redos.clear();
268
		refresh=true;
269
		observable.notifyObservers(this,new CommandNotification(collection,CommandNotification.ADD));
270

  
271
	}
272

  
273
	public void startComplex() {
274
		collection=new CommandCollection();
275
		complex=true;
276
	}
277

  
253 278
}

Also available in: Unified diff