2022-08-15 12:28:09 +02:00
|
|
|
Class {
|
|
|
|
#name : #DiyaLoader,
|
|
|
|
#superclass : #DiyaBaseObject,
|
|
|
|
#instVars : [
|
|
|
|
'node',
|
2022-08-16 00:59:35 +02:00
|
|
|
'jobs',
|
|
|
|
'target'
|
2022-08-15 12:28:09 +02:00
|
|
|
],
|
|
|
|
#category : #'Diya-Applications'
|
|
|
|
}
|
|
|
|
|
2022-08-16 00:59:35 +02:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaLoader class >> on: target [
|
|
|
|
^ self new target: target; yourself
|
|
|
|
]
|
|
|
|
|
2022-08-15 12:28:09 +02:00
|
|
|
{ #category : #scheduling }
|
|
|
|
DiyaLoader >> executeJobs: callback [
|
2022-08-16 00:59:35 +02:00
|
|
|
"target visibility: false."
|
|
|
|
target empty.
|
|
|
|
target addNode: node.
|
|
|
|
"target visibility: true".
|
|
|
|
node visibility: true.
|
|
|
|
self updateLayout.
|
|
|
|
500 milliSeconds wait.
|
|
|
|
self job: [ 500 milliSeconds wait. ] name: 'finishing' .
|
2022-08-15 12:28:09 +02:00
|
|
|
jobs withIndexDo: [ :job :i|
|
|
|
|
self updateProgress: job key percent: ((i - 1) * 100 / (jobs size)) asInteger.
|
|
|
|
job value value.
|
|
|
|
].
|
|
|
|
jobs := OrderedCollection new.
|
|
|
|
self updateProgress: 'Finishing...' percent: 100.
|
2022-08-16 00:59:35 +02:00
|
|
|
|
|
|
|
node visibility: false.
|
|
|
|
target empty.
|
2022-08-15 12:28:09 +02:00
|
|
|
callback value.
|
2022-08-16 00:59:35 +02:00
|
|
|
target visibility: true.
|
2022-08-15 12:28:09 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaLoader >> initialize [
|
|
|
|
super initialize.
|
|
|
|
node := DiyaCompositeNode new.
|
|
|
|
jobs := OrderedCollection new.
|
2022-08-16 00:59:35 +02:00
|
|
|
target := nil.
|
2022-08-15 12:28:09 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #scheduling }
|
|
|
|
DiyaLoader >> job: aBlock name: aName [
|
|
|
|
jobs add: (aName -> aBlock)
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLoader >> node [
|
|
|
|
^ node
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #scheduling }
|
|
|
|
DiyaLoader >> onloaded: aBlock [
|
|
|
|
[ self executeJobs: aBlock ] fork"At: Processor userBackgroundPriority".
|
|
|
|
]
|
|
|
|
|
2022-08-16 00:59:35 +02:00
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLoader >> target [
|
|
|
|
^ target
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaLoader >> target: anObject [
|
|
|
|
target := anObject
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaLoader >> updateLayout [
|
|
|
|
self subclassResponsibility
|
|
|
|
]
|
|
|
|
|
2022-08-15 12:28:09 +02:00
|
|
|
{ #category : #scheduling }
|
|
|
|
DiyaLoader >> updateProgress: name percent: p [
|
|
|
|
self subclassResponsibility
|
|
|
|
]
|