--- /dev/null
+/*******************************************************************************\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.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+/**\r
+ * Synchronizer that is composed of several other synchronizers. It will consult\r
+ * the composed synchronizers in the order in which they were specified. Should\r
+ * a composed synchronizer report that it has handled the synchronization, i.e.\r
+ * returns <code>true</code>, the consultation will end there.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class CompositeHintSynchronizer implements IHintSynchronizer {\r
+\r
+ private final List<IHintSynchronizer> synchronizers = new ArrayList<IHintSynchronizer>();\r
+\r
+ public CompositeHintSynchronizer() {\r
+ }\r
+\r
+ public CompositeHintSynchronizer(IHintSynchronizer... synchronizers) {\r
+ for (IHintSynchronizer s : synchronizers)\r
+ this.synchronizers.add(s);\r
+ }\r
+\r
+ public CompositeHintSynchronizer(Collection<IHintSynchronizer> synchronizers) {\r
+ this.synchronizers.addAll(synchronizers);\r
+ }\r
+\r
+ public CompositeHintSynchronizer add(IHintSynchronizer s) {\r
+ synchronizers.add(s);\r
+ return this;\r
+ }\r
+\r
+ @Override\r
+ public int synchronize(ISynchronizationContext context, IHintObservable observable) {\r
+ int count = 0;\r
+ for (IHintSynchronizer synchronizer : synchronizers) {\r
+ count += synchronizer.synchronize(context, observable);\r
+ }\r
+ return count;\r
+ }\r
+\r
+ @Override\r
+ public boolean hintChanged(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue,\r
+ Object newValue) {\r
+ for (IHintSynchronizer s : synchronizers) {\r
+ if (s.hintChanged(context, sender, key, oldValue, newValue))\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean hintRemoved(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue) {\r
+ for (IHintSynchronizer s : synchronizers) {\r
+ if (s.hintRemoved(context, sender, key, oldValue))\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+}\r