Changeset 2246

Show
Ignore:
Timestamp:
03/03/08 23:40:52 (2 months ago)
Author:
arj..@yirdis.nl
Message:

Redefine events are now only sent if the class who's property is set has the redefine declared.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/UML/properties.py

    r2140 r2246  
    569569    """ 
    570570    Redefined association 
    571     Element.x = redefine('x', Class, Element.assoc) 
     571    Element.x = redefine('x', Element, Class, Element.assoc) 
    572572    If the redefine eclipses the original property (it has the same name) 
    573573    it ensures that the original values are saved and restored. 
    574574    """ 
    575575 
    576     def __init__(self, name, type, original): 
     576    def __init__(self, decl_class, name, type, original): 
     577        self.decl_class = decl_class 
    577578        self.name = intern(name) 
    578579        self._name = intern('_' + name) 
     
    633634    @component.adapter(IAssociationChangeEvent) 
    634635    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)
    636637            # mimic the events for Set/Add/Delete 
    637638            if IAssociationSetEvent.providedBy(event): 
  • gaphor/trunk/gaphor/UML/tests/test_properties.py

    r2204 r2246  
    608608        A.a = association('a', A, upper=1) 
    609609 
    610         A.a = redefine('a', A, A.a) 
     610        A.a = redefine(A, 'a', A, A.a) 
    611611        events = [] 
    612612        @component.adapter(AssociationChangeEvent) 
     
    624624            Application.unregister_handler(handler) 
    625625 
     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 
    626668 
    627669if __name__ == '__main__': 
  • gaphor/trunk/utils/command/gen_uml.py

    r2150 r2246  
    235235        """ 
    236236        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)) 
    238238 
    239239