use of org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter in project nebula.widgets.nattable by eclipse.
the class _5046_MultiScrollExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
List<PersonWithAddress> values = PersonService.getPersonsWithAddress(10);
ContentBodyLayerStack contentBodyLayer = new ContentBodyLayerStack(values);
StructureBodyLayerStack structureBodyLayer = new StructureBodyLayerStack(values, contentBodyLayer);
// build the column header layer
IDataProvider contentHeaderDataProvider = new DefaultColumnHeaderDataProvider(contentBodyLayer.propertyNames, contentBodyLayer.propertyToLabelMap);
DataLayer contentHeaderDataLayer = new DefaultColumnHeaderDataLayer(contentHeaderDataProvider);
AbstractLayer contentColumnHeaderLayer = new ColumnHeaderLayer(contentHeaderDataLayer, contentBodyLayer, contentBodyLayer.getSelectionLayer());
IDataProvider structureHeaderDataProvider = new DefaultColumnHeaderDataProvider(structureBodyLayer.propertyNames, structureBodyLayer.propertyToLabelMap);
DataLayer structureHeaderDataLayer = new DefaultColumnHeaderDataLayer(structureHeaderDataProvider);
ColumnHeaderLayer structureColumnHeaderLayer = new ColumnHeaderLayer(structureHeaderDataLayer, structureBodyLayer, structureBodyLayer.selectionLayer);
structureColumnHeaderLayer.setVerticalLayerDependency(contentColumnHeaderLayer);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(contentBodyLayer.bodyDataProvider));
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, contentBodyLayer, (SelectionLayer) null);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(contentHeaderDataProvider, rowHeaderDataLayer.getDataProvider());
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, contentColumnHeaderLayer);
ExtendedGridLayer gridLayer = new ExtendedGridLayer(contentBodyLayer, contentColumnHeaderLayer, structureBodyLayer, structureColumnHeaderLayer, rowHeaderLayer, cornerLayer);
// MULTI-VIEWPORT-CONFIGURATION
// 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
int leftWidth = 80;
ClientAreaAdapter leftClientAreaAdapter = new ClientAreaAdapter(structureBodyLayer.getViewportLayer().getClientAreaProvider());
leftClientAreaAdapter.setWidth(leftWidth);
structureBodyLayer.getViewportLayer().setClientAreaProvider(leftClientAreaAdapter);
structureBodyLayer.getViewportLayer().setVerticalScrollbarEnabled(false);
// use a cell layer painter that is configured for left clipping
// this ensures that the rendering works correctly for split
// viewports
contentBodyLayer.getSelectionLayer().setLayerPainter(new SelectionLayerPainter(true, false));
contentColumnHeaderLayer.setLayerPainter(new CellLayerPainter(true, false));
ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
// Wrap NatTable in composite so we can slap on the external horizontal
// sliders
Composite composite = new Composite(sc, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, gridLayer);
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
natTable.setLayoutData(gridData);
createSplitSliders(composite, gridLayer, rowHeaderLayer.getWidth());
sc.setContent(composite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
updateScrolledCompositeSize(sc, gridLayer);
// add an IOverlayPainter to render the split viewport border
natTable.addOverlayPainter(new IOverlayPainter() {
@Override
public void paintOverlay(GC gc, ILayer layer) {
Color beforeColor = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_GRAY);
int viewportBorderX = rowHeaderLayer.getWidth() + gridLayer.getStructureBody().getWidth() - 1;
gc.drawLine(viewportBorderX, 0, viewportBorderX, layer.getHeight() - 1);
gc.setForeground(beforeColor);
}
});
// Mouse move - Show resize cursor
natTable.getUiBindingRegistry().registerFirstMouseMoveBinding(new ClientAreaResizeMatcher(gridLayer), new VerticalResizeCursorAction());
natTable.getUiBindingRegistry().registerFirstMouseDragMode(new ClientAreaResizeMatcher(gridLayer), new ClientAreaResizeDragMode(gridLayer, sc));
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter in project nebula.widgets.nattable by eclipse.
the class _5042_HorizontalSplitViewportExample 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(true, false));
// create a ViewportLayer for the left part of the table and configure
// it to only contain the first 5 columns
final ViewportLayer viewportLayerLeft = new ViewportLayer(bodyDataLayer);
viewportLayerLeft.setMaxColumnPosition(5);
// create a ViewportLayer for the right part of the table and configure
// it to only contain the last 4 columns
ViewportLayer viewportLayerRight = new ViewportLayer(bodyDataLayer);
viewportLayerRight.setMinColumnPosition(5);
// create a CompositeLayer that contains both ViewportLayers
CompositeLayer compositeLayer = new CompositeLayer(2, 1);
compositeLayer.setChildLayer("REGION_A", viewportLayerLeft, 0, 0);
compositeLayer.setChildLayer("REGION_B", viewportLayerRight, 1, 0);
// 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(viewportLayerLeft, viewportLayerRight));
compositeLayer.registerCommandHandler(new MultiTurnViewportOffCommandHandler(viewportLayerLeft, viewportLayerRight));
// set the width of the left viewport to only showing 2 columns at the
// same time
int leftWidth = bodyDataLayer.getStartXOfColumnPosition(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 leftClientAreaAdapter = new ClientAreaAdapter(viewportLayerLeft.getClientAreaProvider());
leftClientAreaAdapter.setWidth(leftWidth);
viewportLayerLeft.setClientAreaProvider(leftClientAreaAdapter);
// Wrap NatTable in composite so we can slap on the external horizontal
// sliders
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, 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, viewportLayerLeft, viewportLayerRight);
// 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 viewportBorderX = viewportLayerLeft.getWidth() - 1;
gc.drawLine(viewportBorderX, 0, viewportBorderX, layer.getHeight() - 1);
gc.setForeground(beforeColor);
}
});
return composite;
}
use of org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter 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;
}
Aggregations