}
@Override
- public boolean requiresParentOps() {
- return add;
+ public boolean requiresOp(UpdateOp op) {
+ if (add) {
+ if (getParentOps().contains(op))
+ return true;
+ } else {
+ if (getSubOps().contains(op))
+ return true;
+ }
+ return false;
}
-
+
@Override
- public boolean requiresSubOps() {
- return !add;
+ public boolean selectOp(UpdateOp op, boolean select) {
+ if (select) {
+ return requiresOp(op);
+ } else {
+ return op.requiresOp(this);
+ }
}
protected static void copyProperties(WriteGraph g, Resource source, Resource destination) throws DatabaseException {
public boolean isChange() {
return isAdd() || isDelete();
}
-
- /**
- * Is parent operation applied before this.
- * @return
- */
- public abstract boolean requiresParentOps();
- /**
- * Is child operation applied before this.
- * @return
- */
- public abstract boolean requiresSubOps();
-
+
/**
- * Is parent operation selected when this is selected
+ * Should given operation to be applied before this operation.
+ * @param op
* @return
*/
- public boolean selectParentOps() {
- return requiresParentOps();
+ public boolean requiresOp(UpdateOp op) {
+ return false;
}
/**
- * Is child operation selected when this is selected
+ * Should selection state to be propagated to given op.
+ * @param op parent or sub op of this.
+ * @param select selection flag.
* @return
*/
- public boolean selectSubOps() {
- return requiresSubOps();
- }
+ public boolean selectOp(UpdateOp op, boolean select) {
+ return requiresOp(op);
+ }
public boolean select(boolean select) {
if (!enabled)
manualSelection = true;
return b;
}
-
+
private boolean _select(boolean select) {
if (select == selected)
return true;
if (applied)
return false;
- if (!isChange())
- return false;
if (select) {
- if (selectParentOps()) {
- for (UpdateOp op : parentOps)
- op._select(true);
- }
-
- selected = true;
- manualSelection = false;
- if (selectSubOps()) {
- for (UpdateOp op : subOps)
- op._select(true);
- }
-
+ selected = true;
+ manualSelection = false;
+ for (UpdateOp op : parentOps) {
+ if (selectOp(op,true))
+ op._select(true);
+ }
+ for (UpdateOp op : subOps) {
+ if (selectOp(op,true))
+ op._select(true);
+ }
+ return true;
} else {
selected = false;
manualSelection = false;
for (UpdateOp op : subOps) {
- if (op.selectParentOps())
- op._select(false);
- else if (!op.manualSelection)
- op._select(false);
- }
+ if (selectOp(op, false))
+ op._select(false);
+ else if (!op.manualSelection)
+ op._select(false);
+ }
for (UpdateOp op : parentOps)
- if (op.selectSubOps())
- op._select(false);
+ if (selectOp(op, false))
+ op._select(false);
return true;
}
- return false;
}
+
public boolean selected() {
+ if (!isChange())
+ // Non change operations are not really selected, but the selected flag may be used for selection propagation
+ return false;
return selected;
}
* @return
*/
public abstract Resource getCreatedResource();
+
+ @Override
+ public String toString() {
+ String s = this.getClass().getSimpleName();
+ if (selected)
+ s += " selected";
+ if (enabled)
+ s += " enabled";
+ if (visible)
+ s += " visible";
+ if (applied)
+ s += " applied";
+ return s;
+ }
}