Now that you have implemented open, you can implement the remaining ten methods of class Chooser. The first seven methods define different parts of the user interface. The remaining three methods add items to a list box and perform functions when a push button is pressed or when the window closes.
Method createWindow
Method createWindow defines the window for DevelopChooser. To implement the method, do the following:
Method createWindow
createWindow "Private - Creates a window." shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w width: 220; height: 175]. shell title: 'Applications'; addCallback: XmNdestroyCallback receiver: self selector: #destroyCallback:clientData:callData: "Call if window closes" clientData: nil.
Follow the above steps to create the following six more methods for the Window Creation category.
Method createForm
createForm "Private - Creates a form to hold other user interface elements." widgetManager := shell createForm: 'widgetManager' "Positions the label, list box, and button" argBlock: nil. widgetManager manageChild.
Method createLabel
createLabel "Private - Creates a label." instructions := widgetManager createLabel: 'Select an application: ' argBlock: [:w | w marginHeight: 10; leftAttachment: XmATTACHFORM; topAttachment: XmATTACHFORM ; rightAttachment: XmATTACHFORM]. instructions manageChild.
Method createList
createList "Private - Creates a list box to hold application names." listBox := widgetManager "Define a list box." createScrolledList: 'listBox' argBlock: [:w | w items: self addApplicationsToList; "Add list of applications" visibleItemCount: 5; selectionPolicy: XmEXTENDEDSELECT]. listBox parent topAttachment: XmATTACHWIDGET; topWidget: instructions; leftAttachment: XmATTACHFORM; rightAttachment: XmATTACHFORM. listBox addCallback: XmNdefaultActionCallback receiver: self selector: #executeCallback:clientData:callData: "Call if button pressed" clientData: nil. listBox manageChild.
Method createButton
createButton "Private - Define a push button." openButton := widgetManager createPushButton: 'Open' argBlock: [:w | w leftAttachment: XmATTACHFORM; topAttachment: XmATTACHWIDGET; topWidget: listBox; rightAttachment: XmATTACHFORM; bottomAttachment: XmATTACHFORM]. openButton alignment: XmALIGNMENTCENTER; addCallback: XmNactivateCallback receiver: self selector: #executeCallback:clientData:callData: clientData: nil; manageChild.
Method displayWindow
displayWindow "Private - Show the window." shell realizeWidget.
Method setCursorBusy
setCursorBusy "Private - Create a cursor." busyCursor := shell display createFontCursor: XCWatch.
Method addApplicationsToList
Method addApplicationsToList defines what application names are shown in the list box. To implement it, do the following:
addApplicationsToList "Private - Answer a list of application classes to go into the list box." ^#( Stopwatch TextEditor TimeLogger) select: [:className | (Smalltalk classAt: className asSymbol) notNil]
Stopwatch, TextEditor, and TimeLogger are the names of main classes in other applications that you can create by completing the examples in this book.
Method destroyCallback:clientData:callData:
The method destroyCallback:clientData:callData: enables you to close the window for DevelopChooser when you are finished using it. To implement the method, do the following:
destroyCallback: aWidget clientData: clientData callData: callData "Private - The receiver has been destroyed, free all resources." busyCursor freeCursor
Method executeCallback:clientData:callData:
The method executeCallback:clientData:callData: enables you to open one of the applications named in the list box. To implement the method, do the following:
executeCallback: aWidget clientData: aString callData: callData "Private - Open the selected application." listBox selectedItems do: [:className | (Smalltalk classAt: className asSymbol) new open].
Note the words new open in this method. The classes
Chooser, Stopwatch, TextEditor, and
TimeLogger, when completed, each open an instance when their class
name followed by new open is evaluated in a Transcript or Workspace
window.
![]() | If you are using views created with the Composition Editor, you can generally open the views by replacing new open with newPart openWidget. |