]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Store Property change selections to UpdateList
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Mon, 3 Apr 2017 12:04:17 +0000 (15:04 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Mon, 3 Apr 2017 12:04:17 +0000 (15:04 +0300)
refs #7045

Change-Id: If505e8452f4d424cadf281be5e5190b60db46d99

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java

index 18dad814361946b46442952f8172a93e79d88152..9ea83a4c94577af32b8065087e26e4528fd0e4b3 100644 (file)
@@ -93,8 +93,7 @@ public abstract class ModelUpdateEditor extends Composite{
        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>();
        
@@ -213,23 +212,23 @@ public abstract class ModelUpdateEditor extends Composite{
                        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);
@@ -389,6 +388,7 @@ public abstract class ModelUpdateEditor extends Composite{
                for (ICheckStateListener l : checkStateListeners) {
                        l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false));
                }
+               changeViewer.refresh();
        }
        
        
@@ -440,7 +440,6 @@ public abstract class ModelUpdateEditor extends Composite{
                                for (Pair<Statement, Statement> mod : updateList.getChanges()) {
                                        applyLiteralChange(graph, mod);
                                }
-                               selected.clear();
                                updateList.clear();
                                
                                updateTree.getUpdateOps().applyAll(graph);
@@ -493,11 +492,10 @@ public abstract class ModelUpdateEditor extends Composite{
                        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);
                                
@@ -675,9 +673,8 @@ public abstract class ModelUpdateEditor extends Composite{
        
        private class SelectionLabelProvider extends ColumnLabelProvider {
                
-               Collection<?>  selected;
-               public SelectionLabelProvider(Collection<?>  selected) {
-                       this.selected = selected;
+               public SelectionLabelProvider() {
+                       
                }
                @Override
                public String getText(Object element) {
@@ -686,7 +683,9 @@ public abstract class ModelUpdateEditor extends Composite{
                
                @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;
@@ -753,14 +752,10 @@ public abstract class ModelUpdateEditor extends Composite{
        
        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;
                        
                }
 
@@ -776,16 +771,20 @@ public abstract class ModelUpdateEditor extends Composite{
                
                @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);
                }
index 255d9ea93491787a0be294e681476ed570eadac9..447ddff2579bf19421044cb82e0bb548c2bee842 100644 (file)
@@ -1,35 +1,88 @@
 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;
        }
 }