Contributionitemprovider extension points in GMF

Source: Internet
Author: User

Functions of the contributionitemprovider extension point in GMF and org. eclipse. UI. editexceptions is similar to adding actions to the specified editor. However, you can use contributionitemprovider to add actions to the view and add popupmenu and other functions, it is equivalent to a set of multiple action-related extension points provided by eclipse. The following example shows how to use contributionitemprovider to add action to editor.

First, describe the contributionitemprovider Implementation Method in plugin. xml. In the following XMLCodeFirst, use the contributionitemprovider element to specify the implementation Class As COM. my. mycontributionitemprovider. This implementation class can be divided into two situations: Generally, it inherits from the abstractcontributionitemprovider provided by GMF; you can also directly implement icontributionitemprovider, in the latter case, no other elements under the contributionitemprovider element need to be defined. All actions can be constructed using Java code in the contributetoactionbars () and contributetopopupmenu () methods.

 <  Extension  Point  = "Org. Eclipse. GMF. runtime. Common. UI. Services. Action. contributionitemproviders" >      <  Contributionitemprovider  Checkpluginloaded  = "False"  Class  = "Com. My. mycontributionitemprovider"  >         <  Priority  Name  = "Low"  />         <  Partcontribution  ID = "Com. My. rulediagrameditorid"  >            <  Partaction  ID  = "Showconsole"  Menubarpath  = "/Window/views"  >            </  Partaction  >         </  Partcontribution  >      </ Contributionitemprovider  >   </  Extension  > 

Now we will discuss the inheritance of abstractcontributionitemprovider. We need to implement the createaction () method, which accepts actionid as a parameter. The actionid parameter is in plugin. in XML, the partcontribution element is used to specify the editor to which the action will be added, then, use the partaction element to specify other parameters such as the ID of the action to be added and the location of menubarpath.

In fact, the main function of abstractcontributionitemprovider is to parse the XML elements under contributionitemprovider and call the createaction () method based on the content of these elements () you can get the actionid and create the actual action class based on it. The following is the mycontributionitemprovider code corresponding to the preceding XML snippet:

 Public   Class Mycontributionitemprovider Extends Abstractcontributionitemprovider {@ override  Protected  Iaction createaction (string actionid, iworkbenchpartdescriptor partdescriptor ){  If (Actionid. Equals ("showconsole" ) {Iaction action = New Showviewaction ("& console", "console. View. ID" ); Action. setimagedescriptor ();  Return  Action ;}  Return   Super . Createaction (actionid, partdescriptor );}  Class Showviewaction Extends  Action {}} 

Note that if editor and contributionitemprovider are not in the same plugin, you must specify the checkpluginloaded attribute of the contributionitemprovider element in plugin. XML to false. Otherwise, the contributionitemprovider will not be loaded. (Supplement 08/01/02: If the menupath settings are incorrect, contributionitemprovider may not be loaded. The correct menupath is "/file/print ")

Several reference links:
Http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/msg06035.html
Http://dev.eclipse.org/newslists/news.eclipse.technology.gmf/msg04270.html
Http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/msg00757.html
Http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/msg08196.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.