Bug 543200 - [Tests]Ant Editor gets NPE while getShell

getSite().getShell() is discouraged way to retrieve a Shell instance,
and check if the shell is disposed is wrong anyway for an editor which
can be closed but the shell is still there.

Added "disposed" flag and changed the checks accordingly to check if
*editor* is disposed.

Change-Id: I7bd015e5bfca1cfdeb76bf23784c2fd6a8efd666
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
index 687310d..a0dc277 100644
--- a/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
+++ b/ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditor.java
@@ -110,6 +110,7 @@
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.editors.text.TextEditor;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.part.IShowInTargetList;
@@ -504,6 +505,8 @@
 
 	private AntModel fAntModel;
 
+	private boolean disposed;
+
 	/**
 	 * Default no-argument constructor
 	 */
@@ -1045,6 +1048,7 @@
 	 */
 	@Override
 	public void dispose() {
+		disposed = true;
 		if (fEditorSelectionChangedListener != null) {
 			fEditorSelectionChangedListener.uninstall(getSelectionProvider());
 			fEditorSelectionChangedListener = null;
@@ -1072,11 +1076,10 @@
 		super.dispose();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
-	 */
+	public boolean isDisposed() {
+		return disposed;
+	}
+
 	@Override
 	public void doSave(IProgressMonitor monitor) {
 		super.doSave(monitor);
@@ -1141,10 +1144,9 @@
 	}
 
 	private void postImageChange(final AntElementNode node) {
-		Shell shell = getSite().getShell();
-		if (shell != null && !shell.isDisposed()) {
-			shell.getDisplay().asyncExec(() -> {
-				if (getSite().getShell() == null || getSite().getShell().isDisposed()) {
+		if (!isDisposed()) {
+			PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
+				if (isDisposed()) {
 					return;
 				}
 				Image titleImage = getTitleImage();
@@ -1223,10 +1225,9 @@
 			}
 		}
 
-		Shell shell = getSite().getShell();
-		if (shell != null && !shell.isDisposed()) {
-			shell.getDisplay().asyncExec(() -> {
-				if (getSite().getShell() == null || getSite().getShell().isDisposed()) {
+		if (!isDisposed()) {
+			PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
+				if (isDisposed()) {
 					return;
 				}
 				synchronize(true);
diff --git a/ant/org.eclipse.ant.ui/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.ui/META-INF/MANIFEST.MF
index a496614..97345ef 100644
--- a/ant/org.eclipse.ant.ui/META-INF/MANIFEST.MF
+++ b/ant/org.eclipse.ant.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.ant.ui; singleton:=true
-Bundle-Version: 3.7.300.qualifier
+Bundle-Version: 3.7.400.qualifier
 Bundle-Activator: org.eclipse.ant.internal.ui.AntUIPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/ant/org.eclipse.ant.ui/pom.xml b/ant/org.eclipse.ant.ui/pom.xml
index a13a435..838e105 100644
--- a/ant/org.eclipse.ant.ui/pom.xml
+++ b/ant/org.eclipse.ant.ui/pom.xml
@@ -19,7 +19,7 @@
   </parent>
   <groupId>org.eclipse.ant</groupId>
   <artifactId>org.eclipse.ant.ui</artifactId>
-  <version>3.7.300-SNAPSHOT</version>
+  <version>3.7.400-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
   <properties>
     <defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>