Search in sources :

Example 1 with CellVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent 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 2 with CellVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method shouldFireCellVisualChangeEventOnceSummaryIsCalculated.

@Test
public void shouldFireCellVisualChangeEventOnceSummaryIsCalculated() throws Exception {
    // need to resize because otherwise the ViewportLayer would not process
    // the CellVisualChangeEvent any further
    this.natTable.setSize(800, 400);
    LayerListenerFixture listener = new LayerListenerFixture();
    this.natTable.addLayerListener(listener);
    // Trigger summary calculation
    this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    Thread.sleep(500);
    assertTrue(listener.containsInstanceOf(CellVisualChangeEvent.class));
    CellVisualChangeEvent event = (CellVisualChangeEvent) listener.getReceivedEvents().get(0);
    assertEquals(this.askPriceColumnIndex, event.getColumnPosition());
    assertEquals(4, event.getRowPosition());
    Collection<Rectangle> changedPositionRectangles = event.getChangedPositionRectangles();
    assertEquals(1, changedPositionRectangles.size());
    // only the cell gets updated
    Rectangle rectangle = changedPositionRectangles.iterator().next();
    assertEquals(6, rectangle.x);
    assertEquals(4, rectangle.y);
    assertEquals(1, rectangle.width);
    assertEquals(1, rectangle.height);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) CellVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent) Test(org.junit.Test)

Example 3 with CellVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class TickUpdateCommandHandlerTest method shouldNotThrowExceptionOnNoSelection.

@Test
public void shouldNotThrowExceptionOnNoSelection() {
    // if no exception occurs this test succeeds
    // we also check that no update has been triggered
    this.selectionLayer.clear();
    this.selectionLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof CellVisualChangeEvent) {
                fail("update triggered");
            }
        }
    });
    this.commandHandler.doCommand(new TickUpdateCommand(this.testConfigRegistry, true));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) CellVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent) Test(org.junit.Test)

Example 4 with CellVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayerSummaryRowConcurrencyTest method shouldCorrectlyCalculateSummaryValues.

// summary value == 55
@Test
public void shouldCorrectlyCalculateSummaryValues() {
    this.summaryRowLayer.addLayerListener(new ILayerListener() {

        @Override
        public synchronized void handleLayerEvent(ILayerEvent event) {
            if (event instanceof CellVisualChangeEvent) {
                GroupByDataLayerSummaryRowConcurrencyTest.this.calcCount++;
            }
        }
    });
    assertNull(this.summaryRowLayer.getDataValueByPosition(0, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(1, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(2, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(3, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(4, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(5, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(6, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(7, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(8, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(9, 0));
    assertNull(this.summaryRowLayer.getDataValueByPosition(10, 0));
    while (this.calcCount < 11) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(0, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(1, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(2, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(3, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(4, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(5, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(6, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(7, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(8, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(9, 0));
    assertEquals(55.0, this.summaryRowLayer.getDataValueByPosition(10, 0));
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) CellVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent) Test(org.junit.Test)

Example 5 with CellVisualChangeEvent

use of org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent in project nebula.widgets.nattable by eclipse.

the class DataLayerCommandHandlingTest method handleUpdateDataCommandRaisesEvents.

@Test
public void handleUpdateDataCommandRaisesEvents() throws Exception {
    LayerListenerFixture listener = new LayerListenerFixture();
    this.dataLayer.addLayerListener(listener);
    this.dataLayer.doCommand(this.command);
    Assert.assertTrue(listener.getReceivedEvents().get(0) instanceof CellVisualChangeEvent);
}
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)

Aggregations

CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)8 Test (org.junit.Test)5 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)2 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 SortedList (ca.odell.glazedlists.SortedList)1 TreeList (ca.odell.glazedlists.TreeList)1 Timer (java.util.Timer)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 DefaultBooleanDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter)1 CellEditDragMode (org.eclipse.nebula.widgets.nattable.edit.action.CellEditDragMode)1 MouseEditAction (org.eclipse.nebula.widgets.nattable.edit.action.MouseEditAction)1