Nattable column and row resize behaviour [message #1707395] |
Fri, 04 September 2015 09:13  |
Eclipse User |
|
|
|
Hi everyone
I am developing an application that has a number of small Nattables to display various information.
The user can manually alter the column widths & row heights using mouse drags on the headers. Great, but for visual aesthetics I would prefer the column widths & row heights to change dynamically whilst the user is moving the mouse, instead of jumping to the new size when the user releases the mouse button.
Any hints or tips how this can be achieved?
Willing to do a bit of coding to achieve but looking around the Javadoc and the source code, not sure how to make this happen!
Understand the current/default behaviour was for performance reasons, but my tables are simple enough and the machines powerful enough that I think this won't be a problem.
Any help gratefully received
Many thanks
Richard
|
|
|
|
Re: Nattable column and row resize behaviour [message #1707723 is a reply to message #1707456] |
Tue, 08 September 2015 15:04  |
Eclipse User |
|
|
|
Many thanks Dirk, just the hint I needed.
Now all successfully implemented and working very well.
For those who might want to do the same, he is what I did:
(1) When creating the ColumnHeaderLayer added custom config, remembering to say false to useDefaultConfiguration.
(2) In custom config add custom ColumnResizeDragMode, in my case called XColumnResizeDragMode
uiBindingRegistry.registerFirstMouseDragMode( new ColumnResizeEventMatcher( SWT.NONE,
GridRegion.COLUMN_HEADER, 1 ), new XColumnResizeDragMode() );
(3) And here is my XColumnResizeDragMode
public class XColumnResizeDragMode implements IDragMode
{
private int m_column;
private int m_originalWidth;
private int m_originalX;
private static final int MIN_COLUMN_WIDTH = 25;
/****************************************** mouseDown ******************************************/
@Override
public void mouseDown( NatTable nattable, MouseEvent event )
{
// determine which column is being resized
nattable.forceFocus();
m_column = CellEdgeDetectUtil.getColumnPositionToResize( nattable, new Point( event.x, event.y ) );
if ( m_column >= 0 )
{
m_originalWidth = nattable.getColumnWidthByPosition( m_column );
m_originalX = event.x;
}
}
/****************************************** mouseMove ******************************************/
@Override
public void mouseMove( NatTable nattable, MouseEvent event )
{
// determine new width
int width = m_originalWidth + event.x - m_originalX;
// don't allow width to go below minimum
if ( width < MIN_COLUMN_WIDTH )
width = MIN_COLUMN_WIDTH;
// update table column width and trigger redraw
nattable.doCommand( new ColumnResizeCommand( nattable, m_column, width ) );
nattable.redraw();
}
/******************************************* mouseUp *******************************************/
@Override
public void mouseUp( NatTable nattable, MouseEvent event )
{
// nothing to do
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03742 seconds