Fix exception when pressing FileDialog Cancel button

When FileDialog Cancel button is pressed, FileUpload widget is disposed
before the uploading runnable is terminated.

Do not dispose already disposed FileUpload widget in
UploaderWidget#dispose.

440887: FileUpload widget is disposed exception
https://bugs.eclipse.org/bugs/show_bug.cgi?id=440887

Change-Id: If552b3e0e0e5c9f031d3bc417077078409222e0f
Signed-off-by: Ivan Furnadjiev <ivan@eclipsesource.com>
diff --git a/bundles/org.eclipse.rap.addons.filedialog/src/org/eclipse/swt/internal/widgets/UploaderWidget.java b/bundles/org.eclipse.rap.addons.filedialog/src/org/eclipse/swt/internal/widgets/UploaderWidget.java
index 6874fbf..990db5e 100644
--- a/bundles/org.eclipse.rap.addons.filedialog/src/org/eclipse/swt/internal/widgets/UploaderWidget.java
+++ b/bundles/org.eclipse.rap.addons.filedialog/src/org/eclipse/swt/internal/widgets/UploaderWidget.java
@@ -27,7 +27,7 @@
   }
 
   public void dispose() {
-    if( ( fileUpload.getStyle() & SWT.MULTI ) != 0 ) {
+    if( !fileUpload.isDisposed() && ( fileUpload.getStyle() & SWT.MULTI ) != 0 ) {
       fileUpload.dispose();
     }
   }
diff --git a/tests/org.eclipse.rap.addons.filedialog.test/src/org/eclipse/swt/internal/widgets/UploaderWidget_Test.java b/tests/org.eclipse.rap.addons.filedialog.test/src/org/eclipse/swt/internal/widgets/UploaderWidget_Test.java
index 8701901..a647ad1 100644
--- a/tests/org.eclipse.rap.addons.filedialog.test/src/org/eclipse/swt/internal/widgets/UploaderWidget_Test.java
+++ b/tests/org.eclipse.rap.addons.filedialog.test/src/org/eclipse/swt/internal/widgets/UploaderWidget_Test.java
@@ -12,12 +12,14 @@
 
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
 import org.eclipse.rap.rwt.widgets.FileUpload;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
 import org.junit.Test;
 
 
@@ -54,4 +56,16 @@
     verify( fileUpload ).dispose();
   }
 
+  @Test
+  public void testDispose_withAlreadyDisposedFileUpload() {
+    FileUpload fileUpload = mock( FileUpload.class );
+    doReturn( Boolean.TRUE).when( fileUpload ).isDisposed();
+    doThrow( SWTException.class ).when( fileUpload ).getStyle();
+    UploaderWidget uploader = new UploaderWidget( fileUpload );
+
+    uploader.dispose();
+
+    verify( fileUpload, never() ).dispose();
+  }
+
 }