Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Adding a Block under Package with Eclipse EMF programatically
Adding a Block under Package with Eclipse EMF programatically [message #1850086] Tue, 15 February 2022 13:04 Go to next message
Chaitali Agarwal is currently offline Chaitali AgarwalFriend
Messages: 3
Registered: February 2022
Junior Member
Hi,

I am very new to EMF as a whole but I'll try to explain as expressively as I can.
I have a project that uses SysML Profiles and is built on top of Eclipse papyrus EMF APIs. What I want to achieve is to be able to add a block under a package programmatically. I understand a write Transaction needs to be started to achieve this.
Any helps on how to get started with Write Transactions, which commands to use for this, etc. will be very appreciated.
Re: Adding a Block under Package with Eclipse EMF programatically [message #1850095 is a reply to message #1850086] Tue, 15 February 2022 16:24 Go to previous messageGo to next message
Thomas Wiman is currently offline Thomas WimanFriend
Messages: 83
Registered: June 2012
Location: Stockholm , Sweden
Member

This should do the trick:

import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.util.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Stereotype;

...
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(yourPackage);
domain.getCommandStack().execute(new RecordingCommand(domain, "Create a block", "Some description...") {
	@Override
	protected void doExecute() {
		Class yourBlock = yourPackage.createOwnedClass("yourBlockName", false);
		Stereotype blockStereotype = block.getApplicableStereotype("SysML::Blocks::Block");
		yourBlock.applyStereotype(blockStereotype);
	}
});


/Thomas


Thomas Wiman
MetaModelAgent Product Manager
Re: Adding a Block under Package with Eclipse EMF programatically [message #1851690 is a reply to message #1850086] Tue, 12 April 2022 13:59 Go to previous message
Chaitali Agarwal is currently offline Chaitali AgarwalFriend
Messages: 3
Registered: February 2022
Junior Member
Thanks!
Previous Topic:Validation plug-in does not use profile stereotype classes when validating model (Solved)
Next Topic:Unable to generate Sequence Diagram from source code
Goto Forum:
  


Current Time: Thu Apr 25 09:11:53 GMT 2024

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

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

Back to the top