[Title] common-eplugin: fixed a invalid thread problem in DialogUtil
authorJihoon Song <jihoon80.song@samsung.com>
Wed, 24 Apr 2013 07:33:51 +0000 (16:33 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Thu, 25 Apr 2013 12:41:05 +0000 (21:41 +0900)
[Desc.]
[Issue]

Change-Id: Ia4c864a26757d5f86a373fe88d9ce74fa83bfa09

org.tizen.common/src/org/tizen/common/util/DialogUtil.java

index f93ca57..66101f6 100644 (file)
 
 package org.tizen.common.util;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
 
 public abstract class DialogUtil {
     /**
@@ -100,25 +103,31 @@ public abstract class DialogUtil {
      * @return int if user select 'yes', return SWT.YES. if user select 'no',
      *         return SWT.NO.
      */
-    protected static int retValue = 0;
     private final static Object lockQuestion = new Object(); 
     public static int openQuestionDialog(String message) {
-        return openQuestionDialog(new Shell(), "Question", message);
+        Shell activeShell = getActiveShell();
+        return openQuestionDialog( activeShell, "Question", message );
     }
     
     public static int openQuestionDialog(final Shell shell, final String title, final String message) {
         synchronized (lockQuestion) {
-            final String msg = message;
-            SWTUtil.syncExec(new Runnable() {
+            final AtomicInteger retValue = new AtomicInteger();
+            
+            SWTUtil.syncExec( new Runnable() {
                 public void run() {
-                    MessageBox dialog = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
+                    MessageBox dialog = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION );
                     dialog.setText( title );
-                    dialog.setMessage(msg);
-                    retValue = dialog.open();
+                    dialog.setMessage( message );
+                    retValue.set( dialog.open() );
                 }
             });
             
-            return retValue;
+            return retValue.get();
         }
     }
+    
+    public static Shell getActiveShell() {
+        IWorkbenchWindow window = ViewUtil.getWorkbenchWindow();
+        return ( window != null ) ? window.getShell() : null;
+    }
 }