]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/ProfileMonitorRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / rules / ProfileMonitorRule.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * 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.modeling.typicals.rules;\r
13 \r
14 import org.simantics.db.Resource;\r
15 import org.simantics.db.WriteGraph;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.diagram.stubs.DiagramResource;\r
18 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;\r
19 import org.simantics.modeling.typicals.TypicalInfo;\r
20 \r
21 /**\r
22  * Synchronizes:\r
23  * * Grow Profile Monitors Upward?\r
24  * * Hide Profile Monitors?\r
25  * * Profile Monitor Offset?\r
26  * * Profile Monitor Spacing?\r
27  * \r
28  * @author Antti Villberg\r
29  */\r
30 public enum ProfileMonitorRule implements ITypicalSynchronizationRule {\r
31 \r
32     INSTANCE;\r
33 \r
34     public static ProfileMonitorRule getInstance() {\r
35         return INSTANCE;\r
36     }\r
37 \r
38     @Override\r
39     public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {\r
40         \r
41         DiagramResource DIA = DiagramResource.getInstance(graph);\r
42 \r
43         // TODO consider making sure HasMonitorComponent is up-to-date also even though users should not be able to modify it\r
44 \r
45         boolean changed = false;\r
46         boolean result = changed |= Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Element_upProfileMonitors);\r
47         if(result) info.messageLog.add("\t\t\tgrow profile monitors upward => " + graph.getPossibleRelatedValue(instance, DIA.Element_upProfileMonitors));\r
48         changed |= result;\r
49         result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Element_hideProfileMonitors);\r
50         if(result) info.messageLog.add("\t\t\thide profile monitors => " +  graph.getPossibleRelatedValue(instance, DIA.Element_hideProfileMonitors));\r
51         changed |= result;\r
52         result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Element_profileMonitorOffset);\r
53         if(result) info.messageLog.add("\t\t\tprofile monitor offset => " + graph.getPossibleRelatedValue(instance, DIA.Element_profileMonitorOffset));\r
54         changed |= result;\r
55         result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, DIA.Element_profileMonitorSpacing);\r
56         if(result) info.messageLog.add("\t\t\tprofile monitor spacing => " + graph.getPossibleRelatedValue(instance, DIA.Element_profileMonitorSpacing));\r
57         changed |= result;\r
58 \r
59         // TODO: sync font\r
60         //changed |= Properties.synchronizeStructuredPropertyValue(graph, template, instance, G2D.HasFont);\r
61 \r
62         return changed;\r
63     }\r
64 \r
65 }\r