data UpdateList
@JavaName getChanges
- getListChanges :: UpdateList -> <Proc> [Pair]
+ getListChanges :: UpdateList -> <Proc> [PropertyChange]
@JavaName getSelected
- getListSelected :: UpdateList -> <Proc> MSet.T Pair
+ getListSelected :: UpdateList -> <Proc> [PropertyChange]
- @JavaName addSelected
- addListSelected :: UpdateList -> Pair -> <Proc>()
+ @JavaName getChanges
+ getResChanges :: UpdateList -> Resource -> <ReadGraph> [PropertyChange]
+
+ @JavaName getChange
+ getStmChange :: UpdateList -> Statement -> <ReadGraph> Maybe PropertyChange
- @JavaName removeSelected
- removeListSelected :: UpdateList -> Pair -> <Proc>()
+ //@JavaName addSelected
+ //addListSelected :: UpdateList -> Pair -> <Proc>()
- @JavaName isSelected
- isListSelected :: UpdateList -> Pair -> <Proc> Boolean
+ //@JavaName removeSelected
+ //removeListSelected :: UpdateList -> Pair -> <Proc>()
+
+ //@JavaName isSelected
+ //isListSelected :: UpdateList -> Pair -> <Proc> Boolean
importJava "org.simantics.interop.test.GraphChanges" where
data GraphChanges
@JavaName getModifications
getModifications :: GraphChanges -> <Proc> [Pair]
+
+importJava "org.simantics.interop.update.model.PropertyChange" where
+ data PropertyChange
+
+ @JavaName "<init>"
+ createPropertyChange :: GraphChanges -> Maybe Statement -> Maybe Statement -> <Proc> PropertyChange
+
+ @JavaName applied
+ pcApplied :: PropertyChange -> <Proc> Boolean
+ @JavaName selected
+ pcSelected :: PropertyChange -> <Proc> Boolean
+
+ @JavaName "select"
+ pcSelect :: PropertyChange -> Boolean -> <Proc> Boolean
+
+ @JavaName getFirst
+ getFirst :: PropertyChange -> <Proc> Maybe Statement
+
+ @JavaName getSecond
+ getSecond :: PropertyChange -> <Proc> Maybe Statement
+
+
importJava "org.simantics.interop.update.model.UpdateNode" where
data UpdateNode
createPair :: Maybe a -> Maybe b -> <Proc> Pair
@JavaName first
- getFirst :: Pair -> <Proc> Maybe a
+ getPairFirst :: Pair -> <Proc> Maybe a
@JavaName second
- getSecond :: Pair -> <Proc> Maybe b
+ getPairSecond :: Pair -> <Proc> Maybe b
importJava "org.simantics.utils.datastructures.BijectionMap" where
data BijectionMap
import org.simantics.interop.test.GraphChanges;
import org.simantics.interop.update.Activator;
import org.simantics.interop.update.model.ModelUpdate;
+import org.simantics.interop.update.model.PropertyChange;
import org.simantics.interop.update.model.ModelUpdate.WarningListener;
import org.simantics.interop.update.model.UpdateList;
import org.simantics.interop.update.model.UpdateNode;
if (update.getUpdateList().getSelected().size() > 0) {
update.getUpdateList().clearSelected();
} else {
- for (Pair<Statement, Statement> nr : update.getUpdateList().getChanges())
- update.getUpdateList().addSelected(nr);
+ for (PropertyChange nr : update.getUpdateList().getChanges())
+ nr.select(true);
}
changeViewer.refresh();
}
public Image getImage(Object element) {
if (update == null || !update.isInit())
return null;
-// if (update.getUpdateList() == null)
-// return null;
- if (update.getUpdateList().isSelected((Pair<Statement, Statement>) element))
+ PropertyChange pc = (PropertyChange)element;
+ if (pc.selected())
return checked;
else
return unchecked;
protected Object getValue(Object element) {
if (update == null || !update.isInit())
return false;
- return update.getUpdateList().isSelected((Pair<Statement, Statement>) element);
+ PropertyChange pc = (PropertyChange)element;
+ return pc.selected();
}
@SuppressWarnings("unchecked")
protected void setValue(Object element, Object value) {
if (update == null || !update.isInit())
return;
+ PropertyChange pc = (PropertyChange)element;
if (Boolean.TRUE.equals(value))
- update.getUpdateList().addSelected((Pair<Statement, Statement>) element);
+ pc.select(true);
else
- update.getUpdateList().removeSelected((Pair<Statement, Statement>) element);
+ pc.select(false);
getViewer().refresh(element);
}
package org.simantics.interop.update.model;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
protected abstract Pair<GraphComparator,String> getChanges(Resource r1, Resource r2) throws DatabaseException;
protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException;
protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException {
- return new UpdateList(changes.getModifications());
+ return new UpdateList(changes, changes.getModifications());
}
protected void addFilters(List<ChangeFilter> filters) {
public void applyAll(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply all model updates");
graph.markUndoPoint();
- for (Pair<Statement, Statement> mod : updateList.getChanges()) {
- applyLiteralChange(graph, mod);
+ for (PropertyChange mod : updateList.getChanges()) {
+ mod.apply(graph);
}
- updateList.clear();
updateTree.getUpdateOps().applyAll(graph);
}
public void applySelected(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
graph.markUndoPoint();
- HashSet<Pair<Statement, Statement>> changes = new HashSet<>(updateList.getSelected());
- for (Pair<Statement, Statement> mod : changes) {
- updateList.removeChange(mod);
- applyLiteralChange(graph, mod);
+ for (PropertyChange mod : updateList.getChanges()) {
+ if (mod.selected())
+ mod.apply(graph);
}
updateTree.getUpdateOps().applySelected(graph);
}
- protected void applyLiteralChange(WriteGraph graph, Pair<Statement, Statement> mod) throws DatabaseException {
- if (mod.second == null) {
- graph.deny(mod.first);
- return;
- }
- Resource s = changes.getComparable().getLeft(mod.second.getSubject());
- Resource pred = mod.second.getPredicate();
- if (graph.hasValue(mod.second.getObject())) {
- Object value = graph.getValue(mod.second.getObject());
- graph.claimLiteral(s, pred, value);
- } else {
- graph.deny(s,pred);
- }
- }
+
protected Session getSession() {
}
- for (Pair<Statement, Statement> pair : updateList.getChanges()) {
- updateList.addSelected(pair);
+ for (PropertyChange pair : updateList.getChanges()) {
+ pair.select(true);
}
// preserve user-made changes (by removing selections)
}
}
- for (Pair<Statement, Statement> pair : updateList.getChanges()) {
- if (pair.first != null) {
+ for (PropertyChange pair : updateList.getChanges()) {
+ if (pair.getFirst() != null) {
boolean found = false;
- for (Pair<Statement, Statement> pair2 : updateList2.getChanges()) {
- if (pair.first.equals(pair2.second)) {
+ for (PropertyChange pair2 : updateList2.getChanges()) {
+ if (pair.getFirst().equals(pair2.getSecond())) {
found = true;
break;
}
}
if (found) {
- updateList.removeSelected(pair);
+ pair.select(false);
}
}
}
--- /dev/null
+package org.simantics.interop.update.model;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.interop.test.GraphChanges;
+import org.simantics.utils.datastructures.Pair;
+
+public class PropertyChange {
+ protected GraphChanges changes;
+ protected Pair<Statement, Statement> pair;
+ protected boolean applied = false;
+ protected boolean selected = false;
+
+
+ public PropertyChange(GraphChanges changes, Statement first, Statement second) {
+ this.pair = new Pair<Statement, Statement>(first, second);
+ this.changes = changes;
+ }
+
+ public PropertyChange(GraphChanges changes, Pair<Statement, Statement> change) {
+ this.pair = change;
+ this.changes = changes;
+ }
+
+ public Statement getFirst() {
+ return pair.first;
+ }
+
+ public Statement getSecond() {
+ return pair.second;
+ }
+
+ public GraphChanges getChanges() {
+ return changes;
+ }
+
+ @Override
+ public int hashCode() {
+ return pair.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (obj.getClass() != this.getClass())
+ return false;
+ PropertyChange c = (PropertyChange)obj;
+ return pair.equals(c.pair);
+ }
+
+ public void apply(WriteGraph graph) throws DatabaseException {
+ if (applied)
+ return;
+ if (pair.second == null) {
+ graph.deny(pair.first);
+ return;
+ }
+ Resource s = changes.getComparable().getLeft(pair.second.getSubject());
+ //Resource s = pair.first.getSubject();
+ Resource pred = pair.second.getPredicate();
+ if (graph.hasValue(pair.second.getObject())) {
+ Object value = graph.getValue(pair.second.getObject());
+ graph.claimLiteral(s, pred, value);
+ } else {
+ graph.deny(s,pred);
+ }
+ applied = true;
+
+ }
+
+ public boolean select(boolean select) {
+ if (applied)
+ return false;
+ this.selected = select;
+ return true;
+ }
+
+
+ public boolean selected() {
+ return selected;
+ }
+
+ public boolean applied() {
+ return applied;
+ }
+
+
+}
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<Pair<Statement, Statement>> changes;
- private HashSet<Pair<Statement, Statement>> selected;
+ private HashSet<PropertyChange> changes;
public UpdateList() {
changes = new HashSet<>();
- selected = new HashSet<>();
}
- public UpdateList(Collection<Pair<Statement, Statement>> changes) {
+ public UpdateList(Collection<PropertyChange> changes) {
this.changes = new HashSet<>(changes);
- this.selected = new HashSet<>();
}
- public Collection<Pair<Statement, Statement>> getChanges() {
- return changes;
+ public UpdateList(GraphChanges graphChanges, Collection<Pair<Statement, Statement>> coll) {
+ this.changes = new HashSet<>();
+ for (Pair<Statement, Statement> p : coll) {
+ changes.add(create(graphChanges, p));
+ }
}
- public HashSet<Pair<Statement, Statement>> getSelected() {
- return selected;
+ protected PropertyChange create(GraphChanges changes, Pair<Statement, Statement> change) {
+ return new PropertyChange(changes, change);
}
- public void addChange(Pair<Statement, Statement> change) {
+ public Collection<PropertyChange> getChanges() {
+ return changes;
+ }
+
+ public void addChange(PropertyChange change) {
changes.add(change);
}
- public void removeChange(Pair<Statement, Statement> change) {
+ public void removeChange(PropertyChange change) {
changes.remove(change);
- selected.remove(change);
- }
-
- public void addSelected(Pair<Statement, Statement> change) {
- selected.add(change);
}
- public void removeSelected(Pair<Statement, Statement> change) {
- selected.remove(change);
- }
-
- public boolean isSelected(Pair<Statement, Statement> change) {
- return selected.contains(change);
+ public Collection<PropertyChange> getSelected() {
+ HashSet<PropertyChange> 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<Pair<Statement, Statement>> getChanges(ReadGraph g, Resource r) throws DatabaseException{
- List<Pair<Statement, Statement>> list = new ArrayList<>();
- for (Pair<Statement, Statement> pair : changes) {
- if (pair.first != null) {
- if (pair.first.getSubject().equals(r)) {
+ public Collection<PropertyChange> getChanges(ReadGraph g, Resource r) throws DatabaseException{
+ List<PropertyChange> 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;
}
private boolean _select(boolean select) {
if (select == selected)
return true;
+ if (applied)
+ return false;
if (select) {
if (selectParentOps()) {
for (UpdateOp op : parentOps)