to.etc.domui.component.ntbl
Class ExpandingEditTable<T>

java.lang.Object
  extended by to.etc.domui.dom.css.CssBase
      extended by to.etc.domui.dom.html.NodeBase
          extended by to.etc.domui.dom.html.NodeContainer
              extended by to.etc.domui.dom.html.Div
                  extended by to.etc.domui.component.tbl.TableModelTableBase<T>
                      extended by to.etc.domui.component.ntbl.ExpandingEditTable<T>
All Implemented Interfaces:
java.lang.Iterable<NodeBase>, IModelBinding, ITableModelListener<T>, INodeErrorDelegate, IHasModifiedIndication, IDraggable, IDropTargetable

public class ExpandingEditTable<T>
extends TableModelTableBase<T>
implements IHasModifiedIndication

This component is a table, using a TableModel, which can also edit it's rows and expand them. It does not support pagination and is used for relatively small datasets.

The basic display is that of a normal table, with each row occupying a single table row, controlled by a RowRenderer as with the DataTable. This row usually displays a "summary" of the available data.

To edit a row the row is expanded by selecting it's index column; this makes the row enter EDIT mode. In edit mode the entire contents of the row is replaced with an edit form containing all of the data to enter on the row. When editing is complete the row can be collapsed again at which point the data will be moved to the underlying model and the result will be redisplayed in the "summary". If the data is in some way invalid the row cannot collapse until the data is valid.

Author:
Frits Jalvingh Created on Dec 7, 2009

Constructor Summary
ExpandingEditTable(java.lang.Class<T> actualClass, ITableModel<T> m, IRowRenderer<T> r)
           
ExpandingEditTable(ITableModel<T> m, IRowRenderer<T> r)
           
 
Method Summary
 void addNew(T instance)
          Make the control enter ADD NEW mode for the specified instance.
 void cancelNew()
           
 boolean collapseAllExpandedRows()
          When executed, method would try to collapse all currently expanded rows.
 void collapseRow(int index)
           
protected  void commitNewRow()
           
 void createContent()
          Create the structure [(div=self)][ErrorMessageDiv][table]
 void expandRow(int index)
           
 IRowEditorFactory<T,? extends NodeContainer> getEditorFactory()
          Return the editor factory to use to create the row editor.
 IRowEditorEvent<T,?> getOnRowChangeCompleted()
          Set a handler to call when editing a row in an editable table component after editing is (somehow) marked as complete.
protected  java.util.List<T> getPageItems()
          Returns all items in the list.
 IRowButtonFactory<T> getRowButtonFactory()
          Returns the button factory to use to add buttons to a row, when needed.
protected  Table getTable()
          Return the backing table for this data browser.
 boolean isDisableErrors()
          Returns T if this control's error handling has been disabled, causing the parent to handle errors instead of showing the errors in the control.
 boolean isEnableAddingItems()
          When set (the default) items are added to the table by calling IModifyableTableModel.add(Object) when the new row action executed succesfully.
 boolean isEnableDeleteButton()
          When T (the default) this component will render a 'delete' linkbutton in the button area after the row, for every row present.
 boolean isEnableExpandItems()
           
 boolean isEnableRowEdit()
           
 boolean isHideHeader()
          When set the table will not render a THead.
 boolean isHideIndex()
          When set the index number before the row is not shown.
 boolean isModified()
          Returns the modified-by-user flag.
 boolean isNewAtStart()
          By default new rows are edited @ the end; set this to edit @ the start.
 void modelChanged(ITableModel<T> model)
          Called when there are sweeping changes to the model.
 void rowAdded(ITableModel<T> model, int index, T value)
          A record is added.
 void rowDeleted(ITableModel<T> model, int index, T value)
          Delete the row specified.
 void rowModified(ITableModel<T> model, int index, T value)
          When a row is modified we redraw the row in collapsed mode; if it was in edit mode before bad luck.
 void setDisableErrors(boolean on)
          When set to T this control no longer shows errors.
 void setEditorFactory(IRowEditorFactory<T,? extends NodeContainer> editorFactory)
           
 void setEnableAddingItems(boolean enableAddingItems)
          When set items are added to the table by calling IModifyableTableModel.add(Object) when the new row action executed succesfully.
 void setEnableDeleteButton(boolean enableDeleteButton)
           
 void setEnableExpandItems(boolean enableExpandItems)
           
 void setEnableRowEdit(boolean enableRowEdit)
           
 void setHideHeader(boolean hideHeader)
           
 void setHideIndex(boolean hideIndex)
           
 void setModified(boolean as)
          Set or clear the modified by user flag.
 void setNewAtStart(boolean newAtStart)
           
 void setOnRowChangeCompleted(IRowEditorEvent<T,?> onRowChangeCompleted)
          Set a handler to call when editing a row in an editable table component after editing is (somehow) marked as complete.
 void setRowButtonFactory(IRowButtonFactory<T> rowButtonFactory)
          Returns the button factory to use to add buttons to a row, when needed.
 void setTableWidth(java.lang.String w)
           
