Revision 24961

View differences:

branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/UndoRedoInfo.java
34 34
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
35 35
 */
36 36
public interface UndoRedoInfo {
37
    
38
    public final static int DELETE = 0;
39
    public final static int INSERT = 1;
40
    public final static int UPDATE = 2;
37 41

  
38 42
    /**
39 43
     * Returns this command description
......
50 54
     *         redone
51 55
     */
52 56
    public Date getDate();
57
    
58
    /**
59
     * Returns the type of action related to data: insertion, deletion or
60
     * update.
61
     * 
62
     * @return the type of action related to data: insertion, deletion or update
63
     */
64
    public int getType();
53 65
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/AbstractCommand.java
1
/* 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}  {{Task}}
26
 */
27
package org.gvsig.tools.undo.command;
28

  
29
import java.text.DateFormat;
30
import java.util.Date;
31

  
32
/**
33
 * Base implementation for Commands.
34
 *
35
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
36
 */
37
public abstract class AbstractCommand implements Command {
38

  
39
    private Date date;
40

  
41
    private String description;
42

  
43

  
44
    /**
45
     * Creates a new AbstractCommand.
46
     *
47
     * @param description
48
     *            of the command
49
     */
50
    public AbstractCommand() {
51
        updateDate();
52
    }
53

  
54
    /**
55
     * Creates a new AbstractCommand.
56
     *
57
     * @param description
58
     *            of the command
59
     */
60
    public AbstractCommand(String description) {
61
        this.description = description;
62
        updateDate();
63
    }
64

  
65
    public Date getDate() {
66
        return date;
67
    }
68

  
69
    public String getDescription() {
70
        return description;
71
    }
72

  
73
    protected void updateDate() {
74
        date = new Date();
75
    }
76

  
77
    public String toString() {
78
        DateFormat format = DateFormat.getDateTimeInstance();
79
        return "Command: ".concat(getDescription()).concat(", date: ").concat(
80
                format.format(getDate()));
81
    }
82
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/CompoundCommand.java
1
package org.gvsig.tools.undo.command;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.gvsig.tools.undo.RedoException;
7
import org.gvsig.tools.undo.UndoException;
8

  
9
public class CompoundCommand extends AbstractCommand {
10

  
11
    private List commands = new ArrayList();
12

  
13
    public CompoundCommand(String description) {
14
        super(description);
15
    }
16

  
17
    public boolean isEmpty() {
18
        return commands.size() == 0;
19
    }
20

  
21
    public void undo() throws UndoException {
22
        for (int i = commands.size() - 1; i >= 0; i--) {
23
            ((AbstractCommand) commands.get(i)).undo();
24
        }
25
    }
26

  
27
    public void redo() throws RedoException {
28
        for (int i = 0; i < commands.size(); i++) {
29
            ((AbstractCommand) commands.get(i)).redo();
30
        }
31
    }
32

  
33
    public void add(Command c) {
34
        commands.add(c);
35
    }
36
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/DefaultUndoRedoCommandStack.java
1
package org.gvsig.tools.undo.command;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Stack;
6

  
7
import org.gvsig.tools.observer.Observer;
8
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable;
9
import org.gvsig.tools.undo.RedoException;
10
import org.gvsig.tools.undo.UndoException;
11

  
12
/**
13
 * Clase en memoria para registrar y gestionar los comandos que vamos
14
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
15
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
16
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
17
 * para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
18
 * inserta este a la pila de deshacer(undos) y se borra de la de rehacer(redos).
19
 * Si se realiza un deshacer se desapila este comando de la pila deshacer(undos)
20
 * y se apila en la de rehacer(redos). Y de la misma forma cuando se realiza un
21
 * rehacer se desapila este comando de la pila de rehacer(redos) y pasa a la de
22
 * deshacer(undos).
23
 * 
24
 * @author Vicente Caballero Navarro
25
 */
26
public class DefaultUndoRedoCommandStack implements UndoRedoCommandStack {
27
	private Stack undos = new Stack();
28
    private Stack redos = new Stack();
29
    private boolean refresh = true;
30
    private int undosCount = 0;
31
    private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(
32
            this);
33
    private boolean complex = false;
34
    private CompoundCommand collection = null;
35

  
36
	public void add(Command command) {
37
        if (complex) {
38
            collection.add(command);
39
        } else {
40
            undos.add(command);
41
            redos.clear();
42
            refresh = true;
43
            delegateObservable.notifyObservers(new DefaultCommandNotification(
44
                    command, CommandNotification.ADD));
45
        }
46
    }
47

  
48
	public void undo() throws UndoException {
49
        AbstractCommand command = (AbstractCommand) undos.pop();
50
        command.undo();
51
        redos.add(command);
52
        delegateObservable.notifyObservers(new DefaultCommandNotification(
53
                command, CommandNotification.UNDO));
54
    }
55

  
56
	public void redo() throws RedoException {
57
        AbstractCommand command = (AbstractCommand) redos.pop();
58
        command.redo();
59
        undos.add(command);
60
        delegateObservable.notifyObservers(new DefaultCommandNotification(
61
                command, CommandNotification.REDO));
62
    }
63

  
64
    public boolean canRedo() {
65
        // TODO Implement
66
        throw new UnsupportedOperationException("Not Implemented");
67
    }
68

  
69
    public boolean canUndo() {
70
        // TODO Implement
71
        throw new UnsupportedOperationException("Not Implemented");
72
    }
73

  
74
    public void redo(int commands) throws RedoException {
75
        // TODO Implement
76
        throw new UnsupportedOperationException("Not Implemented");
77
    }
78

  
79
    public void undo(int commands) throws UndoException {
80
        // TODO Implement
81
        throw new UnsupportedOperationException("Not Implemented");
82
    }
83
    
84
	public boolean moreUndoCommands() {
85
        return (!undos.isEmpty());
86
    }
87

  
88
	public boolean moreRedoCommands() {
89
        return (!redos.isEmpty());
90
    }
91

  
92
	public List getUndoInfos() {
93
        Stack clonedUndos = (Stack) undos.clone();
94

  
95
		ArrayList commands = new ArrayList();
96
        while (!clonedUndos.isEmpty()) {
97
            commands.add(clonedUndos.pop());
98
        }
99

  
100
		return commands;
101
    }
102

  
103
	public List getRedoInfos() {
104
        Stack clonedRedos = (Stack) redos.clone();
105

  
106
		ArrayList commands = new ArrayList();
107
        while (!clonedRedos.isEmpty()) {
108
            commands.add(clonedRedos.pop());
109
        }
110
        return commands;
111
    }
112

  
113
    // public int getPointer(){
114
    // if (refresh){
115
    // undosCount=undos.size()-1;
116
    // }
117
    // return undosCount;
118
    // }
119
    //
120
    // public void setPointer(int newpos) throws DataException {
121
    // int pos=getPointer();
122
    // if (newpos>pos){
123
    // for (int i=pos;i<newpos;i++){
124
    // redo();
125
    // System.out.println("redos = "+i);
126
    // }
127
    // }else if (pos>newpos){
128
    // for (int i=pos-1;i>=newpos;i--){
129
    // undo();
130
    // System.out.println("undos = "+i);
131
    // }
132
    // }
133
    // }
134

  
135
	public int size() {
136
        return undos.size() + redos.size();
137
    }
138

  
139
	public void clear() {
140
        redos.clear();
141
        undos.clear();
142
    }
143

  
144
	public Command getNextUndoCommand() {
145
        return (Command) undos.peek();
146
    }
147

  
148
	public Command getNextRedoCommand() {
149
        return (Command) redos.peek();
150
    }
151

  
152
	public void addObserver(Observer o) {
153
        delegateObservable.addObserver(o);
154

  
155
	}
156

  
157
	public void deleteObserver(Observer o) {
158
        delegateObservable.deleteObserver(o);
159
    }
160

  
161
	public void deleteObservers() {
162
        delegateObservable.deleteObservers();
163
    }
164

  
165
	public void endComplex() {
166
        if (collection.isEmpty()) {
167
            complex = false;
168
            return;
169
        }
170
		complex = false;
171
        undos.add(collection);
172
        redos.clear();
173
        refresh = true;
174
        delegateObservable.notifyObservers(new DefaultCommandNotification(
175
                collection, CommandNotification.ADD));
176

  
177
	}
178

  
179
	public void startComplex(String description) {
180
        collection = new CompoundCommand(description);
181
        complex = true;
182
    }
183

  
184
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/DefaultCommandNotification.java
1
package org.gvsig.tools.undo.command;
2

  
3
public class DefaultCommandNotification implements CommandNotification {
4
	private Command command;
5
	private String type;
6

  
7
	public DefaultCommandNotification(Command command, String type) {
8
		this.command=command;
9
		this.type=type;
10
	}
11

  
12
	public Command getCommand() {
13
		return this.command;
14
	}
15

  
16
	public String getType() {
17
		return this.type;
18
	}
19
}
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/impl/AbstractCommand.java
1
/* 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}  {{Task}}
26
 */
27
package org.gvsig.tools.undo.command.impl;
28

  
29
import java.text.DateFormat;
30
import java.util.Date;
31

  
32
import org.gvsig.tools.undo.command.Command;
33

  
34
/**
35
 * Base implementation for Commands.
36
 * 
37
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
38
 */
39
public abstract class AbstractCommand implements Command {
40

  
41
    private Date date;
42

  
43
    private String description;
44

  
45
    /**
46
     * Creates a new AbstractCommand.
47
     * 
48
     * @param description
49
     *            of the command
50
     */
51
    public AbstractCommand(String description) {
52
        this.description = description;
53
        updateDate();
54
    }
55

  
56
    public Date getDate() {
57
        return date;
58
    }
59

  
60
    public String getDescription() {
61
        return description;
62
    }
63

  
64
    protected void updateDate() {
65
        date = new Date();
66
    }
67

  
68
    public String toString() {
69
        DateFormat format = DateFormat.getDateTimeInstance();
70
        return "Command: ".concat(getDescription()).concat(", date: ").concat(
71
                format.format(getDate()));
72
    }
73
}
0 74

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/impl/CompoundCommand.java
1
package org.gvsig.tools.undo.command.impl;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.gvsig.tools.undo.RedoException;
7
import org.gvsig.tools.undo.UndoException;
8
import org.gvsig.tools.undo.command.Command;
9

  
10
public class CompoundCommand extends AbstractCommand {
11

  
12
    private List commands = new ArrayList();
13

  
14
    public CompoundCommand(String description) {
15
        super(description);
16
    }
17

  
18
    public boolean isEmpty() {
19
        return commands.size() == 0;
20
    }
21

  
22
    public void undo() throws UndoException {
23
        for (int i = commands.size() - 1; i >= 0; i--) {
24
            ((AbstractCommand) commands.get(i)).undo();
25
        }
26
    }
27

  
28
    public void redo() throws RedoException {
29
        for (int i = 0; i < commands.size(); i++) {
30
            ((AbstractCommand) commands.get(i)).redo();
31
        }
32
    }
33

  
34
    public void add(Command c) {
35
        commands.add(c);
36
    }
37
    
38
    public int getType() {
39
        if (isEmpty()) {
40
            return UPDATE;
41
        } else {
42
            return ((Command) commands.get(0)).getType();
43
        }
44
    }
45
}
0 46

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/impl/DefaultUndoRedoCommandStack.java
1
package org.gvsig.tools.undo.command.impl;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Stack;
6

  
7
import org.gvsig.tools.observer.Observer;
8
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable;
9
import org.gvsig.tools.undo.RedoException;
10
import org.gvsig.tools.undo.UndoException;
11
import org.gvsig.tools.undo.command.Command;
12
import org.gvsig.tools.undo.command.CommandNotification;
13
import org.gvsig.tools.undo.command.UndoRedoCommandStack;
14

  
15
/**
16
 * Clase en memoria para registrar y gestionar los comandos que vamos
17
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
18
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
19
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
20
 * para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
21
 * inserta este a la pila de deshacer(undos) y se borra de la de rehacer(redos).
22
 * Si se realiza un deshacer se desapila este comando de la pila deshacer(undos)
23
 * y se apila en la de rehacer(redos). Y de la misma forma cuando se realiza un
24
 * rehacer se desapila este comando de la pila de rehacer(redos) y pasa a la de
25
 * deshacer(undos).
26
 * 
27
 * @author Vicente Caballero Navarro
28
 */
29
public class DefaultUndoRedoCommandStack implements UndoRedoCommandStack {
30
	private Stack undos = new Stack();
31
    private Stack redos = new Stack();
32
    private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(
33
            this);
34
    private boolean complex = false;
35
    private CompoundCommand collection = null;
36

  
37
	public void add(Command command) {
38
        if (complex) {
39
            collection.add(command);
40
        } else {
41
            undos.add(command);
42
            redos.clear();
43
            delegateObservable.notifyObservers(new DefaultCommandNotification(
44
                    command, CommandNotification.ADD));
45
        }
46
    }
47

  
48
	public void undo() throws UndoException {
49
        AbstractCommand command = (AbstractCommand) undos.pop();
50
        command.undo();
51
        redos.add(command);
52
        delegateObservable.notifyObservers(new DefaultCommandNotification(
53
                command, CommandNotification.UNDO));
54
    }
55

  
56
	public void redo() throws RedoException {
57
        AbstractCommand command = (AbstractCommand) redos.pop();
58
        command.redo();
59
        undos.add(command);
60
        delegateObservable.notifyObservers(new DefaultCommandNotification(
61
                command, CommandNotification.REDO));
62
    }
63

  
64
    public void redo(int commands) throws RedoException {
65
        for (int i = 0; i < commands; i++) {
66
            redo();
67
        }
68
    }
69

  
70
    public void undo(int commands) throws UndoException {
71
        for (int i = 0; i < commands; i++) {
72
            undo();
73
        }
74
    }
75
    
76
	public boolean canUndo() {
77
        return (!undos.isEmpty());
78
    }
79

  
80
	public boolean canRedo() {
81
        return (!redos.isEmpty());
82
    }
83

  
84
	public List getUndoInfos() {
85
        Stack clonedUndos = (Stack) undos.clone();
86

  
87
		ArrayList commands = new ArrayList();
88
        while (!clonedUndos.isEmpty()) {
89
            commands.add(clonedUndos.pop());
90
        }
91

  
92
		return commands;
93
    }
94

  
95
	public List getRedoInfos() {
96
        Stack clonedRedos = (Stack) redos.clone();
97

  
98
		ArrayList commands = new ArrayList();
99
        while (!clonedRedos.isEmpty()) {
100
            commands.add(clonedRedos.pop());
101
        }
102
        return commands;
103
    }
104

  
105
	public int size() {
106
        return undos.size() + redos.size();
107
    }
108

  
109
	public void clear() {
110
        redos.clear();
111
        undos.clear();
112
    }
113

  
114
	public Command getNextUndoCommand() {
115
        return (Command) undos.peek();
116
    }
117

  
118
	public Command getNextRedoCommand() {
119
        return (Command) redos.peek();
120
    }
121

  
122
	public void addObserver(Observer o) {
123
        delegateObservable.addObserver(o);
124

  
125
	}
126

  
127
	public void deleteObserver(Observer o) {
128
        delegateObservable.deleteObserver(o);
129
    }
130

  
131
	public void deleteObservers() {
132
        delegateObservable.deleteObservers();
133
    }
134

  
135
	public void endComplex() {
136
        if (collection.isEmpty()) {
137
            complex = false;
138
            return;
139
        }
140
		complex = false;
141
        undos.add(collection);
142
        redos.clear();
143
        delegateObservable.notifyObservers(new DefaultCommandNotification(
144
                collection, CommandNotification.ADD));
145

  
146
	}
147

  
148
	public void startComplex(String description) {
149
        collection = new CompoundCommand(description);
150
        complex = true;
151
    }
152

  
153
}
0 154

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/impl/DefaultCommandNotification.java
1
package org.gvsig.tools.undo.command.impl;
2

  
3
import org.gvsig.tools.undo.command.Command;
4
import org.gvsig.tools.undo.command.CommandNotification;
5

  
6
public class DefaultCommandNotification implements CommandNotification {
7
	private Command command;
8
	private String type;
9

  
10
	public DefaultCommandNotification(Command command, String type) {
11
		this.command=command;
12
		this.type=type;
13
	}
14

  
15
	public Command getCommand() {
16
		return this.command;
17
	}
18

  
19
	public String getType() {
20
		return this.type;
21
	}
22
}
0 23

  
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/undo/command/UndoRedoCommandStack.java
37 37

  
38 38
    public void add(Command command);
39 39

  
40
    public boolean moreUndoCommands();
41

  
42
    public boolean moreRedoCommands();
43

  
44 40
    public int size();
45 41

  
46 42
    public void clear();
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/FeatureStore.java
12 12
import org.gvsig.fmap.geom.Geometry;
13 13
import org.gvsig.fmap.geom.primitive.Envelope;
14 14
import org.gvsig.tools.observer.Observer;
15
import org.gvsig.tools.undo.command.UndoRedoCommandStack;
15
import org.gvsig.tools.undo.UndoRedoStack;
16 16

  
17 17
/**
18 18
 * <p>
......
36 36
 * </ul>
37 37
 *
38 38
 */
39
public interface FeatureStore extends DataStore {
39
public interface FeatureStore extends DataStore, UndoRedoStack {
40 40

  
41 41
	/** Indicates that this store is in query mode */
42 42
	final static int MODE_QUERY = 0;
......
302 302
	public void insert(EditableFeature feature) throws DataException;
303 303

  
304 304
	/**
305
	 * Undoes the last command executed on the store
306
	 * 
307
	 * @throws DataException
308
	 */
309
	public void undo() throws DataException;
310

  
311
	/**
312
	 * Re-does the last undone command.
313
	 * 
314
	 * @throws DataException
315
	 */
316
	public void redo() throws DataException;
317

  
318
	/**
319
	 * Returns the store command record.
320
	 * 
321
	 * @return
322
	 * 		store's {@link CommandsRecord}
323
	 * 
324
	 * @throws DataException
325
	 */
326
	public UndoRedoCommandStack getCommandsRecord() throws DataException;
327

  
328
	/**
329 305
	 * Creates a new feature using the default feature type and 
330 306
	 * returns it as an {@link EditableFeature}
331 307
	 * 
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
1 1
package org.gvsig.fmap.dal.feature.impl;
2 2

  
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.Iterator;
6
import java.util.List;
3
import java.util.*;
7 4

  
8
import org.gvsig.fmap.dal.DALLocator;
9
import org.gvsig.fmap.dal.DataManager;
10
import org.gvsig.fmap.dal.DataQuery;
11
import org.gvsig.fmap.dal.DataServerExplorer;
12
import org.gvsig.fmap.dal.DataSet;
13
import org.gvsig.fmap.dal.DataStoreNotification;
14
import org.gvsig.fmap.dal.DataStoreParameters;
15
import org.gvsig.fmap.dal.exception.CloseException;
16
import org.gvsig.fmap.dal.exception.DataException;
17
import org.gvsig.fmap.dal.exception.InitializeException;
18
import org.gvsig.fmap.dal.exception.OpenException;
19
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
20
import org.gvsig.fmap.dal.exception.ReadException;
21
import org.gvsig.fmap.dal.feature.EditableFeature;
22
import org.gvsig.fmap.dal.feature.EditableFeatureType;
23
import org.gvsig.fmap.dal.feature.Feature;
24
import org.gvsig.fmap.dal.feature.FeatureIndex;
25
import org.gvsig.fmap.dal.feature.FeatureIndexes;
26
import org.gvsig.fmap.dal.feature.FeatureQuery;
27
import org.gvsig.fmap.dal.feature.FeatureReference;
28
import org.gvsig.fmap.dal.feature.FeatureSelection;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
32
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
33
import org.gvsig.fmap.dal.feature.FeatureType;
34
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
35
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException;
36
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
37
import org.gvsig.fmap.dal.feature.exception.CreateFeatureException;
38
import org.gvsig.fmap.dal.feature.exception.DataExportException;
39
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException;
40
import org.gvsig.fmap.dal.feature.exception.FinishEditingException;
41
import org.gvsig.fmap.dal.feature.exception.GetFeatureTypeException;
42
import org.gvsig.fmap.dal.feature.exception.IllegalFeatureException;
43
import org.gvsig.fmap.dal.feature.exception.IllegalFeatureTypeException;
44
import org.gvsig.fmap.dal.feature.exception.NeedEditingModeException;
45
import org.gvsig.fmap.dal.feature.exception.NoNewFeatureInsertException;
46
import org.gvsig.fmap.dal.feature.exception.NullFeatureTypeException;
47
import org.gvsig.fmap.dal.feature.exception.SelectionNotAllowedException;
48
import org.gvsig.fmap.dal.feature.exception.StoreCancelEditingException;
49
import org.gvsig.fmap.dal.feature.exception.StoreDeleteEditableFeatureException;
50
import org.gvsig.fmap.dal.feature.exception.StoreDeleteFeatureException;
51
import org.gvsig.fmap.dal.feature.exception.StoreEditException;
52
import org.gvsig.fmap.dal.feature.exception.StoreInsertFeatureException;
53
import org.gvsig.fmap.dal.feature.exception.StoreRedoException;
54
import org.gvsig.fmap.dal.feature.exception.StoreUndoException;
55
import org.gvsig.fmap.dal.feature.exception.StoreUpdateFeatureException;
56
import org.gvsig.fmap.dal.feature.exception.StoreUpdateFeatureTypeException;
57
import org.gvsig.fmap.dal.feature.exception.ValidateFeaturesException;
58
import org.gvsig.fmap.dal.feature.exception.WriteNotAllowedException;
59
import org.gvsig.fmap.dal.feature.impl.commands.AbstractCommandsRecord;
60
import org.gvsig.fmap.dal.feature.impl.commands.implementation.FeatureCommandsRecord;
5
import org.gvsig.fmap.dal.*;
6
import org.gvsig.fmap.dal.exception.*;
7
import org.gvsig.fmap.dal.feature.*;
8
import org.gvsig.fmap.dal.feature.exception.*;
61 9
import org.gvsig.fmap.dal.feature.impl.expansionadapter.MemoryExpansionAdapter;
62 10
import org.gvsig.fmap.dal.feature.impl.featureset.DefaultFeatureSet;
63
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureData;
64
import org.gvsig.fmap.dal.feature.spi.FeatureData;
65
import org.gvsig.fmap.dal.feature.spi.FeatureLocks;
66
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
67
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
68
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
11
import org.gvsig.fmap.dal.feature.impl.undo.DefaultFeatureCommandsStack;
12
import org.gvsig.fmap.dal.feature.impl.undo.FeatureCommandsStack;
13
import org.gvsig.fmap.dal.feature.spi.*;
69 14
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices;
70 15
import org.gvsig.fmap.dal.impl.DefaultDataManager;
71 16
import org.gvsig.fmap.geom.primitive.Envelope;
......
78 23
import org.gvsig.tools.operations.OperationContext;
79 24
import org.gvsig.tools.operations.OperationException;
80 25
import org.gvsig.tools.operations.OperationNotSupportedException;
81
import org.gvsig.tools.persistence.AbstractPersistenceManager;
82
import org.gvsig.tools.persistence.PersistenceException;
83
import org.gvsig.tools.persistence.PersistenceValueNotFoundException;
84
import org.gvsig.tools.persistence.PersistentState;
26
import org.gvsig.tools.persistence.*;
27
import org.gvsig.tools.undo.RedoException;
28
import org.gvsig.tools.undo.UndoException;
85 29
import org.gvsig.tools.undo.command.Command;
86
import org.gvsig.tools.undo.command.UndoRedoCommandStack;
87 30
import org.slf4j.Logger;
88 31
import org.slf4j.LoggerFactory;
89 32

  
......
100 43

  
101 44
	private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(this);
102 45

  
103
	private AbstractCommandsRecord commands;
46
	private FeatureCommandsStack commands;
104 47
	private FeatureTypeManager featureTypeManager;
105 48
	private FeatureManager featureManager;
106 49
	private SpatialManager spatialManager;
......
413 356
		return this.provider.isLocksSupported();
414 357
	}
415 358

  
416

  
417 359
	public FeatureSet getLocks() throws DataException {
418 360
		if (!this.provider.isLocksSupported()) {
419 361
			getLogger().warn("Locks not supporteds");
......
588 530
						new MemoryExpansionAdapter());
589 531
				spatialManager = new SpatialManager();
590 532

  
591
				commands = new FeatureCommandsRecord(featureManager,
533
				commands = new DefaultFeatureCommandsStack(featureManager,
592 534
						spatialManager, featureTypeManager);
593 535
				this.mode = MODE_FULLEDIT;
594 536
				hasStrongChanges = false;
......
729 671
		}
730 672
	}
731 673

  
732
	synchronized public void redo() throws DataException {
733
		try {
734
			checkInEditingMode();
735
			Command redo = commands.getNextRedoCommand();
736
			notifyChange(FeatureStoreNotification.BEFORE_REDO, redo);
737
			newVersionOfUpdate();
738
			commands.redo();
739
			hasStrongChanges = true;
740
			notifyChange(FeatureStoreNotification.AFTER_REDO, redo);
741
		} catch (Exception e) {
742
			throw new StoreRedoException(e, this.getName());
743
		}
674
	synchronized public void redo() throws RedoException {
675
	    Command redo = commands.getNextRedoCommand();
676
        try {
677
            checkInEditingMode();
678
        } catch (NeedEditingModeException ex) {
679
            throw new RedoException(redo, ex);
680
        }
681
		notifyChange(FeatureStoreNotification.BEFORE_REDO, redo);
682
        newVersionOfUpdate();
683
        commands.redo();
684
        hasStrongChanges = true;
685
        notifyChange(FeatureStoreNotification.AFTER_REDO, redo);
744 686
	}
745 687

  
746
	synchronized public void undo() throws DataException {
747
		try {
748
			checkInEditingMode();
749
			Command undo = commands.getNextUndoCommand();
750
			notifyChange(FeatureStoreNotification.BEFORE_UNDO, undo);
751
			newVersionOfUpdate();
752
			commands.undo();
753
			hasStrongChanges = true;
754
			notifyChange(FeatureStoreNotification.AFTER_UNDO, undo);
755
		} catch (Exception e) {
756
			throw new StoreUndoException(e, this.getName());
757
		}
688
	synchronized public void undo() throws UndoException {
689
	    Command undo = commands.getNextUndoCommand();
690
        try {
691
            checkInEditingMode();
692
        } catch (NeedEditingModeException ex) {
693
            throw new UndoException(undo, ex);
694
        }
695
		notifyChange(FeatureStoreNotification.BEFORE_UNDO, undo);
696
        newVersionOfUpdate();
697
        commands.undo();
698
        hasStrongChanges = true;
699
        notifyChange(FeatureStoreNotification.AFTER_UNDO, undo);
758 700
	}
759 701

  
760
	synchronized public UndoRedoCommandStack getCommandsRecord() throws DataException {
761
		checkInEditingMode();
762
		return commands;
763
	}
702
    public List getRedoInfos() {
703
        if (isEditing() && commands != null) {
704
            return commands.getRedoInfos();
705
        } else {
706
            return null;
707
        }
708
    }
764 709

  
710
    public List getUndoInfos() {
711
        if (isEditing() && commands != null) {
712
            return commands.getUndoInfos();
713
        } else {
714
            return null;
715
        }
716
    }
717

  
718
    public synchronized FeatureCommandsStack getCommandsStack()
719
            throws DataException {
720
        checkInEditingMode();
721
        return commands;
722
    }
723

  
765 724
	synchronized public void cancelEditing() throws DataException {
766 725
		try {
767 726
			checkInEditingMode();
......
1173 1132
	public FeatureStoreTransforms getTransforms() {
1174 1133
		return this.transforms;
1175 1134
	}
1176

  
1135
	
1177 1136
	public FeatureQuery createFeatureQuery() {
1178
		return new FeatureQuery();
1179
	}
1137
        return new FeatureQuery();
1138
    }
1180 1139

  
1181
}
1140
    public boolean canRedo() {
1141
        return commands.canRedo();
1142
    }
1143

  
1144
    public boolean canUndo() {
1145
        return commands.canUndo();
1146
    }
1147

  
1148
    public void redo(int num) throws RedoException {
1149
        commands.redo(num);
1150
    }
1151

  
1152
    public void undo(int num) throws UndoException {
1153
        commands.undo(num);
1154
    }
1155
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/commands/AbstractCommandsRecord.java
1
package org.gvsig.fmap.dal.feature.impl.commands;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Stack;
6

  
7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.feature.FeatureReference;
9
import org.gvsig.fmap.dal.feature.FeatureReferenceSelection;
10
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
11
import org.gvsig.fmap.dal.feature.impl.commands.implementation.FeatureCommand;
12
import org.gvsig.tools.observer.Observer;
13
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable;
14
import org.gvsig.tools.undo.RedoException;
15
import org.gvsig.tools.undo.UndoException;
16
import org.gvsig.tools.undo.command.AbstractCommand;
17
import org.gvsig.tools.undo.command.Command;
18
import org.gvsig.tools.undo.command.CommandNotification;
19
import org.gvsig.tools.undo.command.CompoundCommand;
20
import org.gvsig.tools.undo.command.DefaultCommandNotification;
21
import org.gvsig.tools.undo.command.UndoRedoCommandStack;
22

  
23
/**
24
 * Clase en memoria para registrar y gestionar los comandos que vamos
25
 * realizando. La forma en que ha sido implementada esta clase, en vez de una
26
 * ?nica lista para albergar los comandos de deshacer(undos) y los de
27
 * rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
28
 * para rehacer(redos), de esta forma :  Cuando se a?ade un nuevo comando, se
29
 * inserta este a la pila de deshacer(undos) y se borra de la de
30
 * rehacer(redos). Si se realiza un deshacer se desapila este comando de la
31
 * pila deshacer(undos) y se apila en la de rehacer(redos). Y de la misma
32
 * forma cuando se realiza un rehacer se desapila este comando de la pila de
33
 * rehacer(redos) y pasa a la de deshacer(undos).
34
 *
35
 * @author Vicente Caballero Navarro
36
 */
37
public abstract class AbstractCommandsRecord implements UndoRedoCommandStack{
38
	private Stack undos = new Stack();
39
	private Stack redos = new Stack();
40
	private boolean refresh=true;
41
	private int undosCount=0;
42
	private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(this);
43
	private boolean complex=false;
44
	private CompoundCommand compound=null;
45

  
46
	public void add(Command command){
47
		if (complex){
48
			compound.add(command);
49
		}else{
50
			undos.add(command);
51
			redos.clear();
52
			refresh=true;
53
			delegateObservable.notifyObservers(new DefaultCommandNotification(command,
54
                    CommandNotification.ADD));
55
		}
56
	}
57

  
58
	public void undo() throws UndoException {
59
		Command command = (Command) undos.pop();
60
		command.undo();
61
		redos.add(command);
62
		delegateObservable.notifyObservers(new DefaultCommandNotification(command,
63
                CommandNotification.UNDO));
64
	}
65

  
66
	public void redo() throws RedoException {
67
		AbstractCommand command = (AbstractCommand) redos.pop();
68
		command.redo();
69
		undos.add(command);
70
		delegateObservable.notifyObservers(new DefaultCommandNotification(command,
71
                CommandNotification.REDO));
72
	}
73

  
74
	public boolean moreUndoCommands() {
75
		return (!undos.isEmpty());
76
	}
77

  
78
	public boolean moreRedoCommands() {
79
		return (!redos.isEmpty());
80
	}
81

  
82
	public List getUndoCommands(){
83
		Stack clonedUndos=(Stack)undos.clone();
84

  
85
		ArrayList commands=new ArrayList();
86
		while (!clonedUndos.isEmpty()){
87
			commands.add(clonedUndos.pop());
88
		}
89

  
90
		return commands;
91
	}
92

  
93
	public List getRedoCommands(){
94
		Stack clonedRedos=(Stack)redos.clone();
95

  
96
		ArrayList commands=new ArrayList();
97
		while (!clonedRedos.isEmpty()){
98
			commands.add(clonedRedos.pop());
99
		}
100
		return commands;
101
	}
102

  
103
	public int getPointer(){
104
		if (refresh){
105
			undosCount=undos.size()-1;
106
		}
107
		return undosCount;
108
	}
109

  
110
//	public void setPointer(int newpos) throws DataException {
111
//		int pos=getPointer();
112
//		if (newpos>pos){
113
//			for (int i=pos;i<newpos;i++){
114
//				redo();
115
//				System.out.println("redos = "+i);
116
//			}
117
//		}else if (pos>newpos){
118
//			for (int i=pos-1;i>=newpos;i--){
119
//				undo();
120
//				System.out.println("undos = "+i);
121
//			}
122
//		}
123
//	}
124

  
125
	public int size() {
126
		return undos.size()+redos.size();
127
	}
128

  
129
	public void clear() {
130
		redos.clear();
131
		undos.clear();
132
	}
133

  
134
	public Command getNextUndoCommand() {
135
		return (Command)undos.peek();
136
	}
137

  
138
	public Command getNextRedoCommand() {
139
		return (Command)redos.peek();
140
	}
141

  
142
	public void addObserver(Observer o) {
143
		delegateObservable.addObserver(o);
144

  
145
	}
146

  
147
	public void deleteObserver(Observer o) {
148
		delegateObservable.deleteObserver(o);
149
	}
150

  
151
	public void deleteObservers() {
152
		delegateObservable.deleteObservers();
153
	}
154
///**
155
// * @deprecated
156
// * @return
157
// */
158
//	public List getCommandsFeatureDeleted() { // List of Feature
159
//		Stack clonedUndos=(Stack)undos.clone();
160
//
161
//		ArrayList commands=new ArrayList();
162
//		while (!clonedUndos.isEmpty()){
163
//			Command command=(Command)clonedUndos.pop();
164
//			if (command.getType().equals(Command.DELETE) && command instanceof FeatureCommand) {
165
//				commands.add(command);
166
//			}
167
//		}
168
//
169
//		return commands;
170
//	}
171
//	/**
172
//	 * @deprecated
173
//	 * @return
174
//	 */
175
//	public List getCommandsFeatureUpdated() { // List of Feature
176
//		Stack clonedUndos=(Stack)undos.clone();
177
//
178
//		ArrayList commands=new ArrayList();
179
//		while (!clonedUndos.isEmpty()){
180
//			Command command=(Command)clonedUndos.pop();
181
//			if (command.getType().equals(Command.UPDATE) && command instanceof FeatureCommand) {
182
//				commands.add(command);
183
//			}
184
//		}
185
//
186
//		return commands;
187
//	}
188
//	/**
189
//	 * @deprecated
190
//	 * @return
191
//	 */
192
//	public List getCommandsFeatureInserted() { // List of Feature
193
//		Stack clonedUndos=(Stack)undos.clone();
194
//
195
//		ArrayList commands=new ArrayList();
196
//		while (!clonedUndos.isEmpty()){
197
//			Command command=(Command)clonedUndos.pop();
198
//			if (command.getType().equals(Command.INSERT) && command instanceof FeatureCommand) {
199
//				commands.add(command);
200
//			}
201
//		}
202
//
203
//		return commands;
204
//	}
205

  
206
	public void endComplex() {
207
		if (compound.isEmpty()) {
208
        	complex = false;
209
        	return;
210
        }
211
		complex=false;
212
		undos.add(compound);
213
		redos.clear();
214
		refresh=true;
215
		delegateObservable.notifyObservers(new DefaultCommandNotification(compound,
216
                CommandNotification.ADD));
217

  
218
	}
219

  
220
	public void startComplex(String description) {
221
		compound=new CompoundCommand(description);
222
		complex=true;
223
	}
224

  
225
	public abstract void delete(Object obj);
226

  
227
	public abstract void insert(Object obj);
228

  
229
	public abstract void update(Object obj, Object oldObj);
230

  
231
	public abstract void select(
232
			FeatureReferenceSelection selection,
233
			FeatureReference reference);
234

  
235
	public abstract void deselect(
236
			FeatureReferenceSelection selection,
237
			FeatureReference reference);
238

  
239
	public abstract void selectAll(
240
			FeatureReferenceSelection selection)
241
            throws DataException;
242

  
243
	public abstract void deselectAll(
244
			FeatureReferenceSelection selection)
245
            throws DataException;
246

  
247
	public abstract void selectionReverse(
248
			FeatureReferenceSelection selection);
249

  
250
	public abstract void selectionSet(DefaultFeatureStore store,
251
			FeatureReferenceSelection oldSelection,
252
			FeatureReferenceSelection newSelection);
253
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReferenceSelection.java
37 37
import org.gvsig.fmap.dal.feature.FeatureReference;
38 38
import org.gvsig.fmap.dal.feature.FeatureReferenceSelection;
39 39
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
40
import org.gvsig.fmap.dal.feature.impl.commands.AbstractCommandsRecord;
40
import org.gvsig.fmap.dal.feature.impl.undo.FeatureCommandsStack;
41 41
import org.gvsig.tools.exception.BaseException;
42 42
import org.gvsig.tools.observer.Observable;
43 43
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable;
......
285 285
	 * 
286 286
	 * @return the reference to the commands record
287 287
	 */
288
    protected AbstractCommandsRecord getCommands() {
288
    protected FeatureCommandsStack getCommands() {
289 289
        try {
290
            return (AbstractCommandsRecord) getFeatureStore()
291
                    .getCommandsRecord();
290
            return getFeatureStore().getCommandsStack();
292 291
        } catch (DataException e) {
293 292
            // Ignore
294 293
            return null;

Also available in: Unified diff