From 19fa38f6cd07e0917e5f25e009a90617ce431488 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Sat, 7 Oct 2017 23:59:13 +0300 Subject: [PATCH] More robustness fixes for editing of texts inside SVG elements. refs #7458 Change-Id: I5cd30ed29229147b2dd1adf3862f1cd2cea99f60 --- .../src/org/simantics/diagram/elements/SVGNode.java | 2 +- .../src/org/simantics/scenegraph/utils/NodeUtil.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java index 4d6547919..0b1ee8b0d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/SVGNode.java @@ -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 diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/NodeUtil.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/NodeUtil.java index 615899a59..9439369a5 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/NodeUtil.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/NodeUtil.java @@ -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) { -- 2.47.1