use of org.eclipse.nebula.widgets.nattable.search.event.SearchEvent in project nebula.widgets.nattable by eclipse.
the class SearchGridCommandHandlerTest method doTest.
private void doTest() 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 GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(this.configRegistry, this.isWrapSearch, 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(1, selectionLayer.getSelectedCellPositions().length);
assertEquals(this.expected.columnPosition, selectionLayer.getSelectedCellPositions()[0].columnPosition);
assertEquals(this.expected.rowPosition, selectionLayer.getSelectedCellPositions()[0].rowPosition);
} else {
assertNull(searchResultCellCoordinate);
}
} finally {
this.gridLayer.removeLayerListener(listener);
}
}
use of org.eclipse.nebula.widgets.nattable.search.event.SearchEvent in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayer method handleLayerEvent.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isVerticalStructureChanged()) {
// recalculate node row indexes
// build a new collection of nodes to avoid duplication clashes
// as nodes are equal per column and row index
int negativeIndex = -1;
Set<HierarchicalTreeNode> updatedCollapsedNodes = new HashSet<HierarchicalTreeNode>();
for (HierarchicalTreeNode node : this.collapsedNodes) {
int newRowIndex = findTopRowIndex(node.columnIndex, node.rowObject);
// the underlying collection
if (newRowIndex >= 0) {
updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, newRowIndex, this.underlyingList.get(newRowIndex)));
} else if (this.retainRemovedRowObjectNodes) {
updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, negativeIndex, node.rowObject));
negativeIndex--;
}
}
this.collapsedNodes.clear();
this.collapsedNodes.addAll(updatedCollapsedNodes);
// recalculate hidden rows based on updated collapsed nodes
Set<Integer> updatedHiddenRows = new HashSet<Integer>();
for (HierarchicalTreeNode node : this.collapsedNodes) {
updatedHiddenRows.addAll(getChildIndexes(node.columnIndex, node.rowIndex));
}
getHiddenRowIndexes().clear();
getHiddenRowIndexes().addAll(updatedHiddenRows);
}
} else if (event instanceof SearchEvent) {
PositionCoordinate coord = ((SearchEvent) event).getCellCoordinate();
if (coord != null) {
Integer foundIndex = coord.getLayer().getRowIndexByPosition(coord.rowPosition);
if (getHiddenRowIndexes().contains(foundIndex)) {
if (this.expandOnSearch) {
// not collapsible
for (int level = this.nodeColumnMapping.size() - 2; level >= 0; level--) {
ILayerCell nodeCell = coord.getLayer().getCellByPosition(this.nodeColumnMapping.get(level), coord.rowPosition);
int colIdx = coord.getLayer().getColumnIndexByPosition(nodeCell.getOriginColumnPosition());
int rowIdx = coord.getLayer().getRowIndexByPosition(nodeCell.getOriginRowPosition());
if (this.collapsedNodes.contains(new HierarchicalTreeNode(colIdx, rowIdx, null))) {
expandOrCollapse(colIdx, rowIdx);
}
}
} else {
// only make the single row visible again
getHiddenRowIndexes().remove(foundIndex);
}
}
invalidateCache();
fireLayerEvent(new ShowRowPositionsEvent(this, Arrays.asList(foundIndex)));
}
}
super.handleLayerEvent(event);
}
use of org.eclipse.nebula.widgets.nattable.search.event.SearchEvent 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;
}
use of org.eclipse.nebula.widgets.nattable.search.event.SearchEvent 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);
}
}
Aggregations