Commit e9017669 authored by Dietrich Travkin's avatar Dietrich Travkin Committed by Balazs Grill
Browse files

[579937] Bugfix: Check editor disposal when handling events



Change-Id: If95e759a4ec1ef44126aab3f86b0c6097c526e5c
Signed-off-by: default avatarBalázs Grill <balazs.grill@incquerylabs.com>
Signed-off-by: default avatarDietrich Travkin <travkin@gmx.de>
parent 826cdf83
Loading
Loading
Loading
Loading
+76 −67
Original line number Diff line number Diff line
@@ -1082,7 +1082,8 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd

	public void setStatusLineManager(ISelection selection) {
		IStatusLineManager statusLineManager = currentSelectionProvider != null && currentSelectionProvider == contentOutlineViewer
				? contentOutlineStatusLineManager : getActionBars() != null ? getActionBars().getStatusLineManager() : null;
				? contentOutlineStatusLineManager
				: getActionBars() != null ? getActionBars().getStatusLineManager() : null;
		if (statusLineManager != null) {
			if (selection instanceof IStructuredSelection) {
				Collection<?> collection = ((IStructuredSelection) selection).toList();
@@ -1190,14 +1191,18 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
	 * Tests if this editor has already been disposed.
	 * <p>
	 * This implementation determines the disposed state of the editor by checking if the {@link FormEditor#pages} field
	 * is <code>null</code> or not. When the editor has been disposed, it is an error to invoke any other method using
	 * the editor.
	 * is <code>null</code> or not and if its site and workbench window are available. When the editor has been
	 * disposed, it is an error to invoke any other method using the editor.
	 * </p>
	 *
	 * @return <code>true</code> when the editor is disposed and <code>false</code> otherwise.
	 */
	protected boolean isDisposed() {
		return pages == null;
		if (pages == null || getSite() == null || getSite().getWorkbenchWindow() == null) {
			return true;
		}

		return false;
	}

	/**
@@ -1219,10 +1224,14 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
	}

	protected boolean isActivePart() {
		return this == getSite().getWorkbenchWindow().getPartService().getActivePart();
		return !isDisposed() && this == getSite().getWorkbenchWindow().getPartService().getActivePart();
	}

	protected boolean isActivePropertySheetPage() {
		if (isDisposed()) {
			return false;
		}

		IWorkbenchPart activePart = getSite().getWorkbenchWindow().getPartService().getActivePart();
		if (activePart instanceof PropertySheet) {
			return propertySheetPages.contains(((PropertySheet) activePart).getCurrentPage());
@@ -1604,10 +1613,12 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		@Override
		public void handleEditorInputObjectAdded(IEditorInput editorInput, final Set<EObject> addedObjects) {
			IWorkbenchPartSite site = getSite();
			if (site != null && site.getShell() != null && !site.getShell().isDisposed()) {
			if (!isDisposed() && site.getShell() != null && !site.getShell().isDisposed()) {
				site.getShell().getDisplay().asyncExec(new Runnable() {

					@Override
					public void run() {
						if (!isDisposed()) {
							// Reset the editor state
							reset();

@@ -1619,6 +1630,8 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
								finishCreatePagesOnActivation = true;
							}
						}
					}

				});
			}
		}
@@ -1629,8 +1642,10 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		@Override
		public void handleEditorInputObjectRemoved(IEditorInput editorInput, Set<EObject> removedObjects) {
			// Close editor
			if (!isDisposed()) {
				close(false);
			}
		}

		/**
		 * {@inheritDoc}
@@ -1647,10 +1662,12 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		public void handleEditorInputObjectChanged(IEditorInput editorInput, final Set<EObject> changedObjects) {
			// Handle affected objects
			IWorkbenchPartSite site = getSite();
			if (site != null && site.getShell() != null && !site.getShell().isDisposed()) {
			if (!isDisposed() && site.getShell() != null && !site.getShell().isDisposed()) {
				site.getShell().getDisplay().asyncExec(new Runnable() {

					@Override
					public void run() {
						if (!isDisposed()) {
							if (isActivePart() || isActivePropertySheetPage()) {
								// Try to select the affected objects
								setSelectionToViewer(changedObjects);
@@ -1668,6 +1685,8 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
							setPartName(getEditorInputName());
							setTitleImage(getEditorInputImage());
						}
					}

				});
			}
		}
@@ -1678,24 +1697,7 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		@Override
		public void handleEditorInputResourceLoaded(IEditorInput editorInput) {
			// Invoked when editor input object has been added.
			final IWorkbenchPartSite site = getSite();
			if (site != null && site.getShell() != null && !site.getShell().isDisposed()) {
				site.getShell().getDisplay().asyncExec(new Runnable() {
					@Override
					public void run() {
						// Reset the editor state
						reset();

						// Finish page creation if editor is currently visible; otherwise mark that as to be done when
						// editor gets activated the next time
						if (site.getPage().isPartVisible(BasicTransactionalFormEditor.this)) {
							finishCreatePages();
						} else {
							finishCreatePagesOnActivation = true;
						}
					}
				});
			}
			handleEditorInputObjectAdded(editorInput, Collections.emptySet());
		}

		/**
@@ -1704,10 +1706,12 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		@Override
		public void handleEditorInputResourceUnloaded(IEditorInput editorInput) {
			IWorkbenchPartSite site = getSite();
			if (site != null && site.getShell() != null && !site.getShell().isDisposed()) {
			if (!isDisposed() && site.getShell() != null && !site.getShell().isDisposed()) {
				site.getShell().getDisplay().asyncExec(new Runnable() {

					@Override
					public void run() {
						if (!isDisposed()) {
							// Reset the editor state
							reset();

@@ -1715,6 +1719,8 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
							// visible)
							setMessagePage(createNoEditorInputPage());
						}
					}

				});
			}
		}
@@ -1725,10 +1731,12 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		@Override
		public void handleEditorInputResourceMoved(IEditorInput editorInput, URI oldURI, final URI newURI) {
			IWorkbenchPartSite site = getSite();
			if (site != null && site.getShell() != null && !site.getShell().isDisposed()) {
			if (!isDisposed() && site.getShell() != null && !site.getShell().isDisposed()) {
				site.getShell().getDisplay().asyncExec(new Runnable() {

					@Override
					public void run() {
						if (!isDisposed()) {
							// Discard undo context
							IOperationHistory operationHistory = getOperationHistory();
							if (operationHistory != null) {
@@ -1741,6 +1749,8 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
							// Update this editor's dirty state
							firePropertyChange(IEditorPart.PROP_DIRTY);
						}
					}

				});
			}
		}
@@ -1750,8 +1760,7 @@ public class BasicTransactionalFormEditor extends FormEditor implements IModelEd
		 */
		@Override
		public void handleEditorInputResourceRemoved(IEditorInput editorInput) {
			// Close editor
			close(false);
			handleEditorInputObjectRemoved(editorInput, Collections.emptySet());
		}
	}
}
 No newline at end of file