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;
19 private boolean visible = true;
22 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
25 * @param resource old Resource if status is DELETED or EXISTS.
29 public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{
33 this.r = op.getResource();
37 public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
45 protected void init(ReadGraph g) throws DatabaseException {
46 this.label = getLabel(g, r);
49 public Resource getResource() {
53 public Resource getParentResource(ReadGraph g) throws DatabaseException {
54 Layer0 l0 = Layer0.getInstance(g);
55 return g.getPossibleObject(r, l0.PartOf);
58 public void setStatus(UpdateStatus status) {
62 public UpdateStatus getStatus() {
66 public Collection<UpdateNode> getChildren() {
70 public void addChild(UpdateNode node) {
72 if (op != null && node.op != null) {
73 if (!op.getSubOps().contains(node.op)) {
75 node.op.addParentOp(op);
80 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
84 public String getLabel() {
89 public String toString() {
93 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
94 String label = NameUtils.getSafeLabel(graph, r);
95 if (label.length() == 0)
96 label = NameUtils.getSafeName(graph, r);
102 public UpdateOp getOp() {
106 public boolean isVisible() {
110 public void setVisible(boolean visible) {
111 this.visible = visible;
113 op.visible = visible;