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 UpdateNode parent;
+ private UpdateStatus status;
private UpdateOp op;
private Resource r;
+ private String label;
+ private boolean visible = true;
private Collection<UpdateNode> children = new ArrayList<UpdateNode>();
* @param status
* @param changes
*/
- public UpdateNode(Status status, UpdateOp op) {
+ public UpdateNode(ReadGraph g, UpdateStatus status, UpdateOp op) throws DatabaseException{
this.status = status;
this.op = op;
this.r = op.getResource();
+ init(g);
}
- public UpdateNode(Status status, Resource r) {
+ public UpdateNode(ReadGraph g, UpdateStatus status, Resource r) throws DatabaseException {
this.status = status;
this.op = null;
this.r = r;
+ init(g);
+ }
+
+ protected void init(ReadGraph g) throws DatabaseException {
+ this.label = getLabel(g, r);
}
public Resource getResource() {
return g.getPossibleObject(r, l0.PartOf);
}
- public void setStatus(Status status) {
+ public void setStatus(UpdateStatus status) {
this.status = status;
}
- public Status getStatus() {
+ public UpdateStatus getStatus() {
return status;
}
public void addChild(UpdateNode node) {
children.add(node);
+ node.parent = this;
if (op != null && node.op != null) {
if (!op.getSubOps().contains(node.op)) {
op.addSubOp(node.op);
return null;
}
- public String getLabel(ReadGraph graph) throws DatabaseException {
- return getLabel(graph,r);
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public String toString() {
+ return label;
}
- protected String getLabel(ReadGraph graph, Resource r) throws ValidationException, ServiceException, NoSingleResultException {
+ protected String getLabel(ReadGraph graph, Resource r) throws DatabaseException {
String label = NameUtils.getSafeLabel(graph, r);
if (label.length() == 0)
label = NameUtils.getSafeName(graph, r);
public UpdateOp getOp() {
return op;
}
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ if (op != null)
+ op.visible = visible;
+ if (visible) {
+ if (parent != null && !parent.visible)
+ parent.setVisible(true);
+ } else {
+ for (UpdateNode n : children)
+ n.setVisible(false);
+ }
+ }
+
+ public void setAllVisible(boolean visible) {
+ this.visible = visible;
+ if (op != null)
+ op.visible = visible;
+ for (UpdateNode n : children)
+ n.setAllVisible(visible);
+ }
}