Home » Eclipse Projects » NatTable » How to combine two nattables (so that they appear to be one)
| |
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 14:57 |
Thorsten Schlathölter Messages: 312 Registered: February 2012 Location: Düsseldorf |
Senior Member |
|
|
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 14:57 |
Thorsten Schlathölter Messages: 312 Registered: February 2012 Location: Düsseldorf |
Senior Member |
|
|
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]
|
|
| | | | |
Goto Forum:
Current Time: Wed Apr 24 22:56:39 GMT 2024
Powered by FUDForum. Page generated in 0.04377 seconds
|