Thanks sven for your spirit and attittude. I should say that if people would have more your attitude I would fell much better. Yes indeed I'm down because of people wanting always more and not putting a drop of energy on the table. PS: I turned your mail into a spec future book chapter :) Le 13/2/15 00:53, Sven Van Caekenberghe a écrit :
t turns out it only takes 3 methods and some boilerplate code that is mostly auto generated.
0. Make a subclass of ComposableModel with instance variables for the UI elements that we need
ComposableModel subclass: #LoginModel instanceVariableNames: 'usernameLabel usernameField passwordLabel passwordField' classVariableNames: '' category: '_UnpackagedPackage'
1. Specify the layout of the UI
LoginModel class>>#defaultSpec <spec: #default>
^ SpecLayout composed newColumn: [ :col | col newRow: [ :row | row add: #usernameLabel width: 80; add: #usernameField ] height: self inputTextHeight; newRow: [ :row | row add: #passwordLabel width: 80; add: #passwordField ] height: self inputTextHeight ]; yourself
2. Build the UI elements
LoginModel>>#initializeWidgets usernameLabel := self newLabel. usernameLabel text: 'Username'. usernameField := self newTextInput. usernameField autoAccept: true; ghostText: 'john@acme.com'. passwordLabel := self newLabel. passwordLabel text: 'Password'; yourself. passwordField := self newTextInput. passwordField beEncrypted; autoAccept: true; ghostText: '******'. self focusOrder add: usernameField; add: passwordField
3. Open the UI as modal dialog
LoginModel class>>#getCredentials "self getCredentials"
| login dialog | login := self new. dialog := login openDialogWithSpec. dialog modalRelativeTo: self currentWorld. dialog cancelled ifTrue: [ ^ nil ]. ^ login credentials
X. Some boilerplate code
Auto-generate read accessors for the 4 instance variables.
LoginModel>>#title ^ 'Login'
LoginModel>>#initialExtent ^ 350 @ 150
LoginModel>>#credentials ^ usernameField text -> passwordField text
I think this is pretty cool. I really can't imagine how much easier, how much less code this should take.