IndirectValue.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Aug 2003 12:38:04 +0200
changeset 1796 26780a84bcad
child 1797 88aea9574f9d
permissions -rw-r--r--
initial checkin

"{ Package: 'stx:libview2' }"

ValueModel subclass:#IndirectValue
	instanceVariableNames:'valueHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Support-Models'
!

!IndirectValue class methodsFor:'documentation'!

documentation
"
    IndirectValue referes to another valueHolder and presents that holders value
    as my own value.
    However, the holder can be changed, which results in a change message from myself.
    Can be used if a valueHolder is needed which represents different values over
    time, for example, a line/column holder for a notebook-like multi-codeView 
    application, where the line/col holder is switched whenever the tab is switched.
    (use an IndirectValue as holder of the line/col labels).

    [author:]
        Claus Gittinger
"
!

examples
"
    a label alternatively showing the value of 2 other valueHolders:
                                                                        [exBegin]
        |holder1 holder2 indirVal lbl|

        holder1 := '1' asValue.
        holder2 := '2' asValue.
        indirVal := IndirectValue for:holder1.

        lbl := Label new.
        lbl labelChannel:indirVal.
        lbl open.
        lbl waitUntilVisible.
        
        Delay waitForSeconds:2.
        indirVal valueHolder:holder2.

        Delay waitForSeconds:2.
        indirVal valueHolder:holder1.
                                                                        [exEnd]
"
! !

!IndirectValue class methodsFor:'instance creation'!

for:aValueHolder
    "return a new IndirectValue presenting aValueHolder"

    ^ self new setValueHolder:aValueHolder
! !

!IndirectValue methodsFor:'accessing'!

setValue:newValue 
    "physically set my value, without change notifications"

    valueHolder setValue:newValue
!

setValueHolder:aValueHolder
    "change my holder"

    valueHolder notNil ifTrue:[
        valueHolder removeDependent:self.
    ].
    valueHolder := aValueHolder.
    valueHolder notNil ifTrue:[
        valueHolder addDependent:self.
    ].
!

value 
    "return my value"

    ^ valueHolder value
!

valueHolder:aValueHolder
    "change my holder"

    |oldValue|

    oldValue := valueHolder value.
    self setValueHolder:aValueHolder.
    oldValue ~~ valueHolder value ifTrue:[
        self changed:#value
    ].
! !

!IndirectValue methodsFor:'change and update'!

update:something with:aParameter from:someone
    "the holder I depend on has changed - send a change notification to my dependents"

    self changed:#value
! !

!IndirectValue class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/IndirectValue.st,v 1.1 2003-08-28 10:38:04 cg Exp $'
! !