gui.dialog
Class WorkerContentPane

java.lang.Object
  extended by gui.dialog.DialogContentPane
      extended by gui.dialog.WorkerContentPane
All Implemented Interfaces:
DialogContentPane.IWizardSuitable, DialogContentPane.IWizardSuitableNoWizardButtons, IDialogOptions, JAPHelpContext.IHelpContext
Direct Known Subclasses:
AccountSettingsPanel.AccountCreationPane

public class WorkerContentPane
extends DialogContentPane
implements DialogContentPane.IWizardSuitableNoWizardButtons

This is a dialog that executes a given Thread or Runnable if it is shown on screen. It has an optional cancel button. A click on the dialog close button or on the cancel button will interrupt the Thread. The Thread may watch for this event but does not need to. The behaviour if the Thread is interrupted (isInterrupted() returns true) and has finished is the same as if a user clicks the cancel button. You may therefore control this behaviour by defining another default button operation for the cancel button and by overwriting the isInterrupted() method of your Thread. If the Thread is not interrupted and has finished, the next content pane is shown. If there is no next content pane, the dialog is closed according to the ON_CLICK button operation. By default, it is disposed.

Warning: The Thread should not call dispose() on the dialog, as this may lead to a deadlock or an Exception!

Author:
Rolf Wendolsky

Nested Class Summary
private  class WorkerContentPane.InternalThread
          A wrapper for the worker runnable.
private  class WorkerContentPane.WorkerComponentListener
           
 
Nested classes/interfaces inherited from class gui.dialog.DialogContentPane
DialogContentPane.CheckError, DialogContentPane.IWizardSuitable, DialogContentPane.IWizardSuitableNoWizardButtons, DialogContentPane.Layout
 
Field Summary
static java.lang.String DOTS
           
static java.lang.String IMG_BUSY
           
private  boolean m_bInterruptThreadSafe
           
private  java.lang.Thread m_internalThread
           
private  int m_iProgressStatus
           
private  java.lang.Runnable m_workerRunnable
           
private  java.lang.Thread m_workerThread
           
static java.lang.String MSG_PLEASE_WAIT
           
 
Fields inherited from class gui.dialog.DialogContentPane
BUTTON_OPERATION_WIZARD, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_EMPTY, DEFAULT_BUTTON_HELP, DEFAULT_BUTTON_KEEP, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_OK, DEFAULT_BUTTON_YES, MSG_CANCEL, MSG_FINISH, MSG_NEXT, MSG_NO, MSG_OK, MSG_OPERATION_FAILED, MSG_PREVIOUS, MSG_SEE_FULL_MESSAGE, MSG_YES, ON_CANCEL_DISPOSE_DIALOG, ON_CANCEL_HIDE_DIALOG, ON_CANCEL_SHOW_NEXT_CONTENT, ON_CANCEL_SHOW_PREVIOUS_CONTENT, ON_CLICK_DISPOSE_DIALOG, ON_CLICK_DO_NOTHING, ON_CLICK_HIDE_DIALOG, ON_CLICK_SHOW_NEXT_CONTENT, ON_CLICK_SHOW_PREVIOUS_CONTENT, ON_NO_DISPOSE_DIALOG, ON_NO_HIDE_DIALOG, ON_NO_SHOW_NEXT_CONTENT, ON_NO_SHOW_PREVIOUS_CONTENT, ON_YESOK_DISPOSE_DIALOG, ON_YESOK_HIDE_DIALOG, ON_YESOK_SHOW_NEXT_CONTENT, ON_YESOK_SHOW_PREVIOUS_CONTENT
 
Fields inherited from interface gui.dialog.IDialogOptions
MESSAGE_TYPE_ERROR, MESSAGE_TYPE_INFORMATION, MESSAGE_TYPE_PLAIN, MESSAGE_TYPE_QUESTION, MESSAGE_TYPE_WARNING, OPTION_TYPE_CANCEL, OPTION_TYPE_DEFAULT, OPTION_TYPE_EMPTY, OPTION_TYPE_OK_CANCEL, OPTION_TYPE_YES_NO, OPTION_TYPE_YES_NO_CANCEL, RETURN_VALUE_CANCEL, RETURN_VALUE_CLOSED, RETURN_VALUE_NO, RETURN_VALUE_OK, RETURN_VALUE_UNINITIALIZED, RETURN_VALUE_YES
 
