]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/UndoRedoSupport.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / UndoRedoSupport.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.service;
13
14 import java.util.Collection;
15 import java.util.List;
16
17 import org.simantics.db.Operation;
18 import org.simantics.db.Session;
19 import org.simantics.db.UndoContext;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.exception.ConflictException;
22 import org.simantics.db.exception.DatabaseException;
23
24 public interface UndoRedoSupport {
25
26     Operation getCurrent();
27
28     /**
29      * @param operations
30      * @return Operation generated by the undo operation.
31      * 
32      * @throws DatabaseException
33      * @throws ConflictException
34      */
35     Operation undo(Collection<Operation> operations)
36     throws DatabaseException, ConflictException;
37
38     /**
39      * This is just a wrapper for the undo operation above. See documentation above
40      * 
41      * @param op the operation that will be undone.
42      * @throws DatabaseException
43      * @throws ConflictException
44      */
45     void undo(Operation op)
46     throws DatabaseException, ConflictException;
47
48     /**
49      * Undo first count operations from the session undo list.
50      * 
51      * @param count number of operations to revert and move to sessions redo list.
52      * @return Number of changes sets reverted.
53      * @throws DatabaseException
54      * @throws ConflictException
55      */
56     int undo(Session session, int count)
57     throws DatabaseException;
58     
59     List<Operation> undoAndReturnOperations(Session session, int count)
60     throws DatabaseException;   
61     
62     List<Operation> redo(Session session, int count)
63     throws DatabaseException;
64
65     int undoTo(Session session, long changeSet)
66     throws DatabaseException;
67
68     int initUndoListFrom(Session session, long changeSet)
69     throws DatabaseException;
70
71     /**
72      * @return undo context used by given session. If session does not support
73      *         undo or session is disposed, <code>null</code> will be returned.
74      */
75     UndoContext getUndoContext(Session session);
76
77     interface ChangeListener {
78         /**
79          * Called when undo/redo lists change. 
80          */
81         void onChanged();
82     }
83     void subscribe(ChangeListener changeListener);
84     void cancel(ChangeListener changeListener);
85     
86     void addExternalOperation(WriteGraph graph, ExternalOperation op);
87     
88 }