ClassRevisionTree.st
changeset 2612 ce84f1d3dae9
parent 2547 49e7cb306cd5
child 2625 d70f0361a027
equal deleted inserted replaced
2611:143fe4202159 2612:ce84f1d3dae9
     1 ApplicationModel subclass:#ClassRevisionTree
     1 ApplicationModel subclass:#ClassRevisionTree
     2 	instanceVariableNames:'selectionHolder classHolder menuBlock selectionBlock
     2 	instanceVariableNames:'selectionHolder dataHolder menuBlock selectionBlock listView
     3 		classItemClass listView semaphoreCritical revisionInfoList
     3 		hierarchicalList'
     4 		revisionTask currentClassItemInTask'
       
     5 	classVariableNames:''
     4 	classVariableNames:''
     6 	poolDictionaries:''
     5 	poolDictionaries:''
     7 	category:'Interface-Browsers-Support'
     6 	category:'Interface-Browsers-Support'
     8 !
     7 !
     9 
     8 
    77       )
    76       )
    78 ! !
    77 ! !
    79 
    78 
    80 !ClassRevisionTree class methodsFor:'protocol'!
    79 !ClassRevisionTree class methodsFor:'protocol'!
    81 
    80 
    82 classItemClass
       
    83 
       
    84     ^ClassItem
       
    85 !
       
    86 
       
    87 classItemRootClass
    81 classItemRootClass
    88 
    82 
    89     ^ClassItemRoot
    83     ^ClassItemRoot
    90 ! !
    84 ! !
    91 
    85 
    95 
    89 
    96     |theTree|
    90     |theTree|
    97 
    91 
    98     theTree := self new.
    92     theTree := self new.
    99     theTree allButOpen.
    93     theTree allButOpen.
       
    94     theTree classItemRootClass:ClassItemRoot.
   100     theTree classHolder:aClassHolder.
    95     theTree classHolder:aClassHolder.
   101     theTree openWindow.
    96     theTree openWindow.
   102      ^theTree
    97      ^theTree
   103 
    98 
   104 "
    99 "
   111 theClassHolder value:(Smalltalk allClasses asOrderedCollection sort:[:x : y|x name < y name]).
   106 theClassHolder value:(Smalltalk allClasses asOrderedCollection sort:[:x : y|x name < y name]).
   112 theTree := ClassRevisionTree openOnClassHolder:theClassHolder.
   107 theTree := ClassRevisionTree openOnClassHolder:theClassHolder.
   113 theSelectionHolder value:(Array with:(theTree itemList children last)).
   108 theSelectionHolder value:(Array with:(theTree itemList children last)).
   114 theTree selectionHolder:theSelectionHolder.
   109 theTree selectionHolder:theSelectionHolder.
   115 Delay waitForMilliseconds:1500.
   110 Delay waitForMilliseconds:1500.
   116 theClassHolder value:(Project current changedClasses).
   111 theClassHolder value:(Project current changedClasses asOrderedCollection).
   117 Delay waitForMilliseconds:1500.
   112 Delay waitForMilliseconds:1500.
   118 theTree classHolder:nil.
   113 theTree classHolder:nil.
   119 Delay waitForMilliseconds:1500.
   114 Delay waitForMilliseconds:1500.
   120 theTree classHolder:theClassHolder.
   115 theTree classHolder:theClassHolder.
   121 Delay waitForMilliseconds:1500.
   116 Delay waitForMilliseconds:1500.
   124 
   119 
   125 
   120 
   126 
   121 
   127 !
   122 !
   128 
   123 
   129 openOnClasses:aClassColl
   124 openOnClassRevisionInfoColl:aClassRevisionInfoColl
   130 
   125 
   131     |theTree|
   126     |theTree|
   132 
   127 
   133     theTree := self new.
   128     theTree := self new.
   134     theTree allButOpen.
   129     theTree allButOpen.
   135     theTree classHolder value:aClassColl.
   130     theTree classItemRootClass:ClassItemRootForRevision.
       
   131     theTree dataHolder value:aClassRevisionInfoColl.
   136     theTree openWindow.
   132     theTree openWindow.
   137      ^theTree
   133      ^theTree
       
   134 "
       
   135 |theTree infoLog|
       
   136 
       
   137 infoLog := OrderedCollection new.
       
   138 CVSSourceCodeManager reportHistoryLogSince:'yesterday'
       
   139         filterSTSources:true 
       
   140         filterUser:nil 
       
   141         filterRepository:nil 
       
   142         inTo:[:info| infoLog add:info].
       
   143 
       
   144 theTree := self new.
       
   145 theTree open.
       
   146 theTree classItemRootClass:ClassItemRootForRevision.
       
   147 theTree setupOnClasses:infoLog
       
   148 "
       
   149 
       
   150 "
       
   151 |infoLog|
       
   152 
       
   153 infoLog := OrderedCollection new.
       
   154 CVSSourceCodeManager reportHistoryLogSince:'yesterday'
       
   155         filterSTSources:true 
       
   156         filterUser:nil 
       
   157         filterRepository:nil 
       
   158         inTo:[:info| infoLog add:info].
       
   159 self openOnClassRevisionInfoColl:infoLog.
       
   160 "
       
   161 !
       
   162 
       
   163 openOnClasses:aClassColl
       
   164 
       
   165     |theTree|
       
   166 
       
   167     theTree := self new.
       
   168     theTree classItemRootClass:ClassItemRoot.
       
   169     theTree allButOpen.
       
   170     theTree setupOnClasses:aClassColl.
       
   171     theTree openWindow.
       
   172     ^theTree
       
   173 "
       
   174 self openOnClasses:(Smalltalk allClasses asOrderedCollection sort:[:x : y|x name < y name]).
       
   175 "
   138 
   176 
   139 "
   177 "
   140 |theSelectionHolder theTree|
   178 |theSelectionHolder theTree|
   141 
   179 
   142 theSelectionHolder := ValueHolder new.
   180 theSelectionHolder := ValueHolder new.
   148 "
   186 "
   149 ! !
   187 ! !
   150 
   188 
   151 !ClassRevisionTree methodsFor:'accessing'!
   189 !ClassRevisionTree methodsFor:'accessing'!
   152 
   190 
   153 classItemClass
   191 dataHolder
   154     "return the value of the instance variable 'classItemClass' (automatically generated)"
   192     "return the value of the instance variable 'classHolder' (automatically generated)"
   155 
   193 
   156     ^ classItemClass ifNil:[classItemClass := self class classItemClass]
   194     ^dataHolder ifNil:[
   157 !
   195         dataHolder := ValueHolder new.
   158 
   196         dataHolder addDependent:self
   159 classItemClass:something
   197     ]
   160     "set the value of the instance variable 'classItemClass' (automatically generated)"
   198 !
   161 
   199 
   162     classItemClass := something.!
   200 dataHolder:aValueHolder
   163 
   201     "set the value of the instance variable 'classHolder' (automatically generated)"
   164 classItemRootClass
   202 
   165     "return the value of the instance variable 'classItemClass' (automatically generated)"
   203     (dataHolder ~~ aValueHolder) ifTrue:[
   166 
   204         dataHolder removeDependent:self.
   167     ^ self class classItemRootClass
   205         dataHolder := aValueHolder.
       
   206         dataHolder notNil ifTrue:[
       
   207             dataHolder addDependent:self.
       
   208         ].
       
   209         self setUpList
       
   210     ].
       
   211 !
       
   212 
       
   213 hierarchicalList
       
   214 "
       
   215 returns a hierarchical list which is the model for tree. All necassary things like icons,
       
   216 root and subnodes must be hold by this list. Therefore the list must have a special protocoll.
       
   217 See examples.
       
   218 
       
   219 <return: HierarchicalList>
       
   220 "
       
   221 
       
   222     hierarchicalList isNil
       
   223         ifTrue:[self error: 'no necessary list is set'. "hierarchicalList := HierarchicalList new"].
       
   224     ^ hierarchicalList
       
   225 !
       
   226 
       
   227 hierarchicalList:aHierarchicalList
       
   228 "
       
   229 sets the hierarchical list which is the model for tree. All necassary things like icons
       
   230 root and subnodes must be hold by this list. Therefore the list must have a special protocoll.
       
   231 See examples.
       
   232 
       
   233 <return: self>
       
   234 "
       
   235 
       
   236     hierarchicalList := aHierarchicalList.
   168 !
   237 !
   169 
   238 
   170 itemForSelectionIndex:anIndex
   239 itemForSelectionIndex:anIndex
   171 ""
   240 "
       
   241 
       
   242 <return: HierarchicalItem | nil >
       
   243 "
   172     ^self listModel at:anIndex ifAbsent:nil
   244     ^self listModel at:anIndex ifAbsent:nil
   173 !
   245 !
   174 
   246 
   175 itemList
   247 itemList
   176     "automatically generated by UIPainter ..."
   248     "automatically generated by UIPainter ..."
   185 
   257 
   186 
   258 
   187 
   259 
   188 !
   260 !
   189 
   261 
   190 revisionInfoList
   262 listView
   191     "return the value of the instance variable 'revisionInfoList' (automatically generated)"
   263     "return the value of the instance variable 'listView' (automatically generated)"
   192 
   264 
   193     ^ revisionInfoList ifNil:[revisionInfoList := IdentitySet new]
   265     ^ listView!
   194 !
   266 
   195 
   267 listView:something
   196 semaphoreCritical
   268     "set the value of the instance variable 'listView' (automatically generated)"
   197     "return the value of the instance variable 'semaphoreCritical' (automatically generated)"
   269 
   198 
   270     listView := something.! !
   199     ^ semaphoreCritical ifNil:[semaphoreCritical := RecursionLock new]
       
   200 ! !
       
   201 
   271 
   202 !ClassRevisionTree methodsFor:'actions'!
   272 !ClassRevisionTree methodsFor:'actions'!
   203 
   273 
   204 doubleClick:anIndex
   274 doubleClick:anIndex
   205 
   275 
   206     |theItem|
   276     |theItem|
   207 
   277 
   208     (((theItem := self itemForSelectionIndex:anIndex) isExpandableRevisionItem) and:[listView sensor shiftDown])
   278     theItem := self itemForSelectionIndex:anIndex. self halt.
   209         ifTrue: [theItem recursiveToggleExpand]
   279     self listModel root doubleClickOn:theItem.
   210         ifFalse:[theItem toggleExpand]  
   280 
   211 !
       
   212 
       
   213 getRevisionInfoForClassItem: aClassItem
       
   214 
       
   215     self semaphoreCritical critical:[
       
   216         |theList|
       
   217         currentClassItemInTask == aClassItem ifTrue:[^self].
       
   218         (theList := self revisionInfoList) removeIdentical:aClassItem ifAbsent:[nil].
       
   219         theList add:aClassItem.
       
   220         self startRevisionTask]
       
   221 !
   281 !
   222 
   282 
   223 isItemSelectable:anIndex
   283 isItemSelectable:anIndex
   224 "
   284 "
   225 checks if an item at anIndex can be selected. If an selection block
   285 checks if an item at anIndex can be selected. If an selection block
   234 ! !
   294 ! !
   235 
   295 
   236 !ClassRevisionTree methodsFor:'aspects'!
   296 !ClassRevisionTree methodsFor:'aspects'!
   237 
   297 
   238 icons
   298 icons
   239     |icons|
   299 "
   240 
   300 gets the icons from hierarchical list which should be registered on the view. 
   241     icons := Dictionary new.
   301 
   242     icons at:#loadedRevision put:(Image fromFile:'gifImages/artwork/dots/red_ball.gif').
   302 <return: Dictionary of: Symbol->Image | nil>
   243     icons at:#unloadedRevision put:(Image fromFile:'gifImages/artwork/dots/green_ball.gif').
   303 "
   244     icons at:#unloadedClassItem put:(Image fromFile:'xpmBitmaps/file_images/small_folder_yellow_grey1.xpm').
   304     ^self hierarchicalList icons
   245     icons at:#loadingClassItem put:(Image fromFile:'xpmBitmaps/file_images/small_folder_yellow_search.xpm').
       
   246     icons at:#loadedClassItem put:(Image fromFile:'xpmBitmaps/file_images/small_folder_yellow.xpm').
       
   247     ^icons
       
   248 !
   305 !
   249 
   306 
   250 listModel
   307 listModel
   251     "automatically generated by UIPainter ..."
   308 "
   252 
   309 
   253     "*** the code below creates a default model when invoked."
   310 <return: HierarchicalList>
   254     "*** (which may not be the one you wanted)"
   311 "
   255     "*** Please change as required and accept it in the browser."
       
   256 
       
   257     |holder|
   312     |holder|
   258 
   313 
   259     (holder := builder bindingAt:#listModel) isNil ifTrue:[
   314     (holder := builder bindingAt:#listModel) isNil ifTrue:[
   260         holder := HierarchicalList new.
   315         holder := self hierarchicalList.
   261         holder root:(self classItemRootClass new).
       
   262         holder showRoot:false.
       
   263         builder aspectAt:#listModel put:holder.
   316         builder aspectAt:#listModel put:holder.
   264         holder application:self.
   317         holder application:self.
   265     ].
   318     ].
   266     ^ holder.
   319     ^ holder.
   267 ! !
   320 ! !
   268 
   321 
   269 !ClassRevisionTree methodsFor:'change & update'!
   322 !ClassRevisionTree methodsFor:'change & update'!
   270 
   323 
   271 update:something with:aParameter from:changedObject
   324 update:something with:aParameter from:changedObject
   272 
   325 
   273      changedObject == self classHolder
   326      changedObject == self dataHolder
   274         ifTrue:[self setUpItemList].
   327         ifTrue:[self setUpList].
   275 
   328 
   276 
   329 
   277 ! !
   330 ! !
   278 
   331 
   279 !ClassRevisionTree methodsFor:'interface opening'!
   332 !ClassRevisionTree methodsFor:'interface opening'!
   280 
   333 
   281 postBuildWith: aBuilder
   334 postBuildWith: aBuilder
   282 
   335 
   283     super postBuildWith: aBuilder.
   336     super postBuildWith: aBuilder.
   284     listView := self builder componentAt:#HierarchicalItemListView.
   337     self listView:(self builder componentAt:#HierarchicalItemListView).
   285     selectionHolder notNil
   338     selectionHolder notNil
   286         ifTrue:[listView model:selectionHolder].
   339         ifTrue:[listView model:selectionHolder].
   287     listView useDefaultIcons:false.
   340     self listView useDefaultIcons:false.
   288 !
   341 !
   289 
   342 
   290 release
   343 release
   291 
   344 
   292     self stopRevisionTask.    
   345 "/    self stopItemTask.    
   293     ^super release
   346     ^super release
   294 
   347 
   295 
   348 
   296 ! !
   349 ! !
   297 
   350 
   307     ^ [ menuBlock value ]
   360     ^ [ menuBlock value ]
   308 ! !
   361 ! !
   309 
   362 
   310 !ClassRevisionTree methodsFor:'private'!
   363 !ClassRevisionTree methodsFor:'private'!
   311 
   364 
   312 revisionTaskCycle
   365 setUpList
   313 
   366 
   314     |theClassItem|
   367     self halt.
   315 
   368     ^self hierarchicalList newData: self dataHolder value
   316     [
       
   317         theClassItem := nil.
       
   318         self semaphoreCritical critical:[
       
   319             self revisionInfoList notEmpty
       
   320                 ifTrue:[theClassItem := self revisionInfoList remove:(self revisionInfoList last) ifAbsent:[nil]]
       
   321         ].
       
   322         (theClassItem notNil and:[theClassItem needsChildren])ifTrue:[
       
   323             currentClassItemInTask:=theClassItem.
       
   324             theClassItem computeRevisions.
       
   325             currentClassItemInTask:=nil
       
   326         ].
       
   327         theClassItem notNil
       
   328     ] whileTrue.
       
   329 !
       
   330 
       
   331 setUpItemList
       
   332 
       
   333     |theClassColl theClassItemColl root|
       
   334 
       
   335     root := self classItemRootClass new.
       
   336     (theClassColl := self classHolder value) notNil ifTrue:[
       
   337         theClassItemColl := theClassColl collect:[:eachClass |
       
   338             |theClassItem theClass|
       
   339             theClassItem := self classItemClass new.
       
   340             theClass := Smalltalk resolveName:eachClass inClass:Smalltalk.
       
   341             theClassItem myClass:theClass.
       
   342             theClassItem].
       
   343        root addAll: theClassItemColl.
       
   344     ].  
       
   345     self listModel root:root.
       
   346 !
       
   347 
       
   348 startRevisionTask
       
   349 
       
   350     self semaphoreCritical critical:[
       
   351         revisionTask ifNil:[
       
   352             revisionTask := Process for:[
       
   353                                             self revisionTaskCycle
       
   354                                         ]
       
   355                                priority:(Processor userBackgroundPriority).
       
   356             revisionTask addExitAction:[revisionTask := nil].
       
   357             revisionTask resume.
       
   358         ].
       
   359     ].
       
   360 !
       
   361 
       
   362 stopRevisionTask
       
   363     |task|
       
   364 
       
   365     self semaphoreCritical critical:[
       
   366         (task := revisionTask) notNil ifTrue:[
       
   367             revisionTask := nil.
       
   368             Exception handle:[:ex|] do:[
       
   369                 task terminateWithAllSubprocesses.
       
   370                 task waitUntilTerminated.
       
   371             ]
       
   372         ]
       
   373     ].
       
   374 
       
   375 ! !
   369 ! !
   376 
   370 
   377 !ClassRevisionTree methodsFor:'protocol accessing'!
   371 !ClassRevisionTree methodsFor:'protocol accessing'!
   378 
       
   379 classHolder
       
   380     "return the value of the instance variable 'classHolder' (automatically generated)"
       
   381 
       
   382     ^classHolder ifNil:[
       
   383         classHolder := ValueHolder new.
       
   384         classHolder addDependent:self
       
   385     ]
       
   386 !
       
   387 
       
   388 classHolder:aValueHolder
       
   389     "set the value of the instance variable 'classHolder' (automatically generated)"
       
   390 
       
   391     (classHolder ~~ aValueHolder) ifTrue:[
       
   392         classHolder removeDependent:self.
       
   393         classHolder := aValueHolder.
       
   394         classHolder notNil ifTrue:[
       
   395             classHolder addDependent:self.
       
   396         ].
       
   397         self setUpItemList
       
   398     ].
       
   399 !
       
   400 
   372 
   401 menuBlock
   373 menuBlock
   402     "return the value of the instance variable 'menuBlock' (automatically generated)"
   374     "return the value of the instance variable 'menuBlock' (automatically generated)"
   403 
   375 
   404     ^ menuBlock
   376     ^ menuBlock
   426 
   398 
   427 selectionHolder:aValueHolder
   399 selectionHolder:aValueHolder
   428     "set the value of the instance variable 'revisionItemSelection' (automatically generated)"
   400     "set the value of the instance variable 'revisionItemSelection' (automatically generated)"
   429 
   401 
   430     selectionHolder := aValueHolder.
   402     selectionHolder := aValueHolder.
   431     listView ifNil:[^self].
   403     self listView ifNil:[^self].
   432     listView model:selectionHolder
   404     self listView model:selectionHolder
   433 ! !
   405 ! !
   434 
   406 
   435 !ClassRevisionTree methodsFor:'protocol setup'!
   407 !ClassRevisionTree methodsFor:'protocol setup'!
   436 
   408 
   437 setupOnClasses:aClassColl
   409 setupOnData:aDataObject
   438 
   410 
   439     self classHolder value:aClassColl.
   411     self dataHolder value:aDataObject.
   440 "
   412 "
   441 |theTree|
   413 |theTree infoLog theHierarchicalList|
   442 
   414 
   443 theTree := ClassRevisionTree new.
   415 theTree := ClassRevisionTree new.
       
   416 theHierarchicalList := HierarchicalClassRevisionList new.
       
   417 theTree hierarchicalList:theHierarchicalList.
   444 theTree open.
   418 theTree open.
   445 theTree setupOnClasses:#(VersionDiffBrowser HierarchicalVersionDiffBrowser SourceRevisionItem Project)
   419 infoLog := OrderedCollection new.
       
   420 theTree setupOnData:infoLog.
       
   421 "
       
   422 "
       
   423 |theTree infoLog theHierarchicalList|
       
   424 
       
   425 theTree := ClassRevisionTree new.
       
   426 theHierarchicalList := HierarchicalClassRevisionList new.
       
   427 theTree hierarchicalList:theHierarchicalList.
       
   428 infoLog := OrderedCollection new.
       
   429 CVSSourceCodeManager reportHistoryLogSince:'yesterday'
       
   430         filterSTSources:true 
       
   431         filterUser:nil 
       
   432         filterRepository:nil 
       
   433         inTo:[:info| infoLog add:info].
       
   434 theTree open.
       
   435 theTree setupOnData:infoLog.
   446 "
   436 "
   447 ! !
   437 ! !
   448 
   438 
   449 !ClassRevisionTree class methodsFor:'documentation'!
   439 !ClassRevisionTree class methodsFor:'documentation'!
   450 
   440 
   451 version
   441 version
   452     ^ '$Header: /cvs/stx/stx/libtool/ClassRevisionTree.st,v 1.6 2000-01-14 15:57:06 cg Exp $'
   442     ^ '$Header: /cvs/stx/stx/libtool/ClassRevisionTree.st,v 1.7 2000-02-15 16:49:16 ps Exp $'
   453 ! !
   443 ! !