'From Squeak6.0alpha of 6 January 2018 [latest update: #17660] on 16 January 2018 at 12:20:20 pm'!
Model subclass: #MyBusinessModel
	instanceVariableNames: 'username date message mail password'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Example'!

!MyBusinessModel methodsFor: 'ui building' stamp: 'mt 1/16/2018 12:18'!
buildWith: builder

	| window nameField dateField mailField messageField passwordField button fieldHeight numFields |
	
	fieldHeight := TextStyle defaultFont height * 1.5. "Height of input field to be used to layout calculation." 
	numFields := 4. "Also used for layout calculation."
	
	window := builder pluggableWindowSpec new
		model: self;
		label: 'My Business Application';
		spacing: 5;
		children: OrderedCollection new.
		
	nameField := builder pluggableInputFieldSpec new
		model: self;
		getText: #username;
		setText: #username:;
		help: 'Username';
		frame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (0@ (fieldHeight + window spacing * 0) corner: 0@(fieldHeight + window spacing * 1)));
		yourself.
	window children add: nameField.

	dateField := builder pluggableInputFieldSpec new
		model: self;
		getText: #date;
		setText: #date:;
		help: 'Date';
		frame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (0@ (fieldHeight + window spacing * 1) corner: 0@(fieldHeight + window spacing * 2)));
		yourself.
	window children add: dateField.

	mailField := builder pluggableInputFieldSpec new
		model: self;
		getText: #mail;
		setText: #mail:;
		help: 'E-Mail address';
		editText: #checkMail:;
		frame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (0@ (fieldHeight + window spacing * 2) corner: 0@(fieldHeight + window spacing * 3)));
		yourself.
	window children add: mailField.

	passwordField := builder pluggableInputFieldSpec new
		model: self;
		getText: #password;
		setText: #password:;
		font: (StrikeFont passwordFontSize: 12);
		help: 'Password';
		frame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (0@ (fieldHeight + window spacing * 3) corner: 0@(fieldHeight + window spacing * 4)));
		yourself.
	window children add: passwordField.

	messageField := builder pluggableTextSpec new
		model: self;
		getText: #message;
		setText: #message:;
		help: 'Type your multi-line message here...';
		frame: (LayoutFrame fractions: (0@0 corner: 1@1) offsets: (0 @ ((fieldHeight + window spacing) * numFields) corner: 0@fieldHeight negated));
		yourself.
	window children add: messageField.
	
	button := builder pluggableButtonSpec new
		model: self;
		label: 'Accept';
		action: #accept;
		frame: (LayoutFrame fractions: (0@1 corner: 1@1) offsets: (0 @ fieldHeight negated corner: 0@0));
		yourself.
	window children add: button.
		
	^ builder build: window! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 12:13'!
checkMail: aText
	
	| tokens |
	tokens := aText asString findTokens: '@'.
	
	tokens ifEmpty: [^ self mail: ''].
	tokens size = 1 ifTrue: [^ self mail: tokens first].

	self mail: tokens first, '@', tokens second.! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 12:09'!
date
	
	^ date printString
! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 12:09'!
date: anObject
	
	date := Date fromString: anObject.
	self changed: #date.! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:21'!
mail
	
	^ mail
! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:21'!
mail: anObject
	
	mail := anObject.
	self changed: #mail.! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:15'!
message
	
	^ message
! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:15'!
message: anObject
	
	message := anObject.
	self changed: #message.! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:21'!
password
	
	^ password
! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:21'!
password: anObject
	
	password := anObject.
	self changed: #password.! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:11'!
username
	
	^ username
! !

!MyBusinessModel methodsFor: 'accessing' stamp: 'mt 1/16/2018 11:12'!
username: anObject
	
	username := anObject.
	self changed: #username.
! !

!MyBusinessModel methodsFor: 'callbacks' stamp: 'mt 1/16/2018 12:18'!
accept

	self inform: ('{1} ({2}password set)\{3}\{4}\\{5}' withCRs format: {
		self username.
		self password ifNotEmpty: [''] ifEmpty: ['no '].
		self date.
		self mail.
		self message
	}).! !

!MyBusinessModel methodsFor: 'initialize-release' stamp: 'mt 1/16/2018 12:10'!
initialize

	super initialize.
	
	self date: '01/01/2018'.
	self mail: ''.
	self message: ''.
	self password: ''.
	self username: 'James Bond'.! !


!MyBusinessModel class methodsFor: 'as yet unclassified' stamp: 'mt 1/16/2018 11:11'!
open

	^ ToolBuilder open: self new! !


!MyBusinessModel reorganize!
('ui building' buildWith:)
('accessing' checkMail: date date: mail mail: message message: password password: username username:)
('callbacks' accept)
('initialize-release' initialize)
!

