'From VisualWorks(TM), Release 1.0 of 8 October 1992 on 7 May 1997 at 12:32:23 pm'!Model subclass: #ContactManager instanceVariableNames: 'contacts names currentName company phone ' classVariableNames: '' poolDictionaries: '' category: 'ContactManager Project'! ContactManager comment: 'Instances of this class are able to track business contacts. They keep track of the name, company affiliation, and phone number. New contacts can be added, and old ones can be removed. Instance Variables contacts
associates a name which is the key with an array containing a company and a phone number names key values in contacts variable currentName currently selected name company company associated with currentName phone phone number associated with currentName '! !ContactManager methodsFor: 'initialize-release'!
initialize (contacts := Dictionary new) add: ('Jobs, Steve'->#('Next Computer' '332-9803')); add: ('West, Mae'->#('Playtex Inc.' '445-9063')); add: ('Adams, Gomez'->#('Independent Eccentric' '999-1313')). names := contacts keys asSortedCollection.! !
!ContactManager methodsFor: 'accessing'!
company ^company!
company: aString | array | company := aString. array := self contacts at: self currentName ifAbsent: [Array new: 2]. array at: 1 put: aString. ^true!
contacts ^contacts!
currentName ^currentName!
currentName: aString "When the currently selected name changes, set the fields to their new values and update views." | array | currentName := aString. array := self contacts at: aString ifAbsent: [Array new: 2]. self company: (array at: 1). self changed: #company. self phone: (array at: 2). self changed: #phone!
names ^names!
names: aCollection "Set the names variable to aCollection and notify the views that the names list has changed." names := aCollection. self changed: #names!
phone ^phone!
phone: aString | array | phone := aString. array := self contacts at: self currentName ifAbsent: [Array new: 2]. array at: 2 put: aString. ^true! !
!ContactManager methodsFor: 'actions'!
add "Use a dialog to prompt the user for a new contact name. Update the contacts dictionary, the currentName, and the names collection appropriately." | reply | (reply := DialogView request: 'Name of new contact') isEmpty ifTrue: [^nil]. self contacts at: reply put: (Array new: 2). self currentName: reply. self names: self contacts keys asSortedCollection.!
delete "Make sure the user wants to remove the current contact and then update the contacts dictionary, currentName, and names collection appropriately." self currentName isNil ifTrue: [^nil]. (DialogView confirm: 'Remove this contact?') ifFalse: [^nil]. self contacts removeKey: self currentName. self currentName: nil. self names: self contacts keys asSortedCollection! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
ContactManager class instanceVariableNames: ''!
!ContactManager class methodsFor: 'interface opening'!
open "self open" ^self openOn: self new!
openOn: aContactManager "Open a user interface for the model aContactManager." | window component view layout wrapper | window := ScheduledWindow new model: aContactManager; label: 'Contact Manager'; minimumSize: 300@150. component := CompositePart new. view := SelectionInListView on: aContactManager aspect: #names change: #currentName: list: #names menu: nil initialSelection: #currentName. layout := LayoutFrame leftFraction: 0.0 offset: 10 rightFraction: 0.5 offset: -10 topFraction: 0.0 offset: 10 bottomFraction: 1.0 offset: -10. wrapper := LookPreferences edgeDecorator on: view. component add: wrapper in: layout. view := 'Company' asText allBold asComposedText. layout := LayoutFrame leftFraction: 0.5 offset: 10 rightFraction: 1.0 offset: -10 topFraction: 0.0 offset: 10 bottomFraction: 0.0 offset: 31. component add: view in: layout. view := TextView on: aContactManager aspect: #company change: #company: menu: nil. view controller initializeMenuForText. layout := LayoutFrame leftFraction: 0.5 offset: 10 rightFraction: 1.0 offset: -10 topFraction: 0.0 offset: 30 bottomFraction: 0.0 offset: 56. wrapper := (LookPreferences edgeDecorator on: view) noVerticalScrollBar. component add: wrapper in: layout. view := 'Phone Number' asText allBold asComposedText. layout := LayoutFrame leftFraction: 0.5 offset: 10 rightFraction: 1.0 offset: -10 topFraction: 0.5 offset: -15 bottomFraction: 0.5 offset: 6. component add: view in: layout. view := TextView on: aContactManager aspect: #phone change: #phone: menu: nil. view controller initializeMenuForText. layout := LayoutFrame leftFraction: 0.5 offset: 10 rightFraction: 1.0 offset: -10 topFraction: 0.5 offset: 4 bottomFraction: 0.5 offset: 29. wrapper := (LookPreferences edgeDecorator on: view) noVerticalScrollBar. component add: wrapper in: layout. view := Button trigger model: ((PluggableAdaptor on: aContactManager) performAction: #add); label: 'Add'. layout := LayoutFrame leftFraction: 0.5 offset: 10 rightFraction: 0.5 offset: 70 topFraction: 1.0 offset: -40 bottomFraction: 1.0 offset: -10. wrapper := BoundedWrapper on: view. component add: wrapper in: layout. view := Button trigger model: ((PluggableAdaptor on: aContactManager) performAction: #delete); label: 'Delete'. layout := LayoutFrame leftFraction: 1.0 offset: -70 rightFraction: 1.0 offset: -10 topFraction: 1.0 offset: -40 bottomFraction: 1.0 offset: -10. wrapper := BoundedWrapper on: view. component add: wrapper in: layout. window component: component. ^window open.! !
!ContactManager class methodsFor: 'instance creation'!
new ^super new initialize! !
News Page | CS2390 Sum'97 Home Page | MMC-CaMILE | STABLE
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 7/16/97; 10:15:11 AM