From ea8430990a15eb2820ed85d637cc7db8dd4fc7d4 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 30 Mar 2017 11:05:00 +0300 Subject: [PATCH] Create UpdateNode labels in the constructor. refs #7045 Change-Id: Ic173aeb933cff44d40f746af707804b91c57259b --- .../update/editor/ModelUpdateEditor.java | 11 +---------- .../interop/update/model/UpdateNode.java | 18 +++++++++++++----- .../interop/update/model/UpdateTree.java | 10 +++++----- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index 8e315d8..dbfb035 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -687,16 +687,7 @@ public abstract class ModelUpdateEditor extends Composite{ @Override public String getText(Object element) { final UpdateNode node = (UpdateNode)element; - try { - return getSession().syncRequest(new Read() { - @Override - public String perform(ReadGraph graph) throws DatabaseException { - return node.getLabel(graph); - } - }); - } catch (Exception e) { - return e.getMessage(); - } + return node.getLabel(); } @Override diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java index de9d685..fec8e09 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java @@ -21,6 +21,7 @@ public class UpdateNode { private Status status; private UpdateOp op; private Resource r; + private String label; private Collection children = new ArrayList(); @@ -30,18 +31,20 @@ public class UpdateNode { * @param status * @param changes */ - public UpdateNode(Status status, UpdateOp op) { + public UpdateNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{ this.status = status; this.op = op; this.r = op.getResource(); + this.label = getLabel(g, r); } - public UpdateNode(Status status, Resource r) { + public UpdateNode(ReadGraph g, Status status, Resource r) throws DatabaseException { this.status = status; this.op = null; this.r = r; + this.label = getLabel(g, r); } public Resource getResource() { @@ -79,11 +82,16 @@ public class UpdateNode { return null; } - public String getLabel(ReadGraph graph) throws DatabaseException { - return getLabel(graph,r); + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; } - protected String getLabel(ReadGraph graph, Resource r) throws ValidationException, ServiceException, NoSingleResultException { + protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException { String label = NameUtils.getSafeLabel(graph, r); if (label.length() == 0) label = NameUtils.getSafeName(graph, r); diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java index 107c2b8..7396672 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java @@ -42,11 +42,11 @@ public class UpdateTree { } protected UpdateNode createNode(ReadGraph g, Status status, Resource r) throws DatabaseException { - return new UpdateNode(status, r); + return new UpdateNode(g,status, r); } - protected UpdateNode createNode(Status status, UpdateOp op) { - return new UpdateNode(status, op); + protected UpdateNode createNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{ + return new UpdateNode(g,status, op); } private UpdateNode createNode(ReadGraph g, Resource r1, Resource r2) throws DatabaseException { @@ -56,10 +56,10 @@ public class UpdateTree { nodes.put(r1, node); nodes.put(r2, node); } else if (r1 != null) { - node = createNode(Status.DELETED ,updateOps.getUpdateOp(r1)); + node = createNode(g,Status.DELETED ,updateOps.getUpdateOp(r1)); nodes.put(r1, node); } else if (r2 != null) { - node = createNode(Status.NEW, updateOps.getUpdateOp(r2)); + node = createNode(g,Status.NEW, updateOps.getUpdateOp(r2)); nodes.put(r2, node); } return node; -- 2.43.2