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 UpdateNode parent;
16 private UpdateStatus status;
20 private boolean visible = true;
23 private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
26 * @param resource old Resource if status is DELETED or EXISTS.
30 public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{
34 this.r = op.getResource();
38 public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
46 protected void init(ReadGraph g) throws DatabaseException {
47 this.label = getLabel(g, r);
50 public Resource getResource() {
54 public Resource getParentResource(ReadGraph g) throws DatabaseException {
55 Layer0 l0 = Layer0.getInstance(g);
56 return g.getPossibleObject(r, l0.PartOf);
59 public void setStatus(UpdateStatus status) {
63 public UpdateStatus getStatus() {
67 public Collection<UpdateNode> getChildren() {
71 public void addChild(UpdateNode node) {
74 if (op != null && node.op != null) {
75 if (!op.getSubOps().contains(node.op)) {
77 node.op.addParentOp(op);
82 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
86 public String getLabel() {
91 public String toString() {
95 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
96 String label = NameUtils.getSafeLabel(graph, r);
97 if (label.length() == 0)
98 label = NameUtils.getSafeName(graph, r);
104 public UpdateOp getOp() {
108 public boolean isVisible() {
112 public void setVisible(boolean visible) {
113 this.visible = visible;
115 op.visible = visible;
117 if (parent != null && !parent.visible)
118 parent.setVisible(true);
120 for (UpdateNode n : children)
125 public void setAllVisible(boolean visible) {
126 this.visible = visible;
128 op.visible = visible;
129 for (UpdateNode n : children)
130 n.setAllVisible(visible);