use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.
the class AutoResizeColumnsTest method autoResizeOneColumn.
/**
* These sequence of actions were causing a nasty bug in AutoResize
*/
@Test
public void autoResizeOneColumn() throws Exception {
GridLayer gridLayer = new DummyGridLayerStack();
setClientAreaProvider(gridLayer);
// Resize column
gridLayer.doCommand(new ColumnResizeCommand(gridLayer, 2, 10));
assertEquals(10, gridLayer.getColumnWidthByPosition(2));
// Auto resize the one column
InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(gridLayer, 2, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
// Note: the actual resized width is platform specific (font
// dependency),
// hence we can't compare against a fixed value.
int columnWidth = gridLayer.getColumnWidthByPosition(2);
assertTrue(columnWidth > 10);
// Reorder columns
gridLayer.doCommand(new ColumnReorderCommand(gridLayer, 2, 1));
assertEquals(columnWidth, gridLayer.getColumnWidthByPosition(1));
// Select all columns
gridLayer.doCommand(new SelectAllCommand());
// Resize all selected columns
command = new InitializeAutoResizeColumnsCommand(gridLayer, 1, this.configRegistry, this.gcFactory);
gridLayer.doCommand(command);
for (int columnPosition = 1; columnPosition <= 20; columnPosition++) {
assertTrue("column " + columnPosition + " should have been resized, but it is still its original width", gridLayer.getColumnWidthByPosition(columnPosition) != 100);
}
}
use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.
the class InitializeAutoResizeColumnsCommandHandler method doCommand.
@Override
protected boolean doCommand(InitializeAutoResizeColumnsCommand initCommand) {
int columnPosition = initCommand.getColumnPosition();
if (this.selectionLayer.isColumnPositionFullySelected(columnPosition)) {
initCommand.setSelectedColumnPositions(this.selectionLayer.getFullySelectedColumnPositions());
} else {
initCommand.setSelectedColumnPositions(new int[] { columnPosition });
}
// Fire command carrying the selected columns
initCommand.getSourceLayer().doCommand(new AutoResizeColumnsCommand(initCommand));
return true;
}
use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.
the class MenuItemProviders method autoResizeAllSelectedColumnMenuItemProvider.
public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
@Override
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
autoResizeColumns.setText(Messages.getLocalizedMessage(menuLabel));
autoResizeColumns.setEnabled(true);
autoResizeColumns.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GCFactory(natTable)));
}
});
}
};
}
use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand in project nebula.widgets.nattable by eclipse.
the class MenuItemProviders method autoResizeColumnMenuItemProvider.
public static IMenuItemProvider autoResizeColumnMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
@Override
public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
autoResizeColumns.setText(Messages.getLocalizedMessage(menuLabel));
// $NON-NLS-1$
autoResizeColumns.setImage(GUIHelper.getImage("auto_resize"));
autoResizeColumns.setEnabled(true);
autoResizeColumns.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int columnPosition = getNatEventData(event).getColumnPosition();
natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GCFactory(natTable)));
}
});
}
};
}
use of org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand 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