org.eclipse.nebula.widgets.nattable.viewport
Class ViewportLayer

java.lang.Object
  extended by org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
      extended by org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
          extended by org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer
All Implemented Interfaces:
ILayer, ILayerListener, IUniqueIndexLayer, IPersistable
Direct Known Subclasses:
ViewportLayerFixture

public class ViewportLayer
extends AbstractLayerTransform
implements IUniqueIndexLayer

Viewport - the visible area of NatTable Places a 'viewport' over the table. Introduces scroll bars over the table and keeps them in sync with the data being displayed. This is typically placed over the SelectionLayer.


Field Summary
 
Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
underlyingLayer
 
Fields inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
commandHandlers, eventHandlers, layerPainter
 
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
 
Constructor Summary
ViewportLayer(IUniqueIndexLayer underlyingLayer)
           
 
Method Summary
protected  int adjustOriginX(int originX)
          If the client area size is greater than the content size, move origin to fill as much content as possible.
protected  int adjustOriginY(int originY)
          If the client area size is greater than the content size, move origin to fill as much content as possible.
 void dispose()
           
 boolean doCommand(ILayerCommand command)
          Opportunity to respond to a command as it flows down the stack.
 void drag(int x, int y)
          Used for edge hover scrolling.
 void drag(SelectionLayer.MoveDirectionEnum horizontal, SelectionLayer.MoveDirectionEnum vertical)
          Used to scroll in the given direction on drag operations outside the visible region.
protected  void fireScrollEvent()
           
 org.eclipse.swt.graphics.Rectangle getBoundsByPosition(int columnPosition, int rowPosition)
          Calculates the bounds in pixel for the given cell position.
 int getClientAreaHeight()
           
 int getClientAreaWidth()
           
 int getColumnCount()
           
 int getColumnPositionByIndex(int columnIndex)
           
 int getColumnPositionByX(int x)
          Returns the column position that contains the given x coordinate.
 int getColumnWidthByPosition(int columnPosition)
          Returns the width in pixels of the given column.
 int getHeight()
          Returns the total height in pixels of this layer.
 int getMaxColumnPosition()
           
 int getMaxHeight()
           
 int getMaxRowPosition()
           
 int getMaxWidth()
           
 int getMinColumnPosition()
           
 int getMinHorizontalStart()
           
 PixelCoordinate getMinimumOrigin()
           
 int getMinimumOriginColumnPosition()
           
 int getMinimumOriginRowPosition()
           
 int getMinRowPosition()
           
 int getMinVerticalStart()
           
 PixelCoordinate getOrigin()
           
 int getRowCount()
           
 int getRowHeightByPosition(int rowPosition)
          Returns the height in pixels of the given row.
 int getRowPositionByIndex(int rowIndex)
           
 int getRowPositionByY(int y)
          Returns the row position that contains the given y coordinate.
 IUniqueIndexLayer getScrollableLayer()
           
 int getStartXOfColumnPosition(int columnPosition)
          Returns the x offset in pixels of the given column.
 int getStartYOfRowPosition(int rowPosition)
          Returns the y offset in pixels of the given row.
 int getWidth()
          Returns the total width in pixels of this layer.
protected  void handleGridResize()
          Recalculate viewport characteristics when the grid has been resized.
 void handleLayerEvent(ILayerEvent event)
          Handle layer event notification.
 void invalidateHorizontalStructure()
          Clear horizontal caches
 void invalidateVerticalStructure()
          Clear vertical caches
 boolean isColumnPositionResizable(int columnPosition)
           
protected  boolean isLastColumnCompletelyDisplayed()
           
protected  boolean isLastRowCompletelyDisplayed()
           
 int localToUnderlyingColumnPosition(int localColumnPosition)
          Convert a column position to the coordinates of the underlying layer.
 int localToUnderlyingRowPosition(int localRowPosition)
           
 void moveCellPositionIntoViewport(int scrollableColumnPosition, int scrollableRowPosition)
          Srcolls the table so that the specified cell is visible i.e.
 void moveColumnPositionIntoViewport(int scrollableColumnPosition)
          Scrolls the viewport (if required) so that the specified column is visible.
 void moveRowPositionIntoViewport(int scrollableRowPosition)
           
