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();
33 this.label = getLabel(g, r);
36 public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
41 this.label = getLabel(g, r);
44 public Resource getResource() {
48 public Resource getParentResource(ReadGraph g) throws DatabaseException {
49 Layer0 l0 = Layer0.getInstance(g);
50 return g.getPossibleObject(r, l0.PartOf);
53 public void setStatus(UpdateStatus status) {
57 public UpdateStatus getStatus() {
61 public Collection<UpdateNode> getChildren() {
65 public void addChild(UpdateNode node) {
67 if (op != null && node.op != null) {
68 if (!op.getSubOps().contains(node.op)) {
70 node.op.addParentOp(op);
75 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
79 public String getLabel() {
84 public String toString() {
88 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
89 String label = NameUtils.getSafeLabel(graph, r);
90 if (label.length() == 0)
91 label = NameUtils.getSafeName(graph, r);
97 public UpdateOp getOp() {