SystemOrganization addCategory: #'Synchronicity-Core'! SystemOrganization addCategory: #'Synchronicity-Events'! SystemOrganization addCategory: #'Synchronicity-Examples'! Trait named: #SYChildrenTrait uses: {} category: 'Synchronicity-Core'! !SYChildrenTrait methodsFor: 'actions' stamp: 'lr 2/20/2007 09:21'! add: anElement ^ self add: anElement before: nil! ! !SYChildrenTrait methodsFor: 'actions' stamp: 'lr 2/20/2007 09:27'! add: anElement before: aReferenceElement anElement remove. self children add: (anElement setParent: self) beforeIndex: (self children indexOf: aReferenceElement ifAbsent: [ self children size + 1 ]). (SYAddedElementEvent on: anElement) dispatch. ^ anElement! ! !SYChildrenTrait methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:12'! children self requirement! ! !SYChildrenTrait methodsFor: 'testing' stamp: 'lr 2/20/2007 09:30'! hasChildren ^ self children notEmpty! ! !SYChildrenTrait methodsFor: 'actions' stamp: 'lr 2/20/2007 09:22'! remove: anElement self children remove: anElement ifAbsent: [ ^ nil ]. (SYRemovedElementEvent on: anElement) dispatch. anElement setParent: nil. ^ anElement! ! !SYChildrenTrait methodsFor: 'actions' stamp: 'lr 2/20/2007 09:30'! replace: anOldElement with: aNewElement | index | index := self children indexOf: anOldElement ifAbsent: [ ^ nil ]. self children at: index put: (aNewElement setParent: self). (SYRemovedElementEvent on: anOldElement) dispatch. (SYAddedElementEvent on: aNewElement) dispatch. anOldElement setParent: nil. ^ aNewElement! ! WAComponent subclass: #SYMain instanceVariableNames: 'view' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! SYMain subclass: #SYCounterView instanceVariableNames: 'model node' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Examples'! !SYCounterView class methodsFor: 'accessing' stamp: 'lr 2/20/2007 10:55'! example ^ self new! ! !SYCounterView methodsFor: 'initialization' stamp: 'lr 2/20/2007 14:34'! initialize super initialize. model := SYCounterModel new. view := SYDivTag new add: (SYDomText new when: SYCounterChanged in: model update: [ :ann | model count ]); add: (SYDomText new text: ' '); add: (SYAnchorTag new on: SYClickedElementEvent do: [ :ann | model decrease ]; add: (SYDomText new text: '--'); yourself); add: (SYDomText new text: ' '); add: (SYAnchorTag new on: SYClickedElementEvent do: [ :ann | model increase ]; add: (SYDomText new text: '++'); yourself); yourself. model count: 0! ! !SYMain class methodsFor: 'testing' stamp: 'lr 2/20/2007 10:48'! canBeRoot ^ self name ~= #SYMain! ! !SYMain methodsFor: 'rendering' stamp: 'lr 2/20/2007 14:18'! renderContentOn: html html render: self view! ! !SYMain methodsFor: 'accessing' stamp: 'lr 2/20/2007 14:18'! view ^ view! ! Announcement subclass: #SYCounterChanged instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Examples'! Announcement subclass: #SYElementEvent instanceVariableNames: 'element current cancelled' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Events'! SYElementEvent subclass: #SYAddedElementEvent instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Events'! SYElementEvent subclass: #SYClickedElementEvent instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Events'! !SYElementEvent class methodsFor: 'initialization' stamp: 'lr 2/20/2007 09:10'! on: anElement ^ self basicNew initializeOn: anElement! ! !SYElementEvent methodsFor: 'actions' stamp: 'lr 2/20/2007 09:07'! cancel cancelled := true! ! !SYElementEvent methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:07'! current "Answer the element that is currently dispatching this event." ^ current! ! !SYElementEvent methodsFor: 'actions' stamp: 'lr 2/20/2007 09:08'! dispatch "Dispatch the receiving event trough the owner chain. Immediatley stop processing when the event gets cancelled or when reaching to root." [ cancelled or: [ current isNil ] ] whileFalse: [ current announce: self. current := current parent ]! ! !SYElementEvent methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:07'! element "Answer the element that originally received this event." ^ element! ! !SYElementEvent methodsFor: 'initialization' stamp: 'lr 2/20/2007 14:48'! initializeOn: anElement element := current := anElement. cancelled := false! ! !SYElementEvent methodsFor: 'testing' stamp: 'lr 2/20/2007 09:09'! isCancelled ^ cancelled! ! !SYElementEvent methodsFor: 'testing' stamp: 'lr 2/20/2007 09:09'! isInitiator ^ element = current! ! !SYElementEvent methodsFor: 'printing' stamp: 'lr 2/20/2007 09:09'! printOn: aStream super printOn: aStream. aStream nextPutAll: ' on: '; print: self element! ! SYElementEvent subclass: #SYRemovedElementEvent instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Events'! Object subclass: #SYModel instanceVariableNames: 'announcer' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! SYModel subclass: #SYCounterModel instanceVariableNames: 'count' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Examples'! !SYCounterModel methodsFor: 'accessing' stamp: 'lr 2/20/2007 14:11'! count ^ count! ! !SYCounterModel methodsFor: 'accessing' stamp: 'lr 2/20/2007 14:14'! count: anNumber count := anNumber. self announce: SYCounterChanged! ! !SYCounterModel methodsFor: 'actions' stamp: 'lr 2/20/2007 14:14'! decrease self count: self count - 1! ! !SYCounterModel methodsFor: 'actions' stamp: 'lr 2/20/2007 14:13'! increase self count: self count + 1! ! SYModel subclass: #SYElement instanceVariableNames: 'parent' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! SYElement subclass: #SYDomNode instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! SYDomNode subclass: #SYDomTag uses: SYChildrenTrait instanceVariableNames: 'attributes children' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! SYDomTag class uses: SYChildrenTrait classTrait instanceVariableNames: ''! SYDomTag subclass: #SYAnchorTag instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! !SYAnchorTag methodsFor: 'rendering' stamp: 'lr 2/20/2007 09:55'! renderOn: html html anchor attributes: self attributes; callback: [ (SYClickedElementEvent on: self) dispatch ]; with: self children! ! !SYAnchorTag methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:32'! tag ^ 'a'! ! SYDomTag subclass: #SYDivTag instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! !SYDivTag methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:31'! tag ^ 'div'! ! !SYDomTag methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:01'! attributes ^ attributes! ! !SYDomTag methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:02'! children ^ children! ! !SYDomTag methodsFor: 'initialization' stamp: 'lr 2/20/2007 09:02'! initialize super initialize. attributes := WAHtmlAttributes new. children := OrderedCollection new! ! !SYDomTag methodsFor: 'rendering' stamp: 'lr 2/20/2007 10:54'! renderOn: html (html tag: self tag) attributes: self attributes; with: self children! ! !SYDomTag methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:01'! tag self subclassResponsibility! ! SYDomNode subclass: #SYDomText instanceVariableNames: 'text' classVariableNames: '' poolDictionaries: '' category: 'Synchronicity-Core'! !SYDomText methodsFor: 'rendering' stamp: 'lr 2/20/2007 10:50'! renderOn: html html render: self text! ! !SYDomText methodsFor: 'accessing' stamp: 'lr 2/20/2007 08:56'! text ^ text! ! !SYDomText methodsFor: 'accessing' stamp: 'lr 2/20/2007 08:56'! text: aString text := aString! ! !SYDomText methodsFor: 'events' stamp: 'lr 2/20/2007 14:34'! when: aClass in: anObject update: aBlock anObject on: aClass do: [ :ann | self text: (aBlock value: ann) ]! ! !SYElement methodsFor: 'testing' stamp: 'lr 2/20/2007 09:31'! hasChildren ^ false! ! !SYElement methodsFor: 'testing' stamp: 'lr 2/20/2007 09:22'! isRoot ^ parent isNil! ! !SYElement methodsFor: 'accessing' stamp: 'lr 2/20/2007 09:13'! parent ^ parent! ! !SYElement methodsFor: 'actions' stamp: 'lr 2/20/2007 09:24'! remove ^ self isRoot ifFalse: [ self parent remove: self ]! ! !SYElement methodsFor: 'initialization' stamp: 'lr 2/20/2007 09:57'! setParent: anElement parent := anElement! ! !SYModel methodsFor: 'announcing' stamp: 'lr 2/20/2007 14:15'! announce: anAnnouncement ^ announcer isNil ifTrue: [ anAnnouncement ] ifFalse: [ announcer announce: anAnnouncement ]! ! !SYModel methodsFor: 'accessing' stamp: 'lr 2/20/2007 14:10'! announcer ^ announcer ifNil: [ announcer := Announcer new ]! ! !SYModel methodsFor: 'registration' stamp: 'lr 2/20/2007 14:15'! on: aClass do: aValuable ^ self announcer on: aClass do: aValuable! ! !SYModel methodsFor: 'registration' stamp: 'lr 2/20/2007 14:16'! on: aClass send: aSymbol to: anObject ^ self announcer on: aClass send: aSymbol to: anObject! !