protected  void toggleExpanded(int index)
          If the selected row is collapsed it gets expanded; if it is expanded it's values get moved to the model and if that worked the row gets collapsed.
 
Methods inherited from class to.etc.domui.component.tbl.TableModelTableBase
fireModelChanged, firePageChanged, getModel, getModelItem, onRefresh, onShelve, onUnshelve, setModel
 
Methods inherited from class to.etc.domui.dom.html.Div
afterCreateContent, componentHandleWebAction, fadeIn, fadeOut, getCustomUpdatesCallJS, getDragHandler, getDropBody, getDropHandler, getDropMode, getReturnPressed, setDragHandler, setDropBody, setDropHandler, setReturnPressed, slideDown, slideUp, tb, visit
 
Methods inherited from class to.etc.domui.dom.html.NodeContainer
add, add, add, addTable, canContain, delegateTo, findChildIndex, forceRebuild, getChild, getChildCount, getChildren, getDeepChild, getDeepChildren, getErrorFence, internalCheckNotDirty, internalClearDelta, internalClearDeltaFully, internalGetOldChildren, internalShelve, internalUnshelve, iterator, moveControlToModel, moveModelToControl, removeAllChildren, removeChild, removeChild, replaceChild, setControlsEnabled, setErrorFence, setErrorFence, setText, setValue
 
Methods inherited from class to.etc.domui.dom.html.NodeBase
$, acceptRequestParameter, addCssClass, addGlobalMessage, appendAfterMe, appendBeforeMe, appendCreateJS, appendJavascript, build, changed, clearFocusRequested, clearGlobalMessage, clearGlobalMessage, clearGlobalMessage, clearMessage, findComponentBundle, getActualID, getAllocationTracepoint, getClicked, getComponentBundle, getCreateJS, getCssClass, getErrorDelegate, getErrorLocation, getMessage, getOnClickJS, getOnMouseDownJS, getPage, getParent, getParent, getParent, getSharedContext, getSpecialAttribute, getSpecialAttributeList, getTag, getTestID, getTitle, getUserObject, handleDrop, hasCssClass, hasError, internalGetOldParent, internalHasChangedAttributes, internalNeedClickHandler, internalOnClicked, internalOnValueChanged, internalSetHasChangedAttributes, internalSetHasChangedAttributes, internalSetLogAllocations, internalSetTag, isBuilt, isFocusRequested, isStretchHeight, onAddedToPage, onBeforeFullRender, onForceRebuild, onHeaderContributors, onRemoveFromPage, refresh, remove, removeCssClass, renderJavascriptState, replaceWith, setClicked, setComponentBundle, setCssClass, setErrorDelegate, setErrorLocation, setFocus, setMessage, setOnClickJS, setOnMouseDownJS, setSpecialAttribute, setStretchHeight, setTestID, setTitle, setUserObject, toString
 
Methods inherited from class to.etc.domui.dom.css.CssBase
getBackgroundAttachment, getBackgroundColor, getBackgroundImage, getBackgroundPosition, getBackgroundRepeat, getBorderBottomColor, getBorderBottomStyle, getBorderBottomWidth, getBorderLeftColor, getBorderLeftStyle, getBorderLeftWidth, getBorderRightColor, getBorderRightStyle, getBorderRightWidth, getBorderTopColor, getBorderTopStyle, getBorderTopWidth, getBottom, getCachedStyle, getClear, getColor, getDisplay, getFloat, getFontFamily, getFontSize, getFontSizeAdjust, getFontStyle, getFontVariant, getFontWeight, getHeight, getLeft, getLineHeight, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOverflow, getPosition, getRight, getTextAlign, getTop, getTransform, getVerticalAlign, getVisibility, getWidth, getZIndex, internalSetDisplay, setBackgroundAttachment, setBackgroundColor, setBackgroundImage, setBackgroundPosition, setBackgroundRepeat, setBorder, setBorder, setBorderBottomColor, setBorderBottomStyle, setBorderBottomWidth, setBorderColor, setBorderLeftColor, setBorderLeftStyle, setBorderLeftWidth, setBorderRightColor, setBorderRightStyle, setBorderRightWidth, setBorderStyle, setBorderTopColor, setBorderTopStyle, setBorderTopWidth, setBorderWidth, setBottom, setBottom, setCachedStyle, setClear, setColor, setDisplay, setFloat, setFontFamily, setFontSize, setFontSizeAdjust, setFontStyle, setFontVariant, setFontWeight, setHeight, setLeft, setLeft, setLineHeight, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setOverflow, setPosition, setRight, setRight, setTextAlign, setTop, setTop, setTransform, setVerticalAlign, setVisibility, setWidth, setZIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpandingEditTable

