use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.
the class AutoResizeColumnsTest method shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected.
/**
* Scenario: Multiple columns are selected but a non selected column is auto
* resized.
*/
@Test
public void shouldAutoResizeCorrectlyIfMultipleColumnsAreSelected() throws Exception {
GridLayer gridLayer = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
setClientAreaProvider(gridLayer);
// Resize grid column 1, 2
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 1, 10));
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(1));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
// Fully select columns 1, 2
SelectionLayer selectionLayer = ((DefaultBodyLayerStack) gridLayer.getBodyLayer()).getSelectionLayer();
selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 0, 0, false, false));
selectionLayer.doCommand(new SelectColumnCommand(selectionLayer, 1, 0, true, false));
assertEquals(2, selectionLayer.getFullySelectedColumnPositions().length);
// Resize grid column 5
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 5, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(5));
// Auto resize column 5
InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 5, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
// Columns 1 and 2 should not be resized
assertEquals(10, gridLayer.getColumnWidthByPosition(1));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
assertTrue(gridLayer.getColumnWidthByPosition(5) > 10);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.
the class MultiColumnResizeCommandTest method testMultiResizeWithDownscaleOnSelection.
@Test
public void testMultiResizeWithDownscaleOnSelection() {
GridLayer gridLayer = new DummyGridLayerStack();
IDpiConverter dpiConverter = new AbstractDpiConverter() {
@Override
protected void readDpiFromDisplay() {
this.dpi = 120;
}
};
gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
setClientAreaProvider(gridLayer);
// select columns
gridLayer.doCommand(new SelectColumnCommand(gridLayer, 3, 1, false, false));
gridLayer.doCommand(new SelectColumnCommand(gridLayer, 4, 1, false, true));
gridLayer.doCommand(new SelectColumnCommand(gridLayer, 5, 1, false, true));
// scaling enabled, therefore default width of 100 pixels is up scaled
// to 125
assertEquals(125, gridLayer.getColumnWidthByPosition(2));
assertEquals(125, gridLayer.getColumnWidthByPosition(3));
assertEquals(125, gridLayer.getColumnWidthByPosition(4));
assertEquals(125, gridLayer.getColumnWidthByPosition(5));
assertEquals(125, gridLayer.getColumnWidthByPosition(6));
// resize one of the selected columns
ColumnResizeCommand columnResizeCommand = new ColumnResizeCommand(gridLayer, 3, 150, true);
gridLayer.doCommand(columnResizeCommand);
// command executed with down scaling enabled, therefore set width 150
// is first down scaled on setting the value and then up scaled to 150
// again on accessing the width
assertEquals(125, gridLayer.getColumnWidthByPosition(2));
assertEquals(150, gridLayer.getColumnWidthByPosition(3));
assertEquals(150, gridLayer.getColumnWidthByPosition(4));
assertEquals(150, gridLayer.getColumnWidthByPosition(5));
assertEquals(125, gridLayer.getColumnWidthByPosition(6));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.
the class SelectionEventsTest method shouldFireColumnSelectionEvent.
@Test
public void shouldFireColumnSelectionEvent() throws Exception {
this.nattable.doCommand(new SelectColumnCommand(this.nattable, 5, 5, NO_SHIFT, NO_CTRL));
assertEquals(2, this.listener.getEventsCount());
assertTrue(this.listener.containsInstanceOf(ColumnSelectionEvent.class));
assertTrue(this.listener.containsInstanceOf(ColumnHeaderSelectionEvent.class));
ColumnSelectionEvent event = (ColumnSelectionEvent) this.listener.getReceivedEvents().get(0);
assertEquals(5, event.getColumnPositionRanges().iterator().next().start);
assertEquals(6, event.getColumnPositionRanges().iterator().next().end);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.
the class ColumnSelectionTest method shouldSetAnchorWithInitialShiftKeyPressed.
@Test
public void shouldSetAnchorWithInitialShiftKeyPressed() {
// start from a clear selection state
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 4, 0, true, false));
assertEquals(4, this.selectionLayer.getSelectionAnchor().getColumnPosition());
assertEquals(0, this.selectionLayer.getSelectionAnchor().getRowPosition());
assertFalse("column 3 fully selected", this.selectionLayer.isColumnPositionFullySelected(3));
assertTrue("column 4 not fully selected", this.selectionLayer.isColumnPositionFullySelected(4));
assertFalse("column 5 fully selected", this.selectionLayer.isColumnPositionFullySelected(5));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand in project nebula.widgets.nattable by eclipse.
the class ColumnSelectionTest method shouldExtendFromAnchorWithShiftKeyPressed.
@Test
public void shouldExtendFromAnchorWithShiftKeyPressed() {
// start from a clear selection state
this.selectionLayer.clear();
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 4, 0, true, false));
// select columns to the left
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 2, 0, true, false));
for (int col = 2; col <= 4; col++) {
assertTrue("column " + col + " not fully selected", this.selectionLayer.isColumnPositionFullySelected(col));
}
assertFalse("column 5 fully selected", this.selectionLayer.isColumnPositionFullySelected(5));
// select columns to the right
this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 6, 0, true, false));
assertFalse("column 2 fully selected", this.selectionLayer.isColumnPositionFullySelected(2));
assertFalse("column 3 fully selected", this.selectionLayer.isColumnPositionFullySelected(3));
for (int col = 4; col <= 6; col++) {
assertTrue("column " + col + " not fully selected", this.selectionLayer.isColumnPositionFullySelected(col));
}
}
Aggregations