protected  void recalculateAvailableHeightAndRowCount()
          Recalculate vertical dimension properties.
protected  void recalculateAvailableWidthAndColumnCount()
          Recalculate horizontal dimension properties.
 void recalculateScrollBars()
          Recalculate scrollbar characteristics.
protected  void registerCommandHandlers()
          Layers should use this method to register their command handlers and call it from their constructor.
 void resetOrigin(int newOriginX, int newOriginY)
          Reset the origin pixel position to the given values.
 void scrollVerticallyByAPage(ScrollSelectionCommand scrollSelectionCommand)
          Scrolls the viewport vertically by a page.
protected  MoveSelectionCommand scrollVerticallyByAPageCommand(ScrollSelectionCommand scrollSelectionCommand)
           
 void setHorizontalScrollbarEnabled(boolean enabled)
          Enable/disable the horizontal scrollbar in this ViewportLayer.
 void setHorizontalScroller(IScroller<?> scroller)
          Set a different horizontal scroller than the default one.
 void setMaxColumnPosition(int maxColumnPosition)
           
 void setMaxRowPosition(int maxRowPosition)
           
 void setMinColumnPosition(int minColumnPosition)
          Sets the minimum column position for a split viewport and directly sets the minimum origin x value dependent on the configuration.
 void setMinimumOrigin(int newMinimumOriginX, int newMinimumOriginY)
          Set the minimum origin pixel position to the given values.
 void setMinimumOriginX(int newMinimumOriginX)
          Set the minimum origin X pixel position.
 void setMinimumOriginY(int newMinimumOriginY)
          Set the minimum origin Y pixel position.
 void setMinRowPosition(int minRowPosition)
          Sets the minimum row position for a split viewport and directly sets the minimum origin y value dependent on the configuration.
 void setOriginX(int newOriginX)
          Set the origin X pixel position.
 void setOriginY(int newOriginY)
          Set the origin Y pixel position.
 void setVerticalScrollbarEnabled(boolean enabled)
          Enable/disable the vertical scrollbar in this ViewportLayer.
 void setVerticalScroller(IScroller<?> scroller)
          Set a different vertical scroller than the default one.
 String toString()
           
 int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition)
           
 int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition)
           
 
Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform
configure, getCellByPosition, getCellPainter, getColumnIndexByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRegionLabelsByXY, getRowIndexByPosition, getUnderlyingLayer, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, isRowPositionResizable, loadState, saveState, setClientAreaProvider, setUnderlyingLayer, underlyingToLocalColumnPositions, underlyingToLocalRowPositions
 
Methods inherited from class org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
addConfiguration, addLayerListener, clearConfiguration, fireLayerEvent, getClientAreaProvider, getConfigLabelAccumulator, getRegionName, hasLayerListener, registerCommandHandler, registerEventHandler, registerPersistable, removeLayerListener, setConfigLabelAccumulator, setLayerPainter, setRegionName, unregisterCommandHandler, unregisterEventHandler, unregisterPersistable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.nebula.widgets.nattable.layer.ILayer
addLayerListener, configure, fireLayerEvent, getCellByPosition, getCellPainter, getClientAreaProvider, getColumnIndexByPosition, getConfigLabelsByPosition, getDataValueByPosition, getDisplayModeByPosition, getLayerPainter, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRegionLabelsByXY, getRowIndexByPosition, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, hasLayerListener, isRowPositionResizable, registerCommandHandler, registerPersistable, removeLayerListener, setClientAreaProvider, underlyingToLocalColumnPositions, underlyingToLocalRowPositions, unregisterCommandHandler, unregisterPersistable
 
