1

I have configured my code to open multiple instances of the same view but the secondary view opens in a different tab in a different location in the same perspective but I would like the duplicate view instances to open next to the original view instance like tabbed multiple views, I had posted another similar question a few days ago and received a positive response on using IFolderLayout.addPlaceholder but still I did not find a way to specify the 'stack' relationship using IPageLayout, here's my plugin.xml code where I have defined a few Eclipse views that should show up in my application -

<menuContribution
      allPopups="false"
      locationURI="toolbar:com.my.ui.MyView?after=additions">
      <command
          commandId="com.my.ui.MyView"
          icon="platform:/plugin/com.my.ui.icons.eclipse/icons/new_wiz.gif"
          style="push">
      </command>
</menuContribution>

<command
    categoryId="org.eclipse.ui.category.views"
    defaultHandler="com.my.ui.commands.NewMyViewHandler"
    id="com.my.ui.MyView"
    name="Open My View">
</command>

<extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="com.my.ui.perspectives.myPerspective">
         <view
               closeable="true"
               id="org.eclipse.ui.console.ConsoleView"
               minimized="false"
               moveable="true"
               ratio=".65"
               relationship="bottom"
               relative="org.eclipse.ui.editorss"
               visible="true">
         </view>
         <view
               closeable="true"
               id="org.eclipse.ui.navigator.ProjectExplorer"
               minimized="false"
               moveable="true"
               ratio=".8"
               relationship="left"
               relative="org.eclipse.ui.editorss"
               visible="true">
         </view>
         <view
               closeable="true"
               id="org.eclipse.ui.views.PropertySheet"
               minimized="false"
               moveable="true"
               ratio=".05"
               relationship="right"
               relative="org.eclipse.ui.editorss"
               visible="true">
         </view>
      </perspectiveExtension>
</extension>

And, here's the Java code that implements IPerspectiveFactory and adds my custom view and a placeholder for duplicate instances of my custom view -

public class MyPerspective implements IPerspectiveFactory
{

  @Override
  public void createInitialLayout(final IPageLayout layout)
  {
    IFolderLayout folderLayout = layout.createFolder("right", IPageLayout.RIGHT, 0.27f, IPageLayout.ID_PROJECT_EXPLORER);
    folderLayout.addView("com.my.ui.MyView");
    folderLayout.addPlaceholder("com.my.ui.MyView" + ":*");
    layout.setEditorAreaVisible(false);
    layout.setFixed(true);
  }
}

And here's my handler class to open multiple instances of the view when the button "Open My View" us clicked -

public class MyViewHandler extends AbstractHandler
{

  int counter = 1;

  private String getNextSecondaryId()
  {
    return "com.my.ui.MyView#" + this.counter;
  }
  
  @Override
  public Object execute(final ExecutionEvent event) throws ExecutionException
  {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    IWorkbenchPage page = activePart.getSite().getPage()
    for (; page.findViewReference("com.my.ui.MyView", getNextSecondaryId()) != null; this.counter++)
    {
    }

    try
    {
      page.showView("com.my.ui.MyView", getNextSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE);
      this.counter++;
    }

    return null;
  }

}

But using this the property view first opens to the right of Project Explorer and my view occupies all of the right space including the 'top' and the 'bottom' but I want my view to open to the right of project explorer view and then the property view to open to the right of my view and the console view to the bottom of my view.

My questions are that:

  1. Is there a need to define org.eclipse.ui.perspectiveExtensions for my own view in the plugin.xml file or should I just add the view using IFolderLayout.addView?

  2. Under what circumstances should I use both i.e., defining org.eclipse.ui.perspectiveExtensions for my own view and also add the view using IFolderLayout.addView?

  3. I tried using the org.eclipse.ui.perspectiveExtensions to define my own view and then just adding the placeholder using IFolderLayout.addPlaceholder("com.my.ui.MyView" + ":*"); but this opened the first instance of my view correctly right to the Project Explorer but the other instances of my view does not open as Tabbed views but to the right of my first view since I cannot specify a stack relationship using IPageLayout in the code.

Basically I want my first instance of the view to open to the right of project explorer and the duplicate instances to open as tabbed views right beside my first opened view. I would like to open the duplicate instances of the same view next to the original view tab and not in a new tab.

What am I doing wrong here? Also, are there any good examples of supporting multiple duplicate views instances where the duplicate views are all 'stacked' next to the original view?

Sangli
  • 373
  • 4
  • 20

0 Answers0