]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CopyAdvisor.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CopyAdvisor.java
new file mode 100644 (file)
index 0000000..959b627
--- /dev/null
@@ -0,0 +1,103 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.synchronization;\r
+\r
+import java.util.EnumSet;\r
+import java.util.Map;\r
+\r
+import org.simantics.g2d.diagram.IDiagram;\r
+\r
+/**\r
+ * A CopyAdvisor is used to abstractly evaluate whether a source object can be\r
+ * copied and for performing the actual copy operation. CopyAdvisor is a part of\r
+ * the Simantics diagram to backend (graph) synchronization framework.\r
+ * \r
+ * <p>\r
+ * The {@link #canCopy(ISynchronizationContext, Object)} method returns an\r
+ * evaluation of what can be regarding copying of the specified source object.\r
+ * The type of the source object depends on the backend just like the contents\r
+ * of the received {@link ISynchronizationContext}.\r
+ * \r
+ * <p>\r
+ * CopyAdvisor is currently used with {@link IDiagram} to describe how copying\r
+ * happens within a diagram (or diagram type).\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public interface CopyAdvisor {\r
+\r
+    public enum Evaluation {\r
+        SUPPORTED,\r
+        NOT_SUPPORTED,\r
+        DENIED,\r
+    }\r
+\r
+    EnumSet<Evaluation> SUPPORTED  = EnumSet.of(Evaluation.SUPPORTED);\r
+    EnumSet<Evaluation> DENIED     = EnumSet.of(Evaluation.DENIED);\r
+    EnumSet<Evaluation> NOT_DENIED = EnumSet.complementOf(DENIED);\r
+\r
+    /**\r
+     * @param context a context for the synchronization operation\r
+     * @param source\r
+     * @param sourceContainer\r
+     * @param targetContainer\r
+     * @return evaluation of the possibilities of copying the source object\r
+     */\r
+    Evaluation canCopy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
+\r
+    /**\r
+     * @param context a context for the synchronization operation\r
+     * @param source\r
+     * @param sourceContainer\r
+     * @param targetContainer\r
+     * @return copied backend object or <code>null</code> if the specified\r
+     *         source object is not supported\r
+     * @throws SynchronizationException if copying is denied for the source\r
+     *         object\r
+     */\r
+    Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
+\r
+    /**\r
+     * @param context a context for the synchronization operation\r
+     * @param source\r
+     * @param sourceContainer\r
+     * @param targetContainer\r
+     * @param map a map for storing the correspondences between original and\r
+     *        copied objects. This is used to output data from the copy process.\r
+     * @return copied backend object or <code>null</code> if the specified\r
+     *         source object is not supported\r
+     * @throws SynchronizationException if copying is denied for the source\r
+     *         object\r
+     */\r
+    Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer,\r
+            Map<Object, Object> map);\r
+\r
+    /**\r
+     * @param context\r
+     * @param source\r
+     * @param sourceContainer\r
+     * @param targetContainer\r
+     * @return any non-null object if successful, <code>null</code> if couldn't\r
+     *         cut\r
+     * @throws SynchronizationException if cut fails\r
+     */\r
+    Object cut(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer);\r
+\r
+    /**\r
+     * Invoked when either a copy or cut operation has been finished.\r
+     * \r
+     * @param context\r
+     * @throws SynchronizationException if onFinish fails\r
+     */\r
+    void onFinish(ISynchronizationContext context);\r
+\r
+}\r