Skip to content

Commit

Permalink
Call prompts on Swing thread
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-wyluda committed Jul 28, 2014
1 parent 1b0033b commit 46bf045
Showing 1 changed file with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.jboss.forge.plugin.idea.runtime;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.ui.Messages;
import org.jboss.forge.addon.ui.input.UIPrompt;

Expand All @@ -14,10 +16,21 @@
*/
public class UIPromptImpl implements UIPrompt
{
private volatile String stringValue;
private volatile boolean booleanValue;

@Override
public String prompt(String message)
public String prompt(final String message)
{
return Messages.showInputDialog("", message, Messages.getQuestionIcon());
ApplicationManager.getApplication().invokeAndWait(new Runnable()
{
@Override
public void run()
{
stringValue = Messages.showInputDialog("", message, Messages.getQuestionIcon());
}
}, ModalityState.any());
return stringValue;
}

@Override
Expand All @@ -28,15 +41,31 @@ public String promptSecret(String message)
}

@Override
public boolean promptBoolean(String message)
public boolean promptBoolean(final String message)
{
return Messages.showYesNoDialog(message, "", Messages.getQuestionIcon()) == Messages.YES;
ApplicationManager.getApplication().invokeAndWait(new Runnable()
{
@Override
public void run()
{
booleanValue = Messages.showYesNoDialog(message, "", Messages.getQuestionIcon()) == Messages.YES;
}
}, ModalityState.any());
return booleanValue;
}

@Override
public boolean promptBoolean(String message, boolean defaultValue)
public boolean promptBoolean(final String message, final boolean defaultValue)
{
int result = Messages.showYesNoCancelDialog(message, "", Messages.getQuestionIcon());
return result == Messages.CANCEL ? defaultValue : result == Messages.YES;
ApplicationManager.getApplication().invokeAndWait(new Runnable()
{
@Override
public void run()
{
int result = Messages.showYesNoCancelDialog(message, "", Messages.getQuestionIcon());
booleanValue = result == Messages.CANCEL ? defaultValue : result == Messages.YES;
}
}, ModalityState.any());
return booleanValue;
}
}

0 comments on commit 46bf045

Please sign in to comment.