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 {
56 Resource parent = op.getParentResource(g);
60 Layer0 l0 = Layer0.getInstance(g);
61 return g.getPossibleObject(r, l0.PartOf);
64 public void setStatus(UpdateStatus status) {
68 public UpdateStatus getStatus() {
72 public Collection<UpdateNode> getChildren() {
76 public void addChild(UpdateNode node) {
79 if (op != null && node.op != null) {
80 if (!op.getSubOps().contains(node.op)) {
82 node.op.addParentOp(op);
87 public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException {
91 public String getLabel() {
96 public String toString() {
100 protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
101 String label = NameUtils.getSafeLabel(graph, r);
102 if (label.length() == 0)
103 label = NameUtils.getSafeName(graph, r);
109 public UpdateOp getOp() {
113 public boolean isVisible() {
117 public void setVisible(boolean visible) {
118 this.visible = visible;
120 op.visible = visible;
122 if (parent != null && !parent.visible)
123 parent.setVisible(true);
125 for (UpdateNode n : children)
130 public void setAllVisible(boolean visible) {
131 this.visible = visible;
133 op.visible = visible;
134 for (UpdateNode n : children)
135 n.setAllVisible(visible);