Methods inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
loadState, saveState
 

Constructor Detail

ViewportLayer

public ViewportLayer(IUniqueIndexLayer underlyingLayer)
Method Detail

dispose

public void dispose()
Specified by:
dispose in interface ILayer
Overrides:
dispose in class AbstractLayerTransform

setHorizontalScroller

public void setHorizontalScroller(IScroller<?> scroller)
Set a different horizontal scroller than the default one.

Parameters:
scroller - The scroller that should be used for horizontal scrolling.

setVerticalScroller

public void setVerticalScroller(IScroller<?> scroller)
Set a different vertical scroller than the default one.

Parameters:
scroller - The scroller that should be used for vertical scrolling.

getMaxWidth

public int getMaxWidth()

getMinVerticalStart

public int getMinVerticalStart()

getMaxHeight

public int getMaxHeight()

getMinHorizontalStart

public int getMinHorizontalStart()

getMinimumOrigin

public PixelCoordinate getMinimumOrigin()
Returns:
The minimum origin pixel position.

getMinimumOriginColumnPosition

public int getMinimumOriginColumnPosition()
Returns:
The minimum origin column position

getMinimumOriginRowPosition

public int getMinimumOriginRowPosition()
Returns:
The minimum origin row position

setMinimumOriginX

public void setMinimumOriginX(int newMinimumOriginX)
Set the minimum origin X pixel position.

Parameters:
newMinimumOriginX -

setMinimumOriginY

public void setMinimumOriginY(int newMinimumOriginY)
Set the minimum origin Y pixel position.

Parameters:
newMinimumOriginY -

setMinimumOrigin

public void setMinimumOrigin(int newMinimumOriginX,
                             int newMinimumOriginY)
Set the minimum origin pixel position to the given values.

Parameters:
newMinimumOriginX -
newMinimumOriginY -

getOrigin

public PixelCoordinate getOrigin()
Returns:
The origin pixel position

setOriginX

public void setOriginX(int newOriginX)
Set the origin X pixel position.

Parameters:
newOriginX -

setOriginY

public void setOriginY(int newOriginY)
Set the origin Y pixel position.

Parameters:
newOriginY -

resetOrigin

public void resetOrigin(int newOriginX,
                        int newOriginY)
Reset the origin pixel position to the given values.

Parameters:
newOriginX -
newOriginY -

getMaxColumnPosition

public int getMaxColumnPosition()
Returns:
The maximum column position of a split viewport or -1 in case there are no multiple viewports configured.

setMaxColumnPosition

public void setMaxColumnPosition(int maxColumnPosition)
Parameters:
maxColumnPosition - The right most column position in case split viewports need to be configured.

getMinColumnPosition

public int getMinColumnPosition()
Returns:
The minimum column position of a split viewport or -1 in case there are no multiple viewports configured.

setMinColumnPosition

public void setMinColumnPosition(int minColumnPosition)
Sets the minimum column position for a split viewport and directly sets the minimum origin x value dependent on the configuration.

Parameters:
minColumnPosition - The left most column position in case split viewport need to be configured.

getMaxRowPosition

public int getMaxRowPosition()
Returns:
The maximum row position of a split viewport or -1 in case there are no multiple viewports configured.

setMaxRowPosition

public void setMaxRowPosition(int maxRowPosition)
Parameters:
maxRowPosition - The right most row position in case split viewports need to be configured.

getMinRowPosition

public int getMinRowPosition()
Returns:
The minimum row position of a split viewport or -1 in case there are no multiple viewports configured.

setMinRowPosition

public void setMinRowPosition(int minRowPosition)
Sets the minimum row position for a split viewport and directly sets the minimum origin y value dependent on the configuration.

Parameters:
minRowPosition - The left most row position in case split viewport need to be configured.

registerCommandHandlers

protected void registerCommandHandlers()
Description copied from class: AbstractLayer
Layers should use this method to register their command handlers and call it from their constructor. This allows easy overriding if required of command handlers

