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;
}
Aggregations