X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2FCompositeHintSynchronizer.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2FCompositeHintSynchronizer.java;h=4d63a16ff868d6d2b79d643803b9049c4ac539de;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CompositeHintSynchronizer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CompositeHintSynchronizer.java new file mode 100644 index 000000000..4d63a16ff --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CompositeHintSynchronizer.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.simantics.utils.datastructures.hints.IHintObservable; +import org.simantics.utils.datastructures.hints.IHintContext.Key; + +/** + * Synchronizer that is composed of several other synchronizers. It will consult + * the composed synchronizers in the order in which they were specified. Should + * a composed synchronizer report that it has handled the synchronization, i.e. + * returns true, the consultation will end there. + * + * @author Marko Luukkainen + * @author Tuukka Lehtonen + */ +public class CompositeHintSynchronizer implements IHintSynchronizer { + + private final List synchronizers = new ArrayList(); + + public CompositeHintSynchronizer() { + } + + public CompositeHintSynchronizer(IHintSynchronizer... synchronizers) { + for (IHintSynchronizer s : synchronizers) + this.synchronizers.add(s); + } + + public CompositeHintSynchronizer(Collection synchronizers) { + this.synchronizers.addAll(synchronizers); + } + + public CompositeHintSynchronizer add(IHintSynchronizer s) { + synchronizers.add(s); + return this; + } + + @Override + public int synchronize(ISynchronizationContext context, IHintObservable observable) { + int count = 0; + for (IHintSynchronizer synchronizer : synchronizers) { + count += synchronizer.synchronize(context, observable); + } + return count; + } + + @Override + public boolean hintChanged(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue, + Object newValue) { + for (IHintSynchronizer s : synchronizers) { + if (s.hintChanged(context, sender, key, oldValue, newValue)) + return true; + } + return false; + } + + @Override + public boolean hintRemoved(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue) { + for (IHintSynchronizer s : synchronizers) { + if (s.hintRemoved(context, sender, key, oldValue)) + return true; + } + return false; + } + +}