Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!fnnews.fnal.gov!nntp-server.caltech.edu!news.claremont.edu!paris.ics.uci.edu!csulb.edu!csus.edu!netcom.com!lovejoya
From: lovejoya@netcom.com (Alan Lovejoy)
Subject: Re: VW2.0 Datasets Questions
Message-ID: <lovejoyaD6CD3F.5zn@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <3lbtui$s63@news.duke.edu>
Date: Sat, 1 Apr 1995 05:40:27 GMT
Lines: 286
Sender: lovejoya@netcom18.netcom.com

Ju-Sung Lee (lee00074@mc.duke.edu) wrote:

>Where can I go if I need to find out more information
>about datasets?  Specifically I need to find out 
>ways to dynamically modify it (e.g. add columns to
>it programatically).

>Please e-mail replies to: lee00074@mc.duke.edu

>Thanks in advance for your replies.

>Ju-Sung Lee
>lee00074@mc.duke.edu

Here is an example that does what you want:

ApplicationModel subclass: #DataSetDemo
	instanceVariableNames: 'selectionInList selectedRow columnDescriptors '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Test'!


!DataSetDemo methodsFor: 'aspects'!

selectedRow
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^selectedRow isNil
		ifTrue:
			[selectedRow := nil asValue]
		ifFalse:
			[selectedRow]!

selectionInList
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

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

!DataSetDemo methodsFor: 'events'!

windowEvent: anEvent from: anApplicationWindow 
	"The default response of an ApplicationModel to receiving an event 
	from one of its windows is to propagate it as an update to its 
	dependents."

	super windowEvent: anEvent from: anApplicationWindow.
	anEvent key == #bounds ifTrue: [self updateDataSetColumnWidths]! !

!DataSetDemo methodsFor: 'initialize-release'!

initialize
	self selectionInList list: (ColorValue constantNames collect: [:name | ColorValue perform: name])! !

!DataSetDemo methodsFor: 'interface opening'!

postBuildWith: aBuilder 
	"This message is sent by the builder when it has completed work on 
	either a complete window or a SubCanvas."

	self updateDataSetColumnWidths.
	(self builder window) sendWindowEvent: #bounds; application: self! !

!DataSetDemo methodsFor: 'private'!

columnDescriptors
	columnDescriptors == nil ifTrue: [columnDescriptors := self computeDataSetColumnDescriptors].
	^columnDescriptors!

