package org.simantics.interop.update.model; import java.util.ArrayList; import java.util.Collection; import org.eclipse.jface.resource.ImageDescriptor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.exception.ServiceException; import org.simantics.db.exception.ValidationException; import org.simantics.layer0.Layer0; public class UpdateNode { public enum Status {EXIST,DELETED,NEW,CONTAINS}; private Status status; private UpdateOp op; private Resource r; private String label; private Collection children = new ArrayList(); /** * * @param resource old Resource if status is DELETED or EXISTS. * @param status * @param changes */ public UpdateNode(ReadGraph g, Status status, UpdateOp op) throws DatabaseException{ this.status = status; this.op = op; this.r = op.getResource(); this.label = getLabel(g, r); } public UpdateNode(ReadGraph g, Status status, Resource r) throws DatabaseException { this.status = status; this.op = null; this.r = r; this.label = getLabel(g, r); } public Resource getResource() { return r; } public Resource getParentResource(ReadGraph g) throws DatabaseException { Layer0 l0 = Layer0.getInstance(g); return g.getPossibleObject(r, l0.PartOf); } public void setStatus(Status status) { this.status = status; } public Status getStatus() { return status; } public Collection getChildren() { return children; } public void addChild(UpdateNode node) { children.add(node); if (op != null && node.op != null) { if (!op.getSubOps().contains(node.op)) { op.addSubOp(node.op); node.op.addParentOp(op); } } } public ImageDescriptor getImage(ReadGraph graph) throws DatabaseException { return null; } public String getLabel() { return label; } @Override public String toString() { return label; } protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException { String label = NameUtils.getSafeLabel(graph, r); if (label.length() == 0) label = NameUtils.getSafeName(graph, r); return label; } public UpdateOp getOp() { return op; } }