Skip to main content
Jump to: navigation, search

Papyrus/Papyrus Developer Guide/Type Creation

The goal of this page is to explain the architecture and how to add an element in the service creation.

For example, this service provides menu in the model explorer, or element that can be created in the property view. By default, it exists a creation service for UML. Dedicated creation service for profiles can be easily added.


Gmf concepts

The service creation is based on the framework of GMF, see http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r5m0/index.jsp?topic=/com.ibm.xtools.modeler.doc.isv/prog-guide/creating-types.html CreationService.jpg

The pattern has been applied to obtain a creation service for UML.

• The Enumeration UMLElementTypes contains all possible UML types that can be managed.

• A DefaultUMLHelper is associated, it provides a set of commands in order to create them.

• In order to construct menu in the model explorer by using extension point ui.menus (http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm), a set of handlers is added. This set of handler has in charge to call a create command for an element.

• An NamedElementInitializerHelperAdvice has in charge to initialize name of element is also added. For more details, the plugin.xml and the code can be seen in the plugin org.eclipse.papyrus.uml.service.creation http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/branches/0.7.X/plugins/uml/org.eclipse.papyrus.uml.service.creation.

Papyrus adding

By using pattern provided by GMF, several clientContext can be found. In order to find ClientContext used for papyrus and others, a specific matcher has to be associated to this created context. This matcher has to implement IPapyrusContextMatcher. A useful class PapyrusClientContextManager allows finding all context that has a matcher with the type IPapyrusContextMatcher. This class can be used as an entry point to access to all types to know all elements that can be created by papyrus. (used in the property view)

Filter.jpg

Concept of filters

Thanks to this we can create all elements from all IClientContext in papyrus. Creation Menus of model explorer can be displayed if the command can be executed. This is the same function in the property view.

In order to customize papyrus, filters on possible command are needed. An abstract class provides the mechanism of filter see PapyrusEditHelperFilter. By implementing the method valideRequest you can restrict the menu creation

The example http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/branches/0.7.X/examples/org.eclipse.papyrus.examples.restrictedservicecreation provides an example to reduce the creation menu.

This example allows only creation of package or class in a package and properties into a class. This plugin contains a filter that illustrates the implementation of validateRequest() method.

public boolean validateRequest(IEditCommandRequest request) {
		if(request instanceof GetEditContextRequest){
			IEditCommandRequest subrequest= ((GetEditContextRequest)request).getEditCommandRequest();
			if( subrequest instanceof CreateElementRequest){
				
				//allows only creation of class or package into a package
				if(((CreateElementRequest) subrequest).getContainer() instanceof org.eclipse.uml2.uml.Package){
					if(((CreateElementRequest) subrequest).getElementType().equals(UMLElementTypes.CLASS)||
							((CreateElementRequest) subrequest).getElementType().equals(UMLElementTypes.PACKAGE)){
							return true;
					}
				}
				//allows only creation of property into a class
				if(((CreateElementRequest) subrequest).getContainer() instanceof org.eclipse.uml2.uml.Class){
					if(((CreateElementRequest) subrequest).getElementType().equals(UMLElementTypes.PROPERTY)){
							return true;
				}
			}
		}
        }
	return false;
}

Back to the top