private Color containsColor;
private Color deletedColor;
private Color addedColor;
-
- private HashSet<Pair<Statement, Statement>> selected = new HashSet<Pair<Statement,Statement>>();
+
private HashSet<UpdateNode> selectedStructure = new HashSet<UpdateNode>();
oldValue.setLabelProvider(getLabelProvider(4));
newValue.setLabelProvider(getLabelProvider(5));
- selection.setLabelProvider(new SelectionLabelProvider(selected));
+ selection.setLabelProvider(new SelectionLabelProvider());
selection.getColumn().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (updateList.getChanges().size() > 0) {
- if (selected.contains(updateList.getChanges().iterator().next())) {
+ if (updateList.getSelected().contains(updateList.getChanges().iterator().next())) {
for (Pair<Statement, Statement> nr : updateList.getChanges())
- selected.remove(nr);
+ updateList.removeSelected(nr);
} else {
for (Pair<Statement, Statement> nr : updateList.getChanges())
- selected.add(nr);
+ updateList.addSelected(nr);
}
changeViewer.refresh();
}
}
});
- selection.setEditingSupport(new SelectionEditingSupport(changeViewer, selected));
+ selection.setEditingSupport(new SelectionEditingSupport(changeViewer));
}
Composite buttonComposite = new Composite(this, SWT.NONE);
for (ICheckStateListener l : checkStateListeners) {
l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false));
}
+ changeViewer.refresh();
}
for (Pair<Statement, Statement> mod : updateList.getChanges()) {
applyLiteralChange(graph, mod);
}
- selected.clear();
updateList.clear();
updateTree.getUpdateOps().applyAll(graph);
public void perform(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
graph.markUndoPoint();
- for (Pair<Statement, Statement> mod : selected) {
+ for (Pair<Statement, Statement> mod : updateList.getSelected()) {
updateList.removeChange(mod);
applyLiteralChange(graph, mod);
}
- selected.clear();
updateTree.getUpdateOps().applySelected(graph);
private class SelectionLabelProvider extends ColumnLabelProvider {
- Collection<?> selected;
- public SelectionLabelProvider(Collection<?> selected) {
- this.selected = selected;
+ public SelectionLabelProvider() {
+
}
@Override
public String getText(Object element) {
@Override
public Image getImage(Object element) {
- if (selected.contains(element))
+ if (updateList == null)
+ return null;
+ if (updateList.getSelected().contains(element))
return checked;
else
return unchecked;
private class SelectionEditingSupport extends EditingSupport {
- @SuppressWarnings("rawtypes")
- Collection selected;
-
@SuppressWarnings("rawtypes")
- public SelectionEditingSupport(ColumnViewer viewer, Collection selected) {
+ public SelectionEditingSupport(ColumnViewer viewer) {
super(viewer);
- this.selected = selected;
}
@Override
protected Object getValue(Object element) {
- return selected.contains(element);
+ if (updateList == null)
+ return false;
+ return updateList.getSelected().contains(element);
}
@SuppressWarnings("unchecked")
@Override
protected void setValue(Object element, Object value) {
+ if (updateList == null)
+ return;
if (Boolean.TRUE.equals(value))
- selected.add(element);
+ updateList.addSelected((Pair<Statement, Statement>) element);
else
- selected.remove(element);
+ updateList.removeSelected((Pair<Statement, Statement>) element);
getViewer().refresh(element);
}
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.utils.datastructures.Pair;
public class UpdateList {
private HashSet<Pair<Statement, Statement>> changes;
+ private HashSet<Pair<Statement, Statement>> selected;
public UpdateList() {
changes = new HashSet<>();
+ selected = new HashSet<>();
}
public UpdateList(Collection<Pair<Statement, Statement>> changes) {
this.changes = new HashSet<>(changes);
+ this.selected = new HashSet<>();
}
public Collection<Pair<Statement, Statement>> getChanges() {
return changes;
}
+ public HashSet<Pair<Statement, Statement>> getSelected() {
+ return selected;
+ }
+
public void addChange(Pair<Statement, Statement> change) {
changes.add(change);
}
public void removeChange(Pair<Statement, Statement> 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 void clear() {
changes.clear();
+ selected.clear();
+ }
+
+ public void clearSelected() {
+ selected.clear();
+ }
+
+ 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)) {
+ list.add(pair);
+ continue;
+ }
+ if (pair.first.getObject().equals(r)) {
+ list.add(pair);
+ continue;
+ }
+ }
+ if (pair.second != null) {
+ if (pair.second.getSubject().equals(r)) {
+ list.add(pair);
+ continue;
+ }
+ if (pair.second.getObject().equals(r)) {
+ list.add(pair);
+ continue;
+ }
+ }
+ }
+ return list;
}
}