public ExpandingEditTable(@Nonnull
                          java.lang.Class<T> actualClass,
                          @Nonnull
                          ITableModel<T> m,
                          @Nonnull
                          IRowRenderer<T> r)

ExpandingEditTable

public ExpandingEditTable(@Nonnull
                          ITableModel<T> m,
                          @Nonnull
                          IRowRenderer<T> r)
Method Detail

createContent

public void createContent()
                   throws java.lang.Exception
Create the structure [(div=self)][ErrorMessageDiv][table]

Overrides:
createContent in class NodeBase
Throws:
java.lang.Exception
See Also:
NodeBase.createContent()

getPageItems

@Nonnull
protected java.util.List<T> getPageItems()
                                  throws java.lang.Exception
Returns all items in the list.

Returns:
Throws:
java.lang.Exception

toggleExpanded

protected void toggleExpanded(int index)
                       throws java.lang.Exception
If the selected row is collapsed it gets expanded; if it is expanded it's values get moved to the model and if that worked the row gets collapsed.

Parameters:
index -
Throws:
java.lang.Exception

collapseRow

public void collapseRow(int index)
                 throws java.lang.Exception
Throws:
java.lang.Exception

expandRow

public void expandRow(int index)
               throws java.lang.Exception
Throws:
java.lang.Exception

addNew

public void addNew(@Nonnull
                   T instance)
            throws java.lang.Exception
Make the control enter ADD NEW mode for the specified instance. The previous NEW row, if present, is commited if possible; if that fails we exit with an exception. After that we create a new edit row at the end or the start of the table and edit it. This version uses an IModifyableTableModel to do the actual adding of the item to the model.

Parameters:
instance -
Throws:
java.lang.Exception

cancelNew

public void cancelNew()

commitNewRow

protected void commitNewRow()
                     throws java.lang.Exception
Throws:
java.lang.Exception

modelChanged

public void modelChanged(@Nullable
                         ITableModel<T> model)
Called when there are sweeping changes to the model. It forces a complete re-render of the table.

Specified by:
modelChanged in interface ITableModelListener<T>

rowAdded

public void rowAdded(@Nonnull
                     ITableModel<T> model,
                     int index,
                     @Nullable
                     T value)
              throws java.lang.Exception
A record is added. Add a collapsed row at the required position.

Specified by:
rowAdded in interface ITableModelListener<T>
Throws:
java.lang.Exception
See Also:
ITableModelListener.rowAdded(to.etc.domui.component.tbl.ITableModel, int, java.lang.Object)

rowDeleted

public void rowDeleted(@Nonnull
                       ITableModel<T> model,
                       int index,
                       @Nullable
                       T value)
                throws java.lang.Exception
Delete the row specified. If it is not visible we do nothing. If it is visible we delete the row. This causes one less row to be shown, so we check if we have a pagesize set; if so we add a new row at the end IF it is available.

Specified by:
rowDeleted in interface ITableModelListener<T>
index - The index of the deleted row in the table.
value - The deleted value.
Throws:
java.lang.Exception
See Also:
ITableModelListener.rowDeleted(to.etc.domui.component.tbl.ITableModel, int, java.lang.Object)

rowModified

public void rowModified(@Nonnull
                        ITableModel<T> model,
                        int index,
                        @Nullable
                        T value)
                 throws java.lang.Exception
When a row is modified we redraw the row in collapsed mode; if it was in edit mode before bad luck.

Specified by:
rowModified in interface ITableModelListener<T>
Throws:
java.lang.Exception
See Also:
ITableModelListener.rowModified(to.etc.domui.component.tbl.ITableModel, int, java.lang.Object)

isModified

public boolean isModified()
Returns the modified-by-user flag.