Overrides:
registerCommandHandlers in class AbstractLayer

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface ILayer
Overrides:
getColumnCount in class AbstractLayerTransform
Returns:
visible column count Note: This takes care of the frozen columns

getColumnPositionByIndex

public int getColumnPositionByIndex(int columnIndex)
Specified by:
getColumnPositionByIndex in interface IUniqueIndexLayer

localToUnderlyingColumnPosition

public int localToUnderlyingColumnPosition(int localColumnPosition)
Description copied from interface: ILayer
Convert a column position to the coordinates of the underlying layer. This is possible since each layer is aware of its underlying layer.

Specified by:
localToUnderlyingColumnPosition in interface ILayer
Overrides:
localToUnderlyingColumnPosition in class AbstractLayerTransform
Parameters:
localColumnPosition - column position in local (the layer's own) coordinates
Returns:
column position in the underlying layer's coordinates

underlyingToLocalColumnPosition

public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer,
                                           int underlyingColumnPosition)
Specified by:
underlyingToLocalColumnPosition in interface ILayer
Overrides:
underlyingToLocalColumnPosition in class AbstractLayerTransform

getWidth

public int getWidth()
Description copied from interface: ILayer
Returns the total width in pixels of this layer.

Specified by:
getWidth in interface ILayer
Overrides:
getWidth in class AbstractLayerTransform
Returns:
the width of the total number of visible columns

getColumnWidthByPosition

public int getColumnWidthByPosition(int columnPosition)
Description copied from interface: ILayer
Returns the width in pixels of the given column. The width of invisible and non-existing columns is 0.

Specified by:
getColumnWidthByPosition in interface ILayer
Overrides:
getColumnWidthByPosition in class AbstractLayerTransform
Parameters:
columnPosition - the column position in this layer
Returns:
the width of the column

isColumnPositionResizable

public boolean isColumnPositionResizable(int columnPosition)
Specified by:
isColumnPositionResizable in interface ILayer
Overrides:
isColumnPositionResizable in class AbstractLayerTransform

getColumnPositionByX

public int getColumnPositionByX(int x)
Description copied from interface: ILayer
Returns the column position that contains the given x coordinate.

Specified by:
getColumnPositionByX in interface ILayer
Overrides:
getColumnPositionByX in class AbstractLayerTransform
Parameters:
x - a horizontal pixel location relative to the pixel boundary of this layer
Returns:
a column position relative to the associated coordinate system, or -1 if there is no column that contains x

getStartXOfColumnPosition

public int getStartXOfColumnPosition(int columnPosition)
Description copied from interface: ILayer
Returns the x offset in pixels of the given column.

Specified by:
getStartXOfColumnPosition in interface ILayer
Overrides:
getStartXOfColumnPosition in class AbstractLayerTransform
Parameters:
columnPosition - the column position in this layer
Returns:
the x offset of the column, or -1

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface ILayer
Overrides:
getRowCount in class AbstractLayerTransform
Returns:
total number of rows visible in the viewport

getRowPositionByIndex

public int getRowPositionByIndex(int rowIndex)
Specified by:
getRowPositionByIndex in interface IUniqueIndexLayer

localToUnderlyingRowPosition

public int localToUnderlyingRowPosition(int localRowPosition)
Specified by:
localToUnderlyingRowPosition in interface ILayer
Overrides:
localToUnderlyingRowPosition in class AbstractLayerTransform

underlyingToLocalRowPosition

public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer,
                                        int underlyingRowPosition)
Specified by:
underlyingToLocalRowPosition in interface ILayer
Overrides:
underlyingToLocalRowPosition in class AbstractLayerTransform

getHeight

public int getHeight()
Description copied from interface: ILayer
Returns the total height in pixels of this layer.

Specified by:
getHeight in interface ILayer
Overrides:
getHeight in class AbstractLayerTransform
Returns:
the height of this layer

