Search in sources :

Example 1 with SelectAllCommand

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

the class SearchGridCommandHandlerTest method shouldFindTextInSelectionWithoutWrap.

@Test
public void shouldFindTextInSelectionWithoutWrap() {
    // select all
    this.gridLayer.doCommand(new SelectAllCommand());
    this.isForward = true;
    this.isWrapSearch = false;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTestOnSelection();
    this.isForward = false;
    this.searchText = "[2,3]";
    this.expected = new PositionCoordinate(null, 2, 3);
    doTestOnSelection();
    this.searchText = "[2,4]";
    this.expected = null;
    doTestOnSelection();
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 2 with SelectAllCommand

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

the class AutoResizeColumnsTest method autoResizeOneColumn.

/**
 * These sequence of actions were causing a nasty bug in AutoResize
 */
@Test
public void autoResizeOneColumn() throws Exception {
    GridLayer gridLayer = new DummyGridLayerStack();
    setClientAreaProvider(gridLayer);
    // Resize column
    gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
    assertEquals(10, gridLayer.getColumnWidthByPosition(2));
    // Auto resize the one column
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 2, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    // Note: the actual resized width is platform specific (font
    // dependency),
    // hence we can't compare against a fixed value.
    int columnWidth = gridLayer.getColumnWidthByPosition(2);
    assertTrue(columnWidth > 10);
    // Reorder columns
    gridLayer.doCommand(new ColumnReorderCommand(gridLayer, 2, 1));
    assertEquals(columnWidth, gridLayer.getColumnWidthByPosition(1));
    // Select all columns
    gridLayer.doCommand(new SelectAllCommand());
    // Resize all selected columns
    command = new InitializeAutoResizeColumnsCommand(gridLayer, 1, this.configRegistry, this.gcFactory);
    gridLayer.doCommand(command);
    for (int columnPosition = 1; columnPosition <= 20; columnPosition++) {
        assertTrue("column " + columnPosition + " should have been resized, but it is still its original width", gridLayer.getColumnWidthByPosition(columnPosition) != 100);
    }
}
Also used : ColumnResizeCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand) SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 3 with SelectAllCommand

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

the class SelectionSearchStrategyTest method shouldSearchSelectionBackwards.

@Test
public void shouldSearchSelectionBackwards() {
    // Select entire grid
    this.gridLayer.doCommand(new SelectAllCommand());
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setWrapSearch(true);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    // the selection anchor is already in the first cell,
    // therefore the search result will return the second row in the first
    // column
    PositionCoordinate positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(0, positionCoordinate.columnPosition);
    assertEquals(1, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(1, this.selectionLayer.getSelectionAnchor().getRowPosition());
    // Should find last cell
    selectionStrategy = new SelectionSearchStrategy(this.configRegistry, ISearchDirection.SEARCH_BACKWARDS, true);
    selectionStrategy.setWrapSearch(true);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    // one backwards will find the first cell in the grid
    positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(0, positionCoordinate.columnPosition);
    assertEquals(0, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
    // second backwards will find the last cell
    positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertEquals(9, positionCoordinate.columnPosition);
    assertEquals(4, positionCoordinate.rowPosition);
    // selection stays unchanged, only the selection anchor moves
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(9, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 4 with SelectAllCommand

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

the class SelectionSearchStrategyTest method shouldNotWrap.

@Test
public void shouldNotWrap() {
    this.gridLayer.doCommand(new SelectAllCommand());
    this.selectionLayer.moveSelectionAnchor(9, 4);
    assertEquals(50, this.selectionLayer.getSelectedCells().size());
    assertEquals(9, this.selectionLayer.getSelectionAnchor().getColumnPosition());
    assertEquals(4, this.selectionLayer.getSelectionAnchor().getRowPosition());
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setComparator(new CellValueAsStringComparator<>());
    selectionStrategy.setContextLayer(this.selectionLayer);
    PositionCoordinate positionCoordinate = selectionStrategy.executeSearch(CELL_VALUE);
    assertNull(positionCoordinate);
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 5 with SelectAllCommand

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

the class SearchGridCommandHandlerTest method shouldFindTextInSelectionWithWrap.

@Test
public void shouldFindTextInSelectionWithWrap() {
    // select all
    this.gridLayer.doCommand(new SelectAllCommand());
    this.isForward = true;
    this.isWrapSearch = true;
    this.isCaseSensitive = false;
    this.isWholeWord = false;
    this.isIncremental = false;
    this.isRegex = false;
    this.isIncludeCollapsed = false;
    this.isColumnFirst = true;
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTestOnSelection();
    this.isForward = false;
    this.searchText = "[2,3]";
    this.expected = new PositionCoordinate(null, 2, 3);
    doTestOnSelection();
    this.searchText = "[2,4]";
    this.expected = new PositionCoordinate(null, 2, 4);
    doTestOnSelection();
}
Also used : SelectAllCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Aggregations

SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)5 Test (org.junit.Test)5 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)4 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)1 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)1 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)1 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)1 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)1 InitializeAutoResizeColumnsCommand (org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand)1