|
|
|
Re: Create Papyrus diagram programmatically [message #1748102 is a reply to message #1748100] |
Fri, 18 November 2016 13:54 |
|
If you create an element using the UML factory, the element is not associated with any resource. You need to add it to an element of the created model first (e.g. if you already have an existing package or model, you need to call
org.eclipse.uml2.uml.Package root = (org.eclipse.uml2.uml.Package) umlModel.lookupRoot();
root.getPackagedElements().add(new element);
(btw. I don't think, you can directly add a sequenceNode to a package).
|
|
|
|
Re: Create Papyrus diagram programmatically [message #1748245 is a reply to message #1748109] |
Mon, 21 November 2016 15:00 |
|
Hi Ismael,
I know I tried to do something alike some time ago and here is what I came up with.
// Create the new Component diagram associated to the newly created package
Collection<ViewPrototype> availablePrototypes = PolicyChecker.getCurrent().getPrototypesFor(newContextPackage);
for (ViewPrototype viewPrototype : availablePrototypes) {
if (viewPrototype.getLabel().equals(UML_COMPONENT_DIAGRAM)) {
viewPrototype.instantiateOn(newContextPackage, decomposeDialog.getDiagramName());
}
}
// Create the package used to populate the new diagram, rename
final CreateElementRequest requestFunctionPackage = new CreateElementRequest(currentDomain, newContextPackage,
ElementTypeRegistry.getInstance().getType(ORG_ECLIPSE_PAPYRUS_UML_PACKAGE));
IElementEditService providerFunctionPackage = ElementEditServiceUtils.getCommandProvider(newContextPackage);
ICommand createGMFCommandFunctionPackage = providerFunctionPackage.getEditCommand(requestFunctionPackage);
final Command emfCommandFunctionPackage = GMFtoEMFCommandWrapper.wrap(createGMFCommandFunctionPackage);
currentDomain.getCommandStack().execute(emfCommandFunctionPackage);
final EObject newFunctionPackage = requestFunctionPackage.getNewElement();
RenameElementCommand renameFunctionPackageCommand = new RenameElementCommand(currentDomain,
(NamedElement) UMLUtil.resolveUMLElement(newFunctionPackage), decomposeDialog.getFunctionName());
renameFunctionPackageCommand.execute();
Then you have to drop the newly created package/element in the new diagram.
HTH
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05040 seconds