InterestConverter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 15 Jun 2009 20:55:05 +0100
branchjv
changeset 17711 39faaaf888b4
parent 11737 cbf8d519c784
child 17761 b0e5971141bc
permissions -rw-r--r--
Added branch jv

"
 COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#InterestConverter
	instanceVariableNames:'destination selector aspect'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support-Models'
!

!InterestConverter class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

!

documentation
"
    instances convert update messages into messages as setup via
    #onChangeSend:to:.
    This is a temporary kludge and will be replaced by a more intelligent
    DependencyCollection class in the future.

    [author:]
        Claus Gittinger
"
!

examples
"
  #onChangeSend:to / #retractInterestsIn:
  interested in any change:
                                                                        [exBegin]
    |p b|

    b := [Transcript showCR:'--> notification: point has changed'].

    p := Point new.
    p onChangeSend:#value to:b.
    Delay waitForSeconds:1.
    Transcript showCR:'sending change ...'.
    p changed.
    Transcript showCR:'retracting ...'.
    p retractInterestsFor:b.
    Delay waitForSeconds:1.
    Transcript showCR:'sending change ...'.
    p changed.
                                                                        [exEnd]



  #expressInterestIn:for:sendBack / #retractInterestIn:for:
  interested in a specific change:
                                                                        [exBegin]
     |p b|

     b := [Transcript showCR:'the point changed'].

     p := Point new.
     Transcript showCR:'interest in #foo'.
     p expressInterestIn:#foo for:b sendBack:#value.
     p x:1.
     Transcript showCR:'now changing #bar'.
     p changed:#bar.
     Transcript cr.

     Delay waitForSeconds:1.
     Transcript showCR:'now changing #foo'.
     p changed:#foo.
     Transcript cr.

     Delay waitForSeconds:1.
     Transcript showCR:'no more interest in #foo'.
     p retractInterestIn:#foo for:b.
     Transcript showCR:'now changing #foo'.
     p changed:#foo.
     Transcript cr.

     Delay waitForSeconds:1.
     Transcript showCR:'interest in #bar now'.
     p expressInterestIn:#bar for:b sendBack:#value.
     Transcript showCR:'now changing #foo'.
     p changed:#foo.
     Transcript showCR:'now changing #bar'.
     p changed:#bar.
     Transcript cr.

     Delay waitForSeconds:1.
     Transcript showCR:'interest in #foo now'.
     p expressInterestIn:#foo for:b sendBack:#value.
     Transcript showCR:'now changing #foo'.
     p changed:#foo.
     Transcript showCR:'now changing #bar'.
     p changed:#bar.
     Transcript cr.

     Delay waitForSeconds:1.
     Transcript showCR:'no more interests'.
     p retractInterestsFor:b.
     Transcript showCR:'now changing #foo'.
     p changed:#foo.
     Transcript showCR:'now changing #bar'.
     p changed:#bar.
     Transcript cr.
                                                                        [exEnd]
"
! !

!InterestConverter class methodsFor:'instance creation'!

destination:anObject selector:aSelector
    "create & return an interestConverter, which sends aSelector
     to anObject when a change notification arrives"

    ^ self basicNew destination:anObject selector:aSelector

    "Modified: 21.5.1997 / 11:59:08 / cg"
!

destination:anObject selector:aSelector aspect:aspect
    "create & return an interestConverter, which sends aSelector
     to anObject when a change notification for aspect arrives"

    ^ self basicNew destination:anObject selector:aSelector aspect:aspect

    "Modified: 21.5.1997 / 11:59:26 / cg"
! !

!InterestConverter methodsFor:'accessing'!

aspect
    "return my aspect (if any)"

    ^ aspect

    "Created: 8.3.1996 / 23:00:37 / cg"
    "Modified: 21.5.1997 / 11:59:43 / cg"
!

destination
    ^ destination

    "Created: 7.3.1996 / 10:57:01 / cg"
!

destination:dest selector:sel
    destination := dest.
    selector := sel

    "Created: 7.3.1996 / 10:49:13 / cg"
!

destination:dest selector:sel aspect:a
    destination := dest.
    selector := sel.
    aspect := a

    "Created: 8.3.1996 / 22:42:03 / cg"
!

selector
    ^ selector

    "Created: 7.3.1996 / 10:57:01 / cg"
! !

!InterestConverter methodsFor:'change & update'!

update:something with:aParameter from:someObject
    (aspect isNil or:[aspect == something]) ifTrue:[
        (selector numArgs) == 0 ifTrue:[
            destination perform:selector
        ] ifFalse:[
            destination perform:selector withOptionalArgument:something and:aParameter and:someObject
        ]
    ]

    "Created: 7.3.1996 / 10:14:30 / cg"
    "Modified: 8.3.1996 / 22:41:53 / cg"
! !

!InterestConverter methodsFor:'printing'!

displayString
    ^ self className , '(sending ' , selector storeString , ' to ' , destination printString , ')'
! !

!InterestConverter methodsFor:'testing'!

isInterestConverter
    ^ true
! !

!InterestConverter class methodsFor:'documentation'!

version
    ^ '$Id: InterestConverter.st 10448 2009-06-14 16:10:51Z vranyj1 $'
! !