import org.simantics.objmap.graph.impl.Link;
-public class RangeUpdateRequest<Domain,Range> implements Read<Boolean>, SyncListener<Boolean> {
+public class RangeUpdateRequest<Domain,Range> implements Read<Integer>, SyncListener<Integer> {
Link<Domain,Range> link;
/*
*/
IForwardMapping<Domain, Range> map; // map==null is used to flag that request is performed once
Mapping<Domain, Range> mapping; // mapping==null is used as a flag the request disposed
+ int counter;
public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {
this.link = link;
this.map = map;
this.mapping = mapping;
+ this.counter = 0;
}
@Override
- public Boolean perform(ReadGraph g) throws DatabaseException {
- if(map != null) {
- link.type.updateRange(g, map, link.domainElement, link.rangeElement);
- map = null;
- return Boolean.TRUE;
- }
- else if(mapping != null) {
- mapping.domainModified(link);
- mapping = null;
- return Boolean.FALSE;
- }
- else
- return null;
+ public Integer perform(ReadGraph g) throws DatabaseException {
+ boolean changed = false;
+ if (map != null)
+ changed = link.type.checkChanges(g, map, link.domainElement, link.rangeElement);
+ else if (mapping != null)
+ changed = link.type.checkChanges(g, mapping, link.domainElement, link.rangeElement);
+
+ return changed ? counter + 1 : counter;
}
@Override
}
@Override
- public void execute(ReadGraph graph, Boolean result)
- throws DatabaseException {
+ public void execute(ReadGraph graph, Integer result)
+ throws DatabaseException {
+ boolean changed = result != counter;
+ counter = result;
+
+ if (map != null) {
+ if (changed)
+ link.type.updateRange(graph, map, link.domainElement, link.rangeElement);
+ map = null;
+ }
+ else if (mapping != null && changed) {
+ mapping.domainModified(link);
+ mapping = null;
+ }
}
@Override
public boolean isDisposed() {
return mapping == null || link.removed || mapping.isDisposed();
}
-
-
-
}