use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumnRanges.
@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumnRanges() {
this.natTableFixture.doCommand(new TurnViewportOffCommand());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
// simulate deletion of a column
this.provider.setColumnCount(this.provider.getColumnCount() + 3);
this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 3), new Range(7, 8)));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(7, 0).toString());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.
the class AutoResizeRowCommandHandler method doCommand.
@Override
public boolean doCommand(ILayer targetLayer, AutoResizeRowsCommand command) {
// Need to resize selected rows even if they are outside the viewport
targetLayer.doCommand(new TurnViewportOffCommand());
int[] rowPositions = ObjectUtils.asIntArray(command.getRowPositions());
int[] gridRowPositions = command.doPositionTransformation() ? convertFromPositionToCommandLayer(rowPositions) : rowPositions;
int[] gridRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(command.getConfigRegistry(), command.getGCFactory(), this.commandLayer, gridRowPositions);
this.commandLayer.doCommand(new MultiRowResizeCommand(this.commandLayer, gridRowPositions, gridRowHeights, true));
targetLayer.doCommand(new TurnViewportOnCommand());
return true;
}
use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.
the class AutoResizeHelper method init.
/**
* Prepare the layer for complete in-memory rendering.
*/
protected void init() {
this.layer.addLayerListener(this.resizeListener);
this.layer.setClientAreaProvider(this.clientAreaProvider);
this.layer.doCommand(new TurnViewportOffCommand());
this.layer.doCommand(new PrintEntireGridCommand());
}
use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.
the class ViewportLayer method doCommand.
@Override
public boolean doCommand(ILayerCommand command) {
if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
if (this.processingClientAreaResizeCommand) {
return false;
}
this.processingClientAreaResizeCommand = true;
// on client area resize we reset the keep in viewport row position
this.keepInViewportRowPosition = -1;
ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
// remember the difference from client area to body region area
// needed because the scrollbar will be removed and therefore the
// client area will become bigger
Scrollable scrollable = clientAreaResizeCommand.getScrollable();
Rectangle clientArea = scrollable.getClientArea();
Rectangle calcArea = clientAreaResizeCommand.getCalcArea();
int widthDiff = clientArea.width - calcArea.width;
int heightDiff = clientArea.height - calcArea.height;
boolean initialClientAreaResize = false;
if (this.hBarListener == null && this.horizontalScrollbarEnabled) {
initialClientAreaResize = true;
ScrollBar hBar = scrollable.getHorizontalBar();
if (hBar != null) {
if (this.horizontalScroller != null) {
hBar.setEnabled(false);
hBar.setVisible(false);
} else {
this.horizontalScroller = new ScrollBarScroller(hBar);
}
this.hBarListener = new HorizontalScrollBarHandler(this, this.horizontalScroller);
if (scrollable instanceof NatTable) {
this.hBarListener.setTable((NatTable) scrollable);
}
}
}
if (this.vBarListener == null && this.verticalScrollbarEnabled) {
initialClientAreaResize = true;
ScrollBar vBar = scrollable.getVerticalBar();
if (vBar != null) {
if (this.verticalScroller != null) {
vBar.setEnabled(false);
vBar.setVisible(false);
} else {
this.verticalScroller = new ScrollBarScroller(vBar);
}
this.vBarListener = new VerticalScrollBarHandler(this, this.verticalScroller);
if (scrollable instanceof NatTable) {
this.vBarListener.setTable((NatTable) scrollable);
}
}
}
if (initialClientAreaResize) {
handleGridResize();
// after handling the scrollbars recalculate the area to use for
// percentage calculation
Rectangle possibleArea = scrollable.getClientArea();
possibleArea.width = possibleArea.width - widthDiff;
possibleArea.height = possibleArea.height - heightDiff;
clientAreaResizeCommand.setCalcArea(possibleArea);
}
// we don't return true here because the ClientAreaResizeCommand
// needs to be handled by the DataLayer in case percentage sizing is
// enabled. if we would return true, the DataLayer wouldn't be able
// to calculate the column/row sizes regarding the client area
boolean result = super.doCommand(command);
if (!initialClientAreaResize) {
handleGridResize();
}
// we need to first give underlying layers the chance to process the
// command and afterwards set the processing flag to false
// this way we avoid processing the resize multiple times because of
// re-calculation in conjunction with scrollbar visibility state
// changes
this.processingClientAreaResizeCommand = false;
return result;
} else if (command instanceof TurnViewportOffCommand) {
this.savedOrigin = this.origin;
this.viewportOff = true;
return true;
} else if (command instanceof TurnViewportOnCommand) {
this.viewportOff = false;
this.origin = this.savedOrigin;
// only necessary in case of split viewports and auto resizing, but
// shouldn't hurt in other cases
recalculateScrollBars();
return true;
} else if (command instanceof PrintEntireGridCommand) {
moveCellPositionIntoViewport(0, 0);
}
return super.doCommand(command);
}
use of org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumn.
@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumn() {
this.natTableFixture.doCommand(new TurnViewportOffCommand());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
// simulate deletion of a column
this.provider.setColumnCount(this.provider.getColumnCount() + 3);
this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 4)));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(8, 0).toString());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
Aggregations