author | Claus Gittinger <cg@exept.de> |
Tue, 02 Nov 2010 22:00:38 +0100 | |
changeset 3961 | 6cd0b3929aa2 |
parent 3703 | 818df7b84e65 |
child 4177 | bc837fdacd46 |
permissions | -rw-r--r-- |
542 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2090
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
13 |
|
1487 | 14 |
ScrollableView subclass:#DataSetView |
2146 | 15 |
instanceVariableNames:'labelView rememberedTopOffsetOfScrolledView' |
542 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-DataSet' |
|
19 |
! |
|
20 |
||
21 |
!DataSetView class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
||
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
This class implements a selection list view based on rows and columns. |
|
43 |
It allows for the dynamic editing of this information. |
|
44 |
||
2901 | 45 |
This is a replacement for the obsolete TableView. |
46 |
||
542 | 47 |
[author:] |
48 |
Claus Atzkern |
|
49 |
||
50 |
[see also:] |
|
51 |
DataSetColumnSpec |
|
52 |
DataSetColumn |
|
53 |
DSVColumnView |
|
54 |
" |
|
55 |
! |
|
56 |
||
57 |
examples |
|
58 |
" |
|
2901 | 59 |
example 1: list with valid rows of type Array |
611 | 60 |
[exBegin] |
61 |
|top scr columns rows bool rdWtSel| |
|
542 | 62 |
|
1495 | 63 |
top := StandardSystemView new label:'Simple Test'; extent:700@440. |
611 | 64 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
65 |
||
66 |
columns := OrderedCollection new. |
|
67 |
rows := OrderedCollection new. |
|
68 |
bool := true. |
|
69 |
rdWtSel := #( #at: #at:put: ). |
|
70 |
||
71 |
1 to:1000 do:[:i||n| |
|
72 |
n := i printString. |
|
3506 | 73 |
rows add:(Array with:('text: ', n) with:('input: ', n) with:bool with:(i==20)). |
611 | 74 |
bool := bool not. |
75 |
]. |
|
76 |
||
77 |
columns add:(DataSetColumnSpec label:'Text' editorType:#None selector:rdWtSel). |
|
78 |
columns add:(DataSetColumnSpec label:'Input' editorType:#InputField selector:rdWtSel). |
|
79 |
columns add:(DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:rdWtSel). |
|
3506 | 80 |
columns add:(DataSetColumnSpec label:'Radio' editorType:#RadioButton selector:rdWtSel). |
611 | 81 |
|
82 |
scr columnDescriptors:columns. |
|
83 |
scr list:rows. |
|
84 |
top open. |
|
85 |
[exEnd] |
|
86 |
||
87 |
||
619 | 88 |
|
2901 | 89 |
example 2: list with none valid rows; defining #rowIfAbsent: block |
619 | 90 |
[exBegin] |
91 |
|top scr columns bool rdWtSel| |
|
92 |
||
1495 | 93 |
top := StandardSystemView new label:'Row Is Absent'; extent:700@440. |
619 | 94 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
95 |
||
96 |
columns := OrderedCollection new. |
|
97 |
bool := true. |
|
98 |
rdWtSel := #( #at: #at:put: ). |
|
99 |
||
100 |
columns add:(DataSetColumnSpec label:'Text' editorType:#None selector:rdWtSel). |
|
101 |
columns add:(DataSetColumnSpec label:'Input' editorType:#InputField selector:rdWtSel). |
|
102 |
columns add:(DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:rdWtSel). |
|
103 |
||
104 |
scr rowIfAbsent:[:i| |
|
105 |
bool := bool not. |
|
106 |
Array with:('text: ', i printString) with:('input: ') with:bool |
|
107 |
]. |
|
108 |
||
109 |
scr columnDescriptors:columns. |
|
110 |
scr list:(Array new:1000). |
|
111 |
top open. |
|
112 |
[exEnd] |
|
113 |
||
114 |
||
115 |
||
2901 | 116 |
example 3: list with valid rows of type Structure |
542 | 117 |
[exBegin] |
118 |
|top scr clDc rows slct list idx bool| |
|
119 |
||
1495 | 120 |
top := StandardSystemView new label:'Editors'; extent:700@440. |
542 | 121 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
122 |
||
123 |
clDc := OrderedCollection new. |
|
124 |
rows := OrderedCollection new. |
|
125 |
list := #( 'Text ' 'Field ' 'C-Box ' 'C-List ' true #( 'foo' 'bar' 'baz' ) ). |
|
126 |
slct := #( #text #field #cbox #clist #toggle #choices ). |
|
127 |
idx := 11. |
|
128 |
bool := true. |
|
129 |
||
130 |
20 timesRepeat:[ |values| |
|
131 |
values := list collect:[:n| |
|
132 |
n isString ifTrue:[n, idx printString] |
|
133 |
ifFalse:[n == true ifTrue:[bool] ifFalse:[n]] |
|
134 |
]. |
|
135 |
rows add:(Structure newWith:slct values:values). |
|
136 |
bool := bool not. |
|
137 |
idx := idx + 1. |
|
138 |
]. |
|
139 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
140 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
141 |
clDc add:( DataSetColumnSpec label:'Field' editorType:#InputField selector:#field ). |
|
142 |
clDc add:( DataSetColumnSpec label:'C-Box' editorType:#ComboBox selector:#cbox ). |
|
143 |
clDc last choices:#choices. |
|
144 |
clDc add:( DataSetColumnSpec label:'C-List' editorType:#ComboList selector:#clist ). |
|
145 |
clDc last choices:#choices. |
|
146 |
clDc add:( DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:#toggle ). |
|
147 |
||
607 | 148 |
scr has3Dseparators:true. |
542 | 149 |
scr columnDescriptors:clDc. |
150 |
scr list:rows. |
|
151 |
top open. |
|
152 |
[exEnd] |
|
153 |
||
154 |
||
155 |
||
156 |
||
2901 | 157 |
example 4: table includes a row selector and multiple select is enabled |
542 | 158 |
[exBegin] |
159 |
|top scr clDc rows slct list idx bool| |
|
160 |
||
1495 | 161 |
top := StandardSystemView new label:'Multiple Select'; extent:700@440. |
542 | 162 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
163 |
||
164 |
clDc := OrderedCollection new. |
|
165 |
rows := OrderedCollection new. |
|
166 |
list := #( 'Text ' 'Field ' 'C-Box ' 'C-List ' true #( 'foo' 'bar' 'baz' ) ). |
|
167 |
slct := #( #text #field #cbox #clist #toggle #choices ). |
|
168 |
idx := 11. |
|
169 |
bool := true. |
|
170 |
||
171 |
20 timesRepeat:[ |values| |
|
172 |
values := list collect:[:n| |
|
173 |
n isString ifTrue:[n, idx printString] |
|
174 |
ifFalse:[n == true ifTrue:[bool] ifFalse:[n]] |
|
175 |
]. |
|
176 |
rows add:(Structure newWith:slct values:values). |
|
177 |
bool := bool not. |
|
178 |
idx := idx + 1. |
|
179 |
]. |
|
180 |
clDc add:( DataSetColumnSpec rowSelector ). |
|
181 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
182 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
183 |
clDc add:( DataSetColumnSpec label:'Field' editorType:#InputField selector:#field ). |
|
184 |
clDc add:( DataSetColumnSpec label:'C-Box' editorType:#ComboBox selector:#cbox ). |
|
185 |
clDc last choices:#choices. |
|
186 |
clDc add:( DataSetColumnSpec label:'C-List' editorType:#ComboList selector:#clist ). |
|
187 |
clDc last choices:#choices. |
|
188 |
clDc add:( DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:#toggle ). |
|
189 |
||
607 | 190 |
scr has3Dseparators:true. |
542 | 191 |
scr columnDescriptors:clDc. |
619 | 192 |
scr multipleSelectOk:true. |
542 | 193 |
scr list:rows. |
194 |
top open. |
|
195 |
[exEnd] |
|
196 |
||
197 |
||
2901 | 198 |
example 5: Images and Layout |
542 | 199 |
[exBegin] |
1495 | 200 |
|top scr columns rows colDesc image text| |
542 | 201 |
|
1495 | 202 |
text := 'Text'. |
203 |
rows := Array new:1000. |
|
542 | 204 |
|
1495 | 205 |
1 to:(rows size) do:[:i| |
206 |
rows at:i put:(Array with:('Id: ', i printString) with:text with:text) |
|
207 |
]. |
|
542 | 208 |
|
1495 | 209 |
columns := OrderedCollection new. |
210 |
image := Image fromFile:('xpmBitmaps/misc_tools/box_full.xpm' ). |
|
211 |
||
212 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Left') selector:#at:. |
|
213 |
colDesc labelAlignment:#left. |
|
214 |
colDesc columnAlignment:#left. |
|
215 |
columns add:colDesc. |
|
542 | 216 |
|
1495 | 217 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Right') selector:#at:. |
218 |
colDesc labelAlignment:#right. |
|
219 |
colDesc columnAlignment:#right. |
|
220 |
columns add:colDesc. |
|
221 |
||
222 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Center') selector:#at:. |
|
223 |
colDesc labelAlignment:#center. |
|
224 |
colDesc columnAlignment:#center. |
|
225 |
columns add:colDesc. |
|
542 | 226 |
|
1495 | 227 |
columns do:[:el|el labelActionSelector:#dummy]. |
542 | 228 |
|
1495 | 229 |
top := StandardSystemView new label:'Layout'; extent:500@500. |
230 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
231 |
scr has3Dseparators:true. |
|
232 |
scr columnDescriptors:columns. |
|
233 |
scr list:rows. |
|
542 | 234 |
|
1495 | 235 |
top open |
542 | 236 |
[exEnd] |
237 |
||
238 |
||
239 |
||
2901 | 240 |
example 6: adding and removing |
1487 | 241 |
[exBegin] |
242 |
|top scr list| |
|
243 |
||
1495 | 244 |
top := StandardSystemView new label:'Adding & Removing'; extent:600@440. |
1487 | 245 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
246 |
||
247 |
scr columnDescriptors:( Array with:(DataSetColumnSpec label:'FOO' selector:#at:) |
|
248 |
with:(DataSetColumnSpec label:'BAR' selector:#at:) |
|
249 |
with:(DataSetColumnSpec label:'BAZ' selector:#at:) |
|
250 |
). |
|
251 |
||
252 |
scr has3Dseparators:true. |
|
253 |
scr listHolder:(list := List new). |
|
254 |
top openAndWait. |
|
255 |
||
256 |
1 to:32 do:[:i| |pid| |
|
257 |
pid := i printString. |
|
258 |
list add:(Array with:('foo: ', pid) with:('bar: ', pid) with:('baz: ', pid)). |
|
259 |
i even ifTrue:[ |
|
260 |
list removeFirst |
|
261 |
]. |
|
262 |
Delay waitForSeconds:0.1. |
|
263 |
]. |
|
264 |
[exEnd] |
|
265 |
||
266 |
||
542 | 267 |
" |
268 |
! ! |
|
269 |
||
2829 | 270 |
!DataSetView methodsFor:'accessing'! |
271 |
||
272 |
columnView |
|
273 |
^ scrolledView |
|
274 |
! |
|
275 |
||
276 |
labelView |
|
277 |
^ labelView |
|
278 |
! ! |
|
279 |
||
2146 | 280 |
!DataSetView methodsFor:'change & update'! |
281 |
||
282 |
update:something with:aParameter from:changedObject |
|
283 |
changedObject == labelView ifTrue:[ |
|
2153 | 284 |
((something == #columnLayout) |
285 |
or:[something == #visibility]) ifTrue:[ |
|
2146 | 286 |
self recomputeLayouts. |
287 |
^ self |
|
288 |
]. |
|
289 |
]. |
|
290 |
||
291 |
super update:something with:aParameter from:changedObject |
|
292 |
! ! |
|
293 |
||
2500 | 294 |
!DataSetView methodsFor:'initialization & release'! |
542 | 295 |
|
296 |
initialize |
|
297 |
"set column area |
|
298 |
" |
|
2146 | 299 |
|columnView| |
300 |
||
2090
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
301 |
"/ preset flags to avoid creation and later destruction of scrollBars ... |
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
302 |
self setVertical:true mini:false horizontal:true mini:true. |
542 | 303 |
super initialize. |
304 |
||
1487 | 305 |
self setupVertical:true mini:false horizontal:true mini:true. |
2146 | 306 |
|
307 |
labelView := DSVLabelView in:self. |
|
308 |
columnView := DSVColumnView new. |
|
309 |
columnView labelView:labelView. |
|
310 |
||
2150 | 311 |
"/ columnView addDependent:self. |
2146 | 312 |
labelView addDependent:self. |
313 |
||
314 |
self scrolledView:columnView. |
|
315 |
! ! |
|
316 |
||
317 |
!DataSetView methodsFor:'layout computation'! |
|
318 |
||
319 |
recomputeLayouts |
|
320 |
|columnView columnViewLayout newOffset| |
|
321 |
||
322 |
columnView := self scrolledView. |
|
323 |
columnView isNil ifTrue:[^ self]. |
|
324 |
(columnViewLayout := columnView layout) isNil ifTrue:[^ self]. |
|
325 |
||
326 |
labelView isVisible ifFalse:[ |
|
327 |
newOffset := scrolledViewLayout topOffset. |
|
328 |
] ifTrue:[ |
|
329 |
newOffset := scrolledViewLayout topOffset + (columnView preferredLabelViewHeight). |
|
330 |
]. |
|
331 |
||
332 |
newOffset ~~ columnViewLayout topOffset ifTrue:[ |
|
333 |
columnViewLayout topOffset:newOffset. |
|
2721
5d00500ffc3e
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2720
diff
changeset
|
334 |
"/ columnView realized ifTrue:[ |
2146 | 335 |
columnView containerChangedSize. |
2721
5d00500ffc3e
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2720
diff
changeset
|
336 |
"/ ] |
2146 | 337 |
]. |
2153 | 338 |
labelView containerChangedSize. |
2146 | 339 |
! |
340 |
||
341 |
scrolledViewLayout:aLayout |
|
342 |
"invoked by superclasses setLayout method, whenever the scrolled views |
|
343 |
layout changes (due to added/removed scrollbars)." |
|
344 |
||
2150 | 345 |
|modifiedLayout originalTopOffset labelViewLayout newLeft newRight| |
2146 | 346 |
|
347 |
"/ always copy - since layout it destructively modified in #recomputeLayouts |
|
348 |
modifiedLayout := aLayout copy. |
|
2153 | 349 |
|
350 |
originalTopOffset := scrolledViewLayout topOffset. |
|
2146 | 351 |
labelView isVisible ifTrue:[ |
352 |
modifiedLayout topOffset:(originalTopOffset + labelView height). |
|
2153 | 353 |
]. |
2150 | 354 |
|
2153 | 355 |
newLeft := aLayout leftOffset. |
356 |
newRight := aLayout rightOffset. |
|
2151
50f8723054e7
selected row is highlighted over the full width;
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
357 |
|
2153 | 358 |
(scrolledView level == 0 |
359 |
and:[self level < 0 |
|
360 |
and:[labelView level == 0]]) ifTrue:[ |
|
361 |
newRight := (newRight + 1) min:0. |
|
362 |
modifiedLayout rightOffset:newRight. |
|
363 |
]. |
|
2150 | 364 |
|
2153 | 365 |
labelViewLayout := labelView layout. |
366 |
labelViewLayout topOffset:originalTopOffset. |
|
367 |
labelViewLayout |
|
368 |
leftOffset:newLeft |
|
369 |
rightOffset:newRight. |
|
370 |
||
371 |
labelView isVisible ifTrue:[ |
|
2150 | 372 |
labelView containerChangedSize. |
2146 | 373 |
]. |
374 |
super scrolledViewLayout:modifiedLayout |
|
542 | 375 |
! ! |
376 |
||
377 |
!DataSetView methodsFor:'queries'! |
|
378 |
||
3677
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
379 |
preferredExtent |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
380 |
"return my preferredExtent from the scrolledViews prefExtent |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
381 |
plus the size of the scrollBar" |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
382 |
|
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
383 |
|preferred| |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
384 |
|
3703 | 385 |
"/ If I have an explicit preferredExtent.. |
3677
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
386 |
explicitExtent notNil ifTrue:[ |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
387 |
^ explicitExtent |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
388 |
]. |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
389 |
|
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
390 |
"/ If I have a cached preferredExtent value.. |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
391 |
preferredExtent notNil ifTrue:[ |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
392 |
^ preferredExtent |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
393 |
]. |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
394 |
|
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
395 |
preferred := super preferredExtent. |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
396 |
^ (preferred x) @ (preferred y + labelView preferredHeight). |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
397 |
|
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
398 |
"Created: 6.3.1997 / 18:06:24 / cg" |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
399 |
"Modified: 6.3.1997 / 22:34:09 / cg" |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
400 |
! |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
401 |
|
542 | 402 |
specClass |
637 | 403 |
"returns my spec class |
404 |
" |
|
542 | 405 |
^ DataSetSpec |
406 |
! ! |
|
407 |
||
408 |
!DataSetView class methodsFor:'documentation'! |
|
409 |
||
410 |
version |
|
3703 | 411 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetView.st,v 1.44 2009-05-20 07:19:14 cg Exp $' |
542 | 412 |
! ! |