getRowHeightByPosition

public int getRowHeightByPosition(int rowPosition)
Description copied from interface: ILayer
Returns the height in pixels of the given row. The height of invisible and non-existing rows is 0.

Specified by:
getRowHeightByPosition in interface ILayer
Overrides:
getRowHeightByPosition in class AbstractLayerTransform
Parameters:
rowPosition - the row position in this layer
Returns:
the height of the row

getRowPositionByY

public int getRowPositionByY(int y)
Description copied from interface: ILayer
Returns the row position that contains the given y coordinate.

Specified by:
getRowPositionByY in interface ILayer
Overrides:
getRowPositionByY in class AbstractLayerTransform
Parameters:
y - a vertical pixel location relative to the pixel boundary of this layer
Returns:
a row position relative to the associated coordinate system, or -1 if there is no row that contains y

getStartYOfRowPosition

public int getStartYOfRowPosition(int rowPosition)
Description copied from interface: ILayer
Returns the y offset in pixels of the given row.

Specified by:
getStartYOfRowPosition in interface ILayer
Overrides:
getStartYOfRowPosition in class AbstractLayerTransform
Parameters:
rowPosition - the row position in this layer
Returns:
the y offset of the row, or -1

getBoundsByPosition

public org.eclipse.swt.graphics.Rectangle getBoundsByPosition(int columnPosition,
                                                              int rowPosition)
Description copied from interface: ILayer
Calculates the bounds in pixel for the given cell position.

Specified by:
getBoundsByPosition in interface ILayer
Overrides:
getBoundsByPosition in class AbstractLayer
Parameters:
columnPosition - the column position of the cell
rowPosition - the row position of the cell
Returns:
the bounds, or null if there are no valid bounds

invalidateHorizontalStructure

public void invalidateHorizontalStructure()
Clear horizontal caches


invalidateVerticalStructure

public void invalidateVerticalStructure()
Clear vertical caches


recalculateAvailableWidthAndColumnCount

protected void recalculateAvailableWidthAndColumnCount()
Recalculate horizontal dimension properties.


recalculateAvailableHeightAndRowCount

protected void recalculateAvailableHeightAndRowCount()
Recalculate vertical dimension properties.


moveCellPositionIntoViewport

public void moveCellPositionIntoViewport(int scrollableColumnPosition,
                                         int scrollableRowPosition)
Srcolls the table so that the specified cell is visible i.e. in the Viewport

Parameters:
scrollableColumnPosition -
scrollableRowPosition -

moveColumnPositionIntoViewport

public void moveColumnPositionIntoViewport(int scrollableColumnPosition)
Scrolls the viewport (if required) so that the specified column is visible.

Parameters:
scrollableColumnPosition - column position in terms of the Scrollable Layer

moveRowPositionIntoViewport

public void moveRowPositionIntoViewport(int scrollableRowPosition)
See Also:
moveColumnPositionIntoViewport(int)

fireScrollEvent

protected void fireScrollEvent()

doCommand

public boolean doCommand(ILayerCommand command)
Description copied from interface: ILayer
Opportunity to respond to a command as it flows down the stack. If the layer is not interested in the command it should allow the command to keep traveling down the stack. Note: Before the layer can process a command it must convert the command to its local co-ordinates using ILayerCommand.convertToTargetLayer(ILayer)

Specified by:
doCommand in interface ILayer
Overrides:
doCommand in class AbstractLayerTransform
Parameters:
command - the command to perform
Returns:
true if the command has been handled, false otherwise

recalculateScrollBars

public void recalculateScrollBars()
Recalculate scrollbar characteristics.


handleGridResize

protected void handleGridResize()
Recalculate viewport characteristics when the grid has been resized.


adjustOriginX

protected int adjustOriginX(int originX)
If the client area size is greater than the content size, move origin to fill as much content as possible.


adjustOriginY

