Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create Connection between two Nodes programmatically (newbie)
Create Connection between two Nodes programmatically (newbie) [message #212495] Sat, 29 November 2008 16:58 Go to next message
Eclipse UserFriend
Originally posted by: descipar.gmail.com

Hello all!
I guess this is really a newbie question, but sadly I can`t get it to
work on my own. :(

I want to create a connection between to 2 Nodes which are created
briefly before.
Node creation works fine, but i`m stuck with the connection part

My Code to create a Node looks like this:

CreationTool tool = new CreationTool(
GridConfigurationElementTypes.Building_2003);
CreateViewAndElementRequest req =
(CreateViewAndElementRequest)tool.createCreateRequest();
CreateViewAndOptionallyElementCommand createCmd =
new CeateViewAndOptionallyElementCommand(
req.getViewAndElementDescriptor().getElementAdapter(),
(GridConfigurationEditPart) selection.getFirstElement(),
null, req.getViewAndElementDescriptor()
.getPreferencesHint());
ICommandProxy cmdProxy = new ICommandProxy(createCmd);
cmdProxy.execute();

This is executed for nodes and then I tried to create a connection like
this:

Command createCMD3 = CreateConnectionViewAndElementRequest
.getCreateCommand(
GridConfigurationElementTypes.BuildingSmartMeterRelation_400 1,
sourceEditPart, targetEditPart); createCMD3.execute();

The part which I do not know, is how to get the sourceEditPart and
targetEditPart.
I would guess it is fairly simple...

Hope someone can help me!

Thanks,
Kai
Re: Create Connection between two Nodes programmatically (newbie) [message #212497 is a reply to message #212495] Sun, 30 November 2008 12:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: descipar.gmail.com

Nobody a clue how to get this done?

Any advise is appreciated...
And sorry for posting twice, but this is quite important for me.

Thanks again

Kai Schulte wrote:
> Hello all!
> I guess this is really a newbie question, but sadly I can`t get it to
> work on my own. :(
>
> I want to create a connection between to 2 Nodes which are created
> briefly before.
> Node creation works fine, but i`m stuck with the connection part
>
> My Code to create a Node looks like this:
>
> CreationTool tool = new CreationTool(
> GridConfigurationElementTypes.Building_2003);
> CreateViewAndElementRequest req =
> (CreateViewAndElementRequest)tool.createCreateRequest();
> CreateViewAndOptionallyElementCommand createCmd =
> new CeateViewAndOptionallyElementCommand(
> req.getViewAndElementDescriptor().getElementAdapter(),
> (GridConfigurationEditPart) selection.getFirstElement(),
> null, req.getViewAndElementDescriptor()
> .getPreferencesHint());
> ICommandProxy cmdProxy = new ICommandProxy(createCmd);
> cmdProxy.execute();
>
> This is executed for nodes and then I tried to create a connection like
> this:
>
> Command createCMD3 = CreateConnectionViewAndElementRequest
> .getCreateCommand(
> GridConfigurationElementTypes.BuildingSmartMeterRelation_400 1,
> sourceEditPart, targetEditPart); createCMD3.execute();
>
> The part which I do not know, is how to get the sourceEditPart and
> targetEditPart.
> I would guess it is fairly simple...
>
> Hope someone can help me!
>
> Thanks,
> Kai
Re: Create Connection between two Nodes programmatically (newbie) [solved] [message #212554 is a reply to message #212497] Mon, 01 December 2008 12:20 Go to previous message
Eclipse UserFriend
Originally posted by: descipar.gmail.com

Solved it. I guess not really in a fine way, but it works.

I put the corresponding code here in case someone has the same problem.

Kai

-------
/*
* Getting the current EditPart. Should always be the last one.
* After creating the Node
*/
BuildingEditPart buildingEditPart = null;
ListIterator buildingIte = buildingGridEditPart.getTargetEditPart(
buildingRequest).getChildren().listIterator();
while (buildingIte.hasNext()) {
EditPart editPart = (EditPart) buildingIte.next();
if (buildingIte.hasNext() == false) {
buildingEditPart = (BuildingEditPart) editPart;
}
}

/*
* Create connection
*/

IElementType buildingSmartMeterElementType =
GridConfigurationElementTypes.BuildingSmartMeterRelation_400 1;
CreateConnectionViewAndElementRequest
buildingSmartMeterRequest = new CreateConnectionViewAndElementRequest(
buildingSmartMeterElementType,
((IHintedType) buildingSmartMeterElementType)
.getSemanticHint(), PreferencesHint.USE_DEFAULTS);
Command buildingSmartMeterCmd = buildingSmartMeterRequest
.getCreateCommand(buildingSmartMeterRequest,
buildingEditPart, smartMeterEditPart);
buildingSmartMeterCmd.execute();


Kai Schulte wrote:
> Nobody a clue how to get this done?
>
> Any advise is appreciated...
> And sorry for posting twice, but this is quite important for me.
>
> Thanks again
>
> Kai Schulte wrote:
>> Hello all!
>> I guess this is really a newbie question, but sadly I can`t get it to
>> work on my own. :(
>>
>> I want to create a connection between to 2 Nodes which are created
>> briefly before.
>> Node creation works fine, but i`m stuck with the connection part
>>
>> My Code to create a Node looks like this:
>>
>> CreationTool tool = new CreationTool(
>> GridConfigurationElementTypes.Building_2003);
>> CreateViewAndElementRequest req =
>> (CreateViewAndElementRequest)tool.createCreateRequest();
>> CreateViewAndOptionallyElementCommand createCmd =
>> new CeateViewAndOptionallyElementCommand(
>> req.getViewAndElementDescriptor().getElementAdapter(),
>> (GridConfigurationEditPart) selection.getFirstElement(),
>> null, req.getViewAndElementDescriptor()
>> .getPreferencesHint());
>> ICommandProxy cmdProxy = new ICommandProxy(createCmd);
>> cmdProxy.execute();
>>
>> This is executed for nodes and then I tried to create a connection
>> like this:
>>
>> Command createCMD3 = CreateConnectionViewAndElementRequest
>> .getCreateCommand(
>> GridConfigurationElementTypes.BuildingSmartMeterRelation_400 1,
>> sourceEditPart, targetEditPart); createCMD3.execute();
>>
>> The part which I do not know, is how to get the sourceEditPart and
>> targetEditPart.
>> I would guess it is fairly simple...
>>
>> Hope someone can help me!
>>
>> Thanks,
>> Kai
Previous Topic:Target Decoration of Polyline Connection
Next Topic:TopDownCompositeLayout zoom level bugs
Goto Forum:
  


Current Time: Sat Jun 07 06:37:03 EDT 2025

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

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

Back to the top