View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Working with Datasets - Miguel Lloreda

Datasets are extremely nice to work with - I found them a lot neater and easier to use that the usual list widget. I decided to write this little tutorial because I remember running into some silly problems when trying to get my Datasets to work in one of the assignments. I looked_everywhere_and nothing helped so maybe this will be able to benefit some of you guys.

You can add and install a Dataset just like any other widget from the palette, however, there are a couple of things you need to do to make your Dataset work just like you want. In my example Dataset, I am displaying each a student's name, id, and status. Things may be different in your situation but as far as my example goes, this means that a student should have variables for a name, id, and status.

Given this information, you need to create your desired columns. Then you need to ctrl+click each column and edit a couple of things - if done correctly, the Dataset should look like so:

selIdRow.png

Now looking at your GUI Painter Tool window, the first thing that should be done is to edit the 'String' textbox - whatever you put here is what will be displayed on top of your Dataset column for the user to see. Last thing you need to change is the 'Aspect' textbox. Your window should look like this:

As you can see, the changes pertain to a student's id variable.
idRow.png


For consistency purposes, here is what it looks like for a student's name variable.
nameRow.png


Once you're done with the steps above, make sure your code looks like the code below.

Here is what the getter for the Dataset widget should look like - it returns any selection made in the data set. Note that I named the widget with "dataSet".

dataSet

	^dataSet isNil
		ifTrue:
			[dataSet :=  SelectionInList new.
			dataSet selectionIndexHolder compute:
				[:v |
				self selectedRow value: dataSet selection].
			dataSet]
		ifFalse:
			[dataSet]



Next up is to add the following line to the end of your model method in order to keep your Dataset and model in sync. Be sure to make any changes in respect to your own variable names and such.

"This aspect adaptor automatically updates the students collection."
	self dataSet listHolder:((UI.AspectAdaptor subject: model sendsUpdates: true) forAspect: #students).




At last, if you have a button to add a new object to your data set - which, you probably should ;) - don't forget to include an addRow method. Remember to have your button use this method!

addRow

	"This method adds a row to the Dataset, esentially adding a new student to a course."
	(dataSet list) add: Student new.
	model changed: #students.



I hope I've covered everything and I hope this tutorial is of help to future classes!

Link to this Page