com.waveset.ui
Class Table

java.lang.Object
  extended bycom.waveset.ui.Table
Direct Known Subclasses:
HierarchicalCapabilityTable, HierarchicalResourceTable, HierarchicalTable, SearchTableBase

public abstract class Table
extends java.lang.Object

A bean providing a generic representation for a tabular result set which may wrap a variety of RepositoryResults. Intended for use with the genlist.jsp for generating table forms.

Using bean-style accessors so we can use but I still don't see what the great advantage of that is...


Nested Class Summary
static class Table.ActionButton
           
static class Table.AppletCell
          This is an object to represent an Applet cell.
static class Table.Button
           
static class Table.Cell
          Represents a cell in a table.
static class Table.ColorTextCell
          This is an object to represent a colored text cell.
static class Table.Column
          An object that describes each column.
static class Table.CompoundCell
          Deprecated. - use com.waveset.ui.html.CompoundCell.
static class Table.DateCell
          This is an object to represent a "date" cell.
static class Table.GridCell
          Deprecated. - use com.waveset.ui.html.GridCell.
static class Table.GridSpanCell
          Deprecated. - use com.waveset.ui.html.GridCell.
static class Table.IconCell
          A class describing the contents of an element.
static class Table.JavascriptButton
           
static class Table.JavascriptSelectButton
          Another "do something when the user makes a selection" button, this one will call a named javascript function.
static class Table.LinkCell
          This is an object to represent a link cell.
static class Table.Row
          This is an object to represent a row.
static class Table.SelectButton
           
static class Table.SubmitCommandButton
           
static class Table.SubmitSelectButton
           
static class Table.TextCell
          A class describing the contents of an element.
 
Field Summary
protected  Table.Column[] _columns
          Internal descriptor objects for each column.
protected  boolean _descendingSort
          True if the sort order should be descending.
 java.lang.String _headerLinks
          A spanning header that is used for "head"' links above the table.
protected static Catalog _mc
          The catalog of localized display strings for internationalization
protected  Table.Row[] _rows
          A grid of values.
protected  java.lang.String _sortColumn
          The name of the column we currently want to sort by.
static java.lang.String code_id
           
protected static Trace trace
           
 
Constructor Summary
Table()
           
 
Method Summary
static void addMessageParams(java.lang.StringBuffer params, java.util.Locale locale)
           
static void addParameter(java.lang.StringBuffer params, java.lang.String name, java.lang.String value)
           
static java.lang.String encodeURLParameter(java.lang.String name, java.lang.String value)
          A helper to take two names of parameters that may have null values.
abstract  void generate(javax.servlet.http.HttpSession httpSession, javax.servlet.ServletRequest request, Session s, javax.servlet.http.HttpServletResponse response)
          External table generation method.
 java.lang.String getAppletHTML(RequestState req)
           
 int getButtonCount()
          Return the number of buttons.
 java.lang.String getButtonHtml(RequestState req, int b, boolean topButton, Session session)
           
 java.lang.String getButtonHtml(RequestState req, int b, Session session)
          Returns the HTML representation of a button.
 java.lang.String getButtonName(int b)
          Return the display name of a button.
 java.lang.String getButtonValue(int b)
          Return the form value when this button is selected.
 java.lang.String getCellHtml(RequestState req, int r, int c)
          Return the cell representation in HTML.
 int getColumnCount()
          Return the number of columns.
protected  int getColumnIndex(java.lang.String colname)
          Map a column name into a numeric index.
 boolean getColumnIsWrap(int c)
           
 java.lang.String getColumnLabel(int c)
          Return the column label, for the title strip.
 java.lang.String getColumnName(int c)
          Return the column name, for the title strip.
 java.lang.String getColumnNameNoColon(int c)
           
 java.lang.String getError()
          Get an optional error message for this table.
 java.util.Hashtable getHiddenFormData()
          get the optional hidden form data
 int getLinkColumn()
          Get the column number (starts at 0) that will be used for placing the links defined by setLinkURL
 java.lang.String getLinkURL()
          Get the link URL for the form.
 java.lang.String getMessage()
          Get the optional information message.
 java.lang.String getObjectName(Session s, Type type, java.lang.String id)
          A helper to translate object IDs into object names
 java.lang.String getObjectNames(Session s, Type type, java.lang.Object[] ids)
           
 PageInformation getPageInformation()
          Get the PageInformation object for this page
 java.lang.String getParameter(javax.servlet.ServletRequest r, java.lang.String name)
          Return the value of a parameter, converting empty strings to null.
 java.lang.String getPostURL()
          Get the post URL for the form.
 int getRowCount()
          Return the number of rows.
 boolean getRowHasCheckbox(int r)
          Return whether this row should generate a check box
 boolean getRowNeedsLink(int r)
          Return whether this row should have a link in the _linkColumn column
 java.lang.String getRowTypeName(int r)
          Set the type name string for the row.
 java.lang.String getSelectValue(int row)
          Return the value to assign to the checkbox form item in a mult-select table.
 java.lang.String getSortColumn()
          Return the sort column name.
 boolean getSortEnable()
           
 java.lang.String getSortOrder()
          Return the sort order.
 java.lang.String getSortURL()
          Get the sort URL for the form.
 java.lang.String getSortURLParams()
          Get the sort URL parameters for the form.
 java.lang.String getSubTitle()
           
 Table.TextCell getTableName()
           
 java.lang.String getTableNameHTML(RequestState req)
           
 java.lang.String getTitle()
          Get the title for the table.
 int getTopButtonCount()
           
 java.lang.String getTopButtonName(int b)
          Return the display name of a button.
 java.lang.String getTopButtonValue(int b)
           
 java.lang.String getType()
          Get the type of the table.
