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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.synchronization;
\r
14 import java.util.EnumSet;
\r
15 import java.util.Map;
\r
17 import org.simantics.g2d.diagram.IDiagram;
\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
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
31 * CopyAdvisor is currently used with {@link IDiagram} to describe how copying
\r
32 * happens within a diagram (or diagram type).
\r
34 * @author Tuukka Lehtonen
\r
36 public interface CopyAdvisor {
\r
38 public enum Evaluation {
\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
49 * @param context a context for the synchronization operation
\r
51 * @param sourceContainer
\r
52 * @param targetContainer
\r
53 * @return evaluation of the possibilities of copying the source object
\r
55 Evaluation canCopy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);
\r
58 * @param context a context for the synchronization operation
\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
67 Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);
\r
70 * @param context a context for the synchronization operation
\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
81 Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer,
\r
82 Map<Object, Object> map);
\r
87 * @param sourceContainer
\r
88 * @param targetContainer
\r
89 * @return any non-null object if successful, <code>null</code> if couldn't
\r
91 * @throws SynchronizationException if cut fails
\r
93 Object cut(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);
\r
96 * Invoked when either a copy or cut operation has been finished.
\r
99 * @throws SynchronizationException if onFinish fails
\r
101 void onFinish(ISynchronizationContext context);
\r