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.ITableAction;
021 import org.apache.tapestry.contrib.table.model.ITableColumn;
022 import org.apache.tapestry.contrib.table.model.ITableModel;
023 import org.apache.tapestry.contrib.table.model.ITableModelSource;
024
025 /**
026 * The facade component in the Table family. Table allows you to present a
027 * sortable and pagable table simply and easily by using only this one
028 * component. Please see the Component Reference for details on how to use this
029 * component. [ <a
030 * href="../../../../../../../ComponentReference/contrib.Table.html">Component
031 * Reference </a>]
032 *
033 * @author mindbridge
034 */
035 public abstract class Table extends BaseComponent implements ITableModelSource
036 {
037
038 public abstract boolean getVolatile();
039
040 /**
041 * @see org.apache.tapestry.contrib.table.model.ITableModelSource#getTableModel()
042 */
043 public ITableModel getTableModel()
044 {
045 return getTableViewComponent().getTableModel();
046 }
047
048 /**
049 * Indicates that the table model has changed and it may need to saved. This
050 * method has to be invoked if modifications are made to the model.
051 *
052 * @see org.apache.tapestry.contrib.table.model.ITableModelSource#fireObservedStateChange()
053 */
054 public void fireObservedStateChange()
055 {
056 getTableViewComponent().fireObservedStateChange();
057 }
058
059 /**
060 * Resets the state of the component and forces it to load a new TableModel
061 * from the tableModel binding the next time it renders.
062 */
063 public void reset()
064 {
065 getTableViewComponent().reset();
066 }
067
068 /**
069 * Returns the currently rendered table column. You can call this method to
070 * obtain the current column.
071 *
072 * @return ITableColumn the current table column
073 */
074 public ITableColumn getTableColumn()
075 {
076 Object objCurrentRow = getTableRow();
077
078 // if the current row is null, then we are most likely rendering
079 // TableColumns
080 if (objCurrentRow == null)
081 return getTableColumnsComponent().getTableColumn();
082
083 return getTableValuesComponent().getTableColumn();
084 }
085
086 /**
087 * Returns the currently rendered table row or null if the rows are not
088 * rendered at the moment. You can call this method to obtain the current
089 * row.
090 *
091 * @return Object the current table row
092 */
093 public Object getTableRow()
094 {
095 return getTableRowsComponent().getTableRow();
096 }
097
098 protected TableView getTableViewComponent()
099 {
100 return (TableView) getComponent("tableView");
101 }
102
103 protected TableColumns getTableColumnsComponent()
104 {
105 return (TableColumns) getComponent("tableColumns");
106 }
107
108 protected TableRows getTableRowsComponent()
109 {
110 return (TableRows) getComponent("tableRows");
111 }
112
113 protected TableValues getTableValuesComponent()
114 {
115 return (TableValues) getComponent("tableValues");
116 }
117
118 public boolean getShowNormalPages()
119 {
120 if (getVolatile()) return true;
121
122 IForm form = (IForm) getPage().getRequestCycle().getAttribute(
123 TapestryUtils.FORM_ATTRIBUTE);
124 return (form == null);
125 }
126
127 /*
128 * (non-Javadoc)
129 *
130 * @see org.apache.tapestry.contrib.table.model.ITableModelSource#storeTableAction(org.apache.tapestry.contrib.table.model.ITableAction)
131 */
132 public void storeTableAction(ITableAction action)
133 {
134 getTableViewComponent().storeTableAction(action);
135 }
136 }