X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2FCopyAdvisor.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2FCopyAdvisor.java;h=959b627ac0b0ae44527da6b9015e6086a776985e;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..959b627ac --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CopyAdvisor.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.synchronization; + +import java.util.EnumSet; +import java.util.Map; + +import org.simantics.g2d.diagram.IDiagram; + +/** + * A CopyAdvisor is used to abstractly evaluate whether a source object can be + * copied and for performing the actual copy operation. CopyAdvisor is a part of + * the Simantics diagram to backend (graph) synchronization framework. + * + *

+ * The {@link #canCopy(ISynchronizationContext, Object)} method returns an + * evaluation of what can be regarding copying of the specified source object. + * The type of the source object depends on the backend just like the contents + * of the received {@link ISynchronizationContext}. + * + *

+ * CopyAdvisor is currently used with {@link IDiagram} to describe how copying + * happens within a diagram (or diagram type). + * + * @author Tuukka Lehtonen + */ +public interface CopyAdvisor { + + public enum Evaluation { + SUPPORTED, + NOT_SUPPORTED, + DENIED, + } + + EnumSet SUPPORTED = EnumSet.of(Evaluation.SUPPORTED); + EnumSet DENIED = EnumSet.of(Evaluation.DENIED); + EnumSet NOT_DENIED = EnumSet.complementOf(DENIED); + + /** + * @param context a context for the synchronization operation + * @param source + * @param sourceContainer + * @param targetContainer + * @return evaluation of the possibilities of copying the source object + */ + Evaluation canCopy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer); + + /** + * @param context a context for the synchronization operation + * @param source + * @param sourceContainer + * @param targetContainer + * @return copied backend object or null if the specified + * source object is not supported + * @throws SynchronizationException if copying is denied for the source + * object + */ + Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer); + + /** + * @param context a context for the synchronization operation + * @param source + * @param sourceContainer + * @param targetContainer + * @param map a map for storing the correspondences between original and + * copied objects. This is used to output data from the copy process. + * @return copied backend object or null if the specified + * source object is not supported + * @throws SynchronizationException if copying is denied for the source + * object + */ + Object copy(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer, + Map map); + + /** + * @param context + * @param source + * @param sourceContainer + * @param targetContainer + * @return any non-null object if successful, null if couldn't + * cut + * @throws SynchronizationException if cut fails + */ + Object cut(ISynchronizationContext context, Object source, Object sourceContainer, Object targetContainer); + + /** + * Invoked when either a copy or cut operation has been finished. + * + * @param context + * @throws SynchronizationException if onFinish fails + */ + void onFinish(ISynchronizationContext context); + +}