author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 17:30:31 +0100 | |
changeset 86 | 4d7dbb5f1719 |
parent 84 | 4478ea2d40c2 |
child 184 | 13a2f3677c68 |
permissions | -rw-r--r-- |
84 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
3 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
4 |
All Rights Reserved |
|
5 |
||
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
13 |
||
14 |
SelectionInListView subclass:#SelectionInHierarchyView |
|
15 |
instanceVariableNames:'itemList showConnectingLines' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Text' |
|
19 |
! |
|
20 |
||
21 |
!SelectionInHierarchyView class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1994 by AEG Industry Automation |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
86
4d7dbb5f1719
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
84
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInHierarchyView.st,v 1.2 1995-11-11 16:29:22 cg Exp $' |
84 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like) |
|
45 |
lists and adds the functions to show/hide subtrees. |
|
46 |
Requires SelectionInHierarchy as model and HierarchyNode (or compatible) list entries. |
|
47 |
See examples. |
|
48 |
" |
|
49 |
! |
|
50 |
||
51 |
examples |
|
52 |
" |
|
53 |
shows the tree of smalltalk classes: |
|
54 |
||
55 |
|top hierarchy hierarchyV scroller| |
|
56 |
||
57 |
hierarchy := SelectionInHierarchy new. |
|
58 |
hierarchy root:(HierarchyNode newAsTreeFromSmalltalkClass:Object). |
|
59 |
hierarchy setHideToChildren:true startingAt:hierarchy root. |
|
60 |
||
61 |
top := StandardSystemView new. |
|
62 |
top extent:300@300. |
|
63 |
||
64 |
hierarchyV := SelectionInHierarchyView new. |
|
65 |
hierarchyV model: hierarchy. |
|
66 |
hierarchyV action:[:nr | Transcript show:'selected:'; showCr:nr]. |
|
67 |
||
68 |
top add:(ScrollableView forView:hierarchyV) |
|
69 |
in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
70 |
top open. |
|
71 |
||
72 |
||
73 |
same, with nice connecting links: |
|
74 |
||
75 |
|top hierarchy hierarchyV scroller| |
|
76 |
||
77 |
hierarchy := SelectionInHierarchy new. |
|
78 |
hierarchy root:(HierarchyNode newAsTreeFromSmalltalkClass:Object). |
|
79 |
hierarchy setHideToChildren:true startingAt:hierarchy root. |
|
80 |
||
81 |
top := StandardSystemView new. |
|
82 |
top extent:300@300. |
|
83 |
||
84 |
hierarchyV := SelectionInHierarchyView new. |
|
85 |
hierarchyV showConnectingLines:true. |
|
86 |
hierarchyV model: hierarchy. |
|
87 |
hierarchyV action:[:nr | Transcript show:'selected:'; showCr:nr]. |
|
88 |
||
89 |
top add:(ScrollableView forView:hierarchyV) |
|
90 |
in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)). |
|
91 |
top open. |
|
92 |
" |
|
93 |
! ! |
|
94 |
||
95 |
!SelectionInHierarchyView methodsFor:'event handling'! |
|
96 |
||
97 |
buttonPress:button x:x y:y |
|
98 |
|oldSelection listLineNr| |
|
99 |
||
100 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
101 |
enabled ifTrue:[ |
|
102 |
oldSelection := selection. |
|
103 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
104 |
(selectConditionBlock isNil or:[selectConditionBlock value:listLineNr]) ifTrue:[ |
|
105 |
listLineNr notNil ifTrue: [ |
|
106 |
self selectWithoutScroll:listLineNr |
|
107 |
]. |
|
108 |
((ignoreReselect not and:[selection notNil]) |
|
109 |
or:[selection ~= oldSelection]) ifTrue:[ |
|
110 |
"actionBlock notNil ifTrue:[actionBlock value:selection]." |
|
111 |
"the ST-80 way of doing things" |
|
112 |
model notNil ifTrue:[ |
|
113 |
model perform:#selection: with:(selection) |
|
114 |
] |
|
115 |
]. |
|
116 |
clickLine := listLineNr |
|
117 |
] |
|
118 |
] |
|
119 |
] ifFalse:[ |
|
120 |
super buttonPress:button x:x y:y |
|
121 |
] |
|
122 |
||
123 |
"Modified: 10.10.94 / 17:13:38 / W.Olberding" |
|
124 |
"Modified: 08.11.94 / 15:38:43 / R.Sailer"! |
|
125 |
||
126 |
selection: anIndex |
|
127 |
"Pass the selection along to the model." |
|
128 |
||
129 |
super selection: anIndex. |
|
130 |
model selection: anIndex. |
|
131 |
||
132 |
"Modified: 10.10.94 / 16:13:38 / W.Olberding"! |
|
133 |
||
134 |
keyPress:key x:x y:y |
|
135 |
"a key was pressed - handle [-][+][*] here" |
|
136 |
||
137 |
(key == $-) ifTrue: [^ model collapse]. |
|
138 |
(key == $+) ifTrue: [^ model expand]. |
|
139 |
(key == $*) ifTrue: [^ model expandAll]. |
|
140 |
(key == $.) ifTrue: [^ model collapseAll]. |
|
141 |
||
142 |
super keyPress:key x:x y:y |
|
143 |
||
144 |
"Modified: 10.10.94 / 16:13:38 / W.Olberding"! ! |
|
145 |
||
146 |
!SelectionInHierarchyView methodsFor:'model access'! |
|
147 |
||
148 |
model:aModel |
|
149 |
super model:aModel. |
|
150 |
self setNewList |
|
151 |
! |
|
152 |
||
153 |
getSelectionFromModel |
|
154 |
"Get the current list selection from model. " |
|
155 |
||
156 |
^ model selection |
|
157 |
||
158 |
"Modified: 10.10.94 / 16:13:39 / W.Olberding"! |
|
159 |
||
160 |
getListFromModel |
|
161 |
"Get list entries from model. |
|
162 |
Answer them as idented Text." |
|
163 |
||
164 |
| listOfNodes textList textLine treeLevels isLastOnLevel oldLevel | |
|
165 |
||
166 |
listOfNodes := model list. |
|
167 |
listOfNodes isNil ifTrue:[^ #()]. |
|
168 |
||
169 |
showConnectingLines ifFalse:[ |
|
170 |
textList := listOfNodes collect: [ :aNode | |
|
171 |
textLine := ReadWriteStream on: String new. |
|
172 |
aNode level timesRepeat: [ |
|
173 |
textLine space; space. |
|
174 |
]. |
|
175 |
textLine nextPutAll: aNode name. |
|
176 |
aNode isExpandable ifTrue: [ |
|
177 |
textLine nextPutAll: ' ...'. |
|
178 |
]. |
|
179 |
textLine contents. |
|
180 |
]. |
|
181 |
] ifTrue:[ |
|
182 |
isLastOnLevel:=Set new. |
|
183 |
treeLevels:=Set new. |
|
184 |
oldLevel:=0. |
|
185 |
||
186 |
listOfNodes reverseDo: [ :aNode | |
|
187 |
(treeLevels includes:(aNode level)) ifFalse:[ |
|
188 |
isLastOnLevel add:aNode. |
|
189 |
treeLevels add:(aNode level). |
|
190 |
]. |
|
191 |
aNode level < oldLevel ifTrue:[ |
|
192 |
treeLevels remove:oldLevel. |
|
193 |
]. |
|
194 |
oldLevel:=aNode level. |
|
195 |
]. |
|
196 |
||
197 |
treeLevels:=Set new. |
|
198 |
oldLevel:=0. |
|
199 |
textList := listOfNodes collect: [ :aNode | |
|
200 |
textLine := ReadWriteStream on: String new. |
|
201 |
||
202 |
1 to:((aNode level)-1) do: [ :l | |
|
203 |
(treeLevels includes:l) ifTrue:[ |
|
204 |
textLine space; nextPutAll:((Character value:25)printString); space. |
|
205 |
]ifFalse:[ |
|
206 |
textLine space; space; space. |
|
207 |
] |
|
208 |
]. |
|
209 |
treeLevels add:(aNode level). |
|
210 |
oldLevel:=aNode level. |
|
211 |
||
212 |
(aNode = (listOfNodes first)) ifFalse:[ |
|
213 |
textLine space. |
|
214 |
(isLastOnLevel includes:aNode)ifTrue:[ |
|
215 |
textLine nextPutAll:((Character value:14)printString). |
|
216 |
treeLevels remove:(aNode level). |
|
217 |
]ifFalse:[ |
|
218 |
textLine nextPutAll:((Character value:21)printString). |
|
219 |
]. |
|
220 |
textLine nextPutAll:((Character value:18)printString). |
|
221 |
]. |
|
222 |
aNode isExpandable ifTrue: [ |
|
223 |
textLine nextPutAll: '[+]'. |
|
224 |
]ifFalse:[ |
|
225 |
aNode isCollapsable ifTrue: [ |
|
226 |
textLine nextPutAll: '[-]'. |
|
227 |
]ifFalse:[textLine nextPutAll:((Character value:18)printString).]. |
|
228 |
]. |
|
229 |
||
230 |
textLine nextPutAll:' ', aNode name. |
|
231 |
textLine contents. |
|
232 |
]. |
|
233 |
]. |
|
234 |
||
235 |
^textList |
|
236 |
||
237 |
"Modified: 10.10.94 / 16:13:39 / W.Olberding" |
|
238 |
! |
|
239 |
||
240 |
getListAttributes |
|
241 |
"get list attributes (selectable, disabled ...) from model)" |
|
242 |
||
243 |
^Array new: 0. |
|
244 |
||
245 |
"Modified: 10.10.94 / 16:13:38 / W.Olberding"! ! |
|
246 |
||
247 |
!SelectionInHierarchyView methodsFor:'updating'! |
|
248 |
||
249 |
update: aSymbol with:aParameter from:changedObject |
|
250 |
"Change my apperance according to the occurred change." |
|
251 |
||
252 |
aSymbol==#list |
|
253 |
ifTrue: [^self setNewList]. |
|
254 |
aSymbol==#selection |
|
255 |
ifTrue: [^self selection: self getSelectionFromModel]. |
|
256 |
aSymbol==#attributes |
|
257 |
ifTrue: []. |
|
258 |
||
259 |
"Modified: 10.10.94 / 16:13:38 / W.Olberding"! ! |
|
260 |
||
261 |
!SelectionInHierarchyView methodsFor:'private'! |
|
262 |
||
263 |
setNewList |
|
264 |
"Build a completely new hierarchy list." |
|
265 |
||
266 |
||
267 |
self setList: (self getListFromModel). |
|
268 |
"/ self attributes: (self getListAttributes). |
|
269 |
self selection: (self getSelectionFromModel). |
|
270 |
||
271 |
"Modified: 10.10.94 / 17:13:38 / W.Olberding" |
|
272 |
"Modified: 08.11.94 / 15:28:03 / R.Sailer"! ! |
|
273 |
||
274 |
!SelectionInHierarchyView methodsFor:'initialization'! |
|
275 |
||
276 |
initialize |
|
277 |
||
278 |
super initialize. |
|
279 |
showConnectingLines := true. |
|
280 |
||
281 |
self doubleClickAction: |
|
282 |
[:selection | model doubleClickSelection: selection ]. |
|
283 |
"this will usualy initiate a hide/show operation" |
|
284 |
||
285 |
"Modified: 10.10.94 / 16:13:39 / W.Olberding" |
|
286 |
! |
|
287 |
||
288 |
showConnectingLines:aBoolean |
|
289 |
showConnectingLines := aBoolean |
|
290 |
! ! |
|
291 |
||
292 |
!SelectionInHierarchyView methodsFor:'accessing'! |
|
293 |
||
294 |
||
295 |
selectElement:anObject |
|
296 |
"select the element with same printString as the argument, anObject" |
|
297 |
||
298 |
|index| |
|
299 |
||
300 |
index:= 1. |
|
301 |
||
302 |
list notNil ifTrue:[ |
|
303 |
||
304 |
list do:[:each| |
|
305 |
((each withoutSpaces) = (anObject printString)) ifTrue:[ |
|
306 |
self selection: index. |
|
307 |
^index |
|
308 |
]. |
|
309 |
index:= index + 1. |
|
310 |
]. |
|
311 |
]. |
|
312 |
^index |
|
313 |
||
314 |
"Modified: 10.10.94 / 16:13:39 / W.Olberding"! ! |