DataSetColumn.st
changeset 1007 4ea1ecf23596
parent 991 c1bc86ebe79e
child 1040 c8e6a2ed7928
--- a/DataSetColumn.st	Thu Jul 23 16:48:03 1998 +0200
+++ b/DataSetColumn.st	Sat Jul 25 16:10:25 1998 +0200
@@ -17,7 +17,7 @@
 	instanceVariableNames:'columnNumber dataSet labelExtent minWidth width description form
 		buttonInset buttonExtent textInset drawableAction toggleExtent
 		rendererType backgroundColor foregroundColor fgSelector
-		bgSelector columnAlignment label'
+		bgSelector columnAlignment label readSelector columnAdaptor'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-DataSet'
@@ -49,28 +49,50 @@
     [Instance variables:]
 
         columnNumber    <Integer>               sequence number (into list of columns)
+
         description     <DataSetColumnSpec>     the column description
+
         dataSet         <DSVColumnView>         the view it belongs to
+
         width           <Integer>               width of column
+
         minWidth        <Integer>               minimum required width by the column
+
         buttonInset     <Integer>               top inset of a button (toggle)
+
         buttonExtent    <Point>                 extent of form
+
         textInset       <Integer>               top inset of a string
+
         form            <Form>                  a form drawn in the cell
+
         labelExtent     <Point>                 the preferred extent of the cell label on device
+
         drawableAction  <Action>                action to access the printable
                                                 label of a cell
-        rendererType    <Type>                  renderer type derived from
-                                                column specification.
+
+        rendererType    <Type>                  renderer type (cached value from
+                                                the column specification).
+
         backgroundColor <Color or nil>          background color of all cells or nil
                                                 (nil: use default background color).
+
         foregroundColor <Color or nil>          foreground color of all cells or nil
                                                 (nil: use default foreground color).
+
         fgSelector      <Selector or nil>       access specific foreground color for
                                                 a cell
+
         bgSelector      <Selector or nil>       access specific background color for
                                                 a cell
 
+        readSelector    <Symbol>                cached readSelector (from the spec)
+
+        columnAdaptor   <nil or any>            if non-nil, that one is asked (via
+                                                read-writeSelectors to extract a column
+                                                from a row object.
+                                                If nil, the row object is used itself.
+
 
     [author:]
         Claus Atzkern
@@ -89,13 +111,17 @@
 at:aRowNr
     "get the value of the raw at an index, aRowNr
     "
-    ^ description row:(dataSet at:aRowNr) at:columnNumber
+    ^ self extractColFromRow:(dataSet at:aRowNr).
 !
 
 at:aRowNr put:something
     "set the value of the raw at an index, aRowNr
     "
-    description row:(dataSet at:aRowNr) at:columnNumber put:something
+    |row|
+
+    row := dataSet at:aRowNr.
+    self storeCol:something inRow:row
+
 !
 
 backgroundColor
@@ -367,8 +393,8 @@
 editorAt:aRowNr
     |val row|
 
-    row := dataSet at:aRowNr.
-    val := description row:row at:columnNumber.
+    row := (dataSet at:aRowNr).
+    val := self extractColFromRow:row.
 
     val isText ifTrue:[val := val string].
 
@@ -476,6 +502,8 @@
     bgSelector      := description backgroundSelector.
     backgroundColor := description backgroundColor.
     foregroundColor := description foregroundColor.
+    readSelector    := description readSelector.
+    columnAdaptor   := dataSet columnAdaptor.
     buttonExtent    := 0 @ 0.
     labelExtent     := 0 @ 0.
     columnAlignment := #left.
@@ -549,12 +577,12 @@
         format := '%0.', idx printString, 'f'.
 
         drawableAction := [:aRow||n|
-            n := description row:aRow at:columnNumber.
+            n := self extractColFromRow:aRow.
             n isReal ifTrue:[n := n asFloat printfPrintString:format].
             n
         ]
     ] ifFalse:[         "/ default: no format string
-        drawableAction := [:aRow| description row:aRow at:columnNumber ]
+        drawableAction := [:aRow| self extractColFromRow:aRow ]
     ]
 
 
@@ -616,6 +644,44 @@
     "get the drawable label at an index
     "
     ^ drawableAction value:(dataSet at:aRowNr)
+!
+
+extractColFromRow:aRow
+    |numArgs|
+
+    numArgs := readSelector numArgs.
+    columnAdaptor notNil ifTrue:[
+        numArgs == 1 ifTrue:[
+            ^ columnAdaptor perform:readSelector with:aRow
+        ].
+        ^ columnAdaptor perform:readSelector with:aRow with:columnNumber
+    ].
+
+    numArgs == 0 ifTrue:[
+        ^ aRow perform:readSelector
+    ].
+    ^ aRow perform:readSelector with:columnNumber
+!
+
+storeCol:newValue inRow:aRow
+    |writeSelector numArgs|
+
+    writeSelector := description writeSelector.
+    numArgs := writeSelector numArgs.
+
+    columnAdaptor notNil ifTrue:[
+        numArgs == 2 ifTrue:[
+            ^ columnAdaptor perform:writeSelector with:aRow with:newValue
+        ].
+        ^ columnAdaptor perform:writeSelector with:aRow with:columnNumber with:newValue
+    ].
+
+    numArgs == 1 ifTrue:[
+        aRow perform:writeSelector with:newValue
+    ] ifFalse:[
+        aRow perform:writeSelector with:columnNumber with:newValue
+    ]
+
 ! !
 
 !DataSetColumn methodsFor:'queries'!
@@ -708,5 +774,5 @@
 !DataSetColumn class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/DataSetColumn.st,v 1.22 1998-07-20 14:39:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DataSetColumn.st,v 1.23 1998-07-25 14:10:25 cg Exp $'
 ! !