From: Jani Mäkinen Date: Mon, 3 Jun 2019 09:39:15 +0000 (+0300) Subject: symbol renaming doesn't work when done in the options view X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F2913%2F3;p=simantics%2Fsysdyn.git symbol renaming doesn't work when done in the options view includes edits recommended by Tuukka gitlab #42 Change-Id: I07618031cbb3d5afff6e9f14042658b64c23e4a5 --- diff --git a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java index b557586b..68a21267 100644 --- a/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java +++ b/bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java @@ -19,10 +19,12 @@ import java.util.function.Consumer; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPage; import org.simantics.Simantics; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.elements.DiagramNodeUtil; @@ -49,6 +51,8 @@ import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils; import org.simantics.sysdyn.ui.utils.VariableNameValidator; import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * TextElement for variables in Siamntics System Dynamics @@ -62,6 +66,8 @@ import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; */ public class SysdynTextElementNoBounds extends TextElementNoBounds { + final static Logger LOGGER = LoggerFactory.getLogger(SysdynTextElementNoBounds.class); + private static final long serialVersionUID = -148784588840819612L; public static final Key ELEMENT_INITIALIZED = new KeyOf(Boolean.class, "SYSDYN_TEXT_ELEMENT_INITIALIZED"); @@ -143,16 +149,39 @@ public class SysdynTextElementNoBounds extends TextElementNoBounds { TextNode node = (TextNode) e.getHint(SG_NODE); if (node == null) return; + String text = node.getText(); + + try { + + String currentName = Simantics.getSession().syncRequest(new UniqueRead() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + return graph.getRelatedValue(component, Layer0.getInstance(graph).HasName, Bindings.STRING); + } + }); + + + if(!currentName.equals(textBeforeEdit)) text = currentName; + + } catch (DatabaseException e1) { + + LOGGER.error("Error while validating current name: " , e1); + } + if(!new VariableNameValidator().isValid(component, text, false)) { - text = textBeforeEdit; - node.setEditMode(false); - node.setText(text); - if(new VariableNameValidator().isValid(component, text, false)) - node.setColor(ElementUtils.getTextColor(e, Color.BLACK)); + text = textBeforeEdit; + node.setEditMode(false); + node.setText(text); + if(new VariableNameValidator().isValid(component, text, false)) + node.setColor(ElementUtils.getTextColor(e, Color.BLACK)); + + } else { Object o = e.getHint(ElementHints.KEY_OBJECT); final String textAfterEdit = text; + node.setText(text); if(o != null && o instanceof Resource) { Simantics.getSession().asyncRequest(new WriteRequest() { @Override