com.ptc.windchill.upgrade.util
Class ThreadedCancelConfirmPrompt

java.lang.Object
  extended bycom.ptc.windchill.upgrade.util.ThreadedCancelConfirmPrompt
All Implemented Interfaces:
CancellationMonitor

public class ThreadedCancelConfirmPrompt
extends Object
implements CancellationMonitor

A class that displays a JOptionPane dialog with a YES_NO option to confirm cancellation of a threaded work task. Allows the worker thread to decide if the work should continue while the user is being prompted.


Field Summary
private  ThreadedOptionPane cancelOptionPane_
           
private  boolean cancelRequested_
           
 
Constructor Summary
ThreadedCancelConfirmPrompt(String title, String question)
           
 
Method Summary
 void closePromptIfOpen()
          Close the prompt if it's open.
 boolean hasCancelBeenRequested(boolean block_if_deciding)
          Worker threads can call this if they want to halt work while the prompt is open and a decision has not yet been made.
protected  void onCancelRequested()
          Subclasses can override this to do additional work when confirmation of a cancel is actually made.
 void openPromptIfNotOpen(Component parent_component)
          Display a JDialog for the prompt if one is not currently open AND a cancel confirmation hasn't already been made.
 void reset()
          Resets the cancel requested state so that an instance can be used over and over for confirming cancellations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cancelOptionPane_

private ThreadedOptionPane cancelOptionPane_

cancelRequested_

private boolean cancelRequested_
Constructor Detail

ThreadedCancelConfirmPrompt

public ThreadedCancelConfirmPrompt(String title,
                                   String question)
Method Detail

hasCancelBeenRequested

public boolean hasCancelBeenRequested(boolean block_if_deciding)
Worker threads can call this if they want to halt work while the prompt is open and a decision has not yet been made.

Example

    public void run() {
       ThreadedCancelConfirmPrompt cancel_prompt = ...; // add cancel action that makes canceled() return true
       while(!cancel_prompt.hasCancelBeenRequested(true)) { // block if prompting
          ... do work ...
       }
       ...
    }

Specified by:
hasCancelBeenRequested in interface CancellationMonitor
Parameters:
block_if_deciding - If true, block the caller if the decision is in progress, and return once a decision has been made. Otherwise, return the latest decision immediately.

reset

public void reset()
Resets the cancel requested state so that an instance can be used over and over for confirming cancellations.


openPromptIfNotOpen

public void openPromptIfNotOpen(Component parent_component)
Display a JDialog for the prompt if one is not currently open AND a cancel confirmation hasn't already been made.


closePromptIfOpen

public void closePromptIfOpen()
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() {
          ThreadedCancelConfrmPrompt cancel_prompt = ...;
       try {
          ... do work ...
       } finally {
          cancel_prompt.closePromptIfOpen(); // makes sure you don't leave the dialog open
       }
    }


onCancelRequested

protected void onCancelRequested()
Subclasses can override this to do additional work when confirmation of a cancel is actually made. A call to super.onCancelRequested() is not necessary in immediate subclasses.