]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
symbol renaming doesn't work when done in the options view 13/2913/3
authorJani Mäkinen <jani.makinen@semantum.fi>
Mon, 3 Jun 2019 09:39:15 +0000 (12:39 +0300)
committerJani Mäkinen <jani.makinen@semantum.fi>
Wed, 5 Jun 2019 11:13:03 +0000 (14:13 +0300)
includes edits recommended by Tuukka

gitlab #42

Change-Id: I07618031cbb3d5afff6e9f14042658b64c23e4a5

bundles/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynTextElementNoBounds.java

index b557586bd0ce27632644bbe7f5b3cd50129ec140..68a21267e565c6fb4a97e961b1666f31242cfa98 100644 (file)
@@ -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<String>() {
+
+                                       @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