Search in sources :

Example 11 with DefaultBodyLayerStack

use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.

the class _000_Styled_grid method setup.

private NatTable setup(Composite parent) {
    DummyGridLayerStack gridLayer = new DummyGridLayerStack();
    final NatTable natTable = new NatTable(parent, gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    // Add an AggregateConfigLabelAccumulator - we can add other
    // accumulators to this as required
    AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
    bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
    ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    aggregrateConfigLabelAccumulator.add(columnLabelAccumulator);
    aggregrateConfigLabelAccumulator.add(bodyLabelAccumulator);
    // Add a label for the highlighted column
    // We will add a style for this label to the config registry in a bit
    bodyLabelAccumulator.registerColumnOverrides(2, BODY_LABEL_1);
    columnLabelAccumulator.registerColumnOverrides(2, COLUMN_LABEL_1);
    // Register a command handler for the StyleEditorDialog
    DisplayColumnStyleEditorCommandHandler styleChooserCommandHandler = new DisplayColumnStyleEditorCommandHandler(gridLayer.getBodyLayer().getSelectionLayer(), columnLabelAccumulator, natTable.getConfigRegistry());
    DefaultBodyLayerStack bodyLayer = gridLayer.getBodyLayer();
    bodyLayer.registerCommandHandler(styleChooserCommandHandler);
    // Register the style editor as persistable
    // This will persist the style applied to the columns when
    // NatTable#saveState is invoked
    bodyLayer.registerPersistable(styleChooserCommandHandler);
    bodyLayer.registerPersistable(columnLabelAccumulator);
    return natTable;
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DisplayColumnStyleEditorCommandHandler(org.eclipse.nebula.widgets.nattable.style.editor.command.DisplayColumnStyleEditorCommandHandler) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator)

Example 12 with DefaultBodyLayerStack

use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack 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 13 with DefaultBodyLayerStack

use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.

the class ReorderColumnEventTest method reorderEventMustPropagateToTheTop.

/**
 * Fix for http://nattable.org/jira/browse/NTBL-476
 */
@Test
public void reorderEventMustPropagateToTheTop() throws Exception {
    DefaultBodyLayerStack underlyingLayer = new DefaultBodyLayerStack(new DataLayerFixture(20, 10, 100, 20));
    NatTableFixture natTableFixture = new NatTableFixture(underlyingLayer);
    // Add listener
    LayerListenerFixture listenerFixture = new LayerListenerFixture();
    natTableFixture.addLayerListener(listenerFixture);
    assertEquals(6, natTableFixture.getColumnCount());
    assertEquals(1, natTableFixture.getColumnIndexByPosition(1));
    // Move to outside the visible range
    List<Integer> columnToMove = Arrays.asList(1, 2, 3);
    int destinationPosition = 10;
    natTableFixture.doCommand(new MultiColumnReorderCommand(natTableFixture, columnToMove, destinationPosition));
    // Ensure that the event propagates to the top
    assertEquals(1, listenerFixture.getEventsCount());
    assertNotNull(listenerFixture.getReceivedEvent(ColumnReorderEvent.class));
    assertEquals(4, natTableFixture.getColumnIndexByPosition(1));
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) Test(org.junit.Test)

Example 14 with DefaultBodyLayerStack

use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.

the class ReorderRowEventTest method reorderEventMustPropagateToTheTop.

@Test
public void reorderEventMustPropagateToTheTop() throws Exception {
    DefaultBodyLayerStack underlyingLayer = new DefaultBodyLayerStack(new RowReorderLayer(new DataLayerFixture(10, 10, 100, 20)));
    NatTableFixture natTableFixture = new NatTableFixture(underlyingLayer);
    // Add listener
    LayerListenerFixture listenerFixture = new LayerListenerFixture();
    natTableFixture.addLayerListener(listenerFixture);
    Assert.assertEquals(10, natTableFixture.getRowCount());
    Assert.assertEquals(1, natTableFixture.getRowIndexByPosition(1));
    // Move to outside the visible range
    List<Integer> rowsToMove = Arrays.asList(1, 2, 3);
    int destinationPosition = 10;
    natTableFixture.doCommand(new MultiRowReorderCommand(natTableFixture, rowsToMove, destinationPosition));
    // Ensure that the event propagates to the top
    Assert.assertEquals(1, listenerFixture.getEventsCount());
    Assert.assertNotNull(listenerFixture.getReceivedEvent(RowReorderEvent.class));
    Assert.assertEquals(4, natTableFixture.getRowIndexByPosition(1));
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) MultiRowReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiRowReorderCommand) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) RowReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer) Test(org.junit.Test)

Example 15 with DefaultBodyLayerStack

use of org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack in project nebula.widgets.nattable by eclipse.

the class AutoResizeColumnsTest method shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected.

/**
 * Scenario: Multiple columns are selected but a non selected column is auto
 * resized.
 */
@Test
public void shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected() throws Exception {
    GridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    setClientAreaProvider(gridLayer);
    // Resize grid column 1, 2
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 1, 10));
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    // Fully select columns 1, 2
    SelectionLayer selectionLayer = ((DefaultBodyLayerStack) gridLayer.getBodyLayer()).getSelectionLayer();
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 0, 0, false, false));
    selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 1, 0, true, false));
    assertEquals(2, selectionLayer.getFullySelectedColumnPositions().length);
    // Resize grid column 5
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 5, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(5));
    // Auto resize column 5
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 5, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    // Columns 1 and 2 should not be resized
    assertEquals(10, gridLayer.getColumnWidthByPosition(1));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    assertTrue(gridLayer.getColumnWidthByPosition(5) > 10);
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) Test(org.junit.Test)

Aggregations

DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)23 Test (org.junit.Test)10 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)7 ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)7 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)6 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)6 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)6 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)5 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 Before (org.junit.Before)5 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)4 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)4 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)4 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)4 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)4 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)4 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)4 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)4