X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateList.java;fp=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FUpdateList.java;h=6f66ba399326f0eb4ffa480d3b9d3874c54841f4;hb=b0205b09bbd81755eb69452eae0142d5a93f95a4;hp=747cd78c7c2a5a4381677f288a4782cd789eac51;hpb=6fd88055dcf1a4982cc607222e77907a786173a8;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 747cd78..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 @@ -9,79 +9,86 @@ 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> selected; + private HashSet changes; public UpdateList() { changes = new HashSet<>(); - selected = new HashSet<>(); } - public UpdateList(Collection> changes) { + public UpdateList(Collection changes) { this.changes = new HashSet<>(changes); - this.selected = new HashSet<>(); } - public Collection> getChanges() { - return changes; + public UpdateList(GraphChanges graphChanges, Collection> coll) { + this.changes = new HashSet<>(); + for (Pair p : coll) { + changes.add(create(graphChanges, p)); + } } - public HashSet> getSelected() { - return selected; + 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); - selected.remove(change); - } - - public void addSelected(Pair change) { - selected.add(change); } - public void removeSelected(Pair change) { - selected.remove(change); - } - - public boolean isSelected(Pair change) { - return selected.contains(change); + public Collection getSelected() { + HashSet selected = new HashSet<>(); + for (PropertyChange c : selected) { + if (c.selected()) + selected.add(c); + } + return selected; } - public void clear() { - changes.clear(); - selected.clear(); + public void clearSelected() { + for (PropertyChange c : changes) + c.select(false); } - public void clearSelected() { - selected.clear(); + 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 (Pair pair : changes) { - if (pair.first != null) { - if (pair.first.getSubject().equals(r)) { + 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.first.getObject().equals(r)) { + if (pair.getFirst().getObject().equals(r)) { list.add(pair); continue; } } - if (pair.second != null) { - if (pair.second.getSubject().equals(r)) { + if (pair.getSecond() != null) { + if (pair.getSecond().getSubject().equals(r)) { list.add(pair); continue; } - if (pair.second.getObject().equals(r)) { + if (pair.getSecond().getObject().equals(r)) { list.add(pair); continue; }