static java.lang.reflect.Method implementsToHTML(java.lang.Object o)
          Determines if an object contains a toHTML method that takes no arguments and returns a String
 boolean isGenerateLinks()
          Returns true if the table will be generated with links in the column specified by _linkColumn (defaults to 0).
 boolean isMultiSelect()
          Returns true if this is designated as a multi-select table.
 void setApplet(Table.AppletCell applet)
           
 void setButtons(Table.Button[] buttons)
          Set the buttons.
 void setColumns(Table.Column[] cols)
          Set the columns.
 void setError(java.lang.String e)
          Set an optional error message for this table.
 void setGenerateLinks(boolean b)
          Set the link generation option.
 void setHiddenFormData(java.util.Hashtable ht)
          Set the hidden attributes
 void setLinkColumn(int col)
          Set the column number (starts at 0) that will be used for placing the links defined by setLinkURL
 void setLinkURL(java.lang.String url)
          Set the URL that we will goto when a link is selected.
 void setMessage(java.lang.String msg)
          Set the optional information message.
 void setMultiSelect(boolean b)
          Sets the multi-select flag.
 void setPageInformation(PageInformation pi)
          Set the PageInformation object for this page
 void setPostURL(java.lang.String url)
          Set the URL that we will POST to when the generated form is submitted.
 void setRouteURLParams(java.lang.String params, javax.servlet.http.HttpSession hs, javax.servlet.ServletRequest req, java.lang.String curpage, java.lang.String routeName)
           
 void setRowHasCheckbox(int r, boolean hasCheckbox)
          Set whether this row should generate a check box
 void setRows(Table.Row[] rows)
          Set the rows.
 void setRowTypeName(int r, java.lang.String typeName)
          Set this row's datatype (stored as string in checkbox name)
 void setSortColumn(java.lang.String name)
          Set the sort column.
 boolean setSortEnable(boolean on)
           
 void setSortOrder(java.lang.String order)
          Set the sort order.
 void setSortURL(java.lang.String url)
          Set the URL that we will POST to when one of the sort "buttons" is hit.
 void setSortURLParams(java.lang.String params)
          Set the URL parameters that will be added to the sortURL along with the sort column and order The parameters must be URLEncoded using something like com.waveset.util.URLUTF8Encoder.encode()
 void setSubTitle(java.lang.String subTitle)
           
 void setTableName(Table.TextCell tableName)
           
 void setTitle(java.lang.String title)
          Set the title for the table.
 void setTopButtons(Table.Button[] buttons)
           
 void setType(java.lang.String type)
          Sets the type of this table.
 void sort()
          Called by generate() after building up a _rows matrix.
 void Table()
          Base constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static final Trace trace

_headerLinks

public java.lang.String _headerLinks
A spanning header that is used for "head"' links above the table. Used ASIS, in HTML


_sortColumn

protected java.lang.String _sortColumn
The name of the column we currently want to sort by.


_descendingSort

protected boolean _descendingSort
True if the sort order should be descending.


_columns

protected Table.Column[] _columns
Internal descriptor objects for each column. We could expose these and shift some of the Table methods to Column methods, but given that there aren't that many Column properties, it feels simpler to keep this hidden.


_rows

protected Table.Row[] _rows
A grid of values.


_mc

protected static Catalog _mc
The catalog of localized display strings for internationalization

Constructor Detail

Table

public Table()
Method Detail

Table

public void Table()
Base constructor. All the interesting construction happens after setting property values and calling the generate() method.


getType

public java.lang.String getType()
Get the type of the table.


getTitle

public java.lang.String getTitle()
Get the title for the table.


getSubTitle

public java.lang.String getSubTitle()

getTableName

public Table.TextCell getTableName()

getTableNameHTML

public java.lang.String getTableNameHTML(RequestState req)

setTableName

public void setTableName(Table.TextCell tableName)

getAppletHTML

public java.lang.String getAppletHTML(RequestState req)

