use of org.eclipse.nebula.widgets.nattable.util.ClientAreaAdapter in project nebula.widgets.nattable by eclipse.
the class _5043_VerticalSplitViewportExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getPersonsWithAddress(50), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// use a cell layer painter that is configured for left clipping
// this ensures that the rendering works correctly for split viewports
bodyDataLayer.setLayerPainter(new GridLineCellLayerPainter(false, true));
// create a ViewportLayer for the top part of the table and configure it
// to only contain the first 10 rows
final ViewportLayer viewportLayerTop = new ViewportLayer(bodyDataLayer);
viewportLayerTop.setMaxRowPosition(10);
// create a ViewportLayer for the bottom part of the table and configure
// it to only contain the last rows
ViewportLayer viewportLayerBottom = new ViewportLayer(bodyDataLayer);
viewportLayerBottom.setMinRowPosition(10);
// create a CompositeLayer that contains both ViewportLayers
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer("REGION_A", viewportLayerTop, 0, 0);
compositeLayer.setChildLayer("REGION_B", viewportLayerBottom, 0, 1);
// in order to make printing and exporting work correctly you need to
// register the following command handlers although in this example
// printing and exporting is not enabled, we show the registering
compositeLayer.registerCommandHandler(new MultiTurnViewportOnCommandHandler(viewportLayerTop, viewportLayerBottom));
compositeLayer.registerCommandHandler(new MultiTurnViewportOffCommandHandler(viewportLayerTop, viewportLayerBottom));
// set the height of the top viewport to only showing 2 rows at the same
// time
int topHeight = bodyDataLayer.getStartYOfRowPosition(2);
// as the CompositeLayer is setting a IClientAreaProvider for the
// composition we need to set a special ClientAreaAdapter after the
// creation of the CompositeLayer to support split viewports
ClientAreaAdapter topClientAreaAdapter = new ClientAreaAdapter(viewportLayerTop.getClientAreaProvider());
topClientAreaAdapter.setHeight(topHeight);
viewportLayerTop.setClientAreaProvider(topClientAreaAdapter);
// Wrap NatTable in composite so we can slap on the external vertical
// sliders
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, compositeLayer);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
natTable.setLayoutData(gridData);
createSplitSliders(composite, viewportLayerTop, viewportLayerBottom);
// add an IOverlayPainter to ensure the right border of the left
// viewport always this is necessary because the left border of layer
// stacks is not rendered by default
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int viewportBorderY = viewportLayerTop.getHeight() - 1;
gc.drawLine(0, viewportBorderY, layer.getWidth() - 1, viewportBorderY);
gc.setForeground(beforeColor);
}
});
return composite;
}
use of org.eclipse.nebula.widgets.nattable.util.ClientAreaAdapter in project nebula.widgets.nattable by eclipse.
the class _5044_HorizontalSplitViewportGridExample method createSplitSliders.
private void createSplitSliders(Composite natTableParent, final ILayer rowHeaderLayer, final ViewportLayer left, final ViewportLayer right) {
Composite sliderComposite = new Composite(natTableParent, SWT.NONE);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = false;
gridData.heightHint = 17;
sliderComposite.setLayoutData(gridData);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
sliderComposite.setLayout(gridLayout);
// Slider Left
// Need a composite here to set preferred size because Slider can't be
// subclassed.
Composite sliderLeftComposite = new Composite(sliderComposite, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
int width = ((ClientAreaAdapter) left.getClientAreaProvider()).getWidth();
width += rowHeaderLayer.getWidth();
return new Point(width, 17);
}
};
sliderLeftComposite.setLayout(new FillLayout());
gridData = new GridData();
gridData.horizontalAlignment = GridData.BEGINNING;
gridData.verticalAlignment = GridData.BEGINNING;
sliderLeftComposite.setLayoutData(gridData);
Slider sliderLeft = new Slider(sliderLeftComposite, SWT.HORIZONTAL);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
sliderLeft.setLayoutData(gridData);
left.setHorizontalScroller(new SliderScroller(sliderLeft));
// Slider Right
Slider sliderRight = new Slider(sliderComposite, SWT.HORIZONTAL);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.BEGINNING;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
sliderRight.setLayoutData(gridData);
right.setHorizontalScroller(new SliderScroller(sliderRight));
}
Aggregations