SelectionInTree.st
author tz
Sat, 14 Feb 1998 17:15:32 +0100
changeset 762 df337e82f064
parent 758 0f0b16a16fa7
child 811 a688e8f11bc6
permissions -rw-r--r--
supports dynamic read behavior for contents, label, children, and icon of tree items
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     1
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     3
              All Rights Reserved
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     4
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    10
 hereby transferred.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    11
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    12
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    13
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    14
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    15
Model subclass:#SelectionInTree
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    16
	instanceVariableNames:'root list selection showRoot contentsAction labelAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    17
		childrenAction iconAction'
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    18
	classVariableNames:''
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    19
	poolDictionaries:''
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    20
	category:'Interface-Support-Models'
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    21
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    22
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    23
!SelectionInTree class methodsFor:'documentation'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    24
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    25
copyright
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    26
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    27
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    28
              All Rights Reserved
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    29
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    30
 This software is furnished under a license and may be used
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    35
 hereby transferred.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    36
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    37
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    38
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    39
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    40
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    41
documentation
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    42
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    43
    list and selection holder for hierarchical list structures. Used
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    44
    to buildup file-trees, class tress etc.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    45
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    46
    Especially suited for use with SelectionInTreeView.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    47
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    48
    [See also:]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    49
        TreeItem
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    50
        SelectionInTreeView
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    51
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    52
    [Author:]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    53
        W. Olberding
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    54
        Claus Atzkern
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    55
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    56
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    57
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    58
!SelectionInTree methodsFor:'accessing'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    59
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    60
list
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    61
    "get list oc currently shown objects
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    62
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    63
    ^ list
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    64
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    65
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    66
root
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    67
    "get the root node
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    68
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    69
    ^ root
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    70
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    71
509
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
    72
root:aRoot
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
    73
    "set a new root
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    74
    "
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    75
    root notNil ifTrue: [
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    76
        root tree: nil
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    77
    ].
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    78
515
2c09c8688bb8 set parent of root allways to nil
ca
parents: 509
diff changeset
    79
    (root := aRoot) notNil ifTrue:[
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    80
        root parent:nil.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    81
        root tree: self.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    82
    ]. 
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
    83
    self recomputeList.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
    84
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
    85
! !
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
    86
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
    87
