]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Initial implementation of model updates with three-way comparison.
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Mon, 3 Apr 2017 15:40:02 +0000 (18:40 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Mon, 3 Apr 2017 15:40:02 +0000 (18:40 +0300)
refs #7045

Change-Id: Ie6365fd4c5a7f8e93f5cb96b3cadc5b986213c14

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop.update/src/org/simantics/interop/update/editor/UpdateEditorInput.java

index 9ea83a4c94577af32b8065087e26e4528fd0e4b3..860057d240f6d9763c6659f62fed9b9f876a05e8 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Collection;
 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;
@@ -81,6 +82,10 @@ public abstract class ModelUpdateEditor extends Composite{
        private UpdateTree updateTree;
        private UpdateList updateList;
        
+       private GraphChanges changes2;
+       private UpdateTree updateTree2;
+       private UpdateList updateList2;
+       
        private Button updateAllButton;
        private Button updateSelectedButton;
        
@@ -217,9 +222,8 @@ public abstract class ModelUpdateEditor extends Composite{
                                @Override
                                public void widgetSelected(SelectionEvent e) {
                                        if (updateList.getChanges().size() > 0) {
-                                               if (updateList.getSelected().contains(updateList.getChanges().iterator().next())) {
-                                                       for (Pair<Statement, Statement> nr : updateList.getChanges())
-                                                               updateList.removeSelected(nr);
+                                               if (updateList.getSelected().size() > 0) {
+                                                       updateList.clearSelected();
                                                } else {
                                                        for (Pair<Statement, Statement> nr : updateList.getChanges())
                                                                updateList.addSelected(nr);
@@ -294,7 +298,7 @@ public abstract class ModelUpdateEditor extends Composite{
        }
        
        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());
@@ -399,19 +403,32 @@ public abstract class ModelUpdateEditor extends Composite{
 
                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());
@@ -550,6 +567,39 @@ public abstract class ModelUpdateEditor extends Composite{
        }
        
        
+       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);
+                       }
+               }
+       }
+       
        
        
        /**
@@ -685,7 +735,7 @@ public abstract class ModelUpdateEditor extends Composite{
                public Image getImage(Object element) {
                        if (updateList == null)
                                return null;
-                       if (updateList.getSelected().contains(element))
+                       if (updateList.isSelected((Pair<Statement, Statement>) element))
                                return checked;
                        else
                                return unchecked;
@@ -773,7 +823,7 @@ public abstract class ModelUpdateEditor extends Composite{
                protected Object getValue(Object element) {
                        if (updateList == null)
                                return false;
-                       return updateList.getSelected().contains(element);
+                       return updateList.isSelected((Pair<Statement, Statement>) element);
                }
                
                @SuppressWarnings("unchecked")
index 83b381f765c29f20debce51e1e4fb5cc29cd4fc6..f54b1c935e9439e471ea175382b41486b62e558b 100644 (file)
@@ -27,6 +27,7 @@ public class UpdateEditorInput extends ResourceEditorInput2{
                super(editorID, r1, model, rvi);
                this.r1 = r1;
                this.r2 = r2;
+               this.r3 = r3;
                this.editorID = editorID;
        }