com.ccg.swing
Class DirtyChecker

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by com.ccg.swing.DirtyChecker
All Implemented Interfaces:
WindowFocusListener, WindowListener, WindowStateListener, EventListener

public class DirtyChecker
extends WindowAdapter

An attempt to provide a API for the purpose of letting the user know that not everything has been saved before allowing the user to exit.

Since:
1.0
Version:
$Revision: 1.3 $
Author:
$Author: pkb $

Constructor Summary
DirtyChecker(RStockDialogs rd, boolean allowExit)
          Construct the object and indicate whether it should allow exit.
 
Method Summary
 void addDirtyObject(DirtySaver val)
          Set a object that can be saved to the dirty list.
 boolean attemptSave()
          Attempt to save the state of the system.
 void clearFailedSave()
          Clear any internally error conditions set by last save attempt.
 Exception getFailedReason(Object o)
          Get reason that the last save attempt failed.
 Enumeration getFailedSave()
          Get set of dirty objects that failed when we tried to save them.
 boolean isDirty()
          Does something need to be saved, or has something failed to save?
 boolean isExitAllowed()
          Are we allowed to exit the JVM on the window closing event?
 boolean isOkToClear()
          Checks to see if its OK to clear the current state of the object.
 void removeDirtyObject(DirtySaver ds)
          Get a object that can be saved to the dirty list.
 void setExitAllowed(boolean val)
          Set whether we are allowed to exit the JVM on the window closing event.
 void windowClosing(WindowEvent e)
           
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirtyChecker

public DirtyChecker(RStockDialogs rd,
                    boolean allowExit)
Construct the object and indicate whether it should allow exit.

Since:
1.0
Method Detail

windowClosing

public void windowClosing(WindowEvent e)
Specified by:
windowClosing in interface WindowListener
Overrides:
windowClosing in class WindowAdapter

setExitAllowed

public void setExitAllowed(boolean val)
Set whether we are allowed to exit the JVM on the window closing event.

Parameters:
val - New boolean value to assign. see #getExitAllowed

isExitAllowed

public boolean isExitAllowed()
Are we allowed to exit the JVM on the window closing event?

Returns:
Current boolean value assigned. see #setExitAllowed

addDirtyObject

public void addDirtyObject(DirtySaver val)
Set a object that can be saved to the dirty list.

Parameters:
val - New DirtySaver value to assign.
See Also:
removeDirtyObject(com.ccg.swing.DirtySaver)

removeDirtyObject

public void removeDirtyObject(DirtySaver ds)
Get a object that can be saved to the dirty list.

See Also:
addDirtyObject(com.ccg.swing.DirtySaver)

isOkToClear

public boolean isOkToClear()
Checks to see if its OK to clear the current state of the object.

This method can be used to determine if its OK to clear the current state of the object. If the object is "dirty", the user will be presented a dialog box asking whether they want to:

This method then returns true if it's OK to clear the current state of the system.

For example, when a "File|New" action is chosen by the user, this method is invoked to make sure that its OK to clear the current state prior to creating a new one.

Returns:
true if it is OK to clear the state of the object, false if not.
Since:
1.0 #see #isDirty

attemptSave

public boolean attemptSave()
Attempt to save the state of the system.

This method attempts to save the state of all of the dirty objects (hopeully taking us out of the "dirty" state).

Returns:
true if all of the "dirty" objects were successfully saved. false if there are still dirty objects remaining.
Since:
1.0

getFailedSave

public Enumeration getFailedSave()
Get set of dirty objects that failed when we tried to save them.

Returns:
A Enumeration of DirtySaver objects that failed to save the last time we tried to save them.
Since:
1.0

getFailedReason

public Exception getFailedReason(Object o)
Get reason that the last save attempt failed.

Returns:
The exception (or null if there wasn't one) which caused the save to fail.
Since:
1.0
See Also:
attemptSave()

clearFailedSave

public void clearFailedSave()
Clear any internally error conditions set by last save attempt.

Since:
1.0
See Also:
attemptSave()

isDirty

public boolean isDirty()
Does something need to be saved, or has something failed to save?

You can use this method to determine if your application is "dirty" that means that something needs to be saved, OR something which we tried to save failed. You can use the attemptSave() method to try and "save" all of the dirty objects.

You can use the getFailedSave() method if you want to see what objects failed to "save" themselves (and why), or you can use the clearFailedSave() if you don't care about the objects that failed to save themselves.

Returns:
Current boolean value assigned. see #attemptSave


Copyright 1998-1998-2006 null. All Rights Reserved.