!SelectionInTree methodsFor:'accessing behavior'!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
    88
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    89
childrenAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    90
    "get children action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    91
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    92
    ^childrenAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    93
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    94
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    95
childrenAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    96
    "set children action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    97
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    98
    childrenAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    99
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   100
    self changed:#list.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   101
    
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   102
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   103
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   104
contentsAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   105
    "get contents action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   106
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   107
    ^contentsAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   108
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   109
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   110
contentsAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   111
    "set contents action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   112
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   113
    contentsAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   114
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   115
    self changed:#list.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   116
    
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   117
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   118
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   119
iconAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   120
    "get icon action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   121
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   122
    ^iconAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   123
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   124
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   125
iconAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   126
    "set icon action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   127
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   128
    iconAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   129
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   130
    self changed:#list.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   131
    
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   132
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   133
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   134
labelAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   135
    "get label action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   136
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   137
    ^labelAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   138
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   139
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   140
labelAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   141
    "set label action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   142
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   143
    labelAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   144
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   145
    self changed:#list.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   146
    
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   147
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   148
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   149
showRoot
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   150
    "list with or without root
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   151
    "
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   152
    ^ showRoot
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   153
!
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   154
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   155
showRoot:aState
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   156
    "list with or without root
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   157
    "
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   158
    aState ~~ showRoot ifTrue:[
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   159
        showRoot := aState.
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   160
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   161
        root notNil ifTrue:[
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   162
            aState ifTrue:[list addFirst:root]
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   163
                  ifFalse:[list removeFirst].
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   164
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   165
            self changed:#list.
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   166
        ].
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   167
    ].
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   168
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   169
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   170
!SelectionInTree methodsFor:'accessing hierarchy'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   171
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   172
collapse:something 
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   173
    "collapse a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   174
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   175
    |invalidate|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   176
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   177
    self each:something do:[:aNode|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   178
        aNode isCollapsable ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   179
            aNode collapse.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   180
            invalidate := true
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   181
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   182
    ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   183
    invalidate == true ifTrue:[self recomputeList]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   184
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   185
509
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   186
expand
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   187
    "expand the root
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   188
    "
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   189
    self expand:root
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   190
!
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   191
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   192
expand:something 
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   193
    "expand a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   194
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   195
    |invalidate|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   196
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   197
    self each:something do:[:aNode|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   198
        aNode isExpandable ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   199
            aNode expand.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   200
            invalidate := true
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   201
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   202
    ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   203
    invalidate == true ifTrue:[self recomputeList]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   204
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   205
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   206
!SelectionInTree methodsFor:'adding & removing'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   207
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   208
add:something after:aChild
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   209
    "add a node or collection of nodes to parent after a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   210
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   211
    "add a node or collection of nodes to after a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   212
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   213
    aChild notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   214
        aChild parent add:something after:aChild.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   215
        self recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   216
    ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   217
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   218
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   219
add:something afterIndex:anIndex below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   220
    "add a node or collection of nodes to parent after an index
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   221
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   222
    aParent add:something afterIndex:anIndex.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   223
    self recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   224
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   225
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   226
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   227
add:something before:aChild
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   228
    "add a node or collection of nodes to before a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   229
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   230
    aChild notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   231
        aChild parent add:something before:aChild.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   232
        self recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   233
    ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   234
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   235
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   236
add:something beforeIndex:anIndex below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   237
    "add a node or collection of nodes to parent before an index
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   238
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   239
    aParent add:something beforeIndex:anIndex.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   240
    self recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   241
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   242
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   243
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   244
add:something below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   245
    "add a node or collection of nodes to parent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   246
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   247
    aParent add:something.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   248
    self recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   249
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   250
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   251
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   252
remove:something
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   253
    "remove a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   254
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   255
    |invalidate|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   256
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   257
    self each:something do:[:aNode|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   258
        aNode parent notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   259
            aNode parent remove:aNode.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   260
            invalidate := true
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   261
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   262
    ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   263
    invalidate == true ifTrue:[self recomputeList].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   264
  ^ something
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   265
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   266
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   267
removeIndex:something
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   268
    "remove a node at index or collection of indexed nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   269
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   270
    |invalidate node|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   271
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   272
    something isCollection ifFalse:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   273
        (something isNil or:[something == 0]) ifFalse:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   274
            ^ self remove:(list at:something)
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   275
        ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   276
      ^ nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   277
    ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   278
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   279
    (SortedCollection withAll:something) reverseDo:[:anIndex|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   280
        node := list at:anIndex.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   281
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   282
        node parent notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   283
            node parent remove:node.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   284
            invalidate := true
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   285
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   286
    ].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   287
    invalidate == true ifTrue:[self recomputeList].
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   288
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   289
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   290
removeSelection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   291
    "remove selected nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   292
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   293
    self removeIndex:(self selectionIndex).
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   294
    self selectionIndex:nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   295
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   296
758
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   297
!SelectionInTree methodsFor:'change & update'!
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   298
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   299
invalidate
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   300
    "called; something changed what requires a redraw but no recomputation.
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   301
     for example a name
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   302
    "
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   303
    self dependents do:[:aDependent|
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   304
        aDependent isView ifTrue:[ aDependent invalidate ]
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   305
    ].
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   306
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   307
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   308
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   309
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   310
update:something with:aParameter from:aModel
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   311
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   312
    self dependents do:[:aDependent|
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   313
        aDependent update:something with:aParameter from:aModel
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   314
    ]
758
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   315
! !
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   316
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   317
!SelectionInTree methodsFor:'enumerating'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   318
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   319
each:something do:aBlock
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   320
    "evaluate a block for something or in case of a collection for each
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   321
     element in the collection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   322
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   323
    something notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   324
        something isCollection ifTrue:[something do:[:el|aBlock value:el]]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   325
                              ifFalse:[aBlock value:something]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   326
    ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   327
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   328
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   329
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   330
!SelectionInTree methodsFor:'initialization'!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   331
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   332
initialize
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   333
    super initialize.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   334
    showRoot := true.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   335
! !
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   336
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   337
!SelectionInTree methodsFor:'private'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   338
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   339
recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   340
    "Travers the tree and build a new list."
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   341
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   342
    list := OrderedCollection new.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   343
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   344
    root notNil ifTrue:[
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   345
        showRoot ifTrue:[   
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   346
            list add:root
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   347
        ].
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   348
        root recomputeList:list
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   349
    ].
585
5a0ed2305998 bug fixes:
ca
parents: 515
diff changeset
   350
    self changed:#list.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   351
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   352
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   353
!SelectionInTree methodsFor:'selection'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   354
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   355
selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   356
    "get the selection or nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   357
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   358
    ^ self selectionIndex
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   359
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   360
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   361
selection:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   362
    "set the selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   363
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   364
    self selectionIndex:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   365
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   366
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   367
selectionIndex
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   368
    "get the selection or nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   369
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   370
    ^ selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   371
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   372
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   373
selectionIndex:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   374
    "set the selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   375
    "
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   376
    |oldSel|
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   377
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   378
    oldSel := selection.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   379
    self setSelectionIndex:indexesOrNil.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   380
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   381
    oldSel = selection ifFalse:[
585
5a0ed2305998 bug fixes:
ca
parents: 515
diff changeset
   382
        self changed:#selectionIndex
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   383
    ]
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   384
!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   385
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   386
setSelection:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   387
    "set the selection without raising a notification
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   388
    "
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   389
    self setSelectionIndex:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   390
!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   391
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   392
setSelectionIndex:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   393
    "set the selection without raising a notification
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   394
    "
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   395
    |indexes|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   396
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   397
    indexes := indexesOrNil.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   398
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   399
    indexes size == 0 ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   400
        (indexes isCollection or:[indexes == 0]) ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   401
            indexes := nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   402
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   403
    ].
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   404
    selection := indexes
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   405
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   406
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   407
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   408
!SelectionInTree class methodsFor:'documentation'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   409
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   410
version
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   411
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.9 1998-02-14 16:15:32 tz Exp $'
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   412
! !