Changeset 2204
- Timestamp:
- 02/06/08 23:32:44 (3 months ago)
- Files:
-
- gaphor/trunk/gaphor/UML/collection.py (modified) (2 diffs)
- gaphor/trunk/gaphor/UML/tests/test_properties.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/UML/collection.py
r1835 r2204 4 4 5 5 import inspect 6 from zope import component 7 from event import AssociationChangeEvent 6 8 7 9 class CollectionError(Exception): … … 207 209 i2 = self.items.index(item2) 208 210 self.items[i1], self.items[i2] = self.items[i2], self.items[i1] 211 209 212 # send a notification that this list has changed 210 self.property.notify(self.object)213 component.handle(AssociationChangeEvent(self.object, self.property)) 211 214 return True 212 215 except IndexError, ex: gaphor/trunk/gaphor/UML/tests/test_properties.py
r2140 r2204 2 2 3 3 import unittest 4 from zope import component 5 from gaphor.application import Application 4 6 from gaphor.UML.properties import * 5 7 from gaphor.UML.element import Element 8 from gaphor.UML.event import AssociationChangeEvent 6 9 7 10 class PropertiesTestCase(unittest.TestCase): … … 223 226 #assert len(a1._observers.get('__unlink__')) == 0 224 227 #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 225 263 226 264 def test_association_unlink_1(self): … … 426 464 427 465 def test_derivedunion(self): 428 from zope import component429 from gaphor.application import Application430 from gaphor.UML.event import AssociationChangeEvent431 466 432 467 class A(Element):
