use of org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method testFreezeRowResize.
@Test
public void testFreezeRowResize() {
this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {
@Override
public Rectangle getClientArea() {
return new Rectangle(0, 0, 1500, 400);
}
});
// Fire this command so that the viewport can be initialized
this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 2));
assertEquals(3, this.freezeLayer.getRowCount());
assertEquals(7, this.viewportLayer.getRowCount());
assertEquals(60, this.viewportLayer.getOrigin().getY());
this.compositeFreezeLayer.doCommand(new RowResizeCommand(this.freezeLayer, 2, 120));
assertEquals(3, this.freezeLayer.getRowCount());
assertEquals(7, this.viewportLayer.getRowCount());
assertEquals(160, this.viewportLayer.getOrigin().getY());
}
use of org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method testFreezeAllRowsResize.
@Test
public void testFreezeAllRowsResize() {
this.compositeFreezeLayer.setClientAreaProvider(new IClientAreaProvider() {
@Override
public Rectangle getClientArea() {
return new Rectangle(0, 0, 1500, 400);
}
});
// Shoot this command so that the viewport can be initialized
this.compositeFreezeLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.H_SCROLL | SWT.V_SCROLL)));
this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 9));
assertEquals(10, this.freezeLayer.getRowCount());
assertEquals(0, this.viewportLayer.getRowCount());
assertEquals(200, this.viewportLayer.getOrigin().getY());
this.compositeFreezeLayer.doCommand(new RowResizeCommand(this.freezeLayer, 2, 120));
assertEquals(10, this.freezeLayer.getRowCount());
assertEquals(0, this.viewportLayer.getRowCount());
assertEquals(300, this.viewportLayer.getOrigin().getY());
}
use of org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand in project nebula.widgets.nattable by eclipse.
the class PersistenceIntegrationTest method saveStateToPropeties.
public void saveStateToPropeties() throws Exception {
// Resize column 2 to 200px
assertEquals(100, this.natTableFixture.getColumnWidthByPosition(2));
this.natTableFixture.doCommand(new ColumnResizeCommand(this.natTableFixture, 2, 200));
assertEquals(200, this.natTableFixture.getColumnWidthByPosition(2));
// Resize row 2 to 100px
assertEquals(20, this.natTableFixture.getRowHeightByPosition(2));
this.natTableFixture.doCommand(new RowResizeCommand(this.natTableFixture, 2, 100));
assertEquals(100, this.natTableFixture.getRowHeightByPosition(2));
// Reorder column 1 --> 5 (grid coordinates)
// 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
assertEquals(0, this.natTableFixture.getColumnIndexByPosition(1));
this.natTableFixture.doCommand(new ColumnReorderCommand(this.natTableFixture, 1, 5));
assertEquals(1, this.natTableFixture.getColumnIndexByPosition(1));
// Reorder row 1 --> 5 (grid coordinates)
// 0, 1, 2, 3, 4, 5,.. --> 1, 2, 3, 0, 4, 5,..
assertEquals(0, this.natTableFixture.getRowIndexByPosition(1));
this.natTableFixture.doCommand(new RowReorderCommand(this.natTableFixture, 1, 5));
assertEquals(1, this.natTableFixture.getRowIndexByPosition(1));
// Hide column with index 3 (grid coordinates)
assertEquals(3, this.natTableFixture.getColumnIndexByPosition(3));
this.natTableFixture.doCommand(new ColumnHideCommand(this.natTableFixture, 3));
assertEquals(0, this.natTableFixture.getColumnIndexByPosition(3));
this.natTableFixture.saveState(TEST_PERSISTENCE_PREFIX, this.properties);
// Ensure that properties got persisted
assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.resizableByDefault"));
assertEquals("100", this.properties.get("testPrefix.COLUMN_HEADER.columnWidth.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.COLUMN_HEADER.rowHeight.resizableByDefault"));
assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.columnWidth.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.rowHeight.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.ROW_HEADER.columnWidth.resizableByDefault"));
assertEquals("40", this.properties.get("testPrefix.ROW_HEADER.rowHeight.defaultSize"));
assertEquals("20", this.properties.get("testPrefix.CORNER.rowHeight.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.CORNER.columnWidth.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.CORNER.rowHeight.resizableByDefault"));
assertEquals("20", this.properties.get("testPrefix.BODY.rowHeight.defaultSize"));
assertEquals("true", this.properties.get("testPrefix.BODY.rowHeight.resizableByDefault"));
assertEquals("true", this.properties.get("testPrefix.BODY.columnWidth.resizableByDefault"));
assertEquals("1,2,3,0,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,", this.properties.get("testPrefix.BODY.columnIndexOrder"));
assertEquals("1:100,", this.properties.get("testPrefix.BODY.rowHeight.sizes"));
assertEquals("1:200,", this.properties.get("testPrefix.BODY.columnWidth.sizes"));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand in project nebula.widgets.nattable by eclipse.
the class ImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
int contentHeight = imageBounds.height;
if (this.calculateByHeight && (contentHeight > bounds.height)) {
int contentToCellDiff = (cell.getBounds().height - bounds.height);
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
int contentWidth = imageBounds.width;
if (this.calculateByWidth && (contentWidth > bounds.width)) {
int contentToCellDiff = (cell.getBounds().width - bounds.width);
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand in project nebula.widgets.nattable by eclipse.
the class TextPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
if (this.paintFg) {
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
// Draw Text
text = getTextToDisplay(cell, gc, rectangle.width, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content height is bigger than the available row height
// we're extending the row height (only if word wrapping is enabled)
int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().height - rectangle.height);
if (performRowResize(contentHeight, rectangle)) {
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
if (numberOfNewLines == 1) {
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.width);
gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
// start x of line = start x of text
int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing;
// y = start y of text
int y = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
int length = gc.textExtent(text).x;
paintDecoration(cellStyle, gc, x, y, length, fontHeight);
} else {
// draw every line by itself because of the alignment, otherwise
// the whole text is always aligned right
int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
// $NON-NLS-1$
String[] lines = text.split("\n");
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width);
gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing, yStartPos + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
// start x of line = start x of text
int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing;
// y = start y of text
int y = yStartPos + this.spacing;
int length = gc.textExtent(line).x;
paintDecoration(cellStyle, gc, x, y, length, fontHeight);
// after every line calculate the y start pos new
yStartPos += fontHeight;
yStartPos += this.lineSpacing;
}
}
gc.setClipping(originalClipping);
resetGC(gc);
}
}
Aggregations