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 private UpdateStatus status;
21 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
24 * @param resource old Resource if status is DELETED or EXISTS.
28 public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{
32 this.r = op.getResource();
36 public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
44 protected void init(ReadGraph g) throws DatabaseException {
45 this.label = getLabel(g, r);
48 public Resource getResource() {
52 public Resource getParentResource(ReadGraph g) throws DatabaseException {
53 Layer0 l0 = Layer0.getInstance(g);
54 return g.getPossibleObject(r, l0.PartOf);
57 public void setStatus(UpdateStatus status) {
61 public UpdateStatus getStatus() {
65 public Collection<UpdateNode> getChildren() {
69 public void addChild(UpdateNode node) {
71 if (op != null && node.op != null) {
72 if (!op.getSubOps().contains(node.op)) {
74 node.op.addParentOp(op);
79 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
83 public String getLabel() {
88 public String toString() {
92 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
93 String label = NameUtils.getSafeLabel(graph, r);
94 if (label.length() == 0)
95 label = NameUtils.getSafeName(graph, r);
101 public UpdateOp getOp() {