]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CopyAdvisor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / CopyAdvisor.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.diagram.synchronization;\r
13 \r
14 import java.util.EnumSet;\r
15 import java.util.Map;\r
16 \r
17 import org.simantics.g2d.diagram.IDiagram;\r
18 \r
19 /**\r
20  * A CopyAdvisor is used to abstractly evaluate whether a source object can be\r
21  * copied and for performing the actual copy operation. CopyAdvisor is a part of\r
22  * the Simantics diagram to backend (graph) synchronization framework.\r
23  * \r
24  * <p>\r
25  * The {@link #canCopy(ISynchronizationContext, Object)} method returns an\r
26  * evaluation of what can be regarding copying of the specified source object.\r
27  * The type of the source object depends on the backend just like the contents\r
28  * of the received {@link ISynchronizationContext}.\r
29  * \r
30  * <p>\r
31  * CopyAdvisor is currently used with {@link IDiagram} to describe how copying\r
32  * happens within a diagram (or diagram type).\r
33  * \r
34  * @author Tuukka Lehtonen\r
35  */\r
36 public interface CopyAdvisor {\r
37 \r
38     public enum Evaluation {\r
39         SUPPORTED,\r
40         NOT_SUPPORTED,\r
41         DENIED,\r
42     }\r
43 \r
44     EnumSet<Evaluation> SUPPORTED  = EnumSet.of(Evaluation.SUPPORTED);\r
45     EnumSet<Evaluation> DENIED     = EnumSet.of(Evaluation.DENIED);\r
46     EnumSet<Evaluation> NOT_DENIED = EnumSet.complementOf(DENIED);\r
47 \r
48     /**\r
49      * @param context a context for the synchronization operation\r
50      * @param source\r
51      * @param sourceContainer\r
52      * @param targetContainer\r
53      * @return evaluation of the possibilities of copying the source object\r
54      */\r
55     Evaluation canCopy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
56 \r
57     /**\r
58      * @param context a context for the synchronization operation\r
59      * @param source\r
60      * @param sourceContainer\r
61      * @param targetContainer\r
62      * @return copied backend object or <code>null</code> if the specified\r
63      *         source object is not supported\r
64      * @throws SynchronizationException if copying is denied for the source\r
65      *         object\r
66      */\r
67     Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
68 \r
69     /**\r
70      * @param context a context for the synchronization operation\r
71      * @param source\r
72      * @param sourceContainer\r
73      * @param targetContainer\r
74      * @param map a map for storing the correspondences between original and\r
75      *        copied objects. This is used to output data from the copy process.\r
76      * @return copied backend object or <code>null</code> if the specified\r
77      *         source object is not supported\r
78      * @throws SynchronizationException if copying is denied for the source\r
79      *         object\r
80      */\r
81     Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer,\r
82             Map<Object, Object> map);\r
83 \r
84     /**\r
85      * @param context\r
86      * @param source\r
87      * @param sourceContainer\r
88      * @param targetContainer\r
89      * @return any non-null object if successful, <code>null</code> if couldn't\r
90      *         cut\r
91      * @throws SynchronizationException if cut fails\r
92      */\r
93     Object cut(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
94 \r
95     /**\r
96      * Invoked when either a copy or cut operation has been finished.\r
97      * \r
98      * @param context\r
99      * @throws SynchronizationException if onFinish fails\r
100      */\r
101     void onFinish(ISynchronizationContext context);\r
102 \r
103 }\r