| 1 |
from zope import interface, component |
|---|
| 2 |
|
|---|
| 3 |
from gaphor.diagram import items |
|---|
| 4 |
from gaphor.diagram.interfaces import IGroup |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
class AbstractGroup(object): |
|---|
| 41 |
""" |
|---|
| 42 |
Base class for grouping of UML objects. |
|---|
| 43 |
|
|---|
| 44 |
Attributes: |
|---|
| 45 |
- parent: parent item |
|---|
| 46 |
- item: item to be part of parent item |
|---|
| 47 |
""" |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
interface.implements(IGroup) |
|---|
| 52 |
|
|---|
| 53 |
def __init__(self, parent, item): |
|---|
| 54 |
self.parent = parent |
|---|
| 55 |
self.item = item |
|---|
| 56 |
|
|---|
| 57 |
def can_contain(self): |
|---|
| 58 |
raise NotImplemented, 'This is abstract class' |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
def group(self): |
|---|
| 62 |
raise NotImplemented, 'This is abstract class' |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
from gaphor.diagram import DiagramItemMeta |
|---|
| 67 |
class InteractionLifelineGroup(AbstractGroup): |
|---|
| 68 |
""" |
|---|
| 69 |
Add lifeline to interaction. |
|---|
| 70 |
""" |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
def pre_can_contain(self): |
|---|
| 74 |
return isinstance(self.parent, items.InteractionItem) \ |
|---|
| 75 |
and issubclass(self.item, items.LifelineItem) |
|---|
| 76 |
|
|---|
| 77 |
def can_contain(self): |
|---|
| 78 |
return isinstance(self.parent, items.InteractionItem) \ |
|---|
| 79 |
and isinstance(self.item, items.LifelineItem) |
|---|
| 80 |
|
|---|
| 81 |
def group(self): |
|---|
| 82 |
self.parent.subject.lifeline = self.item.subject |
|---|
| 83 |
self.parent.canvas.reparent(self.item, self.parent) |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
def ungroup(self): |
|---|
| 88 |
del self.parent.subject.lifeline[self.item.subject] |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
component.provideAdapter(factory=InteractionLifelineGroup, |
|---|
| 92 |
adapts=(items.InteractionItem, DiagramItemMeta)) |
|---|
| 93 |
component.provideAdapter(factory=InteractionLifelineGroup, |
|---|
| 94 |
adapts=(items.InteractionItem, items.LifelineItem)) |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
class ComponentClassGroup(AbstractGroup): |
|---|
| 98 |
""" |
|---|
| 99 |
Add class to component. |
|---|
| 100 |
""" |
|---|