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