ResourceSelectionBrowser.st
changeset 425 cf47d420764a
child 426 b8110a424326
equal deleted inserted replaced
424:2137dff405f0 425:cf47d420764a
       
     1 "
       
     2  COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
       
     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 SelectionBrowser subclass:#ResourceSelectionBrowser
       
    15 	instanceVariableNames:'resourceMethod resourceClass resourceSuperclass resourceTypes'
       
    16 	classVariableNames:''
       
    17 	poolDictionaries:''
       
    18 	category:'Interface-Advanced-Tools'
       
    19 !
       
    20 
       
    21 !ResourceSelectionBrowser class methodsFor:'documentation'!
       
    22 
       
    23 copyright
       
    24 "
       
    25  COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
       
    26               All Rights Reserved
       
    27 
       
    28  This software is furnished under a license and may be used
       
    29  only in accordance with the terms of that license and with the
       
    30  inclusion of the above copyright notice. This software may not
       
    31  be provided or otherwise made available to, or used by, any
       
    32  other person. No title to or ownership of the software is
       
    33  hereby transferred.
       
    34 "
       
    35 
       
    36 !
       
    37 
       
    38 documentation
       
    39 "
       
    40     documentation to be added.
       
    41 "
       
    42 !
       
    43 
       
    44 history
       
    45     "Created: / 10.1.1998 / 10:59:18 / tz"
       
    46 ! !
       
    47 
       
    48 !ResourceSelectionBrowser class methodsFor:'instance creation'!
       
    49 
       
    50 request: aTitle onSuperclass: aSuperclass andClass: aClass andSelector: aSelector withResourceTypes: aResourceTypes
       
    51 
       
    52     "self
       
    53         request: 'Select A Resource Selector'
       
    54         onSuperclass: #ApplicationModel 
       
    55         andClass: #ToolApplicationModel 
       
    56         andSelector: #saveIcon 
       
    57         withResourceTypes: #(canvas menu image) 
       
    58     "
       
    59 
       
    60     ^self new
       
    61         title: aTitle;
       
    62         openOnSuperclass: aSuperclass
       
    63         andClass: aClass
       
    64         andSelector: aSelector
       
    65         withResourceTypes: aResourceTypes
       
    66 ! !
       
    67 
       
    68 !ResourceSelectionBrowser class methodsFor:'interface specs'!
       
    69 
       
    70 windowSpec
       
    71     "this window spec was automatically generated by the ST/X UIPainter"
       
    72 
       
    73     "do not manually edit this - the painter/builder may not be able to
       
    74      handle the specification if its corrupted."
       
    75 
       
    76     "
       
    77      UIPainter new openOnClass:ResourceSelectionBrowser andSelector:#windowSpec
       
    78      ResourceSelectionBrowser new openInterface:#windowSpec
       
    79     "
       
    80     "ResourceSelectionBrowser open"
       
    81 
       
    82     <resource: #canvas>
       
    83 
       
    84     ^
       
    85      
       
    86        #(#FullSpec
       
    87           #'window:' 
       
    88            #(#WindowSpec
       
    89               #'name:' 'Resource Browser'
       
    90               #'layout:' #(#LayoutFrame 177 0 194 0 576 0 493 0)
       
    91               #'label:' 'Resource Browser'
       
    92               #'min:' #(#Point 400 300)
       
    93               #'max:' #(#Point 1152 864)
       
    94               #'bounds:' #(#Rectangle 177 194 577 494)
       
    95               #'usePreferredExtent:' false
       
    96           )
       
    97           #'component:' 
       
    98            #(#SpecCollection
       
    99               #'collection:' 
       
   100                #(
       
   101                  #(#VariableHorizontalPanelSpec
       
   102                     #'name:' 'variableHorizontalPanel'
       
   103                     #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -40 1.0)
       
   104                     #'component:' 
       
   105                      #(#SpecCollection
       
   106                         #'collection:' 
       
   107                          #(
       
   108                            #(#ViewSpec
       
   109                               #'name:' 'view1'
       
   110                               #'component:' 
       
   111                                #(#SpecCollection
       
   112                                   #'collection:' 
       
   113                                    #(
       
   114                                      #(#SelectionInTreeViewSpec
       
   115                                         #'name:' 'listOfClassesView'
       
   116                                         #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
   117                                         #'model:' #selectionOfClass
       
   118                                         #'hasHorizontalScrollBar:' true
       
   119                                         #'hasVerticalScrollBar:' true
       
   120                                         #'miniScrollerHorizontal:' true
       
   121                                         #'showRoot:' false
       
   122                                         #'valueChangeSelector:' #'classSelected:'
       
   123                                         #'hierarchicalList:' #listOfClasses
       
   124                                     )
       
   125                                   )
       
   126                               )
       
   127                               #'level:' -1
       
   128                           )
       
   129                            #(#ViewSpec
       
   130                               #'name:' 'view2'
       
   131                               #'component:' 
       
   132                                #(#SpecCollection
       
   133                                   #'collection:' 
       
   134                                    #(
       
   135                                      #(#DataSetSpec
       
   136                                         #'name:' 'resourcesDataSetView'
       
   137                                         #'layout:' #(#LayoutFrame 2 0.0 0 0.0 2 1.0 -22 1.0)
       
   138                                         #'model:' #selectionOfResource
       
   139                                         #'hasHorizontalScrollBar:' true
       
   140                                         #'hasVerticalScrollBar:' true
       
   141                                         #'miniScrollerHorizontal:' true
       
   142                                         #'dataList:' #listOfResources
       
   143                                         #'useIndex:' false
       
   144                                         #'doubleClickSelector:' #resourceDoubleClicked
       
   145                                         #'valueChangeSelector:' #resourceSelected
       
   146                                         #'verticalSpacing:' 1
       
   147                                         #'columns:' 
       
   148                                          #(
       
   149                                            #(#DataSetColumnSpec
       
   150                                               #'width:' 20
       
   151                                               #'height:' 24
       
   152                                               #'printSelector:' #'iconOn:'
       
   153                                               #'canSelect:' false
       
   154                                           )
       
   155                                            #(#DataSetColumnSpec
       
   156                                               #'label:' 'Selector'
       
   157                                               #'model:' #selector
       
   158                                               #'canSelect:' false
       
   159                                           )
       
   160                                            #(#DataSetColumnSpec
       
   161                                               #'label:' 'Resource'
       
   162                                               #'model:' #resourceType
       
   163                                               #'canSelect:' false
       
   164                                           )
       
   165                                         )
       
   166                                     )
       
   167                                      #(#InputFieldSpec
       
   168                                         #'name:' 'selectorInputField'
       
   169                                         #'layout:' #(#LayoutFrame 2 0.0 -22 1 2 1.0 0 1)
       
   170                                         #'model:' #valueOfSelector
       
   171                                     )
       
   172                                   )
       
   173                               )
       
   174                               #'level:' -1
       
   175                           )
       
   176                         )
       
   177                     )
       
   178                     #'handles:' #(#Any 0.5 1.0)
       
   179                 )
       
   180                  #(#HorizontalPanelViewSpec
       
   181                     #'name:' 'horizontalPanelView'
       
   182                     #'layout:' #(#LayoutFrame 0 0.0 -40 1 0 1.0 0 1.0)
       
   183                     #'component:' 
       
   184                      #(#SpecCollection
       
   185                         #'collection:' 
       
   186                          #(
       
   187                            #(#ActionButtonSpec
       
   188                               #'name:' 'actionButton2'
       
   189                               #'label:' 'Cancel'
       
   190                               #'model:' #cancel
       
   191                               #'extent:' #(#Point 99 24)
       
   192                           )
       
   193                            #(#ActionButtonSpec
       
   194                               #'name:' 'actionButton1'
       
   195                               #'label:' 'OK'
       
   196                               #'model:' #accept
       
   197                               #'extent:' #(#Point 99 24)
       
   198                           )
       
   199                         )
       
   200                     )
       
   201                     #'level:' 1
       
   202                     #'horizontalLayout:' #center
       
   203                     #'verticalLayout:' #center
       
   204                     #'horizontalSpace:' 3
       
   205                     #'verticalSpace:' 3
       
   206                 )
       
   207               )
       
   208           )
       
   209       )
       
   210 ! !
       
   211 
       
   212 !ResourceSelectionBrowser methodsFor:'accessing - views'!
       
   213 
       
   214 listOfClassesView
       
   215 
       
   216     ^builder componentAt: #listOfClassesView
       
   217 ! !
       
   218 
       
   219 !ResourceSelectionBrowser methodsFor:'aspects'!
       
   220 
       
   221 listOfClasses
       
   222 
       
   223     |holder|
       
   224     (holder := builder bindingAt:#listOfClasses) isNil ifTrue:[
       
   225         builder aspectAt:#listOfClasses put:
       
   226             (holder := 
       
   227                 (TreeItem name: resourceSuperclass)
       
   228                     children: (OrderedCollection with:
       
   229                         (TreeItem newAsTreeFromSmalltalkClass: (Smalltalk at:resourceSuperclass))))
       
   230     ].
       
   231     ^ holder
       
   232 
       
   233 
       
   234 !
       
   235 
       
   236 listOfResources
       
   237 
       
   238     |holder|
       
   239     (holder := builder bindingAt:#listOfResources) isNil ifTrue:[
       
   240         builder aspectAt:#listOfResources put:(holder :=  List new).
       
   241     ].
       
   242     ^ holder
       
   243 !
       
   244 
       
   245 selectionOfClass
       
   246 
       
   247     |holder|
       
   248     (holder := builder bindingAt:#selectionOfClass) isNil ifTrue:[
       
   249         builder aspectAt:#selectionOfClass put:(holder :=  ValueHolder new).
       
   250     ].
       
   251     ^ holder
       
   252 !
       
   253 
       
   254 selectionOfResource
       
   255 
       
   256     |holder|
       
   257     (holder := builder bindingAt:#selectionOfResource) isNil ifTrue:[
       
   258         builder aspectAt:#selectionOfResource put:(holder :=  '' asValue).
       
   259     ].
       
   260     ^ holder
       
   261 !
       
   262 
       
   263 valueOfSelector
       
   264 
       
   265     |holder|
       
   266     (holder := builder bindingAt:#valueOfSelector) isNil ifTrue:[
       
   267         builder aspectAt:#valueOfSelector put:(holder :=  '' asValue).
       
   268     ].
       
   269     ^ holder
       
   270 ! !
       
   271 
       
   272 !ResourceSelectionBrowser methodsFor:'callbacks'!
       
   273 
       
   274 classSelected: anIndex
       
   275     
       
   276     self selectionOfClass value isNil ifTrue: [^nil].
       
   277     self withWaitCursorDo:
       
   278     [
       
   279         |clsName|
       
   280         resourceTypes isNil ifTrue: [resourceTypes := #(canvas menu image fileImage)].
       
   281         clsName := self listOfClassesView list at: anIndex.
       
   282         self class lastSelection: clsName.
       
   283         self listOfResources contents:
       
   284             ((Smalltalk at: clsName) 
       
   285                 class methodDictionary
       
   286                 asOrderedCollection select: 
       
   287                     [:m| m resources notNil and: [resourceTypes includes: m resourceType]]).
       
   288     ]
       
   289 !
       
   290 
       
   291 resourceDoubleClicked
       
   292 
       
   293     resourceMethod := self selectionOfResource value.
       
   294     accept value: true.
       
   295     self close
       
   296 !
       
   297 
       
   298 resourceSelected
       
   299 
       
   300     resourceMethod := self selectionOfResource value.
       
   301     self valueOfSelector value: self selectionOfResource value selector
       
   302 ! !
       
   303 
       
   304 !ResourceSelectionBrowser methodsFor:'initialization'!
       
   305 
       
   306 postBuildWith:aBuilder
       
   307 
       
   308     self listOfClassesView selectFromListOfNames: 
       
   309             (((Smalltalk at: self class lastSelection ? resourceClass ifAbsent: [Object]))
       
   310                 withAllSuperclasses reverse collect: [:cls| cls name asString]).
       
   311 
       
   312     ^super postBuildWith:aBuilder
       
   313 
       
   314 ! !
       
   315 
       
   316 !ResourceSelectionBrowser methodsFor:'instance creation'!
       
   317 
       
   318 openOnSuperclass: aSuperclassOrSymbol andClass: aClassOrSymbol andSelector: aSelector withResourceTypes: aResourceTypes
       
   319 
       
   320     |cls sel|
       
   321     resourceTypes := aResourceTypes.
       
   322     resourceSuperclass := aSuperclassOrSymbol isClass ifTrue: [aSuperclassOrSymbol name] ifFalse: [aSuperclassOrSymbol].
       
   323     resourceClass := aClassOrSymbol isClass ifTrue: [aClassOrSymbol name] ifFalse: [aClassOrSymbol].
       
   324     self valueOfSelector value: aSelector.
       
   325 
       
   326     self open. 
       
   327     (self selectionOfClass value notNil and: [
       
   328     (cls := Smalltalk at: self selectionOfClass value name) isClass &
       
   329     (cls class implements: (sel := self valueOfSelector value)) &
       
   330     accept value])
       
   331     ifTrue:
       
   332     [
       
   333         ^cls name, ' ', sel
       
   334     ].
       
   335     ^nil
       
   336 ! !
       
   337 
       
   338 !ResourceSelectionBrowser methodsFor:'startup / release'!
       
   339 
       
   340 closeCancel
       
   341 
       
   342     resourceMethod := nil.
       
   343     super closeCancel
       
   344 
       
   345 
       
   346 
       
   347 ! !
       
   348 
       
   349 !ResourceSelectionBrowser class methodsFor:'documentation'!
       
   350 
       
   351 version
       
   352     ^ '$Header$'
       
   353 ! !