X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Feditor%2FModelUpdateEditor.java;h=9ea83a4c94577af32b8065087e26e4528fd0e4b3;hb=930c049303df44922114e177e174a3c94d423b7f;hp=8e315d8703b3311db00f4dd79513b3375be82295;hpb=253e225cc04fc4a11cf41ec77fc6d37018825969;p=simantics%2Finterop.git 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 8e315d8..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 @@ -47,14 +47,12 @@ import org.simantics.db.Statement; 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; @@ -81,6 +79,7 @@ public abstract class ModelUpdateEditor extends Composite{ private GraphChanges changes; private UpdateTree updateTree; + private UpdateList updateList; private Button updateAllButton; private Button updateSelectedButton; @@ -94,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(); @@ -214,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 (changes.getModifications().size() > 0) { - if (selected.contains(changes.getModifications().get(0))) { - for (Pair nr : changes.getModifications()) - selected.remove(nr); + if (updateList.getChanges().size() > 0) { + if (updateList.getSelected().contains(updateList.getChanges().iterator().next())) { + for (Pair nr : updateList.getChanges()) + updateList.removeSelected(nr); } else { - for (Pair nr : changes.getModifications()) - selected.add(nr); + for (Pair 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); @@ -298,6 +296,9 @@ public abstract class ModelUpdateEditor extends Composite{ protected abstract ColumnLabelProvider getLabelProvider(int i); protected abstract Pair 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 filters) { @@ -311,6 +312,10 @@ public abstract class ModelUpdateEditor extends Composite{ return updateTree; } + public UpdateList getUpdateList() { + return updateList; + } + public CheckboxTreeViewer getChangeBrowser() { return changeBrowser; } @@ -383,6 +388,7 @@ public abstract class ModelUpdateEditor extends Composite{ for (ICheckStateListener l : checkStateListeners) { l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false)); } + changeViewer.refresh(); } @@ -405,6 +411,7 @@ public abstract class ModelUpdateEditor extends Composite{ changes = comparator.getChanges(); changes = getSession().syncRequest(new FilterChangesRead(changes)); updateTree = getUpdateTree(changes); + updateList = getUpdateList(changes); } catch (DatabaseException e) { Text text = new Text(this, SWT.MULTI); text.setText(e.getMessage()); @@ -412,14 +419,15 @@ public abstract class ModelUpdateEditor extends Composite{ 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); @@ -429,11 +437,10 @@ public abstract class ModelUpdateEditor extends Composite{ public void perform(WriteGraph graph) throws DatabaseException { Layer0Utils.addCommentMetadata(graph, "Apply all model updates"); graph.markUndoPoint(); - for (Pair mod : changes.getModifications()) { + for (Pair mod : updateList.getChanges()) { applyLiteralChange(graph, mod); } - selected.clear(); - changes.getModifications().clear(); + updateList.clear(); updateTree.getUpdateOps().applyAll(graph); @@ -460,10 +467,13 @@ public abstract class ModelUpdateEditor extends Composite{ }); } - private void applyLiteralChange(WriteGraph graph, Pair mod) throws DoesNotContainValueException, ServiceException, ManyObjectsForFunctionalRelationException { - + protected void applyLiteralChange(WriteGraph graph, Pair 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); @@ -482,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) { - changes.getModifications().remove(mod); + for (Pair mod : updateList.getSelected()) { + updateList.removeChange(mod); applyLiteralChange(graph, mod); } - selected.clear(); updateTree.getUpdateOps().applySelected(graph); @@ -664,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) { @@ -675,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; @@ -687,16 +697,7 @@ public abstract class ModelUpdateEditor extends Composite{ @Override public String getText(Object element) { final UpdateNode node = (UpdateNode)element; - try { - return getSession().syncRequest(new Read() { - @Override - public String perform(ReadGraph graph) throws DatabaseException { - return node.getLabel(graph); - } - }); - } catch (Exception e) { - return e.getMessage(); - } + return node.getLabel(); } @Override @@ -751,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; } @@ -774,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); }