ValModel.st
author Claus Gittinger <cg@exept.de>
Tue, 20 Feb 1996 19:24:36 +0100
changeset 163 80f4fe3bcc71
parent 143 ae38792bd85c
child 175 df08e5b663d0
permissions -rw-r--r--
care for interrupts while adding/removing dependents

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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.
"

Model subclass:#ValueModel
	 instanceVariableNames:'accepted interest'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Interface-Support-Models'
!

!ValueModel class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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
"
    abstract superclass for ValueHolders and Adaptors.
    It does not itself know how and where the value is stored,
    but knows about interested objects (which get informed, whenever
    the value changes) and keeps track if the value was ever accepted.

    Notice: this class was implemented using protocol information
    from alpha testers - it may not be complete or compatible to
    the corresponding ST-80 class. If you encounter any incompatibilities,
    please forward a note to the ST/X team.

    subclasses must redefine: #setValue: and #value
    (and optionally redefine #value:)
"
! !

!ValueModel class methodsFor:'instance creation'!

new
    ^ (super new) initialize
! !

!ValueModel methodsFor:'accessing'!

accept
    accepted := true
!

accepted
    ^ accepted
!

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

    ^ self subclassResponsibility
!

value 
    "return my value"

    ^ self subclassResponsibility
!

value:anObject
    "set my value, if it changed, send change notifications to my dependents."

    |oldValue|

    oldValue := self value.
    self setValue:anObject.
    anObject ~= oldValue ifTrue:[
	"/ self notifyChange:#value
	self changed:#value
    ]
! !

!ValueModel methodsFor:'change notification'!

changed:aSymbol
    "notify my dependents and those that are interested"

    interest notNil ifTrue:[
	interest keysAndValuesDo:[:someone :selector |
	    someone perform:selector
	].
    ].
    super changed:aSymbol
! !

!ValueModel methodsFor:'initialization'!

initialize
    accepted := false
! !

!ValueModel methodsFor:'interest'!

onChangeSend:selector to:someone
    "add an interest, arranging that
     a message with selector will be sent to someone 
     when my value changes."

    interest isNil ifTrue:[
	interest := IdentityDictionary new
    ].
    interest at:someone put:selector
!

retractInterestsFor:someone
    "release interest i.e. do no longer send changeMsg to changeReceiver
     iff someone is the changeReceiver.
     This can be used to (temporarily) turn off information sends,
     to break endless cycles (if two values change each other)"

    interest notNil ifTrue:[
	interest removeKey:someone ifAbsent:nil
    ]
! !

!ValueModel class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/Attic/ValModel.st,v 1.14 1995-12-15 13:02:23 cg Exp $'
! !