]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/TransactionContext.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / handler / TransactionContext.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.diagram.handler;\r
13 \r
14 import org.simantics.g2d.diagram.IDiagram;\r
15 import org.simantics.g2d.element.ElementClass.Required;\r
16 import org.simantics.g2d.element.ElementClass.Single;\r
17 \r
18 /**\r
19  * @author Toni Kalajainen\r
20  */\r
21 @Single\r
22 @Required\r
23 public interface TransactionContext extends DiagramHandler {\r
24 \r
25     public static enum TransactionType {\r
26         READ, WRITE\r
27     }\r
28 \r
29     public static interface Transaction {\r
30         TransactionType getType();\r
31 \r
32         public static class Impl implements Transaction {\r
33             TransactionType type;\r
34             public Impl(TransactionType type) {\r
35                 this.type = type;\r
36             }\r
37             @Override\r
38             public TransactionType getType() {\r
39                 return type;\r
40             }\r
41             @Override\r
42             public String toString() {\r
43                 return "Transaction.Impl[" + type + "]";\r
44             }\r
45         }\r
46     }\r
47 \r
48     /**\r
49      * A listener for diagram transaction context events.\r
50      */\r
51     public static interface TransactionListener {\r
52         /**\r
53          * Invoked when the transaction has been started and locked properly\r
54          * using\r
55          * {@link TransactionContext#startTransaction(IDiagram, TransactionType)}\r
56          * .\r
57          * \r
58          * @param d the diagram where the transaction has started\r
59          * @param t the transaction handle\r
60          */\r
61         void transactionStarted(IDiagram d, Transaction t);\r
62 \r
63         /**\r
64          * Invoked if a transaction is committed using\r
65          * {@link TransactionContext#finishTransaction(IDiagram, Transaction)}\r
66          * while transaction t still holds on to its lock, either read or write.\r
67          * \r
68          * @param d the diagram where the transaction took place\r
69          * @param t the transaction handle\r
70          */\r
71         void transactionFinished(IDiagram d, Transaction t);\r
72     }\r
73 \r
74     void addTransactionListener(IDiagram d, TransactionListener l);\r
75     void removeTransactionListener(IDiagram d, TransactionListener l);\r
76 \r
77     Transaction startTransaction(IDiagram d, TransactionType type);\r
78     void finishTransaction(IDiagram d, Transaction t);\r
79 \r
80 //    /**\r
81 //     * @deprecated will be removed\r
82 //     */\r
83 //    @Deprecated\r
84 //    public static class ChangeSet {\r
85 //        public List<IElement>             added, removed;\r
86 //        public Map<IElement, HintContext> modifications;\r
87 //    }\r
88 \r
89 }\r