use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class DefaultBodyLayerStackTest method resizeAColumnAndReorderIt.
@Test
public void resizeAColumnAndReorderIt() throws Exception {
assertEquals(10, this.layerStack.getColumnCount());
assertEquals(1000, this.layerStack.getWidth());
// Resize 2
this.layerStack.doCommand(new ColumnResizeCommand(this.layerStack, 2, 500));
assertEquals(1400, this.layerStack.getWidth());
// Reorder 2 -> 4
this.layerStack.doCommand(new ColumnReorderCommand(this.layerStack, 2, 4));
assertEquals(0, this.layerStack.getColumnIndexByPosition(0));
assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
assertEquals(3, this.layerStack.getColumnIndexByPosition(2));
assertEquals(2, this.layerStack.getColumnIndexByPosition(3));
assertEquals(4, this.layerStack.getColumnIndexByPosition(4));
assertEquals(5, this.layerStack.getColumnIndexByPosition(5));
assertEquals(6, this.layerStack.getColumnIndexByPosition(6));
assertEquals(7, this.layerStack.getColumnIndexByPosition(7));
assertEquals(8, this.layerStack.getColumnIndexByPosition(8));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class DefaultBodyLayerStackTest method resizeAColumnAndHideIt.
@Test
public void resizeAColumnAndHideIt() throws Exception {
assertEquals(10, this.layerStack.getColumnCount());
assertEquals(1000, this.layerStack.getWidth());
// Resize 2
this.layerStack.doCommand(new ColumnResizeCommand(this.layerStack, 2, 500));
assertEquals(1400, this.layerStack.getWidth());
assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
assertEquals(2, this.layerStack.getColumnIndexByPosition(2));
assertEquals(500, this.layerStack.getColumnWidthByPosition(2));
assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
assertEquals(3, this.layerStack.getColumnIndexByPosition(3));
assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
assertEquals(700, this.layerStack.getStartXOfColumnPosition(3));
// Hide 2
this.layerStack.doCommand(new ColumnHideCommand(this.layerStack, 2));
assertEquals(9, this.layerStack.getColumnCount());
assertEquals(1, this.layerStack.getColumnIndexByPosition(1));
assertEquals(100, this.layerStack.getColumnWidthByPosition(1));
assertEquals(100, this.layerStack.getStartXOfColumnPosition(1));
assertEquals(3, this.layerStack.getColumnIndexByPosition(2));
assertEquals(100, this.layerStack.getColumnWidthByPosition(2));
assertEquals(200, this.layerStack.getStartXOfColumnPosition(2));
assertEquals(4, this.layerStack.getColumnIndexByPosition(3));
assertEquals(100, this.layerStack.getColumnWidthByPosition(3));
assertEquals(300, this.layerStack.getStartXOfColumnPosition(3));
assertEquals(9, this.layerStack.getColumnIndexByPosition(8));
assertEquals(100, this.layerStack.getColumnWidthByPosition(8));
assertEquals(800, this.layerStack.getStartXOfColumnPosition(8));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method testEditorResize.
@Test
public void testEditorResize() {
this.natTable.enableEditingOnAllCells();
ILayerCell cell = this.natTable.getCellByPosition(4, 4);
this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
assertEquals(new Rectangle(340, 80, 99, 19), this.natTable.getActiveCellEditor().getEditorControl().getBounds());
this.natTable.doCommand(new ColumnResizeCommand(this.natTable, 2, 110));
assertEquals(new Rectangle(340, 80, 99, 19), this.natTable.getActiveCellEditor().getEditorControl().getBounds());
this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.FocusOut, null);
// ActiveCellEditor should be closed if a ColumnResizeCommand is
// executed and the editor loses focus
assertNull(this.natTable.getActiveCellEditor());
assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class TextPainter method setNewMinLength.
@Override
protected void setNewMinLength(ILayerCell cell, int contentWidth) {
int cellLength = cell.getBounds().width;
if (cellLength < contentWidth) {
// execute ColumnResizeCommand
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth, true));
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class VerticalTextImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
boolean underline = renderUnderlined(cellStyle);
boolean strikethrough = renderStrikethrough(cellStyle);
String text = convertDataType(cell, configRegistry);
// calculate the text to display, adds dots if the text is longer than
// the available row height and adds new lines instead of spaces if word
// wrapping is enabled
text = getTextToDisplay(cell, gc, rectangle.height, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content width is bigger than the available column width
// we're extending the column width (only if word wrapping is enabled)
int fontHeight = gc.getFontMetrics().getHeight();
int contentWidth = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().width - rectangle.width);
if ((contentWidth > rectangle.width) && this.calculateByTextHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
if (text != null && text.length() > 0) {
if (numberOfNewLines == 1) {
int contentHeight = Math.min(getLengthFromCache(gc, text), rectangle.height);
GraphicsUtils.drawVerticalText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
} else {
// draw every line by itself because of the alignment, otherwise
// the whole text is always aligned right
int xStartPos = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth);
// $NON-NLS-1$
String[] lines = text.split("\n");
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
GraphicsUtils.drawVerticalText(line, xStartPos + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
// after every line calculate the x start pos new
xStartPos += fontHeight;
xStartPos += this.lineSpacing;
}
}
}
gc.setClipping(originalClipping);
}
Aggregations