From: Tuukka Lehtonen Date: Fri, 22 Sep 2017 06:31:55 +0000 (+0300) Subject: Robustness fixes for inline SVG text editing on diagrams X-Git-Tag: v1.31.0~172 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ba07153e79390fea754342c51a1a669add711d95;p=simantics%2Fplatform.git Robustness fixes for inline SVG text editing on diagrams This fixes the code to not assume during scene graph rendering that the canvas context is hosted by an AWTChassis. refs #7458 Change-Id: Ibb9955424784a1d3c2069d6a668559d95d88b181 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java index 859154d0b..893573d0f 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java @@ -43,7 +43,7 @@ import org.simantics.simulation.ontology.SimulationResource; public class DiagramNodeUtil { public static ICanvasContext getCanvasContext(IG2DNode node) { - G2DSceneGraph sg = NodeUtil.getPossibleRootNode(node); + G2DSceneGraph sg = node.getRootNode2D(); if (sg == null) return null; Component rootPane = sg.getRootPane(); @@ -55,7 +55,7 @@ public class DiagramNodeUtil { } public static ICanvasContext getPossibleCanvasContext(IG2DNode node) { - G2DSceneGraph sg = NodeUtil.getPossibleRootNode(node); + G2DSceneGraph sg = node.getRootNode2D(); if (sg == null) return null; Component rootPane = sg.getRootPane(); @@ -236,7 +236,7 @@ public class DiagramNodeUtil { } public static final Set getTexts(Set nodes) { - Set result = new HashSet(); + Set result = new HashSet(nodes.size()); for(TextNode n : nodes) result.add(n.getText()); return result; } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java index 8ddb16ac7..5c59177cc 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/EditorStateManager.java @@ -67,6 +67,9 @@ class EditorStateManager { String currentText = span.getText(); SingleElementNode sne = node.getSingleElementNode(); + if (sne == null) + return; + Function1 fullTextFunction = sne.getParameter("textEditorFullText"); if(fullTextFunction != null) es.currentText = fullTextFunction.apply(es.base.textElementId); @@ -114,10 +117,12 @@ class EditorStateManager { void applyEdit() { SingleElementNode sne = node.getSingleElementNode(); - EditorState es = currentState(); - Function2 editor = sne.getParameter("textEditor"); - if(editor != null) { - editor.apply(es.base.textElementId, es.currentText); + if (sne != null) { + EditorState es = currentState(); + Function2 editor = sne.getParameter("textEditor"); + if(editor != null) { + editor.apply(es.base.textElementId, es.currentText); + } } } 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 8084c2a41..bccba4aa7 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 @@ -51,12 +51,14 @@ public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode { public void render(Graphics2D g2d) { if (!parametersProcessed) { SingleElementNode sne = getSingleElementNode(); - Boolean enableEditing = sne.getParameter("enableEditing"); - if (enableEditing != null && enableEditing) { - esm = new EditorStateManager(this); - addEventHandler(this); + if (sne != null) { + Boolean enableEditing = sne.getParameter("enableEditing"); + if (enableEditing != null && enableEditing) { + esm = new EditorStateManager(this); + addEventHandler(this); + } + parametersProcessed = true; } - parametersProcessed = true; } super.render(g2d); @@ -76,7 +78,9 @@ public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode { } private boolean isSelected(IG2DNode node) { - ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(this); + ICanvasContext ctx = DiagramNodeUtil.getPossibleCanvasContext(this); + if (ctx == null) + return false; IElement ie = DiagramNodeUtil.getElement(ctx, node); if (ie == null) return false; @@ -119,10 +123,6 @@ public class SVGNode extends org.simantics.scenegraph.g2d.nodes.SVGNode { } SingleElementNode getSingleElementNode() { - ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(this); - // FIXME: needed only because eventdelegator registrations are done before adding node to scene graph. - if (ctx == null) - return null; return (SingleElementNode)NodeUtil.getNearestParentOfType(this, SingleElementNode.class); }