use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class ColumnResizeDragMode method updateColumnWidth.
private void updateColumnWidth(ILayer natLayer, MouseEvent e) {
int dragWidth = e.x - this.startX;
int newColumnWidth = this.originalColumnWidth + dragWidth;
if (newColumnWidth < getColumnWidthMinimum()) {
newColumnWidth = getColumnWidthMinimum();
}
// trigger the ColumnResizeCommand with downScaling enabled
// as the user performed a drag operation the newColumnWidth is the
// value on the screen, which needs to be down scaled in the DataLayer
natLayer.doCommand(new ColumnResizeCommand(natLayer, this.columnPositionToResize, newColumnWidth, true));
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class RichTextCellPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
String htmlText = CellDisplayConversionUtils.convertDataType(cell, configRegistry);
Rectangle painterBounds = new Rectangle(bounds.x, bounds.y - this.richTextPainter.getParagraphSpace(), bounds.width, bounds.height);
this.richTextPainter.paintHTML(htmlText, gc, painterBounds);
int height = this.richTextPainter.getPreferredSize().y - 2 * this.richTextPainter.getParagraphSpace();
if (performRowResize(height, painterBounds)) {
cell.getLayer().doCommand(new RowResizeCommand(cell.getLayer(), cell.getRowPosition(), GUIHelper.convertVerticalDpiToPixel(height) + (cell.getBounds().height - bounds.height)));
}
if (performColumnResize(this.richTextPainter.getPreferredSize().x, painterBounds)) {
cell.getLayer().doCommand(new ColumnResizeCommand(cell.getLayer(), cell.getColumnPosition(), GUIHelper.convertHorizontalDpiToPixel(this.richTextPainter.getPreferredSize().x) + (cell.getBounds().width - bounds.width)));
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method testFreezeColumnResize.
@Test
public void testFreezeColumnResize() {
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 FreezeColumnCommand(this.compositeFreezeLayer, 2));
assertEquals(3, this.freezeLayer.getColumnCount());
assertEquals(7, this.viewportLayer.getColumnCount());
assertEquals(300, this.viewportLayer.getOrigin().getX());
this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
assertEquals(3, this.freezeLayer.getColumnCount());
assertEquals(7, this.viewportLayer.getColumnCount());
assertEquals(400, this.viewportLayer.getOrigin().getX());
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand in project nebula.widgets.nattable by eclipse.
the class FreezeHandlerTest method testFreezeAllColumnsResize.
@Test
public void testFreezeAllColumnsResize() {
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 FreezeColumnCommand(this.compositeFreezeLayer, 9));
assertEquals(10, this.freezeLayer.getColumnCount());
assertEquals(0, this.viewportLayer.getColumnCount());
assertEquals(1000, this.viewportLayer.getOrigin().getX());
this.compositeFreezeLayer.doCommand(new ColumnResizeCommand(this.freezeLayer, 2, 200));
assertEquals(10, this.freezeLayer.getColumnCount());
assertEquals(0, this.viewportLayer.getColumnCount());
assertEquals(1100, this.viewportLayer.getOrigin().getX());
}
use of org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand 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);
}
Aggregations