]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/TransactionContext.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / handler / TransactionContext.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.g2d.diagram.handler;
13
14 import org.simantics.g2d.diagram.IDiagram;
15 import org.simantics.g2d.element.ElementClass.Required;
16 import org.simantics.g2d.element.ElementClass.Single;
17
18 /**
19  * @author Toni Kalajainen
20  */
21 @Single
22 @Required
23 public interface TransactionContext extends DiagramHandler {
24
25     public static enum TransactionType {
26         READ, WRITE
27     }
28
29     public static interface Transaction {
30         TransactionType getType();
31
32         public static class Impl implements Transaction {
33             TransactionType type;
34             public Impl(TransactionType type) {
35                 this.type = type;
36             }
37             @Override
38             public TransactionType getType() {
39                 return type;
40             }
41             @Override
42             public String toString() {
43                 return "Transaction.Impl[" + type + "]";
44             }
45         }
46     }
47
48     /**
49      * A listener for diagram transaction context events.
50      */
51     public static interface TransactionListener {
52         /**
53          * Invoked when the transaction has been started and locked properly
54          * using
55          * {@link TransactionContext#startTransaction(IDiagram, TransactionType)}
56          * .
57          * 
58          * @param d the diagram where the transaction has started
59          * @param t the transaction handle
60          */
61         void transactionStarted(IDiagram d, Transaction t);
62
63         /**
64          * Invoked if a transaction is committed using
65          * {@link TransactionContext#finishTransaction(IDiagram, Transaction)}
66          * while transaction t still holds on to its lock, either read or write.
67          * 
68          * @param d the diagram where the transaction took place
69          * @param t the transaction handle
70          */
71         void transactionFinished(IDiagram d, Transaction t);
72     }
73
74     void addTransactionListener(IDiagram d, TransactionListener l);
75     void removeTransactionListener(IDiagram d, TransactionListener l);
76
77     Transaction startTransaction(IDiagram d, TransactionType type);
78     void finishTransaction(IDiagram d, Transaction t);
79
80 //    /**
81 //     * @deprecated will be removed
82 //     */
83 //    @Deprecated
84 //    public static class ChangeSet {
85 //        public List<IElement>             added, removed;
86 //        public Map<IElement, HintContext> modifications;
87 //    }
88
89 }