Question

I have created an editor plug-in for eclipse that is associated with the file extension .eap

I have also created a perspective that contains views for this data.

I would like to add the following behaviour: When I double click on the .eap file I'd like the EAP Perspective to be opened.

Just like what happens when you click on a Java file for the first time.

Any help appreciated!

Will


    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        workbench.showPerspective(EapPerspective.ID,
                workbench.getActiveWorkbenchWindow());
    } catch (WorkbenchException e) {
        e.printStackTrace();
    }
Was it helpful?

Solution

As far as I know, clicking on or opening a Java file for the first time will not open the Java perspective. However, perhaps you are thinking about how after using the New Java Class Wizard, you are prompted to change to the Java perspective.

Regardless, there are several things that you can do:

  • In the org.eclipse.ui.newWizards extension point, specify the finalPerspective as well as preferredPerspectives
  • Assuming that you have sub-classed AbstractTextEditor, then override the setFocus() method and add some logic to change to the appropriate perspective, something like this (but be careful to add specific null checks):

    getEditorSite().getWorkbenchWindow().getWorkbench().showPerspective(desc.getId(), getWindow(), pageInput);

The first solution is recommended, although it will not cover all the cases that you are asking for, and the second is a bit naughty as it goes against Eclipse conventions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top