Search code examples
eclipse-rcprcp

How can i add two views into one perspective?


I have made a new plug-in project with a minimal template and defined two views. This is my first view:

public class MyView extends ViewPart {

    public MyView() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void createPartControl(Composite parent) {
        Text text = new Text(parent, SWT.BORDER);
        text.setText("First view");
    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }

}

This is my second view:

public class SecondView extends ViewPart {

    public SecondView() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void createPartControl(Composite parent) {
        Text text = new Text(parent, SWT.BORDER);
        text.setText("Second view");
    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }

}

This is my plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         id="application"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run
               class="com.rcptest.testez.Application">
         </run>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="RCP Perspective"
            class="com.rcptest.testez.Perspective"
            id="com.rcptest.testez.perspective">
      </perspective>
   </extension>
   <extension
         point="org.eclipse.ui.views">
      <view
            class="com.rcptest.testez.view.MyView"
            id="com.rcptest.testez.view.MyView"
            name="FirstView"
            restorable="true">
      </view>
      <view
            class="com.rcptest.testez.view.SecondView"
            id="com.rcptest.testez.view.SecondView"
            name="SecondView"
            restorable="true">
      </view>
   </extension>
   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="*">
         <view
               id="com.rcptest.testez.view.MyView"
               minimized="false"
               ratio="0.3f"
               relationship="top"
               relative="org.eclipse.ui.editorss">
         </view>
         <view
               id="com.rcptest.testez.view.SecondView"
               minimized="false"
               ratio="0.5f"
               relationship="bottom"
               relative="org.eclipse.ui.editorss">
         </view>
      </perspectiveExtension>
   </extension>

</plugin>

When I run the application I can only see my first view. I really don't see where I'm going wrong. How can I show the second view also?

EDIT: Perspective class:

public void createInitialLayout(IPageLayout layout) {
         layout.addView("com.rcptest.testez.view.MyView", IPageLayout.TOP,
                    IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
         layout.addView("com.rcptest.testez.view.SecondView", IPageLayout.BOTTOM,
                    IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
    }

Solution

  • Your Perspective class is saying that each of the views should occupy 95% of the space (IPageLayout.RATIO.MAX) which is impossible.

    You must specify ratios which add up to no more than 100% (1.0) or less if you want an editor area as well. For example:

    layout.addView("com.rcptest.testez.view.MyView", IPageLayout.TOP,
                   0.3f, IPageLayout.ID_EDITOR_AREA);
    layout.addView("com.rcptest.testez.view.SecondView", IPageLayout.BOTTOM,
                   0.3f, IPageLayout.ID_EDITOR_AREA);
    

    Note: you may need to do a 'Reset Perspective' when you rerun your test with the modified perspective.