import java.util.HashSet;
import java.util.List;
import java.util.Stack;
+import java.util.Map.Entry;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.DoesNotContainValueException;
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
-import org.simantics.db.exception.ServiceException;
import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.db.request.Read;
import org.simantics.interop.test.GraphChanges;
import org.simantics.interop.test.GraphComparator;
import org.simantics.interop.update.Activator;
+import org.simantics.interop.update.model.UpdateList;
import org.simantics.interop.update.model.UpdateNode;
import org.simantics.interop.update.model.UpdateNode.Status;
import org.simantics.interop.update.model.UpdateOp;
private GraphChanges changes;
private UpdateTree updateTree;
+ private UpdateList updateList;
+
+ private GraphChanges changes2;
+ private UpdateTree updateTree2;
+ private UpdateList updateList2;
private Button updateAllButton;
private Button updateSelectedButton;
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 (changes.getModifications().size() > 0) {
- if (selected.contains(changes.getModifications().get(0))) {
- for (Pair<Statement, Statement> nr : changes.getModifications())
- selected.remove(nr);
+ if (updateList.getChanges().size() > 0) {
+ if (updateList.getSelected().size() > 0) {
+ updateList.clearSelected();
} else {
- for (Pair<Statement, Statement> nr : changes.getModifications())
- selected.add(nr);
+ for (Pair<Statement, Statement> nr : updateList.getChanges())
+ updateList.addSelected(nr);
}
changeViewer.refresh();
}
}
});
- selection.setEditingSupport(new SelectionEditingSupport(changeViewer, selected));
+ selection.setEditingSupport(new SelectionEditingSupport(changeViewer));
}
Composite buttonComposite = new Composite(this, SWT.NONE);
}
protected abstract ColumnLabelProvider getLabelProvider(int i);
- protected abstract Pair<GraphComparator,Boolean> getChanges(Resource r1, Resource r2) throws DatabaseException;
+ 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());
+ }
protected void addFilters(List<ChangeFilter> filters) {
return updateTree;
}
+ public UpdateList getUpdateList() {
+ return updateList;
+ }
+
public CheckboxTreeViewer getChangeBrowser() {
return changeBrowser;
}
for (ICheckStateListener l : checkStateListeners) {
l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false));
}
+ changeViewer.refresh();
}
Resource r1 = uei.getR1();
Resource r2 = uei.getR2();
-
+ Resource r3 = uei.getR3();
try {
- Pair<GraphComparator,Boolean> result = getChanges(r1,r2);
+ Pair<GraphComparator,String> result = getChanges(r1,r2);
GraphComparator comparator = result.first;
- if (result.second)
- showWarning("Structural symbols have been changed. Model update is not able to update these, please create a new model.");
+ if (result.second != null)
+ showWarning(result.second);
comparator.test(getSession());
changes = comparator.getChanges();
changes = getSession().syncRequest(new FilterChangesRead(changes));
updateTree = getUpdateTree(changes);
+ updateList = getUpdateList(changes);
+ if (r3 != null) {
+ Pair<GraphComparator,String> result2 = getChanges(r1,r3);
+ GraphComparator comparator2 = result2.first;
+ if (result2.second != null)
+ showWarning(result2.second);
+ comparator2.test(getSession());
+ changes2 = comparator2.getChanges();
+ changes2 = getSession().syncRequest(new FilterChangesRead(changes2));
+ updateTree2 = getUpdateTree(changes2);
+ updateList2 = getUpdateList(changes2);
+
+ createDefaultSelections();
+ }
} catch (DatabaseException e) {
Text text = new Text(this, SWT.MULTI);
text.setText(e.getMessage());
return;
}
-
-
- changeViewer.setInput(changes.getModifications());
- changeBrowser.setInput(updateTree);
+ setInputs();
+
refreshChecked();
}
-
+ protected void setInputs() {
+ changeViewer.setInput(updateList.getChanges());
+ changeBrowser.setInput(updateTree);
+ }
private void applyAll() {
updateAllButton.setEnabled(false);
public void perform(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply all model updates");
graph.markUndoPoint();
- for (Pair<Statement, Statement> mod : changes.getModifications()) {
+ for (Pair<Statement, Statement> mod : updateList.getChanges()) {
applyLiteralChange(graph, mod);
}
- selected.clear();
- changes.getModifications().clear();
+ updateList.clear();
updateTree.getUpdateOps().applyAll(graph);
});
}
- private void applyLiteralChange(WriteGraph graph, Pair<Statement, Statement> mod) throws DoesNotContainValueException, ServiceException, ManyObjectsForFunctionalRelationException {
-
+ 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.first.getPredicate();
+ Resource pred = mod.second.getPredicate();
if (graph.hasValue(mod.second.getObject())) {
Object value = graph.getValue(mod.second.getObject());
graph.claimLiteral(s, pred, value);
public void perform(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
graph.markUndoPoint();
- for (Pair<Statement, Statement> mod : selected) {
- changes.getModifications().remove(mod);
+ for (Pair<Statement, Statement> mod : updateList.getSelected()) {
+ updateList.removeChange(mod);
applyLiteralChange(graph, mod);
}
- selected.clear();
updateTree.getUpdateOps().applySelected(graph);
}
+ protected void createDefaultSelections() {
+ for (Entry<Resource, UpdateOp> op : updateTree.getUpdateOps().getResourceMap().entrySet()) {
+ UpdateOp op2 = updateTree2.getUpdateOps().getUpdateOp(op.getKey());
+ if (op2 == null) {
+ op.getValue().select(true);
+ }
+ }
+
+ for (Entry<Statement, UpdateOp> op : updateTree.getUpdateOps().getStatementMap().entrySet()) {
+ UpdateOp op2 = updateTree2.getUpdateOps().getUpdateOp(op.getKey());
+ if (op2 == null) {
+ op.getValue().select(true);
+ }
+ }
+
+ for (Pair<Statement, Statement> pair : updateList.getChanges()) {
+ if (pair.first != null) {
+ boolean found = false;
+ for (Pair<Statement, Statement> pair2 : updateList2.getChanges()) {
+ if (pair.first.equals(pair2.first)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ updateList.addSelected(pair);
+ }
+ } else {
+ updateList.addSelected(pair);
+ }
+ }
+ }
+
/**
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.isSelected((Pair<Statement, Statement>) element))
return checked;
else
return unchecked;
@Override
public String getText(Object element) {
final UpdateNode node = (UpdateNode)element;
- try {
- return getSession().syncRequest(new Read<String>() {
- @Override
- public String perform(ReadGraph graph) throws DatabaseException {
- return node.getLabel(graph);
- }
- });
- } catch (Exception e) {
- return e.getMessage();
- }
+ return node.getLabel();
}
@Override
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.isSelected((Pair<Statement, Statement>) 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);
}