Search in sources :

Example 6 with ClientAreaAdapter

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;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) Composite(org.eclipse.swt.widgets.Composite) IOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Color(org.eclipse.swt.graphics.Color) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) Point(org.eclipse.swt.graphics.Point) MultiTurnViewportOffCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.MultiTurnViewportOffCommandHandler) MultiTurnViewportOnCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.MultiTurnViewportOnCommandHandler) ClientAreaAdapter(org.eclipse.nebula.widgets.nattable.util.ClientAreaAdapter) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) GridLayout(org.eclipse.swt.layout.GridLayout) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) GridData(org.eclipse.swt.layout.GridData) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) GridLineCellLayerPainter(org.eclipse.nebula.widgets.nattable.painter.layer.GridLineCellLayerPainter) GC(org.eclipse.swt.graphics.GC)

Example 7 with ClientAreaAdapter

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));
}
Also used : ClientAreaAdapter(org.eclipse.nebula.widgets.nattable.util.ClientAreaAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Slider(org.eclipse.swt.widgets.Slider) GridData(org.eclipse.swt.layout.GridData) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) SliderScroller(org.eclipse.nebula.widgets.nattable.viewport.SliderScroller) Point(org.eclipse.swt.graphics.Point)

Aggregations

ClientAreaAdapter (org.eclipse.nebula.widgets.nattable.util.ClientAreaAdapter)7 Point (org.eclipse.swt.graphics.Point)7 GridData (org.eclipse.swt.layout.GridData)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Composite (org.eclipse.swt.widgets.Composite)7 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)4 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)4 IOverlayPainter (org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter)4 Color (org.eclipse.swt.graphics.Color)4 GC (org.eclipse.swt.graphics.GC)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)3 PersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress)3 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)3 SliderScroller (org.eclipse.nebula.widgets.nattable.viewport.SliderScroller)3 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 Slider (org.eclipse.swt.widgets.Slider)3 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)2