Implement editpolicyproviders extension points in GMF

Source: Internet
Author: User

By using Org. eclipse. GMF. runtime. digoal. UI. the editpolicyproviders extension point can add the required editpolicy to the editpart In the GMF application. The command returned by the editpolicy can control the editpart behavior freely. By the way, GMF runtime provides many extensions to allow various customization of applications generated by GMF through other plug-ins.

For exampleProgramIs namedBookDouble-click to open a dialog box to modify the model attributes. The most direct method is to find the bookeditpart generated by GMF, overwrite the receivmrequest () method, and determine whether request. GetType () is requestconstatns. req_open. If yes, open a dialog box. However, this requires usCodeWritten in a GMF-generated plug-in project, what if we cannot modify the code of a third-party plug-in because it sometimes needs to be extended?

If you use the editpolicyproviders extension point, there is no such restriction. You still need to follow the steps below:

Create a plug-in project and rely on the generated GMF application and GMF dependencies (especially Org. eclipse. GMF. runtime. digoal. UI. providers), In the plugin. add Org. eclipse. GMF. runtime. digoal. UI. editpolicyproviders, specifying a provider class through the class attribute.

 <  Extension  Point = "Org. Eclipse. GMF. runtime. diruntime. UI. editpolicyproviders"  >      <  Editpolicyprovider  Class  = "Com. My. digoal. Custom. myeditpolicyprovider"  >         <  Priority  Name  = "Lowest"  >         </  Priority  >     </  Editpolicyprovider  >  </  Extension  > 

The provider defined here must be written by itself. It should implement the ieditpolicyprovider interface. Its provide () method determines whether to create an editpolicy for the relevant editpart based on the input operation. If so, createeditpolicies () use the installeditpolicy () method to add. The following code enables double-click to open a dialog box:

 Public   Class Myeditpolicyprovider Implements  Ieditpolicyprovider {  Public   Void Createeditpolicies (editpart) {editpart. installeditpolicy (editpolicyroles. open_role,  New  Openconditioneditpolicy ());}  Public   Void  Addproviderchangelistener (iproviderchangelistener listener ){}  Public   Boolean  Provides (ioperation operation ){  If (Operation Instanceof  Createeditpoliciesoperation) {editpart = (Createeditpoliciesoperation) Operation). geteditpart ();  If (Editpart Instanceof  Conditioneditpart)  Return   True  ;}  Return   False  ;}  Public   Void  Removeproviderchangelistener (iproviderchangelistener listener ){}} 

Refer:

http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/msg05684.html
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/msg00931.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.