Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2019-04-22 12:16:49 -0400
committerlgoubet2019-04-22 12:16:49 -0400
commitd2f51867b94fbd32268ee9bcc4a04a7045a9ee2a (patch)
tree6a9434d46789003bb3d097f47e0409efa6c1063f
parent382d98c7ea5028fd3e8c24eb607ee2526de93016 (diff)
downloadorg.eclipse.emf.compare-d2f51867b94fbd32268ee9bcc4a04a7045a9ee2a.tar.gz
org.eclipse.emf.compare-d2f51867b94fbd32268ee9bcc4a04a7045a9ee2a.tar.xz
org.eclipse.emf.compare-d2f51867b94fbd32268ee9bcc4a04a7045a9ee2a.zip
Prevent CMV disposal when user selects multiple elements in the SMW
This is most likely a Platform/compare bug. The structure merge viewers don't support multiple selections and if the user selects two differences, the ContentMergeViewer is disposed and cleared out. If the user then merges the two differences at once, since no CMV is currently shown, the editor will not become dirty: the CompareEditorInput is the one in charge of managing the comparison's dirty state, and that state is _only_ updated through the listener (CompareEditorInput#fDirtyStateListener) that is installed on the opened CMV. Change-Id: I7c754ca4ce1eb2f6dcf80dd5472c8f787572790d
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
index 9b083bb08..ac6653aff 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
@@ -159,6 +159,7 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ISelection;
@@ -353,6 +354,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
private ISelectionChangedListener selectionChangeListener;
+ private List<ISelectionChangedListener> selectionChangeListeners;
+
/** The current selection. */
protected ISelection currentSelection;
@@ -421,6 +424,8 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
createContextMenu();
+ selectionChangeListeners = new ArrayList<ISelectionChangedListener>();
+
selectionChangeListener = new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
handleSelectionChangedEvent(event);
@@ -2096,6 +2101,52 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
}
+ @Override
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ selectionChangeListeners.add(listener);
+ }
+
+ @Override
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ selectionChangeListeners.remove(listener);
+ }
+
+ @Override
+ protected void fireSelectionChanged(SelectionChangedEvent event) {
+ /*
+ * Platform/compare does not support multiple selections in the structure viewer. When the user
+ * selects multiple differences, org.eclipse.compare.CompareEditorInput#getElement(ISelection)) will
+ * return a null selection, causing the CompareViewerSwitchingPane to dispose of the currently shown
+ * ContentMergeViewer. Unfortunately, the dirty state of the CompareEditorInput is _only_ managed
+ * through the CMV: ContentMergeViewer.setLeftDirty will notify the CompareEditorInput that it needs
+ * to update the dirty state... Only if a CMV is currently shown. In short, if a user selects multiple
+ * differences and merges them, the CompareEditorInput will never know that it is dirty and needs a
+ * save.
+ */
+ ISelection selection = event.getSelection();
+ final SelectionChangedEvent compareEvent;
+ if (!selection.isEmpty() && selection instanceof IStructuredSelection
+ && ((IStructuredSelection)selection).size() != 1) {
+ ISelection modifiedSelection = new StructuredSelection(
+ ((IStructuredSelection)selection).getFirstElement());
+ compareEvent = new SelectionChangedEvent(event.getSelectionProvider(), modifiedSelection);
+ } else {
+ compareEvent = event;
+ }
+ for (ISelectionChangedListener listener : selectionChangeListeners) {
+ SafeRunnable.run(new SafeRunnable() {
+ @Override
+ public void run() {
+ if (listener instanceof CompareViewerSwitchingPane) {
+ listener.selectionChanged(compareEvent);
+ } else {
+ listener.selectionChanged(event);
+ }
+ }
+ });
+ }
+ }
+
private void handleSelectionChangedEvent(SelectionChangedEvent event) {
if (!Objects.equal(currentSelection, event.getSelection())) {
this.currentSelection = event.getSelection();

Back to the top