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;
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
*/
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");
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