home *** CD-ROM | disk | FTP | other *** search
/ European Smalltalk User Group 2004 September / esugcd.iso / Books-Tutorial-Lectures / Tutorials / vw-tutorials / AnApplikationAproach / PhoneBook.st < prev    next >
Encoding:
Text File  |  1995-10-26  |  6.8 KB  |  290 lines

  1. Object subclass: #Customer
  2.     instanceVariableNames: 'name number '
  3.     classVariableNames: ''
  4.     poolDictionaries: ''
  5.     category: 'UIApplications-New'!
  6. Customer comment:
  7. 'This class defines "customers" for a phone book listing.  Each customer has a name and
  8. a phone number.'!
  9.  
  10.  
  11. !Customer methodsFor: 'operators'!
  12.  
  13. <= aCustomer
  14.     ^self name <= aCustomer name! !
  15.  
  16. !Customer methodsFor: 'printing'!
  17.  
  18. printOn: aStream
  19.     aStream nextPutAll:  name , ' - ' , number displayString! !
  20.  
  21. !Customer methodsFor: 'accessing'!
  22.  
  23. name
  24.     ^name!
  25.  
  26. name: aName
  27.     name := aName!
  28.  
  29. number
  30.     ^number!
  31.  
  32. number: aNumber
  33.     number := aNumber! !
  34.  
  35. !Customer methodsFor: 'private'!
  36.  
  37. show
  38.     "internal display method"
  39.  
  40.     Transcript cr; show: name; show: ' - '; show: number displayString; cr! !
  41. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  42.  
  43. Customer class
  44.     instanceVariableNames: ''!
  45.  
  46.  
  47. !Customer class methodsFor: 'initialize'!
  48.  
  49. name: aName number: aNumber
  50.     "create a new customer (initialized)"
  51.  
  52.     |newCustomer|
  53.  
  54.     newCustomer := super new name: aName.
  55.       newCustomer number: aNumber.
  56.      ^newCustomer!
  57.  
  58. new
  59.     "create a new customer"
  60.  
  61.     |newCustomer|
  62.  
  63.     newCustomer := super new name: ''.
  64.       newCustomer number: 0.
  65.      ^newCustomer! !
  66.  
  67. Model subclass: #PhoneBook
  68.     instanceVariableNames: 'whitepages '
  69.     classVariableNames: ''
  70.     poolDictionaries: ''
  71.     category: 'UIApplications-New'!
  72. PhoneBook comment:
  73. 'This class defines a phone book consisting of a list of Customers.'!
  74.  
  75.  
  76. !PhoneBook methodsFor: 'transactions'!
  77.  
  78. addCustomer: aCustomer
  79.  
  80.     self whitepages add: aCustomer!
  81.  
  82. deleteCustomer: aCustomer
  83.  
  84.     self whitepages remove: aCustomer! !
  85.  
  86. !PhoneBook methodsFor: 'accessing'!
  87.  
  88. whitepages
  89.     ^whitepages! !
  90.  
  91. !PhoneBook methodsFor: 'initialize'!
  92.  
  93. initialize
  94.     whitepages := SortedCollection new! !
  95.  
  96. !PhoneBook methodsFor: 'private'!
  97.  
  98. show
  99.     "internal display method"
  100.     Transcript cr.
  101.     whitepages do: [:customer | 
  102.         Transcript show: customer name; show: ' - '; show: customer number displayString; cr.].
  103.     Transcript cr! !
  104. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  105.  
  106. PhoneBook class
  107.     instanceVariableNames: ''!
  108.  
  109.  
  110. !PhoneBook class methodsFor: 'initialize'!
  111.  
  112. new
  113.     ^super new initialize! !
  114.  
  115. ApplicationModel subclass: #PhoneBookInterface
  116.     instanceVariableNames: 'phoneList phonebook phoneHolder '
  117.     classVariableNames: ''
  118.     poolDictionaries: ''
  119.     category: 'UIApplications-New'!
  120. PhoneBookInterface comment:
  121. 'This class defines an interface for a phone book listing.'!
  122.  
  123.  
  124. !PhoneBookInterface methodsFor: 'aspects'!
  125.  
  126. phoneHolder
  127.     "This method was generated by UIDefiner.  Any edits made here
  128.     may be lost whenever methods are automatically defined.  The
  129.     initialization provided below may have been preempted by an
  130.     initialize method."
  131.  
  132.     ^phoneHolder isNil
  133.         ifTrue:
  134.             [phoneHolder := Customer new asValue]
  135.         ifFalse:
  136.             [phoneHolder]!
  137.  
  138. phoneList
  139.     "This method was generated by UIDefiner.  Any edits made here
  140.     may be lost whenever methods are automatically defined.  The
  141.     initialization provided below may have been preempted by an
  142.     initialize method."
  143.  
  144.     ^phoneList isNil
  145.         ifTrue:
  146.             [phoneList := SelectionInList with: phonebook whitepages]
  147.         ifFalse:
  148.             [phoneList]! !
  149.  
  150. !PhoneBookInterface methodsFor: 'actions'!
  151.  
  152. addCustomer
  153.  
  154.     |accepted newCustomer|
  155.  
  156.     phoneHolder := nil.
  157.     accepted := self openDialogInterface: #dialogSpec. 
  158.     accepted ifTrue: [
  159.         newCustomer := Customer name: phoneHolder value name
  160.                                               number: phoneHolder value number.
  161.         phonebook addCustomer: newCustomer.   
  162.         self phoneList list: phonebook whitepages]!
  163.  
  164. deleteCustomer
  165.  
  166.     self phoneList selection isNil
  167.         ifTrue: [^Dialog warn: 'Select a customer to delete.'].
  168.     phonebook deleteCustomer: self phoneList selection.
  169.     self phoneList list: phonebook whitepages!
  170.  
  171. updateCustomer
  172.  
  173.     |accepted updatedCustomer|
  174.  
  175.     self phoneList selection isNil
  176.         ifTrue: [^Dialog warn: 'Select a customer to update.'].
  177.     self phoneHolder value: self phoneList selection.
  178.     accepted := self openDialogInterface: #dialogSpec.
  179.     accepted ifTrue: [
  180.         phonebook deleteCustomer: self phoneList selection.
  181.         updatedCustomer := Customer name: phoneHolder value name
  182.                                                     number: phoneHolder value number.
  183.         phonebook addCustomer: updatedCustomer.
  184.         self phoneList list: phonebook whitepages]! !
  185.  
  186. !PhoneBookInterface methodsFor: 'initialize'!
  187.  
  188. initialize
  189.     phonebook := PhoneBook new! !
  190. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  191.  
  192. PhoneBookInterface class
  193.     instanceVariableNames: ''!
  194.  
  195.  
  196. !PhoneBookInterface class methodsFor: 'interface specs'!
  197.  
  198. dialogSpec
  199.     "UIPainter new openOnClass: self andSelector: #dialogSpec"
  200.  
  201.     <resource: #canvas>
  202.     ^#(#FullSpec 
  203.         #window: 
  204.         #(#WindowSpec 
  205.             #label: 'Add/Update' 
  206.             #bounds: #(#Rectangle 631 473 1084 677 ) ) 
  207.         #component: 
  208.         #(#SpecCollection 
  209.             #collection: #(
  210.                 #(#InputFieldSpec 
  211.                     #layout: #(#Rectangle 172 23 292 49 ) 
  212.                     #model: #'phoneHolder number' 
  213.                     #type: #number 
  214.                     #formatString: '(000) 000-0000' ) 
  215.                 #(#InputFieldSpec 
  216.                     #layout: #(#Rectangle 123 77 423 106 ) 
  217.                     #model: #'phoneHolder name' ) 
  218.                 #(#LabelSpec 
  219.                     #layout: #(#Point 55 29 ) 
  220.                     #label: 'Phone Number:' ) 
  221.                 #(#LabelSpec 
  222.                     #layout: #(#Point 9 84 ) 
  223.                     #label: 'Customer Name:' ) 
  224.                 #(#DividerSpec 
  225.                     #layout: #(#Rectangle 16 136 434 140 ) ) 
  226.                 #(#ActionButtonSpec 
  227.                     #layout: #(#Rectangle 82 158 140 192 ) 
  228.                     #model: #accept 
  229.                     #label: 'OK' 
  230.                     #defaultable: true ) 
  231.                 #(#ActionButtonSpec 
  232.                     #layout: #(#Rectangle 302 156 362 194 ) 
  233.                     #model: #cancel 
  234.                     #label: 'Cancel' 
  235.                     #defaultable: true ) ) ) )!
  236.  
  237. windowSpec
  238.     "UIPainter new openOnClass: self andSelector: #windowSpec"
  239.  
  240.     <resource: #canvas>
  241.     ^#(#FullSpec 
  242.         #window: 
  243.         #(#WindowSpec 
  244.             #label: 'ClemsonBell White Pages' 
  245.             #bounds: #(#Rectangle 618 490 1065 806 ) 
  246.             #flags: 4 
  247.             #menu: #menuBar ) 
  248.         #component: 
  249.         #(#SpecCollection 
  250.             #collection: #(
  251.                 #(#SequenceViewSpec 
  252.                     #layout: #(#Rectangle 36 64 420 238 ) 
  253.                     #model: #phoneList ) 
  254.                 #(#ActionButtonSpec 
  255.                     #layout: #(#Rectangle 98 254 162 288 ) 
  256.                     #model: #updateCustomer 
  257.                     #label: 'Update' 
  258.                     #defaultable: true ) 
  259.                 #(#ActionButtonSpec 
  260.                     #layout: #(#Rectangle 279 255 342 290 ) 
  261.                     #model: #deleteCustomer 
  262.                     #label: 'Delete' 
  263.                     #defaultable: true ) 
  264.                 #(#LabelSpec 
  265.                     #layout: #(#Point 36 29 ) 
  266.                     #label: 'Phone Listing' ) ) ) )! !
  267.  
  268. !PhoneBookInterface class methodsFor: 'resources'!
  269.  
  270. menuBar
  271.     "UIMenuEditor new openOnClass: self andSelector: #menuBar"
  272.  
  273.     <resource: #menu>
  274.     ^#(#Menu #(
  275.             #(#MenuItem 
  276.                 #label: 'File' 
  277.                 #submenu: #(#Menu #(
  278.                         #(#MenuItem 
  279.                             #label: 'Exit' ) ) #(1 ) #(#closeRequest ) ) ) 
  280.             #(#MenuItem 
  281.                 #label: 'Phone' 
  282.                 #submenu: #(#Menu #(
  283.                         #(#MenuItem 
  284.                             #label: 'Add' ) 
  285.                         #(#MenuItem 
  286.                             #label: 'Update' ) 
  287.                         #(#MenuItem 
  288.                             #label: 'Delete' ) ) #(3 ) #(#addCustomer #updateCustomer #deleteCustomer ) ) ) ) #(2 ) #(nil nil ) ) decodeAsLiteralArray! !
  289.  
  290.