You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/06/24 00:48:15 UTC
svn commit: r201513 - in /struts/sandbox/trunk/overdrive/Nexus:
Core/Core.csproj Web/BaseGridPage.aspx Web/BaseGridPage.aspx.cs
Web/BaseGridPage.aspx.resx Web/GridViewHelper.cs Web/IGridViewHelper.cs
Web/Web.csproj Web/WebViewHelper.cs
Author: husted
Date: Thu Jun 23 15:48:13 2005
New Revision: 201513
URL: http://svn.apache.org/viewcvs?rev=201513&view=rev
Log:
OVR-17
* Port the IGridViewHelper and BaseGridPage from the prototype, refactoring the multiple commands into multiple helpers.
Added:
struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx
struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.cs
struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.resx
struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Web/IGridViewHelper.cs
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj
struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj?rev=201513&r1=201512&r2=201513&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj Thu Jun 23 15:48:13 2005
@@ -94,6 +94,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "IContextList.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "IKeyValue.cs"
SubType = "Code"
BuildAction = "Compile"
Added: struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx?rev=201513&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx Thu Jun 23 15:48:13 2005
@@ -0,0 +1,19 @@
+<%@ Page language="c#" Codebehind="BaseGridPage.aspx.cs" AutoEventWireup="true" Inherits="Nexus.Web.BaseGridPage" %>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
+
+<html>
+ <head>
+ <title>GridBasePage</title>
+ <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
+ <meta name="CODE_LANGUAGE" Content="C#">
+ <meta name=vs_defaultClientScript content="JavaScript">
+ <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
+ </head>
+ <body>
+
+ <form id="Form1" method="post" runat="server">
+
+ </form>
+
+ </body>
+</html>
Added: struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.cs?rev=201513&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.cs Thu Jun 23 15:48:13 2005
@@ -0,0 +1,346 @@
+using System;
+using System.Collections;
+using System.Web.UI.WebControls;
+using Nexus.Core.Helpers;
+using Nexus.Web;
+using Spring.Web.UI;
+
+namespace Nexus.Web
+{
+ /// <summary>
+ /// Base page for using a IGridViewHelper.
+ /// </summary>
+ public class BaseGridPage : Page
+ {
+
+ #region Helper
+
+ private IGridViewHelper _Helper;
+ /// <summary>
+ /// Obtain dynamic data for the default view.
+ /// </summary>
+ ///
+ public virtual IGridViewHelper Helper
+ {
+ get { return _Helper; }
+ set { _Helper = value; }
+ }
+
+ #endregion
+
+ #region Page Properties
+
+ protected Panel pnlError;
+ protected Label lblError;
+
+ private IViewHelper _Page_Error;
+ /// <summary>
+ /// Set is called when an error occurs; override to provide functionality.
+ /// </summary>
+ protected virtual IViewHelper Page_Error
+ {
+ set {_Page_Error = value;}
+ get {return _Page_Error;}
+ }
+
+ private string _Page_Prompt;
+ /// <summary>
+ /// Set is called when the prompt changes; override to provide functionality.
+ /// </summary>
+ protected virtual string Page_Prompt
+ {
+ set {_Page_Prompt = value;}
+ get {return _Page_Prompt;}
+ }
+ #endregion
+
+
+ #region Messages
+
+ // ISSUE: Move messages to a default store (when available). [WNE-60]
+ // FIXME: Make these text properties on DataGridHelper.
+
+ protected const string msg_ADD_COMMAND = "ADD ITEM";
+ protected const string msg_ADD_SUCCESS = "Item added.";
+ protected const string msg_EDIT_HINT = "Edit description, press update. ";
+ protected const string msg_QUIT_SUCCESS = "Change cancelled. ";
+ protected const string msg_SAVE_SUCCESS = "Changes saved.";
+ protected const string msg_TITLE = "NPDES Enforcement";
+
+ #endregion
+
+ #region Page Properties
+
+ /// <summary>
+ /// Attribute token for List_Criteria.
+ /// </summary>
+ private string LIST_CRITERIA_KEY = "__LIST_CRITERIA_KEY";
+
+ /// <summary>
+ /// Values to use with a query statement.
+ /// </summary>
+ public virtual IDictionary List_Criteria
+ {
+ get
+ {
+ IDictionary criteria = ViewState [LIST_CRITERIA_KEY] as IDictionary;
+ return criteria;
+ }
+ set { ViewState [LIST_CRITERIA_KEY] = value; }
+ }
+
+ /// <summary>
+ /// Attribute token for List_ItemIndex
+ /// </summary>
+ private const string LIST_ITEM_INDEX = "__LIST_ITEM_INDEX";
+
+ /// <summary>
+ /// Current item index, used mainly to signal editing.
+ /// </summary>
+ public virtual int List_ItemIndex
+ {
+ get
+ {
+ object value = ViewState [LIST_ITEM_INDEX];
+ if (value == null) return -1;
+ return (int) value;
+ }
+ set
+ {
+ ViewState [LIST_ITEM_INDEX] = value;
+ if (repList != null) repList.EditItemIndex = value;
+ }
+ }
+
+ /// <summary>
+ /// Attribute token for List_ItemKey.
+ /// </summary>
+ private const string LIST_ITEM_KEY = "__LIST_ITEM_KEY";
+
+ /// <summary>
+ /// The data key for the selected item.
+ /// </summary>
+ public virtual string List_ItemKey
+ {
+ get { return ViewState [LIST_ITEM_KEY] as string; }
+ set { ViewState [LIST_ITEM_KEY] = value; }
+ }
+
+ /// <summary>
+ /// Attribute token for List_Insert.
+ /// </summary>
+ private const string LIST_INSERT_KEY = "__LIST_INSERT_KEY";
+
+ /// <summary>
+ /// Insert mode - are we adding or modifying?
+ /// </summary>
+ public virtual bool List_Insert
+ {
+ get
+ {
+ object value = ViewState [LIST_INSERT_KEY];
+ if (value == null) return false;
+ return (bool) value;
+ }
+ set
+ {
+ ViewState [LIST_INSERT_KEY] = value;
+ cmdListAdd.Visible = !value;
+ }
+ }
+
+ #endregion
+
+ #region Find methods
+
+ protected Panel pnlFind;
+
+ protected virtual bool Find_Submit (string prefix)
+ {
+ IViewHelper h = Helper;
+ h.Read (pnlFind.Controls);
+ List_Criteria = h.Criteria;
+ return List_Load ();
+ }
+
+ #endregion
+
+ #region panel: List
+
+ #region List controls
+
+ protected Panel pnlList;
+ protected DataGrid repList;
+ protected Button cmdListAdd;
+
+ #endregion
+
+ #region List methods
+
+ protected virtual bool List_Load ()
+ {
+ IGridViewHelper h = Helper;
+ bool okay = h.Load (repList, List_Criteria);
+ if (okay)
+ {
+ // Template_Load(h.TitleText,h.HeadingText,h.PromptText);
+ cmdListAdd.Text = msg_ADD_COMMAND;
+ pnlList.Visible = true;
+ }
+ else
+ {
+ pnlList.Visible = false;
+ Page_Error = h;
+ }
+ return okay;
+ }
+
+ protected virtual void List_Item (string commandName, int index)
+ {
+ switch (commandName)
+ {
+ case "Page":
+ // Handled by StepList_PageIndexChanged
+ break;
+ default:
+ {
+ if (List_Insert)
+ // ISSUE: If insert fails, old input is not retained. [WNE-67]
+ List_Add_Load ();
+ else
+ List_Refresh ();
+ break;
+ }
+ }
+ }
+
+ protected virtual void List_Edit (int index)
+ {
+ Page_Prompt = msg_EDIT_HINT;
+ List_ItemIndex = index;
+ List_Refresh ();
+ }
+
+ protected virtual void List_Quit ()
+ {
+ Page_Prompt = msg_QUIT_SUCCESS;
+ List_Insert = false;
+ List_ItemIndex = -1;
+ List_Refresh ();
+ }
+
+ protected virtual void List_Save (string key, ICollection controls)
+ {
+ IGridViewHelper h = Helper;
+ bool okay = h.Save (key, controls);
+ if (okay)
+ {
+ okay = h.List (repList);
+ Page_Prompt = (List_Insert) ? msg_ADD_SUCCESS : msg_SAVE_SUCCESS;
+ List_Insert = false;
+ List_ItemIndex = -1;
+ List_Refresh ();
+ }
+ if (!okay) Page_Error = h;
+ }
+
+ protected virtual void List_Refresh ()
+ {
+ IGridViewHelper h = Helper;
+ h.DataBind (repList);
+ pnlList.Visible = true;
+ }
+
+ protected virtual void List_Add_Load ()
+ {
+ IGridViewHelper h = Helper;
+ bool okay = h.DataInsert (repList);
+ if (okay)
+ {
+ Page_Prompt = msg_EDIT_HINT;
+ List_Insert = true;
+ List_ItemIndex = 0;
+ pnlList.Visible = true;
+ }
+ else Page_Error = h;
+ }
+
+ #endregion
+
+ #region List events
+
+ // init events
+
+ private void List_Init ()
+ {
+ repList.AutoGenerateColumns = false;
+ repList.EditItemIndex = List_ItemIndex;
+ repList.CancelCommand += new DataGridCommandEventHandler (this.List_Quit);
+ repList.EditCommand += new DataGridCommandEventHandler (this.List_Edit);
+ repList.UpdateCommand += new DataGridCommandEventHandler (this.List_Save);
+ repList.ItemCommand += new DataGridCommandEventHandler (this.List_Item);
+ repList.PageIndexChanged += new DataGridPageChangedEventHandler (this.List_PageIndexChanged);
+ cmdListAdd.Click += new EventHandler (this.List_Add);
+ }
+
+ // postback events
+
+ protected void List_Edit (object source, DataGridCommandEventArgs e)
+ {
+ List_Edit (e.Item.ItemIndex);
+ }
+
+ protected void List_Save (object source, DataGridCommandEventArgs e)
+ {
+ IGridViewHelper h = Helper;
+ string key = (List_Insert) ? null : h.GetDataKey (e, repList);
+ ICollection controls = h.GetControls (e, repList);
+ List_Save (key, controls);
+ }
+
+ protected void List_Quit (object source, DataGridCommandEventArgs e)
+ {
+ List_Quit ();
+ }
+
+ protected virtual void List_Add (object sender, EventArgs e)
+ {
+ List_Add_Load ();
+ }
+
+ protected void List_Item (object source, DataGridCommandEventArgs e)
+ {
+ int index = e.Item.ItemIndex;
+ List_Item (e.CommandName, index);
+ }
+
+ protected void List_PageIndexChanged (object sender, DataGridPageChangedEventArgs e)
+ {
+ repList.CurrentPageIndex = e.NewPageIndex;
+ List_Refresh ();
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Page events
+
+ protected void Page_Init ()
+ {
+ List_Init ();
+ bool isFirstView = !IsPostBack;
+ if (isFirstView)
+ pnlList.Visible = false;
+ }
+
+ protected void Page_Load (object sender, EventArgs e)
+ {
+ if (pnlList.Visible)
+ List_Load ();
+ }
+
+ #endregion
+
+ }
+}
Added: struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.resx
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.resx?rev=201513&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.resx (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/BaseGridPage.aspx.resx Thu Jun 23 15:48:13 2005
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<root>
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="ResMimeType">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="Version">
+ <value>1.0.0.0</value>
+ </resheader>
+ <resheader name="Reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="Writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
Added: struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs?rev=201513&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/GridViewHelper.cs Thu Jun 23 15:48:13 2005
@@ -0,0 +1,290 @@
+using System;
+using System.Collections;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using Nexus.Core;
+using Nexus.Core.Helpers;
+using Nexus.Core.Tables;
+using Nexus.Web;
+using Nexus.Web.Helpers;
+
+namespace Nexus
+{
+ /// <summary>
+ /// Summary description for GridViewHelper.
+ /// </summary>
+ public abstract class GridViewHelper : WebViewHelper, IGridViewHelper
+ {
+
+ #region IListViewHelper
+
+ public const string msg_EDIT_TEXT = "EDIT";
+ public const string msg_QUIT_TEXT = "CANCEL";
+ public const string msg_SAVE_TEXT = "SAVE";
+ public const string msg_ITEM_TEXT = "#";
+ public const string msg_ITEM_COMMAND = "cmdItem";
+
+ private IViewHelper _SaveHelper;
+ public virtual IViewHelper SaveHelper
+ {
+ get { return _SaveHelper; }
+ set { _SaveHelper = value; }
+ }
+
+ private IViewHelper _FindHelper;
+ public virtual IViewHelper FindHelper
+ {
+ get { return _FindHelper; }
+ set { _FindHelper = value; }
+ }
+
+ private IViewHelper _ListHelper;
+ public virtual IViewHelper ListHelper
+ {
+ get { return _ListHelper; }
+ set { _ListHelper = value; }
+ }
+
+ private bool _HasItemColumn = false;
+ public virtual bool HasItemColumn
+ {
+ get { return _HasItemColumn; }
+ set { _HasItemColumn = value; }
+ }
+
+ public virtual bool HasEditColumn
+ {
+ get { return (SaveHelper != null); }
+ set { throw new NotImplementedException (); }
+ }
+
+ private bool _HasCriteria = true;
+ public virtual bool HasCriteria
+ {
+ get { return _HasCriteria; }
+ set { _HasCriteria = value; }
+ }
+
+ private string _EditText = msg_EDIT_TEXT;
+ public virtual string EditText
+ {
+ get { return _EditText; }
+ set { _EditText = value; }
+ }
+
+ private string _QuitText = msg_QUIT_TEXT;
+ public virtual string QuitText
+ {
+ get { return _QuitText; }
+ set { _QuitText = value; }
+ }
+
+ private string _SaveText = msg_SAVE_TEXT;
+ public virtual string SaveText
+ {
+ get { return _SaveText; }
+ set { _SaveText = value; }
+ }
+
+ private string _ItemText = msg_ITEM_TEXT;
+ public virtual string ItemText
+ {
+ get { return _ItemText; }
+ set { _ItemText = value; }
+ }
+
+ private string _ItemCommandName = msg_ITEM_COMMAND;
+ public virtual string ItemCommandName
+ {
+ get { return _ItemCommandName as string; }
+ set { _ItemCommandName = value; }
+ }
+
+ private string _DataKeyField;
+ public virtual string DataKeyField
+ {
+ get { return _DataKeyField; }
+ set { _DataKeyField = value; }
+ }
+
+ #endregion
+
+ #region IGridViewHelper
+
+ public virtual bool Load (DataGrid grid, IDictionary criteria)
+ {
+ if (HasCriteria)
+ ExecuteList (grid, criteria);
+ else
+ ExecuteList (grid);
+ return IsNominal;
+ }
+
+ public virtual bool Find (ICollection controls)
+ {
+ FindHelper.Execute ();
+ FindHelper.Bind(controls);
+ return FindHelper.IsNominal ;
+ }
+
+ public virtual bool List (ICollection controls)
+ {
+ ListHelper.ReadExecute (controls);
+ return ListHelper.IsNominal ;
+ }
+
+ public virtual bool List (DataGrid grid)
+ {
+ ListHelper.Execute();
+ bool okay = IsNominal ;
+ if (okay)
+ {
+ DataSource (grid);
+ DataBind (grid);
+ }
+ return okay;
+ }
+
+ public virtual bool Save (string key, ICollection controls)
+ {
+ if (SaveHelper.IsNominal)
+ {
+ SaveHelper.Criteria [DataKeyField] = key;
+ int cols = FieldSet.Count;
+ string[] keys = new string[2 + cols];
+ // reconstruct the standard edit column keys
+ // just as placeholders, really
+ keys [0] = SaveText;
+ keys [1] = QuitText;
+ int index = 2;
+ // append our field names to the array of keys
+ for (int i = 0; i < cols; i++)
+ {
+ IFieldContext fc = FieldSet[i] as IFieldContext;
+ keys [index++] = fc.ID;
+ }
+
+ ReadGridControls (controls, SaveHelper.Criteria, keys, SaveHelper.NullIfEmpty);
+ }
+ return IsNominal ;
+ }
+
+ public virtual int BindItemColumn (DataGrid grid, int i)
+ {
+ ButtonColumn column = new ButtonColumn ();
+ column.ButtonType = ButtonColumnType.PushButton;
+ column.Text = ItemText;
+ column.CommandName = ItemCommandName;
+ grid.Columns.AddAt (i, column);
+ return ++i;
+ }
+
+ public virtual int BindEditColumn (DataGrid grid, int i)
+ {
+ EditCommandColumn column = new EditCommandColumn ();
+ column.ButtonType = ButtonColumnType.PushButton;
+ column.EditText = EditText;
+ column.CancelText = QuitText;
+ column.UpdateText = SaveText;
+ grid.Columns.AddAt (i, column);
+ return ++i;
+ }
+
+ public virtual int BindColumns (DataGrid grid, int i)
+ {
+ grid.DataKeyField = DataKeyField;
+ int colCount = FieldSet.Count;
+ for (int c = 0; c < colCount; c++)
+ {
+ IFieldContext fc = FieldSet [c] as IFieldContext;
+ string column = fc.ID;
+ string label = fc.Label;
+ if ((label==null) || (label.Length==0)) label = column;
+ i = BindColumn (grid, i, label, column);
+ }
+ return i;
+ }
+
+ public virtual void DataSource (DataGrid grid)
+ {
+ IList list = ListHelper.Outcome;
+ grid.DataSource = list;
+ }
+
+ public abstract IContextList NewContextList ();
+
+ public virtual bool DataInsert (DataGrid grid)
+ {
+ // Fake a blank row
+ IContextList list = NewContextList ();
+ list.Insert (String.Empty);
+ ListHelper.Criteria [ListHelper.Command.ID] = list;
+ grid.DataSource = list;
+ grid.CurrentPageIndex = 0;
+ grid.EditItemIndex = 0;
+ DataBind (grid);
+ return IsNominal ;
+ }
+
+ public virtual void DataBind (DataGrid grid)
+ {
+ grid.DataBind ();
+ }
+
+ private bool bind = true;
+
+ public virtual void BindGrid (DataGrid grid)
+ {
+ // Only bind columns once
+ // WARNING: Won't work with a singleton
+ if (bind)
+ {
+ bind = false;
+ int i = 0;
+ if (HasEditColumn) i = BindEditColumn (grid, i);
+ if (HasItemColumn) i = BindItemColumn (grid, i);
+ BindColumns (grid, i);
+
+ }
+ DataSource (grid);
+ DataBind (grid);
+ }
+
+ public virtual bool ExecuteList (DataGrid grid)
+ {
+ ListHelper.Execute();
+ bool okay = ListHelper.IsNominal ;
+ if (okay) BindGrid (grid);
+ return okay;
+ }
+
+ public virtual bool ExecuteList (DataGrid grid, IDictionary criteria)
+ {
+ ListHelper.ReadExecute(criteria);
+ bool okay = ListHelper.IsNominal ;
+ if (okay) BindGrid (grid);
+ return okay;
+ }
+
+ public string GetDataKey (DataGridCommandEventArgs e, DataGrid grid)
+ {
+ int index = grid.EditItemIndex;
+ string key = grid.DataKeys [index] as string;
+ return key;
+ }
+
+ public ICollection GetControls (DataGridCommandEventArgs e, DataGrid grid)
+ {
+ ControlCollection controls = new ControlCollection (grid);
+ foreach (TableCell t in e.Item.Cells)
+ {
+ for (int i = 0; i < t.Controls.Count; i++)
+ controls.Add (t.Controls [i]);
+ }
+ return controls;
+ }
+
+ #endregion
+
+ }
+}
Added: struts/sandbox/trunk/overdrive/Nexus/Web/IGridViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/IGridViewHelper.cs?rev=201513&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/IGridViewHelper.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/IGridViewHelper.cs Thu Jun 23 15:48:13 2005
@@ -0,0 +1,178 @@
+using System.Collections;
+using System.Web.UI.WebControls;
+using Nexus.Core.Helpers;
+
+namespace Nexus.Web
+{
+ /// <summary>
+ /// Helper for controls that display a list, including an editable list.
+ /// </summary>
+ public interface IGridViewHelper : IViewHelper
+ {
+ #region IListViewHelper
+
+ IViewHelper FindHelper { get; set; }
+ IViewHelper ListHelper { get; set; }
+ IViewHelper SaveHelper { get; set; }
+
+ string EditText { get; set; }
+ string QuitText { get; set; }
+ string SaveText { get; set; }
+
+ string ItemText { get; set; }
+ string ItemCommandName { get; set; }
+
+ /// <summary>
+ /// Indicate whether this instance has a standard item command [false].
+ /// </summary>
+ bool HasItemColumn { get; set; }
+
+ /// <summary>
+ /// Indicate whether this instance has standard edit commands.
+ /// </summary>
+ /// <remarks><p>
+ /// By default, this property can return true if a SaveCommandID is present.
+ /// Otherwise false. If the standard heuristic is followed, then the
+ /// implementation may throw a NotImplementedException on an attempt to set
+ /// this property manually.
+ /// </p></remarks>
+ bool HasEditColumn { get; set; }
+
+ /// <summary>
+ /// Indicate whether the business logic expects values to be passed in the context [true].
+ /// </summary>
+ /// <remarks>
+ /// Commands that do not use search criteria can set this property to false.
+ /// </remarks>
+ bool HasCriteria { get; set; }
+
+ string DataKeyField { get; set; }
+
+ #endregion
+
+ #region IGridViewHelper
+
+ /// <summary>
+ /// Ready grid for initial display of data.
+ /// </summary>
+ /// <param name="grid">The instant DataGrid.</param>
+ /// <param name="criteria">Search criteria, if any.</param>
+ /// <returns>True if no errors were detected.</returns>
+ bool Load (DataGrid grid, IDictionary criteria);
+
+ /// <summary>
+ /// Execute find command (enter search criteria).
+ /// </summary>
+ /// <param name="controls">The list of controls to which to bind values.</param>
+ bool Find (ICollection controls);
+
+ /// <summary>
+ /// Execute list command (filter records based on search criteria).
+ /// </summary>
+ /// <param name="controls">The list of controls from which to obtain the values to filter.</param>
+ bool List (ICollection controls);
+
+ /// <summary>
+ /// Execute list command (filter records based on search criteria).
+ /// </summary>
+ /// <param name="grid">The instant datagrid.</param>
+ /// <returns>True if no errors were detected.</returns>
+ bool List (DataGrid grid);
+
+ /// <summary>
+ /// Execute save command for the given key, using the given control collection.
+ /// </summary>
+ /// <param name="key">The primary key for the entity being saved.</param>
+ /// <param name="controls">The list of controls from which to obtain the values to save.</param>
+ bool Save (string key, ICollection controls);
+
+ /// <summary>
+ /// Create a standard datagrid button column.
+ /// </summary>
+ /// <param name="grid">Our datagrid instance</param>
+ /// <param name="i">The first column to use, usually 0</param>
+ /// <returns>The next column to use, usually 1</returns>
+ int BindItemColumn (DataGrid grid, int i);
+
+ /// <summary>
+ /// Create a standard datagrid edit column.
+ /// </summary>
+ /// <param name="grid">Our datagrid instance</param>
+ /// <param name="i">The first column to use, usually 0</param>
+ /// <returns>The next column to use, usually 1</returns>
+ int BindEditColumn (DataGrid grid, int i);
+
+ /// <summary>
+ /// Bind whatever columns need to be displayed for this data type.
+ /// </summary>
+ /// <param name="grid">Our datagrid instance</param>
+ /// <param name="i">The first column to use, usually 1</param>
+ /// <returns>The next column to use</returns>
+ int BindColumns (DataGrid grid, int i);
+
+ /// <summary>
+ /// Use the Listcommand to obtain a datasource.
+ /// </summary>
+ /// <comment>
+ /// Usually called just before DataBind.
+ /// </comment>
+ /// <param name="grid">Our datagrid instance</param>
+ void DataSource (DataGrid grid);
+
+ /// <summary>
+ /// Use the DataFields property to create a blank row.
+ /// </summary>
+ /// <param name="grid">Our datagrid instance</param>
+ bool DataInsert (DataGrid grid);
+
+ /// <summary>
+ /// Convenience method to bind our datagrid.
+ /// </summary>
+ /// <comment>
+ /// Usually called just after DataSource.
+ /// </comment>
+ /// <param name="grid">Our datagrid instance</param>
+ void DataBind (DataGrid grid);
+
+ /// <summary>
+ /// Bind the columns and datasource to the DataGrid.
+ /// </summary>
+ /// <param name="grid">A DataGrid instance</param>
+ void BindGrid (DataGrid grid);
+
+ /// <summary>
+ /// Run ExecuteContext using the ListCommand and bind the result.
+ /// </summary>
+ /// <param name="grid">A DataGrid instance</param>
+ /// <returns>True if the Context is nominal.</returns>
+ bool ExecuteList (DataGrid grid);
+
+ /// <summary>
+ /// Run Execute using the ListCommand and supplied criteria and bind the result.
+ /// </summary>
+ /// <param name="grid">A DataGrid instance</param>
+ /// <param name="criteria">Criteria values</param>
+ /// <returns>True if the Context is nominal.</returns>
+ bool ExecuteList (DataGrid grid, IDictionary criteria);
+
+ /// <summary>
+ /// Obtain the DataKey value from a DataGrid.
+ /// </summary>
+ /// <param name="e">Current event</param>
+ /// <param name="grid">The DataGrid</param>
+ /// <returns>The DataKey Value as a string</returns>
+ string GetDataKey (DataGridCommandEventArgs e, DataGrid grid);
+
+ /// <summary>
+ /// Create a collection of the controls in the current DataGrid cell.
+ /// </summary>
+ /// <param name="e">Current event</param>
+ /// <param name="grid">The DataGrid</param>
+ /// <returns>Collection of controls in the current DataGrid cell</returns>
+ ICollection GetControls (DataGridCommandEventArgs e, DataGrid grid);
+
+ #endregion
+
+
+ }
+}
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj?rev=201513&r1=201512&r2=201513&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj Thu Jun 23 15:48:13 2005
@@ -99,6 +99,16 @@
AssemblyName = "Agility.Core"
HintPath = "..\..\Agility\Core\bin\Debug\Agility.Core.dll"
/>
+ <Reference
+ Name = "Spring.Web"
+ AssemblyName = "Spring.Web"
+ HintPath = "..\..\SpringNet.bin\Spring.Web.dll"
+ />
+ <Reference
+ Name = "Spring.Core"
+ AssemblyName = "Spring.Core"
+ HintPath = "..\..\SpringNet.bin\Spring.Core.dll"
+ />
</References>
</Build>
<Files>
@@ -109,6 +119,22 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "BaseGridPage.aspx"
+ SubType = "Form"
+ BuildAction = "Content"
+ />
+ <File
+ RelPath = "BaseGridPage.aspx.cs"
+ DependentUpon = "BaseGridPage.aspx"
+ SubType = "ASPXCodeBehind"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "BaseGridPage.aspx.resx"
+ DependentUpon = "BaseGridPage.aspx.cs"
+ BuildAction = "EmbeddedResource"
+ />
+ <File
RelPath = "Global.asax"
SubType = "Component"
BuildAction = "Content"
@@ -123,6 +149,16 @@
RelPath = "Global.asax.resx"
DependentUpon = "Global.asax.cs"
BuildAction = "EmbeddedResource"
+ />
+ <File
+ RelPath = "GridViewHelper.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "IGridViewHelper.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
/>
<File
RelPath = "Web.config"
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs?rev=201513&r1=201512&r2=201513&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs Thu Jun 23 15:48:13 2005
@@ -69,7 +69,7 @@
#region Bind methods
- private void BindControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix)
+ public void BindControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix)
{
foreach (Control t in controls)
{
@@ -111,7 +111,7 @@
}
}
- private void BindListControl (ListControl control, IList list)
+ protected void BindListControl (ListControl control, IList list)
{
bool insertKey = ((list != null) && (!list.Contains (String.Empty)) && (!list.Contains (SelectItemPrompt)));
if (insertKey) list.Insert (0, new KeyValue (String.Empty, SelectItemPrompt));
@@ -126,7 +126,7 @@
/// <param name="list">List of TextKey objects.</param>
/// <param name="value">Value to select, or null if nothing is selected.</param>
///
- private void BindListControl (ListControl control, IList list, string value)
+ protected void BindListControl (ListControl control, IList list, string value)
{
control.DataTextField = "Value";
control.DataValueField = "Key";
@@ -139,7 +139,8 @@
#region Read method
- private void ReadControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix, bool nullIfEmpty)
+ // See also ReadGridControls in Extra Utilities
+ public void ReadControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix, bool nullIfEmpty)
{
foreach (Control t in controls)
{
@@ -183,17 +184,17 @@
#region Control utilities
- private bool IsCheckBox (Control control)
+ protected bool IsCheckBox (Control control)
{
return (typeof (CheckBox).Equals (control.GetType ()));
}
- private bool IsLabel (Control control)
+ protected bool IsLabel (Control control)
{
return (typeof (Label).Equals (control.GetType ()));
}
- private bool IsListControl (Control control)
+ protected bool IsListControl (Control control)
{
bool isList = false;
Type type = control.GetType ();
@@ -205,12 +206,12 @@
return isList;
}
- private bool IsRadioButton (Control control)
+ protected bool IsRadioButton (Control control)
{
return (typeof (RadioButton).Equals (control.GetType ()));
}
- private bool IsTextBox (Control control)
+ protected bool IsTextBox (Control control)
{
return (typeof (TextBox).Equals (control.GetType ()));
}
@@ -361,5 +362,66 @@
}
#endregion
+
+ #region Extra utilities (for GridViewHelper)
+
+ protected void ReadGridControls (ICollection controls, IDictionary dictionary, string[] keys, bool nullIfEmpty)
+ {
+ int i = 0;
+ foreach (Control t in controls)
+ {
+ string key = keys [i];
+ if (IsTextBox (t))
+ {
+ TextBox x = (TextBox) t;
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.Text) : x.Text;
+ dictionary.Add (key, value);
+ }
+ if (IsLabel (t))
+ {
+ Label x = (Label) t;
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.Text) : x.Text;
+ dictionary.Add (key, value);
+ }
+ if (IsListControl (t))
+ {
+ ListControl x = (ListControl) t;
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.SelectedValue) : x.SelectedValue;
+ dictionary.Add (key, value);
+ }
+ if (IsCheckBox (t))
+ {
+ CheckBox x = (CheckBox) t;
+ string value = (x.Checked) ? key : null;
+ dictionary.Add (key, value);
+ }
+ if (IsRadioButton (t))
+ {
+ RadioButton x = (RadioButton) t;
+ string value = (x.Checked) ? key : null;
+ dictionary.Add (key, value);
+ }
+ i++;
+ }
+ }
+
+ protected int BindColumn (DataGrid grid, int pos, string headerText, string dataField, string sortExpression, string dataFormat)
+ {
+ BoundColumn column = new BoundColumn ();
+ column.HeaderText = headerText;
+ column.DataField = dataField;
+ column.SortExpression = sortExpression; // See DataGridColumn.SortExpression Property
+ column.DataFormatString = dataFormat; // See Formatting Types in .NET Dev Guide
+ grid.Columns.AddAt (pos, column);
+ return pos + 1;
+ }
+
+ protected int BindColumn (DataGrid grid, int pos, string headerText, string dataField)
+ {
+ return BindColumn (grid, pos, headerText, dataField, String.Empty, String.Empty);
+ }
+
+ #endregion
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org