Search in sources :

Example 56 with SelectionLayer

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.

the class PercentageSizingDataLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite simplePanel = new Composite(panel, SWT.NONE);
    simplePanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(simplePanel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
    final DummyModifiableBodyDataProvider dataProvider = new DummyModifiableBodyDataProvider(3, 2);
    // example for percentage calculation with default sizing
    // all columns will be same size while the NatTable itself will have
    // 100%
    final DataLayer n1DataLayer = new DataLayer(dataProvider);
    n1DataLayer.setColumnPercentageSizing(true);
    n1DataLayer.setRowPercentageSizing(true);
    ViewportLayer layer = new ViewportLayer(new SelectionLayer(n1DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n1 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n1);
    // example for fixed percentage sizing
    // ensure that the sum of column sizes is not greater than 100
    final DataLayer n2DataLayer = new DataLayer(dataProvider);
    n2DataLayer.setColumnWidthPercentageByPosition(0, 25);
    n2DataLayer.setColumnWidthPercentageByPosition(1, 25);
    n2DataLayer.setColumnWidthPercentageByPosition(2, 50);
    layer = new ViewportLayer(new SelectionLayer(n2DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n2 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n2);
    // example for mixed percentage sizing
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    final DataLayer n3DataLayer = new DataLayer(dataProvider);
    n3DataLayer.setColumnPercentageSizing(true);
    n3DataLayer.setColumnWidthPercentageByPosition(0, 40);
    n3DataLayer.setColumnWidthPercentageByPosition(2, 40);
    layer = new ViewportLayer(new SelectionLayer(n3DataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable n3 = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n3);
    // example for mixed fixed/percentage sizing
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    final DataLayer mixDataLayer = new DataLayer(dataProvider);
    mixDataLayer.setColumnPercentageSizing(true);
    mixDataLayer.setColumnPercentageSizing(0, false);
    mixDataLayer.setColumnPercentageSizing(1, false);
    mixDataLayer.setColumnWidthByPosition(0, 100);
    mixDataLayer.setColumnWidthByPosition(1, 100);
    layer = new ViewportLayer(new SelectionLayer(mixDataLayer));
    layer.setRegionName(GridRegion.BODY);
    final NatTable mix = new NatTable(simplePanel, layer);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mix);
    // example for percentage calculation with default sizing in a grid
    // all columns will be same size while the NatTable itself will have
    // 100%
    DummyGridLayerStack gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n4DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n4DataLayer.setColumnPercentageSizing(true);
    n4DataLayer.setRowPercentageSizing(true);
    final NatTable n4 = new NatTable(gridPanel, gridLayer, false);
    n4.addConfiguration(new DefaultNatTableStyleConfiguration());
    n4.addConfiguration(new HeaderMenuConfiguration(n4));
    n4.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n4);
    // example for fixed percentage sizing in a grid
    // ensure that the sum of column sizes is not greater than 100
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n5DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n5DataLayer.setColumnWidthByPosition(0, 25);
    n5DataLayer.setColumnWidthByPosition(1, 25);
    n5DataLayer.setColumnWidthByPosition(2, 50);
    n5DataLayer.setColumnPercentageSizing(true);
    final NatTable n5 = new NatTable(gridPanel, gridLayer, false);
    n5.addConfiguration(new DefaultNatTableStyleConfiguration());
    n5.addConfiguration(new HeaderMenuConfiguration(n5));
    n5.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n5);
    // example for mixed percentage sizing in a grid
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer n6DataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    n6DataLayer.setColumnWidthByPosition(0, 20);
    n6DataLayer.setColumnWidthByPosition(2, 20);
    n6DataLayer.setColumnPercentageSizing(true);
    final NatTable n6 = new NatTable(gridPanel, gridLayer, false);
    n6.addConfiguration(new DefaultNatTableStyleConfiguration());
    n6.addConfiguration(new HeaderMenuConfiguration(n6));
    n6.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(n6);
    // example for mixed fixed/percentage sizing in a grid
    // configure not every column with the exact percentage value, this way
    // the columns for which
    // no exact values are set will use the remaining space
    gridLayer = new DummyGridLayerStack(dataProvider);
    final DataLayer mixGridDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    mixGridDataLayer.setColumnPercentageSizing(true);
    mixGridDataLayer.setColumnPercentageSizing(0, false);
    mixGridDataLayer.setColumnPercentageSizing(1, false);
    mixGridDataLayer.setColumnWidthByPosition(0, 100);
    mixGridDataLayer.setColumnWidthByPosition(1, 100);
    final NatTable mixGrid = new NatTable(gridPanel, gridLayer, false);
    mixGrid.addConfiguration(new DefaultNatTableStyleConfiguration());
    mixGrid.addConfiguration(new HeaderMenuConfiguration(mixGrid));
    mixGrid.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mixGrid);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("add column - no width");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n1.refresh();
            n2.refresh();
            n3.refresh();
            mix.refresh();
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    Button addColumnButton2 = new Button(buttonPanel, SWT.PUSH);
    addColumnButton2.setText("add column - 20 percent width");
    addColumnButton2.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dataProvider.setColumnCount(dataProvider.getColumnCount() + 1);
            n1DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n2DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n3DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            mixDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n4DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n5DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n6DataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            mixGridDataLayer.setColumnWidthPercentageByPosition(dataProvider.getColumnCount() - 1, 20);
            n1.refresh();
            n2.refresh();
            n3.refresh();
            mix.refresh();
            n4.refresh();
            n5.refresh();
            n6.refresh();
            mixGrid.refresh();
        }
    });
    return panel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DummyModifiableBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyModifiableBodyDataProvider) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 57 with SelectionLayer

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.

