org.cruxframework.crux.widgets.client.grid
Class AbstractGrid<R extends Row>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Composite
              extended by org.cruxframework.crux.widgets.client.grid.AbstractGrid<R>
All Implemented Interfaces:
com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, HasBeforeCancelRowEditionHandler, HasBeforeRowEditHandlers, HasBeforeSaveRowEditionHandler, HasBeforeShowDetailsHandlers, HasCancelRowEditionHandler, HasLoadRowDetailsHandlers, HasRowClickHandlers, HasRowDoubleClickHandlers, HasRowEditHandlers, HasRowEditingHandlers, HasRowRenderHandlers, HasShowRowDetailsHandlers
Direct Known Subclasses:
Grid

public abstract class AbstractGrid<R extends Row>
extends com.google.gwt.user.client.ui.Composite
implements HasRowClickHandlers, HasRowDoubleClickHandlers, HasRowRenderHandlers, HasBeforeShowDetailsHandlers, HasShowRowDetailsHandlers, HasLoadRowDetailsHandlers, HasBeforeRowEditHandlers, HasRowEditHandlers, HasBeforeSaveRowEditionHandler, HasBeforeCancelRowEditionHandler, HasCancelRowEditionHandler, HasRowEditingHandlers

Base class for implementing grids. All subclasses must invoke the method render() in their constructors.

Author:
Gesse Dafe

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
protected  org.cruxframework.crux.core.client.collection.FastList<BeforeCancelRowEditionHandler> beforeCancelRowEditionHandlers
           
protected  org.cruxframework.crux.core.client.collection.FastList<BeforeSaveRowEditionHandler> beforeSaveRowEditionHandlers
           
protected  ColumnDefinitions definitions
           
protected  boolean freezeHeaders
           
protected  String generatedId
           
protected  Boolean hasFrozenColumns
           
protected  boolean highlightRowOnMouseOver
           
protected  RowDetailWidgetCreator rowDetailWidgetCreator
           
protected  org.cruxframework.crux.core.client.collection.FastList<R> rows
           
protected  RowSelectionModel rowSelection
           
protected  com.google.gwt.user.client.ui.ScrollPanel scrollingArea
           
protected  boolean showRowDetailsIcon
           
protected  boolean stretchColumns
           
protected  GridBaseTable table
           
protected  Map<com.google.gwt.user.client.ui.Widget,R> widgetsPerRow
           
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
AbstractGrid(ColumnDefinitions columnDefinitions, RowSelectionModel rowSelection, int cellSpacing, boolean stretchColumns, boolean highlightRowOnMouseOver, boolean fixedCellSize)
          Full constructor
AbstractGrid(ColumnDefinitions columnDefinitions, RowSelectionModel rowSelection, int cellSpacing, boolean stretchColumns, boolean highlightRowOnMouseOver, boolean fixedCellSize, RowDetailWidgetCreator rowDetailWidgetCreator, boolean showRowDetailsIcon, boolean freezeHeaders)
          Full constructor
 
