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.layer0.Layer0;
13 public class UpdateNode {
15 public enum Status {EXIST,DELETED,NEW,CONTAINS};
18 private Status status;
24 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
27 * @param resource old Resource if status is DELETED or EXISTS.
31 public UpdateNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{
35 this.r = op.getResource();
36 this.label = getLabel(g, r);
39 public UpdateNode(ReadGraph g, Status status, Resource r) throws DatabaseException {
44 this.label = getLabel(g, r);
47 public Resource getResource() {
51 public Resource getParentResource(ReadGraph g) throws DatabaseException {
52 Layer0 l0 = Layer0.getInstance(g);
53 return g.getPossibleObject(r, l0.PartOf);
56 public void setStatus(Status status) {
60 public Status getStatus() {
64 public Collection<UpdateNode> getChildren() {
68 public void addChild(UpdateNode node) {
70 if (op != null && node.op != null) {
71 if (!op.getSubOps().contains(node.op)) {
73 node.op.addParentOp(op);
78 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
82 public String getLabel() {
87 public String toString() {
91 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
92 String label = NameUtils.getSafeLabel(graph, r);
93 if (label.length() == 0)
94 label = NameUtils.getSafeName(graph, r);
100 public UpdateOp getOp() {