com.ptc.windchill.upgrade.util
Class ThreadedOptionPane

java.lang.Object
  extended bycom.ptc.windchill.upgrade.util.ThreadedOptionPane

public class ThreadedOptionPane
extends Object

A class that displays prompts that can be use to control worker threads. For example, this class can be used to show a "cancel work" dialog and if the user selects "cancel" run a command that will ask the worker thread to cancel what it is doing. Through use of the blockWhilePromptOpen() method you may control whether the worker thread will wait for a response before continuing.


Field Summary
private  String message_
           
private  int messageType_
           
private  HashMap optionActionMap_
           
private  JOptionPane optionPane_
           
private  int optionType_
           
private  JDialog promptDialog_
           
private  Thread thread_
           
private  String title_
           
 
Constructor Summary
ThreadedOptionPane(String message, String title, int message_type, int option_type)
          Create an instance that will open a JOptionPane with the specified arguments.
 
Method Summary
 void blockWhilePromptOpen()
          Close the prompt if it's open.
 void closePromptIfOpen()
          Worker threads should call this when they're done so that the prompt will go away when no longer needed.
private  void makeDialogNotVisible()
           
 void openPromptIfNotOpen(Component parent_component)
          Opens the prompt if it is not already open.
 void removeBehaviorForOption(int option)
          Remove the behavior for the specified option.
 void setOptionBehavior(int option, Runnable behavior)
          Set the behavior that will be run when the user selects the given option.
private  void waitUpBlockers()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

message_

private String message_

title_

private String title_

messageType_

private int messageType_

optionType_

private int optionType_

optionActionMap_

private HashMap optionActionMap_

promptDialog_

private JDialog promptDialog_

optionPane_

private JOptionPane optionPane_

thread_

private Thread thread_
Constructor Detail

ThreadedOptionPane

public ThreadedOptionPane(String message,
                          String title,
                          int message_type,
                          int option_type)
Create an instance that will open a JOptionPane with the specified arguments. See javax.swing.JOptionPane for details about the argument types.

Method Detail

setOptionBehavior

public void setOptionBehavior(int option,
                              Runnable behavior)
Set the behavior that will be run when the user selects the given option. The behavior will run in the event handing thread.


removeBehaviorForOption

public void removeBehaviorForOption(int option)
Remove the behavior for the specified option.


openPromptIfNotOpen

public void openPromptIfNotOpen(Component parent_component)
Opens the prompt if it is not already open.


waitUpBlockers

private void waitUpBlockers()

closePromptIfOpen

public void closePromptIfOpen()
Worker threads should call this when they're done so that the prompt will go away when no longer needed.

Example

    public void run() {
          ThreadedOptionPane prompt = ...;
       try {
          do work
       } finally {
          prompt.closePromptIfOpen();
       }
    }


makeDialogNotVisible

private void makeDialogNotVisible()

blockWhilePromptOpen

public void blockWhilePromptOpen()
Close the prompt if it's open. Worker threads should call this in finally block to prevent the dialog from remaining open past the end of the thread.

Example

    public void run() {
          ThreadedOptionPane cancel_prompt = ...; // add cancel action that makes canceled() return true
       try {
          while(cancel_prompt.blockWhilePromptOpen() && !canceled()) { // canceled() second so that work is canceled as soon as possible after prompt closes
             do work
          }
       } finally {
          cancel_prompt.closePromptIfOpen();
       }
    }