import java.util.List;
import java.util.Map.Entry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
* @throws DatabaseException
*/
public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct) throws DatabaseException{
+ this.setInput(oldModel, newModel, originalModel, newDistinct, null);
+ }
+ public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct, IProgressMonitor monitor) throws DatabaseException{
+
this.oldModel = oldModel;
this.newModel = newModel;
this.originalModel = originalModel;
+
+ if (monitor == null)
+ monitor = new NullProgressMonitor();
// addFilters(filters);
if (originalModel != null) {
// tree way comparison
GraphComparator comparator2 = result2.first;
if (result2.second != null)
showWarning(result2.second);
- comparator2.test(getSession());
+ comparator2.test(getSession(), monitor);
changes2 = comparator2.getChanges();
+ if (monitor.isCanceled()) {
+ dispose();
+ return;
+ }
changes2 = getSession().syncRequest(createFilterRead(changes2, filters));
- updateTree2 = getUpdateTree(changes2);
- updateList2 = getUpdateList(changes2);
+ Pair<UpdateTree, UpdateList> chg2 = createChangeObjects(changes2, null);
+ updateTree2 = chg2.first;
+ updateList2 = chg2.second;
// compare the original and the new model
Pair<GraphComparator,String> result3 = getChanges(originalModel,newModel);
GraphComparator comparator3 = result3.first;
if (result3.second != null)
showWarning(result3.second);
- comparator3.test(getSession());
+ comparator3.test(getSession(), monitor);
changes3 = comparator3.getChanges();
changes3 = getSession().syncRequest(createFilterRead(changes3, filters));
}
+ if (monitor.isCanceled()) {
+ dispose();
+ return;
+ }
Pair<GraphComparator,String> result = getChanges(oldModel,newModel);
GraphComparator comparator = result.first;
}
}
}
- comparator.test(getSession());
+ if (monitor.isCanceled()) {
+ dispose();
+ return;
+ }
+ comparator.test(getSession(), monitor);
+ monitor.setTaskName("Processing changes...");
+ monitor.subTask("");
changes = comparator.getChanges();
changes = getSession().syncRequest(createFilterRead(changes, filters));
- updateTree = getUpdateTree(changes);
- updateList = getUpdateList(changes);
+ Pair<UpdateTree, UpdateList> chg = createChangeObjects(changes, monitor);
+ if (chg == null) {
+ dispose();
+ return;
+ }
+ updateTree = chg.first;
+ updateList = chg.second;
if (userFilters.size() != 0) {
refreshUserFilters();
}
if (originalModel != null) {
defaultSelections();
}
-
init = true;
}
}
protected abstract Pair<GraphComparator,String> getChanges(Resource r1, Resource r2) throws DatabaseException;
+
+ protected Pair<UpdateTree, UpdateList> createChangeObjects(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException{
+ if (monitor != null) {
+ if (monitor.isCanceled())
+ return null;
+ monitor.subTask("Processing structural changes");
+ }
+ UpdateTree updateTree = getUpdateTree(changes);
+ if (monitor != null) {
+ if (monitor.isCanceled())
+ return null;
+ monitor.subTask("Processing property changes");
+ }
+ UpdateList updateList = getUpdateList(changes);
+ if (monitor != null) {
+ if (monitor.isCanceled())
+ return null;
+ monitor.subTask("Postprocessing changes");
+ }
+ postProcess(updateTree, updateList);
+ return new Pair<UpdateTree, UpdateList>(updateTree, updateList);
+ }
+
protected abstract UpdateTree getUpdateTree(GraphChanges changes) throws DatabaseException;
protected UpdateList getUpdateList(GraphChanges changes) throws DatabaseException {
return new UpdateList(changes, changes.getModifications());
}
+
+ protected void postProcess(UpdateTree updateTree, UpdateList updateList) throws DatabaseException{
+
+ }
+
public Resource getOldModel() {
return oldModel;
}
}
public UpdateTree getUpdateTree3() throws DatabaseException{
- if (updateTree3 == null && changes3 != null)
- updateTree3 = getUpdateTree(changes3);
+ if (updateTree3 == null && changes3 != null) {
+ Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
+ updateTree3 = chg3.first;
+ updateList3 = chg3.second;
+ }
return updateTree3;
}
public UpdateList getUpdateList3() throws DatabaseException {
- if (updateList3 == null && changes3 != null)
- updateList3 = getUpdateList(changes3);
+ if (updateList3 == null && changes3 != null) {
+ Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
+ updateTree3 = chg3.first;
+ updateList3 = chg3.second;
+ }
return updateList3;
}
public void applySelected(WriteGraph graph) throws DatabaseException {
Layer0Utils.addCommentMetadata(graph, "Apply selected model updates");
graph.markUndoPoint();
+
+ updateTree.getUpdateOps().applySelected(graph);
+
for (PropertyChange mod : updateList.getChanges()) {
if (mod.selected())
mod.apply(graph);
}
-
- updateTree.getUpdateOps().applySelected(graph);
}
@Override
public boolean accept(ReadGraph g, Modification change) throws DatabaseException {
//filter floating point values that have less than 1% difference.
+ if (change.getLeftStm() == null || change.getRightStm() == null)
+ return true;
if (!g.hasValue(change.getLeftStm().getObject()) || !g.hasValue(change.getRightStm().getObject()))
return true;
Object v1 = g.getValue(change.getLeftStm().getObject());
public void removeListener(WarningListener listener) {
warningListeners.remove(listener);
}
+
+ public void dispose() {
+ changes = null;
+ changes2 = null;
+ changes3 = null;
+ filters = null;
+ userFilters = null;
+ updateList = null;
+ updateList2 = null;
+ updateList3 = null;
+ updateTree = null;
+ updateTree2 = null;
+ updateTree3 = null;
+ updateNode3 = null;
+ init = false;
+ }
}