#========================================================================
# Copyright (C) GemStone Systems Inc. 1986-2005.  All Rights Reserved.
#
# $Id: tutorialWorkspace.txt,v 1.3 2005/03/31 00:28:03 ewinger Exp $
#
#=========================================================================
#
# 	Personal Information Manager
#
# The Personal Information Manager starts as a simple VisualWorks application
# that can use GemStone as a data repository. It is intended for use
# with the GemBuilder for Smalltalk tutorial, shipped as the Acrobat file
# GBS_Tutorial.pdf in the tutorial subdirectory of your GemBuilder 
# installation directory. Please consult this file for instructions 
# on using and redesigning this application to work with GemStone.
#
# The workspace below contains all the expressions and other code 
# you will need to complete the tutorial. Select and execute the expressions,
# or copy and paste the code into a browser as you work,
# to save yourself the labor of typing as well as any confusion
# from possible typographical errors.
#
# Happy exploring! -- the GemBuilder Team
#
########################################################################


	*** CHAPTER 1 ***

***TASK 1.2

System myUserProfile insertDictionary: UserClasses at: 1.

System myUserProfile removeDictionaryAt: 1.

*** TASK 1.3

Array new: 4.

Smalltalk

UserClasses

1 to: 220.

*** TASK 1.4

Bag with: 'string' with: 23 with: 23.

Set with: 'anotherString' with: 856.

Set new addAll: (1 to: 220); yourself.

*** TASK 1.5

GemStoneAdministrator

utilities

todaysDateString
	^Date today asStringUsingFormat: #(2 1 3 $_ 1 2)

UserClasses at: #Administrator put: GemStoneAdministrator new.

Administrator backupDevelopmentServer.

*** TASK 1.6

GBSM currentSession execute: '#abc at: 5'.

	*** CHAPTER 2 ***

*** TASK 2.3

Smalltalk at: #STRainbow put: (Array new: 7).

STRainbow at: 1 put: 'red'; at: 3 put: 'green'; at: 6 put: 'indigo'; yourself.

STRainbow at: 2 put: 'orange'; at: 3 put: 'yellow'; yourself.
STRainbow markDirty.

GSRainbow at: 4 put: 'green'; at: 5 put: 'blue'; at: 7 put: 'violet' ; yourself.

Smalltalk at: #STRainbow put: nil.


	*** CHAPTER 3 ***

*** TASK 3.2

PimManagerUI open

Calendar item:
lunch with Alice
Feb 12
noon
1:30
Bring book you borrowed.

To-Do list item:
Set up meeting with landscaper
Feb 28
Visit library first -- borrow books on roses.

Contact item:
Juan Q. Wan
555-1212
555-2121

*** TASK 3.3

AllUsers userWithId: #PimAdmin.
self collect: [:each | each name ].
AllUsers userWithId: #DataCurator.

*** TASK 3.5

PimUserProfile allUserProfiles.

*** TASK 4.2

For the new class PimScheduleItems:

soleInstance
	^SoleInstance

initialize
	SoleInstance := self new

For PimUserProfile:

initialize
	super initialize.
	scheduleItems := PimScheduleItems soleInstance.
	toDoItems := OrderedCollection new.
	contactItems := OrderedCollection new.

PimUserProfile replaceIndividualSchedulesWithSharedSchedule.

For PimScheduleItemEditUI >> flushAspects new last line:
	mdl user: self user

For PimManagerUI:

updateView
	"Update subcanvas itemDetailView with the UI for the currently selected view."

	| app viewCls spec subcanvas |

	app := (viewCls := self currentViewClass) new.
	app model value: self profile.
	app user: self sessionManager username.
	self mainView: app.
	spec := viewCls interfaceSpecFor: #windowSpec.
	subcanvas := (self builder componentAt: #mainView) widget.
	subcanvas client: app spec: spec.

For PimManagerUI:

apply

	(self mainView)
	user: self sessionManager username;
	flushAspects;
	refreshItemList

For PimScheduleItem:

displayFields
	^#( user date startTime endTime description )

PimManagerUI open.

PimUserProfile allUserProfiles

(PimUserProfile allUserProfiles at: 'PimAdmin') scheduleItems ==
(PimUserProfile allUserProfiles at: 'PimUser1') scheduleItems

*** TASK 4.3

For PimScheduleItems:

querying

scheduleItemsFor: aUser
	^self select: {:each | each.user = aUser}

For PimScheduleItemEditUI:

private

modelCollection
	^PimScheduleItems soleInstance

modelList
	^self model value scheduleItems asOrderedCollection

Smalltalk defineClass: #PimPersonalScheduleItemEditUI
superclass: #(PimScheduleItemEditUI)
indexedType: #none
private: false
instancevariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: ''

For PimPersonalScheduleItemEditUI:

accessing

modelList
	"modelCollection returns either a forwarder if connected to GemStone,
or nil if unconnected. Because the list widget needs a collection,
return an empty one if not logged in."
	^self modelCollection isNil
		ifTrue: [OrderedCollection new]
		ifFalse: [self modelCollection scheduleItemsFor: self user]

For PimScheduleItemEditUI:

actions

addNewItem
	| newModel |
	newModel := self modelClass new.
	self modelCollection add: newModel.
	self itemList list add: newModel.
	self refreshItemList

removeItem
	self modelCollection remove: self itemList selection.
	self itemList list remove: self itemList selection.
	self refreshItemList.

For PimManagerUI class:

viewMenu
	"MenuEditor new openOnClass: self andSelector: #viewMenu"

	<resource: #menu>
	^#(#Menu #(
		#(#MenuItem
			#rawLabel: 'Personal Calendar'
			#nameKey: #PimPersonalScheduleItemEditUI
			#value: #PimPersonalScheduleItemEditUI )
		#(#MenuItem
			#rawLabel: 'Shared Calendar'
			#nameKey: #PimScheduleItemEditUI
			#value: #PimScheduleItemEditUI )
		#(#MenuItem
			#rawLabel: 'To Do List'
			#nameKey: #PimToDoItemEditUI
			#value: #PimToDoItemEditUI )
		#(#MenuItem
			#rawLabel: 'Contacts'
			#nameKey: #PimContactItemEditUI
			#value: #PimContactItemEditUI ) ) #(4 ) nil )
	decodeAsLiteralArray

	*** END OF TUTORIAL WORKSPACE ***