[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: how can I get the reference to the element that I have just created by executing a command?

Hi Sylvain,

thank you for your answer but I have not been able to apply the MindMap 
example to my case.

Reading the MindMap tutorial, I guessed that after creating the request and 
getting the command, by this code:

        EditPartViewer viewer = selectedElement.getViewer();
        EditPart elementPart = (EditPart) 
viewer.getEditPartRegistry().get(topicViewAdapter.getAdapter(View.class));

the elementPart variable would be referencing to the EditPart of the new 
element (the one created by executing the command).

I have tryed to adapted this example to my case, but the elementPart is 
null. My code has been included in the handleNotificationEvent-method of the 
ProductRequirementEditPart-class, since a new ProductRequirement is created 
programmatically when a specific event happens. It is as follows:

    ...

    IElementType type = ParamMMElementTypes.ProductRequirement_1001;


    ViewAndElementDescriptor viewDescriptor = new 
ViewAndElementDescriptor(new CreateElementRequestAdapter(new 
CreateElementRequest(type)),

         Node.class,

        ((IHintedType) type).getSemanticHint(),

         this.getDiagramPreferencesHint());


    CreateViewAndElementRequest request = new 
CreateViewAndElementRequest(viewDescriptor);


    Command command = catalog.getCommand(request);


    IAdaptable viewAdapter = (IAdaptable) ((List) 
request.getNewObject()).get(0);


    this.getDiagramEditDomain().getDiagramCommandStack().execute(command);


    EditPartViewer viewer = this.getViewer();

    EditPart elementPart = (EditPart) 
viewer.getEditPartRegistry().get(viewAdapter.getAdapter(View.class));

Do you know what is wrong in this code? Probably there is something that I 
did not understand from the tutorial.

Best regards,
            Begoña


"sylvain ladoux" <sylvain.ladoux@xxxxxxxx> escribió en el mensaje 
news:fd0qv1$5ko$1@xxxxxxxxxxxxxxxxxxxx
> Begoa Moros wrote:
>
>> Hi all,
>>
>> after creating a new element as it is explained by tip 1 in
>> http://wiki.eclipse.org/GMF_Tips, is it possible to get the reference to
>> the
>> element that has been created?  I need to achieve this in order to
>> properly initialize the new element since the default initialization it 
>> is
>> not enough in this case.
>>
>> Thanks in advance for any hint!!
>
> Hi Begoa
>
> Look at Custom Actions in the MindMap tutorial.
> http://wiki.eclipse.org/GMF_Tutorial_Part_3
>
> Best regards,
> Sylvain
>