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;
26 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
29 * @param resource old Resource if status is DELETED or EXISTS.
33 public UpdateNode(Status status, UpdateOp op) {
37 this.r = op.getResource();
40 public UpdateNode(Status status, Resource 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) {
72 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
76 public String getLabel(ReadGraph graph) throws DatabaseException {
77 return getLabel(graph,r);
80 protected String getLabel(ReadGraph graph, Resource r) throws ValidationException, ServiceException, NoSingleResultException {
81 String label = NameUtils.getSafeLabel(graph, r);
82 if (label.length() == 0)
83 label = NameUtils.getSafeName(graph, r);
89 public UpdateOp getOp() {