use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.
the class SelectionSearchStrategyTest method setUp.
@Before
public void setUp() {
this.bodyDataProvider = new IDataProvider() {
@Override
public int getColumnCount() {
return GridLayerFixture.bodyDataProvider.getColumnCount();
}
@Override
public int getRowCount() {
return GridLayerFixture.bodyDataProvider.getRowCount();
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
if (columnIndex == 0 || columnIndex == 9) {
return CELL_VALUE;
}
return GridLayerFixture.bodyDataProvider.getDataValue(columnIndex, rowIndex);
}
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
throw new UnsupportedOperationException();
}
};
this.gridLayer = new DefaultGridLayer(this.bodyDataProvider, GridLayerFixture.colHeaderDataProvider, GridLayerFixture.rowHeaderDataProvider, GridLayerFixture.cornerDataProvider);
this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {
@Override
public Rectangle getClientArea() {
return new Rectangle(0, 0, 1050, 250);
}
});
this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
this.selectionLayer = this.gridLayer.getBodyLayer().getSelectionLayer();
this.configRegistry = new ConfigRegistry();
new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
}
use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.
the class GridLayer method doCommand.
@Override
public boolean doCommand(ILayerCommand command) {
if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
// remove the column header height and the row header width from the
// client area to
// ensure that only the body region is used for percentage
// calculation
Rectangle rowLayerArea = getRowHeaderLayer().getClientAreaProvider().getClientArea();
Rectangle columnLayerArea = getColumnHeaderLayer().getClientAreaProvider().getClientArea();
possibleArea.width = possibleArea.width - rowLayerArea.width;
possibleArea.height = possibleArea.height - columnLayerArea.height;
clientAreaResizeCommand.setCalcArea(possibleArea);
}
return super.doCommand(command);
}
use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand 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.grid.command.ClientAreaResizeCommand 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.grid.command.ClientAreaResizeCommand 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());
}
Aggregations