Search in sources :

Example 56 with PositionCoordinate

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

the class SearchGridCommandHandlerTest method doTestOnSelection.

private void doTestOnSelection() 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 SelectionSearchStrategy gridSearchStrategy = new SelectionSearchStrategy(this.configRegistry, 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(50, selectionLayer.getSelectedCellPositions().length);
            assertEquals(this.expected.columnPosition, selectionLayer.getSelectionAnchor().getColumnPosition());
            assertEquals(this.expected.rowPosition, selectionLayer.getSelectionAnchor().getRowPosition());
        } else {
            assertNull(searchResultCellCoordinate);
        }
    } finally {
        this.gridLayer.removeLayerListener(listener);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) 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) SelectionSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy)

Example 57 with PositionCoordinate

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

the class SearchGridCommandHandlerTest method shouldFindTextInGridAfterWrapping.

@Test
public void shouldFindTextInGridAfterWrapping() {
    this.isForward = true;
    this.isWrapSearch = true;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,2]";
    this.expected = new PositionCoordinate(null, 2, 2);
    doTest();
    this.isForward = false;
    this.isWrapSearch = false;
    this.searchText = "[2,4]";
    this.expected = null;
    doTest();
    this.isWrapSearch = true;
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    selectCell(0, 0);
    final int columnCount = this.gridLayer.getBodyLayer().getColumnCount();
    final int rowCount = this.gridLayer.getBodyLayer().getRowCount();
    this.searchText = "[" + String.valueOf(columnCount - 1) + ",";
    this.expected = new PositionCoordinate(null, columnCount - 1, rowCount - 1);
    doTest();
    this.isForward = true;
    this.searchText = "[0,";
    this.expected = new PositionCoordinate(null, 0, 0);
    doTest();
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 58 with PositionCoordinate

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

the class SearchGridCommandHandlerTest method shouldFindTextInGridNonIncrementally.

@Test
public void shouldFindTextInGridNonIncrementally() {
    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 = "[";
    this.expected = new PositionCoordinate(null, 2, 3);
    doTest();
    this.searchText = "[2";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.searchText = "[2,4";
    this.expected = null;
    doTest();
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 59 with PositionCoordinate

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

the class SearchGridCommandHandlerTest method shouldFindTextInSelectionWithWrap.

@Test
public void shouldFindTextInSelectionWithWrap() {
    // select all
    this.gridLayer.doCommand(new SelectAllCommand());
    this.isForward = true;
    this.isWrapSearch = true;
    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 = new PositionCoordinate(null, 2, 4);
    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 60 with PositionCoordinate

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

the class SearchGridCommandHandlerTest method shouldFindTextInGridIncrementally.

@Test
public void shouldFindTextInGridIncrementally() {
    this.isForward = true;
    this.isWrapSearch = false;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = true;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[";
    this.expected = new PositionCoordinate(null, 2, 2);
    doTest();
    this.searchText = "[2";
    this.expected = new PositionCoordinate(null, 2, 2);
    doTest();
    this.searchText = "[2,";
    this.expected = new PositionCoordinate(null, 2, 2);
    doTest();
    this.searchText = "[2,4";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.isForward = false;
    this.searchText = "[";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.searchText = "[2";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.searchText = "[2,";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTest();
    this.searchText = "[2,2";
    this.expected = new PositionCoordinate(null, 2, 2);
    doTest();
}
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