Changeset 1088
- Timestamp:
- 11/24/06 03:02:44 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/TODO (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/adapters/connectors.py (modified) (10 diffs)
- gaphor/branches/new-canvas/gaphor/adapters/tests/test_connector.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/TODO
r1087 r1088 7 7 other support classes. 8 8 9 - Currently (r1085) relations (association, dependency) can be created between10 model elements. Some items (e.g. comment lines) can be connected to the11 relationship at the time it realizes a relation at model level (both ends12 get connected). This should result in a trigger to the attached13 (comment-)line so it can also establish it's relationship at model level.14 This can be solved in two places:15 1. handle it in the DiagramItem. This will ensure such relationship is16 always up to date, but may result in weird behavior in the loading code.17 2. handle it in the IConnect adapters. That's the only place where18 relationship are established so doing some extra work there won't hurt19 Hmm.. Option 2 I guess..20 21 9 - using stereotypes 22 - associations23 10 - components and stuff 24 11 gaphor/branches/new-canvas/gaphor/adapters/connectors.py
r1087 r1088 295 295 opposite = self.line.opposite(handle) 296 296 if handle.connected_to and opposite.connected_to: 297 if isinstance(opposite.connected_to.subject, UML.Comment): 297 if isinstance(handle.connected_to.subject, UML.Comment): 298 del handle.connected_to.subject.annotatedElement[opposite.connected_to.subject] 299 else: 298 300 del opposite.connected_to.subject.annotatedElement[handle.connected_to.subject] 299 else:300 del handle.connected_to.subject.annotatedElement[opposite.connected_to.subject]301 301 super(CommentLineLineConnect, self).disconnect(handle) 302 302 … … 379 379 return relation 380 380 381 def trigger_connected_items(self, line):381 def connect_connected_items(self, connected_items=None): 382 382 """ 383 383 Cause items connected to @line to reconnect, allowing them to 384 384 establish or destroy relationships at model level. 385 385 """ 386 line = self.line 386 387 canvas = line.canvas 387 388 solver = canvas.solver … … 389 390 # First make sure coordinates match 390 391 solver.solve() 391 for item, handle in self.line.canvas.get_connected_items(line):392 for item, handle in connected_items or line.canvas.get_connected_items(line): 392 393 adapter = component.queryMultiAdapter((line, item), IConnect) 393 394 assert adapter 394 395 adapter.connect(handle, handle.x, handle.y) 395 396 397 def disconnect_connected_items(self): 398 """ 399 Cause items connected to @line to be disconnected. 400 This is nessesary if the subject of the @line is to be removed. 401 402 Returns a list of (item, handle) pairs that were connected (this 403 list can be used to connect items again with connect_connected_items()). 404 """ 405 line = self.line 406 canvas = line.canvas 407 solver = canvas.solver 408 409 # First make sure coordinates match 410 solver.solve() 411 connected_items = list(line.canvas.get_connected_items(line)) 412 for item, handle in connected_items: 413 adapter = component.queryMultiAdapter((line, item), IConnect) 414 assert adapter 415 adapter.disconnect(handle) 416 return connected_items 417 396 418 def glue(self, handle, x, y): 397 419 opposite = self.line.opposite(handle) … … 417 439 """ 418 440 raise NotImplemented, 'Implement connect_subject() in a subclass' 441 442 def disconnect_subject(self, handle): 443 """ 444 Disconnect the diagram item from its model element. If there are 445 no more presentations(diagram items) connected to the model element, 446 unlink() it too. 447 """ 448 line = self.line 449 old = line.subject 450 del line.subject 451 if old and len(old.presentation) == 0: 452 old.unlink() 419 453 420 454 def connect(self, handle, x, y): … … 429 463 line = self.line 430 464 if line.subject: 431 self. trigger_connected_items(line)465 self.connect_connected_items() 432 466 433 467 def disconnect(self, handle): … … 435 469 Disconnect model element. 436 470 """ 437 opposite = self.line.opposite(handle) 471 line = self.line 472 opposite = line.opposite(handle) 438 473 if handle.connected_to and opposite.connected_to: 439 old = self.line.subject 440 del self.line.subject 474 old = line.subject 475 476 connected_items = self.disconnect_connected_items() 477 478 self.disconnect_subject(handle) 441 479 if old: 442 self.trigger_connected_items(self.line) 443 if old and len(old.presentation) == 0: 444 old.unlink() 480 self.connect_connected_items(connected_items) 445 481 446 482 super(RelationshipConnect, self).disconnect(handle) … … 692 728 line.subject = relation 693 729 694 def disconnect (self, handle):730 def disconnect_subject(self, handle): 695 731 """ 696 732 Disconnect model element. … … 706 742 e.unlink() 707 743 old.unlink() 708 709 super(ExtensionConnect, self).disconnect(handle)710 744 711 745 … … 794 828 line.tail_end.subject = tail_end 795 829 796 def disconnect (self, handle):830 def disconnect_subject(self, handle): 797 831 """ 798 832 Disconnect model element. … … 811 845 old.unlink() 812 846 813 super(AssociationConnect, self).disconnect(handle)814 815 847 816 848 component.provideAdapter(AssociationConnect) gaphor/branches/new-canvas/gaphor/adapters/tests/test_connector.py
r1087 r1088 222 222 assert assoc.subject in comment.subject.annotatedElement 223 223 224 # And now disconnect again: 224 # And now disconnect the association (comment.annotatedElement should 225 # also become empty: 225 226 226 227 adapter.disconnect(handle)
