eclipse plugin: Rework a bit the MyRunnable
This commit is contained in:
parent
9ad32462ef
commit
689f46c0dc
3 changed files with 23 additions and 19 deletions
|
@ -87,19 +87,19 @@ public class GUIUtils
|
|||
if (window == null || window.getShell() == null || message == null)
|
||||
return -1;
|
||||
|
||||
MyRunnable<Integer> runnable = new MyRunnable<Integer>() {
|
||||
RunnableWithResult<Integer> runnable = new RunnableWithResult<Integer>() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
MessageBox box = new MessageBox(window.getShell(), style);
|
||||
box.setMessage(message);
|
||||
runnableObject_ = box.open();
|
||||
setResult( box.open() );
|
||||
}
|
||||
} ;
|
||||
try
|
||||
{
|
||||
window.getShell().getDisplay().syncExec(runnable);
|
||||
return runnable.runnableObject_;
|
||||
return runnable.getResult( );
|
||||
} catch (Exception e)
|
||||
{
|
||||
Logger.getInstance().logException(e);
|
||||
|
|
|
@ -8,19 +8,17 @@
|
|||
*******************************************************************************/
|
||||
package org.wesnoth.utils;
|
||||
|
||||
public class MyRunnable<T> implements Runnable
|
||||
public abstract class RunnableWithResult<T> implements Runnable
|
||||
{
|
||||
protected T runnableObject_;
|
||||
private T result_;
|
||||
|
||||
public MyRunnable(T t) {
|
||||
this.runnableObject_ = t;
|
||||
}
|
||||
|
||||
public MyRunnable(){
|
||||
|
||||
}
|
||||
@Override
|
||||
public void run()
|
||||
public void setResult( T result )
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
|
||||
public T getResult( )
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
}
|
|
@ -146,15 +146,21 @@ public class WorkspaceUtils
|
|||
{
|
||||
if (window == null)
|
||||
return null;
|
||||
MyRunnable<IStructuredSelection> runnable = new MyRunnable<IStructuredSelection>(){
|
||||
|
||||
RunnableWithResult<IStructuredSelection> runnable =
|
||||
new RunnableWithResult<IStructuredSelection>(){
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try{
|
||||
runnableObject_ = null;
|
||||
if (!(window.getSelectionService().getSelection() instanceof IStructuredSelection))
|
||||
setResult( null );
|
||||
|
||||
if ( !( window.getSelectionService().getSelection()
|
||||
instanceof IStructuredSelection ) )
|
||||
return;
|
||||
runnableObject_ = (IStructuredSelection) window.getSelectionService().getSelection();
|
||||
|
||||
setResult( ( IStructuredSelection)
|
||||
window.getSelectionService().getSelection( ) );
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -162,7 +168,7 @@ public class WorkspaceUtils
|
|||
}
|
||||
};
|
||||
Display.getDefault().syncExec(runnable);
|
||||
return runnable.runnableObject_;
|
||||
return runnable.getResult( );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue