Author: husted
Date: Thu Nov  3 12:03:13 2005
New Revision: 330619

URL: http://svn.apache.org/viewcvs?rev=330619&view=rev
Log:
OVR-24
* Add Letter Filter control.

Added:
    struts/sandbox/trunk/overdrive/Nexus/Web/Controls/
    struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx
    struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.cs
    struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.resx
Modified:
    struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj

Added: struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx?rev=330619&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx Thu Nov 
 3 12:03:13 2005
@@ -0,0 +1,10 @@
+<%@ Control Language="c#" AutoEventWireup="false" 
Codebehind="LetterFilter.ascx.cs" Inherits="Nexus.Web.Controls.LetterFilter" 
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
+<asp:repeater id="letters" runat="server">
+       <itemtemplate>
+               <asp:linkbutton id="letter" runat="server" 
+                       commandname="filter" 
+                       commandargument='<%# DataBinder.Eval(Container, 
"DataItem.Letter")%>' >
+                       <%# DataBinder.Eval(Container, "DataItem.Letter")%>
+               </asp:linkbutton>
+       </itemtemplate>
+</asp:repeater>
\ No newline at end of file

Added: struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.cs
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.cs?rev=330619&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.cs 
(added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.cs Thu 
Nov  3 12:03:13 2005
@@ -0,0 +1,288 @@
+using System;
+using System.Collections;
+using System.Data;
+using System.Web.UI.WebControls;
+using Nexus.Web;
+using WQD.Core.Controls;
+
+namespace Nexus.Web.Controls
+{
+       /// <summary>
+       /// Display a list of letters, one of which can be selected at a time, 
+       /// so a client control can filter a list of entries.
+       /// </summary>
+       /// <remarks><p>
+       /// Adapted from http://www.codeproject.com/aspnet/LetterBasedPaging.asp
+       /// </p></remarks>
+       /// 
+       public class LetterFilter : FindControl
+       {
+               
+               /// <summary>
+               /// Document token representing match all entries.
+               /// </summary>
+               public const string ALL = "[*]";
+
+               /// <summary>
+               /// Document the attribute name for the initial letter by which 
to filter.
+               /// </summary>
+               public const string ITEM_INITIAL = "initial";
+               /// <summary>
+
+               /// Provide a key under which to store the selected letter in 
ViewState.
+               /// </summary>
+               /// 
+               public const string LETTER_KEY = "_Letter";
+                                       
+               /// <summary>
+               /// Document the wildcard character used by SQL queries.
+               /// </summary>
+               public const string WILDCARD = "%";
+
+               /// <summary>
+               /// Signal that input is ready to submit, 
+               /// passing the ITEM_INTIIAL value as FindArgs.
+               /// </summary>
+               /// 
+               public event EventHandler View_Filter;
+
+               /// <summary>
+               /// List the letters that can selected.
+               /// </summary>
+               /// 
+               protected Repeater letters;
+
+               /// <summary>
+               /// Provide a private field to cache the LetterFilter property.
+               /// </summary>
+               /// 
+               private string _Letter;
+
+               /// <summary>
+               /// Store the current letter by which client is to filter.
+               /// </summary>
+               /// <remarks><p>
+               /// The value is stored by ID in ViewState 
+               /// so that more than one LetterFilter can be used by the same 
parent control.
+               /// </p></remarks>
+               /// 
+               public string Letter
+               {
+                       get
+                       {
+                               if (_Letter == null) _Letter = ViewState[ID + 
LETTER_KEY] as string;
+                               return _Letter;
+                       }
+                       set
+                       {
+                               _Letter = value;
+                               ViewState[ID + LETTER_KEY] = value;
+                               // Bind the datasource so that Letter change is 
reflected
+                               letters.DataBind();
+                       }
+               }
+
+               /// <summary>
+               /// Provide a key under which to store the DataTable in 
ViewState.
+               /// </summary>
+               ///             
+               private string LETTER_TABLE_KEY = "_LetterData";
+
+               /// <summary>
+               /// Provide a private field to cache the LetterTable property.
+               /// </summary>
+               ///             
+               private DataTable _LetterTable;
+
+               /// <summary>
+               /// Store the DataTable containing our letters. 
+               /// </summary>
+               ///             
+               public DataTable LetterTable
+               {
+                       get
+                       {
+                               if (_LetterTable == null) _LetterTable = 
ViewState[ID + LETTER_TABLE_KEY] as DataTable;
+                               return _LetterTable;
+                       }
+                       set
+                       {
+                               _LetterTable = value;
+                               ViewState[ID + LETTER_TABLE_KEY] = value;
+                       }
+
+               }
+
+               /// <summary>
+               /// Provide the name of the item command to fire when the 
linkbutton for a letter is clicked.
+               /// </summary>
+               ///             
+               protected const string FILTER_CMD = "filter";
+
+               /// <summary>
+               /// Identify the linkbutton that will contain the letter in 
each repeater cell.
+               /// </summary>
+               /// 
+               protected const string LETTER_ID = "letter";
+
+               /// <summary>
+               /// Identify the column in our DataTable that holds the 
letters. 
+               /// </summary>
+               /// 
+               protected const string LETTER_COLUMN = "Letter";
+
+               /// <summary>
+               /// Handle the "Filter" by new letter command, 
+               /// passing NULL if "ALL" is selected.
+               /// </summary>
+               /// 
+               protected void letters_ItemCommand(object source, 
RepeaterCommandEventArgs e)
+               {
+                       // Handle the "Filter" new record command
+                       if (e.CommandName == FILTER_CMD)
+                       {
+                               // Set the new Letter selection
+                               Letter = (string) e.CommandArgument;
+
+                               // Raise the "Filter" event so that client can 
update its list. 
+                               if (View_Filter != null)
+                               {
+                                       string letter = Letter;
+                                       if (ALL.Equals(letter)) letter = null;
+                                       string letter2 = letter + WILDCARD;
+                                       IDictionary criteria = new Hashtable(1);
+                                       criteria.Add(ITEM_INITIAL,letter2);
+                                       FindArgs a = new FindArgs(e, criteria);
+                                       View_Filter(source, a);
+                               }
+                       }
+               }
+
+               /// <summary>
+               /// Called when an item in the letters repeater control is data 
bound to a source.
+               /// </summary>
+               protected void letters_ItemDataBound(object source, 
RepeaterItemEventArgs e)
+               {
+                       // Retrieve the row of data that is to be bound to the 
repeater
+                       DataRowView data = (DataRowView) e.Item.DataItem;
+
+                       // If the letter we are binding to the current repeater 
control item is
+                       //  the same as the one currently selected, than 
disable it so the user
+                       //  knows which one was selected.
+                       if ((string) data[0] == Letter)
+                       {
+                               LinkButton cmd = (LinkButton) 
e.Item.FindControl(LETTER_ID);
+                               cmd.Enabled = false;
+                       }
+               }
+
+
+               /// <summary>
+               /// Create a new DataTable from the list of letters provided, 
+               /// and store a referance to the newly create data table for 
use on post back.
+               /// </summary>
+               /// <param name="input">List of letters to present as 
commands</param>
+               private void LetterTable_Init(IList input)
+               {               
+                       DataTable dt = new DataTable();
+                       dt.Columns.Add(new DataColumn(LETTER_COLUMN, typeof 
(string)));
+
+                       for (int i = 0; i < input.Count; i++)
+                       {
+                               DataRow dr = dt.NewRow();
+                               dr[0] = input[i];
+                               dt.Rows.Add(dr);
+                       }
+                       
+                       LetterTable = dt;
+               }
+
+               /// <summary>
+               /// Bind the letters array to the repeater control, 
+               /// set the default letter, 
+               /// so that the letters are ready to present.
+               /// </summary>
+               /// 
+               public bool Open()
+               {
+                       if (LetterTable == null)
+                       {
+                               // Default to A-Z
+                               string[] input = {
+                                                                        "A", 
"B", "C", "D", "E", "F", "G", "H", "I", "J",
+                                                                        "K", 
"L", "M", "N", "O", "P", "Q", "R", "S", "T",
+                                                                        "U", 
"V", "W", "X", "Y", "Z", ALL
+                                                                };
+
+                               LetterTable_Init(input);
+                       }
+
+                       letters.DataSource = LetterTable.DefaultView;
+                       string current = Letter;
+                       if (current == null) Letter = ALL;
+                       return true;
+               }
+
+               /// <summary>
+               /// Bind the letters array to the repeater control, 
+               /// set the default letter, 
+               /// so that the letters are ready to present.
+               /// </summary>
+               /// 
+               public bool Open(IList letters)
+               {
+                       LetterTable_Init(letters);
+                       return Open();                  
+               }
+
+
+               /// <summary>
+               /// Pass our DataGrid instance to base member.
+               /// </summary>
+               /// 
+               private void Page_Init()
+               {
+                       letters.ItemCommand += new 
RepeaterCommandEventHandler(this.letters_ItemCommand);
+                       letters.ItemDataBound += new 
RepeaterItemEventHandler(this.letters_ItemDataBound);
+               }
+
+               /// <summary>
+               /// Handle the page Load event. 
+               /// </summary>
+               /// <param name="sender">Event source</param>
+               /// <param name="e">Runtime parameters</param>
+               /// 
+               private void Page_Load(object sender, EventArgs e)
+               {
+                       Open();
+               }
+
+               #region Web Form Designer generated code
+
+               /// <summary>
+               ///             Generated method for Designer support.
+               /// </summary>
+               /// <param name="e">Runtime parameters</param>
+               /// 
+               protected override void OnInit(EventArgs e)
+               {
+                       //
+                       // CODEGEN: This call is required by the ASP.NET Web 
Form Designer.
+                       //
+                       InitializeComponent();
+                       base.OnInit(e);
+                       Page_Init();
+               }
+
+               /// <summary>
+               ///             Required method for Designer support - do not 
modify
+               ///             the contents of this method with the code 
editor.
+               /// </summary>
+               private void InitializeComponent()
+               {
+                       this.Load += new EventHandler(this.Page_Load);
+               }
+
+               #endregion
+       }
+}
\ No newline at end of file

Added: struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.resx
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.resx?rev=330619&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.resx 
(added)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Controls/LetterFilter.ascx.resx 
Thu Nov  3 12:03: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>

Modified: struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj
URL: 
http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj?rev=330619&r1=330618&r2=330619&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj Thu Nov  3 12:03:13 2005
@@ -218,6 +218,22 @@
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <File
+                    RelPath = "Controls\LetterFilter.ascx"
+                    SubType = "UserControl"
+                    BuildAction = "Content"
+                />
+                <File
+                    RelPath = "Controls\LetterFilter.ascx.cs"
+                    DependentUpon = "LetterFilter.ascx"
+                    SubType = "ASPXCodeBehind"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "Controls\LetterFilter.ascx.resx"
+                    DependentUpon = "LetterFilter.ascx.cs"
+                    BuildAction = "EmbeddedResource"
+                />
             </Include>
         </Files>
     </CSHARP>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to