the class CompositeLayerPerformanceTest method testGridLayerPerformance.

@Test
public void testGridLayerPerformance() {
    DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(1000000, 1000000);
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    DummyColumnHeaderDataProvider columnHeaderDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
    rowHeaderDataLayer.setDefaultColumnWidth(40);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    layer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) Test(org.junit.Test)

Example 58 with SelectionLayer

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.

the class _002_Using_a_custom_cell_painter method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // Setup the layer stack
    final MyDataProvider myDataProvider = new MyDataProvider();
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(myDataProvider));
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(myDataProvider)), selectionLayer, selectionLayer);
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, selectionLayer, 0, 1);
    NatTable natTable = new NatTable(parent, compositeLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // Add our custom painting configuration
    natTable.addConfiguration(new CustomPaintingConfig());
    natTable.configure();
    return natTable;
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider)

Example 59 with SelectionLayer

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.

the class _002_Lateral_layer_composition method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(200, 1000000);
    SelectionLayer selectionLayer = new SelectionLayer(new ColumnReorderLayer(new DataLayer(bodyDataProvider)));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(new DummyColumnHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    NatTable natTable = new NatTable(parent, compositeLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    natTable.configure();
    return natTable;
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DebugMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider)

Example 60 with SelectionLayer

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer in project nebula.widgets.nattable by eclipse.

the class CompositeGridLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    DummyBodyDataProvider bodyDataProvider = new DummyBodyDataProvider(500, 1000000);
    SelectionLayer selectionLayer = new SelectionLayer(new ColumnHideShowLayer(new ColumnReorderLayer(new DataLayer(bodyDataProvider))));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    DummyColumnHeaderDataProvider columnHeaderDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
    rowHeaderDataLayer.setDefaultColumnWidth(40);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
    GridLayer compositeLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
    return new NatTable(parent, compositeLayer);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)

Aggregations

SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)107 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)75 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)73 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)71 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)63 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)58 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)54 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)47 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)46 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)44 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)43 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)43 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)42 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)41 HashMap (java.util.HashMap)38 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)37 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)34 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)27 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)25 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)25