Search in sources :

Example 1 with ILayerListener

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

the class SearchGridCommandHandlerTest method doTest.

private void doTest() throws PatternSyntaxException {
    // Register call back
    final ILayerListener listener = new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof SearchEvent) {
                // Check event, coordinate should be in composite layer
                // coordinates
                SearchEvent searchEvent = (SearchEvent) event;
                if (SearchGridCommandHandlerTest.this.expected != null) {
                    assertEquals(SearchGridCommandHandlerTest.this.expected.columnPosition, searchEvent.getCellCoordinate().getColumnPosition());
                    assertEquals(SearchGridCommandHandlerTest.this.expected.rowPosition, searchEvent.getCellCoordinate().getRowPosition());
                } else {
                    assertNull(searchEvent.getCellCoordinate());
                }
            }
        }
    };
    this.gridLayer.addLayerListener(listener);
    try {
        SelectionLayer selectionLayer = this.gridLayer.getBodyLayer().getSelectionLayer();
        final GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(this.configRegistry, this.isWrapSearch, this.isColumnFirst);
        final SearchCommand searchCommand = new SearchCommand(this.searchText, selectionLayer, gridSearchStrategy, this.isForward ? ISearchDirection.SEARCH_FORWARD : ISearchDirection.SEARCH_BACKWARDS, this.isWrapSearch, this.isCaseSensitive, this.isWholeWord, this.isIncremental, this.isRegex, this.isIncludeCollapsed, new CellValueAsStringComparator<>());
        this.commandHandler.doCommand(selectionLayer, searchCommand);
        final PositionCoordinate searchResultCellCoordinate = this.commandHandler.getSearchResultCellCoordinate();
        if (this.expected != null) {
            assertEquals(this.expected.columnPosition, searchResultCellCoordinate.columnPosition);
            assertEquals(this.expected.rowPosition, searchResultCellCoordinate.rowPosition);
            assertEquals(1, selectionLayer.getSelectedCellPositions().length);
            assertEquals(this.expected.columnPosition, selectionLayer.getSelectedCellPositions()[0].columnPosition);
            assertEquals(this.expected.rowPosition, selectionLayer.getSelectedCellPositions()[0].rowPosition);
        } else {
            assertNull(searchResultCellCoordinate);
        }
    } finally {
        this.gridLayer.removeLayerListener(listener);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)

Example 2 with ILayerListener

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

the class ColumnReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderLeftCase.

@SuppressWarnings("boxing")
@Test
public /**
 * 	Index		10	11	12	13 ... 20
 *          --------------------
 *  Position 	0 	1	2	3 ... 20
 */
void returnsCorrectPositionRectangleForMultiColumnReorderLeftCase() {
    ColumnReorderLayer reorderLayer = new ColumnReorderLayer(new BaseDataLayerFixture(20, 20));
    // Build expected cell positions to redraw
    final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
    expectedPositions.add(new Rectangle(0, 0, 20, 20));
    reorderLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            ColumnReorderEvent multiReorder = (ColumnReorderEvent) event;
            assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
        }
    });
    // Reorder to beginning of grid
    List<Integer> fromColumnPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 0);
    // Reorder to middle of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(10, 0, 10, 20));
    fromColumnPositions = Arrays.asList(new Integer[] { 19, 18, 17, 16 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
    // Reorder to end of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(5, 0, 15, 20));
    fromColumnPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ILayerListener

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

the class ColumnReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderRightCase.

@SuppressWarnings("boxing")
@Test
public /**
 * 	Index		2	3	0	1 ... 20
 *          --------------------
 *  Position 	0 	1	2	3 ... 20
 */
void returnsCorrectPositionRectangleForMultiColumnReorderRightCase() {
    ColumnReorderLayer reorderLayer = new ColumnReorderLayer(new BaseDataLayerFixture(20, 20));
    // Build expected cell positions to redraw
    final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
    expectedPositions.add(new Rectangle(0, 0, 20, 20));
    reorderLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            ColumnReorderEvent multiReorder = (ColumnReorderEvent) event;
            assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
        }
    });
    // Reorder from beginning of grid
    List<Integer> fromColumnPositions = Arrays.asList(new Integer[] { 0, 1 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 2);
    // Reorder to middle of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(5, 0, 15, 20));
    fromColumnPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 10);
    // Reorder to end of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(10, 0, 10, 20));
    fromColumnPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
    reorderLayer.reorderMultipleColumnPositions(fromColumnPositions, 19);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ILayerListener

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

