Search in sources :

Example 56 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration 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 DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerSummaryRowConcurrencyTest method setup.

@Before
public void setup() {
    List<Value> values = new ArrayList<Value>();
    values.add(new Value(1));
    values.add(new Value(2));
    values.add(new Value(3));
    values.add(new Value(4));
    values.add(new Value(5));
    values.add(new Value(6));
    values.add(new Value(7));
    values.add(new Value(8));
    values.add(new Value(9));
    values.add(new Value(10));
    IColumnAccessor<Value> columnAccessor = new IColumnAccessor<Value>() {

        @Override
        public Object getDataValue(Value rowObject, int columnIndex) {
            if (columnIndex % 2 == 0) {
                try {
                    Thread.sleep(80);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return rowObject.value;
        }

        @Override
        public void setDataValue(Value rowObject, int columnIndex, Object newValue) {
        }

        @Override
        public int getColumnCount() {
            return 10;
        }
    };
    EventList<Value> eventList = GlazedLists.eventList(values);
    TransformedList<Value, Value> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    ConfigRegistry configRegistry = new ConfigRegistry();
    final GroupByDataLayer<Value> dataLayer = new GroupByDataLayer<Value>(new GroupByModel(), eventList, columnAccessor);
    // DataLayer dataLayer = new DataLayer(dataProvider);
    GlazedListsEventLayer<Value> glazedListsEventLayer = new GlazedListsEventLayer<Value>(dataLayer, rowObjectsGlazedList);
    DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(glazedListsEventLayer);
    this.summaryRowLayer = new FixedSummaryRowLayer(dataLayer, bodyLayerStack, configRegistry, false);
    this.summaryRowLayer.setHorizontalCompositeDependency(false);
    CompositeLayer composite = new CompositeLayer(1, 2);
    composite.setChildLayer("SUMMARY", this.summaryRowLayer, 0, 0);
    composite.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
    NatTable natTable = new NatTableFixture(composite, false);
    natTable.addConfiguration(new DefaultSummaryRowConfiguration() {

        @Override
        protected void addSummaryProviderConfig(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new SummationSummaryProvider(dataLayer.getDataProvider(), false), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
        }
    });
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
}
Also used : GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.NatTableFixture) ArrayList(java.util.ArrayList) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IColumnAccessor(org.eclipse.nebula.widgets.nattable.data.IColumnAccessor) SummationSummaryProvider(org.eclipse.nebula.widgets.nattable.summaryrow.SummationSummaryProvider) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) FixedSummaryRowLayer(org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer) GroupByModel(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByModel) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) DefaultSummaryRowConfiguration(org.eclipse.nebula.widgets.nattable.summaryrow.DefaultSummaryRowConfiguration) Before(org.junit.Before)

Example 58 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class StaticFilterGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    IConfigRegistry configRegistry = new ConfigRegistry();
    StaticFilterExampleGridLayer underlyingLayer = new StaticFilterExampleGridLayer(configRegistry);
    DataLayer bodyDataLayer = underlyingLayer.getBodyDataLayer();
    IDataProvider dataProvider = underlyingLayer.getBodyDataProvider();
    // NOTE: Register the accumulator on the body data layer.
    // This ensures that the labels are bound to the column index and are
    // unaffected by column order.
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    NatTable natTable = new NatTable(parent, underlyingLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
    // natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    natTable.addConfiguration(new FilterRowCustomConfiguration());
    natTable.addConfiguration(EditableGridExample.editableGridConfiguration(columnLabelAccumulator, dataProvider));
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    return natTable;
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) StaticFilterExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.StaticFilterExampleGridLayer) FilterRowDataLayer(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Example 59 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class ComboBoxGlazedListsFilterStrategyTest method init.

@BeforeClass
public static void init() {
    // initialize the collection with a big amount of values
    EventList<Person> baseCollection = GlazedLists.eventList(PersonService.getFixedPersons());
    for (int i = 1; i < 1000; i++) {
        baseCollection.addAll(PersonService.getFixedPersons());
    }
    filterList = new FilterList<>(GlazedLists.eventList(baseCollection));
    configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
    new ComboBoxFilterRowConfiguration().configureRegistry(configRegistry);
    columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
    IColumnAccessor<Person> bodyDataColumnAccessor = new ReflectiveColumnPropertyAccessor<>(personPropertyNames);
    comboBoxDataProvider = new GlazedListsFilterRowComboBoxDataProvider<>(new DataLayer(new ListDataProvider<>(filterList, bodyDataColumnAccessor)), baseCollection, bodyDataColumnAccessor);
    filterStrategy = new ComboBoxGlazedListsFilterStrategy<>(comboBoxDataProvider, filterList, bodyDataColumnAccessor, configRegistry);
    dataProvider = new FilterRowDataProvider<>(filterStrategy, columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Also used : ComboBoxFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.combobox.ComboBoxFilterRowConfiguration) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) BeforeClass(org.junit.BeforeClass)

Example 60 with DefaultNatTableStyleConfiguration

use of org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration in project nebula.widgets.nattable by eclipse.

the class DefaultGlazedListsFilterStrategyTest method init.

@BeforeClass
public static void init() {
    // initialize the collection with a big amount of values
    filterList = new FilterList<>(GlazedLists.eventList(PersonService.getFixedPersons()));
    for (int i = 1; i < 1000; i++) {
        filterList.addAll(PersonService.getFixedPersons());
    }
    configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(configRegistry);
    new DefaultFilterRowConfiguration().configureRegistry(configRegistry);
    columnHeaderLayer = new DataLayerFixture(5, 2, 100, 50);
    dataProvider = new FilterRowDataProvider<>(new DefaultGlazedListsFilterStrategy<>(filterList, new ReflectiveColumnPropertyAccessor<Person>(personPropertyNames), configRegistry), columnHeaderLayer, columnHeaderLayer.getDataProvider(), configRegistry);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultFilterRowConfiguration(org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration) DataLayerFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.DataLayerFixture) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)127 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)113 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)96 HashMap (java.util.HashMap)72 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)72 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)72 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)64 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)61 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)61 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)58 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)56 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)54 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)54 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)52 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)51 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)49 GridLayout (org.eclipse.swt.layout.GridLayout)47 Composite (org.eclipse.swt.widgets.Composite)43 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)41