setApplet

public void setApplet(Table.AppletCell applet)

getPostURL

public java.lang.String getPostURL()
Get the post URL for the form.


getLinkURL

public java.lang.String getLinkURL()
Get the link URL for the form. This will be the same as the post URL if no link URL has been specified.


getLinkColumn

public int getLinkColumn()
Get the column number (starts at 0) that will be used for placing the links defined by setLinkURL


getSortURL

public java.lang.String getSortURL()
Get the sort URL for the form.

If this isn't set, we default to the postURL.


getSortURLParams

public java.lang.String getSortURLParams()
Get the sort URL parameters for the form.

If this isn't set, we return an empty string


getColumnCount

public int getColumnCount()
Return the number of columns.


getRowCount

public int getRowCount()
Return the number of rows.


getRowHasCheckbox

public boolean getRowHasCheckbox(int r)
Return whether this row should generate a check box


getRowNeedsLink

public boolean getRowNeedsLink(int r)
Return whether this row should have a link in the _linkColumn column

If the rows have not been set for the table or the specified row is out of bounds, then return the value of Table._generateLinks.


getRowTypeName

public java.lang.String getRowTypeName(int r)
Set the type name string for the row. This is used to generate the name string of the checkbox (defaults to "select")


setRowHasCheckbox

public void setRowHasCheckbox(int r,
                              boolean hasCheckbox)
Set whether this row should generate a check box


setRowTypeName

public void setRowTypeName(int r,
                           java.lang.String typeName)
Set this row's datatype (stored as string in checkbox name)


getSortColumn

public java.lang.String getSortColumn()
Return the sort column name.

If the column is null, it defaults to the name of the first column. getSortColumn should always return a non null value to keep the .jsp from crashing.


getSortOrder

public java.lang.String getSortOrder()
Return the sort order.

Returns either "ASC" or "DESC". This is what Thought Interactive coded for, it probably could be a simple boolean.


getColumnName

public java.lang.String getColumnName(int c)
Return the column name, for the title strip.


getColumnLabel

public java.lang.String getColumnLabel(int c)
Return the column label, for the title strip.


getColumnNameNoColon

public java.lang.String getColumnNameNoColon(int c)

getColumnIsWrap

public boolean getColumnIsWrap(int c)

implementsToHTML

public static java.lang.reflect.Method implementsToHTML(java.lang.Object o)
Determines if an object contains a toHTML method that takes no arguments and returns a String


getCellHtml

public java.lang.String getCellHtml(RequestState req,
                                    int r,
                                    int c)
Return the cell representation in HTML.


getButtonCount

public int getButtonCount()
Return the number of buttons.


getTopButtonCount

public int getTopButtonCount()

getButtonHtml

public java.lang.String getButtonHtml(RequestState req,
                                      int b,
                                      Session session)
Returns the HTML representation of a button. If the button class implements the toHTML method, then it will be used to generate the HTML. Otherwise a generic button of the form will be generated.


getButtonHtml

public java.lang.String getButtonHtml(RequestState req,
                                      int b,
                                      boolean topButton,
                                      Session session)

getButtonName

public java.lang.String getButtonName(int b)
Return the display name of a button.


getTopButtonName

public java.lang.String getTopButtonName(int b)
Return the display name of a button.


getButtonValue

public java.lang.String getButtonValue(int b)
Return the form value when this button is selected.


getTopButtonValue

public java.lang.String getTopButtonValue(int b)

getSelectValue

public java.lang.String getSelectValue(int row)
Return the value to assign to the checkbox form item in a mult-select table.

The value is the value of the _rowKey attribute of the Row inner class. If this is not set, then the first column of the row is used.

It may be overridden by a subclass if necessary.


isMultiSelect

public boolean isMultiSelect()
Returns true if this is designated as a multi-select table. This normally results in the generation of a checkbox column.


isGenerateLinks

public boolean isGenerateLinks()
Returns true if the table will be generated with links in the column specified by _linkColumn (defaults to 0).


getHiddenFormData

public java.util.Hashtable getHiddenFormData()
get the optional hidden form data

Each item in this hash table will be represented as

  


getError

public java.lang.String getError()
Get an optional error message for this table. This will normally be rendered in some obvious way at the top of the table.


getMessage

public java.lang.String getMessage()
Get the optional information message.


getParameter

public java.lang.String getParameter(javax.servlet.ServletRequest r,
                                     java.lang.String name)
Return the value of a parameter, converting empty strings to null.

Trim whitespace from both ends.

This is the same as EditForm.getParameter() and should be moved to some common place.


encodeURLParameter

public static java.lang.String encodeURLParameter(java.lang.String name,
                                                  java.lang.String value)
A helper to take two names of parameters that may have null values. Encode them in the URL. If the name turns out to be null, return an empty string.


getObjectName

