Wednesday, October 14, 2009

Recipe 12.11 Automatically Adding a Plug-in to a Perspective











 < Day Day Up > 







Recipe 12.11 Automatically Adding a Plug-in to a Perspective







12.11.1 Problem





You don't want users to have

to

explicitly add your plug-in to a perspective by customizing it.









12.11.2 Solution





Use the extension point

org.eclipse.ui.perspectiveExtensions in

plugin.xml to add the plug-in to the perspective

automatically.









12.11.3 Discussion





To automatically add a plug-in to a perspective, use the extension

point org.eclipse.ui.perspectiveExtensions in

plugin.xml. You can make this just by editing

the XML in plugin.xml. Here's

how to automatically add the plug-in developed over the previous few

recipes to the Java perspective in plugin.xml:





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

<plugin

id="org.cookbook.ch12.MenuPlugInFromScratch"

name="MenuPlugInFromScratch Plug-in"

version="1.0.0"

provider-name="Eclipse Cookbook"

class="org.cookbook.ch12.MenuPlugInFromScratch.MenuPlugInFromScratchPlugin">



<runtime>

<library name="MenuPlugInFromScratch.jar"/>

</runtime>

<requires>

<import plugin="org.eclipse.core.resources"/>

<import plugin="org.eclipse.ui"/>

</requires>



<extension

point="org.eclipse.ui.actionSets">

<actionSet

label="Action Set 1"

visible="true"

id="org.cookbook.ch12.MenuPlugInFromScratch.actionSet1">

<menu

label="Menu 1"

id="Menu1">

<separator

name="Group1">

</separator>

</menu>

<action

label="Action 1"

class="org.cookbook.ch12.MenuPlugInFromScratch.Action1"

tooltip="This action is functional."

menubarPath="Menu1/Group1"

toolbarPath="Group1"

id="Action1">

</action>

</actionSet>

</extension>

<extension

point = "org.eclipse.ui.perspectiveExtensions">

<perspectiveExtension

targetID="org.eclipse.ui.javaPerspective">

<actionSet

id="org.cookbook.ch12.MenuPlugInFromScratch.actionSet1">

</actionSet>

</perspectiveExtension>

</extension>

</plugin>







Save plugin.xml after editing it, and restart

the Run-time Workbench. When you do, the new plug-in should appear on

startup.







Other perspectives can be reached using similar nomenclature. For

example, to add a plug-in to the Resource perspective, use

org.eclipse.ui.resourcePerspective.
























     < Day Day Up > 



    No comments:

    Post a Comment