Nattable column resize [message #1719954] |
Wed, 13 January 2016 08:33  |
Eclipse User |
|
|
|
Hi,
I have a Nattable with 25 column with different columnwidth. I set the columnwidth using datalayer.setColumnWidthByPosition(i, 30) method.
When I resize the nattable for the first time, the column width gets changed and layed out properly. But after refreshing the table, resizing does not work anymore. In my custom resizing listener method I set the proper column width in datalayer.setColumnWidthByPosition(i, 50) , but still it does not resize the nattable.
The values of the width of each column is based on its parent composite.
What am I doing wrong ? Should I have to set some configuration to nattable after setting the columnwidth?
[Updated on: Wed, 13 January 2016 08:45] by Moderator
|
|
|
|
|
|
|
|
|
|
Re: Nattable column resize [message #1719991 is a reply to message #1719982] |
Wed, 13 January 2016 10:53   |
Eclipse User |
|
|
|
This is the main method that is called when doing refresh/ opening the form , I do the following :
public void createform(SheetType type){
dataLayer = new SpanningDataLayer(this.bodyDataProvider);
cSheetBody.addControlListener(createControlListener(type, dataLayer,cSheetBody,columnNames.length));
dataLayer.registerCommandHandler(new VisualRefreshCommandHandler());
selLayer = new SelectionLayer(dataLayer);
viewportLayer = new ViewportLayer(selLayer);
// Create HeadLayer
colLayer = new ColumnHeaderLayer(
headData.getHeaderDataLayer(),
viewportLayer,
selLayer);
ColumnGroupHeaderLayer colgroupLayer = new ColumnGroupHeaderLayer(colLayer, selLayer, headData.getColumnGroupModel());
table.setColumnHeaderLayer(colLayer);
compLayer = new CompositeLayer(1, 2);
compLayer.registerCommandHandler(new VisualRefreshCommandHandler());
// Cell Editable
selLayer.addConfiguration(new CustomEditBindings(this));
viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE,
IEditableRule.ALWAYS_EDITABLE);
}
});
this.bodyDataProvider.setViewportLayer(viewportLayer);
this.bodyDataProvider.setNatTable(natTable);
natTable.addLayerListener(eListeners.createSelectionListener());
// Set Position of Child Layers
natTable.registerCommandHandler(new VisualRefreshCommandHandler());
compLayer.setChildLayer(GridRegion.COLUMN_HEADER, colgroupLayer, 0, 0);
compLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
final DataLayer headerDataLayer = (DataLayer) colLayer.getBaseLayer();
// create Header Accumulator
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(
headerDataLayer);
headerDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
// Set Vertical Header Columns
CellLabelFactory.setVerticalHeaderColumns(type, columnLabelAccumulator);
// create Column Accumulator
CustomBodyCellOverrideLabelAccumulator bodyColumnLabelAccumulator = new CustomBodyCellOverrideLabelAccumulator(
dataLayer, this.bodyDataProvider, type);
bodyColumnLabelAccumulator.setFactory(this);
dataLayer.setConfigLabelAccumulator(bodyColumnLabelAccumulator);
// printCommandHandler = new PrintCommandHandler(compLayer);
// compLayer.registerCommandHandler(printCommandHandler);
printCommandHandler = new PrintCommandHandler(natTable);
natTable.registerCommandHandler(printCommandHandler);
compLayer.registerCommandHandler(new ExportCommandHandler(compLayer));
// set Container Layer
table.setCompositeLayer(compLayer);
// set Layer to NatTable
natTable.setLayer(compLayer);
// Configure Table
CellLabelFactory.attachToolTip(natTable, group, eListeners);
// natTable.setLayout(new GridLayout());
natTable.setBackground(SWTResourceManager
.getColor(255, 255, 255));
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
//register a custom formatter to the body of the grid
//you could also implement different formatter for different columns by using the label mechanism
configRegistry.registerConfigAttribute(
ExportConfigAttributes.EXPORT_FORMATTER,
new CustomExportFormatter(),
DisplayMode.NORMAL,
GridRegion.BODY);
configRegistry.registerConfigAttribute(
ExportConfigAttributes.EXPORT_FORMATTER,
new CustomExportFormatter(),
DisplayMode.NORMAL,
GridRegion.COLUMN_GROUP_HEADER);
configRegistry.registerConfigAttribute(
ExportConfigAttributes.EXPORT_FORMATTER,
new CustomExportFormatter(),
DisplayMode.NORMAL,
GridRegion.COLUMN_HEADER);
}
});
// Drag/Drop Support
if(filter.getModel().getNotEditable())
{
enableDragDrop();
}
// natTable.addOverlayPainter(new NatTableBorderOverlayPainter(GUIHelper.getColor(0,0,0),true));
// Configure
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
and Inside my control resize listener,
class CustomControlListener implements ControlListener{
public CustomControlListener(){
}
@Override
public void controlResized(ControlEvent e) {
this.dataLayer = CellItemFactory.setDefaultColumnWidth2(this.dataLayer, this.type, this.cSheetBody,this.columns); // method to calculate column width for every resizeand its sets the columnwidth in the datalayer
setDataLayer(dataLayer);
if(getBodyDataProvider() == null){
setBodyDataProvider((SpanningBodyDataProvider)dataLayer.getDataProvider());
}
}
@Override
public void controlMoved(ControlEvent e) {
}
}
If I call the createform(type) in controlresize(), the resizing works fine but as you said before it is not the correct practice to set the layers and configuration everytime during the refresh/resize.
I do not want to call createform(type) method in the resize method.
Hope this information helps to find out whats wrong with the behaviour.
[Updated on: Wed, 13 January 2016 10:54] by Moderator
|
|
|
|
|
Re: Nattable column resize [message #1720067 is a reply to message #1720064] |
Thu, 14 January 2016 03:37  |
Eclipse User |
|
|
|
I still suggest to use percentage sizing instead of calculating the column widths on your own. You don't need a ControlListener. There is an example that shows the different ways and combinations for percentage sizing in NatTable.
|
|
|
Powered by
FUDForum. Page generated in 0.07839 seconds