Bug 574023 - SWT/JFace: Window.getInitialSize()/getInitialLocation() not being called if ToolBarManager is used
Summary: SWT/JFace: Window.getInitialSize()/getInitialLocation() not being called if T...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.9   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-06-04 09:38 EDT by Stefan Kowski CLA
Modified: 2021-06-07 11:38 EDT (History)
2 users (show)

See Also:


Attachments
Sample application (3.13 KB, application/x-zip-compressed)
2021-06-04 09:38 EDT, Stefan Kowski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.