Skip to content

Commit

Permalink
- implemented state transition reconnections
Browse files Browse the repository at this point in the history
  • Loading branch information
wrobell committed Mar 2, 2010
1 parent f06acd8 commit e4222d2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions gaphor/adapters/states/tests/test_transition_connect.py
Expand Up @@ -35,6 +35,39 @@ def test_vertex_connect(self):
self.assertEquals(t.subject.target, v2.subject)


def test_vertex_reconnect(self):
"""Test transition to state vertex reconnection
"""
v1 = self.create(items.StateItem, UML.State)
v2 = self.create(items.StateItem, UML.State)
v3 = self.create(items.StateItem, UML.State)

t = self.create(items.TransitionItem)
assert t.subject is None

# connect: v1 -> v2
self.connect(t, t.head, v1)
self.connect(t, t.tail, v2)

s = t.subject
s.name = 'tname'
s.guard.specification.value = 'tguard'

# reconnect: v1 -> v3
self.connect(t, t.tail, v3)

self.assertSame(s, t.subject)
self.assertEquals(1, len(self.kindof(UML.Transition)))

self.assertEquals(t.subject, v1.subject.outgoing[0])
self.assertEquals(t.subject, v3.subject.incoming[0])
self.assertEquals(t.subject.source, v1.subject)
self.assertEquals(t.subject.target, v3.subject)

self.assertEquals(0, len(v2.subject.incoming))
self.assertEquals(0, len(v2.subject.outgoing))


def test_vertex_disconnect(self):
"""Test transition and state vertices disconnection
"""
Expand Down
12 changes: 12 additions & 0 deletions gaphor/adapters/states/vertexconnect.py
Expand Up @@ -17,6 +17,18 @@ class VertexConnect(RelationshipConnect):
"""
Abstract relationship between two state vertices.
"""
def reconnect(self, handle, port):
line = self.line
c1 = self.get_connected(line.head)
c2 = self.get_connected(line.tail)
if line.head is handle:
line.subject.source = c1.subject
elif line.tail is handle:
line.subject.target = c2.subject
else:
raise ValueError('Incorrect handle passed to adapter')


def connect_subject(self, handle):
relation = self.relationship_or_new(UML.Transition,
('source', 'outgoing'),
Expand Down

0 comments on commit e4222d2

Please sign in to comment.