DataSetBuilder.st
changeset 1004 b7bfaa2d6ecd
parent 983 286a039ea7d1
child 1009 b153d1426731
equal deleted inserted replaced
1003:7880fc48f0bb 1004:b7bfaa2d6ecd
    18 	instanceVariableNames:'rowClass rowSuperClass columnView columns selectedColumnIndex
    18 	instanceVariableNames:'rowClass rowSuperClass columnView columns selectedColumnIndex
    19 		modalOpened'
    19 		modalOpened'
    20 	classVariableNames:''
    20 	classVariableNames:''
    21 	poolDictionaries:''
    21 	poolDictionaries:''
    22 	category:'Interface-UIPainter'
    22 	category:'Interface-UIPainter'
       
    23 !
       
    24 
       
    25 Array subclass:#Row
       
    26 	instanceVariableNames:''
       
    27 	classVariableNames:''
       
    28 	poolDictionaries:''
       
    29 	privateIn:DataSetBuilder
    23 !
    30 !
    24 
    31 
    25 !DataSetBuilder class methodsFor:'documentation'!
    32 !DataSetBuilder class methodsFor:'documentation'!
    26 
    33 
    27 copyright
    34 copyright
   136 
   143 
   137 #basicsEditor
   144 #basicsEditor
   138 'Default widget type or a selector returning an instance of a user defined widget opened in the cell.'
   145 'Default widget type or a selector returning an instance of a user defined widget opened in the cell.'
   139 
   146 
   140 #basicsFont
   147 #basicsFont
   141 'Sets the font of the label text.'
   148 'Sets the font of the labeled text.'
   142 
   149 
   143 #basicsJustification
   150 #basicsJustification
   144 'Aligns the label text to the left, right, or centered in the cell.'
   151 'Aligns the label to the left, right, or center in the cell.'
   145 
   152 
   146 #basicsLabel
   153 #basicsLabel
   147 'The label of the column or a selector returning a string or an image.'
   154 'The label of the column (String or StringCollection) or a selector returning the label.'
       
   155 
       
   156 #basicsLabelId
       
   157 'Unique identifier of the column (optional).'
   148 
   158 
   149 #basicsLabelIsImage
   159 #basicsLabelIsImage
   150 'Turns on/off image behavior of the label string; i.e. it is used as selector returning an image.'
   160 'Label is actually the selector if a message providing an image-label.'
       
   161 
       
   162 #basicsLabelTranslate
       
   163 'Translate the label via the resource mechanism to a national language string.'
   151 
   164 
   152 #basicsRenderer
   165 #basicsRenderer
   153 'Specifies displaying cell as Text, CheckToggle, ComboBox, ComboList or as a RowSelector.'
   166 'Specifies displaying cell as Text, CheckToggle, ComboBox, ComboList or as a RowSelector.'
   154 
   167 
   155 #browseRowClass
   168 #browseRowClass
   226 
   239 
   227 #selectionCellDoubleClickSelector
   240 #selectionCellDoubleClickSelector
   228 'A selector called if cell was double clicked.'
   241 'A selector called if cell was double clicked.'
   229 
   242 
   230 #selectionCellSelector
   243 #selectionCellSelector
   231 'An optional selector, which is used to test whether the cell in the column is selectable; the ''Is Selectable'' flag must be enabled.'
   244 'Name of the message sent to the row to validate a selection.'
   232 
   245 
   233 #selectionIsSelectable
   246 #selectionIsSelectable
   234 'Turns on/off selection behavior of a column.'
   247 'Turns on/off selection behavior of a column.'
   235 
   248 
   236 #selectionLabelClickSelector
   249 #selectionLabelClickSelector
   237 'A selector called if label cell was clicked.'
   250 'A selector called if a cell was clicked.'
   238 
   251 
   239 #selectionLabelSelectorArgument
   252 #selectionLabelSelectorArgument
   240 'An argument passed to label selection selector.'
   253 'An argument passed to the label selection selector.'
   241 
   254 
   242 #showSelectionHighLighted
   255 #showSelectionHighLighted
   243 'Show selected cell highligthened (change fg/bg color).'
   256 'Show selected cell highligthened (change fg/bg color).'
   244 
   257 
   245 #valuesChoiceSelector
   258 #valuesChoiceSelector
   246 'A selector returning a collection of choices for a cell having a ComboBox or a ComboList widget.'
   259 'Selector to get a collection of choices for a cell having a ComboBox or a ComboList widget.'
   247 
   260 
   248 #valuesMenuSelector
   261 #valuesMenuSelector
   249 'A selector returning a middle button menu.'
   262 'Selector to retrive the middle button menu.'
   250 
   263 
   251 #valuesPrintSelector
   264 #valuesPrintSelector
   252 'A key selector used to register images on a DSVColumnView (the arg). For more detailed info see #register... methods in DSVColumnView.'
   265 'Selector used to register images on a DSVColumnView (the arg). For more detailed info see #register... methods in DSVColumnView.'
   253 
   266 
   254 #valuesReadSelector
   267 #valuesReadSelector
   255 'A selector used to get (string or a bitmap) or set (if the write selector is undefined) the contents of a cell.'
   268 'Selector returning the label to be displayed(string, bitmap or a collection).'
   256 
   269 
   257 #valuesWriteSelector
   270 #valuesWriteSelector
   258 'A selector used to set the value of a cell.'
   271 'Selector used to set the value derived from the editor.'
   259 
   272 
   260 )
   273 )
   261 
   274 
   262     "Modified: / 19.5.1998 / 23:20:51 / cg"
   275     "Modified: / 19.5.1998 / 23:20:51 / cg"
   263 ! !
   276 ! !
   302      
   315      
   303        #(#FullSpec
   316        #(#FullSpec
   304           #window: 
   317           #window: 
   305            #(#WindowSpec
   318            #(#WindowSpec
   306               #name: 'DataSet Basic'
   319               #name: 'DataSet Basic'
   307               #layout: #(#LayoutFrame 216 0 173 0 538 0 499 0)
   320               #layout: #(#LayoutFrame 85 0 154 0 407 0 480 0)
   308               #label: 'DataSet Basic'
   321               #label: 'DataSet Basic'
   309               #min: #(#Point 10 10)
   322               #min: #(#Point 10 10)
   310               #max: #(#Point 1280 1024)
   323               #max: #(#Point 1280 1024)
   311               #bounds: #(#Rectangle 216 173 539 500)
   324               #bounds: #(#Rectangle 85 154 408 481)
   312               #usePreferredExtent: false
   325               #usePreferredExtent: false
   313           )
   326           )
   314           #component: 
   327           #component: 
   315            #(#SpecCollection
   328            #(#SpecCollection
   316               #collection: 
   329               #collection: 
   332                               #name: 'labelField'
   345                               #name: 'labelField'
   333                               #layout: #(#LayoutFrame 97 0 28 0 2 1.0 50 0)
   346                               #layout: #(#LayoutFrame 97 0 28 0 2 1.0 50 0)
   334                               #activeHelpKey: #basicsLabel
   347                               #activeHelpKey: #basicsLabel
   335                               #tabable: true
   348                               #tabable: true
   336                               #model: #label
   349                               #model: #label
       
   350                               #type: #smalltalkObject
       
   351                               #immediateAccept: false
       
   352                               #acceptOnLeave: true
   337                           )
   353                           )
   338                            #(#LabelSpec
   354                            #(#LabelSpec
   339                               #name: 'LabelFont'
   355                               #name: 'LabelFont'
   340                               #layout: #(#AlignmentOrigin 94 0 68 0 1 0.5)
   356                               #layout: #(#AlignmentOrigin 94 0 68 0 1 0.5)
   341                               #label: 'Font:'
   357                               #label: 'Font:'
   376                               #label: 'Label Is Image'
   392                               #label: 'Label Is Image'
   377                           )
   393                           )
   378                            #(#CheckBoxSpec
   394                            #(#CheckBoxSpec
   379                               #name: 'CheckBox2'
   395                               #name: 'CheckBox2'
   380                               #layout: #(#LayoutOrigin 142 0 110 0)
   396                               #layout: #(#LayoutOrigin 142 0 110 0)
   381                               #activeHelpKey: #basicsLabelIsImage
   397                               #activeHelpKey: #basicsLabelTranslate
   382                               #tabable: true
   398                               #tabable: true
   383                               #model: #translateLabel
   399                               #model: #translateLabel
   384                               #label: 'Translate Label'
   400                               #label: 'Translate Label'
   385                           )
   401                           )
   386                            #(#LabelSpec
   402                            #(#LabelSpec
   390                               #resizeForLabel: true
   406                               #resizeForLabel: true
   391                           )
   407                           )
   392                            #(#InputFieldSpec
   408                            #(#InputFieldSpec
   393                               #name: 'idField'
   409                               #name: 'idField'
   394                               #layout: #(#LayoutFrame 97 0 0 0 2 1.0 22 0)
   410                               #layout: #(#LayoutFrame 97 0 0 0 2 1.0 22 0)
   395                               #activeHelpKey: #basicsLabel
   411                               #activeHelpKey: #basicsLabelId
   396                               #tabable: true
   412                               #tabable: true
   397                               #model: #id
   413                               #model: #id
   398                           )
   414                           )
   399                         )
   415                         )
   400                     )
   416                     )
   464                     #labelPosition: #topLeft
   480                     #labelPosition: #topLeft
   465                 )
   481                 )
   466               )
   482               )
   467           )
   483           )
   468       )
   484       )
   469 
       
   470     "Modified: / 13.8.1998 / 19:53:18 / cg"
       
   471 !
   485 !
   472 
   486 
   473 colorsEditSpec
   487 colorsEditSpec
   474     "This resource specification was automatically generated
   488     "This resource specification was automatically generated
   475      by the UIPainter of ST/X."
   489      by the UIPainter of ST/X."
  2134     "generate code for #printSelector"
  2148     "generate code for #printSelector"
  2135 
  2149 
  2136     |sel catg code|
  2150     |sel catg code|
  2137 
  2151 
  2138     catg := 'accessing' asSymbol.
  2152     catg := 'accessing' asSymbol.
  2139     code :=   'aGC\'
  2153     code :=   '\'
  2140             , '    "automatically generated by DataSetBuilder ..."\'
  2154             , '    "automatically generated by DataSetBuilder ..."\'
  2141             , '\'
  2155             , '\'
  2142             , '    "get drawable image or text on a gc"\'
  2156             , '    "get drawable image or text on a gc"\'
  2143             , '\'
  2157             , '\'
  2144             , '    ^nil'
  2158             , '    ^ '
  2145             .
  2159             .
  2146 
  2160 
  2147     columns do:
  2161     columns do:[:aColumn|
  2148     [:aColumn|
  2162         (     aColumn rendererType ~~ #rowSelector
  2149         (aColumn rendererType ~~ #rowSelector
  2163          and:[(sel := aColumn printSelector) notNil
  2150         and:[(sel := aColumn printSelector) notNil
  2164          and:[(aClass implements:sel) not]]
  2151         and:[(aClass implements:sel) not]]) 
  2165         ) ifTrue:[
  2152         ifTrue:
  2166             |args bcode keys|
  2153         [
  2167             bcode   := sel asString.
  2154             self compile:(sel asString, code) forClass:aClass inCategory:catg
  2168             args    := sel numArgs.
       
  2169 
       
  2170             args ~~ 0 ifTrue:[
       
  2171                 args == 1 ifTrue:[
       
  2172                     bcode := bcode, 'aGC'
       
  2173                 ] ifFalse:[
       
  2174                     keys := sel keywords.
       
  2175                     bcode := (keys at:1), 'aGC ', (keys at:2), 'aColNr'.
       
  2176                 ]
       
  2177             ].
       
  2178             self compile:(bcode, code, '''', bcode, '''') forClass:aClass inCategory:catg
  2155         ]
  2179         ]
  2156     ]
  2180     ]
  2157 !
  2181 !
  2158 
  2182 
  2159 generateReadSelectorIn:aClass
  2183 generateReadSelectorIn:aClass
  2177         ifTrue:
  2201         ifTrue:
  2178         [
  2202         [
  2179             (aColumn printSelector isNil or:[aColumn canSelect]) 
  2203             (aColumn printSelector isNil or:[aColumn canSelect]) 
  2180             ifTrue:
  2204             ifTrue:
  2181             [
  2205             [
       
  2206                 |selName|
       
  2207                 selName := sel asString.
       
  2208 
  2182                 sel numArgs == 0 
  2209                 sel numArgs == 0 
  2183                     ifTrue: [bCode := sel asString, code] 
  2210                     ifTrue: [bCode := selName, code] 
  2184                     ifFalse:[bCode := sel asString, 'anIndex\', code].
  2211                     ifFalse:[bCode := selName, 'anIndex\', code].
  2185                 aColumn rendererType == #CheckToggle 
  2212                 aColumn rendererType == #CheckToggle 
  2186                     ifFalse:[bCode := bCode, '    ^nil'] 
  2213                     ifFalse:[bCode := bCode, '    ^ ''', selName, ''''] 
  2187                     ifTrue: [bCode := bCode, '    ^true']. 
  2214                     ifTrue: [bCode := bCode, '    ^true']. 
  2188                 self compile:bCode forClass:aClass inCategory:catg
  2215                 self compile:bCode forClass:aClass inCategory:catg
  2189             ]
  2216             ]
  2190         ]
  2217         ]
  2191     ]
  2218     ]
  2300 !DataSetBuilder methodsFor:'private'!
  2327 !DataSetBuilder methodsFor:'private'!
  2301 
  2328 
  2302 askForListModification
  2329 askForListModification
  2303     "asks for resource modification"
  2330     "asks for resource modification"
  2304 
  2331 
  2305     modalOpened
  2332     modalOpened ifFalse:[
  2306     ifFalse:
  2333         ^ super askForListModification
  2307     [
       
  2308         ^super askForListModification
       
  2309     ].
  2334     ].
  2310     ^true
  2335     ^true
  2311 
  2336 
  2312 !
  2337 !
  2313 
  2338 
  2314 labelFromColumn:aColumn
  2339 labelFromColumn:aColumn
  2315 
  2340 
  2316     ^ aColumn rendererType == #rowSelector 
  2341     ^ aColumn rendererType == #rowSelector ifFalse:[aColumn label]
  2317         ifFalse:[aColumn label]
  2342                                            ifTrue: ['Row Selector'].
  2318         ifTrue: ['Row Selector'].
  2343 !
       
  2344 
       
  2345 labelInPreviewPressed:anIndex
       
  2346    (builder componentAt:#labelAndColumns) selection:anIndex
  2319 !
  2347 !
  2320 
  2348 
  2321 updateColumnView
  2349 updateColumnView
  2322     "updates column view from column descriptions"   
  2350     "updates column view from column descriptions
       
  2351     "   
       
  2352     |size|
  2323 
  2353 
  2324     columnView notNil ifTrue:[
  2354     columnView notNil ifTrue:[
  2325         |previewColumns columnItems columnList|
  2355         |previewColumns columnItems columnList|
  2326         columnList     := List new.
  2356         columnList     := List new.
  2327         previewColumns := columns deepCopy.
  2357         previewColumns := columns deepCopy.
  2328         columns notEmpty
  2358         size           := previewColumns size.
  2329         ifTrue:
  2359 
  2330         [               
  2360         size ~~ 0 ifTrue:[               
  2331             previewColumns do: 
  2361             previewColumns keysAndValuesDo:[:anIndex :column| 
  2332             [:column| 
       
  2333                 column readSelector:  #at:;
  2362                 column readSelector:  #at:;
  2334                     writeSelector: #at:put:;
  2363                     writeSelector: #at:put:;
  2335                     backgroundSelector:nil;
  2364                     backgroundSelector:nil;
  2336                     foregroundSelector:nil;
  2365                     foregroundSelector:nil;
  2337                     rowSeparatorSelector:nil;
  2366                     rowSeparatorSelector:nil;
  2338                     selectSelector: nil;
  2367                     selectSelector: nil;
  2339                     doubleClickedSelector: nil;
  2368                     doubleClickedSelector: nil;
  2340                     printSelector: nil;
  2369                     printSelector: nil;
  2341                     menu: nil;
  2370                     menu: nil;
  2342                     choices: nil
  2371                     labelActionSelector:#labelInPreviewPressed:;
       
  2372                     labelActionArgument:anIndex;
       
  2373                     choices:#choices
  2343             ].
  2374             ].
  2344             #('1' '2' '...' 'x') do:
  2375             #(' 1' ' 2' ' x') do:[:suffix|
  2345             [:suffix|
  2376                 columnItems := Row new:size.
  2346                 columnItems := Array new: previewColumns size.
  2377                 1 to:size do:[:i| columnItems at: i put: ('Cell', suffix)].
  2347                 1 to: previewColumns size do: [:i| columnItems at: i put: (previewColumns at: i) label ? 'Cell', suffix].
       
  2348                 columnList add: columnItems.
  2378                 columnList add: columnItems.
  2349             ]
  2379             ]
  2350         ].
  2380         ].
  2351         columnView list: #().
  2381         columnView list: #().
  2352         columnView columnDescriptors: previewColumns.
  2382         columnView columnDescriptors: previewColumns.
  2357 updateInputFields
  2387 updateInputFields
  2358     "reloads item value into input fields"
  2388     "reloads item value into input fields"
  2359 
  2389 
  2360     |column|
  2390     |column|
  2361 
  2391 
  2362     (column := self selectedColumn) isNil 
  2392     (column := self selectedColumn) isNil ifTrue:[
  2363     ifTrue:
       
  2364     [
       
  2365         self tabModel value:0.
  2393         self tabModel value:0.
  2366     ] 
  2394     ] ifFalse:[
  2367     ifFalse:
       
  2368     [
       
  2369         aspects keysAndValuesDo:[:aKey :aModel|aModel value:(column perform:aKey) withoutNotifying: self].
  2395         aspects keysAndValuesDo:[:aKey :aModel|aModel value:(column perform:aKey) withoutNotifying: self].
  2370         tabSelection == 0 ifTrue:[self tabModel value:1]
  2396         tabSelection == 0 ifTrue:[self tabModel value:1]
  2371     ]
  2397     ]
  2372 ! !
  2398 ! !
  2373 
  2399 
  2388 !
  2414 !
  2389 
  2415 
  2390 selectedColumnIndex:something
  2416 selectedColumnIndex:something
  2391     "changes selected column and update specifications"
  2417     "changes selected column and update specifications"
  2392 
  2418 
  2393     something == selectedColumnIndex 
  2419     something == selectedColumnIndex ifFalse:[
  2394     ifFalse:
       
  2395     [
       
  2396         selectedColumnIndex := something ? 0.
  2420         selectedColumnIndex := something ? 0.
  2397         self isColumnSelected value: true
  2421         self isColumnSelected value: true
  2398     ]
  2422     ]
  2399 
  2423 
  2400 !
  2424 !
  2403     "changes selected tab and set corresponding specification"
  2427     "changes selected tab and set corresponding specification"
  2404 
  2428 
  2405     |specSelector|
  2429     |specSelector|
  2406 
  2430 
  2407     something == tabSelection ifTrue:[^self].
  2431     something == tabSelection ifTrue:[^self].
  2408     self selectedColumn isNil 
  2432 
  2409     ifTrue:
  2433     self selectedColumn isNil ifTrue:[
  2410     [
       
  2411         tabSelection == 0 ifTrue:[^self].
  2434         tabSelection == 0 ifTrue:[^self].
  2412         tabSelection := 0
  2435         tabSelection := 0
  2413     ] 
  2436     ] ifFalse:[
  2414     ifFalse:
  2437         (tabSelection := something) ~~ 0 ifTrue:[
  2415     [
  2438             specSelector := (self class slices at:tabSelection) last
  2416         (tabSelection := something) ~~ 0 
  2439         ]
  2417             ifTrue: [specSelector := (self class slices at:tabSelection) last]
       
  2418     ].
  2440     ].
  2419     self specChannel value:specSelector.
  2441     self specChannel value:specSelector.
  2420     (self window notNil and: [self window shown]) ifTrue: [self updateFonts]
  2442     (self window notNil and: [self window shown]) ifTrue: [self updateFonts]
  2421 
  2443 
  2422 ! !
  2444 ! !
  2446 !
  2468 !
  2447 
  2469 
  2448 postBuildWith:builder
  2470 postBuildWith:builder
  2449 
  2471 
  2450     columnView := self builder componentAt:#columnView.
  2472     columnView := self builder componentAt:#columnView.
  2451     columnView labelView enabled:false.
  2473     "/ columnView labelView enabled:false.
  2452 
  2474 
  2453     super postBuildWith:builder.
  2475     super postBuildWith:builder.
  2454 
  2476 
  2455     (builder componentAt: #labelAndColumns) 
  2477     (builder componentAt: #labelAndColumns) 
  2456         selectConditionBlock: [:i|self askForItemModification];
  2478         selectConditionBlock: [:i|self askForItemModification];
  2814     hasSaved := true.
  2836     hasSaved := true.
  2815     modified := false.
  2837     modified := false.
  2816 
  2838 
  2817 ! !
  2839 ! !
  2818 
  2840 
       
  2841 !DataSetBuilder::Row methodsFor:'accessing'!
       
  2842 
       
  2843 choices
       
  2844     ^ #( 'foo' 'bar' 'baz' )
       
  2845 
       
  2846 
       
  2847 ! !
       
  2848 
       
  2849 !DataSetBuilder::Row methodsFor:'message handling'!
       
  2850 
       
  2851 doesNotUnderstand:aMessage
       
  2852     "does not understand message; delegate to column view
       
  2853     "
       
  2854     ^ nil
       
  2855 
       
  2856 ! !
       
  2857 
  2819 !DataSetBuilder class methodsFor:'documentation'!
  2858 !DataSetBuilder class methodsFor:'documentation'!
  2820 
  2859 
  2821 version
  2860 version
  2822     ^ '$Header$'
  2861     ^ '$Header$'
  2823 ! !
  2862 ! !