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