AbstractHierarchicalItem.st
changeset 6193 b50c38f9dbdb
parent 6159 30228fcd40dd
child 6228 8a02146c43d3
equal deleted inserted replaced
6192:601426541811 6193:b50c38f9dbdb
   483      WARNING: refetches children.
   483      WARNING: refetches children.
   484      Precondition: must be collapsed"
   484      Precondition: must be collapsed"
   485 
   485 
   486 "/ true ifTrue:[ ^ self __recursiveExpand ].
   486 "/ true ifTrue:[ ^ self __recursiveExpand ].
   487 
   487 
   488     (self isExpanded not and:[self canExpand]) ifFalse:[ ^ self ].
   488     (self isExpanded not and:[self canRecursiveExpand]) ifFalse:[ ^ self ].
   489 
   489 
   490     self synchronized:[  | index |
   490     self synchronized:[  | index |
   491         index := self listIndex.
   491         index := self listIndex.
   492 
   492                       "/ matilk: why check this again?
   493         (index notNil and:[self isExpanded not and:[self canExpand]]) ifTrue:[ | action mdlist |
   493         (index notNil and:[self isExpanded not and:[self canRecursiveExpand]]) ifTrue:[ | action mdlist |
   494             mdlist := OrderedCollection with:self.
   494             mdlist := OrderedCollection with:self.
   495 
   495 
   496             [ mdlist notEmpty ] whileTrue:[ | toExpand |
   496             [ mdlist notEmpty ] whileTrue:[ | toExpand |
   497                 toExpand := mdlist removeFirst.
   497                 toExpand := mdlist removeFirst.
   498                 toExpand setExpanded:true.
   498                 toExpand setExpanded:true.
   499 
   499 
   500                 toExpand do:[: eachChild |
   500                 toExpand do:[: eachChild |
   501                     (eachChild isExpanded or:[eachChild canExpand])
   501                     (eachChild isExpanded or:[eachChild canRecursiveExpand])
   502                         ifTrue: [ mdlist add:eachChild ]
   502                         ifTrue: [ mdlist add:eachChild ]
   503                         ifFalse:[ eachChild setExpanded:false ].
   503                         ifFalse:[ eachChild setExpanded:false ].
   504                 ].
   504                 ].
   505             ].
   505             ].
   506             mdlist := OrderedCollection new: 100.
   506             mdlist := OrderedCollection new: 100.
   509             mdlist removeFirst.
   509             mdlist removeFirst.
   510             self model itemAddAll:mdlist afterIndex: index.
   510             self model itemAddAll:mdlist afterIndex: index.
   511             self hierarchyChanged.
   511             self hierarchyChanged.
   512         ].
   512         ].
   513     ].
   513     ].
       
   514 
       
   515     "Modified: / 11-12-2019 / 12:58:20 / Maren Tilk"
   514 !
   516 !
   515 
   517 
   516 recursiveToggleExpand
   518 recursiveToggleExpand
   517     "if the item is collapsed, the item and all its sub-items
   519     "if the item is collapsed, the item and all its sub-items
   518      are expanded otherwise collapsed"
   520      are expanded otherwise collapsed"
  1215     "Modified: / 28-07-2018 / 13:48:49 / Claus Gittinger"
  1217     "Modified: / 28-07-2018 / 13:48:49 / Claus Gittinger"
  1216     "Modified: / 02-08-2018 / 16:04:04 / Stefan Vogel"
  1218     "Modified: / 02-08-2018 / 16:04:04 / Stefan Vogel"
  1217     "Modified (comment): / 12-02-2019 / 18:49:58 / Claus Gittinger"
  1219     "Modified (comment): / 12-02-2019 / 18:49:58 / Claus Gittinger"
  1218 !
  1220 !
  1219 
  1221 
       
  1222 from:startIndex to:endIndex doOnCachedChildren:aOneArgBlock
       
  1223     "WARNING: This uses only the children, that are already known, i.e. it does
       
  1224      NOT fetch lazy children, but uses the list cached in the instance variable.
       
  1225      Evaluate a block on each child (non recursive),
       
  1226      starting with the child at startIndex to the endIndex (last index if nil).
       
  1227      Answer the value of the block executed on the last element.
       
  1228      cg: this is stupid: everyoe else in the world returns the receiver from do:-like messages,
       
  1229          and noone seems to need this last result (afaik).
       
  1230          Also: other enumeration methods found here don't do that (see from:to:reverseDo:)
       
  1231          So this ought to be changed."
       
  1232 
       
  1233     ^ self synchronized:[
       
  1234         self nonCriticalFrom:startIndex to:endIndex doOnCachedChildren:aOneArgBlock
       
  1235     ].
       
  1236 
       
  1237     "Created: / 11-12-2019 / 10:28:55 / Maren Tilk"
       
  1238 !
       
  1239 
  1220 from:startIndex to:endIndex reverseDo:aOneArgBlock
  1240 from:startIndex to:endIndex reverseDo:aOneArgBlock
  1221     "WARNING: may fetch lazy children
  1241     "WARNING: may fetch lazy children
  1222      evaluate a block on each child (non recursive),
  1242      evaluate a block on each child (non recursive),
  1223      starting with the child at endIndex to the startIndex."
  1243      starting with the child at endIndex to the startIndex."
  1224 
  1244 
  1317     ].
  1337     ].
  1318 
  1338 
  1319     "Created: / 07-05-2019 / 13:12:53 / Claus Gittinger"
  1339     "Created: / 07-05-2019 / 13:12:53 / Claus Gittinger"
  1320     "Modified: / 30-09-2019 / 12:01:04 / Maren"
  1340     "Modified: / 30-09-2019 / 12:01:04 / Maren"
  1321     "Modified (comment): / 30-09-2019 / 18:02:46 / Maren"
  1341     "Modified (comment): / 30-09-2019 / 18:02:46 / Maren"
       
  1342 !
       
  1343 
       
  1344 recursiveDoOnCachedChildren:aOneArgBlock
       
  1345     "WARNING: This uses only the children, that are already known, i.e. it does
       
  1346      NOT fetch lazy children, but uses the list cached in the instance variable.
       
  1347      Evaluate a block on each item and all the sub-items.
       
  1348      Warning: this only enumerates already visible child elements
       
  1349      i.e. any collapsed items are not visited."
       
  1350 
       
  1351     self from:1 to:nil doOnCachedChildren:[:aChild| "/ notice: do does it synchronized
       
  1352         aOneArgBlock value:aChild.
       
  1353         aChild nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock
       
  1354     ].
       
  1355 
       
  1356     "Created: / 11-12-2019 / 10:32:19 / Maren Tilk"
  1322 !
  1357 !
  1323 
  1358 
  1324 recursiveReverseDo:aOneArgBlock
  1359 recursiveReverseDo:aOneArgBlock
  1325     "WARNING: may fetch lazy children
  1360     "WARNING: may fetch lazy children
  1326      evaluate a block on each item and all the sub-items;
  1361      evaluate a block on each item and all the sub-items;
  1737     "Modified (comment): / 02-08-2018 / 16:02:13 / Stefan Vogel"
  1772     "Modified (comment): / 02-08-2018 / 16:02:13 / Stefan Vogel"
  1738     "Modified: / 12-02-2019 / 16:55:20 / Claus Gittinger"
  1773     "Modified: / 12-02-2019 / 16:55:20 / Claus Gittinger"
  1739     "Modified (comment): / 05-03-2019 / 09:37:28 / Claus Gittinger"
  1774     "Modified (comment): / 05-03-2019 / 09:37:28 / Claus Gittinger"
  1740 !
  1775 !
  1741 
  1776 
       
  1777 nonCriticalFrom:startIndex to:endIndex doOnCachedChildren:aOneArgBlock
       
  1778     <resource: #todo>
       
  1779     "WARNING: This uses only the children, that are already known, i.e. it does
       
  1780      NOT fetch lazy children, but uses the list cached in the instance variable.
       
  1781      Evaluate a block noncritical for each child starting with the
       
  1782      child at startIndex to the endIndex (if nil: to end of list).
       
  1783      Returns the value of the last block's evaluation.
       
  1784      Not synchronized - should only be called internally
       
  1785      within a synchronized region.
       
  1786      Answer the value of the block executed on the last element."
       
  1787 
       
  1788     "/ TODO method is a copy of #nonCriticalFrom:to:do:
       
  1789     |list size resp|
       
  1790 
       
  1791     list := children ? #().
       
  1792     size := list size.
       
  1793 
       
  1794     startIndex > size ifTrue:[^ nil].
       
  1795     resp := nil.
       
  1796 
       
  1797     endIndex notNil ifTrue:[
       
  1798         size := size min:endIndex
       
  1799     ].
       
  1800     startIndex to:size do:[:i| 
       
  1801         |item|
       
  1802 
       
  1803         item := list at:i ifAbsent:nil.
       
  1804         item isNil ifTrue:[self halt:'oops - lost child item?'. ^ resp].
       
  1805         resp := aOneArgBlock value:item.
       
  1806     ].
       
  1807     ^ resp
       
  1808 
       
  1809     "Created: / 11-12-2019 / 10:17:39 / Maren Tilk"
       
  1810     "Modified (comment): / 11-12-2019 / 14:59:39 / Maren Tilk"
       
  1811 !
       
  1812 
  1742 nonCriticalFrom:startIndex to:endIndexArg reverseDo:aOneArgBlock
  1813 nonCriticalFrom:startIndex to:endIndexArg reverseDo:aOneArgBlock
  1743     "WARNING: may fetch lazy children (i.e. calls #children)
  1814     "WARNING: may fetch lazy children (i.e. calls #children)
  1744      evaluate a block non critical for each child starting with the
  1815      evaluate a block non critical for each child starting with the
  1745      child at endIndex (if nil: from the end of list) down to to startIndex.
  1816      child at endIndex (if nil: from the end of list) down to to startIndex.
  1746      Returns the value of the last block's evaluation.
  1817      Returns the value of the last block's evaluation.
  1803         aOneArgBlock value:eachChild.
  1874         aOneArgBlock value:eachChild.
  1804         eachChild nonCriticalRecursiveDo:aOneArgBlock
  1875         eachChild nonCriticalRecursiveDo:aOneArgBlock
  1805     ].
  1876     ].
  1806 
  1877 
  1807     "Modified (comment): / 05-03-2019 / 09:37:48 / Claus Gittinger"
  1878     "Modified (comment): / 05-03-2019 / 09:37:48 / Claus Gittinger"
       
  1879 !
       
  1880 
       
  1881 nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock
       
  1882     "WARNING: This uses only the children, that are already known, i.e. it does
       
  1883      NOT call #children, but uses the list cached in the instance variable.
       
  1884      Not synchronized - should only be called internally
       
  1885      within a synchronized region."
       
  1886 
       
  1887     self nonCriticalFrom:1 to:nil doOnCachedChildren:[:eachChild|
       
  1888         aOneArgBlock value:eachChild.
       
  1889         eachChild nonCriticalRecursiveDoOnCachedChildren:aOneArgBlock
       
  1890     ].
       
  1891 
       
  1892     "Created: / 11-12-2019 / 10:38:58 / Maren Tilk"
  1808 !
  1893 !
  1809 
  1894 
  1810 nonCriticalRecursiveReverseDo:aOneArgBlock
  1895 nonCriticalRecursiveReverseDo:aOneArgBlock
  1811     "WARNING: may fetch lazy children (i.e. calls #children)
  1896     "WARNING: may fetch lazy children (i.e. calls #children)
  1812      evaluate the block non critical for each item and all the sub-items;
  1897      evaluate the block non critical for each item and all the sub-items;