SplitPanel SplitterMoveListener

Hello,
i’m using a vertical SplitPanel to show a picture in the left pane and some information to the right.
If the user moves the splitter i want to automatically resize the picture,
but i can’t find any corresponding event.
The SplitterClickListener is only triggered if the user clicks on the splitter,
not if he moves it, nor is any Listener registered with the addListener method triggered in this case.

So, how can i notice if the user moves the splitter?

Thanks in advance,
Yannik

If you just want to picture to resize, set it to 100%x100% size and it will fill the space automatically.

IIRC, there might be some scaling problems with some browsers when using a full-size Embedded. Then using
ImageScaler
instead of Embedded helps.

Still finding this event missing which is very disappointing.
I am hitting a problem where using combination of a vertical splitPanel and Tabsheet set at 100% width, causes the Tabsheet not to render properly (apparently this is caused by the fact the width of the container with the tabsheet is undefined.
Setting the tabsheet width at a fixed value solves the problem, but then I would like to resize it when the user moves the splitter (even setting it to 100% width is OK after it is rendered initially).

But when the user grabs and move the splitter there is simply no event of any kind…

It is very easy to add the events yourself…

import com.vaadin.server.Sizeable;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelRpc;
import com.vaadin.ui.HorizontalSplitPanel;

public class CustomHorizontalSplitPanel extends HorizontalSplitPanel {

    private float lastSplitterPosition;
    private Sizeable.Unit lastSplitterUnit;

    public CustomHorizontalSplitPanel() {
        super();
        this.splitterChangeListeners = null;
        registerRpc(new CustomSplitPanelRpc());
    }

    private class CustomSplitPanelRpc implements AbstractSplitPanelRpc {

        @Override
        public void setSplitterPosition(final float position) {
            final float newSplitterPosition = position;
            final Sizeable.Unit newSplitterUnit = getSplitPositionUnit();

            if ((Math.abs(newSplitterPosition - lastSplitterPosition) > 0.5) || (newSplitterUnit != lastSplitterUnit)) {
                fireSplitterChange(newSplitterPosition, newSplitterUnit);
                lastSplitterPosition = newSplitterPosition;
                lastSplitterUnit = newSplitterUnit;
            }
        }

        @Override
        public void splitterClick(final MouseEventDetails mouseDetails) {
            // TODO , custom click events ?
        }
    }

    @Override
    public void setSplitPosition(final float pos, final Unit unit) {
        super.setSplitPosition(pos, unit); //To change body of generated methods, choose Tools | Templates.
        lastSplitterPosition = pos;
        lastSplitterUnit = unit;
    }

    private static class CustomSplitterChangeEvent implements SplitterChangeEvent {

        private final Object source;
        private final float splitPosition;
        private final Unit splitPositionUnit;

        public CustomSplitterChangeEvent(final Object source, final float splitPosition, final Unit splitPositionUnit) {
            this.source = source;
            this.splitPosition = splitPosition;
            this.splitPositionUnit = splitPositionUnit;
        }

        @Override
        public Object getSource() {
            return source;
        }

        @Override
        public float getSplitPosition() {
            return splitPosition;
        }

        @Override
        public Unit getSplitPositionUnit() {
            return splitPositionUnit;
        }
    }

    /**
     * <code>SplitterChangeListener</code> interface for listening for
     * <code>SplitterChangeEvent</code> fired by a
     * <code>SplitPanel</code>.
     *
     * @see SplitterChangeEvent
     * @since 6.2
     */
    public interface SplitterChangeListener extends java.io.Serializable {

        /**
         * SplitPanel splitter has been clicked
         *
         * @param event SplitterChangeEvent event.
         */
        void splitterChange(SplitterChangeEvent event);
    }


    public interface SplitterChangeEvent extends java.io.Serializable {


        Object getSource();

        float getSplitPosition();

        Unit getSplitPositionUnit();
    }


    public void addSplitterChangeListener(final SplitterChangeListener listener) {
        synchronized (this) {
            if (splitterChangeListeners == null) {
                splitterChangeListeners = new java.util.LinkedList<>();
            }
        }
        synchronized (splitterChangeListeners) {  // NOPMD
            splitterChangeListeners.add(listener);
        }
    }

    public void removeSplitterChangeListener(final SplitterChangeListener listener) {
        if (splitterChangeListeners != null) {
            synchronized (splitterChangeListeners) {
                splitterChangeListeners.remove(listener);
            }
        }
    }

    private void fireSplitterChange(final float splitPosition, final Unit splitPositionUnit) {
        if (splitterChangeListeners != null) {
            final CustomSplitterChangeEvent event = new CustomSplitterChangeEvent(this, splitPosition, splitPositionUnit);
            SplitterChangeListener[] asArr;
            synchronized (splitterChangeListeners) {
                asArr = splitterChangeListeners.toArray(new SplitterChangeListener[splitterChangeListeners.size()]
);
            }
            for (SplitterChangeListener asArr1 : asArr) {
                asArr1.splitterChange(event);
            }
        }
    }

    @Override
    public java.util.Collection<?> getListeners(final Class<?> eventType) {
        if (SplitterChangeEvent.class.isAssignableFrom(eventType)) {
            if (splitterChangeListeners == null) {
                return java.util.Collections.EMPTY_LIST;
            } else {
                return java.util.Collections.unmodifiableCollection(splitterChangeListeners);
            }
        }
        return super.getListeners(eventType);
    }
    private java.util.List<SplitterChangeListener> splitterChangeListeners; // NOPMD , long names
}

Thank you very much for that code. I also had a need for resizing components after the splitter is moved.