[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: Create Connection between two Nodes programmatically (newbie) [solved]

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_4001;
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_4001,
    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