Changeset 1088

Show
Ignore:
Timestamp:
11/24/06 03:02:44 (2 years ago)
Author:
arjanmol
Message:

Copnnections on lines are now properly reflected in the data model.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/TODO

    r1087 r1088  
    77   other support classes. 
    88 
    9  - Currently (r1085) relations (association, dependency) can be created between 
    10    model elements. Some items (e.g. comment lines) can be connected to the 
    11    relationship at the time it realizes a relation at model level (both ends 
    12    get connected). This should result in a trigger to the attached 
    13    (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 is 
    16       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 where 
    18       relationship are established so doing some extra work there won't hurt 
    19    Hmm.. Option 2 I guess.. 
    20  
    219 - using stereotypes 
    22  - associations 
    2310 - components and stuff 
    2411 
  • gaphor/branches/new-canvas/gaphor/adapters/connectors.py

    r1087 r1088  
    295295        opposite = self.line.opposite(handle) 
    296296        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: 
    298300                del opposite.connected_to.subject.annotatedElement[handle.connected_to.subject] 
    299             else: 
    300                 del handle.connected_to.subject.annotatedElement[opposite.connected_to.subject] 
    301301        super(CommentLineLineConnect, self).disconnect(handle) 
    302302 
     
    379379        return relation 
    380380 
    381     def trigger_connected_items(self, line): 
     381    def connect_connected_items(self, connected_items=None): 
    382382        """ 
    383383        Cause items connected to @line to reconnect, allowing them to 
    384384        establish or destroy relationships at model level. 
    385385        """ 
     386        line = self.line 
    386387        canvas = line.canvas 
    387388        solver = canvas.solver 
     
    389390        # First make sure coordinates match 
    390391        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): 
    392393            adapter = component.queryMultiAdapter((line, item), IConnect) 
    393394            assert adapter 
    394395            adapter.connect(handle, handle.x, handle.y) 
    395396         
     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 
    396418    def glue(self, handle, x, y): 
    397419        opposite = self.line.opposite(handle) 
     
    417439        """ 
    418440        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() 
    419453 
    420454    def connect(self, handle, x, y): 
     
    429463                line = self.line 
    430464                if line.subject: 
    431                     self.trigger_connected_items(line
     465                    self.connect_connected_items(
    432466 
    433467    def disconnect(self, handle): 
     
    435469        Disconnect model element. 
    436470        """ 
    437         opposite = self.line.opposite(handle) 
     471        line = self.line 
     472        opposite = line.opposite(handle) 
    438473        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) 
    441479            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) 
    445481 
    446482        super(RelationshipConnect, self).disconnect(handle) 
     
    692728        line.subject = relation 
    693729 
    694     def disconnect(self, handle): 
     730    def disconnect_subject(self, handle): 
    695731        """ 
    696732        Disconnect model element. 
     
    706742                    e.unlink() 
    707743                old.unlink() 
    708  
    709         super(ExtensionConnect, self).disconnect(handle) 
    710744 
    711745 
     
    794828                line.tail_end.subject = tail_end 
    795829 
    796     def disconnect(self, handle): 
     830    def disconnect_subject(self, handle): 
    797831        """ 
    798832        Disconnect model element. 
     
    811845                old.unlink() 
    812846 
    813         super(AssociationConnect, self).disconnect(handle) 
    814  
    815847 
    816848component.provideAdapter(AssociationConnect) 
  • gaphor/branches/new-canvas/gaphor/adapters/tests/test_connector.py

    r1087 r1088  
    222222        assert assoc.subject in comment.subject.annotatedElement 
    223223 
    224         # And now disconnect again: 
     224        # And now disconnect the association (comment.annotatedElement should 
     225        # also become empty: 
    225226 
    226227        adapter.disconnect(handle)