Specified by:
isModified in interface IHasModifiedIndication
See Also:
IHasModifiedIndication.isModified()

setModified

public void setModified(boolean as)
Set or clear the modified by user flag.

Specified by:
setModified in interface IHasModifiedIndication
See Also:
IHasModifiedIndication.setModified(boolean)

getTable

@Nonnull
protected Table getTable()
Return the backing table for this data browser. For component extension only - DO NOT MAKE PUBLIC.

Returns:

setTableWidth

public void setTableWidth(@Nullable
                          java.lang.String w)

isHideHeader

public boolean isHideHeader()
When set the table will not render a THead.

Returns:

setHideHeader

public void setHideHeader(boolean hideHeader)

isHideIndex

public boolean isHideIndex()
When set the index number before the row is not shown.

Returns:

setHideIndex

public void setHideIndex(boolean hideIndex)

setDisableErrors

public void setDisableErrors(boolean on)
When set to T this control no longer shows errors.

Parameters:
on -

isDisableErrors

public boolean isDisableErrors()
Returns T if this control's error handling has been disabled, causing the parent to handle errors instead of showing the errors in the control.

Returns:

isNewAtStart

public boolean isNewAtStart()
By default new rows are edited @ the end; set this to edit @ the start.


setNewAtStart

public void setNewAtStart(boolean newAtStart)

getEditorFactory

@Nullable
public IRowEditorFactory<T,? extends NodeContainer> getEditorFactory()
Return the editor factory to use to create the row editor. If null we'll use a default editor.

Returns:

setEditorFactory

public void setEditorFactory(@Nullable
                             IRowEditorFactory<T,? extends NodeContainer> editorFactory)

getRowButtonFactory

@Nullable
public IRowButtonFactory<T> getRowButtonFactory()
Returns the button factory to use to add buttons to a row, when needed.

Returns:

setRowButtonFactory

public void setRowButtonFactory(@Nullable
                                IRowButtonFactory<T> rowButtonFactory)
Returns the button factory to use to add buttons to a row, when needed. When set it disables the automatic rendering of the delete button.

Parameters:
rowButtonFactory -

getOnRowChangeCompleted

@Nullable
public IRowEditorEvent<T,?> getOnRowChangeCompleted()
Set a handler to call when editing a row in an editable table component after editing is (somehow) marked as complete. When called the editor's contents has to be handled (f.e. instance should be added to the model by using the bindings. This method can also be used to check the data for validity or to check for duplicates, for instance by using MetaManager.hasDuplicates(java.util.List, Object, String).

Returns:

setOnRowChangeCompleted

public void setOnRowChangeCompleted(@Nullable
                                    IRowEditorEvent<T,?> onRowChangeCompleted)
Set a handler to call when editing a row in an editable table component after editing is (somehow) marked as complete. When called the editor's contents has to be handled (f.e. instance should be added to the model by using the bindings. This method can also be used to check the data for validity or to check for duplicates, for instance by using MetaManager.hasDuplicates(java.util.List, Object, String).

Parameters:
onNewComplete -

isEnableDeleteButton

public boolean isEnableDeleteButton()
When T (the default) this component will render a 'delete' linkbutton in the button area after the row, for every row present. Pressing this button will cause the row to be deleted unconditionally.

This is only very basic functionality. To make it better just disable the this and use setRowButtonFactory(IRowButtonFactory) to define your own method to add buttons; allowing for way more complex interactions.

Returns:

setEnableDeleteButton

public void setEnableDeleteButton(boolean enableDeleteButton)

isEnableAddingItems

public boolean isEnableAddingItems()
When set (the default) items are added to the table by calling IModifyableTableModel.add(Object) when the new row action executed succesfully.

Returns:

setEnableAddingItems

public void setEnableAddingItems(boolean enableAddingItems)
When set items are added to the table by calling IModifyableTableModel.add(Object) when the new row action executed succesfully.

Parameters:
enableAddingItems -

collapseAllExpandedRows

public boolean collapseAllExpandedRows()
                                throws java.lang.Exception
When executed, method would try to collapse all currently expanded rows. In case that some row can not be collapsed, method would return false, that means that probably data validation has failed on some expanded row.

Returns:
Throws:
java.lang.Exception

isEnableExpandItems

public boolean isEnableExpandItems()

setEnableExpandItems

public void setEnableExpandItems(boolean enableExpandItems)

isEnableRowEdit

public boolean isEnableRowEdit()

setEnableRowEdit

public void setEnableRowEdit(boolean enableRowEdit)