1 package org.simantics.interop.update.model;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.HashSet;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.interop.test.GraphChanges;
13 import org.simantics.interop.test.GraphChanges.Modification;
14 import org.simantics.utils.datastructures.Pair;
16 public class UpdateList {
17 private List<PropertyChange> changes;
20 changes = new ArrayList<>();
23 public UpdateList(Collection<PropertyChange> changes) {
24 this.changes = new ArrayList<>(changes);
27 public UpdateList(GraphChanges graphChanges, Collection<Modification> coll) {
28 this.changes = new ArrayList<>();
29 for (Modification p : coll) {
30 addChange(create(graphChanges, p.getLeftSub(),p.getRightSub(),new Pair<Statement, Statement>(p.getLeftStm(), p.getRightStm())));
34 protected PropertyChange create(GraphChanges changes, Resource left, Resource right, Pair<Statement, Statement> change) {
35 return new PropertyChange(changes, left,right, change);
38 public Collection<PropertyChange> getChanges() {
42 public void addChange(PropertyChange change) {
43 if (!changes.contains(change))
47 public void removeChange(PropertyChange change) {
48 changes.remove(change);
51 public Collection<PropertyChange> getSelected() {
52 HashSet<PropertyChange> selected = new HashSet<>();
53 for (PropertyChange c : selected) {
60 public void clearSelected() {
61 for (PropertyChange c : changes)
65 public PropertyChange getChange(ReadGraph g, Statement s) throws DatabaseException {
66 for (PropertyChange c : changes) {
67 if (s.equals(c.pair.first))
69 if (s.equals(c.pair.second))
75 public Collection<PropertyChange> getChanges(ReadGraph g, Resource r) throws DatabaseException{
76 List<PropertyChange> list = new ArrayList<>();
77 for (PropertyChange pair : changes) {
78 if (pair.getFirst() != null) {
79 if (pair.getFirst().getSubject().equals(r)) {
83 if (pair.getFirst().getObject().equals(r)) {
88 if (pair.getSecond() != null) {
89 if (pair.getSecond().getSubject().equals(r)) {
93 if (pair.getSecond().getObject().equals(r)) {