From caef8a0d1a68053c61efa046c84f936177c4e580 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 3 Apr 2017 15:04:17 +0300 Subject: [PATCH] Store Property change selections to UpdateList refs #7045 Change-Id: If505e8452f4d424cadf281be5e5190b60db46d99 --- .../update/editor/ModelUpdateEditor.java | 43 ++++++++------- .../interop/update/model/UpdateList.java | 53 +++++++++++++++++++ 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index 18dad81..9ea83a4 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -93,8 +93,7 @@ public abstract class ModelUpdateEditor extends Composite{ private Color containsColor; private Color deletedColor; private Color addedColor; - - private HashSet> selected = new HashSet>(); + private HashSet selectedStructure = new HashSet(); @@ -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 nr : updateList.getChanges()) - selected.remove(nr); + updateList.removeSelected(nr); } else { for (Pair 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 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 mod : selected) { + for (Pair 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) element); else - selected.remove(element); + updateList.removeSelected((Pair) element); getViewer().refresh(element); } diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java index 255d9ea..447ddff 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateList.java @@ -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> changes; + private HashSet> selected; public UpdateList() { changes = new HashSet<>(); + selected = new HashSet<>(); } public UpdateList(Collection> changes) { this.changes = new HashSet<>(changes); + this.selected = new HashSet<>(); } public Collection> getChanges() { return changes; } + public HashSet> getSelected() { + return selected; + } + public void addChange(Pair change) { changes.add(change); } public void removeChange(Pair change) { changes.remove(change); + selected.remove(change); + } + + public void addSelected(Pair change) { + selected.add(change); + } + + public void removeSelected(Pair change) { + selected.remove(change); } public void clear() { changes.clear(); + selected.clear(); + } + + public void clearSelected() { + selected.clear(); + } + + public Collection> getChanges(ReadGraph g, Resource r) throws DatabaseException{ + List> list = new ArrayList<>(); + for (Pair 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; } } -- 2.45.2