X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateList.java;h=6f66ba399326f0eb4ffa480d3b9d3874c54841f4;hb=b0205b09bbd81755eb69452eae0142d5a93f95a4;hp=255d9ea93491787a0be294e681476ed570eadac9;hpb=e2f57d7e61d6c52b6341f793f6988c123daa1647;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java index 255d9ea..6f66ba3 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java @@ -1,35 +1,99 @@ package org.simantics.interop.update.model; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; import org.simantics.db.Statement; +import org.simantics.db.exception.DatabaseException; +import org.simantics.interop.test.GraphChanges; import org.simantics.utils.datastructures.Pair; public class UpdateList { - private HashSet> changes; + private HashSet changes; public UpdateList() { changes = new HashSet<>(); } - public UpdateList(Collection> changes) { + public UpdateList(Collection changes) { this.changes = new HashSet<>(changes); } - public Collection> getChanges() { - return changes; + public UpdateList(GraphChanges graphChanges, Collection> coll) { + this.changes = new HashSet<>(); + for (Pair p : coll) { + changes.add(create(graphChanges, p)); + } + } + + protected PropertyChange create(GraphChanges changes, Pair change) { + return new PropertyChange(changes, change); } - public void addChange(Pair change) { + public Collection getChanges() { + return changes; + } + + public void addChange(PropertyChange change) { changes.add(change); } - public void removeChange(Pair change) { + public void removeChange(PropertyChange change) { changes.remove(change); } - public void clear() { - changes.clear(); + public Collection getSelected() { + HashSet selected = new HashSet<>(); + for (PropertyChange c : selected) { + if (c.selected()) + selected.add(c); + } + return selected; + } + + public void clearSelected() { + for (PropertyChange c : changes) + c.select(false); + } + + public PropertyChange getChange(ReadGraph g, Statement s) throws DatabaseException { + for (PropertyChange c : changes) { + if (s.equals(c.pair.first)) + return c; + if (s.equals(c.pair.second)) + return c; + } + return null; + } + + public Collection getChanges(ReadGraph g, Resource r) throws DatabaseException{ + List list = new ArrayList<>(); + for (PropertyChange pair : changes) { + if (pair.getFirst() != null) { + if (pair.getFirst().getSubject().equals(r)) { + list.add(pair); + continue; + } + if (pair.getFirst().getObject().equals(r)) { + list.add(pair); + continue; + } + } + if (pair.getSecond() != null) { + if (pair.getSecond().getSubject().equals(r)) { + list.add(pair); + continue; + } + if (pair.getSecond().getObject().equals(r)) { + list.add(pair); + continue; + } + } + } + return list; } }