[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.modeling.gmf] Re: EditPolicyProvider question
|
On Mon, 11 Sep 2006 15:23:20 -0400, "Cherie Revells (Mahoney)"
<cmahoney@xxxxxxxxxx> wrote:
>Hao Zhang,
>
>All you need to do, is write the provides() method as you would in any
>other service, describing the type of editpart you provide for (or
>element of the editpart). Make sure you are specific here so as not to
>have your editpolicy installed on non-applicable editparts.
>
>Then you just need to install your editpolicy on the editpart in the
>createEditPolicies() method.
>
>e.g. editPart.installEditPolicy(THE_ROLE, new TheEditPolicy());
>
>I hope this helps.
I'll add some detail, here's code for a
PropertyHandlerEditPolicyProvider class, that installs a
PropertyHandlerEditPolicy for the
EditPolicyRoles.PROPERTY_HANDLER_ROLE role on edit parts of the types
GateEditPart and AbstractVariableEditPart.
public class PropertyHandlerEditPolicyProvider implements
IEditPolicyProvider {
public void createEditPolicies(EditPart editPart) {
editPart.installEditPolicy(EditPolicyRoles.PROPERTY_HANDLER_ROLE,
new PropertyHandlerEditPolicy());
}
public boolean provides(IOperation operation) {
if (operation instanceof CreateEditPoliciesOperation)
{
EditPart editPart =
((CreateEditPoliciesOperation)operation).getEditPart();
if (editPart instanceof GateEditPart ||
editPart instanceof
AbstractVariableEditPart
)
return true;
}
return false;
}
public void addProviderChangeListener(IProviderChangeListener
listener) {
}
public void
removeProviderChangeListener(IProviderChangeListener listener) {
}
}
Remember also to declare the PropertyHandlerEditPolicyProvider class
in plugin.xml, as follows:
<editPolicyProvider
class="no.hal.diamodl.diagram.custom.providers.PropertyHandlerEditPolicyProvider">
<Priority name="Lowest"/>
<object id="GateEditPart"
class="no.hal.diamodl.diagram.edit.parts.GateEditPart(no.hal.diamodl.gmf.diagram)"/>
<object id="VariableEditPart"
class="no.hal.diamodl.diagram.edit.abstractparts.AbstractVariableEditPart(no.hal.diamodl.gmf.diagram)"/>
<context
editparts="GateEditPart,VariableEditPart"
/>
</editPolicyProvider>
Note how the object elements declares IDs for the EditPart classes
(the project/plugin name is within the parenthesis), and how the
context element refers to these IDs.
Hallvard
>
>- Cherie
>
>
>Hao Zhang wrote:
>> Hi,
>> Is there any editpolicyprovider snippet except the one in GMF Developer
>> Guide, in which I couldn't find the source of
>> TraceDiagramEditPolicyProvider. In fact, I found no implementation of
>> IEditPolicyProvider except EditPolicyService, so I wonder how to
>> implement the TraceDiagramEditPolicyProvider above.
>>