]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Create UpdateNode labels in the constructor.
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 30 Mar 2017 08:05:00 +0000 (11:05 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 30 Mar 2017 08:05:00 +0000 (11:05 +0300)
refs #7045

Change-Id: Ic173aeb933cff44d40f746af707804b91c57259b

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateTree.java

index 8e315d8703b3311db00f4dd79513b3375be82295..dbfb0356251d33dea1c2a03f774ed2f52d81eb49 100644 (file)
@@ -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<String>() {
-                                       @Override
-                                       public String perform(ReadGraph graph) throws DatabaseException {
-                                               return node.getLabel(graph);
-                                       }
-                               });
-                       } catch (Exception e) {
-                               return e.getMessage();
-                       }
+                       return node.getLabel();
                }
                
                @Override
index de9d685abd84fafdeccf9ab69914555f23bc608d..fec8e09d6c1f032a4251a0d97ed3017749bd8cbb 100644 (file)
@@ -21,6 +21,7 @@ public class UpdateNode {
        private Status status;
        private UpdateOp op;
        private Resource r;
+       private String label;
        
        
        private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
@@ -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);
index 107c2b89a4b1e5ef1444659677e626b6cf3a371b..739667228a01291bea2cdf07789e719b72624672 100644 (file)
@@ -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;