Eclipse RCP: Hiding a View inside the View Dialog

If you want to add a view to your Eclipse RCP application, you usually have to register your view using the "org.eclipse.ui.views" extension point. Eclipse then takes care of adding your view to the view dialog automatically, so that users can open this view by selecting it from the menu. But for some reasons you might want to hide a view inside Eclipse's view dialog within your RCP application. For example if you want to open views only programatically or if you have to set specifing parameters when creating the view (e.g. a secondary id when using multiple instances of one view).

You could rewrite / extend the "Show view" menu entry and the view dialog to make it suit your needs but there is an easier way to hide views from this dialog: "Activities". I read about it in this Eclipse bugtracker ticket. Activities are usually meant for grouping, enabling and disabling UI elements based on a current user activity. In this way "activities" are a bit similar to perspectives. You can find more information about activities in the Eclipse help.

In order to hide a view using activites, we simply assign the view to an activity which never gets enabled. This can be done in a declarative way without writing any Java code. First of all add an activity to the "org.eclipse.ui.activities" extension point.

<activity
  description="Hidden View Activity"
  id="com.subshell.example.activity.hiddenView"
  name="Hidden View Activity">
</activity>

If you don't enable the activity somewhere manually, it will be disabled by default.  Users could enable it manually by using the "Capabilities" properties page, which you just have to bother about if you integrated this page in your application. 

After defining the activity, you can assign UI elements like views to it. Simply add an "activityPatternBinding" to the  "org.eclipse.ui.activities" extension point and define the UI element by a pattern. The pattern consists of the plugin ID, a forward slash and the view ID. The activity ID must be the ID of the activity, we defined for hidden views.

<activityPatternBinding
    activityId="com.subshell.example.activity.hiddenView"
    pattern="com.subshell.example.eclipse/com.subshell.example.eclipse.ExampleView">
</activityPatternBinding>

Note that when a view is disabled using activities, it is still possible to open those views programmatically by calling the IWorkbenchPage#showView() method. I figured out that it is not possible though to open hidden views within a custom perspective by calling the IFolderLayout#addView() method.

Sven Hoffmann

Sven Hoffmann

2010-10-11 • 02:35 AM

Eclipse, Java

Categories

Sophora CMS - A New Take on Content Management

Sophora is optimized to meet the needs of modern companies that produce up-to-date multimedia content on a large scale and that require fast delivery of their content.

Toromiro

Toromiro is a professional tool for the administration and editing of Java Content Repositories (JCR). JCR is powering some of today’s most successful solutions for content management and digital asset management.