Changeset 2204

Show
Ignore:
Timestamp:
02/06/08 23:32:44 (3 months ago)
Author:
arj..@yirdis.nl
Message:

Fixed bug in gaphor.UML.collection: should not call notify() anymore.

Files:

Legend:

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

    r1835 r2204  
    44 
    55import inspect 
     6from zope import component 
     7from event import AssociationChangeEvent 
    68 
    79class CollectionError(Exception): 
     
    207209            i2 = self.items.index(item2) 
    208210            self.items[i1], self.items[i2] = self.items[i2], self.items[i1] 
     211 
    209212            # send a notification that this list has changed 
    210             self.property.notify(self.object
     213            component.handle(AssociationChangeEvent(self.object, self.property)
    211214            return True 
    212215        except IndexError, ex: 
  • gaphor/trunk/gaphor/UML/tests/test_properties.py

    r2140 r2204  
    22 
    33import unittest 
     4from zope import component 
     5from gaphor.application import Application 
    46from gaphor.UML.properties import * 
    57from gaphor.UML.element import Element 
     8from gaphor.UML.event import AssociationChangeEvent 
    69 
    710class PropertiesTestCase(unittest.TestCase): 
     
    223226        #assert len(a1._observers.get('__unlink__')) == 0 
    224227        #assert len(b1._observers.get('__unlink__')) == 0 
     228 
     229    def test_association_swap(self): 
     230        class A(Element): pass 
     231        class B(Element): pass 
     232        class C(Element): pass 
     233 
     234        A.one = association('one', B, 0, '*') 
     235 
     236        a = A() 
     237        b1 = B() 
     238        b2 = B() 
     239 
     240        a.one = b1 
     241        a.one = b2 
     242        assert a.one.size() == 2 
     243        assert a.one[0] is b1 
     244        assert a.one[1] is b2 
     245 
     246        events = [] 
     247        @component.adapter(AssociationChangeEvent) 
     248        def handler(event, events=events): 
     249            events.append(event) 
     250 
     251        Application.register_handler(handler) 
     252        try: 
     253            a.one.swap(b1, b2) 
     254            assert len(events) == 1 
     255            assert events[0].property is A.one 
     256            assert events[0].element is a 
     257        finally: 
     258            Application.unregister_handler(handler) 
     259 
     260        assert a.one.size() == 2 
     261        assert a.one[0] is b2 
     262        assert a.one[1] is b1 
    225263 
    226264    def test_association_unlink_1(self): 
     
    426464 
    427465    def test_derivedunion(self): 
    428         from zope import component 
    429         from gaphor.application import Application 
    430         from gaphor.UML.event import AssociationChangeEvent 
    431466         
    432467        class A(Element):