Search in sources :

Example 1 with AbstractSearchStrategy

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

the class SearchGridCellsCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, SearchCommand searchCommand) throws PatternSyntaxException {
    searchCommand.convertToTargetLayer(targetLayer);
    final ILayerListener searchEventListener = searchCommand.getSearchEventListener();
    if (searchEventListener != null) {
        this.selectionLayer.addLayerListener(searchEventListener);
    }
    try {
        PositionCoordinate anchor = this.selectionLayer.getSelectionAnchor();
        if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
            anchor = new PositionCoordinate(this.selectionLayer, 0, 0);
        }
        Object dataValueToFind = null;
        if ((dataValueToFind = searchCommand.getSearchText()) == null) {
            dataValueToFind = this.selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
        }
        boolean performActionOnResult = true;
        if (searchCommand.getSearchStrategy() instanceof AbstractSearchStrategy) {
            AbstractSearchStrategy searchStrategy = (AbstractSearchStrategy) searchCommand.getSearchStrategy();
            searchStrategy.setContextLayer(targetLayer);
            searchStrategy.setCaseSensitive(searchCommand.isCaseSensitive());
            searchStrategy.setWrapSearch(searchCommand.isWrapSearch());
            searchStrategy.setWholeWord(searchCommand.isWholeWord());
            searchStrategy.setIncremental(searchCommand.isIncremental());
            searchStrategy.setRegex(searchCommand.isRegex());
            searchStrategy.setIncludeCollapsed(searchCommand.isIncludeCollapsed());
            searchStrategy.setSearchDirection(searchCommand.getSearchDirection());
            searchStrategy.setComparator(searchCommand.getComparator());
            performActionOnResult = !searchStrategy.processResultInternally();
        }
        this.searchResultCellCoordinate = searchCommand.getSearchStrategy().executeSearch(dataValueToFind);
        this.selectionLayer.fireLayerEvent(new SearchEvent(this.searchResultCellCoordinate));
        if (performActionOnResult && this.searchResultCellCoordinate != null) {
            final SelectCellCommand command = new SelectCellCommand(this.selectionLayer, this.searchResultCellCoordinate.columnPosition, this.searchResultCellCoordinate.rowPosition, false, false);
            command.setForcingEntireCellIntoViewport(true);
            this.selectionLayer.doCommand(command);
        }
    } finally {
        if (searchEventListener != null) {
            this.selectionLayer.removeLayerListener(searchEventListener);
        }
    }
    return true;
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) 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) AbstractSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.AbstractSearchStrategy)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)1 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)1 AbstractSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.AbstractSearchStrategy)1 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)1