]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/MonitorRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / rules / MonitorRule.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * 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.modeling.typicals.rules;
13
14 import org.simantics.db.Resource;
15 import org.simantics.db.WriteGraph;
16 import org.simantics.db.common.utils.NameUtils;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.diagram.stubs.DiagramResource;
19 import org.simantics.diagram.stubs.G2DResource;
20 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
21 import org.simantics.modeling.typicals.TypicalInfo;
22 import org.simantics.operation.Layer0X;
23
24 /**
25  * Synchronizes:
26  * * HasMonitorSuffix
27  * * Visual attributes: alignments, font, format text, colors
28  * 
29  * @author Tuukka Lehtonen
30  */
31 public enum MonitorRule implements ITypicalSynchronizationRule {
32
33     INSTANCE;
34
35     public static MonitorRule getInstance() {
36         return INSTANCE;
37     }
38
39     @Override
40     public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
41         
42         Layer0X L0X = Layer0X.getInstance(graph);
43         DiagramResource DIA = DiagramResource.getInstance(graph);
44         G2DResource G2D = G2DResource.getInstance(graph);
45
46         // TODO consider making sure HasMonitorComponent is up-to-date also even though users should not be able to modify it
47
48         boolean changed = false;
49         boolean result = changed |= Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.HasMonitorSuffix);
50         if(result) info.messageLog.add("\t\t\tmonitor suffix => " + graph.getPossibleRelatedValue(instance, DIA.HasMonitorSuffix));
51         changed |= result;
52
53         result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, L0X.ObtainsProperty1);
54         if(result) info.messageLog.add("\t\t\tmonitor template => " + NameUtils.getSafeName(graph, graph.getPossibleObject(instance, L0X.ObtainsProperty1)));
55         changed |= result;
56
57         result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, G2D.HasBounds);
58         if(result) info.messageLog.add("\t\t\tmonitor bounds => " + graph.getPossibleRelatedValue(instance, G2D.HasBounds));
59         changed |= result;
60         
61         result = Properties.synchronizeDeepPropertyValue(graph, template, instance, DIA.HasColor);
62         if(result) info.messageLog.add("\t\t\tmonitor color");
63         changed |= result;
64         
65         result = Properties.synchronizeDeepPropertyValue(graph, template, instance, DIA.HasFont);
66         if(result) info.messageLog.add("\t\t\tmonitor font");
67         changed |= result;
68
69         result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, DIA.HasFormatter);
70         if(result) info.messageLog.add("\t\t\tmonitor formatter => " + NameUtils.getSafeName(graph, graph.getPossibleObject(instance, DIA.HasFormatter)));
71         changed |= result;
72
73         result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, G2D.HasHorizontalAlignment);
74         if(result) info.messageLog.add("\t\t\tmonitor horizontal alignment => " + NameUtils.getSafeName(graph, graph.getPossibleObject(instance, G2D.HasHorizontalAlignment)));
75         changed |= result;
76         
77         result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, G2D.HasVerticalAlignment);
78         if(result) info.messageLog.add("\t\t\tmonitor vertical alignment => " + NameUtils.getSafeName(graph, graph.getPossibleObject(instance, G2D.HasVerticalAlignment)));
79         changed |= result;
80
81         return changed;
82     }
83
84 }