/*
 * Copyright 2014 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.plugin.idea.runtime;

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

/**
 * @author Adam Wyłuda
 */
public class UIPromptImpl implements UIPrompt
{
    @Override
    public String prompt(String message)
    {
        return Messages.showInputDialog("", message, Messages.getQuestionIcon());
    }

    @Override
    public String promptSecret(String message)
    {
        // TODO Implement promptSecret()
        return prompt(message);
    }

    @Override
    public boolean promptBoolean(String message)
    {
        return Messages.showYesNoDialog(message, "", Messages.getQuestionIcon()) == Messages.YES;
    }

    @Override
    public boolean promptBoolean(String message, boolean defaultValue)
    {
        int result = Messages.showYesNoCancelDialog(message, "", Messages.getQuestionIcon());
        return result == Messages.CANCEL ? defaultValue : result == Messages.YES;
    }
}

@@ -220,16 +220,131 @@
 ntime;%0A%0A
+import com.intellij.openapi.application.ApplicationManager;%0Aimport com.intellij.openapi.application.ModalityState;%0A
 import c
@@ -504,16 +504,101 @@
 rompt%0A%7B%0A
+    private volatile String stringValue;%0A    private volatile boolean booleanValue;%0A%0A
     @Ove
@@ -628,16 +628,22 @@
  prompt(
+final 
 String m
@@ -668,80 +668,319 @@
     
-return Messages.showInputDialog(%22%22, message, Messages.getQuestionIcon())
+ApplicationManager.getApplication().invokeAndWait(new Runnable()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                stringValue = Messages.showInputDialog(%22%22, message, Messages.getQuestionIcon());%0A            %7D%0A        %7D, ModalityState.any());%0A        return stringValue
 ;%0A  
@@ -1170,32 +1170,38 @@
 n promptBoolean(
+final 
 String message)%0A
@@ -1214,22 +1214,187 @@
         
-return
+ApplicationManager.getApplication().invokeAndWait(new Runnable()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                booleanValue =
  Message
@@ -1465,24 +1465,100 @@
 ssages.YES;%0A
+            %7D%0A        %7D, ModalityState.any());%0A        return booleanValue;%0A
     %7D%0A%0A    @
@@ -1599,16 +1599,22 @@
 Boolean(
+final 
 String m
@@ -1620,16 +1620,22 @@
 message,
+ final
  boolean
@@ -1647,32 +1647,189 @@
 ultValue)%0A    %7B%0A
+        ApplicationManager.getApplication().invokeAndWait(new Runnable()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A        
         int resu
@@ -1914,22 +1914,38 @@
         
-return
+        booleanValue =
  result 
@@ -2000,20 +2000,96 @@
 ssages.YES;%0A
+            %7D%0A        %7D, ModalityState.any());%0A        return booleanValue;%0A
     %7D%0A%7D%0A

Call prompts on Swing thread