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 {
/**
* @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;
+ }
}