public java.lang.String getObjectName(Session s,
                                      Type type,
                                      java.lang.String id)
                               throws WavesetException
A helper to translate object IDs into object names

Throws:
WavesetException

getObjectNames

public java.lang.String getObjectNames(Session s,
                                       Type type,
                                       java.lang.Object[] ids)
                                throws WavesetException
Throws:
WavesetException

getPageInformation

public PageInformation getPageInformation()
Get the PageInformation object for this page


setType

public void setType(java.lang.String type)
Sets the type of this table.

This is a bit of a kludge, but I'm trying to keep the type language simple. We need to have a way to specify what we want in the table. Most of the time its a list of one type of PersistentObject, with no filtering. Each type may have a different set of columns. Sometimes the columns are dependent on the combination of type and operation, e.g. "create role" may build a different table than "delete role".

Further each table may have a set of buttons that will vary depending on the operation.

A more flexible language for specifying all these options may one day be required, but at the moment, its ok to hard-wire table-building semantics to a few type symbols. See the generation() method for what actually happens for each type.

Should we error here if the type is wrong, build an empty table, or build a table with some recognizable error text?


setPostURL

public void setPostURL(java.lang.String url)
Set the URL that we will POST to when the generated form is submitted. The URL is expected to have already been processed with encodeURL() if necessary.


setLinkURL

public void setLinkURL(java.lang.String url)
Set the URL that we will goto when a link is selected. This defaults to the postURL, unless explicitly specified.


setLinkColumn

public void setLinkColumn(int col)
Set the column number (starts at 0) that will be used for placing the links defined by setLinkURL


setSortURL

public void setSortURL(java.lang.String url)
Set the URL that we will POST to when one of the sort "buttons" is hit.


setSortURLParams

public void setSortURLParams(java.lang.String params)
Set the URL parameters that will be added to the sortURL along with the sort column and order The parameters must be URLEncoded using something like com.waveset.util.URLUTF8Encoder.encode()


setRouteURLParams

public void setRouteURLParams(java.lang.String params,
                              javax.servlet.http.HttpSession hs,
                              javax.servlet.ServletRequest req,
                              java.lang.String curpage,
                              java.lang.String routeName)
                       throws WavesetException
Throws:
WavesetException

setSortEnable

public boolean setSortEnable(boolean on)

getSortEnable

public boolean getSortEnable()

setTitle

public void setTitle(java.lang.String title)
Set the title for the table.


setSubTitle

public void setSubTitle(java.lang.String subTitle)

setSortColumn

public void setSortColumn(java.lang.String name)
Set the sort column.

The column can be null here in which case getSortColumn will default to the name of the first column.

What should we do if the column name is wrong?


setGenerateLinks

public void setGenerateLinks(boolean b)
Set the link generation option.

If true, the table will be generated with the first column values being links to the url specified in _linkURL or _postURL.


setSortOrder

public void setSortOrder(java.lang.String order)
Set the sort order.

This is really just a boolean, but its being exposed as a string. Not sure if that's really necessary, but its the way Thought Interactive was doing it.

Internally we recognize "DESC" as descending and anything else is considered to be ascending. getSortOrder will return "ASC" for ascending. The default is ascending.


setMultiSelect

public void setMultiSelect(boolean b)
Sets the multi-select flag.


setRows

public void setRows(Table.Row[] rows)
Set the rows.

Normally only called by subclasses.


setColumns

public void setColumns(Table.Column[] cols)
Set the columns.

Normally only called by subclasses.


setButtons

public void setButtons(Table.Button[] buttons)
Set the buttons.

Normally only called by subclasses.


setTopButtons

public void setTopButtons(Table.Button[] buttons)

setHiddenFormData

public void setHiddenFormData(java.util.Hashtable ht)
Set the hidden attributes


setError

public void setError(java.lang.String e)
Set an optional error message for this table. This will normally be rendered in some obvious way at the top of the table.


setMessage

public void setMessage(java.lang.String msg)
Set the optional information message.


setPageInformation

public void setPageInformation(PageInformation pi)
Set the PageInformation object for this page


sort

public void sort()
Called by generate() after building up a _rows matrix. sort the rows according to the sort column if set.


getColumnIndex

protected int getColumnIndex(java.lang.String colname)
Map a column name into a numeric index. Returns -1 if the name does not map.


addMessageParams

public static void addMessageParams(java.lang.StringBuffer params,
                                    java.util.Locale locale)

addParameter

public static void addParameter(java.lang.StringBuffer params,
                                java.lang.String name,
                                java.lang.String value)

generate

public abstract void generate(javax.servlet.http.HttpSession httpSession,
                              javax.servlet.ServletRequest request,
                              Session s,
                              javax.servlet.http.HttpServletResponse response)
                       throws WavesetException
External table generation method. This should be overridden in the subclass to do something interesting.

Throws:
WavesetException