Author: husted Date: Fri Jun 10 13:53:06 2005 New Revision: 190017 URL: http://svn.apache.org/viewcvs?rev=190017&view=rev Log: OVR-10 * Define IViewHelper interface and begin implementation.
Removed: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/EditHelper.cs struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IEditHelper.cs struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IListHelper.cs struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ListHelper.cs Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs?rev=190017&r1=190016&r2=190017&view=diff ============================================================================== --- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs (original) +++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/IViewHelper.cs Fri Jun 10 13:53:06 2005 @@ -14,27 +14,74 @@ * limitations under the License. */ using System; -using Agility.Core; +using System.Collections; +using Nexus.Core.Tables; namespace Nexus.Core.Helpers { /// <summary> - /// An encapsulation of the IRequestContext that hides some methods and exposes others in a more convenient way. + /// A facade for use by a code-behind to simplify access to the IRequestContext and IRequestCommand. /// </summary> - /// <remarks> - /// An IViewHelper implementation may also act as a "front controller" to ensure routine tasks are carried out. - /// </remarks> + /// <remarks><p> + /// The controller for a helper may also act as a "front controller" to ensure routine tasks are carried out. + /// These tasks can include input validation, data conversion, text formatting, command logging, and so forth. + /// </p></remarks> public interface IViewHelper { + + /// <summary> + /// Invoke the helper's command and bind the output to controls in the given collection. + /// </summary> + /// <remarks><p> + /// Most code behinds will call either ExecuteBind or ReadExecute by passing in the collection of controls from a panel control. + /// </p></remarks> + /// <param name="controls">Collection of controls to populate.</param> + /// + void ExecuteBind (ICollection controls); + + + /// <summary> + /// Read input from the controls in the given collection, and invoke the helper's command. + /// </summary> + /// <param name="controls">Collection of controls to populate.</param> + /// <remarks><p> + /// Most code behinds will call either ExecuteBind or ReadExecute by passing in the collection of controls from a panel control. + /// </p></remarks> + /// + void ReadExecute (ICollection controls); + + /// <summary> - /// The IRequestContext we are processing. + /// Bind the output of the helper's command to controls in the given collection. /// </summary> - IRequestContext Context { get; set; } + /// <param name="controls">Collection of controls to populate.</param> + /// + void Bind (ICollection controls); + /// <summary> + /// Invoke the helper's command. + /// </summary> /// + void Execute(); + + + /// <summary> + /// Read input from the controls in the given collection. /// </summary> - IContext Errors { get; } + /// <param name="controls">Collection of controls to populate.</param> + /// + void Read (ICollection controls); + + + // ---- + + /// <summary> + /// A list of error messages, keyed by the field causing the error, or to a magic global key. + /// </summary> + /// + IDictionary Errors { get; } + /// <summary> /// Return true if errors are queued. @@ -42,8 +89,9 @@ /// <returns>True if errors are queued.</returns> bool HasErrors { get; } + /// <summary> - /// + /// An Exception, if thrown. /// </summary> Exception Fault { get; } @@ -53,11 +101,123 @@ /// <returns>True if an exception is caught.</returns> bool HasFault { get; } + /// <summary> /// Return true if there are no errors or exception pending. /// </summary> /// <returns>True if all is well.</returns> bool IsNominal { get; } + + + /// <summary> + /// A list of text messages, keyed by a field or other identifier, or to a magic global key. + /// </summary> + /// + IDictionary Messages { get; } + + + /// <summary> + /// Return true if Messages are queued. + /// </summary> + /// <returns>True if Messages are queued.</returns> + bool HasMessages { get; } + + + // ---- + + /// <summary> + /// Set of IFieldContext definitions available to the application, usually set by the controller. + /// </summary> + /// <remarks><p> + /// The FieldTable can be used to convert display strings to native types on input, + /// and from native types to display strings on output. + /// The FieldTable can also be used to generate UI controls. + /// </p></remarks> + IFieldTable FieldTable { get;} + + + /// <summary> + /// Set of IFieldContext definitions to be used with this helper, usually set by dependency injection. + /// </summary> + /// <remarks><p> + /// Some helpers generate DataGrids or DataForms based on the FieldDefinitions + /// </p></remarks> + IList FieldSet {get;} + + /* + // TODO: + string Text(string key); + string TextIndex {get;} + ITextTable TextTable {get;} + */ + + + // ---- + + /// <summary> + /// Prefix to trim from the id of a control during Read and Bind. + /// </summary> + /// <remarks><p> + /// The Prefix is needed when a single page uses a control more than once + /// often in separate panels. + /// </p></remarks> + /// + string Prefix { get; set; } + + + /// <summary> + /// Suffix to truncate from a list control id in order to set a corresponding value field ["_list"]. + /// </summary> + /// <remark><p> + /// When processing a single-value list control, if the id ends with the list suffix, + /// the suffix is removed, and a field with the remaining name is set to the selected item value. + /// </p><P> + /// So, the selected item from a list control with the id "facility_key_list" will be + /// set to a field named "facility_key". + /// </P></remark> + /// + string ListSuffix {get; set;} + + /* + // TODO: + string AlertSuffix {get; set} + string HintSuffix {get; set} + string LabelSuffix {get; set} + */ + + + /// <summary> + /// If a control value is an empty string, set the value to null instead [TRUE]. + /// </summary> + /// + bool NullIfEmpty {get; set;} + + + /// <summary> + /// String token to insert as item 0 to a list controls ["--v---"]. + /// </summary> + /// <remarks><p> + /// To disable feature, set to a null string. + /// </p></remarks> + /// + string SelectItemPrompt {get; set;} + + + // ---- + + /// <summary> + /// The controller for this helper, usually set by dependency injection. + /// </summary> + /// + IController Controller { get; set; } + + + /// <summary> + /// The command (or chain of commands) for this helper, usually set by dependency injection. + /// </summary> + /// + IRequestCommand Command { get; set; } + } } Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs?rev=190017&r1=190016&r2=190017&view=diff ============================================================================== --- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs (original) +++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Fri Jun 10 13:53:06 2005 @@ -15,104 +15,138 @@ */ using System; using System.Collections; -using System.Text; -using Agility.Core; +using Nexus.Core.Tables; namespace Nexus.Core.Helpers { /// <summary> /// Standard implementation of IViewHelper. /// </summary> - public class ViewHelper : IViewHelper + public abstract class ViewHelper : IViewHelper { - public ViewHelper () - { - Context = new RequestContext (); - } + #region private - /// <summary> - /// Build a set of error messages using HTML markup. - /// </summary> - /// <param name="errors">A list of error messages</param> - /// <returns>HTML markup presenting the errors.</returns> - public static string HtmlErrorList (IList errors) + private IRequestContext _Context; + public IRequestContext Context { - StringBuilder sb = new StringBuilder ("<ul>"); - foreach (object o in errors) + get { - sb.Append ("<li>"); - sb.Append (o.ToString ()); - sb.Append ("</li>"); + if (_Context==null) + { + _Context = Controller.GetContext(Command); + } + return _Context; } - sb.Append ("</ul>"); - - return sb.ToString (); } - /// <summary> - /// Build a set error messages using HTML markup. - /// </summary> - /// <param name="fault">An exception instance, if any</param> - /// <param name="store">A context listing errors, if any</param> - /// <returns>HTML markup presenting the errors.</returns> - public static string HtmlErrorBuilder (Exception fault, IContext store) - { - string errorMarkup = null; - if (store != null) - { - IList errors = new ArrayList (); - ICollection keys = store.Keys; - foreach (string key in keys) - { - IList sublist = store [key] as IList; - foreach (string message in sublist) errors.Add (message); - } - errorMarkup = HtmlErrorList (errors); - } + #endregion - if (errorMarkup != null) - { - StringBuilder sb = new StringBuilder (errorMarkup); - return sb.ToString (); - } - return null; - } + #region Read and Bind - public static string HtmlErrorBuilder (IViewHelper helper) - { - return HtmlErrorBuilder (helper.Fault, helper.Errors); - } + public abstract void ExecuteBind (ICollection controls); - private IRequestContext _Context; - public IRequestContext Context + public abstract void ReadExecute (ICollection controls); + + public abstract void Bind (ICollection controls); + + public abstract void Read (ICollection controls); + + public void Execute () { - get { return _Context; } - set { _Context = value; } + Controller.ExecuteView(Context); } - public IContext Errors + #endregion + + #region Errors ... + + public IDictionary Errors { - get { return Context [Tokens.ERRORS] as IContext; } + get { return Context.Errors; } } public bool HasErrors { - get { return Context.Contains (Tokens.ERRORS); } + get { return Context.HasErrors; } } public Exception Fault { - get { return Context [Tokens.FAULT] as Exception; } + get { return Context.Fault; } } public bool HasFault { - get { return Context.Contains (Tokens.FAULT); } + get { return Context.HasFault; } } public bool IsNominal { get { return (!HasErrors && !HasFault); } } + + public IDictionary Messages + { + get { return Context.Messages; } + } + + public bool HasMessages + { + get { return Context.HasMessages; } + } + + #endregion + + #region Tables + + public IFieldTable FieldTable + { + get { return Context.FieldTable; } + } + + public IList FieldSet + { + get { return Context.FieldSet; } + } + + public string Prefix + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + + public string ListSuffix + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + + #endregion + + #region Properties + + public bool NullIfEmpty + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + public string SelectItemPrompt + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + public IController Controller + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + public IRequestCommand Command + { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + + } + + #endregion } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]