Search in sources :

Example 11 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate 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 12 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchGridCommandHandlerTest method shouldFindTextInSelectionWithoutWrap.

@Test
public void shouldFindTextInSelectionWithoutWrap() {
    // select all
    this.gridLayer.doCommand(new SelectAllCommand());
    this.isForward = true;
    this.isWrapSearch = false;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTestOnSelection();
    this.isForward = false;
    this.searchText = "[2,3]";
    this.expected = new PositionCoordinate(null, 2, 3);
    doTestOnSelection();
    this.searchText = "[2,4]";
    this.expected = null;
    doTestOnSelection();
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 13 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchGridCommandHandlerTest method shouldFindTextInGrid.

@Test
public void shouldFindTextInGrid() {
    this.isForward = true;
    this.isWrapSearch = false;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.isForward = false;
    this.searchText = "[2,3]";
    this.expected = new PositionCoordinate(null, 2, 3);
    doTest();
    this.searchText = "[2,4]";
    this.expected = null;
    doTest();
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 14 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SearchGridCommandHandlerTest method shouldFindWholeWordInGrid.

@Test
public void shouldFindWholeWordInGrid() {
    this.isForward = true;
    this.isWrapSearch = false;
    this.isCaseSensitive = false;
    this.isWholeWord = true;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 15 with PositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate in project nebula.widgets.nattable by eclipse.

the class ColumnSearchStrategyTest method shouldAccessCellsInSelectedColumn.

@Test
public void shouldAccessCellsInSelectedColumn() {
    // Choose three columns for searching
    ColumnSearchStrategy columnSearchStrategy = new ColumnSearchStrategy(new int[] { 2, 5, 8 }, this.configRegistry);
    columnSearchStrategy.setComparator(new CellValueAsStringComparator<>());
    PositionCoordinate[] cellsToSearch = columnSearchStrategy.getColumnCellsToSearch(this.layer);
    PositionCoordinate cell = cellsToSearch[0];
    assertEquals(2, cell.columnPosition);
    cell = cellsToSearch[5];
    assertEquals(5, cell.columnPosition);
    cell = cellsToSearch[10];
    assertEquals(8, cell.columnPosition);
    assertEquals(15, cellsToSearch.length);
    assertEquals(0, this.gridLayer.getBodyLayer().getSelectionLayer().getSelectedCells().size());
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)97 Test (org.junit.Test)55 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)7 ArrayList (java.util.ArrayList)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)4 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)4 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 HashSet (java.util.HashSet)2 Pattern (java.util.regex.Pattern)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)2 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2