Skip to main content
Jump to: navigation, search

Difference between revisions of "Papyrus/Papyrus Developer Guide/Type Creation"

 
(21 intermediate revisions by one other user not shown)
Line 1: Line 1:
The goal of this page is to explain the architecture and how to add element in the service 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 th model explorer, or element that can be created in the property view.
+
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. But we can imagine to add service for dedicated profiles.
+
By default, it exists a creation service for UML. Dedicated creation service for profiles can be easily added.
 +
 
 +
 
 +
== Gmf concepts ==
  
== Architecture  ==
 
 
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
 
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
 +
[[Image: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)
 +
 +
[[Image: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.
  
== How to add element in the service creation ==
+
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.
 +
<pre>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;
 +
}
  
== How to configure==
+
</pre>

Latest revision as of 04:09, 26 January 2018

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