Home » Eclipse Projects » NatTable » How to combine two nattables (so that they appear to be one)
How to combine two nattables (so that they appear to be one) [message #1691969] |
Sat, 11 April 2015 04:13  |
Eclipse User |
|
|
|
Hi,
I have a question regarding the possibility to combine two nattables.
This is hte scenario:
I have a complex grid which extensively uses the SpanningDataLayer. The table has a complex header part which has different columns than the rest of the table (it would actually also make use of a SpanningDataLayer). If the columns of the grid are resized, the header should not change. So the idea is to implement the header in an individual table and just display it above the main grid. Ideally the columns of the main grid should be displayed on top of the header table. The header table itself does not need to display column headers. If possible both tables should be displayed in one viewport. So vertical scrolling should also move the header table.
Is it somehow possible to achieve this (or smething close to this) with nattable?
Thanks in advance
Thorsten
|
|
| |
Re: How to combine two nattables (so that they appear to be one) [message #1691987 is a reply to message #1691973] |
Sat, 11 April 2015 10:57   |
Eclipse User |
|
|
|
Thank you very much for the quick response.
I already tried to use a composite layer with two data layers and a header layer. I think that is what you propose.
I used the VerticalCompositionExample as a starting point, simply created a new data layer with only 2 columns and added it in between the column header and the original data layer.
The second data layer should span the whole table. So I set the layer to percentage resizing. Unfortunately the columns of the original data layer overlapp my second data layer columns.
That is why I thought I need to use two individual tables.
Is the Nattable able to manage this scenario and am I just doing something wrong?
Thanks in advance.
Thorsten
Here is the code I used:
[code][
/*******************************************************************************
* Copyright (c) 2013 Dirk Fauth and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.nattable.examples._500_Layers._503_Compositions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.data.person.Person;
import org.eclipse.nebula.widgets.nattable.examples.data.person.PersonService;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Example showing a NatTable that contains a column header and a body layer.
*
* @author Dirk Fauth
*
*/
public class CopyOf_5031_VerticalCompositionExample extends AbstractNatExample {
public static void main(String[] args) throws Exception {
StandaloneNatExampleRunner.run(600, 400,
new CopyOf_5031_VerticalCompositionExample());
}
@Override
public String getDescription() {
return "This example shows how to assemble a table that consists of a column header and a body layer.";
}
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames1 = { "firstName", "lastName", "gender",
"married", "birthday" };
String[] propertyNames2 = { "firstName", "lastName" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<String, String>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor1 = new ReflectiveColumnPropertyAccessor<Person>(
propertyNames1);
IColumnPropertyAccessor<Person> columnPropertyAccessor2 = new ReflectiveColumnPropertyAccessor<Person>(
propertyNames2);
final List<Person> data = PersonService.getPersons(10);
IDataProvider bodyDataProvider = new ListDataProvider<Person>(data,
columnPropertyAccessor1);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider bodyDataProvider2 = new ListDataProvider<Person>(data,
columnPropertyAccessor2);
final DataLayer bodyDataLayer2 = new DataLayer(bodyDataProvider2);
bodyDataLayer2.setColumnPercentageSizing(true);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(
new DefaultColumnHeaderDataProvider(propertyNames1,
propertyToLabelMap)), viewportLayer, selectionLayer);
// set the region labels to make default configurations work, e.g.
// selection
CompositeLayer compositeLayer = new CompositeLayer(1, 3);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER,
columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 2);
compositeLayer.setChildLayer(GridRegion.BODY, bodyDataLayer2, 0, 1);
return new NatTable(parent, compositeLayer);
}
}
/code]
|
|
|
Re: How to combine two nattables (so that they appear to be one) [message #1691988 is a reply to message #1691973] |
Sat, 11 April 2015 10:57   |
Eclipse User |
|
|
|
Thank you very much for the quick response.
I already tried to use a composite layer with two data layers and a header layer. I think that is what you propose.
I used the VerticalCompositionExample as a starting point, simply created a new data layer with only 2 columns and added it in between the column header and the original data layer.
The second data layer should span the whole table. So I set the layer to percentage resizing. Unfortunately the columns of the original data layer overlapp my second data layer columns.
That is why I thought I need to use two individual tables.
Is the Nattable able to manage this scenario and am I just doing something wrong?
Thanks in advance.
Thorsten
Here is the code I used:
[code][
/*******************************************************************************
* Copyright (c) 2013 Dirk Fauth and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Dirk Fauth <dirk.fauth@gmail.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.nebula.widgets.nattable.examples._500_Layers._503_Compositions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor;
import org.eclipse.nebula.widgets.nattable.examples.AbstractNatExample;
import org.eclipse.nebula.widgets.nattable.examples.data.person.Person;
import org.eclipse.nebula.widgets.nattable.examples.data.person.PersonService;
import org.eclipse.nebula.widgets.nattable.examples.runner.StandaloneNatExampleRunner;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* Example showing a NatTable that contains a column header and a body layer.
*
* @author Dirk Fauth
*
*/
public class CopyOf_5031_VerticalCompositionExample extends AbstractNatExample {
public static void main(String[] args) throws Exception {
StandaloneNatExampleRunner.run(600, 400,
new CopyOf_5031_VerticalCompositionExample());
}
@Override
public String getDescription() {
return "This example shows how to assemble a table that consists of a column header and a body layer.";
}
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames1 = { "firstName", "lastName", "gender",
"married", "birthday" };
String[] propertyNames2 = { "firstName", "lastName" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<String, String>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
IColumnPropertyAccessor<Person> columnPropertyAccessor1 = new ReflectiveColumnPropertyAccessor<Person>(
propertyNames1);
IColumnPropertyAccessor<Person> columnPropertyAccessor2 = new ReflectiveColumnPropertyAccessor<Person>(
propertyNames2);
final List<Person> data = PersonService.getPersons(10);
IDataProvider bodyDataProvider = new ListDataProvider<Person>(data,
columnPropertyAccessor1);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider bodyDataProvider2 = new ListDataProvider<Person>(data,
columnPropertyAccessor2);
final DataLayer bodyDataLayer2 = new DataLayer(bodyDataProvider2);
bodyDataLayer2.setColumnPercentageSizing(true);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(
new DefaultColumnHeaderDataProvider(propertyNames1,
propertyToLabelMap)), viewportLayer, selectionLayer);
// set the region labels to make default configurations work, e.g.
// selection
CompositeLayer compositeLayer = new CompositeLayer(1, 3);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER,
columnHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 2);
compositeLayer.setChildLayer(GridRegion.BODY, bodyDataLayer2, 0, 1);
return new NatTable(parent, compositeLayer);
}
}
/code]
|
|
| | | |
Re: How to combine two nattables (so that they appear to be one) [message #1692061 is a reply to message #1692024] |
Mon, 13 April 2015 02:39  |
Eclipse User |
|
|
|
Putting two nattables on top of each other perfectly suits my needs. Maybe the topic of this thread is a little missleading. There are of course some issues. It would for example be great if the whole structure could be exported to excel as is. Therefor I just wanted to know if the approach to use two tables is the right one or if there are ways to achieve this with one table.
Thanks for sharing your point of view. I have implemented it now with two tables and a vertical scrollbar using a specific IScroller.
Regards
Thorsten
|
|
|
Goto Forum:
Current Time: Mon Jul 28 12:07:18 EDT 2025
Powered by FUDForum. Page generated in 1.07209 seconds
|