diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/SliderScroller.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/SliderScroller.java index ff7545a2..d79e30b2 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/SliderScroller.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/SliderScroller.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2021 Edwin Park and others. + * Copyright (c) 2013, 2025 Edwin Park and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -19,11 +19,26 @@ public class SliderScroller implements IScroller { private Slider slider; + private boolean handleVisibilityChange = true; public SliderScroller(Slider slider) { this.slider = slider; } + /** + * + * @param slider + * The {@link Slider} to use as the scroller. + * @param handleVisibilityChange + * Configure if the scroller will handle visibility changes of + * the slider. + * @since 2.6 + */ + public SliderScroller(Slider slider, boolean handleVisibilityChange) { + this.slider = slider; + this.handleVisibilityChange = handleVisibilityChange; + } + @Override public Slider getUnderlying() { return this.slider; @@ -112,15 +127,17 @@ public boolean getVisible() { @Override public void setVisible(boolean b) { - boolean visible = this.slider.isVisible(); - this.slider.setVisible(b); - // if the slider becomes invisible we fire a resize event to trigger - // re-calculation of percentage sized columns to take the slider - // space - if (!b && visible - && !isDisposed() - && !this.slider.getParent().isDisposed()) { - this.slider.getParent().notifyListeners(SWT.Resize, null); + if (this.handleVisibilityChange) { + boolean visible = this.slider.isVisible(); + this.slider.setVisible(b); + // if the slider becomes invisible we fire a resize event to trigger + // re-calculation of percentage sized columns to take the slider + // space + if (!b && visible + && !isDisposed() + && !this.slider.getParent().isDisposed()) { + this.slider.getParent().notifyListeners(SWT.Resize, null); + } } } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java index ddeb1e3d..b1deb17a 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/viewport/ViewportLayer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2023 Original authors and others. + * Copyright (c) 2012, 2025 Original authors and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -170,6 +170,15 @@ public void setHorizontalScroller(IScroller scroller) { } } + /** + * + * @return The scroller that is used for horizontal scrolling. + * @since 2.6 + */ + public IScroller getHorizontalScroller() { + return this.horizontalScroller; + } + /** * Set a different vertical scroller than the default one. * @@ -185,6 +194,15 @@ public void setVerticalScroller(IScroller scroller) { } } + /** + * + * @return The scroller that is used for vertical scrolling. + * @since 2.6 + */ + public IScroller getVerticalScroller() { + return this.verticalScroller; + } + public int getMaxWidth() { if (getMaxColumnPosition() < 0) { return -1; diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5042_HorizontalSplitViewportExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5042_HorizontalSplitViewportExample.java index b71f1591..8361e8c8 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5042_HorizontalSplitViewportExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5042_HorizontalSplitViewportExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2021 Dirk Fauth and others. + * Copyright (c) 2013, 2025 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -188,11 +188,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) { sliderLeftComposite.setLayoutData(gridData); Slider sliderLeft = new Slider(sliderLeftComposite, SWT.HORIZONTAL); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - sliderLeft.setLayoutData(gridData); - left.setHorizontalScroller(new SliderScroller(sliderLeft)); // Slider Right diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5043_VerticalSplitViewportExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5043_VerticalSplitViewportExample.java index 78681a07..d94e11eb 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5043_VerticalSplitViewportExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5043_VerticalSplitViewportExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2021 Dirk Fauth and others. + * Copyright (c) 2013, 2025 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -187,11 +187,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) { sliderTopComposite.setLayoutData(gridData); Slider sliderTop = new Slider(sliderTopComposite, SWT.VERTICAL); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - sliderTop.setLayoutData(gridData); - top.setVerticalScroller(new SliderScroller(sliderTop)); // Slider Bottom diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5044_HorizontalSplitViewportGridExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5044_HorizontalSplitViewportGridExample.java index 62dcd05a..e30feaab 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5044_HorizontalSplitViewportGridExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5044_HorizontalSplitViewportGridExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2021 Dirk Fauth and others. + * Copyright (c) 2013, 2025 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -321,11 +321,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) { sliderLeftComposite.setLayoutData(gridData); Slider sliderLeft = new Slider(sliderLeftComposite, SWT.HORIZONTAL); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - sliderLeft.setLayoutData(gridData); - left.setHorizontalScroller(new SliderScroller(sliderLeft)); // Slider Right diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5045_ScrollableRowHeaderExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5045_ScrollableRowHeaderExample.java index 7f0fb331..52799813 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5045_ScrollableRowHeaderExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5045_ScrollableRowHeaderExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2024 Dirk Fauth and others. + * Copyright (c) 2015, 2025 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor; import org.eclipse.nebula.widgets.nattable.data.IDataProvider; @@ -183,6 +184,8 @@ public int getColumnCount() { gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + NatTable natTable = new NatTable(composite, gridLayer); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; @@ -219,14 +222,16 @@ public void paintOverlay(GC gc, ILayer layer) { return natTable; } - private void createSplitSliders( - Composite natTableParent, final ViewportLayer left, int fixedHeaderWidth, final ViewportLayer right) { + private void createSplitSliders(Composite natTableParent, final ViewportLayer left, int fixedHeaderWidth, final ViewportLayer right) { + // calculate the slider height according to the display scaling + int sliderHeight = GUIHelper.convertHorizontalPixelToDpi(17, true); + Composite sliderComposite = new Composite(natTableParent, SWT.NONE); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = false; - gridData.heightHint = 17; + gridData.heightHint = sliderHeight; sliderComposite.setLayoutData(gridData); GridLayout gridLayout = new GridLayout(2, false); @@ -243,7 +248,7 @@ private void createSplitSliders( @Override public Point computeSize(int wHint, int hHint, boolean changed) { int width = ((ClientAreaAdapter) left.getClientAreaProvider()).getWidth() + fixedHeaderWidth; - return new Point(width, 17); + return new Point(width, sliderHeight); } }; sliderLeftComposite.setLayout(new FillLayout()); @@ -253,11 +258,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) { sliderLeftComposite.setLayoutData(gridData); Slider sliderLeft = new Slider(sliderLeftComposite, SWT.HORIZONTAL); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - sliderLeft.setLayoutData(gridData); - left.setHorizontalScroller(new SliderScroller(sliderLeft)); // Slider Right diff --git a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5046_MultiScrollExample.java b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5046_MultiScrollExample.java index bcc27bce..21284c2d 100644 --- a/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5046_MultiScrollExample.java +++ b/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_504_Viewport/_5046_MultiScrollExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2024 Dirk Fauth and others. + * Copyright (c) 2016, 2025 Dirk Fauth and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; +import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.command.ILayerCommand; import org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor; @@ -152,6 +153,7 @@ public Control createExampleControl(Composite parent) { contentColumnHeaderLayer.setLayerPainter(new CellLayerPainter(true, false)); ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); // Wrap NatTable in composite so we can slap on the external horizontal // sliders @@ -163,6 +165,8 @@ public Control createExampleControl(Composite parent) { gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + NatTable natTable = new NatTable(composite, gridLayer); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; @@ -222,14 +226,16 @@ private void updateScrolledCompositeSize(ScrolledComposite sc, ExtendedGridLayer * @param gridLayer * @param fixedHeaderWidth */ - private void createSplitSliders( - Composite natTableParent, ExtendedGridLayer gridLayer, int fixedHeaderWidth) { + private void createSplitSliders(Composite natTableParent, ExtendedGridLayer gridLayer, int fixedHeaderWidth) { + // calculate the slider height according to the display scaling + int sliderHeight = GUIHelper.convertHorizontalPixelToDpi(17, true); + Composite sliderComposite = new Composite(natTableParent, SWT.NONE); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = false; - gridData.heightHint = 17; + gridData.heightHint = sliderHeight; sliderComposite.setLayoutData(gridData); GridLayout gridLayout = new GridLayout(2, false); @@ -246,7 +252,7 @@ private void createSplitSliders( @Override public Point computeSize(int wHint, int hHint, boolean changed) { int width = ((ClientAreaAdapter) gridLayer.getStructureBody().getViewportLayer().getClientAreaProvider()).getWidth() + fixedHeaderWidth; - return new Point(width, 17); + return new Point(width, sliderHeight); } }; sliderLeftComposite.setLayout(new FillLayout()); @@ -256,11 +262,6 @@ public Point computeSize(int wHint, int hHint, boolean changed) { sliderLeftComposite.setLayoutData(gridData); Slider sliderLeft = new Slider(sliderLeftComposite, SWT.HORIZONTAL); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - sliderLeft.setLayoutData(gridData); - gridLayer.getStructureBody().getViewportLayer().setHorizontalScroller(new SliderScroller(sliderLeft)); // Slider Right