use of org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand 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.layer.command.ConfigureScalingCommand in project nebula.widgets.nattable by eclipse.
the class MultiColumnResizeCommandTest method testMultiResizeWithDownscale.
@Test
public void testMultiResizeWithDownscale() {
GridLayer gridLayer = new DummyGridLayerStack();
IDpiConverter dpiConverter = new AbstractDpiConverter() {
@Override
protected void readDpiFromDisplay() {
this.dpi = 120;
}
};
gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
setClientAreaProvider(gridLayer);
// 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));
MultiColumnResizeCommand resizeCommand = new MultiColumnResizeCommand(gridLayer, new int[] { 3, 4, 5 }, 150, true);
gridLayer.doCommand(resizeCommand);
// 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.layer.command.ConfigureScalingCommand in project nebula.widgets.nattable by eclipse.
the class MultiRowResizeCommandTest method testMultiResizeWithDownscale.
@Test
public void testMultiResizeWithDownscale() {
GridLayer gridLayer = new DummyGridLayerStack();
IDpiConverter dpiConverter = new AbstractDpiConverter() {
@Override
protected void readDpiFromDisplay() {
this.dpi = 120;
}
};
gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
setClientAreaProvider(gridLayer);
// scaling enabled, therefore default height of 20 pixels is up scaled
// to 25
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(25, gridLayer.getRowHeightByPosition(3));
assertEquals(25, gridLayer.getRowHeightByPosition(4));
assertEquals(25, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
MultiRowResizeCommand resizeCommand = new MultiRowResizeCommand(gridLayer, new int[] { 3, 4, 5 }, 50, true);
gridLayer.doCommand(resizeCommand);
// command executed with down scaling enabled, therefore set height 50
// is first down scaled on setting the value and then up scaled to 50
// again on accessing the height
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(50, gridLayer.getRowHeightByPosition(3));
assertEquals(50, gridLayer.getRowHeightByPosition(4));
assertEquals(50, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
}
use of org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand in project nebula.widgets.nattable by eclipse.
the class MultiRowResizeCommandTest method testMultiResizeWithoutDownscaleOnSelection.
@Test
public void testMultiResizeWithoutDownscaleOnSelection() {
DummyGridLayerStack gridLayer = new DummyGridLayerStack();
IDpiConverter dpiConverter = new AbstractDpiConverter() {
@Override
protected void readDpiFromDisplay() {
this.dpi = 120;
}
};
gridLayer.doCommand(new ConfigureScalingCommand(dpiConverter, dpiConverter));
setClientAreaProvider(gridLayer);
// scaling enabled, therefore default height of 20 pixels is up scaled
// to 25
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(25, gridLayer.getRowHeightByPosition(3));
assertEquals(25, gridLayer.getRowHeightByPosition(4));
assertEquals(25, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
// select rows
gridLayer.doCommand(new SelectRowsCommand(gridLayer, 1, new int[] { 3, 4, 5 }, false, true, -1));
// resize one of the selected columns
RowResizeCommand columnResizeCommand = new RowResizeCommand(gridLayer, 3, 50);
gridLayer.doCommand(columnResizeCommand);
// command executed with down scaling disabled, therefore set height 50
// is up scaled to 63
assertEquals(25, gridLayer.getRowHeightByPosition(2));
assertEquals(63, gridLayer.getRowHeightByPosition(3));
assertEquals(63, gridLayer.getRowHeightByPosition(4));
assertEquals(63, gridLayer.getRowHeightByPosition(5));
assertEquals(25, gridLayer.getRowHeightByPosition(6));
}
use of org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayer method doCommand.
@Override
public boolean doCommand(ILayerCommand command) {
if (command instanceof SelectCellCommand && command.convertToTargetLayer(this)) {
// perform selection of level on level header click
SelectCellCommand selection = (SelectCellCommand) command;
if (isLevelHeaderColumn(selection.getColumnPosition())) {
ILayerCell clickedCell = getCellByPosition(selection.getColumnPosition(), selection.getRowPosition());
// calculate number of header columns to the right
int levelHeaderCount = 0;
for (int i = this.levelHeaderPositions.length - 1; i >= 0; i--) {
if (this.levelHeaderPositions[i] >= selection.getColumnPosition()) {
levelHeaderCount++;
}
}
SelectRegionCommand selectRegion = new SelectRegionCommand(this, clickedCell.getColumnPosition() + 1, clickedCell.getOriginRowPosition(), getColumnCount() - levelHeaderCount - (clickedCell.getColumnPosition()), clickedCell.getRowSpan(), selection.isShiftMask(), selection.isControlMask());
this.underlyingLayer.doCommand(selectRegion);
return true;
}
} else if (command instanceof ConfigureScalingCommand) {
this.dpiConverter = ((ConfigureScalingCommand) command).getHorizontalDpiConverter();
} else if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
// remove the tree level header width from the client area to
// ensure that the percentage calculation is correct
possibleArea.width = possibleArea.width - (this.levelHeaderPositions.length * getScaledLevelHeaderWidth());
clientAreaResizeCommand.setCalcArea(possibleArea);
} else if (command instanceof ColumnReorderCommand) {
ColumnReorderCommand crCommand = ((ColumnReorderCommand) command);
if (!isValidTargetColumnPosition(crCommand.getFromColumnPosition(), crCommand.getToColumnPosition())) {
// command without doing anything
return true;
}
if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
// tree level header
return super.doCommand(new ColumnReorderCommand(this, crCommand.getFromColumnPosition(), crCommand.getToColumnPosition() + 1));
}
} else if (command instanceof MultiColumnReorderCommand) {
MultiColumnReorderCommand crCommand = ((MultiColumnReorderCommand) command);
for (int fromColumnPosition : crCommand.getFromColumnPositions()) {
if (!isValidTargetColumnPosition(fromColumnPosition, crCommand.getToColumnPosition())) {
// command would be skipped
return true;
}
}
if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
// tree level header
return super.doCommand(new MultiColumnReorderCommand(this, crCommand.getFromColumnPositions(), crCommand.getToColumnPosition() + 1));
}
}
return super.doCommand(command);
}
Aggregations