Constructor Summary
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, DialogContentPane a_previousContentPane, java.lang.Runnable a_workerRunnable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, DialogContentPane a_previousContentPane, java.lang.Runnable a_workerRunnable, java.util.Observable a_observable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.Runnable a_workerRunnable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.Runnable a_workerRunnable, java.util.Observable a_observable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.String a_strTitle, DialogContentPane a_previousContentPane, java.lang.Runnable a_workerRunnable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.String a_strTitle, DialogContentPane a_previousContentPane, java.lang.Runnable a_workerRunnable, java.util.Observable a_observable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.String a_strTitle, java.lang.Runnable a_workerRunnable)
           
WorkerContentPane(JAPDialog a_parentDialog, java.lang.String a_strText, java.lang.String a_strTitle, java.lang.Runnable a_workerRunnable, java.util.Observable a_observable)
           
 
Method Summary
 DialogContentPane.CheckError[] checkCancel()
          Interrupts the Thread.
 void dispose()
           
 int getProgressStatus()
          Only meaningful if a ProgressCapsule observer is used.
 java.lang.Object getValue()
          If an instance of IReturnRunnable is run, this method returns the result of IReturnRunnable.getValue().
 void interruptWorkerThread()
          Interrupts the thread.
 boolean isInterruptThreadSafe()
          Returns true if the content pane only does a close or move operation if the thread has stopped.
 boolean isReady()
          Returns if the content pane is ready to start a new thread.
 boolean isSkippedAsPreviousContentPane()
          Returns true by default, that means this worker content pane is skipped if a move from the next content pane to this one is done.
 void joinThread()
          The caller waits until the thread has stopped.
 void setInterruptThreadSafe(boolean a_bInterruptThreadSafe)
          Defines this content pane should interrupt the wrapped thread safe or not if the user closed the parent dialog or clicked cancel.
 
Methods inherited from class gui.dialog.DialogContentPane
addComponentListener, addDialogComponentListener, addDialogWindowListener, checkNo, checkUpdate, checkYesOK, clearStatusMessage, clearStatusMessage, closeDialog, getButtonCancel, getButtonHelp, getButtonNo, getButtonValue, getButtonYesOK, getContentPane, getDefaultButton, getDefaultButtonOperation, getDialog, getHelpContext, getHelpExtractionDisplayContext, getMessageIcon, getNextContentPane, getPreviousContentPane, getText, hasNextContentPane, hasPreviousContentPane, hasValidValue, hasWizardLayout, isActive, isAutomaticFocusSettingEnabled, isDialogVisible, isDisposed, isMoveBackAllowed, isMoveForwardAllowed, isSkippedAsNextContentPane, isVisible, moveToNextContentPane, moveToPreviousContentPane, printErrorStatusMessage, printErrorStatusMessage, printErrorStatusMessage, printStatusMessage, printStatusMessage, removeComponentListener, removeDialogComponentListener, removeDialogWindowListener, setButtonValue, setContentPane, setDefaultButton, setDefaultButtonOperation, setMouseListener, setText, showDialog, updateDialog, updateDialogOptimalSized, updateDialogOptimalSized, validateDialog
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMG_BUSY

public static final java.lang.String IMG_BUSY
See Also:
Constant Field Values

MSG_PLEASE_WAIT

public static final java.lang.String MSG_PLEASE_WAIT

DOTS

public static final java.lang.String DOTS
See Also:
Constant Field Values

m_workerThread

private java.lang.Thread m_workerThread

m_workerRunnable

private java.lang.Runnable m_workerRunnable

m_internalThread

private java.lang.Thread m_internalThread

m_bInterruptThreadSafe

private boolean m_bInterruptThreadSafe

