| | 22 | |
|---|
| | 23 | |
|---|
| | 24 | class UMLAssociation(gtk.ListStore): |
|---|
| | 25 | """ |
|---|
| | 26 | UML association GTK model. |
|---|
| | 27 | """ |
|---|
| | 28 | def __init__(self, data): |
|---|
| | 29 | """ |
|---|
| | 30 | Create GTK model from UML association. |
|---|
| | 31 | |
|---|
| | 32 | Parameters: |
|---|
| | 33 | |
|---|
| | 34 | data: iterator of UML properties |
|---|
| | 35 | """ |
|---|
| | 36 | super(UMLAssociation, self).__init__(str, object) |
|---|
| | 37 | for item in data: |
|---|
| | 38 | self.append([item.render(), item]) |
|---|
| | 39 | self.append(['', None]) |
|---|
| | 40 | |
|---|
| | 41 | |
|---|
| | 42 | def remove(self, iter): |
|---|
| | 43 | """ |
|---|
| | 44 | Remove item from GTK model and destroy it. |
|---|
| | 45 | """ |
|---|
| | 46 | item = self[iter][1] |
|---|
| | 47 | if item: |
|---|
| | 48 | item.unlink() |
|---|
| | 49 | super(UMLAssociation, self).remove(iter) |
|---|
| | 50 | |
|---|
| | 51 | |
|---|
| | 52 | def remove_on_keypress(tree, event): |
|---|
| | 53 | """ |
|---|
| | 54 | Remove selected items from GTK model on ``backspace`` keypress. |
|---|
| | 55 | """ |
|---|
| | 56 | k = gtk.gdk.keyval_name(event.keyval).lower() |
|---|
| | 57 | if k == 'backspace': |
|---|
| | 58 | model, iter = tree.get_selection().get_selected() |
|---|
| | 59 | if iter: |
|---|
| | 60 | model.remove(iter) |
|---|
| | 61 | |
|---|
| 270 | | attributes = gtk.ListStore(str, object) |
|---|
| 271 | | |
|---|
| 272 | | for attribute in self.context.subject.ownedAttribute: |
|---|
| 273 | | if not attribute.association: |
|---|
| 274 | | attributes.append([attribute.render(), attribute]) |
|---|
| 275 | | attributes.append(['', None]) |
|---|
| 276 | | |
|---|
| | 310 | attrs = self.context.subject.ownedAttribute |
|---|
| | 311 | attributes = UMLAssociation(a for a in attrs if not a.association) |
|---|
| | 312 | |
|---|