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: 2751
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: 2751
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 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();
Previous Topic:Text edition and new line
Next Topic:Filter Row Search Icon
Goto Forum:
  


Current Time: Fri Dec 13 00:52:05 GMT 2019

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

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

Back to the top