]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/ElementUtils.java
Avoid unnecessary ElementClass validation work
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / ElementUtils.java
index 1a12210f0912c23ccc2fbd1ea01fcdcb246a4e4a..300e74d31e75e04ee7ecf750ab0b2e58ba513951 100644 (file)
@@ -49,6 +49,7 @@ import org.simantics.g2d.element.handler.Hover;
 import org.simantics.g2d.element.handler.InternalSize;
 import org.simantics.g2d.element.handler.Move;
 import org.simantics.g2d.element.handler.Outline;
+import org.simantics.g2d.element.handler.Parameters;
 import org.simantics.g2d.element.handler.Parent;
 import org.simantics.g2d.element.handler.Pick;
 import org.simantics.g2d.element.handler.Resize;
@@ -350,6 +351,18 @@ public class ElementUtils {
         e.getElementClass().getSingleItem(Transform.class).setTransform(e, at);
     }
 
+    public static void setParameters(IElement e, Map<String,Object> parameters)
+    {
+        Parameters ps = e.getElementClass().getSingleItem(Parameters.class);
+        if(ps != null) ps.setParameters(e, parameters);
+    }
+
+    public static Map<String,Object> getParameters(IElement e)
+    {
+        Parameters ps = e.getElementClass().getAtMostOneItemOfClass(Parameters.class);
+        return ps != null ? ps.getParameters(e) : null;
+    }
+
     public static AffineTransform getInvTransform(IElement e)
     {
         try {
@@ -1162,7 +1175,7 @@ public class ElementUtils {
             // If the previously available node is not a parent of the specified
             // node create a new node under the specified parent and set that
             // as the node of the specified element.
-            if (!node.getParent().equals(withParentNode)) {
+            if (!withParentNode.equals(node.getParent())) {
                 node = nodeId != null ? withParentNode.getOrCreateNode(nodeId, nodeClass) : withParentNode.addNode(nodeClass);
                 forElement.setHint(withNodeKey, node);
                 if (nodeCreationCallback != null)