]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/FlagRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / rules / FlagRule.java
index 3dad91010565b13d53244a8b21a04e640026dcda..318677d05d912a54c756b7a7821c49309b1d9153 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.typicals.rules;\r
-\r
-import java.util.Set;\r
-\r
-import gnu.trove.set.hash.THashSet;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.flag.FlagUtil;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.modeling.typicals.ITypicalSynchronizationRule;\r
-import org.simantics.modeling.typicals.TypicalInfo;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * Synchronizes:\r
- * * joins\r
- * * flag type\r
- * * external tag\r
- * * IO table binding\r
- * * IO table row index \r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public enum FlagRule implements ITypicalSynchronizationRule {\r
-\r
-    INSTANCE;\r
-\r
-    public static FlagRule getInstance() {\r
-        return INSTANCE;\r
-    }\r
-\r
-    @Override\r
-    public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
-\r
-        boolean changed = false;\r
-\r
-        boolean result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, DIA.HasFlagType);\r
-        if(result) info.messageLog.add("\t\t\tflag type");\r
-        changed |= result;\r
-        result = Properties.synchronizeTag(graph, template, instance, DIA.ExternalFlag);\r
-        if(result) info.messageLog.add("\t\t\texternal status");\r
-        changed |= result;\r
-        result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Flag_HasIOTableBinding);\r
-        if(result) info.messageLog.add("\t\t\tIO table binding");\r
-        changed |= result;\r
-        result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Flag_HasIOTableRowIndex);\r
-        if(result) info.messageLog.add("\t\t\tIO table row");\r
-        changed |= result;\r
-        changed |= synchronizeJoins(graph, template, instance, info);\r
-\r
-        return changed;\r
-    }\r
-\r
-    public boolean synchronizeJoins(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {\r
-        boolean changed = false;\r
-\r
-        Set<Resource> tCounterparts = FlagUtil.getCounterparts(graph, template, new THashSet<Resource>(2));\r
-        Set<Resource> iCounterparts = FlagUtil.getCounterparts(graph, instance, new THashSet<Resource>(2));\r
-        if (tCounterparts.isEmpty() && iCounterparts.isEmpty())\r
-            return false;\r
-\r
-        for (Resource tCounterpart : tCounterparts) {\r
-            if (!info.bean.templateElements.contains(tCounterpart)) {\r
-                // Ignore external flag reference in synchronization.\r
-                // The user should not be able to create these at all.\r
-                ErrorLogger.defaultLogWarning("Encountered flag " + NameUtils.getSafeName(graph, template, true)\r
-                        + " in a typical template diagram with an invalid flag reference to correspondence "\r
-                        + NameUtils.getSafeName(graph, tCounterpart, true), new Exception("trace"));\r
-                continue;\r
-            }\r
-            Resource i = info.bean.templateToInstance.get(tCounterpart);\r
-            if (i == null) {\r
-                ErrorLogger.defaultLogError(\r
-                        "Encountered flag " + NameUtils.getSafeName(graph, template, true)\r
-                                + " in a typical template diagram while the instance diagram flag "\r
-                                + NameUtils.getSafeName(graph, instance, true)\r
-                                + " does not contain an element mapped to template flag correspondence "\r
-                                + NameUtils.getSafeName(graph, tCounterpart, true), new Exception("trace"));\r
-                continue;\r
-            }\r
-            if (iCounterparts.remove(i))\r
-                // instance has the similar counterpart as the template\r
-                continue;\r
-\r
-            // Instance does not have the same counterpart as the template.\r
-            // Create a new join.\r
-            FlagUtil.join(graph, instance, i);\r
-                       info.messageLog.add("\t\t\tsynchronized join " + NameUtils.getSafeName(graph, i));\r
-            changed = true;\r
-        }\r
-\r
-        // iCounterparts contains the set of joins that should be severed for\r
-        // the instance flag.\r
-        for (Resource iCounterpart : iCounterparts) {\r
-            FlagUtil.disconnectFlag(graph, instance, iCounterpart);\r
-                       info.messageLog.add("\t\t\tdisconnected flag " + NameUtils.getSafeName(graph, iCounterpart));\r
-            changed = true;\r
-        }\r
-\r
-        return changed;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.typicals.rules;
+
+import java.util.Set;
+
+import gnu.trove.set.hash.THashSet;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.flag.FlagUtil;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
+import org.simantics.modeling.typicals.TypicalInfo;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * Synchronizes:
+ * * joins
+ * * flag type
+ * * external tag
+ * * IO table binding
+ * * IO table row index 
+ * 
+ * @author Tuukka Lehtonen
+ */
+public enum FlagRule implements ITypicalSynchronizationRule {
+
+    INSTANCE;
+
+    public static FlagRule getInstance() {
+        return INSTANCE;
+    }
+
+    @Override
+    public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+
+        boolean changed = false;
+
+        boolean result = Properties.synchronizeEnumerationPropertyValue(graph, template, instance, DIA.HasFlagType);
+        if(result) info.messageLog.add("\t\t\tflag type");
+        changed |= result;
+        result = Properties.synchronizeTag(graph, template, instance, DIA.ExternalFlag);
+        if(result) info.messageLog.add("\t\t\texternal status");
+        changed |= result;
+        result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Flag_HasIOTableBinding);
+        if(result) info.messageLog.add("\t\t\tIO table binding");
+        changed |= result;
+        result = Properties.synchronizePrimitivePropertyValue(graph, template, instance, DIA.Flag_HasIOTableRowIndex);
+        if(result) info.messageLog.add("\t\t\tIO table row");
+        changed |= result;
+        changed |= synchronizeJoins(graph, template, instance, info);
+
+        return changed;
+    }
+
+    public boolean synchronizeJoins(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
+        boolean changed = false;
+
+        Set<Resource> tCounterparts = FlagUtil.getCounterparts(graph, template, new THashSet<Resource>(2));
+        Set<Resource> iCounterparts = FlagUtil.getCounterparts(graph, instance, new THashSet<Resource>(2));
+        if (tCounterparts.isEmpty() && iCounterparts.isEmpty())
+            return false;
+
+        for (Resource tCounterpart : tCounterparts) {
+            if (!info.bean.templateElements.contains(tCounterpart)) {
+                // Ignore external flag reference in synchronization.
+                // The user should not be able to create these at all.
+                ErrorLogger.defaultLogWarning("Encountered flag " + NameUtils.getSafeName(graph, template, true)
+                        + " in a typical template diagram with an invalid flag reference to correspondence "
+                        + NameUtils.getSafeName(graph, tCounterpart, true), new Exception("trace"));
+                continue;
+            }
+            Resource i = info.bean.templateToInstance.get(tCounterpart);
+            if (i == null) {
+                ErrorLogger.defaultLogError(
+                        "Encountered flag " + NameUtils.getSafeName(graph, template, true)
+                                + " in a typical template diagram while the instance diagram flag "
+                                + NameUtils.getSafeName(graph, instance, true)
+                                + " does not contain an element mapped to template flag correspondence "
+                                + NameUtils.getSafeName(graph, tCounterpart, true), new Exception("trace"));
+                continue;
+            }
+            if (iCounterparts.remove(i))
+                // instance has the similar counterpart as the template
+                continue;
+
+            // Instance does not have the same counterpart as the template.
+            // Create a new join.
+            FlagUtil.join(graph, instance, i);
+                       info.messageLog.add("\t\t\tsynchronized join " + NameUtils.getSafeName(graph, i));
+            changed = true;
+        }
+
+        // iCounterparts contains the set of joins that should be severed for
+        // the instance flag.
+        for (Resource iCounterpart : iCounterparts) {
+            FlagUtil.disconnectFlag(graph, instance, iCounterpart);
+                       info.messageLog.add("\t\t\tdisconnected flag " + NameUtils.getSafeName(graph, iCounterpart));
+            changed = true;
+        }
+
+        return changed;
+    }
+
+}