Skip to content

Commit

Permalink
Add proposition utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Nov 4, 2024
1 parent 28e836e commit c7a3099
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/GToolkit-WardleyMap/GtWardleyMapAddProposition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ GtWardleyMapAddProposition >> initialize [
rejectAction icon: BrGlamorousVectorIcons cancel.
rejectAction action: [ self onRejectAction ].
rejectAction tooltip: 'Remove'.

isReadOnly := false
]

{ #category : #testing }
Expand Down
53 changes: 53 additions & 0 deletions src/GToolkit-WardleyMap/GtWardleyMapUtility.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@ Class {
#category : #'GToolkit-WardleyMap-Helpers'
}

{ #category : #'api - diffing' }
GtWardleyMapUtility class >> addModelAsPropositionsFrom: aModel to: propositionModel [
^ self
addModelAsPropositionsFrom: aModel
to: propositionModel
withPropositionBlock: #yourself
]

{ #category : #'api - diffing' }
GtWardleyMapUtility class >> addModelAsPropositionsFrom: aModel to: propositionModel withPropositionBlock: aBlock [
| unsetNodes nodes unsetEdges |
unsetNodes := aModel nodes copy.
nodes := Dictionary new.

propositionModel nodes
do: [ :aNode |
| aName |
aName := aNode label.
unsetNodes
detect: [ :anUnsetNode | aName = anUnsetNode label ]
ifFound: [ :anUnsetNode | unsetNodes remove: anUnsetNode ]
ifNone: [ aNode removeParent
addWardleyMapDecoratorModel: (aBlock value: GtWardleyMapAddProposition new).
aModel addNode: aNode.
nodes at: aName put: aNode ] ].

unsetNodes
do: [ :aNode |
aNode
addWardleyMapDecoratorModel: (aBlock value: GtWardleyMapRemoveProposition new) ].

unsetEdges := aModel edges copy.

propositionModel edges
do: [ :anEdge |
| aKey |
aKey := anEdge fromNode label -> anEdge toNode label.
unsetEdges
detect: [ :anUnsetEdge | aKey = (anUnsetEdge fromNode label -> anUnsetEdge toNode label) ]
ifFound: [ :anUnsetEdge | unsetEdges remove: anUnsetEdge ]
ifNone: [ anEdge removeParent
addWardleyMapDecoratorModel: (aBlock value: GtWardleyMapAddProposition new);
fromNode: (nodes at: aKey key);
toNode: (nodes at: aKey value).
aModel addEdge: anEdge ] ].

unsetEdges
do: [ :anEdge |
anEdge
addWardleyMapDecoratorModel: (aBlock value: GtWardleyMapRemoveProposition new) ].
^ aModel
]

{ #category : #'api - views' }
GtWardleyMapUtility class >> buttonLabelFromString: aString [
aString size <= GtWardleyMapConstants maxButtonLabelCharacters
Expand Down

0 comments on commit c7a3099

Please sign in to comment.