Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Dynamic preferred min column width in composite layer
Dynamic preferred min column width in composite layer [message #1766518] Thu, 22 June 2017 14:19 Go to next message
Odgerel Boldbaatar is currently offline Odgerel BoldbaatarFriend
Messages: 1
Registered: June 2017
Junior Member

How can i get the preferred min width of each column in composite layer? I want the column resize event to fire only if the new column width is more than the preferred width.

I have seen the class MaxCellBoundsHelper, but it is only used in AutoResizeColumnCommandHandler, which requires gridlayer.

By now i have written a custom ColumnResizeCommandHandler and set the min possible width to 75. But this solution i dun find satisfactory.

My table looks as following.
ColumnLabelAccumulator labels = new ColumnLabelAccumulator();
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
bodyDataLayer.registerCommandHandler(new CustomColumnResizeCommandHandler(bodyDataLayer));
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer, false);
ViewportLayer viewportLayer = new ViewportLayer(bodyDataLayer);
ConfigRegistry configRegistry = new ConfigRegistry();

// build the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyTranslationMap);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);

// create the composite layer composed of only column and viewportlayer
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.ROW_HEADER, columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
compositeLayer.addConfiguration(new AbstractUiBindingConfiguration() {

public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
new ColumnResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 0),
new ColumnResizeCursorAction());

new ColumnResizeEventMatcher(SWT.NONE, GridRegion.ROW_HEADER, 1),
new ColumnResizeDragMode());

// create and configure nattable
parent.setLayout(new GridLayout(1, true));
final NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
natTable.addOverlayPainter(new NatTableBorderOverlayPainter());

natTable.addConfiguration(new ModernNatTableThemeConfiguration());
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
this.cellPainter = new LineBorderDecorator(new TextPainter(false, false, 5, false, true));
Re: Dynamic preferred min column width in composite layer [message #1766952 is a reply to message #1766518] Thu, 29 June 2017 05:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2724
Registered: July 2012
Senior Member
I don't understand your requirement. NatTable does not have a concept for a minimum preferred column width. If you resize a column by dragging the column border, a min width of 25 pixels is used, which is currently hard coded in the ColumnResizeDragMode. If you want to change that you can extend ColumnResizeDragMode, override getColumnWidthMinimum() and register your class instead of the default.

If you want to add handling of a minimum column width in combination with the ColumnResizeCommand, then registering a custom ColumnResizeCommandHandler that is able to handle a minimum width is the right way to go. Even if it is not satisfying for you.

If you want a more satisfying solution, feel free to contribute to the project and introduce minimum width configurations.
Re: Dynamic preferred min column width in composite layer [message #1766959 is a reply to message #1766952] Thu, 29 June 2017 06:31 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2724
Registered: July 2012
Senior Member
BTW AutoResizeColumnCommandHandler does not require a GridLayer. You can also register it with two layers to make the index-position transformation possible.
Previous Topic:Static Filter for tree structure in NatTable
Next Topic:Row Reorder issue
Goto Forum:

Current Time: Thu Oct 17 16:29:36 GMT 2019

Powered by FUDForum. Page generated in 0.02292 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top