Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to create UML elements from own popupactions
How to create UML elements from own popupactions [message #632249] Tue, 12 October 2010 09:38 Go to next message
Wladimir Schamai is currently offline Wladimir SchamaiFriend
Messages: 53
Registered: May 2010
Dear Papyrus developers,

I am trying to creat a popup action for the Papyrus model browser popup menu that will create a UML Class and apply a stereotype to it. In the old Papyrus version we used the extension point org.eclipse.ui.popupMenus and actions (see below) that enables the menu based on the meta class (e.g. objectState name="isUmlType" value="Class"):
               label="Modelica Class"
               tooltip="Add new Modelica Class">

This is the code for the class that creates the element in the old Papyrus version:
package com.eadsiw.modelicaml.popupactions;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.notify.impl.NotificationImpl;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
import org.eclipse.uml2.uml.Stereotype;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;
import com.cea.papyrus.core.editor.CommandStackUtils;
import org.eclipse.emf.common.notify.Notification;
import com.eadsiw.modelicaml.Activator;

 * Implementation class for ClassAction action
public class CreateModelicaClassAction extends Action {
	private org.eclipse.uml2.uml.Element selectedElement = null;

	private String stereotypPath = Platform.getResourceString(Activator.getDefault().getBundle(), "%p_path_ModelicaClassConstructs");

	private String stereotypName = Platform.getResourceString(Activator.getDefault().getBundle(), "%s_class");
	protected com.cea.papyrus.core.commands.PapyrusCommand papyrusCommand;

	 * (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	public void run(IAction action) {
		// get CommandStack
		CommandStack stack = (CommandStack) CommandStackUtils.getCommandStack();

		selectedElement = (org.eclipse.uml2.uml.Element) (getSelectedEObject()

		// create new class
		UMLElementCreateCommand papyrusCommand = new UMLElementCreateCommand(
				org.eclipse.uml2.uml.Class.class, selectedElement);
		org.eclipse.uml2.uml.Class clazz = (org.eclipse.uml2.uml.Class) papyrusCommand
		// apply ModelicaML Model Stereotyp to Class
		Stereotype stereotype = clazz
		if (stereotype==null) {
			Shell shell = new Shell();
			MessageDialog.openError(shell, "Error:", "Cannot apply the stereotype. You need to apply the ModelicaML profile to the model/package.");
		else {
		//clazz.eNotify(new NotificationImpl(Notification.SET, null, null)); // this is still buggy. Papyrus don't get the "model is dirty" notification after the element was added to the model.

	public void init(IViewPart view) {
		// TODO Auto-generated method stub


What is the best way to do it in the new Papyrus version?

Thanks for your support!!
Re: How to create UML elements from own popupactions [message #634005 is a reply to message #632249] Wed, 20 October 2010 09:09 Go to previous message
Remi Schnekenburger is currently offline Remi SchnekenburgerFriend
Messages: 168
Registered: July 2009
Location: Palaiseau, France
Senior Member
Hi Wladimir,

you could look in the plugins org.eclipse.papyrus.sysml.modelexplorer and org.eclipse.papyrus.sysml.service.types to see how we create SysML blocks directly from the model explorer, in the menu "create new child" etc.

Otherwise, there are many actions placed on the model explorer. For example, look into the org.eclipse.papyrus.uml.modelexplorer plugin.

The code you propose as an implementation of an action should take care of the fact that Papyrus as migrate to GMF and EMF Transaction.
Thus, it requires to encapsulate commands in a transaction, otherwise, you will have a read/write exception when modifying the model.
I invite you to read the documentation of EMF Transaction project.


Remi Schnekenburger

Get professional Eclipse developer support:
Previous Topic:Cannot install nightly build
Next Topic:Generalization strange behaviour
Goto Forum:

Current Time: Thu Jul 09 21:22:50 GMT 2020

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

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

Back to the top