author | Claus Gittinger <cg@exept.de> |
Sat, 19 Jun 2004 16:42:52 +0200 | |
changeset 2720 | c2781a99aa15 |
parent 2500 | 1477b0a5a918 |
child 2721 | 5d00500ffc3e |
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:[ |
|
2153 | 275 |
((something == #columnLayout) |
276 |
or:[something == #visibility]) ifTrue:[ |
|
2146 | 277 |
self recomputeLayouts. |
278 |
^ self |
|
279 |
]. |
|
280 |
]. |
|
281 |
||
282 |
super update:something with:aParameter from:changedObject |
|
283 |
! ! |
|
284 |
||
2500 | 285 |
!DataSetView methodsFor:'initialization & release'! |
542 | 286 |
|
287 |
initialize |
|
288 |
"set column area |
|
289 |
" |
|
2146 | 290 |
|columnView| |
291 |
||
2090
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
292 |
"/ 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
|
293 |
self setVertical:true mini:false horizontal:true mini:true. |
542 | 294 |
super initialize. |
295 |
||
1487 | 296 |
self setupVertical:true mini:false horizontal:true mini:true. |
2146 | 297 |
|
298 |
labelView := DSVLabelView in:self. |
|
299 |
columnView := DSVColumnView new. |
|
300 |
columnView labelView:labelView. |
|
301 |
||
2150 | 302 |
"/ columnView addDependent:self. |
2146 | 303 |
labelView addDependent:self. |
304 |
||
305 |
self scrolledView:columnView. |
|
306 |
! ! |
|
307 |
||
308 |
!DataSetView methodsFor:'layout computation'! |
|
309 |
||
310 |
recomputeLayouts |
|
311 |
|columnView columnViewLayout newOffset| |
|
312 |
||
313 |
columnView := self scrolledView. |
|
314 |
columnView isNil ifTrue:[^ self]. |
|
315 |
(columnViewLayout := columnView layout) isNil ifTrue:[^ self]. |
|
316 |
||
317 |
labelView isVisible ifFalse:[ |
|
318 |
newOffset := scrolledViewLayout topOffset. |
|
319 |
] ifTrue:[ |
|
320 |
newOffset := scrolledViewLayout topOffset + (columnView preferredLabelViewHeight). |
|
321 |
]. |
|
322 |
||
323 |
newOffset ~~ columnViewLayout topOffset ifTrue:[ |
|
324 |
columnViewLayout topOffset:newOffset. |
|
2720
c2781a99aa15
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2500
diff
changeset
|
325 |
columnView realized ifTrue:[ |
2146 | 326 |
columnView containerChangedSize. |
327 |
] |
|
328 |
]. |
|
2153 | 329 |
labelView containerChangedSize. |
2146 | 330 |
! |
331 |
||
332 |
scrolledViewLayout:aLayout |
|
333 |
"invoked by superclasses setLayout method, whenever the scrolled views |
|
334 |
layout changes (due to added/removed scrollbars)." |
|
335 |
||
2150 | 336 |
|modifiedLayout originalTopOffset labelViewLayout newLeft newRight| |
2146 | 337 |
|
338 |
"/ always copy - since layout it destructively modified in #recomputeLayouts |
|
339 |
modifiedLayout := aLayout copy. |
|
2153 | 340 |
|
341 |
originalTopOffset := scrolledViewLayout topOffset. |
|
2146 | 342 |
labelView isVisible ifTrue:[ |
343 |
modifiedLayout topOffset:(originalTopOffset + labelView height). |
|
2153 | 344 |
]. |
2150 | 345 |
|
2153 | 346 |
newLeft := aLayout leftOffset. |
347 |
newRight := aLayout rightOffset. |
|
2151
50f8723054e7
selected row is highlighted over the full width;
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
348 |
|
2153 | 349 |
(scrolledView level == 0 |
350 |
and:[self level < 0 |
|
351 |
and:[labelView level == 0]]) ifTrue:[ |
|
352 |
newRight := (newRight + 1) min:0. |
|
353 |
modifiedLayout rightOffset:newRight. |
|
354 |
]. |
|
2150 | 355 |
|
2153 | 356 |
labelViewLayout := labelView layout. |
357 |
labelViewLayout topOffset:originalTopOffset. |
|
358 |
labelViewLayout |
|
359 |
leftOffset:newLeft |
|
360 |
rightOffset:newRight. |
|
361 |
||
362 |
labelView isVisible ifTrue:[ |
|
2150 | 363 |
labelView containerChangedSize. |
2146 | 364 |
]. |
365 |
super scrolledViewLayout:modifiedLayout |
|
542 | 366 |
! ! |
367 |
||
368 |
!DataSetView methodsFor:'queries'! |
|
369 |
||
370 |
specClass |
|
637 | 371 |
"returns my spec class |
372 |
" |
|
542 | 373 |
^ DataSetSpec |
374 |
! ! |
|
375 |
||
376 |
!DataSetView class methodsFor:'documentation'! |
|
377 |
||
378 |
version |
|
2720
c2781a99aa15
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2500
diff
changeset
|
379 |
^ '$Header: /cvs/stx/stx/libwidg2/DataSetView.st,v 1.38 2004-06-19 14:42:52 cg Exp $' |
542 | 380 |
! ! |