Search in sources :

Example 1 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method setup.

@Before
public void setup() {
    // de-normalize the object graph without parent structure objects
    this.data = HierarchicalHelper.deNormalize(CarService.getInput(), false, CarService.PROPERTY_NAMES_COMPACT);
    HierarchicalReflectiveColumnPropertyAccessor columnPropertyAccessor = new HierarchicalReflectiveColumnPropertyAccessor(CarService.PROPERTY_NAMES_COMPACT);
    this.bodyDataProvider = new ListDataProvider<>(this.data, columnPropertyAccessor);
    HierarchicalSpanningDataProvider spanningDataProvider = new HierarchicalSpanningDataProvider(this.bodyDataProvider, CarService.PROPERTY_NAMES_COMPACT);
    this.bodyDataLayer = new SpanningDataLayer(spanningDataProvider);
    // simply apply labels for every column by index
    this.bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    this.columnReorderLayer = new ColumnReorderLayer(this.bodyDataLayer);
    this.selectionLayer = new SelectionLayer(this.columnReorderLayer);
    this.treeLayer = new HierarchicalTreeLayer(this.selectionLayer, this.data, CarService.PROPERTY_NAMES_COMPACT);
    this.layerListener = new LayerListenerFixture();
    this.treeLayer.addLayerListener(this.layerListener);
}
Also used : SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) Before(org.junit.Before)

Example 2 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class AbstractLayerTest method testFireClonedEventIfMultipleListeners.

@Test
public void testFireClonedEventIfMultipleListeners() {
    LayerListenerFixture secondListener = new LayerListenerFixture();
    this.dataLayer.addLayerListener(secondListener);
    ILayerEvent event = new ColumnResizeEvent(this.dataLayer, 2);
    this.dataLayer.fireLayerEvent(event);
    List<ILayerEvent> receivedEvents = this.firstListener.getReceivedEvents();
    assertNotNull(receivedEvents);
    assertEquals(1, receivedEvents.size());
    assertNotSame(event, receivedEvents.get(0));
    receivedEvents = secondListener.getReceivedEvents();
    assertNotNull(receivedEvents);
    assertEquals(1, receivedEvents.size());
    assertSame(event, receivedEvents.get(0));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Test(org.junit.Test)

Example 3 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class DataLayerCommandHandlingTest method handleSameUpdateDataCommandRaisesNoEvents.

@Test
public void handleSameUpdateDataCommandRaisesNoEvents() throws Exception {
    LayerListenerFixture listener = new LayerListenerFixture();
    this.dataLayer.addLayerListener(listener);
    this.dataLayer.doCommand(this.command);
    Assert.assertTrue(listener.getReceivedEvents().size() == 1);
    Assert.assertTrue(listener.getReceivedEvents().get(0) instanceof CellVisualChangeEvent);
    // as calling the UpdateCommand with the same value should not trigger
    // any event
    // the size of the received events will stay 1 (the one event from
    // before which is cached)
    this.dataLayer.doCommand(this.command);
    Assert.assertTrue(listener.getReceivedEvents().size() == 1);
}
Also used : LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) CellVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent) Test(org.junit.Test)

Example 4 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class ColumnGroupHeaderLayerSelectionTest method setup.

@Before
public void setup() {
    this.dataProvider = new ListDataProvider<>(getNumberValues(), new ReflectiveColumnPropertyAccessor<>("columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber", "columnSixNumber", "columnSevenNumber", "columnEightNumber", "columnNineNumber", "columnTenNumber"));
    this.gridLayer = new GridLayerFixture(this.dataProvider);
    this.model = new ColumnGroupModel();
    // 10 columns in header
    this.columnGroupLayer = new ColumnGroupHeaderLayer(this.gridLayer.getColumnHeaderLayer(), this.gridLayer.getBodyLayer().getSelectionLayer(), this.model, false);
    this.columnGroupLayer.addConfiguration(new DefaultColumnGroupHeaderLayerConfiguration(this.model, true));
    this.gridLayer.getBodyLayer().getViewportLayer().registerCommandHandler(new ViewportSelectColumnGroupCommandHandler(this.gridLayer.getBodyLayer().getViewportLayer(), this.columnGroupLayer));
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_1, 0, 1, 2);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_2, 5, 6);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_3, 8, 9);
    this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1050, 200);
        }
    });
    this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
    this.layerListener = new LayerListenerFixture();
    this.gridLayer.getBodyLayer().addLayerListener(this.layerListener);
}
Also used : IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) DefaultColumnGroupHeaderLayerConfiguration(org.eclipse.nebula.widgets.nattable.group.config.DefaultColumnGroupHeaderLayerConfiguration) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) Shell(org.eclipse.swt.widgets.Shell) ViewportSelectColumnGroupCommandHandler(org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommandHandler) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 5 with LayerListenerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture in project nebula.widgets.nattable by eclipse.

the class ColumnHideShowLayerTest2 method shouldFireTheCorrectEventOnColumnHide.

@Test
public void shouldFireTheCorrectEventOnColumnHide() throws Exception {
    NatTable natTable = new NatTableFixture();
    LayerListenerFixture listener = new LayerListenerFixture();
    natTable.addLayerListener(listener);
    // Grid coordinates
    natTable.doCommand(new ColumnHideCommand(natTable, 5));
    assertEquals(1, listener.getReceivedEvents().size());
    HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent) listener.getReceivedEvents().get(0);
    Range range = hideEvent.getColumnPositionRanges().iterator().next();
    assertEquals(5, range.start);
    assertEquals(6, range.end);
    // The range Before hide: 5 -> 6
    // The range After hide: 5 -> 5 (column is not there anymore)
    StructuralDiff columnDiff = hideEvent.getColumnDiffs().iterator().next();
    assertEquals(5, columnDiff.getBeforePositionRange().start);
    assertEquals(6, columnDiff.getBeforePositionRange().end);
    assertEquals(5, columnDiff.getAfterPositionRange().start);
    assertEquals(5, columnDiff.getAfterPositionRange().end);
}
Also used : ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) HideColumnPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)37 Test (org.junit.Test)21 Before (org.junit.Before)16 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)11 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)7 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 Shell (org.eclipse.swt.widgets.Shell)4 Properties (java.util.Properties)3 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)3 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)3 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)3 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)2 DummyBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 HideColumnPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideColumnPositionsEvent)2 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)2