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;h=21cde66e1c461e3b4ebb70444b3cccbf3fc282f2;hb=refs%2Fheads%2Frelease%2F1.39.0;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..21cde66 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,100 @@ 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.interop.test.GraphChanges.Modification; 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 (Modification p : coll) { + changes.add(create(graphChanges, p.getLeftSub(),p.getRightSub(),new Pair(p.getLeftStm(), p.getRightStm()))); + } + } + + protected PropertyChange create(GraphChanges changes, Resource left, Resource right, Pair change) { + return new PropertyChange(changes, left,right, 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; } }