Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » update/refresh NatTable after updating the POJO
update/refresh NatTable after updating the POJO [message #1250608] Wed, 19 February 2014 12:01 Go to next message
Edgar Kapler is currently offline Edgar KaplerFriend
Messages: 3
Registered: February 2014
Junior Member
Hello everyone!

I used the Code from the Tutorial at:
http://eclipse.org/nattable/documentation.php?page=articles

Here is the code of my NatTable. It works and displays the desired data.

A ListDataProvider over my POJO "Fault":

	// IRowDataProvider for Fault
	public IRowDataProvider<Fault> getFaultRowDataProvider () { 
		return	new ListDataProvider<Fault>(faultList,
				new ReflectiveColumnPropertyAccessor<Fault> (Fault.getPropertyNames().clone()));
	} 


A NatTable based on the tutorial:

public  class FaultNatTable{ 

	private BodyLayerStack bodyLayer;

	public NatTable createNatTable (Composite parent, IDataProvider dataProvider) { 

//a data Provider based on POJO
		bodyLayer = new BodyLayerStack (dataProvider);
//does this Handler even work?
		bodyLayer.registerCommandHandler(new StructuralRefreshCommandHandler());

		DefaultColumnHeaderDataProvider colHeaderDataProvider =  new  DefaultColumnHeaderDataProvider (Fault.getPropertyNames().clone());
		DefaultRowHeaderDataProvider rowHeaderDataProvider =  new  DefaultRowHeaderDataProvider (dataProvider);
		ColumnHeaderLayerStack columnHeaderLayer =  new  ColumnHeaderLayerStack (colHeaderDataProvider);
		RowHeaderLayerStack rowHeaderLayer =  new  RowHeaderLayerStack (rowHeaderDataProvider);
		DefaultCornerDataProvider cornerDataProvider =  new  DefaultCornerDataProvider (colHeaderDataProvider,  
				rowHeaderDataProvider); 
		CornerLayer cornerLayer =  new  CornerLayer ( new  DataLayer (cornerDataProvider), rowHeaderLayer,  
				columnHeaderLayer); 

		GridLayer gridLayer =  new  GridLayer (bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
		NatTable natTable =  new  NatTable (parent, gridLayer, false);

		gridLayer.registerCommandHandler(new StructuralRefreshCommandHandler());
		
		// Configuration of the NatTable 
		natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
		natTable.addConfiguration(new DefaultFreezeGridBindings());

		// Creation of the dialogue of choice of columns
		/*		DisplayColumnChooserCommandHandler columnChooserCommandHandler =  new  DisplayColumnChooserCommandHandler (
			bodyLayer.getSelectionLayer(),
			bodyLayer.getColumnHideShowLayer(),
			columnHeaderLayer,
			colHeaderDataProvider);
		compositeFreezeLayer.registerCommandHandler (columnChooserCommandHandler);*/

		natTable. addConfiguration ( new  HeaderMenuConfiguration (natTable) { 
			@ Override 
			protected PopupMenuBuilder createColumnHeaderMenu (NatTable natTable) { 
				return  super . createColumnHeaderMenu (natTable). withColumnChooserMenuItem ();
			} 
		} );

		natTable.configure();

		return natTable;
	} 

	/** 
	 *  The  stack  of  layers  for  the  party  central  of  the  NatTable 
	 *  @ author  A .  BERNARD 
	 * 
	 */ 
	public  class BodyLayerStack extends AbstractLayerTransform { 

		private SelectionLayer selectionLayer;

		public  BodyLayerStack (IDataProvider dataProvider) { 
			DataLayer bodyDataLayer =  new  DataLayer (dataProvider);
			selectionLayer =  new SelectionLayer (bodyDataLayer);
			ViewportLayer viewportLayer =  new  ViewportLayer (selectionLayer);
			setUnderlyingLayer (viewportLayer);
		} 

		/** 
		 *  Returns  the  layer  of  selection 
		 *  @ return 
		 */ 
		public SelectionLayer getSelectionLayer () { 
			return selectionLayer;
		} 

	} 

	/** 
	 *  The  stack  of  layers  for  the  in - heads  of  column 
	 *  @ author  A .  BERNARD 
	 * 
	 */ 
	public  class ColumnHeaderLayerStack extends AbstractLayerTransform { 

		public  ColumnHeaderLayerStack (IDataProvider dataProvider) { 
			DataLayer DataLayer =  new  DataLayer (dataProvider);
			ColumnHeaderLayer colHeaderLayer =  new  ColumnHeaderLayer (DataLayer,  
					bodyLayer, bodyLayer.getSelectionLayer ());
			setUnderlyingLayer (colHeaderLayer);
		} 
	} 

	/** 
	 *  The  stack  of  layers  for  the  in - heads  of  lines 
	 *  @ author  A .  BERNARD 
	 * 
	 */ 
	public class RowHeaderLayerStack extends AbstractLayerTransform { 

		public  RowHeaderLayerStack (IDataProvider dataProvider) { 
			DataLayer DataLayer =  new  DataLayer (dataProvider, 50 , 20 );
			RowHeaderLayer rowHeaderLayer =  new  RowHeaderLayer (DataLayer,  
					bodyLayer, bodyLayer.getSelectionLayer());
			setUnderlyingLayer (rowHeaderLayer);
		} 
	} 

	public String getExampleTitle () { 
		return  " Basic  Example " ;
	} 

} 


But if I update the List<POJO> nothing happens when I trigger a refresh, like:

myTableInstance.refresh();



My Question is, what do I have to do to update the displayed data?


Thanks for your help,

Edgar
Re: update/refresh NatTable after updating the POJO [message #1250721 is a reply to message #1250608] Wed, 19 February 2014 14:27 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Where do you update the data? The NatTable only knows about the values in the list.

Are you trying to exchange the list? This might not work because of several references. In that case you simply should operate on the list instead of exchanging it.
Re: update/refresh NatTable after updating the POJO [message #1250841 is a reply to message #1250721] Wed, 19 February 2014 16:58 Go to previous messageGo to next message
Edgar Kapler is currently offline Edgar KaplerFriend
Messages: 3
Registered: February 2014
Junior Member
Yes, I try to exchange the whole list. A model class holds the list in one of its fields.
All values are changing at that point of the application. Even the size of the List<POJO> can change.
In which way should I use the NatTable to cover this condition? Is there maybe an example doing something similar?
Re: update/refresh NatTable after updating the POJO [message #1250942 is a reply to message #1250841] Wed, 19 February 2014 19:05 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
No there is no such example, as I already said that you should try to operate on the list you put into the NatTable.

You can try to either replace the list in the data provider you are using or try to replace the data provider set to the data layer. Not sure if this is working.

Typically I suggest in such cases to set a list to the NatTable and perform clear/add all operations when the underlying list changes. Of course in such cases list modifications wouldn't work.
Re: update/refresh NatTable after updating the POJO [message #1251812 is a reply to message #1250942] Thu, 20 February 2014 16:20 Go to previous messageGo to next message
Edgar Kapler is currently offline Edgar KaplerFriend
Messages: 3
Registered: February 2014
Junior Member
I tried it the way you mentioned it. To conclude this thread quick I will give an example of my dirty solution. It is based on Bernard's tutorial and the replays in this thread. Thank you very much for those fast and kind replies!

It also worked on manipulating the List directly in the my model class. The important thing is that I broke the reference to my List<POJO> by exchanging it with a new one.

Simply clear the list and add the each element from a second List, which contains the new data, to the list to keep the reference.

I hope this helps other newbies to have a lot fun with the NatTables!


public  class FaultNatTable{ 

	private BodyLayerStack bodyLayer;
	List<Fault> lisFault = new LinkedList<Fault>();

	public NatTable createNatTable (Composite parent, List<Fault> lisFault) { 

		addAllLisFault(lisFault);
		
		IDataProvider iDataProvider = new ListDataProvider<Fault>(this.lisFault,
				new ReflectiveColumnPropertyAccessor<Fault> (Fault.getPropertyNames().clone()));

		System.out.println("Column count: " + iDataProvider.getColumnCount());
		System.out.println("Row count: " + iDataProvider.getRowCount());
		
		bodyLayer = new BodyLayerStack (iDataProvider);

		DefaultColumnHeaderDataProvider colHeaderDataProvider =  new  DefaultColumnHeaderDataProvider (Fault.getPropertyNames().clone());
		DefaultRowHeaderDataProvider rowHeaderDataProvider =  new  DefaultRowHeaderDataProvider (iDataProvider);
		ColumnHeaderLayerStack columnHeaderLayer =  new  ColumnHeaderLayerStack (colHeaderDataProvider);
		RowHeaderLayerStack rowHeaderLayer =  new  RowHeaderLayerStack (rowHeaderDataProvider);
		DefaultCornerDataProvider cornerDataProvider =  new  DefaultCornerDataProvider (colHeaderDataProvider,  
				rowHeaderDataProvider); 
		CornerLayer cornerLayer =  new  CornerLayer ( new  DataLayer (cornerDataProvider), rowHeaderLayer,  
				columnHeaderLayer); 

		GridLayer gridLayer =  new  GridLayer (bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
		NatTable natTable =  new  NatTable (parent, gridLayer, false);

		ColumnGroupLayerStack clst = new ColumnGroupLayerStack(iDataProvider);
		// Configuration of the NatTable 
		natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
		natTable.addConfiguration(new DefaultFreezeGridBindings());

		//Creation of the dialogue of choice of columns

		DisplayColumnChooserCommandHandler columnChooserCommandHandler =  new  DisplayColumnChooserCommandHandler (
				bodyLayer.getSelectionLayer(),
				bodyLayer.getColumnHideShowLayer(),
				columnHeaderLayer.getColumnHeaderLayer(),
				bodyLayer.getDataLayer(),
				clst.getColumnGroupHeaderLayer(),
				clst.getColumnGroupModel()
				);
		
		cornerLayer.registerCommandHandler (columnChooserCommandHandler);

		natTable. addConfiguration ( new  HeaderMenuConfiguration (natTable) { 
			@ Override 
			protected PopupMenuBuilder createColumnHeaderMenu (NatTable natTable) { 
				return  super . createColumnHeaderMenu (natTable). withColumnChooserMenuItem ();
			} 
		} );

		natTable.configure();

		return natTable;
	}
	
	public void clearLisFault(){
		while(this.lisFault.size()>0){
			lisFault.remove(lisFault.size()-1);
		}
	}
	
	public void addAllLisFault(List<Fault> lisFault) {
		for (int i = 0; i < lisFault.size(); i++) {
			this.lisFault.add(lisFault.get(i));
		}
	}

	public  class BodyLayerStack extends AbstractLayerTransform { 

		private SelectionLayer selectionLayer;
		private ColumnHideShowLayer columnHideShowLayer;
		private DataLayer bodyDataLayer;
		
		public  BodyLayerStack (IDataProvider dataProvider) { 
			bodyDataLayer =  new  DataLayer (dataProvider);
			selectionLayer =  new SelectionLayer (bodyDataLayer);
			ViewportLayer viewportLayer =  new  ViewportLayer (selectionLayer);
			columnHideShowLayer = new ColumnHideShowLayer(viewportLayer);
			//setUnderlyingLayer (viewportLayer);
			setUnderlyingLayer (columnHideShowLayer);
		} 

		/** 
		 *  Returns  the  layer  of  selection 
		 *  @ return 
		 */ 
		public SelectionLayer getSelectionLayer () { 
			return selectionLayer;
		}

		public ColumnHideShowLayer getColumnHideShowLayer () { 
			return columnHideShowLayer;
		} 

		public DataLayer getDataLayer() {
			return bodyDataLayer;
		}
	} 

	public  class ColumnHeaderLayerStack extends AbstractLayerTransform { 
		private ColumnHeaderLayer colHeaderLayer;
		public  ColumnHeaderLayerStack (IDataProvider dataProvider) { 
			DataLayer DataLayer =  new  DataLayer (dataProvider);
			colHeaderLayer =  new  ColumnHeaderLayer (DataLayer,  
					bodyLayer, bodyLayer.getSelectionLayer ());
			setUnderlyingLayer (colHeaderLayer);
		}
		
		public ColumnHeaderLayer getColumnHeaderLayer() {
			return colHeaderLayer;
		}
	} 

	public class RowHeaderLayerStack extends AbstractLayerTransform { 

		public  RowHeaderLayerStack (IDataProvider dataProvider) { 
			DataLayer DataLayer =  new  DataLayer (dataProvider, 50 , 20 );
			RowHeaderLayer rowHeaderLayer =  new  RowHeaderLayer (DataLayer,  
					bodyLayer, bodyLayer.getSelectionLayer());
			setUnderlyingLayer (rowHeaderLayer);
		} 
	} 

	
	public class ColumnGroupLayerStack extends AbstractLayerTransform { 
		ColumnGroupModel columnGroupModel;
		ColumnGroupHeaderLayer cgHeader;
		public  ColumnGroupLayerStack (IDataProvider dataProvider) {
			DataLayer DataLayer =  new  DataLayer (dataProvider);
			columnGroupModel = new ColumnGroupModel();
			cgHeader = new ColumnGroupHeaderLayer(
					DataLayer,
					bodyLayer.getSelectionLayer(),
					columnGroupModel);
			setUnderlyingLayer (cgHeader);
		} 
		
		public ColumnGroupModel getColumnGroupModel(){
			return columnGroupModel;
		}
		
		public ColumnGroupHeaderLayer getColumnGroupHeaderLayer(){
			return cgHeader;
		}
	}
} 


To refresh the NatTable use:

myTableInstance.refresh();
Re: update/refresh NatTable after updating the POJO [message #1826254 is a reply to message #1251812] Wed, 22 April 2020 08:43 Go to previous messageGo to next message
Chinniah Govindasamy is currently offline Chinniah GovindasamyFriend
Messages: 12
Registered: December 2017
Junior Member
Clearing the list and add new object to the list is not working.
only iterating the list and making changes in the object is reflecting.

Is there any other way updating the values as a list.
Re: update/refresh NatTable after updating the POJO [message #1826273 is a reply to message #1826254] Wed, 22 April 2020 14:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 47
Registered: March 2020
Member
It should work as described here. And there are also some examples that show this.

Please have a look at our examples, e.g. https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_300_Data/_308_DataModificationExample.java where you can add or remove items dynamically by modifying the underlying list.

If it is not working for you, you are doing something wrong.

And please don't hijack old posts with new questions!
Re: update/refresh NatTable after updating the POJO [message #1826993 is a reply to message #1826273] Tue, 05 May 2020 20:43 Go to previous messageGo to next message
Chinniah Govindasamy is currently offline Chinniah GovindasamyFriend
Messages: 12
Registered: December 2017
Junior Member
Thanks for the quick reply.Is their any example available how it can be done in the Nat Tree Table.
Also is there any example like if i pass a new list that should override the old one.
Because in my case every time there is change in value in the combo box, all the values in the table will change , on that occasion i have to delete each and every row and insert all the new rows one by one.
which is fine for small amount of data. but what if the there are lots of data, is that fine to delete all the rows one by one and insert one by one. or is there any other way.
Re: update/refresh NatTable after updating the POJO [message #1827000 is a reply to message #1826993] Wed, 06 May 2020 04:08 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Exchange the data provider https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_300_Data/_307_ChangeDataProviderExample.java
Re: update/refresh NatTable after updating the POJO [message #1827356 is a reply to message #1827000] Wed, 13 May 2020 16:23 Go to previous message
Chinniah Govindasamy is currently offline Chinniah GovindasamyFriend
Messages: 12
Registered: December 2017
Junior Member
Hello Drik,

Thanks for the quick reply. I tried the above given example it worked like charm. Now i am able to update the table fast and easy.Thanks for example.
Previous Topic:How to detect, if underlying data has changed, when editing a cell
Next Topic:problem with column hide
Goto Forum:
  


Current Time: Tue Apr 23 06:11:52 GMT 2024

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

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

Back to the top