Class AbstractLayer
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.layer.AbstractLayer
-
- All Implemented Interfaces:
ILayer
,ILayerListener
,IPersistable
- Direct Known Subclasses:
AbstractIndexLayerTransform
,AbstractLayerTransform
,CompositeLayer
,DataLayer
,DimensionallyDependentLayer
public abstract class AbstractLayer extends Object implements ILayer
Base layer implementation with common methods for managing listeners and caching, etc.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Class<? extends ILayerCommand>,ILayerCommandHandler<? extends ILayerCommand>>
commandHandlers
protected Map<Class<? extends ILayerEvent>,ILayerEventHandler<? extends ILayerEvent>>
eventHandlers
protected ReadWriteLock
eventHelperLock
ReadWriteLock
that is used to ensure that no concurrent modifications happen on event handlingprotected ILayerPainter
layerPainter
-
Fields inherited from interface org.eclipse.nebula.widgets.nattable.persistence.IPersistable
DOT, VALUE_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractLayer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfiguration(IConfiguration configuration)
void
addLayerListener(ILayerListener listener)
Add a generalILayerListener
to handleILayerEvent
s on this layer.void
clearConfiguration()
void
configure(IConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry)
Configure this layer, e.g.void
dispose()
Dispose any resource allocated by this layer.boolean
doCommand(ILayerCommand command)
Opportunity to respond to a command as it flows down the stack.void
fireLayerEvent(ILayerEvent event)
Pass the event to all theILayerListener
registered on this layer.org.eclipse.swt.graphics.Rectangle
getBoundsByPosition(int columnPosition, int rowPosition)
Calculates the bounds in pixel for the given cell position.ILayerCell
getCellByPosition(int columnPosition, int rowPosition)
Returns the cell for the given coordinates on this layer.ICellPainter
getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry)
Return theICellPainter
for the givenILayerCell
at the given coordinates out of the givenIConfigRegistry
.IClientAreaProvider
getClientAreaProvider()
IConfigLabelAccumulator
getConfigLabelAccumulator()
LabelStack
getConfigLabelsByPosition(int columnPosition, int rowPosition)
Returns the config labels for the cell at the given coordinates.DisplayMode
getDisplayModeByPosition(int columnPosition, int rowPosition)
Returns the activeDisplayMode
for the cell at the given coordinates.ILayerPainter
getLayerPainter()
Collection<String>
getProvidedLabels()
LabelStack
getRegionLabelsByXY(int x, int y)
Return theLabelStack
containing the region labels for the cell at the given pixel position.String
getRegionName()
void
handleLayerEvent(ILayerEvent event)
Handle layer event notification.boolean
hasLayerListener(Class<? extends ILayerListener> layerListenerClass)
Check if anILayerListener
of the given type is registered on this layer or not.boolean
isDynamicSizeLayer()
void
loadState(String prefix, Properties properties)
Restore the state out of the given Properties identified by the specified prefix.void
registerCommandHandler(ILayerCommandHandler<?> commandHandler)
Register anILayerCommandHandler
to handle a command in this layer.protected void
registerCommandHandlers()
Layers should use this method to register their command handlers and call it from their constructor.void
registerEventHandler(ILayerEventHandler<?> eventHandler)
void
registerPersistable(IPersistable persistable)
Register anIPersistable
that can write its state to the stateProperties
instance when the layer is persisted.void
removeLayerListener(ILayerListener listener)
Remove the givenILayerListener
from this layer.void
saveState(String prefix, Properties properties)
Saves the state to the given Properties using the specified prefix.void
setClientAreaProvider(IClientAreaProvider clientAreaProvider)
void
setConfigLabelAccumulator(IConfigLabelAccumulator cellLabelAccumulator)
void
setLayerPainter(ILayerPainter layerPainter)
void
setRegionName(String regionName)
String
toString()
void
unregisterCommandHandler(Class<? extends ILayerCommand> commandClass)
Unregister theILayerCommandHandler
that is registered for the givenILayerCommand
class.void
unregisterEventHandler(ILayerEventHandler<?> eventHandler)
void
unregisterPersistable(IPersistable persistable)
Unregister the givenIPersistable
.-
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
getColumnCount, getColumnIndexByPosition, getColumnPositionByX, getColumnWidthByPosition, getDataValueByPosition, getHeight, getPreferredColumnCount, getPreferredHeight, getPreferredRowCount, getPreferredWidth, getRowCount, getRowHeightByPosition, getRowIndexByPosition, getRowPositionByY, getStartXOfColumnPosition, getStartYOfRowPosition, getUnderlyingLayerByPosition, getUnderlyingLayersByColumnPosition, getUnderlyingLayersByRowPosition, getWidth, isColumnPositionResizable, isRowPositionResizable, localToUnderlyingColumnPosition, localToUnderlyingRowPosition, underlyingToLocalColumnPosition, underlyingToLocalColumnPositions, underlyingToLocalRowPosition, underlyingToLocalRowPositions
-
-
-
-
Field Detail
-
layerPainter
protected ILayerPainter layerPainter
-
commandHandlers
protected final Map<Class<? extends ILayerCommand>,ILayerCommandHandler<? extends ILayerCommand>> commandHandlers
-
eventHandlers
protected Map<Class<? extends ILayerEvent>,ILayerEventHandler<? extends ILayerEvent>> eventHandlers
-
eventHelperLock
protected ReadWriteLock eventHelperLock
ReadWriteLock
that is used to ensure that no concurrent modifications happen on event handling- Since:
- 1.4
-
-
Method Detail
-
dispose
public void dispose()
Description copied from interface:ILayer
Dispose any resource allocated by this layer.
-
getRegionLabelsByXY
public LabelStack getRegionLabelsByXY(int x, int y)
Description copied from interface:ILayer
Return theLabelStack
containing the region labels for the cell at the given pixel position.- Specified by:
getRegionLabelsByXY
in interfaceILayer
- Parameters:
x
- the x pixel coordinatey
- the y pixel coordinate- Returns:
- LabelStack containing the region labels for the cell at the given pixel position.
-
getRegionName
public String getRegionName()
-
setRegionName
public void setRegionName(String regionName)
-
getConfigLabelsByPosition
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayer
Returns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry
.- Specified by:
getConfigLabelsByPosition
in interfaceILayer
- Parameters:
columnPosition
- The column position of the cell.rowPosition
- The row position of the cell.- Returns:
- The
LabelStack
with the config labels for the cell at the given coordinates.
-
getConfigLabelAccumulator
public IConfigLabelAccumulator getConfigLabelAccumulator()
-
setConfigLabelAccumulator
public void setConfigLabelAccumulator(IConfigLabelAccumulator cellLabelAccumulator)
-
saveState
public void saveState(String prefix, Properties properties)
Description copied from interface:IPersistable
Saves the state to the given Properties using the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.- Specified by:
saveState
in interfaceIPersistable
- Parameters:
prefix
- The prefix to use for the state keys. Is also used as the state configuration name.properties
- The Properties instance to save the state to.
-
loadState
public void loadState(String prefix, Properties properties)
Description copied from interface:IPersistable
Restore the state out of the given Properties identified by the specified prefix. Note: The prefix must be prepended to the property key to support multiple states within one Properties instance.- Specified by:
loadState
in interfaceIPersistable
- Parameters:
prefix
- The prefix to use for the state keys. Is also used as the state configuration name.properties
- The Properties instance to load the state from.
-
registerPersistable
public void registerPersistable(IPersistable persistable)
Description copied from interface:ILayer
Register anIPersistable
that can write its state to the stateProperties
instance when the layer is persisted.- Specified by:
registerPersistable
in interfaceILayer
- Parameters:
persistable
- The persistable that should be registered.
-
unregisterPersistable
public void unregisterPersistable(IPersistable persistable)
Description copied from interface:ILayer
Unregister the givenIPersistable
.- Specified by:
unregisterPersistable
in interfaceILayer
- Parameters:
persistable
- The persistable to unregister.
-
addConfiguration
public void addConfiguration(IConfiguration configuration)
-
clearConfiguration
public void clearConfiguration()
-
configure
public void configure(IConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry)
Description copied from interface:ILayer
Configure this layer, e.g. add any key/mouse bindings and other general configuration.This method is triggered by
NatTable.configure()
and executed down the layer stack.- Specified by:
configure
in interfaceILayer
- Parameters:
configRegistry
- TheIConfigRegistry
instance owned by theNatTable
this layer is attached to.uiBindingRegistry
- TheUiBindingRegistry
instance owned byNatTable
this layer is attached to.
-
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 coordinates using
ILayerCommand.convertToTargetLayer(ILayer)
-
registerCommandHandlers
protected void registerCommandHandlers()
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
-
registerCommandHandler
public void registerCommandHandler(ILayerCommandHandler<?> commandHandler)
Description copied from interface:ILayer
Register anILayerCommandHandler
to handle a command in this layer. Only oneILayerCommandHandler
perILayerCommand
can be registered per layer.- Specified by:
registerCommandHandler
in interfaceILayer
- Parameters:
commandHandler
- The command handler to register with this layer.
-
unregisterCommandHandler
public void unregisterCommandHandler(Class<? extends ILayerCommand> commandClass)
Description copied from interface:ILayer
Unregister theILayerCommandHandler
that is registered for the givenILayerCommand
class.- Specified by:
unregisterCommandHandler
in interfaceILayer
- Parameters:
commandClass
- TheILayerCommand
class for which theILayerCommandHandler
should be unregistered.
-
addLayerListener
public void addLayerListener(ILayerListener listener)
Description copied from interface:ILayer
Add a generalILayerListener
to handleILayerEvent
s on this layer.- Specified by:
addLayerListener
in interfaceILayer
- Parameters:
listener
- TheILayerListener
to add.
-
removeLayerListener
public void removeLayerListener(ILayerListener listener)
Description copied from interface:ILayer
Remove the givenILayerListener
from this layer.- Specified by:
removeLayerListener
in interfaceILayer
- Parameters:
listener
- TheILayerListener
to remove.
-
hasLayerListener
public boolean hasLayerListener(Class<? extends ILayerListener> layerListenerClass)
Description copied from interface:ILayer
Check if anILayerListener
of the given type is registered on this layer or not.- Specified by:
hasLayerListener
in interfaceILayer
- Parameters:
layerListenerClass
- The type ofILayerListener
to check for.- Returns:
true
if thisILayer
has aILayerListener
of the specified type registered,false
if there is no such listener registered.
-
handleLayerEvent
public void handleLayerEvent(ILayerEvent event)
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 callingsuper.fireLayerEvent(event)
- unless you plan to eat the event yourself.- Specified by:
handleLayerEvent
in interfaceILayerListener
- Parameters:
event
- the event
-
registerEventHandler
public void registerEventHandler(ILayerEventHandler<?> eventHandler)
-
unregisterEventHandler
public void unregisterEventHandler(ILayerEventHandler<?> eventHandler)
-
fireLayerEvent
public void fireLayerEvent(ILayerEvent event)
Pass the event to all theILayerListener
registered on this layer. A cloned copy is passed to each listener.- Specified by:
fireLayerEvent
in interfaceILayer
- Parameters:
event
- the event to fire
-
getLayerPainter
public ILayerPainter getLayerPainter()
- Specified by:
getLayerPainter
in interfaceILayer
- Returns:
ILayerPainter
. Defaults toGridLineCellLayerPainter
-
setLayerPainter
public void setLayerPainter(ILayerPainter layerPainter)
-
getClientAreaProvider
public IClientAreaProvider getClientAreaProvider()
- Specified by:
getClientAreaProvider
in interfaceILayer
- Returns:
- The
IClientAreaProvider
that specifies the rectangular area available on this layer.
-
setClientAreaProvider
public void setClientAreaProvider(IClientAreaProvider clientAreaProvider)
- Specified by:
setClientAreaProvider
in interfaceILayer
- Parameters:
clientAreaProvider
- TheIClientAreaProvider
that specifies the rectangular area available on this layer.
-
getCellByPosition
public ILayerCell getCellByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayer
Returns the cell for the given coordinates on this layer.- Specified by:
getCellByPosition
in interfaceILayer
- Parameters:
columnPosition
- The column position of the requested cell.rowPosition
- The row position of the requested cell.- Returns:
- The
ILayerCell
for the given coordinates in this layer ornull
if the coordinates are invalid on this layer.
-
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 interfaceILayer
- Parameters:
columnPosition
- the column position of the cellrowPosition
- the row position of the cell- Returns:
- the bounds, or
null
if there are no valid bounds
-
getDisplayModeByPosition
public DisplayMode getDisplayModeByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayer
Returns the activeDisplayMode
for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry
. The default value isDisplayMode.NORMAL
. The SelectionLayer for example overrides this to returnDisplayMode.SELECT
for cells that are currently selected.- Specified by:
getDisplayModeByPosition
in interfaceILayer
- Parameters:
columnPosition
- The column position of the cell.rowPosition
- The row position of the cell.- Returns:
DisplayMode
for the cell at the given coordinates.
-
getCellPainter
public ICellPainter getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry)
Description copied from interface:ILayer
Return theICellPainter
for the givenILayerCell
at the given coordinates out of the givenIConfigRegistry
.- Specified by:
getCellPainter
in interfaceILayer
- Parameters:
columnPosition
- The column position of the cell.rowPosition
- The row position of the cell.cell
- TheILayerCell
for which theICellPainter
is requested.configRegistry
- TheIConfigRegistry
to retrieve the painter from.- Returns:
- The
ICellPainter
for the given cell at the given coordinates ornull
if no painter is configured.
-
isDynamicSizeLayer
public boolean isDynamicSizeLayer()
- Specified by:
isDynamicSizeLayer
in interfaceILayer
- Returns:
true
if the layer has a dynamic size (e.g. viewport) or a fixed size.- Since:
- 1.4
-
getProvidedLabels
public Collection<String> getProvidedLabels()
- Specified by:
getProvidedLabels
in interfaceILayer
- Returns:
- The collection of labels that are provided by this layer.
- Since:
- 1.4
-
-