Custom Scrollbar Mousewheel Support [message #1807736] |
Fri, 07 June 2019 01:53  |
Eclipse User |
|
|
|
Hello,
I have the following problem, I have a split Viewport in my table and have added custom scrollbars for both directions following this blogpost:
http://blog.vogella.com/2015/01/26/nattable-with-custom-scrollbars/
Now with this custom scrollbars i have no mousewheel support, i have tried it with an mouse wheel listener directly on the nat table and setSeletion on the Slider Widget, the effect from this is that only the slider moves and not the table. When i move the Slider with the mouse it works like it is supposed to.
Has anybody an idear how i could fix this?
|
|
|
|
|
Re: Custom Scrollbar Mousewheel Support [message #1814075 is a reply to message #1807745] |
Tue, 03 September 2019 02:35  |
Eclipse User |
|
|
|
I checked again and found out that it seems to be an issue with the Slider. Unfortunately it does not get a SWT selection event on mousewheel, and it also does not fire a selection event when setting the selection via setSelection().
I was able to add the mousewheel support manually with the following code which sets the selection programmatically on mousewheel events and then perform actions that would normally done automatically by the ScrollBarHandlerTemplate which is a listener on SWT.Selection events.
ViewportLayer viewportLayer = new ViewportLayer(bodyDataLayer);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Slider slider = new Slider(composite, SWT.VERTICAL);
SliderScroller scroller = new SliderScroller(slider);
viewportLayer.setVerticalScroller(scroller);
GridDataFactory.defaultsFor(slider).align(SWT.BEGINNING, SWT.FILL).grab(false, true).applyTo(slider);
natTable.addListener(SWT.MouseWheel, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.stateMask == SWT.MOD2) {
ScrollBar horizontal = natTable.getHorizontalBar();
// update the selection
horizontal.setSelection(horizontal.getSelection() -
((event.count < 0 ? -1 : 1) * horizontal.getIncrement()));
// perform selection handling
viewportLayer.setOriginX(viewportLayer.getMinimumOrigin().getX() + horizontal.getSelection());
int increment = viewportLayer.getColumnCount() > 0 ? viewportLayer.getColumnWidthByPosition(0) : 0;
int scrollIncrement = Math.min(increment, viewportLayer.getClientAreaWidth() / 4);
horizontal.setIncrement(scrollIncrement);
} else {
// update the selection
slider.setSelection(slider.getSelection() -
((event.count < 0 ? -1 : 1) * slider.getIncrement()));
// perform selection handling
viewportLayer.setOriginY(viewportLayer.getMinimumOrigin().getY() + scroller.getSelection());
int increment = viewportLayer.getRowCount() > 0 ? viewportLayer.getRowHeightByPosition(0) : 0;
int scrollIncrement = Math.min(increment, viewportLayer.getClientAreaHeight() / 4);
scroller.setIncrement(scrollIncrement);
}
event.doit = false;
}
});
[Updated on: Tue, 03 September 2019 03:57] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03934 seconds