InterestConverter.st
author penk
Fri, 13 Jun 2003 12:54:57 +0200
changeset 7347 1c4e0be2c4f0
parent 6056 5406d407a9bb
child 8436 4a9e5fbe67e5
permissions -rw-r--r--
add access method for selector

"
 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:[
        destination perform:selector
    ]

    "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 class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/InterestConverter.st,v 1.11 2003-06-13 10:54:57 penk Exp $'
! !