More robustness fixes for editing of texts inside SVG elements. 83/1083/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 7 Oct 2017 20:59:13 +0000 (23:59 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 7 Oct 2017 20:59:13 +0000 (23:59 +0300)
refs #7458

Change-Id: I5cd30ed29229147b2dd1adf3862f1cd2cea99f60

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/NodeUtil.java

index 4d654791925080230f51a9b525cc777a1f7760d7..0b1ee8b0dd98964833473b3cd93936c8f0806bde 100644 (file)
@@ -129,7 +129,7 @@ public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode {
     }
 
     SingleElementNode getSingleElementNode() {
-        return (SingleElementNode)NodeUtil.getNearestParentOfType(this, SingleElementNode.class);
+        return (SingleElementNode)NodeUtil.getPossibleNearestParentOfType(this, SingleElementNode.class);
     }
 
     @Override
index 615899a59eef25676ff17b0cbdcb69ca0d62d1b8..9439369a5927a89b9cfb714f15a296ef1c0ed678 100644 (file)
@@ -97,6 +97,18 @@ public final class NodeUtil {
         }
     }
 
+    public static INode getPossibleNearestParentOfType(INode node, Class<?> clazz) {
+        ParentNode<?> parent = null;
+        while (true) {
+            parent = node.getParent();
+            if (parent == null)
+                return null;
+            node = parent;
+            if (clazz.isInstance(node))
+                return node;
+        }
+    }
+
     public static INode getRootNode(INode node) {
         ParentNode<?> parent = null;
         while (true) {