Gaphor is designed to be extensible by using plugins that allow you to extend the functionality.
The datamodel classes are located in the gaphor.UML
module. Data objects can
be accessed through the ElementFactory. This is a special class for creating and
managing data objects. Items can be queried using this element factory, which is
registered in the application as element_factory
. When writing a service or
plugin the element factory can be injected into the service like this:
class MyThing:
def do_something(self):
element_factory = Application.get_service('element_factory')
items = element_factory.select()
In the console window services can be retrieved by using the service()
function. For example:
ef = service('element_factory')
Two methods are used for querying:
select(query=None)
-> returns an iteratorlselect(query=None)
-> returns a listquery
is a lambda function with the element as parameter. For example, to
fetch all the Class instances from the element factory:
element_factory.select(lambda e: e.isKindOf(UML.Class))
Once some classes are obtained, it is common to traverse through a few related objects in order to get the required information. For example: to iterate through all parameters related to a class’ operations:
for o in classes.ownedOperation:
for p in o.ownedParameter:
do_something(p)
Using the [:]
operator items can be traversed more easily:
for o in classes.ownedOperation[:].ownedParameter:
do_something(p)
An example Hello World plugin is hosted on GitHub.