Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » create a node and a link programmatically
create a node and a link programmatically [message #155266] Mon, 15 October 2007 11:02 Go to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Hi all,

In the "Custom Action", in the third part of the GMF tutorial
(http://wiki.eclipse.org/GMF_Tutorial_Part_3#Custom_Actions), a new Subtopic
node and a new Link (from the selected Topic to the new Subtopic) are
created. Following the example, I have been trying to do the same thing with
no success. In my case, the node is created but the link is not.

I also have tryed to create the link by means of
CreateViewAndElementRequest.getCreateCommand. In this case, the link is
graphically shown but the model lement is not created.

I do not know what other command or approach I can use.

I have been stuck on this stuff for some weeks, please, can anybody help
me??

Best regards,
Bego
Re: create a node and a link programmatically [message #155315 is a reply to message #155266] Mon, 15 October 2007 11:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

We are in the same boat Begoña :) I have also been working on this for a
few weeks.

I successfully create node and link, the part that creates the link
looks like this in my case:

IElementType linkType = UemlbaseElementTypes.Class_SubclassRelation_4001;
CreateConnectionViewAndElementRequest connectionRequest = new
CreateConnectionViewAndElementRequest( linkType, ((IHintedType)
linkType).getSemanticHint(), selectedElement.getDiagramPreferencesHint());

ICommand createSubClassLinkCmd = new
DeferredCreateConnectionViewAndElementCommand(connectionRequ est,
shapeViewAdapter, new EObjectAdapter((EObject)
selectedElement.getModel()), selectedElement.getViewer());

Does this help?

If any one else is reading this, I really need help in "catching" the
newly created link/connection object.

Regards,

Tomas


Begoña Moros wrote:
> Hi all,
>
> In the "Custom Action", in the third part of the GMF tutorial
> (http://wiki.eclipse.org/GMF_Tutorial_Part_3#Custom_Actions), a new Subtopic
> node and a new Link (from the selected Topic to the new Subtopic) are
> created. Following the example, I have been trying to do the same thing with
> no success. In my case, the node is created but the link is not.
>
> I also have tryed to create the link by means of
> CreateViewAndElementRequest.getCreateCommand. In this case, the link is
> graphically shown but the model lement is not created.
>
> I do not know what other command or approach I can use.
>
> I have been stuck on this stuff for some weeks, please, can anybody help
> me??
>
> Best regards,
> Begoña
>
>
Re: create a node and a link programmatically [message #155400 is a reply to message #155315] Mon, 15 October 2007 14:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Tomas, I do not understand!! My code is the same as yours (you can look at
it below). First, I create a new node (ProductRequirement in my case) and
then the link (DependenceTrace) between the current element, that is the
current ProductRequirement (my code is in the
ProductRequirementEditPart#handleNotificationEvent method) and the new
ProductRequirement. The only thing different is that I use "this" (to refer
to the current ProductRequirement) instead of "selectedElement".

What is the type of selecteElement in your case?

CompoundCommand commands = new CompoundCommand();

// types to be
reated --------------------------------------------------------


IElementType nodeType = ParamMMElementTypes.ProductRequirement_1001;

IElementType traceType = ParamMMElementTypes.DependenceTrace_3001;

// create the node --------------------------------------------------------


CreateViewRequest nodeRequest =
CreateViewRequestFactory.getCreateShapeRequest(

nodeType,

this.getDiagramPreferencesHint());

commands.add(catalogEditPart.getCommand(nodeRequest));



// create the trace --------------------------------------------------------


CreateConnectionViewAndElementRequest createTraceRequest = new
CreateConnectionViewAndElementRequest(


traceType,


((IHintedType)
traceType).getSemanticHint(),


this.getDiagramPreferencesHint());

// Source of the link: this, the current element

IAdaptable sourceViewAdapter = new EObjectAdapter((EObject)
this.getModel());


//Target of the link: the new created Requirement

IAdaptable targetViewAdapter = (IAdaptable) ((List)
nodeRequest.getNewObject()).get(0);


ICommand createTraceCmd = new DeferredCreateConnectionViewAndElementCommand(

createTraceRequest,

sourceViewAdapter,

targetViewAdapter,

this.getViewer());




commands.add(new ICommandProxy(createTraceCmd));


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



"Tomas Zijdemans" <trommas@yahoo.com> escribi
Re: create a node and a link programmatically [message #155414 is a reply to message #155400] Mon, 15 October 2007 15:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

> What is the type of selecteElement in your case?

It is ClassNodeEditPart.

I have to go now, but I'll be able to assist tomorrow. You can just
email me if you want

Regards,

Tomas
Re: create a node and a link programmatically [message #155423 is a reply to message #155414] Mon, 15 October 2007 15:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Did you have to install any EditPolicy in the XXXEditPart in order to create
the link by CreateConnectionViewAndElementRequest properly?


"Tomas Zijdemans" <trommas@yahoo.com> escribi
Re: create a node and a link programmatically [message #155476 is a reply to message #155423] Mon, 15 October 2007 19:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

No, I have not done anything with the EditPolicies.


Tomas


Begoña Moros wrote:
> Did you have to install any EditPolicy in the XXXEditPart in order to create
> the link by CreateConnectionViewAndElementRequest properly?
>
>
> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
> news:ff01ej$gmn$1@build.eclipse.org...
>>> What is the type of selecteElement in your case?
>> It is ClassNodeEditPart.
>>
>> I have to go now, but I'll be able to assist tomorrow. You can just email
>> me if you want
>>
>> Regards,
>>
>> Tomas
>
>
Re: create a node and a link programmatically [message #155508 is a reply to message #155423] Tue, 16 October 2007 07:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Maybe you could send me your code?

I will compare it to mine, and see if I can solve your problem.

Regards,

Tomas

Begoña Moros wrote:
> Did you have to install any EditPolicy in the XXXEditPart in order to create
> the link by CreateConnectionViewAndElementRequest properly?
>
>
> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
> news:ff01ej$gmn$1@build.eclipse.org...
>>> What is the type of selecteElement in your case?
>> It is ClassNodeEditPart.
>>
>> I have to go now, but I'll be able to assist tomorrow. You can just email
>> me if you want
>>
>> Regards,
>>
>> Tomas
>
>
Re: create a node and a link programmatically [message #155574 is a reply to message #155508] Tue, 16 October 2007 10:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Tomas thank you very much for your time!!

My code is part of the handleNotificationEvent in ProductRequirementEditPart
class. What I want to do is create a new ProductRequirement (my node) and
link it (by means of a TraceDependence) to the current ProductRequirement
(the one that has changed some way).

My code is as follows:

CompoundCommand commands = new CompoundCommand();


IElementType reqType = ParamMMElementTypes.ProductRequirement_1001;

IElementType traceType = ParamMMElementTypes.DependenceTrace_3001;


// create the node. This
works!! --------------------------------------------------------

CreateViewRequest reqRequest =
CreateViewRequestFactory.getCreateShapeRequest(


reqType,


this.getDiagramPreferencesHint());

commands.add(catalogEditPart.getCommand(reqRequest));


// create the trace. Nothing
happens!!! --------------------------------------------------------


CreateConnectionViewAndElementRequest createTraceRequest = new
CreateConnectionViewAndElementRequest(


traceType,


((IHintedType) traceType).getSemanticHint(),


this.getDiagramPreferencesHint());

// Source of the link: this, the current element

IAdaptable sourceViewAdapter = new EObjectAdapter((EObject)
this.getModel());


//Target of the link: the new created Requirement

IAdaptable targetViewAdapter = (IAdaptable) ((List)
reqRequest.getNewObject()).get(0);


ICommand createTraceCmd = new DeferredCreateConnectionViewAndElementCommand(

createTraceRequest,

sourceViewAdapter,

targetViewAdapter,

this.getViewer());


commands.add(new ICommandProxy(createTraceCmd));


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

Best regards,
Bego
Re: create a node and a link programmatically [message #155700 is a reply to message #155574] Tue, 16 October 2007 11:28 Go to previous message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

No prob :) Our codes are quite different, but here is what I think your
code should look like:

///////////////////

private ProductRequirementEditPart selectedElement;

public void run(IAction action) {

CompoundCommand commands = new CompoundCommand();

IElementType reqType = ParamMMElementTypes.ProductRequirement_1001;

IElementType traceType = ParamMMElementTypes.DependenceTrace_3001;

CreateViewRequest reqRequest =
CreateViewRequestFactory.getCreateShapeRequest(
reqType,
selectedElement.getDiagramPreferencesHint());

// Get the Adapter to the newly created object
shapeViewAdapter = (IAdaptable) ((List) reqRequest.getNewObject()).get(0);

commands.add(catalogEditPart.getCommand(reqRequest));

selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc);

CreateConnectionViewAndElementRequest createTraceRequest = new
CreateConnectionViewAndElementRequest(
traceType,
((IHintedType)
traceType).getSemanticHint(),

selectedElement.getDiagramPreferencesHint());

ICommand createTraceCmd = new DeferredCreateConnectionViewAndElementCommand(

createTraceRequest, shapeViewAdapternew EObjectAdapter((EObject)
selectedElement.getModel()), selectedElement.getViewer());


// Setup link compound command
CompoundCommand cc2 = new CompoundCommand("Create connection");
cc2.add(new ICommandProxy(createTraceCmd));

selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cc2);

}

public void selectionChanged(IAction action, ISelection selection) {
selectedElement = null;

if (selection instanceof IStructuredSelection) { IStructuredSelection
structuredSelection = (IStructuredSelection) selection;

if (structuredSelection.getFirstElement() instanceof
ProductRequirementEditPart) {
selectedElement = (ProductRequirementEditPart)
structuredSelection.getFirstElement();
}
}
}

///////////////////

Puh! I think that should work. I may be traveling to Spain (that is
where you come from, right?) this spring to collect data for my master
thesis. Looking forward to it (Norway is cold!)

Hope this helps,

Toams
Previous Topic:Location Format>line color>Red extension pt
Next Topic:Element's attributes that don't show up into the model file (XMI)
Goto Forum:
  


Current Time: Thu Jul 25 18:47:14 GMT 2024

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

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

Back to the top