Search in sources :

Example 1 with SelectionSearchStrategy

use of org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy in project nebula.widgets.nattable by eclipse.

the class SearchDialog method createSearchCommand.

private SearchCommand createSearchCommand(String text, boolean isIncremental) {
    this.forwardValue = this.forwardButton.getSelection();
    this.allValue = this.allButton.getSelection();
    this.caseSensitiveValue = this.caseSensitiveButton.getSelection();
    this.wrapSearchValue = this.wrapSearchButton.getSelection();
    this.wholeWordValue = this.wholeWordButton.getSelection();
    this.incrementalValue = this.incrementalButton.getSelection();
    this.regexValue = this.regexButton.getSelection();
    // TODO
    // includeCollapsedValue = includeCollapsedButton.getSelection();
    this.columnFirstValue = this.columnFirstButton.getSelection();
    String searchDirection = this.forwardValue ? ISearchDirection.SEARCH_FORWARD : ISearchDirection.SEARCH_BACKWARDS;
    ISearchStrategy searchStrategy;
    if (this.allValue) {
        searchStrategy = new GridSearchStrategy(this.natTable.getConfigRegistry(), true, this.columnFirstValue);
    } else {
        searchStrategy = new SelectionSearchStrategy(this.natTable.getConfigRegistry(), this.columnFirstValue);
    }
    return new SearchCommand(text, this.natTable, searchStrategy, searchDirection, this.wrapSearchValue, this.caseSensitiveValue, !this.regexValue && this.wholeWordValue, !this.regexValue && this.allValue && isIncremental, this.regexValue, // includeCollapsedValue, comparator);
    false, this.comparator);
}
Also used : GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) ISearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.ISearchStrategy) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) SelectionSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy)

Example 2 with SelectionSearchStrategy

use of org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy 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)

Aggregations

SelectionSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 SearchCommand (org.eclipse.nebula.widgets.nattable.search.command.SearchCommand)1 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)1 GridSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy)1 ISearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.ISearchStrategy)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1