Search in sources :

Example 21 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method movingSelectionWithDownArrow.

@Test
public void movingSelectionWithDownArrow() throws Exception {
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 5, 2, NO_SHIFT, NO_CTRL));
    // Note: the co-ordinates from this point on are in selection later
    // co-ordinates
    SWTUtils.pressKey(SWT.ARROW_DOWN, this.natTable);
    SWTUtils.pressKey(SWT.ARROW_DOWN, this.natTable);
    assertPositionEquals(4, 3, this.selectionLayer.getLastSelectedCellPosition());
    assertSelectionAnchorEquals(4, 3);
    SWTUtils.pressKey(SWT.ARROW_DOWN, SWT.SHIFT, this.natTable);
    SWTUtils.pressKey(SWT.ARROW_DOWN, SWT.SHIFT, this.natTable);
    assertSelectCellsCount(2);
    assertCellSelected(4, 3);
    assertCellSelected(4, 4);
    assertSelectionAnchorEquals(4, 3);
    SWTUtils.pressKey(SWT.ARROW_DOWN, SWT.MOD1, this.natTable);
    assertSelectCellsCount(1);
    int lastRow = this.selectionLayer.getRowCount() - 1;
    assertPositionEquals(4, lastRow, this.selectionLayer.getSelectedCellPositions()[0]);
    assertPositionEquals(4, lastRow, this.selectionLayer.getLastSelectedCellPosition());
    assertSelectionAnchorEquals(4, lastRow);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 22 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method movingSelectionWithRightArrow.

@Test
public void movingSelectionWithRightArrow() throws Exception {
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 5, 2, NO_SHIFT, NO_CTRL));
    // Note: the co-ordinates from this point on are in selection later
    // co-ordinates
    SWTUtils.pressKey(SWT.ARROW_RIGHT, this.natTable);
    assertPositionEquals(5, 1, this.selectionLayer.getLastSelectedCellPosition());
    assertSelectionAnchorEquals(5, 1);
    SWTUtils.pressKey(SWT.ARROW_RIGHT, SWT.SHIFT, this.natTable);
    assertSelectCellsCount(2);
    assertCellSelected(5, 1);
    assertCellSelected(6, 1);
    assertSelectionAnchorEquals(5, 1);
    SWTUtils.pressKey(SWT.ARROW_RIGHT, SWT.MOD1, this.natTable);
    assertSelectCellsCount(1);
    assertPositionEquals(9, 1, this.selectionLayer.getSelectedCellPositions()[0]);
    assertPositionEquals(9, 1, this.selectionLayer.getLastSelectedCellPosition());
    assertSelectionAnchorEquals(9, 1);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 23 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method movingSelectionWithLeftArrow.

@Test
public void movingSelectionWithLeftArrow() throws Exception {
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 5, 2, NO_SHIFT, NO_CTRL));
    // Note: the co-ordinates from this point on are in selection later
    // co-ordinates
    SWTUtils.pressKey(SWT.ARROW_LEFT, this.natTable);
    assertPositionEquals(3, 1, getSelectedCells()[0]);
    assertSelectionAnchorEquals(3, 1);
    SWTUtils.pressKey(SWT.ARROW_LEFT, SWT.SHIFT, this.natTable);
    assertSelectCellsCount(2);
    assertPositionEquals(2, 1, getSelectedCells()[0]);
    assertPositionEquals(3, 1, getSelectedCells()[1]);
    assertSelectionAnchorEquals(3, 1);
    SWTUtils.pressKey(SWT.ARROW_LEFT, SWT.MOD1, this.natTable);
    assertSelectCellsCount(1);
    assertPositionEquals(0, 1, getSelectedCells()[0]);
    assertSelectionAnchorEquals(0, 1);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 24 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand 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)

Example 25 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SearchDialog method createSelectCellCommand.

private SelectCellCommand createSelectCellCommand(PositionCoordinate selection) {
    SelectCellCommand selectCellCommand = new SelectCellCommand(selection.getLayer(), selection.columnPosition, selection.rowPosition, false, false);
    selectCellCommand.setForcingEntireCellIntoViewport(true);
    return selectCellCommand;
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)

Aggregations

SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)54 Test (org.junit.Test)50 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)14 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)4 SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)3 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)2 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)2 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2