protected int adjustOriginY(int originY)
If the client area size is greater than the content size, move origin to fill as much content as possible.


scrollVerticallyByAPage

public void scrollVerticallyByAPage(ScrollSelectionCommand scrollSelectionCommand)
Scrolls the viewport vertically by a page. This is done by creating a MoveSelectionCommand to move the selection, which will then trigger an update of the viewport.

Parameters:
scrollSelectionCommand -

scrollVerticallyByAPageCommand

protected MoveSelectionCommand scrollVerticallyByAPageCommand(ScrollSelectionCommand scrollSelectionCommand)

isLastColumnCompletelyDisplayed

protected boolean isLastColumnCompletelyDisplayed()
Returns:
true if last column is completely displayed, false otherwise

isLastRowCompletelyDisplayed

protected boolean isLastRowCompletelyDisplayed()
Returns:
true if last row is completely displayed, false otherwise

handleLayerEvent

public void handleLayerEvent(ILayerEvent event)
Description copied from class: AbstractLayer
Handle layer event notification. Convert it to your context and propagate UP. If you override this method you MUST NOT FORGET to raise the event up the layer stack by calling super.fireLayerEvent(event) - unless you plan to eat the event yourself.

Specified by:
handleLayerEvent in interface ILayerListener
Overrides:
handleLayerEvent in class AbstractLayer
Parameters:
event - the event

getClientAreaWidth

public int getClientAreaWidth()
Returns:
The width of the visible client area. Will recalculate horizontal dimension information if the width has changed.

getClientAreaHeight

public int getClientAreaHeight()
Returns:
The height of the visible client area. Will recalculate vertical dimension information if the height has changed.

getScrollableLayer

public IUniqueIndexLayer getScrollableLayer()
Returns:
The scrollable layer underlying the viewport.

toString

public String toString()
Overrides:
toString in class AbstractLayer

drag

public void drag(int x,
                 int y)
Used for edge hover scrolling. Called from the ViewportDragCommandHandler.

Parameters:
x -
y -

drag

public void drag(SelectionLayer.MoveDirectionEnum horizontal,
                 SelectionLayer.MoveDirectionEnum vertical)
Used to scroll in the given direction on drag operations outside the visible region. Does not start a background thread for automatic scrolling.

Parameters:
horizontal - The horizontal movement for the scroll operation MoveDirectionEnum.LEFT, MoveDirectionEnum.RIGHT, MoveDirectionEnum.NONE
vertical - The vertical movement for the scroll operation MoveDirectionEnum.UP, MoveDirectionEnum.DOWN, MoveDirectionEnum.NONE
Since:
1.3

setHorizontalScrollbarEnabled

public void setHorizontalScrollbarEnabled(boolean enabled)
Enable/disable the horizontal scrollbar in this ViewportLayer.

Note: Setting the value to false will avoid registering a HorizontalScrollBarHandler, which means that there are no actions performed on the horizontal scrollbar in any case. If a horizontal scrollbar is rendered, it will be shown disabled. The rendering of scrollbar is typically configured via style bit in the NatTable control. So if there is a disabled scrollbar rendered check the style bits of the NatTable, and try to remove SWT.H_SCROLL which is set in the default style options.

Parameters:
enabled - false to disable the horizontal scrollbar, true to enable it.

setVerticalScrollbarEnabled

public void setVerticalScrollbarEnabled(boolean enabled)
Enable/disable the vertical scrollbar in this ViewportLayer.

Note: Setting the value to false will avoid registering a VerticalScrollBarHandler which means that there are no actions performed on the vertical scrollbar in any case. If a vertical scrollbar is rendered, it will be shown disabled. The rendering of scrollbar is typically configured via style bit in the NatTable control. So if there is a disabled scrollbar rendered check the style bits of the NatTable, and try to remove SWT.V_SCROLL which is set in the default style options.

Parameters:
enabled - false to disable the vertical scrollbar, true to enable it.


Copyright © 2015. All rights reserved.