Adding Association and Dependency to BDD Programmatically [message #1807284] |
Mon, 27 May 2019 13:17 |
Dylan Trenti Messages: 7 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 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03038 seconds