m_iProgressStatus

private int m_iProgressStatus
Constructor Detail

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.Runnable a_workerRunnable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.Runnable a_workerRunnable,
                         java.util.Observable a_observable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.String a_strTitle,
                         java.lang.Runnable a_workerRunnable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.String a_strTitle,
                         java.lang.Runnable a_workerRunnable,
                         java.util.Observable a_observable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         DialogContentPane a_previousContentPane,
                         java.lang.Runnable a_workerRunnable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         DialogContentPane a_previousContentPane,
                         java.lang.Runnable a_workerRunnable,
                         java.util.Observable a_observable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.String a_strTitle,
                         DialogContentPane a_previousContentPane,
                         java.lang.Runnable a_workerRunnable)

WorkerContentPane

public WorkerContentPane(JAPDialog a_parentDialog,
                         java.lang.String a_strText,
                         java.lang.String a_strTitle,
                         DialogContentPane a_previousContentPane,
                         java.lang.Runnable a_workerRunnable,
                         java.util.Observable a_observable)
Method Detail

isInterruptThreadSafe

public final boolean isInterruptThreadSafe()
Returns true if the content pane only does a close or move operation if the thread has stopped. Otherwise, the close or move operation is performed if the thread has been interrupted by closing the dialog window or clicking on the cancel button. If you want this, the calling thread is recommended to call joinThread() to safely wait for the end of the thread before starting a new one. Remember that a call to updateDialog() of this content pane gives an undefined result if the previously startet thread has not stopped yet.

Returns:
true if the content pane only does a close or move operation if thetThread has stopped. Otherwise, the close or move operation is performed if the thread has been interrupted by closing the dialog window or clicking on the cancel button

setInterruptThreadSafe

public final void setInterruptThreadSafe(boolean a_bInterruptThreadSafe)
Defines this content pane should interrupt the wrapped thread safe or not if the user closed the parent dialog or clicked cancel.

Parameters:
a_bInterruptThreadSafe - true if the content pane only does a close or move operation if the thread has stopped. Otherwise, the close or move operation is performed if the thread has been interrupted by closing the dialog window or clicking on the cancel button. If you want this, the calling thread is recommended to call joinThread() to safely wait for the end of the thread before starting a new one. Remember that a call to updateDialog() of this content pane gives an undefined result if the previously started thread has not stopped yet.

joinThread

public final void joinThread()
The caller waits until the thread has stopped. This is only needed if isInterruptThreadSafe() returns false and the user closes the dialog or clicks cancel, otherwise this is done automatically. Remember that a new thread started by this content pane is blocked until the old thread has stopped and, if started, it will overwrite the getValue() result of the old thread.


isReady

public boolean isReady()
Returns if the content pane is ready to start a new thread. If it is not ready, no thread will be started when the content pane shows up. Subclasses may override this method to hide and show this content pane while a thread is running. Please note that this method should always return true after the thread has stopped.

Returns:
if the content pane is ready to start a new thread; true by default

isSkippedAsPreviousContentPane

public boolean isSkippedAsPreviousContentPane()
Returns true by default, that means this worker content pane is skipped if a move from the next content pane to this one is done.

Overrides:
isSkippedAsPreviousContentPane in class DialogContentPane
Returns:
true

checkCancel

public DialogContentPane.CheckError[] checkCancel()
Interrupts the Thread.

Overrides:
checkCancel in class DialogContentPane
Returns:
CheckError[]

dispose

public void dispose()
Overrides:
dispose in class DialogContentPane

getProgressStatus

public int getProgressStatus()
Only meaningful if a ProgressCapsule observer is used.

Returns:
ProgressCapsule status information

interruptWorkerThread

public void interruptWorkerThread()
Interrupts the thread.


getValue

public java.lang.Object getValue()
If an instance of IReturnRunnable is run, this method returns the result of IReturnRunnable.getValue(). Otherwise, null is returned.

Overrides:
getValue in class DialogContentPane
Returns:
the result of IReturnRunnable.getValue()