Search in sources :

Example 1 with GridSearchStrategy

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

the class HierarchicalTreeLayerTest method testUnhideOnSearch.

@Test
public void testUnhideOnSearch() {
    this.treeLayer.setExpandOnSearch(false);
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(2, node.columnIndex);
    assertEquals(9, node.rowIndex);
    assertNotNull(node.rowObject);
    assertEquals(10, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    // search for the collapsed row
    ConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
    GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
    SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
    this.treeLayer.doCommand(searchCommand);
    assertEquals(11, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(2, node.columnIndex);
    assertEquals(9, node.rowIndex);
    assertNotNull(node.rowObject);
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) Test(org.junit.Test)

Example 2 with GridSearchStrategy

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

the class HierarchicalTreeLayerTest method testExpandAllLevelsOnSearchWithoutLevelHeader.

@Test
public void testExpandAllLevelsOnSearchWithoutLevelHeader() {
    this.treeLayer.setShowTreeLevelHeader(false);
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(6, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(2, this.treeLayer.collapsedNodes.size());
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    // search for the collapsed row
    ConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
    GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
    SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
    this.treeLayer.doCommand(searchCommand);
    assertEquals(11, this.treeLayer.getRowCount());
    assertEquals(0, this.treeLayer.collapsedNodes.size());
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) Test(org.junit.Test)

Example 3 with GridSearchStrategy

use of org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy 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);
    }
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) 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)

Example 4 with GridSearchStrategy

use of org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy 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 5 with GridSearchStrategy

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

the class HierarchicalTreeLayerTest method testExpandOnSearch.

@Test
public void testExpandOnSearch() {
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(2, node.columnIndex);
    assertEquals(9, node.rowIndex);
    assertNotNull(node.rowObject);
    assertEquals(10, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    // search for the collapsed row
    ConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
    GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
    SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
    this.treeLayer.doCommand(searchCommand);
    assertEquals(11, this.treeLayer.getRowCount());
    assertEquals(0, this.treeLayer.collapsedNodes.size());
    assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) Test(org.junit.Test)

Aggregations

GridSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy)8 SearchCommand (org.eclipse.nebula.widgets.nattable.search.command.SearchCommand)7 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)6 DefaultDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter)6 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)6 Test (org.junit.Test)6 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)4 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 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)1 ISearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.ISearchStrategy)1 SelectionSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.SelectionSearchStrategy)1 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)1