]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/MonitorSynchronizer.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / MonitorSynchronizer.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph;
13
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.Resource;
16 import org.simantics.diagram.elements.MonitorClass;
17 import org.simantics.diagram.synchronization.IModificationQueue;
18 import org.simantics.diagram.synchronization.ISynchronizationContext;
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;
20 import org.simantics.utils.datastructures.hints.IHintObservable;
21
22 /**
23  * @author Tuukka Lehtonen
24  */
25 public class MonitorSynchronizer extends ResourceSynchronizer {
26
27     public static final MonitorSynchronizer INSTANCE = new MonitorSynchronizer();
28
29     private static final Key[] SYNCHRONIZED_HINTS = {
30         MonitorClass.KEY_DIRECTION,
31     };
32
33     @Override
34     public Key[] getSynchronizedHints() {
35         return SYNCHRONIZED_HINTS;
36     }
37
38     @Override
39     public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {
40         if (MonitorClass.KEY_DIRECTION.equals(key)) {
41             BasicResources br = context.get(GraphSynchronizationHints.BASIC_RESOURCES);
42             Double dir = (Double) newValue;
43             queue.offer(new PropertyModification(object, br.DIA.HasDirection, br.L0.Double, dir, Bindings.DOUBLE), null);
44             return true;
45         }
46
47         return false;
48     }
49
50 }