Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Adding Association and Dependency to BDD Programmatically(Need to add Association and Dependency to an existing Block Definition Diagram by code)
Adding Association and Dependency to BDD Programmatically [message #1807284] Mon, 27 May 2019 13:17 Go to next message
Dylan Trenti is currently offline Dylan TrentiFriend
Messages: 6
Registered: March 2019
Junior Member
Hi everyone,

I am working on a project which requires to add associations and dependencies between Blocks in a BDD programmatically.

Here is what I already have:
- Existing BDD
- List of information about elements to add:
(Starting block, Ending block, type[Dependency or Association])

I tried to create an association manually than I got the diagram content and tried to perform reverse engineering on it in order to understand how it is made, but I can't figure out a way to generate one programmatically

UPDATES: 28/05/2019
I figured out how to create a Dependency but I can't actually display it into my existing diagram... I tried to do something similar to adding blocks as following


  
CompoundCommand completeCmd = new CompoundCommand("Show Elements Command");

final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(diagram);
domain.getCommandStack().execute(new GEFtoEMFCommandWrapper(completeCmd));

.... //Adding Blocks here

completeCmd = new CompoundCommand("Show Elements Command");

// Third loop to draw Dependencies FIXME
for (Element element : packageChildren) {
	if (element instanceof Dependency) {
		final Command cmd = showElementIn(element, diagramEP, 1);
		if (cmd != null && cmd.canExecute()) {
			completeCmd.add(cmd);
		}
	}
}
		
// Execute the commands
domain.getCommandStack().execute(new GEFtoEMFCommandWrapper(completeCmd));



Actually I still can't find a way to create associations...

END UPDATE

can someone provide me a way to do that?

thank you

Dylan

[Updated on: Tue, 28 May 2019 12:49]

Report message to a moderator

Re: Adding Association and Dependency to BDD Programmatically [message #1807552 is a reply to message #1807284] Mon, 03 June 2019 08:32 Go to previous messageGo to next message
Nicolas FAUVERGUE is currently offline Nicolas FAUVERGUEFriend
Messages: 47
Registered: February 2014
Member
Hi,

You will find some code to manage associations. This code comes from the tests plug-ins of papyrus :

Create an association (graphically) (source and target are edit parts of elements to associate):
IElementType type = UMLDIElementTypes.ASSOCIATION_DIRECTED_EDGE;

CreateConnectionViewRequest connectionRequest = CreateViewRequestFactory.getCreateConnectionRequest(type, ((IGraphicalEditPart) getDiagramEditPart()).getDiagramPreferencesHint());
connectionRequest.setSourceEditPart(null);
connectionRequest.setTargetEditPart(source);
		connectionRequest.setType(RequestConstants.REQ_CONNECTION_START);
source.getCommand(connectionRequest);
connectionRequest.setSourceEditPart(source);
connectionRequest.setTargetEditPart(target);
		connectionRequest.setType(RequestConstants.REQ_CONNECTION_END);

Command endCommand = target.getCommand(connectionRequest);
Display.getDefault().syncExec(new Runnable() {

	@Override
	public void run() {
		getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(endCommand));
	}
});


Code to drop an element of model into diagram :
DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
ArrayList<Element> list = new ArrayList<Element>();
list.add(association);
dropObjectsRequest.setObjects(list);
dropObjectsRequest.setLocation(new Point(20, 20));

DiagramEditPart diagramEditPart = getDiagramEditPart();

Command command = diagramEditPart.getCommand(dropObjectsRequest);
Display.getDefault().syncExec(new Runnable() {

	@Override
	public void run() {
		getCommandStack().execute(GEFtoEMFCommandWrapper.wrap(command));
	}
});


HTH,
Nicolas
Re: Adding Association and Dependency to BDD Programmatically [message #1807598 is a reply to message #1807552] Tue, 04 June 2019 12:51 Go to previous message
Dylan Trenti is currently offline Dylan TrentiFriend
Messages: 6
Registered: March 2019
Junior Member
Hi

Thank you very much, I finally solved my issue

Dylan
Previous Topic:Loop Nodes in Activity diagrams
Next Topic:Bug on adding a Stereotype on a Message?
Goto Forum:
  


Current Time: Mon Dec 16 02:20:17 GMT 2019

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

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

Back to the top