the class RowReorderLayerVisibleChangeTest method returnsCorrectPositionRectangleForMultiColumnReorderLeftCase.

@SuppressWarnings("boxing")
@Test
public /**
 * 	Index		10	11	12	13 ... 20
 *          --------------------
 *  Position 	0 	1	2	3 ... 20
 */
void returnsCorrectPositionRectangleForMultiColumnReorderLeftCase() {
    RowReorderLayer reorderLayer = new RowReorderLayer(new BaseDataLayerFixture(20, 20));
    // Build expected cell positions to redraw
    final Set<Rectangle> expectedPositions = new HashSet<Rectangle>();
    expectedPositions.add(new Rectangle(0, 0, 20, 20));
    reorderLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            RowReorderEvent multiReorder = (RowReorderEvent) event;
            assertTrue(multiReorder.getChangedPositionRectangles().containsAll(expectedPositions));
        }
    });
    // Reorder to beginning of grid
    List<Integer> fromRowPositions = Arrays.asList(new Integer[] { 10, 11, 12, 13 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 0);
    // Reorder to middle of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(0, 10, 20, 10));
    fromRowPositions = Arrays.asList(new Integer[] { 19, 18, 17, 16 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
    // Reorder to end of grid
    expectedPositions.clear();
    expectedPositions.add(new Rectangle(0, 5, 20, 15));
    fromRowPositions = Arrays.asList(new Integer[] { 5, 6, 7, 8 });
    reorderLayer.reorderMultipleRowPositions(fromRowPositions, 10);
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) BaseDataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) RowReorderEvent(org.eclipse.nebula.widgets.nattable.reorder.event.RowReorderEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ILayerListener

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

the class EditIntegrationTest method openEditorForSpannedCellsShouldOpenInline.

@Test
public void openEditorForSpannedCellsShouldOpenInline() throws Exception {
    CompositeLayer layer = new CompositeLayer(1, 1);
    SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(new DummySpanningBodyDataProvider(100, 100)));
    layer.setChildLayer(GridRegion.BODY, new ViewportLayer(selectionLayer), 0, 0);
    this.natTable = new NatTableFixture(layer, 1200, 300, false);
    layer.addConfiguration(new DefaultEditBindings());
    layer.addConfiguration(new DefaultEditConfiguration());
    this.natTable.enableEditingOnAllCells();
    final boolean[] inlineFired = new boolean[1];
    inlineFired[0] = false;
    selectionLayer.addLayerListener(new ILayerListener() {

        @Override
        public void handleLayerEvent(ILayerEvent event) {
            if (event instanceof InlineCellEditEvent) {
                inlineFired[0] = true;
            }
        }
    });
    this.natTable.configure();
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
    this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.F2));
    // Verify edit mode
    assertNotNull(this.natTable.getActiveCellEditor());
    assertEquals("Col: 1, Row: 1", this.natTable.getActiveCellEditor().getCanonicalValue());
    assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
    assertEquals("Col: 1, Row: 1", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
    // verify that inline editing is used and not dialog
    assertTrue("No InlineCellEditEvent fired", inlineFired[0]);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) DummySpanningBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) Test(org.junit.Test)

Aggregations

ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)15 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)14 Test (org.junit.Test)8 HashSet (java.util.HashSet)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 CellSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent)4 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)3 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)3 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)3 Collection (java.util.Collection)2 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)2 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 HashMap (java.util.HashMap)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1