Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Correct way to customize CreateCommand
Correct way to customize CreateCommand [message #230332] Thu, 14 May 2009 19:02 Go to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Hi,

I am trying to customize my XxxCreateCommand using extension points.

I managed to do it the following way:

* I contribute to extension
point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders "

* In my CustomXxxEditPartProvider I set a CustomXxxEditPartFactory and its
overridden createEditPart-method returns a CustomXxxEditPart.

* In the CustomXxxEditPart I override createDefaultEditPolicies and after
calling super.createDefaultEditPolicies I re-install a
CustomXxxSemanticEditPolicy (the policy EditPolicyRoles.SEMANTIC_ROLE has
already been set by super.createDefaultEditPolicies).

My CustomXxxSemanticEditPolicy then returns a CustomXxxCreateCommand in
getCreateCommand which then overrides doDefaultElementCreation.

Is this the correct way or is there any, well, shorter way? :)

Thanks in advance!
Re: Correct way to customize CreateCommand [message #230343 is a reply to message #230332] Thu, 14 May 2009 19:29 Go to previous messageGo to next message
Tobias Neef is currently offline Tobias NeefFriend
Messages: 17
Registered: July 2009
Junior Member
It is correct to create a new Policy and a new CreateCommand. But I would
not inject the policy by modifying the edit part itself I would rather
recommend to create a own EditPolicy provider to do this. The extension
point for this is org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders.
Re: Correct way to customize CreateCommand [message #230470 is a reply to message #230343] Fri, 15 May 2009 13:11 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Sounds like the way I want to go, thanks!

I'm not sure how to do it though.
I added the extension point for
org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders, and in my
CustomXxxEditPolicyProvider.createEditPolicies I check for instanceof my
XxxEditPart and in that case I call editPart.installEditPolicy.

The method is being called, but the edit-policy is not used. Maybe its
overwritten later.

I tried using "context editparts" in plugin.xml in order to avoid the
instanceof too, but then the policyProvider was not used at all.

Am I taking the right direction and doing something wrong or is this not
how one does it at all?

Thanks in advance!
Re: Correct way to customize CreateCommand [message #230485 is a reply to message #230470] Fri, 15 May 2009 14:23 Go to previous messageGo to next message
Tobias Neef is currently offline Tobias NeefFriend
Messages: 17
Registered: July 2009
Junior Member
Sounds good from my perspective but probably I get you wrong. This is how
it works for me:

public class EditPolicyProvider extends AbstractProvider implements
IEditPolicyProvider {

@Override
public void createEditPolicies(EditPart editPart) {
if (editPart instanceof MyEditPart) {
MyEditPartep = (MyEditPart) editPart;
ep.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new CustomMyEditPartItemSemanticEditPolicy());
new RTLayoutEditPolicy());

} else if (editPart instanceof ....

}

@Override
public boolean provides(IOperation operation) {
if(operation instanceof CreateEditPoliciesOperation){
EditPart editPart = ((CreateEditPoliciesOperation)
operation).getEditPart();
View view = (View) editPart.getModel();
String modelID = view.getDiagram().getType();

return MyModelEditPart.MODEL_ID.equals(modelID);
}
return false;
}
}

Did you implemented it like that? And did you removed the custom
installation in you edit part which could overwrite the semantic policy?

Regards,
Tobias
Re: Correct way to customize CreateCommand [message #230539 is a reply to message #230485] Fri, 15 May 2009 15:44 Go to previous message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Thanks a lot, Tobias!

Not sure what I got wrong at my first try, but your solution works perfect!
Previous Topic:Visibility of view
Next Topic:Regions in a Statemachine diagram
Goto Forum:
  


Current Time: Fri Nov 24 01:54:02 GMT 2017

Powered by FUDForum. Page generated in 0.02382 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software