From 253e225cc04fc4a11cf41ec77fc6d37018825969 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 28 Mar 2017 11:22:21 +0300 Subject: [PATCH] Separate ModelUpdateEditor's ViewPart and the implementation refs #7045 Change-Id: I1efe963f88a10ffe4e5f4b60da09126ff6f9f30e --- .../update/editor/ModelUpdateEditor.java | 105 ++++++++++-------- .../update/editor/ModelUpdateEditorPart.java | 25 +++++ .../update/model/UpdateOperations.java | 8 ++ 3 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditorPart.java 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 94b2461..8e315d8 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 @@ -40,9 +40,9 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorInput; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Session; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; @@ -60,7 +60,7 @@ import org.simantics.interop.update.model.UpdateNode.Status; import org.simantics.interop.update.model.UpdateOp; import org.simantics.interop.update.model.UpdateTree; import org.simantics.interop.utils.TableUtils; -import org.simantics.ui.workbench.ResourceEditorPart2; +import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.ui.ExceptionUtils; @@ -72,10 +72,8 @@ import org.simantics.utils.ui.ExceptionUtils; * @author Marko Luukkainen * */ -public abstract class ModelUpdateEditor extends ResourceEditorPart2 { +public abstract class ModelUpdateEditor extends Composite{ - - private Composite composite; private Composite errorComposite; private CheckboxTreeViewer changeBrowser; @@ -103,23 +101,20 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { private List filters = new ArrayList(); - public ModelUpdateEditor() { + public ModelUpdateEditor(Composite parent) { + super(parent,SWT.NONE); checked = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/tick.png")); unchecked = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/cross.png")); warning = manager.createImage(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/error.png")); - } - - @Override - public void createPartControl(Composite parent) { + containsColor = new Color(parent.getDisplay(), new RGB(255,255,220)); deletedColor = new Color(parent.getDisplay(), new RGB(255,220,220)); addedColor = new Color(parent.getDisplay(), new RGB(220,255,220)); - composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout(1,false)); + this.setLayout(new GridLayout(1,false)); - errorComposite = new Composite(composite, SWT.BORDER); + errorComposite = new Composite(this, SWT.BORDER); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.grabExcessVerticalSpace = false; @@ -130,14 +125,14 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { errorComposite.setVisible(false); - IEditorInput input = getEditorInput(); - if (!(input instanceof UpdateEditorInput)) { - Label label = new Label(composite, SWT.NONE); - label.setText("Unknown input."); - return; - } - - Composite fillComposite = new Composite(composite, SWT.NONE); +// IEditorInput input = getEditorInput(); +// if (!(input instanceof UpdateEditorInput)) { +// Label label = new Label(composite, SWT.NONE); +// label.setText("Unknown input."); +// return; +// } + + Composite fillComposite = new Composite(this, SWT.NONE); data = new GridData(); data.grabExcessHorizontalSpace = true; data.grabExcessVerticalSpace = true; @@ -169,7 +164,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { node.getOp().select(Boolean.TRUE.equals(event.getChecked())); } - updateSelection(); + refreshChecked(); } }); @@ -181,7 +176,8 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { @Override public void run() { - updateSelection(); + // TreeViewer uses lazy load, checked states must be updated when the tree is expanded. + refreshChecked(); } }); @@ -237,7 +233,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { selection.setEditingSupport(new SelectionEditingSupport(changeViewer, selected)); } - Composite buttonComposite = new Composite(composite, SWT.NONE); + Composite buttonComposite = new Composite(this, SWT.NONE); data = new GridData(); data.grabExcessHorizontalSpace = true; @@ -262,7 +258,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { updateAllButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - updateAll(); + applyAll(); } }); updateSelectedButton = new Button(buttonComposite, SWT.PUSH); @@ -270,12 +266,13 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { updateSelectedButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - updateSelected(); + applySelected(); } }); - - load(); - + } + + protected Session getSession() { + return SimanticsUI.getSession(); } protected String getColumntTitle(int i) { @@ -310,6 +307,18 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { return changes; } + public UpdateTree getUpdateTree() { + return updateTree; + } + + public CheckboxTreeViewer getChangeBrowser() { + return changeBrowser; + } + + public TableViewer getChangeViewer() { + return changeViewer; + } + private void showWarning(String text) { errorComposite.setVisible(true); @@ -318,11 +327,22 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { label = new Label(errorComposite, SWT.NONE); label.setText(text); //this.setStatusMessage("Update contains structural changes (new or deleted symbols), please create a new model."); - composite.layout(true); + this.layout(true); + } + + + private List checkStateListeners = new ArrayList<>(); + + public void addCheckStateListener(ICheckStateListener listener) { + checkStateListeners.add(listener); + } + + public void removeCheckStateListener(ICheckStateListener listener) { + checkStateListeners.remove(listener); } - private void updateSelection() { + public void refreshChecked() { Stack nodeStack = new Stack(); nodeStack.push((UpdateNode)updateTree.getRootNode()); while (!nodeStack.isEmpty()) { @@ -360,15 +380,17 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { } changeBrowser.refresh(); + for (ICheckStateListener l : checkStateListeners) { + l.checkStateChanged(new CheckStateChangedEvent(changeBrowser, null, false)); + } } - private void load() { + public void load(UpdateEditorInput uei) { addFilters(filters); - UpdateEditorInput uei = (UpdateEditorInput)getEditorInput(); Resource r1 = uei.getR1(); Resource r2 = uei.getR2(); @@ -384,7 +406,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { changes = getSession().syncRequest(new FilterChangesRead(changes)); updateTree = getUpdateTree(changes); } catch (DatabaseException e) { - Text text = new Text(composite, SWT.MULTI); + Text text = new Text(this, SWT.MULTI); text.setText(e.getMessage()); e.printStackTrace(); return; @@ -394,12 +416,12 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { changeViewer.setInput(changes.getModifications()); changeBrowser.setInput(updateTree); - updateSelection(); + refreshChecked(); } - private void updateAll() { + private void applyAll() { updateAllButton.setEnabled(false); updateSelectedButton.setEnabled(false); getSession().asyncRequest(new WriteRequest(){ @@ -422,7 +444,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { updateAllButton.setEnabled(true); updateSelectedButton.setEnabled(true); - updateSelection(); + refreshChecked(); changeViewer.refresh(); } }); @@ -452,7 +474,7 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { } - private void updateSelected() { + private void applySelected() { updateAllButton.setEnabled(false); updateSelectedButton.setEnabled(false); getSession().asyncRequest(new WriteRequest(){ @@ -475,18 +497,13 @@ public abstract class ModelUpdateEditor extends ResourceEditorPart2 { changeViewer.refresh(); updateAllButton.setEnabled(true); updateSelectedButton.setEnabled(true); - updateSelection(); + refreshChecked(); } }); } }); } - @Override - public void setFocus() { - composite.setFocus(); - - } /** * Filters changes: diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditorPart.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditorPart.java new file mode 100644 index 0000000..5577db5 --- /dev/null +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditorPart.java @@ -0,0 +1,25 @@ +package org.simantics.interop.update.editor; + +import org.eclipse.swt.widgets.Composite; +import org.simantics.ui.workbench.ResourceEditorPart2; + +public abstract class ModelUpdateEditorPart extends ResourceEditorPart2{ + + ModelUpdateEditor editor; + + @Override + public void createPartControl(Composite parent) { + editor = createEditor(parent); + editor.load((UpdateEditorInput)getEditorInput()); + } + + @Override + public void setFocus() { + editor.setFocus(); + } + + protected abstract ModelUpdateEditor createEditor(Composite parent); + + + +} diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java index e24e0cb..0814ecf 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateOperations.java @@ -57,6 +57,14 @@ public abstract class UpdateOperations { public GraphChanges getChanges() { return changes; } + + public Map getResourceMap() { + return resourceMap; + } + + public Map getStatementMap() { + return statementMap; + } private void apply(WriteGraph g, UpdateOp op) throws DatabaseException { Stack stack = new Stack(); -- 2.47.1