Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Nattable column resize(Nattable column resize issue)
Nattable column resize [message #1719954] Wed, 13 January 2016 13:33 Go to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
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 13:45]

Report message to a moderator

Re: Nattable column resize [message #1719962 is a reply to message #1719954] Wed, 13 January 2016 13:44 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
In my custom resizing listener method I set the proper datalayer.setColumnWidthByPosition(i, 30)


I don't know what you are doing where, but it sounds like the references in your listeners aren't correct after the refresh. What are you doing on refresh? Are you doing such weird things like exchanging the layer stack (which is IMHO in almost every case wrong)?
Re: Nattable column resize [message #1719964 is a reply to message #1719962] Wed, 13 January 2016 13:47 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
Hi Dirk,

Thanks for the quick reply.
Quote:
Are you doing such weird things like exchanging the layer stack (which is IMHO in almost every case wrong)?


What do you mean by exchanging the layer stack?
Re: Nattable column resize [message #1719965 is a reply to message #1719962] Wed, 13 January 2016 13:52 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
I have attached sample nattable file (edited the column names in paint, so it doesnt look good).

If you can see, in that there is a white space betwen the last column and the scrollbar. This is what happens when I resize it. The expected behaviour is, it should resize every column and fit to the composite perfectly without white space.


  • Attachment: Nattable.png
    (Size: 11.98KB, Downloaded 513 times)

[Updated on: Wed, 13 January 2016 13:53]

Report message to a moderator

Re: Nattable column resize [message #1719966 is a reply to message #1719965] Wed, 13 January 2016 13:54 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Why don't you use percentage sizing in that case?
Re: Nattable column resize [message #1719974 is a reply to message #1719966] Wed, 13 January 2016 14:15 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
I tried the percentage resizing, but it still has the same problem .It is resized it for the first time, but once the refresh method(in which the layers and configuration is set. ) is called and the resizing doesnt work anymore.

I have different settings to show different types of nattable, so once the settings are chosen , the refresh method is called.

Note: Different types of nattable, I mean nattable with different number columns and data

[Updated on: Wed, 13 January 2016 14:19]

Report message to a moderator

Re: Nattable column resize [message #1719976 is a reply to message #1719974] Wed, 13 January 2016 14:23 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
Sorry for the wrong information, it does not work in the first try as well. Just checked by resizing the nattable to the last possible size it shows the empty space as I have attached in the jpeg file before
Re: Nattable column resize [message #1719982 is a reply to message #1719976] Wed, 13 January 2016 14:47 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Since I don't know what you are doing in your refresh method, I can't help. The way you explain what you are doing should work. I can only assume your references are not correct. But without further information I am not able to help.
Re: Nattable column resize [message #1719991 is a reply to message #1719982] Wed, 13 January 2016 15:53 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
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 15:54]

Report message to a moderator

Re: Nattable column resize [message #1720000 is a reply to message #1719991] Wed, 13 January 2016 16:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Sorry but your code doesn't make much sense to me. Have you looked into our various examples?

For example you are registering command handlers multiple times, e.g. .registerCommandHandler(new VisualRefreshCommandHandler()); Now doing this will break a lot of functionality in NatTable because the VisualRefreshCommand is not processed at the level that it should.

Then you are setting the layer stack on an existing NatTable. Why?
You are setting a layout to the NatTable instance. But NatTable is not a container and therefore setting a layout is wrong.

You store the DataLayer and the DataProvider on control resize. That also makes no sense. For what reason? And why are you sure it is the correct instance?

Sorry, I can not tell you what exactly is wrong. For me it looks like you should start over and create things new because there are a lot of things incorrect with your code regarding NatTable creation.
Re: Nattable column resize [message #1720064 is a reply to message #1720000] Thu, 14 January 2016 08:26 Go to previous messageGo to next message
christy jovita is currently offline christy jovitaFriend
Messages: 22
Registered: June 2014
Junior Member
I will start creating from scratch. But Could you please give an idea what should be there in controlresized() method when resizing is done?

Quote:
But NatTable is not a container and therefore setting a layout is wrong.


I am not setting the layout. That code is commented out.

[Updated on: Thu, 14 January 2016 08:34]

Report message to a moderator

Re: Nattable column resize [message #1720067 is a reply to message #1720064] Thu, 14 January 2016 08:37 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
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.
Previous Topic:New Features for NatTable 1.4
Next Topic:set Background color to row based on condition
Goto Forum:
  


Current Time: Tue Apr 23 12:52:57 GMT 2024

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

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

Back to the top