Method Summary
 com.google.gwt.event.shared.HandlerRegistration addBeforeCancelRowEditionHandler(BeforeCancelRowEditionHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addBeforeRowEditHandler(BeforeRowEditHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addBeforeSaveRowEditionHandler(BeforeSaveRowEditionHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addBeforeShowRowDetailsHandler(BeforeShowRowDetailsHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addCancelRowEditionHandler(CancelRowEditionHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addLoadRowDetailsHandler(LoadRowDetailsHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addRowClickHandler(RowClickHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addRowDoubleClickHandler(RowDoubleClickHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addRowEditHandler(RowEditHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addRowEditingHandler(RowEditingHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addRowRenderHandler(RowRenderHandler handler)
           
 void addScrollHandler(com.google.gwt.event.dom.client.ScrollHandler handler)
           
 com.google.gwt.event.shared.HandlerRegistration addShowRowDetailsHandler(ShowRowDetailsHandler handler)
           
 void clear()
          Clears all grid rows
protected  void clearRendering()
          Resizes the grid table, according with the number of rows that will be rendered.
protected  Cell createBaseCell(com.google.gwt.user.client.ui.Widget widget, boolean fireEvents, boolean selectRowOnclick, boolean highlightRowOnMouseOver, boolean wrapLine, boolean truncate)
          Creates a basic (no style) cell
protected  Cell createCell(com.google.gwt.user.client.ui.Widget widget, boolean wrapLine, boolean truncate)
          Creates a cell
protected  Cell createColumnHeaderCell(ColumnDefinition columnDefinition)
          Creates a cell that will be used as the header for the given column
protected  Cell createHeaderCell(com.google.gwt.user.client.ui.Widget widget)
          Creates a header styled cell
protected abstract  R createRow(int index, com.google.gwt.dom.client.Element element)
          Creates a row
protected  void ensureVisible(com.google.gwt.user.client.ui.UIObject uiObject)
           
protected abstract  boolean fireBeforeCancelRowEditionEvent(R row)
           
protected abstract  void fireBeforeRowEditEvent(R row)
          Fires a before row edit event
protected abstract  boolean fireBeforeSaveRowEditionEvent(R row)
          Fires a row saving event
protected abstract  void fireCancelRowEditionEvent(R row)
           
protected abstract  void fireRowClickEvent(R row)
          Fires a row click event
protected abstract  void fireRowDoubleClickEvent(R row)
          Fires a row double click event
protected abstract  void fireRowEditEvent(R row)
          Fires a row edit event
protected abstract  void fireRowEditingEvent(R row)
          Fires a row editing event
protected abstract  void fireRowRenderEvent(R row)
          Fires a row rendering event
 ColumnDefinition getColumnDefinition(String key)
           
protected  ColumnDefinitions getColumnDefinitions()
          Gets the grid columns (including the invisible columns)
abstract  List<R> getCurrentPageRows()
          Gets all grid rows
 R getRow(com.google.gwt.user.client.ui.Widget w)
          Gets the row where the given widget is rendered
 RowDetailWidgetCreator getRowDetailWidgetCreator()
           
protected  Iterator<R> getRowIterator()
          Gets an iterator for the grid rows
 RowSelectionModel getRowSelectionModel()
           
protected abstract  int getRowsToBeRendered()
           
abstract  List<R> getSelectedRows()
          Gets the selected rows from the current visible page.
 boolean hasFrozenCells()
           
 boolean hasFrozenColumns()
           
 boolean hasFrozenHeaders()
           
protected  boolean hasRowDetails()
          Returns true if the grid has the row-details feature
protected  boolean hasRowDetailsIconColumn()
          Returns true if the grid has a column containing icons that expand or collapse row's details
protected  boolean hasSelectionColumn()
           
protected abstract  void onBeforeRender()
          Return true if the grid can be rendered
protected abstract  void onBeforeRenderRows()
          Callback for before rendering the rows
protected abstract  void onClear()
          Callback for grid clearing
protected abstract  void onClearRendering()
          Callback for before clearing the rows contents
protected abstract  boolean onSelectRow(boolean select, R row, boolean fireEvents)
          Callback for row selection
protected abstract  boolean onShowDetails(boolean show, Row row, boolean fireEvents)
          Executes the implementation-specific logic of showing the details of a row.
 void refresh()
          Repaints the grid
protected  void render()
          Renders the grid.
protected  void renderHeaders(int rowCount)
          Renders the columns headers
protected abstract  void renderRow(R row)
          Renders the given row cells
protected  void renderRows()
          Renders the grid rows
protected  void resetColumnDefinitions()
           
 void selectCurrentPageRows(boolean select, boolean fireEvents)
          Selects or deselects all enabled rows
 void setRowSelectionModel(RowSelectionModel rowSelectionModel)
           
 
Methods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Field Detail

table

protected GridBaseTable table

definitions

protected ColumnDefinitions definitions

generatedId

protected String generatedId

rows

protected org.cruxframework.crux.core.client.collection.FastList<R extends Row> rows

widgetsPerRow

protected Map<com.google.gwt.user.client.ui.Widget,R extends Row> widgetsPerRow

rowSelection

protected RowSelectionModel rowSelection

scrollingArea

protected com.google.gwt.user.client.ui.ScrollPanel scrollingArea

stretchColumns

protected boolean stretchColumns

highlightRowOnMouseOver

protected boolean highlightRowOnMouseOver

rowDetailWidgetCreator

protected RowDetailWidgetCreator rowDetailWidgetCreator

showRowDetailsIcon

protected boolean showRowDetailsIcon

freezeHeaders

protected boolean freezeHeaders

hasFrozenColumns

protected Boolean hasFrozenColumns

beforeSaveRowEditionHandlers

protected org.cruxframework.crux.core.client.collection.FastList<BeforeSaveRowEditionHandler> beforeSaveRowEditionHandlers

beforeCancelRowEditionHandlers

protected org.cruxframework.crux.core.client.collection.FastList<BeforeCancelRowEditionHandler> beforeCancelRowEditionHandlers
Constructor Detail

AbstractGrid

public AbstractGrid(ColumnDefinitions columnDefinitions,
                    RowSelectionModel rowSelection,
                    int cellSpacing,
                    boolean stretchColumns,
                    boolean highlightRowOnMouseOver,
                    boolean fixedCellSize)
Full constructor

Parameters:
columnDefinitions - the columns to be rendered
rowSelection - the behavior of the grid about line selection
cellSpacing - the space between the cells
stretchColumns -
fixedCellSize -

AbstractGrid

public AbstractGrid(ColumnDefinitions columnDefinitions,
                    RowSelectionModel rowSelection,
                    int cellSpacing,
                    boolean stretchColumns,
                    boolean highlightRowOnMouseOver,
                    boolean fixedCellSize,
                    RowDetailWidgetCreator rowDetailWidgetCreator,
                    boolean showRowDetailsIcon,
                    boolean freezeHeaders)
Full constructor

Parameters:
columnDefinitions - the columns to be rendered
rowSelection - the behavior of the grid about line selection
cellSpacing - the space between the cells
stretchColumns -
fixedCellSize -
rowDetailsDefinition -
showRowDetailsIcon -
Method Detail

onShowDetails

protected abstract boolean onShowDetails(boolean show,
                                         Row row,
                                         boolean fireEvents)
Executes the implementation-specific logic of showing the details of a row.

Parameters:
show -
row -
fireEvents -

addRowClickHandler

public com.google.gwt.event.shared.HandlerRegistration addRowClickHandler(RowClickHandler handler)
Specified by:
addRowClickHandler in interface HasRowClickHandlers
See Also:
HasRowClickHandlers.addRowClickHandler(org.cruxframework.crux.widgets.client.event.row.RowClickHandler)

addRowDoubleClickHandler

public com.google.gwt.event.shared.HandlerRegistration addRowDoubleClickHandler(RowDoubleClickHandler handler)
Specified by:
addRowDoubleClickHandler in interface HasRowDoubleClickHandlers
See Also:
HasRowDoubleClickHandlers.addRowDoubleClickHandler(org.cruxframework.crux.widgets.client.event.row.RowDoubleClickHandler)

addRowRenderHandler

public com.google.gwt.event.shared.HandlerRegistration addRowRenderHandler(RowRenderHandler handler)
Specified by:
addRowRenderHandler in interface HasRowRenderHandlers
See Also:
HasRowRenderHandlers.addRowRenderHandler(org.cruxframework.crux.widgets.client.event.row.RowRenderHandler)

addBeforeShowRowDetailsHandler

public com.google.gwt.event.shared.HandlerRegistration addBeforeShowRowDetailsHandler(BeforeShowRowDetailsHandler handler)
Specified by:
addBeforeShowRowDetailsHandler in interface HasBeforeShowDetailsHandlers
See Also:
br.com.sysmap.crux.widgets.client.event.row.HasBeforeShowDetailsHandlers#addBeforeShowRowDetailsHandler(br.com.sysmap.crux.widgets.client.event.row.BeforeShowDetailsHandler)

addShowRowDetailsHandler

public com.google.gwt.event.shared.HandlerRegistration addShowRowDetailsHandler(ShowRowDetailsHandler handler)
Specified by:
addShowRowDetailsHandler in interface HasShowRowDetailsHandlers
See Also:
br.com.sysmap.crux.widgets.client.event.row.HasShowRowDetailsHandlers#addShowRowDetailsHandler(br.com.sysmap.crux.widgets.client.event.row.ShowRowDetailsHandler)

addBeforeRowEditHandler

public com.google.gwt.event.shared.HandlerRegistration addBeforeRowEditHandler(BeforeRowEditHandler handler)
Specified by:
addBeforeRowEditHandler in interface HasBeforeRowEditHandlers
See Also:
HasBeforeRowEditHandlers.addBeforeRowEditHandler(org.cruxframework.crux.widgets.client.event.row.BeforeRowEditHandler)

addCancelRowEditionHandler

public com.google.gwt.event.shared.HandlerRegistration addCancelRowEditionHandler(CancelRowEditionHandler handler)
Specified by:
addCancelRowEditionHandler in interface HasCancelRowEditionHandler
See Also:
HasCancelRowEditionHandler.addCancelRowEditionHandler(org.cruxframework.crux.widgets.client.event.row.CancelRowEditionHandler)

addBeforeCancelRowEditionHandler

public com.google.gwt.event.shared.HandlerRegistration addBeforeCancelRowEditionHandler(BeforeCancelRowEditionHandler handler)
Specified by:
addBeforeCancelRowEditionHandler in interface HasBeforeCancelRowEditionHandler
See Also:
HasBeforeCancelRowEditionHandler.addBeforeCancelRowEditionHandler(org.cruxframework.crux.widgets.client.event.row.BeforeCancelRowEditionHandler)

addRowEditHandler

public com.google.gwt.event.shared.HandlerRegistration addRowEditHandler(RowEditHandler handler)
Specified by:
addRowEditHandler in interface HasRowEditHandlers
See Also:
HasRowEditHandlers.addRowEditHandler(org.cruxframework.crux.widgets.client.event.row.RowEditHandler)

addRowEditingHandler

public com.google.gwt.event.shared.HandlerRegistration addRowEditingHandler(RowEditingHandler handler)
Specified by:
addRowEditingHandler in interface HasRowEditingHandlers
See Also:
HasRowEditHandlers.addRowEditHandler(org.cruxframework.crux.widgets.client.event.row.RowEditHandler)

addLoadRowDetailsHandler

public com.google.gwt.event.shared.HandlerRegistration addLoadRowDetailsHandler(LoadRowDetailsHandler handler)
Specified by:
addLoadRowDetailsHandler in interface HasLoadRowDetailsHandlers
See Also:
br.com.sysmap.crux.widgets.client.event.row.HasLoadRowDetailsHandlers#addLoadRowDetailsHandler(br.com.sysmap.crux.widgets.client.event.row.LoadRowDetailsHandler)

addBeforeSaveRowEditionHandler

public com.google.gwt.event.shared.HandlerRegistration addBeforeSaveRowEditionHandler(BeforeSaveRowEditionHandler handler)
Specified by:
addBeforeSaveRowEditionHandler in interface HasBeforeSaveRowEditionHandler
See Also:
HasBeforeSaveRowEditionHandler.addBeforeSaveRowEditionHandler(org.cruxframework.crux.widgets.client.event.row.BeforeSaveRowEditionHandler)

addScrollHandler

public void addScrollHandler(com.google.gwt.event.dom.client.ScrollHandler handler)

clear

public void clear()
Clears all grid rows


getRow

public R getRow(com.google.gwt.user.client.ui.Widget w)
Gets the row where the given widget is rendered

Parameters:
w - a widget rendered inside a row
Returns:
a Row that contains the given widget. Null if no such row found.;

getSelectedRows

public abstract List<R> getSelectedRows()
Gets the selected rows from the current visible page.

Returns:
a List containing the selected rows

getCurrentPageRows

public abstract List<R> getCurrentPageRows()
Gets all grid rows

Returns:
a List containing the rows

refresh

public void refresh()
Repaints the grid


getColumnDefinition

public ColumnDefinition getColumnDefinition(String key)
Parameters:
key -
Returns:

getRowIterator

protected Iterator<R> getRowIterator()
Gets an iterator for the grid rows

Returns:
an iterator

createCell

protected Cell createCell(com.google.gwt.user.client.ui.Widget widget,
                          boolean wrapLine,
                          boolean truncate)
Creates a cell

Parameters:
widget - the content of the cell
Returns:

createColumnHeaderCell

protected Cell createColumnHeaderCell(ColumnDefinition columnDefinition)
Creates a cell that will be used as the header for the given column

Parameters:
columnDefinition -
Returns:
the newly created cell

createBaseCell

protected Cell createBaseCell(com.google.gwt.user.client.ui.Widget widget,
                              boolean fireEvents,
                              boolean selectRowOnclick,
                              boolean highlightRowOnMouseOver,
                              boolean wrapLine,
                              boolean truncate)
Creates a basic (no style) cell

Parameters:
widget -
fireEvents -
selectRowOnclick -
Returns:

createHeaderCell

protected Cell createHeaderCell(com.google.gwt.user.client.ui.Widget widget)
Creates a header styled cell

Parameters:
widget - the content of the cell
Returns:
the new cell

createRow

protected abstract R createRow(int index,
                               com.google.gwt.dom.client.Element element)
Creates a row

Parameters:
index - the position of the row (zero based)
element - the row HTML element (TR)
Returns:

getColumnDefinitions

protected ColumnDefinitions getColumnDefinitions()
Gets the grid columns (including the invisible columns)

Returns:

getRowsToBeRendered

protected abstract int getRowsToBeRendered()
Returns:
the number of rows that will be rendered, less the header row

hasSelectionColumn

protected boolean hasSelectionColumn()
Returns:
true if grid rows must contain a special cell with a widget for selecting them.

onClearRendering

protected abstract void onClearRendering()
Callback for before clearing the rows contents


onBeforeRenderRows

protected abstract void onBeforeRenderRows()
Callback for before rendering the rows


onClear

protected abstract void onClear()
Callback for grid clearing


onSelectRow

protected abstract boolean onSelectRow(boolean select,
                                       R row,
                                       boolean fireEvents)
Callback for row selection

Parameters:
select - true if the row was selected, false if deselected
row -

render

protected void render()
Renders the grid. The subclasses should call this method for rendering themselves.


resetColumnDefinitions

protected void resetColumnDefinitions()

onBeforeRender

protected abstract void onBeforeRender()
Return true if the grid can be rendered


renderRow

protected abstract void renderRow(R row)
Renders the given row cells

Parameters:
row -

fireRowClickEvent

protected abstract void fireRowClickEvent(R row)
Fires a row click event

Parameters:
row -

fireRowEditEvent

protected abstract void fireRowEditEvent(R row)
Fires a row edit event

Parameters:
row -

fireBeforeRowEditEvent

protected abstract void fireBeforeRowEditEvent(R row)
Fires a before row edit event

Parameters:
row -

fireRowEditingEvent

protected abstract void fireRowEditingEvent(R row)
Fires a row editing event

Parameters:
row -

fireRowDoubleClickEvent

protected abstract void fireRowDoubleClickEvent(R row)
Fires a row double click event

Parameters:
row -

fireRowRenderEvent

protected abstract void fireRowRenderEvent(R row)
Fires a row rendering event

Parameters:
row -

fireBeforeSaveRowEditionEvent

protected abstract boolean fireBeforeSaveRowEditionEvent(R row)
Fires a row saving event

Parameters:
row -

fireBeforeCancelRowEditionEvent

protected abstract boolean fireBeforeCancelRowEditionEvent(R row)
Parameters:
row -
Returns:

fireCancelRowEditionEvent

protected abstract void fireCancelRowEditionEvent(R row)
Parameters:
row -

clearRendering

protected void clearRendering()
Resizes the grid table, according with the number of rows that will be rendered.


renderHeaders

protected void renderHeaders(int rowCount)
Renders the columns headers

Parameters:
rowCount -

renderRows

protected void renderRows()
Renders the grid rows


selectCurrentPageRows

public void selectCurrentPageRows(boolean select,
                                  boolean fireEvents)
Selects or deselects all enabled rows

Parameters:
select - true for select, false for deselect
fireEvents - if true, fires a BeforeRowSelectEvent for each enabled row

hasRowDetails

protected boolean hasRowDetails()
Returns true if the grid has the row-details feature

Returns:

hasRowDetailsIconColumn

protected boolean hasRowDetailsIconColumn()
Returns true if the grid has a column containing icons that expand or collapse row's details

Returns:

ensureVisible

protected void ensureVisible(com.google.gwt.user.client.ui.UIObject uiObject)
Parameters:
uiObject -

getRowDetailWidgetCreator

public RowDetailWidgetCreator getRowDetailWidgetCreator()
Returns:
the rowDetailWidgetCreator

hasFrozenHeaders

public boolean hasFrozenHeaders()

hasFrozenColumns

public boolean hasFrozenColumns()

hasFrozenCells

public boolean hasFrozenCells()

getRowSelectionModel

public RowSelectionModel getRowSelectionModel()

setRowSelectionModel

public void setRowSelectionModel(RowSelectionModel rowSelectionModel)


Copyright © 2015. All rights reserved.