001 package sale.stdforms; 002 003 import sale.SaleProcess; 004 import sale.ProcessErrorCodes; 005 006 import java.io.Serializable; 007 008 /** 009 * <i>Abstract</i> super class of all strategies that are used with FormSheets. 010 * 011 * <p>Strategies are usually used to parameterize certain responses to user actions in standard FormSheets. 012 * Good examples are the parameterized responses to the buttons in a {@link data.stdforms.TwoTableFormSheet}. 013 * </p> 014 * 015 * <p>This <i>abstract</i> base class knows only about error handling. It uses 016 * {@link ErrorHandler error handling strategies} so that subclasses can easily be adapted to behave 017 * differently in case of an error.</p> 018 * 019 * @author Steffen Zschaler 020 * @version 2.0 18/08/1999 021 * @since v2.0 022 */ 023 public abstract class FormSheetStrategy extends Object implements ProcessErrorCodes, Serializable { 024 025 /** 026 * Interface that defines a error handling strategy for a {@link FormSheetStrategy}. 027 * 028 * @author Steffen Zschaler 029 * @version 2.0 18/08/1999 030 * @since v2.0 031 */ 032 public static interface ErrorHandler extends Serializable, ProcessErrorCodes { 033 /** 034 * Handle an error. 035 * 036 * @param p the process in which the error occurred. 037 * @param nErrorCode an int value describing the error. 038 * 039 * @override Always 040 */ 041 public void error(SaleProcess p, int nErrorCode); 042 } 043 044 /** 045 * The default error handler. This will pass the error on to the process' 046 * {@link sale.SaleProcess#error(int)} method. 047 */ 048 public static final ErrorHandler DEFAULT_ERROR_HANDLER = new ErrorHandler() { 049 /** 050 * ID for serialization. 051 */ 052 private static final long serialVersionUID = -6791233095212221336L; 053 054 public void error(SaleProcess p, int nErrorCode) { 055 p.error(nErrorCode); 056 } 057 }; 058 059 /** 060 * An alternative error handler that will pop up a modeless {@link MsgForm} in the process. 061 */ 062 public static final ErrorHandler MSG_POPUP_ERROR_HANDLER = new ErrorHandler() { 063 /** 064 * ID for serialization. 065 */ 066 private static final long serialVersionUID = -4954693744686937233L; 067 068 public void error(SaleProcess p, int nErrorCode) { 069 MsgForm mfs = new MsgForm("Error", p.getErrorMsg(nErrorCode), false); 070 071 try { 072 p.getContext().popUpFormSheet(p, mfs); 073 } 074 catch (InterruptedException ie) {} 075 } 076 }; 077 078 /** 079 * The current error handler. Defaults to the {@link #DEFAULT_ERROR_HANDLER}. 080 * 081 * @serial 082 */ 083 protected ErrorHandler m_ehErrHandler = DEFAULT_ERROR_HANDLER; 084 085 /** 086 * Set the current error handler. 087 * 088 * @param ehErrHandler the new error handler. 089 * 090 * @override Never 091 */ 092 public void setErrorHandler(ErrorHandler ehErrHandler) { 093 if (ehErrHandler != null) { 094 m_ehErrHandler = ehErrHandler; 095 } else { 096 m_ehErrHandler = DEFAULT_ERROR_HANDLER; 097 } 098 } 099 100 /** 101 * Handle an error. 102 * 103 * <p>This is delegated to the error handler.</p> 104 * 105 * @param p the process in which the error occurred. 106 * @param nErrorCode an int describing the error. 107 * 108 * @override Never 109 */ 110 public void error(SaleProcess p, int nErrorCode) { 111 m_ehErrHandler.error(p, nErrorCode); 112 } 113 }