001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.table.components;
016
017 import org.apache.tapestry.BaseComponent;
018 import org.apache.tapestry.IForm;
019 import org.apache.tapestry.TapestryUtils;
020 import org.apache.tapestry.contrib.table.model.ITableColumn;
021 import org.apache.tapestry.contrib.table.model.ITableModel;
022 import org.apache.tapestry.contrib.table.model.ITableModelSource;
023
024 /**
025 * The facade component in the Table family. Table allows you to present a sortable and pagable
026 * table simply and easily by using only this one component. Please see the Component Reference for
027 * details on how to use this component. [ <a
028 * href="../../../../../../../ComponentReference/contrib.Table.html">Component Reference </a>]
029 *
030 * @author mindbridge
031 */
032 public abstract class Table extends BaseComponent implements ITableModelSource
033 {
034 public abstract boolean getVolatile();
035
036 /**
037 * @see org.apache.tapestry.contrib.table.model.ITableModelSource#getTableModel()
038 */
039 public ITableModel getTableModel()
040 {
041 return getTableViewComponent().getTableModel();
042 }
043
044 /**
045 * Indicates that the table model has changed and it may need to saved. This method has to be
046 * invoked if modifications are made to the model.
047 *
048 * @see org.apache.tapestry.contrib.table.model.ITableModelSource#fireObservedStateChange()
049 */
050 public void fireObservedStateChange()
051 {
052 getTableViewComponent().fireObservedStateChange();
053 }
054
055 /**
056 * Resets the state of the component and forces it to load a new TableModel from the tableModel
057 * binding the next time it renders.
058 */
059 public void reset()
060 {
061 getTableViewComponent().reset();
062 }
063
064 /**
065 * Returns the currently rendered table column. You can call this method to obtain the current
066 * column.
067 *
068 * @return ITableColumn the current table column
069 */
070 public ITableColumn getTableColumn()
071 {
072 Object objCurrentRow = getTableRow();
073
074 // if the current row is null, then we are most likely rendering TableColumns
075 if (objCurrentRow == null)
076 return getTableColumnsComponent().getTableColumn();
077
078 return getTableValuesComponent().getTableColumn();
079 }
080
081 /**
082 * Returns the currently rendered table row or null if the rows are not rendered at the moment.
083 * You can call this method to obtain the current row.
084 *
085 * @return Object the current table row
086 */
087 public Object getTableRow()
088 {
089 return getTableRowsComponent().getTableRow();
090 }
091
092 protected TableView getTableViewComponent()
093 {
094 return (TableView) getComponent("tableView");
095 }
096
097 protected TableColumns getTableColumnsComponent()
098 {
099 return (TableColumns) getComponent("tableColumns");
100 }
101
102 protected TableRows getTableRowsComponent()
103 {
104 return (TableRows) getComponent("tableRows");
105 }
106
107 protected TableValues getTableValuesComponent()
108 {
109 return (TableValues) getComponent("tableValues");
110 }
111
112 public boolean getShowNormalPages()
113 {
114 if (getVolatile())
115 return true;
116
117 IForm form = (IForm) getPage().getRequestCycle().getAttribute(TapestryUtils.FORM_ATTRIBUTE);
118 return (form == null);
119 }
120 }