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>>commandHandlersprotected Map<Class<? extends ILayerEvent>,ILayerEventHandler<? extends ILayerEvent>>eventHandlersprotected ReadWriteLockeventHelperLockReadWriteLockthat is used to ensure that no concurrent modifications happen on event handlingprotected ILayerPainterlayerPainter-
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 voidaddConfiguration(IConfiguration configuration)voidaddLayerListener(ILayerListener listener)Add a generalILayerListenerto handleILayerEvents on this layer.voidclearConfiguration()voidconfigure(IConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry)Configure this layer, e.g.voiddispose()Dispose any resource allocated by this layer.booleandoCommand(ILayerCommand command)Opportunity to respond to a command as it flows down the stack.voidfireLayerEvent(ILayerEvent event)Pass the event to all theILayerListenerregistered on this layer.org.eclipse.swt.graphics.RectanglegetBoundsByPosition(int columnPosition, int rowPosition)Calculates the bounds in pixel for the given cell position.ILayerCellgetCellByPosition(int columnPosition, int rowPosition)Returns the cell for the given coordinates on this layer.ICellPaintergetCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry)Return theICellPainterfor the givenILayerCellat the given coordinates out of the givenIConfigRegistry.IClientAreaProvidergetClientAreaProvider()IConfigLabelAccumulatorgetConfigLabelAccumulator()LabelStackgetConfigLabelsByPosition(int columnPosition, int rowPosition)Returns the config labels for the cell at the given coordinates.DisplayModegetDisplayModeByPosition(int columnPosition, int rowPosition)Returns the activeDisplayModefor the cell at the given coordinates.ILayerPaintergetLayerPainter()Collection<String>getProvidedLabels()LabelStackgetRegionLabelsByXY(int x, int y)Return theLabelStackcontaining the region labels for the cell at the given pixel position.StringgetRegionName()voidhandleLayerEvent(ILayerEvent event)Handle layer event notification.booleanhasLayerListener(Class<? extends ILayerListener> layerListenerClass)Check if anILayerListenerof the given type is registered on this layer or not.booleanisDynamicSizeLayer()voidloadState(String prefix, Properties properties)Restore the state out of the given Properties identified by the specified prefix.voidregisterCommandHandler(ILayerCommandHandler<?> commandHandler)Register anILayerCommandHandlerto handle a command in this layer.protected voidregisterCommandHandlers()Layers should use this method to register their command handlers and call it from their constructor.voidregisterEventHandler(ILayerEventHandler<?> eventHandler)voidregisterPersistable(IPersistable persistable)Register anIPersistablethat can write its state to the statePropertiesinstance when the layer is persisted.voidremoveLayerListener(ILayerListener listener)Remove the givenILayerListenerfrom this layer.voidsaveState(String prefix, Properties properties)Saves the state to the given Properties using the specified prefix.voidsetClientAreaProvider(IClientAreaProvider clientAreaProvider)voidsetConfigLabelAccumulator(IConfigLabelAccumulator cellLabelAccumulator)voidsetLayerPainter(ILayerPainter layerPainter)voidsetRegionName(String regionName)StringtoString()voidunregisterCommandHandler(Class<? extends ILayerCommand> commandClass)Unregister theILayerCommandHandlerthat is registered for the givenILayerCommandclass.voidunregisterEventHandler(ILayerEventHandler<?> eventHandler)voidunregisterPersistable(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
ReadWriteLockthat 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:ILayerDispose any resource allocated by this layer.
-
getRegionLabelsByXY
public LabelStack getRegionLabelsByXY(int x, int y)
Description copied from interface:ILayerReturn theLabelStackcontaining the region labels for the cell at the given pixel position.- Specified by:
getRegionLabelsByXYin 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:ILayerReturns the config labels for the cell at the given coordinates. Needed to retrieve the corresponding configurations out of theIConfigRegistry.- Specified by:
getConfigLabelsByPositionin interfaceILayer- Parameters:
columnPosition- The column position of the cell.rowPosition- The row position of the cell.- Returns:
- The
LabelStackwith 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:IPersistableSaves 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:
saveStatein 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:IPersistableRestore 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:
loadStatein 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:ILayerRegister anIPersistablethat can write its state to the statePropertiesinstance when the layer is persisted.- Specified by:
registerPersistablein interfaceILayer- Parameters:
persistable- The persistable that should be registered.
-
unregisterPersistable
public void unregisterPersistable(IPersistable persistable)
Description copied from interface:ILayerUnregister the givenIPersistable.- Specified by:
unregisterPersistablein 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:ILayerConfigure 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:
configurein interfaceILayer- Parameters:
configRegistry- TheIConfigRegistryinstance owned by theNatTablethis layer is attached to.uiBindingRegistry- TheUiBindingRegistryinstance owned byNatTablethis layer is attached to.
-
doCommand
public boolean doCommand(ILayerCommand command)
Description copied from interface:ILayerOpportunity 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:ILayerRegister anILayerCommandHandlerto handle a command in this layer. Only oneILayerCommandHandlerperILayerCommandcan be registered per layer.- Specified by:
registerCommandHandlerin interfaceILayer- Parameters:
commandHandler- The command handler to register with this layer.
-
unregisterCommandHandler
public void unregisterCommandHandler(Class<? extends ILayerCommand> commandClass)
Description copied from interface:ILayerUnregister theILayerCommandHandlerthat is registered for the givenILayerCommandclass.- Specified by:
unregisterCommandHandlerin interfaceILayer- Parameters:
commandClass- TheILayerCommandclass for which theILayerCommandHandlershould be unregistered.
-
addLayerListener
public void addLayerListener(ILayerListener listener)
Description copied from interface:ILayerAdd a generalILayerListenerto handleILayerEvents on this layer.- Specified by:
addLayerListenerin interfaceILayer- Parameters:
listener- TheILayerListenerto add.
-
removeLayerListener
public void removeLayerListener(ILayerListener listener)
Description copied from interface:ILayerRemove the givenILayerListenerfrom this layer.- Specified by:
removeLayerListenerin interfaceILayer- Parameters:
listener- TheILayerListenerto remove.
-
hasLayerListener
public boolean hasLayerListener(Class<? extends ILayerListener> layerListenerClass)
Description copied from interface:ILayerCheck if anILayerListenerof the given type is registered on this layer or not.- Specified by:
hasLayerListenerin interfaceILayer- Parameters:
layerListenerClass- The type ofILayerListenerto check for.- Returns:
trueif thisILayerhas aILayerListenerof the specified type registered,falseif 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:
handleLayerEventin 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 theILayerListenerregistered on this layer. A cloned copy is passed to each listener.- Specified by:
fireLayerEventin interfaceILayer- Parameters:
event- the event to fire
-
getLayerPainter
public ILayerPainter getLayerPainter()
- Specified by:
getLayerPainterin interfaceILayer- Returns:
ILayerPainter. Defaults toGridLineCellLayerPainter
-
setLayerPainter
public void setLayerPainter(ILayerPainter layerPainter)
-
getClientAreaProvider
public IClientAreaProvider getClientAreaProvider()
- Specified by:
getClientAreaProviderin interfaceILayer- Returns:
- The
IClientAreaProviderthat specifies the rectangular area available on this layer.
-
setClientAreaProvider
public void setClientAreaProvider(IClientAreaProvider clientAreaProvider)
- Specified by:
setClientAreaProviderin interfaceILayer- Parameters:
clientAreaProvider- TheIClientAreaProviderthat specifies the rectangular area available on this layer.
-
getCellByPosition
public ILayerCell getCellByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayerReturns the cell for the given coordinates on this layer.- Specified by:
getCellByPositionin interfaceILayer- Parameters:
columnPosition- The column position of the requested cell.rowPosition- The row position of the requested cell.- Returns:
- The
ILayerCellfor the given coordinates in this layer ornullif the coordinates are invalid on this layer.
-
getBoundsByPosition
public org.eclipse.swt.graphics.Rectangle getBoundsByPosition(int columnPosition, int rowPosition)Description copied from interface:ILayerCalculates the bounds in pixel for the given cell position.- Specified by:
getBoundsByPositionin interfaceILayer- Parameters:
columnPosition- the column position of the cellrowPosition- the row position of the cell- Returns:
- the bounds, or
nullif there are no valid bounds
-
getDisplayModeByPosition
public DisplayMode getDisplayModeByPosition(int columnPosition, int rowPosition)
Description copied from interface:ILayerReturns the activeDisplayModefor 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.SELECTfor cells that are currently selected.- Specified by:
getDisplayModeByPositionin interfaceILayer- Parameters:
columnPosition- The column position of the cell.rowPosition- The row position of the cell.- Returns:
DisplayModefor the cell at the given coordinates.
-
getCellPainter
public ICellPainter getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry)
Description copied from interface:ILayerReturn theICellPainterfor the givenILayerCellat the given coordinates out of the givenIConfigRegistry.- Specified by:
getCellPainterin interfaceILayer- Parameters:
columnPosition- The column position of the cell.rowPosition- The row position of the cell.cell- TheILayerCellfor which theICellPainteris requested.configRegistry- TheIConfigRegistryto retrieve the painter from.- Returns:
- The
ICellPainterfor the given cell at the given coordinates ornullif no painter is configured.
-
isDynamicSizeLayer
public boolean isDynamicSizeLayer()
- Specified by:
isDynamicSizeLayerin interfaceILayer- Returns:
trueif the layer has a dynamic size (e.g. viewport) or a fixed size.- Since:
- 1.4
-
getProvidedLabels
public Collection<String> getProvidedLabels()
- Specified by:
getProvidedLabelsin interfaceILayer- Returns:
- The collection of labels that are provided by this layer.
- Since:
- 1.4
-
-