-/*******************************************************************************\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.mapping;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.layer0.utils.triggers.IModification;\r
-import org.simantics.layer0.utils.triggers.Trigger;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.flags.LiftFlag;\r
-import org.simantics.modeling.flags.LiftFlag.LiftedConnectionPoint;\r
-import org.simantics.operation.Layer0X;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.utils.ObjectUtils;\r
-\r
-/**\r
- * This trigger is used for configuration diagrams of structural component types\r
- * to keep them in sync with the rest of the component type configuration,\r
- * external interface and symbol(s).\r
- * \r
- * <p>\r
- * This trigger is needed because generic modifications made to component type\r
- * configurations do not automatically reflect to the symbol and interface.\r
- * Putting this logic into a trigger keeps it nicely decoupled from the normal\r
- * diagram editing logic.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class ComponentTypeUpdater extends Trigger {\r
-\r
- private static final boolean DEBUG = false;\r
-\r
- protected Layer0 L0;\r
- protected Layer0X L0X;\r
- protected DiagramResource DIA;\r
- protected ModelingResources MOD;\r
- protected StructuralResource2 STR;\r
-\r
- protected Session session;\r
-\r
- private Resource configurationDiagram;\r
- private Resource configuration;\r
- private Resource componentType;\r
-\r
- public ComponentTypeUpdater(ReadGraph g, Resource mapping) throws DatabaseException {\r
- L0 = Layer0.getInstance(g);\r
- L0X = Layer0X.getInstance(g);\r
- DIA = DiagramResource.getInstance(g);\r
- MOD = ModelingResources.getInstance(g);\r
- STR = StructuralResource2.getInstance(g);\r
-\r
- this.session = g.getSession();\r
-\r
- this.configurationDiagram = g.getPossibleObject(mapping, g.getInverse(L0X.HasTrigger));\r
- if (configurationDiagram != null) {\r
- this.configuration = g.getPossibleObject(configurationDiagram, MOD.DiagramToComposite);\r
- if (configuration != null) {\r
- this.componentType = g.getPossibleObject(configuration, STR.Defines);\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public boolean equals(Object other) {\r
- if (this == other)\r
- return true;\r
- if (!(other instanceof ComponentTypeUpdater))\r
- return false;\r
- ComponentTypeUpdater map = (ComponentTypeUpdater)other;\r
- return ObjectUtils.objectEquals(map.configurationDiagram, configurationDiagram)\r
- && ObjectUtils.objectEquals(map.configuration, configuration)\r
- && ObjectUtils.objectEquals(map.componentType, componentType);\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- return ObjectUtils.hashCode(configurationDiagram)\r
- + 31 * (ObjectUtils.hashCode(configuration)\r
- + 31 * ObjectUtils.hashCode(componentType));\r
- }\r
-\r
- @Override\r
- public IModification perform(ReadGraph graph) throws DatabaseException {\r
- if (DEBUG)\r
- System.out.println(this + ": Find modification (configuration diagram=" + configurationDiagram\r
- + ", configuration=" + configuration + ", componentType=" + componentType + ")");\r
-\r
- if (componentType== null || configuration == null || configurationDiagram == null)\r
- return null;\r
-\r
- // Disabled because we fixed modeling rules to prevent making different\r
- // types of (invalid) connections to the once-created interface terminal\r
- // flag.\r
-\r
-// for (Resource connectionPoint : graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf,\r
-// STR.ConnectionRelation))) {\r
-// for (Resource flag : graph.getObjects(connectionPoint, DIA.Lifts)) {\r
-// LiftedConnectionPoint lcp = LiftFlag.calculateLiftedConnectionPointForFlag(graph, flag);\r
-// if (DEBUG)\r
-// System.out.println("lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true) + "): " + lcp);\r
-// if (LiftFlag.isConnectionPointValid(graph, flag, connectionPoint, lcp) != null)\r
-// return new LiftedConnectionPointFixer(componentType);\r
-// }\r
-// }\r
-\r
- return null;\r
- }\r
-\r
- /**\r
- * A modification that tries to fix all the connection point definitions of\r
- * the specified component type to match against the current connectivity of\r
- * the flags lifted as these connection points.\r
- */\r
- public class LiftedConnectionPointFixer implements IModification {\r
-\r
- private Resource componentType;\r
-\r
- public LiftedConnectionPointFixer(Resource componentType) {\r
- this.componentType = componentType;\r
- }\r
-\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- for (Resource connectionPoint : graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf,\r
- STR.ConnectionRelation))) {\r
- for (Resource flag : graph.getObjects(connectionPoint, DIA.Lifts)) {\r
- LiftedConnectionPoint lcp = LiftFlag.calculateLiftedConnectionPointForFlag(graph, flag);\r
- if (DEBUG)\r
- System.out.println("test lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true)\r
- + "): " + lcp);\r
- String error = LiftFlag.isConnectionPointValid(graph, componentType, connectionPoint, lcp);\r
- if (error == null)\r
- continue;\r
-\r
- // Fix connection point and symbol terminal type\r
- if (DEBUG)\r
- System.out.println("modi lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true)\r
- + "): " + lcp + "\nerrors: " + error);\r
- error = LiftFlag.validateConnectionPoint(graph, componentType, connectionPoint, lcp);\r
- if (error != null) {\r
- System.out.println(getClass().getSimpleName() + " error: " + error);\r
- }\r
- }\r
- }\r
- }\r
-\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.mapping;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.layer0.utils.triggers.IModification;
+import org.simantics.layer0.utils.triggers.Trigger;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.flags.LiftFlag;
+import org.simantics.modeling.flags.LiftFlag.LiftedConnectionPoint;
+import org.simantics.operation.Layer0X;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.utils.ObjectUtils;
+
+/**
+ * This trigger is used for configuration diagrams of structural component types
+ * to keep them in sync with the rest of the component type configuration,
+ * external interface and symbol(s).
+ *
+ * <p>
+ * This trigger is needed because generic modifications made to component type
+ * configurations do not automatically reflect to the symbol and interface.
+ * Putting this logic into a trigger keeps it nicely decoupled from the normal
+ * diagram editing logic.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class ComponentTypeUpdater extends Trigger {
+
+ private static final boolean DEBUG = false;
+
+ protected Layer0 L0;
+ protected Layer0X L0X;
+ protected DiagramResource DIA;
+ protected ModelingResources MOD;
+ protected StructuralResource2 STR;
+
+ protected Session session;
+
+ private Resource configurationDiagram;
+ private Resource configuration;
+ private Resource componentType;
+
+ public ComponentTypeUpdater(ReadGraph g, Resource mapping) throws DatabaseException {
+ L0 = Layer0.getInstance(g);
+ L0X = Layer0X.getInstance(g);
+ DIA = DiagramResource.getInstance(g);
+ MOD = ModelingResources.getInstance(g);
+ STR = StructuralResource2.getInstance(g);
+
+ this.session = g.getSession();
+
+ this.configurationDiagram = g.getPossibleObject(mapping, g.getInverse(L0X.HasTrigger));
+ if (configurationDiagram != null) {
+ this.configuration = g.getPossibleObject(configurationDiagram, MOD.DiagramToComposite);
+ if (configuration != null) {
+ this.componentType = g.getPossibleObject(configuration, STR.Defines);
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other)
+ return true;
+ if (!(other instanceof ComponentTypeUpdater))
+ return false;
+ ComponentTypeUpdater map = (ComponentTypeUpdater)other;
+ return ObjectUtils.objectEquals(map.configurationDiagram, configurationDiagram)
+ && ObjectUtils.objectEquals(map.configuration, configuration)
+ && ObjectUtils.objectEquals(map.componentType, componentType);
+ }
+
+ @Override
+ public int hashCode() {
+ return ObjectUtils.hashCode(configurationDiagram)
+ + 31 * (ObjectUtils.hashCode(configuration)
+ + 31 * ObjectUtils.hashCode(componentType));
+ }
+
+ @Override
+ public IModification perform(ReadGraph graph) throws DatabaseException {
+ if (DEBUG)
+ System.out.println(this + ": Find modification (configuration diagram=" + configurationDiagram
+ + ", configuration=" + configuration + ", componentType=" + componentType + ")");
+
+ if (componentType== null || configuration == null || configurationDiagram == null)
+ return null;
+
+ // Disabled because we fixed modeling rules to prevent making different
+ // types of (invalid) connections to the once-created interface terminal
+ // flag.
+
+// for (Resource connectionPoint : graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf,
+// STR.ConnectionRelation))) {
+// for (Resource flag : graph.getObjects(connectionPoint, DIA.Lifts)) {
+// LiftedConnectionPoint lcp = LiftFlag.calculateLiftedConnectionPointForFlag(graph, flag);
+// if (DEBUG)
+// System.out.println("lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true) + "): " + lcp);
+// if (LiftFlag.isConnectionPointValid(graph, flag, connectionPoint, lcp) != null)
+// return new LiftedConnectionPointFixer(componentType);
+// }
+// }
+
+ return null;
+ }
+
+ /**
+ * A modification that tries to fix all the connection point definitions of
+ * the specified component type to match against the current connectivity of
+ * the flags lifted as these connection points.
+ */
+ public class LiftedConnectionPointFixer implements IModification {
+
+ private Resource componentType;
+
+ public LiftedConnectionPointFixer(Resource componentType) {
+ this.componentType = componentType;
+ }
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ for (Resource connectionPoint : graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf,
+ STR.ConnectionRelation))) {
+ for (Resource flag : graph.getObjects(connectionPoint, DIA.Lifts)) {
+ LiftedConnectionPoint lcp = LiftFlag.calculateLiftedConnectionPointForFlag(graph, flag);
+ if (DEBUG)
+ System.out.println("test lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true)
+ + "): " + lcp);
+ String error = LiftFlag.isConnectionPointValid(graph, componentType, connectionPoint, lcp);
+ if (error == null)
+ continue;
+
+ // Fix connection point and symbol terminal type
+ if (DEBUG)
+ System.out.println("modi lifted cp(" + NameUtils.getSafeName(graph, connectionPoint, true)
+ + "): " + lcp + "\nerrors: " + error);
+ error = LiftFlag.validateConnectionPoint(graph, componentType, connectionPoint, lcp);
+ if (error != null) {
+ System.out.println(getClass().getSimpleName() + " error: " + error);
+ }
+ }
+ }
+ }
+
+ }
+
+}