From 49ccf41324a2c87b20b84f72355b79d92d6f3d0c Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 4 May 2006 02:52:23 +0000 Subject: Refactored TTable and TTableRow. --- framework/Web/UI/WebControls/TTable.php | 56 ++++++++------------------- framework/Web/UI/WebControls/TTableRow.php | 62 ++++++++---------------------- 2 files changed, 31 insertions(+), 87 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/WebControls/TTable.php b/framework/Web/UI/WebControls/TTable.php index 4fcbb6fb..e7baca02 100644 --- a/framework/Web/UI/WebControls/TTable.php +++ b/framework/Web/UI/WebControls/TTable.php @@ -124,13 +124,21 @@ class TTable extends TWebControl } /** - * @return TTableRowCollection list of {@link TTableRow} controls + * Creates a control collection object that is to be used to hold child controls + * @return TTableRowCollection control collection + * @see getControls + */ + protected function createControlCollection() + { + return new TTableRowCollection($this); + } + + /** + * @return TTableCellCollection list of {@link TTableCell} controls */ public function getRows() { - if(!$this->_rows) - $this->_rows=new TTableRowCollection($this); - return $this->_rows; + return $this->getControls(); } /** @@ -288,10 +296,10 @@ class TTable extends TWebControl */ public function renderContents($writer) { - if($this->_rows) + if($this->getHasControls()) { $writer->writeLine(); - foreach($this->_rows as $row) + foreach($this->getControls() as $row) { $row->renderControl($writer); $writer->writeLine(); @@ -300,6 +308,7 @@ class TTable extends TWebControl } } + /** * TTableRowCollection class. * @@ -310,22 +319,8 @@ class TTable extends TWebControl * @package System.Web.UI.WebControls * @since 3.0 */ -class TTableRowCollection extends TList +class TTableRowCollection extends TControlCollection { - /** - * @var mixed row collection owner - */ - private $_owner=null; - - /** - * Constructor. - * @param mixed row collection owner - */ - public function __construct($owner=null) - { - $this->_owner=$owner; - } - /** * Inserts an item at the specified position. * This overrides the parent implementation by performing additional @@ -337,29 +332,10 @@ class TTableRowCollection extends TList public function insertAt($index,$item) { if($item instanceof TTableRow) - { parent::insertAt($index,$item); - if($this->_owner) - $this->_owner->getControls()->insertAt($index,$item); - } else throw new TInvalidDataTypeException('tablerowcollection_tablerow_required'); } - - /** - * Removes an item at the specified position. - * This overrides the parent implementation by performing additional - * cleanup work when removing a table row. - * @param integer the index of the item to be removed. - * @return mixed the removed item. - */ - public function removeAt($index) - { - $item=parent::removeAt($index); - if($item instanceof TTableRow) - $this->_owner->getControls()->remove($item); - return $item; - } } ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TTableRow.php b/framework/Web/UI/WebControls/TTableRow.php index 6a3f196a..daf921ce 100644 --- a/framework/Web/UI/WebControls/TTableRow.php +++ b/framework/Web/UI/WebControls/TTableRow.php @@ -31,11 +31,6 @@ Prado::using('System.Web.UI.WebControls.TTableHeaderCell'); */ class TTableRow extends TWebControl { - /** - * @var TTableCellCollection cell collection - */ - private $_cells=null; - /** * @return string tag name for the table */ @@ -66,14 +61,22 @@ class TTableRow extends TWebControl return new TTableItemStyle; } + /** + * Creates a control collection object that is to be used to hold child controls + * @return TTableCellCollection control collection + * @see getControls + */ + protected function createControlCollection() + { + return new TTableCellCollection($this); + } + /** * @return TTableCellCollection list of {@link TTableCell} controls */ public function getCells() { - if(!$this->_cells) - $this->_cells=new TTableCellCollection($this); - return $this->_cells; + return $this->getControls(); } /** @@ -124,10 +127,10 @@ class TTableRow extends TWebControl */ public function renderContents($writer) { - if($this->_cells) + if($this->getHasControls()) { $writer->writeLine(); - foreach($this->_cells as $cell) + foreach($this->getControls() as $cell) { $cell->renderControl($writer); $writer->writeLine(); @@ -136,8 +139,6 @@ class TTableRow extends TWebControl } } - - /** * TTableCellCollection class. * @@ -148,23 +149,8 @@ class TTableRow extends TWebControl * @package System.Web.UI.WebControls * @since 3.0 */ -class TTableCellCollection extends TList +class TTableCellCollection extends TControlCollection { - /** - * @var mixed cell collection owner - */ - private $_owner=null; - - /** - * Constructor. - * @param mixed cell collection owner - */ - public function __construct($owner=null) - { - $this->_owner=$owner; - } - - /** * Inserts an item at the specified position. * This overrides the parent implementation by performing additional @@ -176,28 +162,10 @@ class TTableCellCollection extends TList public function insertAt($index,$item) { if($item instanceof TTableCell) - { parent::insertAt($index,$item); - if($this->_owner) - $this->_owner->getControls()->insertAt($index,$item); - } else throw new TInvalidDataTypeException('tablecellcollection_tablecell_required'); } - - /** - * Removes an item at the specified position. - * This overrides the parent implementation by performing additional - * cleanup work when removing a table cell. - * @param integer the index of the item to be removed. - * @return mixed the removed item. - */ - public function removeAt($index) - { - $item=parent::removeAt($index); - if($item instanceof TTableCell) - $this->_owner->getControls()->remove($item); - return $item; - } } + ?> \ No newline at end of file -- cgit v1.2.3