-
Notifications
You must be signed in to change notification settings - Fork 133
Image_services
Modelio v4.0
The image service provide icons for a model element, a stereotyped element or a metaclass:
-
the image service interface is
IImageService
. -
the
IImageService
instance can be obtained from theIModuleContext
of the module viaIModelioServices
.
The provided icons are the same as those that appear in the browser. Icons are 24x24 pixels. You do not have to (and must not) dispose the provided images.
The image service can provide three kinds of icons:
-
Element’s icon, with or without decoration
-
Element’s stereotype icon, with or without decoration
Use the getUmlImage(Element, boolean)
service to get the standard image of the model object ignoring the stereotypes owned by the object. The returned image can be decorated with CMS state image depending on the value of the useCmsDecoration
parameter.
The example below gets the UML image of an element with CMS management marks.
1 IModuleContext ctx = MyModule.getInstance().getModuleContext(); 2 IImageService service = ctx.getModelioServices().getImageService(); 3 4 Element elt = ... // A given model element 5 6 boolean withDecoration = true; 7 Image image = service.getUmlImage(elt, withDecoration);
line 1,2: Get the image service from module context and modelio services
line 6: Get the icon for element elt
which is the element’s metaclass icon decorated by its TeamWork status because the withDecoration
flag value is true
. Passing false
returns the undecorated metaclass icon
Use the getStereotypedImage(Element, IPeerModule, boolean)
service to get the stereotyped image of the model object as it appears in the browser. A filter can be specified to display only a stereotype of the given module, the filtering module being passed as a peer.
The example below gets the stereotyped image of an element:
1 IModuleContext ctx = MyModule.getInstance().getModuleContext(); 2 IImageService service = ctx.getModelioServices().getImageService(); 3 4 Element el = ...; // A given model element 5 IJavaDesignerPeerModule filter = ...; // Let suppose JavaDesigner peer is available in the project 6 7 boolean withDecoration = true; 8 9 Image image1 = service.getStereotypedImage(el, null, withDecoration); 10 11 Image image2 = service.getStereotypedImage(el, filter, withDecoration); 12
line 1,2: Get the image service from module context and modelio services
line 5: to use a filter we need a IPeerModule, here we suppose that the JavaDesigner peer module is known
line 9: get the stereotyped icon of elt
unfiltered. This means that the first stereotype with an icon is used, if no such stereotype is found, the method returns the UML image for elt’s metaclass. The `withDecoration
flag indicates if the returned icon is to be decorated by its TeamWork status or not.
line 11: get the stereotyped icon of elt
filtered by the JavaDesigner peer. This means that the first stereotype belonging to the JavaDesigner module having an icon is used, if no such stereotype is found on elt
, the method returns null
. The withDecoration
flag indicates if the returned icon is to be decorated by its TeamWork status or not.
Use the getMetaclassImage(Class<? extends MObject>)
service to get the image of a metaclass Java class.
The example below gets the image of a metaclass.
1 import org.modelio.metamodel.bpmn.activities.BpmnActivity; 2 3 IModuleContext ctx = MyModule.getInstance().getModuleContext(); 4 IImageService service = ctx.getModelioServices().getImageService(); 5 6 IImageService service = ctx.getImageService(); 7 8 Element elt = ...; // A given model element 9 10 11 Image image1 = service.getMetaclassImage(elt.getMClass().getJavaInterface()); 12 Image image2 = service.getMetaclassImage(BpmnActivity.class); 13
line 3,4: Get the image service from module context and modelio services.
line 10: Get the icon for the metaclass of the element elt
. Note how we pass the Java interface corresponding to elt
’s metaclass, which represents the type of elt
and not elt
itself.
line 11: Get the icon for the metaclass corresponding to the Java class BpmnActivity
from the org.modelio.metamodel.bpmn.activities
package.