Source code: javax/ide/model/Transaction.java
1 package javax.ide.model;
2
3 import java.io.IOException;
4 import javax.swing.undo.UndoableEdit;
5
6 public interface Transaction
7 {
8 /**
9 * Used to instruct a model to start a compound edit
10 * such that all the changes made between this point and when the
11 * <code>endEdit()</code> is called should be combined into a single
12 * UndoableEdit record. This guarantees to the client that the
13 * buffer will be locked for the duration between
14 * <code>beginEdit()</code> and <code>endEdit()</code> for data
15 * consistency. This also takes care of locking the buffer, and
16 * collecting the individual <code>UndoableEdit</code> objects into
17 * a larger compound one. <p>
18 *
19 * Note that compound edits may <b>not</b> be nested - it is illegal
20 * to call <code>beginEdit()</code> twice in a row without calling
21 * <code>endEdit()</code> in between.
22 * @exception ReadOnlyException if the buffer is in read only mode
23 */
24 public void beginEdit() throws IOException;
25
26 /**
27 * Used to indicate to the text buffer to end an in progress
28 * compound edit. This will end the compound edit and returned the
29 * single combined <code>UndoableEdit</code> representing all of the
30 * changes made between the calls to <code>beginEdit()</code> and
31 * <code>endEdit()</code>. If no modifications were made to the
32 * buffer since <code>beginEdit()</code> was called, null will be
33 * returned.
34 * @return the UndoableEdit representing all the changes made
35 */
36 public UndoableEdit commitEdit();
37
38 /**
39 * Used to indicate to the text buffer to end an in progress
40 * compound edit without commiting the changes. The text buffer
41 * will be left in the same state it was found when the call to
42 * <code>beginEdit</code> was made.
43 */
44 public void rollbackEdit();
45
46 /**
47 * This allows the model to be safely read. The given runnable
48 * will be executed in a way that allows it to safely read to the model
49 * (with no changes from other threads) while the runnable is being executed.
50 * Multiple read calls from the same thread are allowed.
51 *
52 * @param runnable a <code>Runnable</code> used to read the model.
53 */
54 public void read( Runnable runnable );
55
56 /**
57 * This allows the model to be safely updated. The given runnable
58 * will be executed in a way that allows it to safely write to the model
59 * (with no changes from other threads) while the runnable is being executed.
60 * Multiple write calls from the same thread are allowed.
61 *
62 * @param runnable a <code>Runnable</code> used to write to the model.
63 */
64 public void write( Runnable runnable );
65
66 }
67