Bug 511459 - [ViewMgmt] IWorkbenchPage#showView opens *newly installed* views next to Welcome view
Summary: [ViewMgmt] IWorkbenchPage#showView opens *newly installed* views next to Welc...
Status: CLOSED DUPLICATE of bug 544222
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-01 07:13 EST by Andreas Sewe CLA
Modified: 2019-05-26 08:56 EDT (History)
1 user (show)

See Also:


Attachments
Minimal example project (3.46 KB, application/zip)
2017-02-01 07:13 EST, Andreas Sewe CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Sewe CLA 2017-02-01 07:13:01 EST
Created attachment 266561 [details]
Minimal example project

Hi,

I have the following use case: When installed, my plug-in should automatically open its view the next time the Eclipse IDE is started. Moreover, if the user starts in the Java perspective, the view should open in the "optimal" location (as determined by a perspectiveExtension).

My implementation looks like this:

1) In IStartup#earlyStartup I schedule a WorkbenchJob.

2) In WorkbenchJob#runInUIThread I do worbenchPage.showView("org.example.SampleView");

    public void earlyStartup() {

        Job job = new WorkbenchJob("") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                try {
                    PlatformUI.getWorkbench().getActivePage().showView("org.example.SampleView");
                } catch (Exception e) {
                }
                return Status.OK_STATUS;
            }
        };
        job.schedule();
    }


Unfortunately, this will open my view right next the "Welcome" view, even though technically the Java Perspective is already open, just minimized.

Strangely enough, the above implementation strategy works if I try to show *another* view which was already installed previously (e.g., the Project Explorer):
    PlatformUI.getWorkbench().getActivePage().showView("org.eclipse.ui.navigator.ProjectExplorer");

This opens the Project Explorer where you would expect it, i.e., next to the Package Explorer rather than next to the Welcome view. What's even more strange is that opening Package Explorer *and then* the Sample View opens both views on the perspective proper, i.e., not next to the Welcome view. (Still, the Sample View is perspectiveExtension/view@ration attribute is not respected.)

FWIW, all this has been tested with both Neon.2 and Oxygen M5.
Comment 1 Rolf Theunissen CLA 2019-05-26 08:56:08 EDT
I think you have multiple issues here:
1. The perspectiveExtensions are only applied to the Java Perspective, after the perspective is reset. So when you open the view, the opening is handled as if it was not defined in the perspective. This is the context of Bug 191256.
2. The location of a new view can be unpredictable, this is context of Bug 544222. 

In case of first showing the ProjectExplorer. The ProjectExplorer as a predefined location, activation this one first changes the focus. After that the 'last container' as discussed in Bug 544222 changes, which explains the other location of the opened view.

Marking as duplicate of Bug 544222.

*** This bug has been marked as a duplicate of bug 544222 ***