From 5af330b442f15be0f0535a9e3c053b8e6eb5a202 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 15 Jan 2006 06:14:10 +0000 Subject: Added TDataGridColumn. --- framework/Web/UI/WebControls/TDataGrid.php | 220 ++++++++++------- framework/Web/UI/WebControls/TDataGridColumn.php | 295 +++++++++++++++++++++++ framework/Web/UI/WebControls/TStyle.php | 2 + 3 files changed, 429 insertions(+), 88 deletions(-) create mode 100644 framework/Web/UI/WebControls/TDataGridColumn.php (limited to 'framework') diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index 23b45842..205b97a0 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -96,96 +96,10 @@ * * An OnItemCreated event will be raised right after each item is created in the datagrid. * - * Namespace: System.Web.UI.WebControls - * - * Properties - * - Items, TDataGridItemCollection, read-only - *
Gets the list of TDataGridItem controls that correspond to each data item. - * - Columns, TCollection, read-only - *
Gets the list of TDataGridColumn controls that are manually specified or created. - * - AutoGenerateColumns, boolean, default=true, kept in viewstate - *
Gets or sets the value indicating whether columns should be generated automatically based on the data in datasource. - * - AllowSorting, boolean, default=false, kept in viewstate - *
Gets or sets the value indicating whether sorting should be enabled. - * - AllowPaging, boolean, default=false, kept in viewstate - *
Gets or sets the value indicating whether paging should be enabled. - * - AllowCustomPaging, boolean, default=false, kept in viewstate - *
Gets or sets the value indicating whether custom paging should be enabled. - * - CurrentPageIndex, integer, default=0, stored in viewstate - *
Gets or sets the index for the page to be displayed - * - PageSize, integer, default=10, stored in viewstate - *
Gets or sets the number of data items to be displayed in each page. - * - PageCount, integer, read-only - *
Gets the number of pages to be displayed. - * - VirtualItemCount, integer, default=0, stored in viewstate - *
Gets or sets the number of data items available for paging purpose when custom paging is enabled. - * - PagerButtonCount, integer, default=10, stored in viewstate - *
Gets or sets the number of buttons to be displayed in pager for navigating among pages. - * - PagerDisplay, string (None,Top,Bottom,TopAndBottom), default=Bottom, stored in viewstate - *
Gets or sets where the pager should be displayed. - * - EditItemIndex, integer, default=-1, stored in viewstate - *
Gets or sets the index for edit item. - * - EditItem, TDataGridItem, read-only - *
Gets the edit item, null if none - * - EditItemStyle, string, stored in viewstate - *
Gets or sets the css style for the edit item - * - EditItemCssClass, string, stored in viewstate - *
Gets or sets the css classs for the edit item - * - SelectedItemIndex, integer, default=-1, stored in viewstate - *
Gets or sets the index for selected item. - * - SelectedItem, TDataGridItem, read-only - *
Gets the selected item, null if none - * - SelectedItemStyle, string, stored in viewstate - *
Gets or sets the css style for the selected item - * - SelectedItemCssClass, string, stored in viewstate - *
Gets or sets the css class for the selected item - * - ItemStyle, string, stored in viewstate - *
Gets or sets the css style for each item - * - ItemCssClass, string, stored in viewstate - *
Gets or sets the css class for each item - * - AlternatingItemStyle, string, stored in viewstate - *
Gets or sets the css style for each alternating item - * - AlternatingItemCssClass, string, stored in viewstate - *
Gets or sets the css class for each alternating item - * - HeaderStyle, string, stored in viewstate - *
Gets or sets the css style for the header - * - HeaderCssClass, string, stored in viewstate - *
Gets or sets the css class for the header - * - FooterStyle, string, stored in viewstate - *
Gets or sets the css style for the footer - * - FooterCssClass, string, stored in viewstate - *
Gets or sets the css class for the footer - * - PagerStyle, string, stored in viewstate - *
Gets or sets the css style for the pager - * - PagerCssClass, string, stored in viewstate - *
Gets or sets the css class for the pager - * - ShowHeader, boolean, default=true, stored in viewstate - *
Gets or sets the value whether to show header - * - ShowFooter, boolean, default=true, stored in viewstate - *
Gets or sets the value whether to show footer - * - Header, TDataGridItem - *
Gets the header of the data grid. - * - Footer, TDataGridItem - *
Gets the footer of the data grid. - * - Pager, TDataGridItem - *
Gets the pager of the data grid. - * - BackImageUrl, string, kept in viewstate - *
Gets or sets the URL of the background image to display behind the datagrid. - * - * Events - * - OnEditCommand, raised when a button control raises an OnCommand event with 'edit' command. - * - OnSelectCommand, raised when a button control raises an OnCommand event with 'select' command. - * - OnUpdateCommand, raised when a button control raises an OnCommand event with 'update' command. - * - OnCancelCommand, raised when a button control raises an OnCommand event with 'cancel' command. - * - OnDeleteCommand, raised when a button control raises an OnCommand event with 'delete' command. - * - OnPageCommand, raised when a button control raises an OnCommand event with 'page' command. - * - OnSortCommand, raised when a button control raises an OnCommand event with 'sort' command. - * - OnItemCommand, raised when a button control raises an OnCommand event. - * - OnItemCreatedCommand, raised right after an item is created. - * * @author Qiang Xue - * @version $Revision: 1.25 $ $Date: 2005/12/17 06:11:28 $ + * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls + * @since 3.0 */ class TDataGrid extends TBaseDataList { @@ -1152,6 +1066,136 @@ class TDataGridColumnCollection extends TList class TDataGridPagerStyle extends TTableItemStyle { + private $_mode=null; + private $_nextText=null; + private $_prevText=null; + private $_buttonCount=null; + private $_position=null; + private $_visible=null; + + public function getMode() + { + return $this->_mode===null?'NextPrev':$this->_mode; + } + + public function setMode($value) + { + $this->_mode=TPropertyValue::ensureEnum($value,'NextPrev','NumericPages'); + } + + public function getNextPageText() + { + return $this->_nextText===null?'>':$this->_nextText; + } + + public function setNextPageText($value) + { + $this->_nextText=$value; + } + + public function getPrevPageText() + { + return $this->_prevText===null?'<':$this->_prevText; + } + + public function setPrevPageText($value) + { + $this->_prevText=$value; + } + + public function getPageButtonCount() + { + return $this->_buttonCount===null?10:$this->_buttonCount; + } + + public function setPageButtonCount($value) + { + if(($value=TPropertyValue::ensureInteger($value))<1) + throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid'); + $this->_buttonCount=$value; + } + + public function getPosition() + { + return $this->_position===null?'Bottom':$this->_position; + } + + public function setPosition($value) + { + $this->_position=TPropertyValue::ensureEnum($value,'Bottom','Top','TopAndBottom'); + } + + public function getVisible() + { + return $this->_visible===null?true:$this->_visible; + } + + public function setVisible($value) + { + $this->_visible=TPropertyValue::ensureBoolean($value); + } + + /** + * Resets the style to the original empty state. + */ + public function reset() + { + parent::reset(); + $this->_visible=null; + $this->_position=null; + $this->_buttonCount=null; + $this->_prevText=null; + $this->_nextText=null; + $this->_mode=null; + } + + /** + * Copies the style content from an existing style + * This method overrides the parent implementation by + * adding additional TDataGridPagerStyle specific attributes. + * @param TStyle source style + */ + public function copyFrom($style) + { + parent::copyFrom($style); + if($style instanceof TDataGridPagerStyle) + { + $this->_visible=$style->_visible; + $this->_position=$style->_position; + $this->_buttonCount=$style->_buttonCount; + $this->_prevText=$style->_prevText; + $this->_nextText=$style->_nextText; + $this->_mode=$style->_mode; + } + } + + /** + * Merges with a style. + * If a style field is not set in the current style but set in the new style + * it will take the value from the new style. + * This method overrides the parent implementation by + * merging with additional TDataGridPagerStyle specific attributes. + * @param TStyle the new style + */ + public function mergeWith($style) + { + parent::mergeWith($style); + if($style instanceof TDataGridPagerStyle) + { + if($style->_visible!==null && $this->_visible===null) + $this->_visible=$style->_visible; + if($style->_position!==null && $this->_position===null) + $this->_position=$style->_position; + if($style->_buttonCount!==null && $this->_buttonCount===null) + $this->_buttonCount=$style->_buttonCount; + if($style->_prevText!==null && $this->_prevText===null) + $this->_prevText=$style->_prevText; + if($style->_nextText!==null && $this->_nextText===null) + $this->_nextText=$style->_nextText; + if($style->_mode!==null && $this->_mode===null) + $this->_mode=$style->_mode; + } + } } ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php new file mode 100644 index 00000000..f78c636d --- /dev/null +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -0,0 +1,295 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class + * + * TDataGridColumn serves as the base class for the different column types of the TDataGrid control. + * TDataGridColumn defines the properties and methods that are common to all column types. + * In particular, it initializes header and footer cells according to + * HeaderText, HeaderStyle, FooterText, and FooterStyle. + * If HeaderImageUrl is specified, the image will be displayed instead in the header cell. + * The ItemStyle is applied to non-header and -footer items. + * + * When the datagrid enables sorting, if the SortExpression is not empty, + * the header cell will display a button (linkbutton or imagebutton) that will + * bubble sort command event to the datagrid. + * + * The framework provides the following TDataGridColumn descendant classes, + * - TBoundColumn, associated with a specific field in datasource and displays the corresponding data. + * - TEditCommandColumn, displaying edit/update/cancel command buttons + * - TButtonColumn, displaying generic command buttons that may be bound to specific field in datasource. + * - THyperLinkColumn, displaying a hyperlink that may be boudn to specific field in datasource. + * - TTemplateColumn, displaying content based on templates. + * + * To create your own column class, simply override {@link initializeCell()} method, + * which is the major logic for managing the data and presentation of cells in the column. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +abstract class TDataGridColumn extends TComponent +{ + private $_owner=null; + private $_viewState=array(); + + /** + * @return string the text to be displayed in the header of this column + */ + public function getHeaderText() + { + return $this->getViewState('HeaderText',''); + } + + /** + * @param string text to be displayed in the header of this column + */ + public function setHeaderText($value) + { + $this->setViewState('HeaderText',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the url of the image to be displayed in header + */ + public function getHeaderImageUrl() + { + return $this->getViewState('HeaderImageUrl',''); + } + + /** + * @param string the url of the image to be displayed in header + */ + public function setHeaderImageUrl($value) + { + $this->setViewState('HeaderImageUrl',$value,''); + $this->onColumnChanged(); + } + + /** + * @return TTableItemStyle the style for header + */ + public function getHeaderStyle() + { + if(($style=$this->getViewState('HeaderStyle',null))===null) + { + $style=new TTableItemStyle; + $this->setViewState('HeaderStyle',$style,null); + } + return $style; + } + + /** + * @return string the text to be displayed in the footer of this column + */ + public function getFooterText() + { + return $this->getViewState('FooterText',''); + } + + /** + * @param string text to be displayed in the footer of this column + */ + public function setFooterText($value) + { + $this->setViewState('FooterText',$value,''); + $this->onColumnChanged(); + } + + /** + * @return TTableItemStyle the style for footer + */ + public function getFooterStyle() + { + if(($style=$this->getViewState('FooterStyle',null))===null) + { + $style=new TTableItemStyle; + $this->setViewState('FooterStyle',$style,null); + } + return $style; + } + + /** + * @return TTableItemStyle the style for item + */ + public function getItemStyle() + { + if(($style=$this->getViewState('ItemStyle',null))===null) + { + $style=new TTableItemStyle; + $this->setViewState('ItemStyle',$style,null); + } + return $style; + } + + /** + * @param string the name of the field or expression for sorting + */ + public function setSortExpression($value) + { + $this->setViewState('SortExpression',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the name of the field or expression for sorting + */ + public function getSortExpression() + { + return $this->getViewState('SortExpression',''); + } + + /** + * @return boolean whether the column is visible. Defaults to true. + */ + public function getVisible($checkParents=true) + { + return $this->getViewState('Visible',true); + } + + /** + * @param boolean whether the column is visible + */ + public function setVisible($value) + { + $this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true); + $this->onColumnChanged(); + } + + /** + * Returns a viewstate value. + * + * @param string the name of the viewstate value to be returned + * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned + * @return mixed the viewstate value corresponding to $key + */ + protected function getViewState($key,$defaultValue=null) + { + return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue; + } + + /** + * Sets a viewstate value. + * + * Make sure that the viewstate value must be serializable and unserializable. + * @param string the name of the viewstate value + * @param mixed the viewstate value to be set + * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate. + */ + protected function setViewState($key,$value,$defaultValue=null) + { + if($value===$defaultValue) + unset($this->_viewState[$key]); + else + $this->_viewState[$key]=$value; + } + + protected function loadState($state) + { + $this->_viewState=$state; + } + + protected function saveState() + { + return $this->_viewState; + } + + protected function getOwner() + { + return $this->_owner; + } + + protected function setOwner(TDataGrid $value) + { + $this->_owner=$value; + } + + protected function onColumnChanged() + { + if($this->_owner) + $this->_owner->onColumnsChanged(); + } + + public function initialize() + { + } + + /** + * Initializes the specified cell to its initial values. + * The default implementation sets the content of header and footer cells. + * If sorting is enabled by the grid and sort expression is specified in the column, + * the header cell will show a link/image button. Otherwise, the header/footer cell + * will only show static text/image. + * This method can be overriden to provide customized intialization to column cells. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + switch($itemType) + { + case 'Header': + $sortExpression=$this->getSortExpression(); + $allowSorting=$sortExpression!=='' && (!$this->_owner || $this->_owner->getAllowSorting()); + if($allowSorting) + { + if(($url=$this->getHeaderImageUrl())!=='') + { + $button=Prado::createComponent('System.Web.UI.WebControls.TImageButton'); + $button->setImageUrl($url); + $button->setCommandName('Sort'); + $button->setCommandParameter($sortExpression); + $button->setCausesValidation(false); + $cell->getControls()->add($button); + } + else if(($text=$this->getHeaderText())!=='') + { + $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); + $button->setText($text); + $button->setCommandName('Sort'); + $button->setCommandParameter($sortExpression); + $button->setCausesValidation(false); + $cell->getControls()->add($button); + } + else + $cell->setText(' '); + } + else + { + if(($url=$this->getHeaderImageUrl())!=='') + { + $image=Prado::createComponent('System.Web.UI.WebControls.TImage'); + $image->setImageUrl($url); + $cell->getControls()->add($image); + } + else + { + if(($text=$this->getHeaderText())==='') + $text=' '; + $cell->setText($text); + } + } + break; + case 'Footer': + if(($text=$this->getFooterText())==='') + $text=' '; + $cell->setText($text); + break; + } + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php index 1996ca47..3198f770 100644 --- a/framework/Web/UI/WebControls/TStyle.php +++ b/framework/Web/UI/WebControls/TStyle.php @@ -260,6 +260,7 @@ class TStyle extends TComponent */ public function reset() { + parent::reset(); $this->_fields=array(); $this->_font=null; $this->_class=null; @@ -578,6 +579,7 @@ class TTableItemStyle extends TStyle */ public function reset() { + parent::reset(); $this->_verticalAlign=null; $this->_horizontalAlign=null; $this->_wrap=null; -- cgit v1.2.3