]> gerrit.simantics Code Review - simantics/platform.git/blob
4ee96f75d8e062fad53dea40bc81e30c997e5b2a
[simantics/platform.git] /
1 package org.simantics.modeling.typicals.rules;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.diagram.query.DiagramRequests;
7 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
8 import org.simantics.g2d.page.DiagramDesc;
9 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
10 import org.simantics.modeling.typicals.TypicalInfo;
11
12 /**
13  * @author Tuukka Lehtonen
14  * @since 1.22.2, 1.25.0
15  */
16 public enum PageSettingsTypicalRule implements ITypicalSynchronizationRule {
17
18         INSTANCE;
19
20         public static PageSettingsTypicalRule get() {
21                 return INSTANCE;
22         }
23
24         @Override
25         public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
26                 DiagramDesc mdesc = graph.syncRequest(DiagramRequests.getDiagramDesc(template));
27                 DiagramDesc idesc = graph.syncRequest(DiagramRequests.getDiagramDesc(instance));
28                 if (mdesc.equals(idesc))
29                         return false;
30
31                 DiagramGraphUtil.setDiagramDesc(graph, instance, mdesc);
32                 info.messageLog.add("\t\tset diagram page settings:"
33                                 + "\n\t\t\tshow page borders: " + mdesc.isPageBordersVisible()
34                                 + "\n\t\t\tshow margins:      " + mdesc.isMarginsVisible()
35                                 + "\n\t\t\tgrid size:         " + mdesc.getGridSize()
36                                 + "\n\t\t\tpage settings:     " + mdesc.getPageDesc()
37                                 + "\n");
38                 return true;
39         }
40
41 }