Bug 574023

Summary: SWT/JFace: Window.getInitialSize()/getInitialLocation() not being called if ToolBarManager is used
Product: [Eclipse Project] Platform Reporter: Stefan Kowski <stefan.kowski>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: loskutov, twolf
Version: 4.9Keywords: regression
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=531854
Whiteboard:
Attachments:
Description Flags
Sample application none

Description Stefan Kowski CLA 2021-06-04 09:38:47 EDT
Created attachment 286525 [details]
Sample application

Dependencies:
    JFace 3.22.100
    SWT 3.116.0 (win32.x64_86)

------

Hi,

I have a strange effect when I add a toolbar to a JFace application window. It is a standalone JFace application, not an Eclipse plugin.

The problem occurs when I add at least one action to the ToolBarManager. It works fine when the ToolBarManager is empty.

    @Override
    protected ToolBarManager createToolBarManager(int style) {

        ToolBarManager tbm = new ToolBarManager(style);
        tbm.add(new NewProjectAction()); // will cause problem
        return tbm;

If the action has been created, my overridden application window functions getInitialSize() and getInitialLocation() will not be called by the framework.

This is because the variable Window.resizeHasOccurred is true so the function Window.initializeBounds() exits.

    protected void initializeBounds() {
        if (resizeListener != null) {
            shell.removeListener(SWT.Resize, resizeListener);
        }
        if (resizeHasOccurred) { // Check if shell size has been set already.
            return; // ** exiting here
        }

        Point size = getInitialSize();
        Point location = getInitialLocation(size);
        shell.setBounds(getConstrainedShellBounds(new Rectangle(location.x,
                location.y, size.x, size.y)));
    }

As a workaround, I may override initializeBounds(). If not, the window will be opened in minimal size at a random location.

But even if I implement initializeBounds(), I also notice the window being opened in minimal size and random location, then disappearing and being shown again in the required size and location.

A minimal application that shows the bug has been provided as attachment.
Comment 1 Thomas Wolf CLA 2021-06-07 11:13:08 EDT
Also reproduces on Mac OS X 10.14.6.

Issue was introduced between JFace 3.14.0 (opens with large window) and 3.14.100 (opens with packed window). I.e., between June 2018 and September 2018. (Keeping the SWT version stable at 3.116.0.)

So the problem appears to be in JFace.

My guess is that this comes from https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/125161 done for bug 531854. That change added a pack() call on the toolbar's parent.

Whether it's a problem with that change or with the usage shown in the example I cannot tell.