update/refresh NatTable after updating the POJO [message #1250608] |
Wed, 19 February 2014 12:01 |
Edgar Kapler 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 #1251812 is a reply to message #1250942] |
Thu, 20 February 2014 16:20 |
Edgar Kapler 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();
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05319 seconds