Skip to content

Commit

Permalink
an attempt to run fix the pharo joblist
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Jan 24, 2024
1 parent ffce4ff commit 9449ee2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 39 deletions.
6 changes: 6 additions & 0 deletions src/Spec2-Core/SpApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ SpApplication >> registerWindow: aWindow [
self windows add: aWindow
]

{ #category : 'accessing - properties' }
SpApplication >> removeProperty: aName [

^ self properties removeKey: aName ifAbsent: [ ]
]

{ #category : 'accessing' }
SpApplication >> reset [

Expand Down
45 changes: 25 additions & 20 deletions src/Spec2-Core/SpJobListPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ Class {

{ #category : 'examples' }
SpJobListPresenter class >> example [
| jobList |

jobList := self new.

[
1 to: 5 do: [ :index |
[
jobList pushJob: (SpJob
newTitle: 'Job ', index asString
Job new
title: 'Job ', index asString;
block: [ :job |
job min: 1; max: 10.
1 to: 10 do: [ :i |
job title: ('Test {1}/10' format: {i}).
job value: i.
250 milliSeconds wait ] ]).
250 milliSeconds wait ] ];
run.
] fork.
200 milliSeconds wait ]
] fork.
Expand All @@ -39,12 +38,6 @@ SpJobListPresenter class >> example [
SpJobListPresenter >> addJobPresenter: aJob [
| presenter |

('adding: {1}, {2}, max={3}, value={4}' format: {
aJob class.
aJob title.
aJob max.
aJob currentValue }) crTrace.

aJob title ifEmpty: [ aJob title: 'Processing...' ].

presenter := self instantiate: SpJobPresenter on: aJob.
Expand All @@ -58,6 +51,14 @@ SpJobListPresenter >> addJobPresenter: aJob [
window resize: 500@(layout children size * self jobPresenterHeight) ]
]

{ #category : 'private' }
SpJobListPresenter >> ensureOpen [

self withWindowDo: [ :aWindow |
aWindow isOpen
ifFalse: [ self open ] ]
]

{ #category : 'private' }
SpJobListPresenter >> findJob: aJob [

Expand All @@ -82,15 +83,22 @@ SpJobListPresenter >> initializeWindow: aWindowPresenter [
centered
]

{ #category : 'testing' }
SpJobListPresenter >> isEmpty [

^ self layout children isEmpty
]

{ #category : 'private - events' }
SpJobListPresenter >> jobChanged: ann [

(self findJob: ann job)
ifNotNil: [ :aPresenter | aPresenter updatePresenter ]
(self findJob: ann job) ifNotNil: [ :aPresenter |
aPresenter model title crTrace.
aPresenter updatePresenter ]
]

{ #category : 'private - events' }
SpJobListPresenter >> jobEnd: ann [
SpJobListPresenter >> jobEnd: ann [

self removeJobPresenter: ann job
]
Expand All @@ -107,21 +115,18 @@ SpJobListPresenter >> jobStart: ann [
"Skip if already there"
(self findJob: ann job) ifNotNil: [ ^ self ].
self addJobPresenter: ann job.
ann job run
self ensureOpen
]

{ #category : 'private' }
SpJobListPresenter >> newJob [

^ SpJob new
^ Job new
]

{ #category : 'api' }
SpJobListPresenter >> pushJob: aJob [

aJob whenStartDo: [ :ann | self addJobPresenter: ann job ].
aJob whenEndDo: [ :ann | self removeJobPresenter: ann job ].

aJob run
]

Expand Down
12 changes: 6 additions & 6 deletions src/Spec2-Core/SpJobPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Class {
SpJobPresenter class >> example [
| job |

job := SpJob newBlock: [ :aJob |
job := Job block: [ :aJob |
aJob title: 'Test'.
aJob min: 1; max: 10.
1 to: 10 do: [ :i |
Expand Down Expand Up @@ -61,7 +61,7 @@ SpJobPresenter >> initializePresenters [

progressLabel := self newLabel label: ''.
progressBar := self newProgressBar
indeterminate;
"indeterminate;"
yourself
]

Expand Down Expand Up @@ -128,19 +128,19 @@ SpJobPresenter >> updatePresenter [
model ifNil: [ ^ self ].

progressLabel label: model title.
"progressBar fixedAt: model progress."
model progress > 0
ifTrue: [ progressBar fixedAt: model progress ]
ifFalse: [ progressBar indeterminate ].

progressBar withAdapterDo: [ :anAdapter | anAdapter updateState ]
progressBar refresh
]

{ #category : 'private' }
SpJobPresenter >> updateSubscriptions [

model announcer weak
"model announcer weak
when: JobStart send: #jobStart: to: self;
when: JobChange send: #jobChanged: to: self;
when: JobEnd send: #jobEnd: to: self.
when: JobEnd send: #jobEnd: to: self."

]
6 changes: 6 additions & 0 deletions src/Spec2-Core/SpProgressBarPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ SpProgressBarPresenter >> progress: aBlock every: aDelay [
self state: (SpProgressingProgressBarState progression: aBlock every: aDelay)
]

{ #category : 'api' }
SpProgressBarPresenter >> refresh [

^ self withAdapterDo: [ :anAdapter | anAdapter updateState ]
]

{ #category : 'private' }
SpProgressBarPresenter >> state [

Expand Down
7 changes: 4 additions & 3 deletions src/Spec2-Dialogs/SpApplication.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ SpApplication >> informUser: aString during: aBlock [

result := nil.
self jobList
pushJob: (SpJob
newTitle: aString
pushJob: (Job new
title: aString;
block: [ :job |
job min: 0; max: 100.
result := aBlock cull: job ]).
result := aBlock cull: job ];
yourself).

^ result
]
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Dialogs/SpProgressDialog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The task can control the progress.
Class {
#name : 'SpProgressDialog',
#superclass : 'SpInformUserDialog',
#classTraits : '{} + TraitedClass',
#instVars : [
'maxValue'
],
Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Layout/SpExecutableLayout.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ SpExecutableLayout >> remove: aPresenter ifAbsent: aBlock [

^ (children includesKey: aPresenter)
ifTrue: [ children removeKey: aPresenter ]
ifFalse: aBlock
ifFalse: [ aBlock value ]
]

{ #category : 'private' }
Expand Down
23 changes: 14 additions & 9 deletions src/Spec2-Morphic-Tests/SpJobListPresenterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ SpJobListPresenterTest >> testJobIsFinishedWhenWaitingMoreThanWorkBlockDuration

self skipOnPharoCITestingEnvironment.
progress := 0.
job := SpJob
newTitle: 'some job'
block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 20 milliSeconds wait. ] ].
job := Job new
title: 'some job';
block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 20 milliSeconds wait. ] ];
yourself.
[ presenter := SpJobListPresenter new
pushJob: job;
yourself. ] fork.
Expand All @@ -35,9 +36,10 @@ SpJobListPresenterTest >> testJobIsNotFinishedWhenWaitingLessThanWorkBlockDurati
self skipOnPharoCITestingEnvironment.

progress := 0.
job := SpJob
newTitle: 'some job'
block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 60 milliSeconds wait. ] ].
job := Job new
title: 'some job';
block: [ : myjob | 1 to: 25 do: [ :i | myjob value: i*4. 60 milliSeconds wait ] ];
yourself.
[ presenter := SpJobListPresenter new
pushJob: job;
yourself. ] fork.
Expand All @@ -57,9 +59,12 @@ SpJobListPresenterTest >> testProgressDoesNotRefreshMoreThanRefreshRate [
refreshRateInMs := 150.
nbUpdates := 25.
counter := 0.
job := SpJob
newTitle: 'some job'
block: [ : myjob | 1 to: nbUpdates do: [ :i | myjob value: i * 4. waitBetweenJobUpdate wait. ] ].
job := Job new
title: 'some job';
block: [ : myjob |
1 to: nbUpdates do: [ :i |
myjob value: i * 4. waitBetweenJobUpdate wait ] ];
yourself.
presenter := SpJobPresenter on: job.

[ presenter open.
Expand Down

0 comments on commit 9449ee2

Please sign in to comment.