1 package org.simantics.interop.update.model;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.utils.NameUtils;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.exception.NoSingleResultException;
12 import org.simantics.db.exception.ServiceException;
13 import org.simantics.db.exception.ValidationException;
14 import org.simantics.layer0.Layer0;
16 public class UpdateNode {
18 public enum Status {EXIST,DELETED,NEW,CONTAINS};
21 private Status status;
27 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
30 * @param resource old Resource if status is DELETED or EXISTS.
34 public UpdateNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{
38 this.r = op.getResource();
39 this.label = getLabel(g, r);
42 public UpdateNode(ReadGraph g, Status status, Resource r) throws DatabaseException {
47 this.label = getLabel(g, r);
50 public Resource getResource() {
54 public Resource getParentResource(ReadGraph g) throws DatabaseException {
55 Layer0 l0 = Layer0.getInstance(g);
56 return g.getPossibleObject(r, l0.PartOf);
59 public void setStatus(Status status) {
63 public Status getStatus() {
67 public Collection<UpdateNode> getChildren() {
71 public void addChild(UpdateNode node) {
73 if (op != null && node.op != null) {
74 if (!op.getSubOps().contains(node.op)) {
76 node.op.addParentOp(op);
81 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
85 public String getLabel() {
90 public String toString() {
94 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
95 String label = NameUtils.getSafeLabel(graph, r);
96 if (label.length() == 0)
97 label = NameUtils.getSafeName(graph, r);
103 public UpdateOp getOp() {