Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Problems wrapping RecordingCommand
Problems wrapping RecordingCommand [message #73164] Thu, 02 November 2006 05:32 Go to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi!

I am trying to create a new object on my diagram programatically, when
another object is double-clicked.

I have tried following the example: "Create New Elements Using
RecordingCommand and CanonicalEditPolicies" at
http://wiki.eclipse.org/index.php/GMF_Tips

I created a proper RecordingCommand and now I would like to return it from
the getOpenCommand function inside the OpenEditPolicy. I tried to wrap it
using: cmd = new ICommandProxy(myRecordingCommand);

but it is not legal. Any suggestions about how to convert RecordingCommand
to Command or any other way of creating objects inside an OpenEditPolicy?
Thanks!
Re: Problems wrapping RecordingCommand [message #73201 is a reply to message #73164] Thu, 02 November 2006 07:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi again!

I just found out that maybe I should use CreateElementRequest for my
purpose of creating objects programatically.
I wrote the following code:

CreateElementRequest thisReq = new
CreateElementRequest(YardElementTypes.Train_2001);
CreateElementCommand mycmd = new CreateElementCommand(thisReq);
Command cmd = new ICommandProxy(mycmd);

but nothing happens in the diagram (no new object is created) when cmd is
executed. I does not give any errors, so I dont know where the problem is.
Any idea?

Thank you very much!
Re: Problems wrapping RecordingCommand [message #73324 is a reply to message #73201] Thu, 02 November 2006 09:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi Noelia,

If you test cmd.canExecute(), I think you would find that it returns
false. At a minimum you would need to instantiate the request with the
EObject that should contain the new train element.

Are you trying to create a new element and its view from an edit policy?
If so, I suggest that you look at
CreateLogicElementActionDelegate#doRun as an example of how to use the
CreateViewRequestFactory to obtain a request and how to ask the
container edit part for a command to honour that request.

Regards,
Linda

Noelia Rodriguez wrote:
> Hi again!
>
> I just found out that maybe I should use CreateElementRequest for my
> purpose of creating objects programatically. I wrote the following code:
>
> CreateElementRequest thisReq = new
> CreateElementRequest(YardElementTypes.Train_2001);
> CreateElementCommand mycmd = new CreateElementCommand(thisReq);
> Command cmd = new ICommandProxy(mycmd);
>
> but nothing happens in the diagram (no new object is created) when cmd
> is executed. I does not give any errors, so I dont know where the
> problem is. Any idea?
>
> Thank you very much!
>
Re: Problems wrapping RecordingCommand [message #73341 is a reply to message #73201] Thu, 02 November 2006 09:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

Here's a sequence of steps that do what you need. You can look for similar
recipes in SemanticEditPolicy.

This will create a semantic element but it will not be shown on the
diagram unless you have a canonical policy. To create both, take a look
in CreationEditPolicy to see what request you need to use. Create that
request (look in Creation tool to see how it's done) and call
getHost().getCommand(req).


CreateElementRequest createRequest = new CreateElementRequest(
getEditingDomain(container), container, type, containmentFeature);

IElementType elementType = ElementTypeRegistry.getInstance()
.getElementType(createRequest.getEditHelperContext());

ICommand createCommand = elementType.getEditCommand(createRequest);


On Thu, 02 Nov 2006 12:41:32 +0000, Noelia Rodriguez wrote:

> Hi again!
>
> I just found out that maybe I should use CreateElementRequest for my
> purpose of creating objects programatically.
> I wrote the following code:
>
> CreateElementRequest thisReq = new
> CreateElementRequest(YardElementTypes.Train_2001);
> CreateElementCommand mycmd = new CreateElementCommand(thisReq);
> Command cmd = new ICommandProxy(mycmd);
>
> but nothing happens in the diagram (no new object is created) when cmd is
> executed. I does not give any errors, so I dont know where the problem is.
> Any idea?
>
> Thank you very much!
Re: Problems wrapping RecordingCommand [message #73430 is a reply to message #73201] Thu, 02 November 2006 10:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

I checked the example in CreateLogicElementActionDelegate and now I am
able to create a new object and its view:

IGraphicalEditPart container = (IGraphicalEditPart) editPart.getParent();
CreateViewRequest createRequest =
CreateViewRequestFactory.getCreateShapeRequest(YardElementTy pes.Train_2001,
container.getDiagramPreferencesHint());
cmd = container.getCommand(createRequest);

I would like to set the attributes value of the new object. Is it possible
to pass them as parameters in this way of creating the object? I checked
the constructor getCreateShapeRequest and it seems to be that the only
parameters that it can take are the IElementType and the PreferencesHint.
Thank you very much!
Re: Problems wrapping RecordingCommand [message #74757 is a reply to message #73430] Mon, 06 November 2006 12:06 Go to previous messageGo to next message
Eclipse UserFriend
Noelia,

If you have a 'kind' of train that you always want to create with this
user gesture, you could define a specialization type that describes the
train and its attributes, which would have an IEditHelperAdvice that
would know how to configure the new element. The half adder in the
logic example demonstrates this approach (see
http://help.eclipse.org/help31/topic/org.eclipse.gmf.doc/tut orials/common/Extensible%20Type%20Registry/extensibleTypeReg istryTutorial.html).

If you only need to set some values on-the-fly and don't have a new type
to declare, you could add custom data in your request
(createRequest#getExtendedData()#put()) that can be interpreted by the
train edit helper.


Noelia Rodriguez wrote:
> I checked the example in CreateLogicElementActionDelegate and now I am
> able to create a new object and its view:
>
> IGraphicalEditPart container = (IGraphicalEditPart) editPart.getParent();
> CreateViewRequest createRequest =
> CreateViewRequestFactory.getCreateShapeRequest(YardElementTy pes.Train_2001,
> container.getDiagramPreferencesHint());
> cmd = container.getCommand(createRequest);
>
> I would like to set the attributes value of the new object. Is it
> possible to pass them as parameters in this way of creating the object?
> I checked the constructor getCreateShapeRequest and it seems to be that
> the only parameters that it can take are the IElementType and the
> PreferencesHint. Thank you very much!
>
>
Re: Problems wrapping RecordingCommand [message #539102 is a reply to message #73164] Wed, 09 June 2010 11:54 Go to previous message
Eclipse UserFriend
ty Laughing Laughing
Previous Topic:Change the graphic aspect of an element according to the value of one of its attributes
Next Topic:Migrating to GMF2.2
Goto Forum:
  


Current Time: Tue Apr 29 12:05:56 EDT 2025

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

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

Back to the top