Changeset 2246
- Timestamp:
- 03/03/08 23:40:52 (2 months ago)
- Files:
-
- gaphor/trunk/gaphor/UML/properties.py (modified) (2 diffs)
- gaphor/trunk/gaphor/UML/tests/test_properties.py (modified) (2 diffs)
- gaphor/trunk/utils/command/gen_uml.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/UML/properties.py
r2140 r2246 569 569 """ 570 570 Redefined association 571 Element.x = redefine('x', Class, Element.assoc)571 Element.x = redefine('x', Element, Class, Element.assoc) 572 572 If the redefine eclipses the original property (it has the same name) 573 573 it ensures that the original values are saved and restored. 574 574 """ 575 575 576 def __init__(self, name, type, original): 576 def __init__(self, decl_class, name, type, original): 577 self.decl_class = decl_class 577 578 self.name = intern(name) 578 579 self._name = intern('_' + name) … … 633 634 @component.adapter(IAssociationChangeEvent) 634 635 def _association_changed(self, event): 635 if event.property is self.original :636 if event.property is self.original and isinstance(event.element, self.decl_class): 636 637 # mimic the events for Set/Add/Delete 637 638 if IAssociationSetEvent.providedBy(event): gaphor/trunk/gaphor/UML/tests/test_properties.py
r2204 r2246 608 608 A.a = association('a', A, upper=1) 609 609 610 A.a = redefine( 'a', A, A.a)610 A.a = redefine(A, 'a', A, A.a) 611 611 events = [] 612 612 @component.adapter(AssociationChangeEvent) … … 624 624 Application.unregister_handler(handler) 625 625 626 def test_redefine_subclass(self): 627 from zope import component 628 from gaphor.application import Application 629 from gaphor.UML.event import AssociationChangeEvent 630 631 class A(Element): 632 is_unlinked = False 633 def unlink(self): 634 self.is_unlinked = True 635 Element.unlink(self) 636 637 A.a = association('a', A, upper=1) 638 639 class B(A): 640 pass 641 642 B.b = redefine(B, 'b', A, A.a) 643 644 events = [] 645 @component.adapter(AssociationChangeEvent) 646 def handler(event, events=events): 647 events.append(event) 648 649 Application.register_handler(handler) 650 try: 651 a = A() 652 a.a = A() 653 # Only a.a changes, no B class involved 654 assert len(events) == 1 655 assert events[0].property is A.a, events[0].property 656 #assert events[1].property is A.a.original, events[1].property 657 del events[:] 658 659 a = B() 660 a.a = A() 661 # Now events are sent for both association and redefine 662 assert len(events) == 2 663 assert events[0].property is B.b, events[0].property 664 assert events[1].property is B.b.original, events[1].property 665 finally: 666 Application.unregister_handler(handler) 667 626 668 627 669 if __name__ == '__main__': gaphor/trunk/utils/command/gen_uml.py
r2150 r2246 235 235 """ 236 236 self.write_property("%s.%s" % (r.class_name, r.name), 237 "redefine( '%s', %s, %s)" % (r.name, r.opposite_class_name, r.redefines))237 "redefine(%s, '%s', %s, %s)" % (r.class_name, r.name, r.opposite_class_name, r.redefines)) 238 238 239 239
