]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/CompositeHintSynchronizer.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / CompositeHintSynchronizer.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.synchronization;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.List;\r
17 \r
18 import org.simantics.utils.datastructures.hints.IHintObservable;\r
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
20 \r
21 /**\r
22  * Synchronizer that is composed of several other synchronizers. It will consult\r
23  * the composed synchronizers in the order in which they were specified. Should\r
24  * a composed synchronizer report that it has handled the synchronization, i.e.\r
25  * returns <code>true</code>, the consultation will end there.\r
26  * \r
27  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
28  * @author Tuukka Lehtonen\r
29  */\r
30 public class CompositeHintSynchronizer implements IHintSynchronizer {\r
31 \r
32     private final List<IHintSynchronizer> synchronizers = new ArrayList<IHintSynchronizer>();\r
33 \r
34     public CompositeHintSynchronizer() {\r
35     }\r
36 \r
37     public CompositeHintSynchronizer(IHintSynchronizer... synchronizers) {\r
38         for (IHintSynchronizer s : synchronizers)\r
39             this.synchronizers.add(s);\r
40     }\r
41 \r
42     public CompositeHintSynchronizer(Collection<IHintSynchronizer> synchronizers) {\r
43         this.synchronizers.addAll(synchronizers);\r
44     }\r
45 \r
46     public CompositeHintSynchronizer add(IHintSynchronizer s) {\r
47         synchronizers.add(s);\r
48         return this;\r
49     }\r
50 \r
51     @Override\r
52     public int synchronize(ISynchronizationContext context, IHintObservable observable) {\r
53         int count = 0;\r
54         for (IHintSynchronizer synchronizer : synchronizers) {\r
55             count += synchronizer.synchronize(context, observable);\r
56         }\r
57         return count;\r
58     }\r
59 \r
60     @Override\r
61     public boolean hintChanged(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue,\r
62             Object newValue) {\r
63         for (IHintSynchronizer s : synchronizers) {\r
64             if (s.hintChanged(context, sender, key, oldValue, newValue))\r
65                 return true;\r
66         }\r
67         return false;\r
68     }\r
69 \r
70     @Override\r
71     public boolean hintRemoved(ISynchronizationContext context, IHintObservable sender, Key key, Object oldValue) {\r
72         for (IHintSynchronizer s : synchronizers) {\r
73             if (s.hintRemoved(context, sender, key, oldValue))\r
74                 return true;\r
75         }\r
76         return false;\r
77     }\r
78 \r
79 }\r