Skip to content

Commit

Permalink
add GtPhlowUpdateOnAnnouncement [feenkcom/gtoolkit#2257]
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajKubelka committed Nov 1, 2024
1 parent f55d24e commit a7c3ad1
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 207 deletions.
105 changes: 105 additions & 0 deletions src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Class {
#name : #GtPhlowChangeAnnouncerListener,
#superclass : #Object,
#instVars : [
'element',
'elementFuture',
'subscriptions'
],
#category : #'GToolkit-Phlow-Updating New'
}

{ #category : #factory }
GtPhlowChangeAnnouncerListener class >> installOn: anElement announcer: anAnnouncer announcement: anAnnouncement [
| aListener |
aListener := anElement userData
at: GtPhlowChangeAnnouncerListener
ifAbsentPut: [ self new element: anElement ].

aListener installAnnouncer: anAnnouncer announcement: anAnnouncement.
^ aListener
]

{ #category : #accessing }
GtPhlowChangeAnnouncerListener >> configuration: aFutureExecutionConfiguration [
elementFuture executionConfiguration: aFutureExecutionConfiguration
]

{ #category : #initialization }
GtPhlowChangeAnnouncerListener >> defaultConfiguration [
^ GtPhlowUtility defaultFutureExecutionConfiguration
]

{ #category : #accessing }
GtPhlowChangeAnnouncerListener >> element [
^ element
]

{ #category : #accessing }
GtPhlowChangeAnnouncerListener >> element: anElement [
self
assert: [ element isNil ]
description: [ 'Element is already initialized' ].

element := anElement.
elementFuture element: anElement
]

{ #category : #'gt - extensions' }
GtPhlowChangeAnnouncerListener >> gtSubscriptionsFor: aView [
<gtView>
subscriptions ifNil: [ ^ aView empty ].
^ aView columnedList
title: 'Subscriptions';
priority: 50;
items: [ subscriptions select: #isNotNil ];
actionUpdateButtonTooltip: 'Update subscription list';
column: 'Announcement'
text: [ :aSubscription | aSubscription announcementClass ];
column: 'Kind' text: [ :aSubscription | aSubscription class ]
]

{ #category : #initialization }
GtPhlowChangeAnnouncerListener >> initialize [
super initialize.
subscriptions := WeakArray empty.
elementFuture := BrAsyncElementFuture new
cancelSoft;
executionConfiguration: self defaultConfiguration;
whenSuccess: [ :anElement :anObject | "do nothing" ]
]

{ #category : #'api - subscriptions' }
GtPhlowChangeAnnouncerListener >> installAnnouncer: anAnnouncer announcement: anAnnouncement [
| aSubscription |
self
assert: [ self element isNotNil ]
description: [ 'Element must be initialized' ].
aSubscription := anAnnouncer weak
when: anAnnouncement
send: #onAnnouncement:
to: self.

"We do not need to collect subscriptions.
We do it just for an explainability purpose."
subscriptions := WeakArray
new: subscriptions size + 1
streamContents: [ :aStream |
aStream
nextPutAll: subscriptions;
nextPut: aSubscription ]
]

{ #category : #'event handling' }
GtPhlowChangeAnnouncerListener >> onAnnouncement: anAnnouncement [
element ifNil: [ ^ self ].
elementFuture future: ([ self updateElement ] asAsyncFuture delayed: 200 milliSeconds)
]

{ #category : #'private - updating' }
GtPhlowChangeAnnouncerListener >> updateElement [
| aPhlowView |
aPhlowView := self element phlow entity.
aPhlowView ifNil: [ ^ self ].
aPhlowView updateContent: self element.
]
209 changes: 209 additions & 0 deletions src/GToolkit-Phlow/GtPhlowChangeSystemListener.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
Class {
#name : #GtPhlowChangeSystemListener,
#superclass : #Object,
#instVars : [
'isSubscribedToSystem',
'onMethodAddedAction',
'onMethodRemovedAction',
'onMethodModifiedAction',
'interestCondition',
'actionExecutor'
],
#category : #'GToolkit-Phlow-Updating New'
}

{ #category : #factory }
GtPhlowChangeSystemListener class >> installOn: aTabGroup [
]

{ #category : #factory }
GtPhlowChangeSystemListener class >> installOnCompositeElement: aTabGroup [
| aListener aCompositeView aBuildContext |
aCompositeView := aTabGroup phlow entity ifNil: [ ^ nil ].
aBuildContext := aCompositeView buildContext.
aBuildContext isBuildContext ifFalse: [ ^ nil ].

aListener := self new
interestingPragmas: GtPhlowViewsCollector defaultViewPragmaNames
andObject: aBuildContext object;
actionExecutor: (GtPhlowChangeTabGroupActionExecutor new
tabGroup: aTabGroup);
onMethodAddedAction: (GtPhlowChangeTabGroupAddTabAction new
tabGroup: aTabGroup;
buildContext: aBuildContext);
onMethodRemovedAction: (GtPhlowChangeTabGroupRemoveTabAction new
tabGroup: aTabGroup);
onMethodModifiedAction: (GtPhlowChangeTabGroupModifyTabAction new
tabGroup: aTabGroup;
buildContext: aBuildContext);
subscribeToSystem.

aTabGroup userData at: GtPhlowChangeSystemListener put: aListener.
^ aListener
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> actionExecutor [
^ actionExecutor
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> actionExecutor: anActionExecutor [
actionExecutor := anActionExecutor
]

{ #category : #initialization }
GtPhlowChangeSystemListener >> initialize [
super initialize.
interestCondition := GtPhlowChangeLackOfInterestCondition default.
isSubscribedToSystem := false.
actionExecutor := GtPhlowChangeBasicActionExecutor default.
onMethodAddedAction := GtPhlowChangeNoAction default.
onMethodRemovedAction := GtPhlowChangeNoAction default.
onMethodModifiedAction := GtPhlowChangeNoAction default.
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> interestingClass: aClass [
self interestingClasses: { aClass }
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> interestingClasses: aCollection [
interestCondition := GtPhlowChangeClassesAndSuperclassesInterestCondition new
classes: aCollection
]

{ #category : #'api - initialization' }
GtPhlowChangeSystemListener >> interestingPragma: aSymbol [
self interestingPragmas: { aSymbol }
]

{ #category : #'api - initialization' }
GtPhlowChangeSystemListener >> interestingPragmas: aCollectionOfSymbols [
interestCondition := GtPhlowChangePragmasInterestCondition new
pragmas: aCollectionOfSymbols
]

{ #category : #'api - initialization' }
GtPhlowChangeSystemListener >> interestingPragmas: aCollectionOfPragmas andObject: anObject [
interestCondition := GtPhlowChangeAndInterestCondition new
left: (GtPhlowChangePragmasInterestCondition new
pragmas: aCollectionOfPragmas);
right: (GtPhlowChangeObjectInterestCondition new
object: anObject)
]

{ #category : #'api - initialization' }
GtPhlowChangeSystemListener >> interestingPragmas: aCollectionOfPragmas andSuperclass: aClass [
interestCondition := GtPhlowChangeAndInterestCondition new
left: (GtPhlowChangePragmasInterestCondition new
pragmas: aCollectionOfPragmas);
right: (GtPhlowChangeClassesAndSubclassesInterestCondition new
superclass: aClass)
]

{ #category : #testing }
GtPhlowChangeSystemListener >> isInterestingClass: anAffectedClass andMethod: anAffectedMethod [
^ interestCondition isInterestingClass: anAffectedClass andMethod: anAffectedMethod
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodAddedAction [
^ onMethodAddedAction
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodAddedAction: anObject [
onMethodAddedAction := anObject
]

{ #category : #'event handling' }
GtPhlowChangeSystemListener >> onMethodAddedAnnouncement: aMethodAdded [
(self
isInterestingClass: aMethodAdded classAffected
andMethod: aMethodAdded methodAdded) ifFalse: [ ^ self ].

actionExecutor
submit: onMethodAddedAction
context: (GtPhlowChangeActionAffectedMethodContext
forAffectedClass: aMethodAdded classAffected
affectedMethod: aMethodAdded methodAdded)
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodModifiedAction [
^ onMethodModifiedAction
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodModifiedAction: anObject [
onMethodModifiedAction := anObject
]

{ #category : #'event handling' }
GtPhlowChangeSystemListener >> onMethodModifiedAnnouncement: aMethodModified [
(self
isInterestingClass: aMethodModified classAffected
andMethod: aMethodModified methodAffected)
ifTrue: [
actionExecutor
submit: onMethodModifiedAction
context: (GtPhlowChangeActionAffectedMethodContext
forAffectedClass: aMethodModified classAffected
affectedMethod: aMethodModified methodAffected).
^ self ].

(self
isInterestingClass: aMethodModified classAffected
andMethod: aMethodModified oldMethod) ifFalse: [ ^ self ].
"The old method has an interesting pragma, while the new method does not have it.
We therefore remove the method."
actionExecutor
submit: onMethodRemovedAction
context: (GtPhlowChangeActionAffectedMethodContext
forAffectedClass: aMethodModified classAffected
affectedMethod: aMethodModified methodAffected)
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodRemovedAction [
^ onMethodRemovedAction
]

{ #category : #accessing }
GtPhlowChangeSystemListener >> onMethodRemovedAction: anObject [
onMethodRemovedAction := anObject
]

{ #category : #'event handling' }
GtPhlowChangeSystemListener >> onMethodRemovedAnnouncement: aMethodRemoved [
(self
isInterestingClass: aMethodRemoved classAffected
andMethod: aMethodRemoved methodRemoved) ifFalse: [ ^ self ].

actionExecutor
submit: onMethodRemovedAction
context: (GtPhlowChangeActionAffectedMethodContext
forAffectedClass: aMethodRemoved classAffected
affectedMethod: aMethodRemoved methodRemoved)
]

{ #category : #subscriptions }
GtPhlowChangeSystemListener >> subscribeToSystem [
SystemAnnouncer uniqueInstance weak
when: MethodAdded
send: #onMethodAddedAnnouncement:
to: self;
when: MethodRemoved
send: #onMethodRemovedAnnouncement:
to: self;
when: MethodModified
send: #onMethodModifiedAnnouncement:
to: self
]

{ #category : #subscriptions }
GtPhlowChangeSystemListener >> unsubscribeFromSystem [
SystemAnnouncer uniqueInstance unsubscribe: self
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ GtPhlowChangeTabGroupActionExecutor >> configuration: aFutureExecutionConfigurat

{ #category : #initialization }
GtPhlowChangeTabGroupActionExecutor >> defaultConfiguration [
^ AsyncFutureExecutionConfiguration new
customGroup: #Phlow;
highPriority
^ GtPhlowUtility defaultFutureExecutionConfiguration
]

{ #category : #'gt - extensions' }
Expand Down
Loading

0 comments on commit a7c3ad1

Please sign in to comment.