computeDataSetColumnDescriptors
	"This message is sent by the builder prior to beginning construction 
	of either a SubCanvas or a complete window."

	| widths cd |
	widths := self computeDataSetColumnWidths.
	cd := Array new: 4.
	cd at: 1 put: (((DataSetColumnSpec new) 
		label: 'Hue';
		model: #'selectedRow hue';
		width: (widths at: 1); 
		noScroll: false; 
		font: #system; 
		rendererType: #Text; 
		editorType: #InputField; 
		alignment: #right; 
		type: #number) columnWithBuilder: self builder).
	cd at: 2 put: (((DataSetColumnSpec new) 
		label: 'Saturation';
		model: #'selectedRow saturation';
		width: (widths at: 2); 
		noScroll: false; 
		font: #system; 
		rendererType: #Text; 
		editorType: #InputField; 
		alignment: #right; 
		type: #number) columnWithBuilder: self builder).
	cd at: 3 put: (((DataSetColumnSpec new) 
		label: 'Luminance';
		model: #'selectedRow luminance';
		width: (widths at: 3); 
		noScroll: false; 
		font: #system; 
		rendererType: #Text; 
		editorType: #InputField; 
		alignment: #right; 
		type: #number) columnWithBuilder: self builder).
	cd at: 4 put: (((DataSetColumnSpec new) 
		label: 'Brightness';
		model: #'selectedRow brightness';
		width: (widths at: 4); 
		noScroll: false; 
		font: #system; 
		rendererType: #Text; 
		editorType: #InputField; 
		alignment: #right; 
		type: #number) columnWithBuilder: self builder).
	^cd!

computeDataSetColumnWidths

	| width | 

	width := self dataSetViewBounds width.
	^#(0.25 0.30 0.25 0.20 ) collect: [:rw | (rw * width) floor - 4]!

configureDataSet
	"This message is sent by the builder prior to beginning construction 
	of either a SubCanvas or a complete window."

	| dsv  cd  |
	dsv := self dataSetView.
	cd := dsv columnDescriptors.
	dsv columnDescriptors: 	(self updateDataSetColumnWidths: self columnDescriptors).
	columnDescriptors := cd!

dataSetView
	| wrapper |
	wrapper := self dataSetViewSpecWrapper.
	^wrapper == nil ifFalse: [wrapper logicalVisual]!

dataSetViewBounds
	| dsv |
	dsv := self dataSetViewSpecWrapper.
	^dsv == nil
		ifTrue: [self windowBounds]
		ifFalse: [dsv component layout rectangleRelativeTo: self windowBounds preferred: nil]!

dataSetViewSpecWrapper
	^ self builder componentAt: #dsv!

updateDataSetColumnWidths 
	"This message is sent by the builder when it has completed work on 
	either a complete window or a SubCanvas."

	| dsv  cd   |
	dsv := self dataSetView.
	cd := dsv columnDescriptors.
	self updateDataSetColumnWidths: cd.
	dsv setColumnDescriptors: cd.
	dsv dropEdit.
	dsv changedPreferredBounds: nil.!

updateDataSetColumnWidths: columnDescriptorArray 
	"This message is sent by the builder when it has completed work on 
	either a complete window or a SubCanvas."

	| widths |
	widths := self computeDataSetColumnWidths.
	1 to: columnDescriptorArray size do: [:i | (columnDescriptorArray at: i)
			width: (widths at: i)].
	^columnDescriptorArray!

windowBounds
	| window |
	window := self builder window.
	^window == nil
		ifTrue: [(self class interfaceSpecFor: #windowSpec) window bounds]
		ifFalse: [window bounds]! !

DataSetDemo class
	instanceVariableNames: ''!


!DataSetDemo class methodsFor: 'interface specs'!

windowSpec
	"UIPainter new openOnClass: self andSelector: #windowSpec"

	<resource: #canvas>
	^#(#FullSpec 
		#window: 
		#(#WindowSpec 
			#label: 'Unlabeled Canvas' 
			#bounds: #(#Rectangle 9 418 649 898 ) ) 
		#component: 
		#(#SpecCollection 
			#collection: #(
				#(#DataSetSpec 
					#layout: #(#LayoutFrame 6 0 6 0 -6 1 -40 1 ) 
					#name: #dsv 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 6708 5590 4980 ) ) 
					#model: #selectionInList 
					#tabable: false 
					#columns: #(
						#(#DataSetColumnSpec 
							#model: #'selectedRow red' 
							#label: 'Red' 
							#labelIsImage: false 
							#width: 201 
							#editorType: #InputField 

							#noScroll: false ) 
						#(#DataSetColumnSpec 
							#model: #'selectedRow green' 
							#label: 'Green' 
							#labelIsImage: false 
							#width: 209 
							#editorType: #InputField 
							#noScroll: false ) 
						#(#DataSetColumnSpec 
							#model: #'selectedRow blue' 
							#label: 'Blue' 
							#labelIsImage: false 
							#width: 192 
							#editorType: #InputField 
							#noScroll: false ) ) ) 
				#(#ActionButtonSpec 
					#layout: #(#LayoutFrame -50 0.5 -36 1 50 0.5 -6 1 ) 
					#model: #configureDataSet 
					#label: 'Configure' 
					#defaultable: true ) ) ) )! !
'From VisualWorks(R) Release 2.0 of 4 August 1994 on 24 March 1995 at 3:53:28 pm'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

!ApplicationWindow methodsFor: 'events'!


sendWindowEvent: aSymbol 
	"Declares what events on the receiver (if any) are to be relayed to 
	dependent windows."

	sendWindowEvents == nil
		ifTrue: [sendWindowEvents := Array with: aSymbol]
		ifFalse: [sendWindowEvents := sendWindowEvents copyWith: aSymbol]! !

!VisualComponent methodsFor: 'accessing'!
logicalVisual
	^self! !

!Wrapper methodsFor: 'accessing'!

logicalVisual
	^component logicalVisual! !

!BorderDecorator methodsFor: 'accessing'!

logicalVisual
	^component logicalVisual! !

_____

Hope this helps...

--alan (lovejoya@ix.netcom.com)

-- 
--
Alan Lovejoy | INTERNET: lovejoya@netcom.com | Smalltalk-80 Consultant
"Do not go gentle into that good night. Old age should burn and rave 
at the closing of the day.  Rage, rage at the dying of the light!"
