Search in sources :

Example 1 with SearchEvent

use of net.sourceforge.nattable.search.event.SearchEvent in project translationstudio8 by heartsome.

the class SearchGridCellsCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, SearchCommand searchCommand) {
    searchCommand.convertToTargetLayer(targetLayer);
    AbstractSearchStrategy searchStrategy = (AbstractSearchStrategy) searchCommand.getSearchStrategy();
    if (searchCommand.getSearchEventListener() != null) {
        selectionLayer.addLayerListener(searchCommand.getSearchEventListener());
    }
    PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
    if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
        anchor = new PositionCoordinate(selectionLayer, 0, 0);
    }
    searchStrategy.setContextLayer(targetLayer);
    Object dataValueToFind = null;
    if ((dataValueToFind = searchCommand.getSearchText()) == null) {
        dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
    }
    searchStrategy.setCaseSensitive(searchCommand.isCaseSensitive());
    searchStrategy.setWrapSearch(searchCommand.isWrapSearch());
    searchStrategy.setSearchDirection(searchCommand.getSearchDirection());
    searchStrategy.setComparator(searchCommand.getComparator());
    searchResultCellCoordinate = searchStrategy.executeSearch(dataValueToFind);
    selectionLayer.fireLayerEvent(new SearchEvent(searchResultCellCoordinate));
    if (searchResultCellCoordinate != null) {
        final SelectCellCommand command = new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, searchResultCellCoordinate.rowPosition, false, false);
        command.setForcingEntireCellIntoViewport(true);
        selectionLayer.doCommand(command);
    }
    return true;
}
Also used : SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) SearchEvent(net.sourceforge.nattable.search.event.SearchEvent) AbstractSearchStrategy(net.sourceforge.nattable.search.strategy.AbstractSearchStrategy)

Aggregations

PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)1 SearchEvent (net.sourceforge.nattable.search.event.SearchEvent)1 AbstractSearchStrategy (net.sourceforge.nattable.search.strategy.AbstractSearchStrategy)1 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)1