Color headers on mouse hover

Developers
Rashmy
2012-04-30
2013-05-08
  • Rashmy

    Rashmy - 2012-04-30

    Hello,
    When we select a cell, the existing NatTable code changes the style of the currently selected cell and the style of the corresponding row and column header cell. In my requirement, I'd like to change only the style of the row and column header cells (not the cell in body layer) when the mouse hovers over certain cells in the body layer.

    Here is a solution that I attempted to implement, I register a cell style against a label and then apply this label to the row header and column header cells when the user hovers over a particular cell in the body layer. But nothing happens since I have not fired an event informing the row and column header layers to paint itself. How can I achieve this? My requirement is very similar to selecting a cell but the difference is that I have to do this on mouse over. Should I be creating a new layer and writing a command handler and execute a command? For selection, NatTable has SelectionLayer, then SelectCellCommandHandler and SelectCellCommand? How does the command "SelectCellCommand" initiate repainting the selected cell, row header cell and column header cell?

    Thanks,
    Rashmy

     
  • Dirk Fauth

    Dirk Fauth - 2012-05-02

    Hi,

    the SelectionLayer has a style configuration itself. Within the DefaultSelectionStyleConfiguration you find how the selection style looks like. You should override it and set the values you like to modify the selection style.

    Greez,
    Dirk

     
  • Rashmy

    Rashmy - 2012-05-02

    Hi Dirk,
    The DefaultSelectionStyleConfiguration will help me change the style for cell selection.
    Instead what I'd like to do is change the style of the row, column header when user_ hovers the mouse over a specific cell_ (not upon cell selection).

    Thanks,
    Rashmy

     
  • Dirk Fauth

    Dirk Fauth - 2012-05-03

    Hi Rashmy,

    sorry for the misunderstanding. Changing the style on hovering over a specific cell is currently not supported by NatTable out of the box. Your attemp to solve this should work if you fire some sort of IVisualChangeEvent which is then handled by the NatTable. Hope this helps, otherwise you can send me an example so I can have a deeper look at it.

    Greez,
    Dirk

     
  • Rashmy

    Rashmy - 2012-05-03

    Hi Dirk,
    Here is what I have implemented thus far.
    1) Define new layer HighLightLayer
    2) Define command HighlightCellCommand
    3) Register for mouse events. On mouse over, fire the command HighlightCellCommand
    4) Register new styles for a label named "FOO_LABEL". this label will be set on the row and column to be highlighted on mouse over.
    5) Define handler HighLightCellCommandHandler. When the handler recieves the command HighlightCellCommand, it sets the mouse over column and row position on the HighlightLayer and asks the layer to fire the HightMouseOverEvent.
    6) I'm hoping just firing this type of event will trigger a repaint and the call would come to HighLightLayer.getConfigLabelsByPosition() where I'd like to now send the FOO_LABEL for row and column header cells.

    Issues:
    1)In HighLightLayer.getConfigLabelsByPosition() how can I get the column and row header layers to set the labels on specific cells?
    2)Do I need to define new painter in the HighLightLayer or just firing the HightMouseOverEvent is enough?

    Thanks,
    Rashmy
    '

     
  • Dirk Fauth

    Dirk Fauth - 2012-05-04

    Hi Rashmy,

    1. If your HighLightLayer needs to modify column and row header layer it should now them. So setting the reference to it if it is part of your body layer stack or try to set it on top of the GridLayer.
    2. If your HightMouseOverEvent is of type IVisualChangeEvent it should be enough.

    Greez,
    Dirk

     
  • Rashmy

    Rashmy - 2012-05-04

    Hi Dirk,
    Finally I got this to work but with one small glitch.

    To get this to work, I created my own ColumnHeaderlayer and RowHeaderLayer. When creating these layers, I passed a reference to the HighLightLayer. Upon mouse over the HighLightLayer stores the mouse over column and row positions. Then I fire a HighlightMouseOverevent. When the methods ColumnHeaderLayer.getConfigLabelsByPosition() or RowHeaderLayer.getConfigLabelsByPosition() is invoked, I get the stored mouse over position from the HighlightLayer and apply the FOO_LABEL accordingly. The hight of the cells in row and column headers are working. The only issue is that it highlights the column+1 and row+1.

    For example, if my table is as below and do a mouse over on "c=2, r=3", the cells "Column 3" and "4" are highlighted. Why is this?

       | Column 1     | Column 2    | Column 3

    1  |  c=1, r=1    | c=2, r=1    | c=3, r=1

    2  |  c=1, r=2    | c=2, r=2    | c=3, r=2

    3  |  c=1, r=3    | c=2, r=3    | c=3, r=3

    4  |  c=1, r=4    | c=2, r=4    | c=3, r=4

    Could you take a look at the below code and let me know if I have to do any other conversion to get the correct row and column from the mouse over positions ?

    public class MyColumnHeaderLayer
        extends ColumnHeaderLayer
    {
        /**
         * @param baseLayer data provider for the column header layer
         * @param horizontalLayerDependency typically the body layer
         * @param selectionLayer required to respond to selection events
         */
        public MyColumnHeaderLayer( IUniqueIndexLayer baseLayer,
                ILayer horizontalLayerDependency, SelectionLayer selectionLayer )
        {
            super( baseLayer, horizontalLayerDependency, selectionLayer, true );
        }
        public MyColumnHeaderLayer( IUniqueIndexLayer baseLayer,
                ILayer horizontalLayerDependency, SelectionLayer selectionLayer,
                boolean useDefaultConfiguration )
        {
            super( baseLayer, horizontalLayerDependency, selectionLayer,
                    useDefaultConfiguration );
        }
        private HighlightLayer highlightLayer;
        public void setHighlightLayer( HighlightLayer layer )
        {
            highlightLayer = layer;
        }
        @Override
        public LabelStack getConfigLabelsByPosition( int columnPosition,
                int rowPosition )
        {
            LabelStack labelStack = super.getConfigLabelsByPosition(
                    columnPosition, rowPosition );
            final int highlightLayerColumnPosition = LayerUtil.convertColumnPosition(
                    this, columnPosition, highlightLayer );
            if( highlightLayerColumnPosition == highlightLayer.getCurrentMouserOverColumnPostition() )
            {
                labelStack.addLabel( My_Custom_Highlighting.FOO_LABEL );
            }
            return labelStack;
        }
    
     
  • Dirk Fauth

    Dirk Fauth - 2012-05-07

    Hi,

    first, like most of Java collection implementations, the position/index starts with 0. The table you showed above is true on looking at the NatTable layer as column 0 is the row header and row 0 is the column header. For the body layer you have to subtract 1 so the body layer starts with 0,0. This transformation is done by the LayerUtil you are using.

    Greez,
    Dirk

     

Log in to post a comment.