Tools__LintRuleSelectionDialog.st
author Claus Gittinger <cg@exept.de>
Fri, 21 Nov 2014 15:02:14 +0100
changeset 14879 c63c3f78cd2f
parent 14775 47d29c6f88ad
child 14922 fc6066810758
permissions -rw-r--r--
class: Tools::LintRuleSelectionDialog changed: #windowSpec

"
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
 Copyright (c) 2009-2010 eXept Software AG

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libtool' }"

"{ NameSpace: Tools }"

SimpleDialog subclass:#LintRuleSelectionDialog
	instanceVariableNames:'selectionHolder variablePanel relativeCorners detailsShown
		listSelection rulesetList rulesetHolder rulesetNameList
		rulesetNameHolder canAcceptHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Lint'
!

!LintRuleSelectionDialog class methodsFor:'documentation'!

copyright
"
 Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
 Copyright (c) 2009-2010 eXept Software AG

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
"
!

documentation
"
    documentation to be added.

    [author:]
        Jan Vrany (jv@neso)

    [instance variables:]

    [class variables:]

    [see also:]

"
!

examples
"
  Starting the application:
                                                                [exBegin]
    Tools::LintRuleSelectionDialog open

                                                                [exEnd]

  more examples to be added:
                                                                [exBegin]
    ... add code fragment for 
    ... executable example here ...
                                                                [exEnd]
"
! !

!LintRuleSelectionDialog class methodsFor:'interface specs'!

windowSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:Tools::LintRuleSelectionDialog andSelector:#windowSpec
     Tools::LintRuleSelectionDialog new openInterface:#windowSpec
     Tools::LintRuleSelectionDialog open
    "

    <resource: #canvas>

    ^ 
    #(FullSpec
       name: windowSpec
       window: 
      (WindowSpec
         label: 'Select Lint Rules'
         name: 'Select Lint Rules'
         min: (Point 10 10)
         bounds: (Rectangle 0 0 466 403)
       )
       component: 
      (SpecCollection
         collection: (
          (LinkButtonSpec
             label: 'Configure Rule Sets...'
             name: 'Button1'
             layout: (LayoutFrame -250 1 0 0 -3 1 24 0)
             translateLabel: true
             labelChannel: configureRulesetsButtonLabel
             adjust: right
             model: doConfigureRulesets
           )
          (HorizontalPanelViewSpec
             name: 'BottonPanel'
             layout: (LayoutFrame 0 0.0 -40 1 0 1.0 0 1)
             horizontalLayout: right
             verticalLayout: center
             horizontalSpace: 3
             verticalSpace: 3
             reverseOrderIfOKAtLeft: true
             component: 
            (SpecCollection
               collection: (
                (ActionButtonSpec
                   label: 'Cancel'
                   name: 'CancelButton'
                   translateLabel: true
                   model: doCancel
                   extent: (Point 159 25)
                 )
                (ActionButtonSpec
                   label: 'OK'
                   name: 'OKButton'
                   translateLabel: true
                   model: doAccept
                   enableChannel: canAcceptHolder
                   isDefault: true
                   defaultable: true
                   extent: (Point 159 25)
                 )
                )
              
             )
             keepSpaceForOSXResizeHandleH: true
           )
          (LabelSpec
             label: 'Select Ruleset'
             name: 'Label1'
             layout: (LayoutFrame 3 0 0 0 -250 1 24 0)
             translateLabel: true
             adjust: left
           )
          (SelectionInListModelViewSpec
             name: 'SelectionInListModelView1'
             layout: (LayoutFrame 3 0 30 0 -3 1 -40 1)
             model: rulesetHolder
             hasHorizontalScrollBar: true
             hasVerticalScrollBar: true
             listModel: rulesetList
             useIndex: false
             highlightMode: line
           )
          )
        
       )
     )
!

windowSpec_old
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:Tools::LintRuleSelectionDialog andSelector:#windowSpec
     Tools::LintRuleSelectionDialog new openInterface:#windowSpec
     Tools::LintRuleSelectionDialog open
    "

    <resource: #canvas>

    ^ 
    #(FullSpec
       name: windowSpec
       window: 
      (WindowSpec
         label: 'Select Lint Rules'
         name: 'Select Lint Rules'
         min: (Point 10 10)
         bounds: (Rectangle 0 0 600 400)
       )
       component: 
      (SpecCollection
         collection: (
          (ComboListSpec
             name: 'ComboBox1'
             layout: (LayoutFrame 0 0 0 0 0 1 25 0)
             model: rulesetNameHolder
             comboList: rulesetNameList
           )
          (VariableVerticalPanelSpec
             name: 'VariableVerticalPanel1'
             layout: (LayoutFrame 0 0 60 0 0 1 -30 1)
             component: 
            (SpecCollection
               collection: (
                (SubCanvasSpec
                   name: 'RuleList'
                   hasHorizontalScrollBar: false
                   hasVerticalScrollBar: false
                   majorKey: #'Tools::HierarchicalLintRuleList'
                   subAspectHolders: 
                  (Array
                     
                    (SubChannelInfoSpec
                       subAspect: inGeneratorHolder
                       aspect: allRulesHolder
                     ) 
                    (SubChannelInfoSpec
                       subAspect: listSelection
                       aspect: listSelection
                     )
                     
                    (SubChannelInfoSpec
                       subAspect: modeHolder
                       aspect: modeHolder
                     ) 
                    (SubChannelInfoSpec
                       subAspect: outGeneratorHolder
                       aspect: selectedRulesHolder
                     )
                     
                    (SubChannelInfoSpec
                       subAspect: selectionHolder
                       aspect: selectionHolder
                     )
                   )
                   createNewApplication: true
                   createNewBuilder: true
                 )
                (SubCanvasSpec
                   name: 'RuleDesc'
                   hasHorizontalScrollBar: false
                   hasVerticalScrollBar: false
                   majorKey: #'Tools::LintRuleDetail'
                   subAspectHolders: 
                  (Array
                     
                    (SubChannelInfoSpec
                       subAspect: ruleHolder
                       aspect: listSelection
                     )
                   )
                   createNewApplication: true
                   createNewBuilder: true
                 )
                )
              
             )
             handles: (Any 0.80810810810810796 1.0)
           )
          (HorizontalPanelViewSpec
             name: 'BottonPanel'
             layout: (LayoutFrame 0 0 -30 1 0 1 0 1)
             horizontalLayout: fitSpace
             verticalLayout: center
             horizontalSpace: 3
             verticalSpace: 3
             reverseOrderIfOKAtLeft: true
             component: 
            (SpecCollection
               collection: (
                (ActionButtonSpec
                   label: 'Cancel'
                   name: 'CancelButton'
                   translateLabel: true
                   model: doCancel
                   extent: (Point 295 22)
                 )
                (ActionButtonSpec
                   label: 'OK'
                   name: 'OKButton'
                   translateLabel: true
                   model: doAccept
                   isDefault: true
                   defaultable: true
                   extent: (Point 296 22)
                 )
                )
              
             )
           )
          (LinkButtonSpec
             label: 'Configure Rule Sets...'
             name: 'Button1'
             layout: (LayoutFrame 0 0 26 0 0 1 50 0)
             translateLabel: true
             labelChannel: configureRulesetsButtonLabel
             adjust: right
             model: doConfigureRulesets
           )
          )
        
       )
     )

    "Created: / 13-10-2014 / 20:40:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog methodsFor:'accessing'!

ruleset: ruleset
    self rulesetHolder value: ruleset

    "Created: / 27-02-2013 / 23:36:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selection

    ^self selectionHolder value

    "Created: / 25-08-2010 / 14:10:03 / Jan Vrany <enter your email here>"
!

selection: anObject

    self selectionHolder value: anObject

    "Created: / 25-08-2010 / 14:09:40 / Jan Vrany <enter your email here>"
!

selectionAsRule

    self rulesetHolder value rules: self selection.
    ^self rulesetHolder value.

    "Created: / 25-08-2010 / 14:10:58 / Jan Vrany <enter your email here>"
    "Modified: / 27-02-2013 / 23:40:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog methodsFor:'actions'!

doConfigureRulesets
    "raise an error: this method should be implemented (TODO)"

    ^AbstractLauncherApplication openSettingsAndSelect: 'Tools/SmallLint'

    "Created: / 08-10-2014 / 23:10:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doEditRuleset
    self doEditRuleset: self rulesetHolder value.

    "Created: / 13-10-2014 / 21:06:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doEditRuleset: anRBCompositeLintRule
    ^ self shouldImplement

    "Created: / 13-10-2014 / 21:07:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hideResultView

    detailsShown == true ifFalse:[^self].

    variablePanel shown ifFalse:[^self].

    relativeCorners := variablePanel relativeCorners.

    variablePanel
        relativeCorners:#( 0.99 1.0 );
        resizeSubviews.
    detailsShown := false.

    "Created: / 10-02-2007 / 11:39:10 / janfrog"
    "Modified: / 24-07-2010 / 15:30:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showResultView
    detailsShown == true ifTrue:[^self].
    variablePanel
        relativeCorners:relativeCorners ? #(0.5 1.0);
        resizeSubviews.
    detailsShown := true.

    "Created: / 10-02-2007 / 11:38:26 / janfrog"
    "Modified: / 24-07-2010 / 15:30:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog methodsFor:'aspects'!

allRulesHolder

    ^[(RBCompositeLintRule allRules) rules]

    "Created: / 15-04-2010 / 20:09:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

canAcceptHolder
    <resource: #uiAspect>

    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."
    "*** (and replace this comment by something more useful ;-)"

    canAcceptHolder isNil ifTrue:[
        canAcceptHolder := false asValue.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       canAcceptHolder addDependent:self.
"/       canAcceptHolder onChangeSend:#canAcceptHolderChanged to:self.
    ].
    ^ canAcceptHolder.

    "Modified: / 13-10-2014 / 21:05:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

configureRulesetsButtonLabel
    ^'Configure...' asText
        colorizeAllWith: Color blue;
        actionForAll:[ self doConfigureRulesets ];
        yourself

    "Created: / 08-10-2014 / 23:10:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-10-2014 / 20:55:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

listSelection
    "return/create the 'listSelection' value holder (automatically generated)"

    listSelection isNil ifTrue:[
        listSelection := ValueHolder new.
    ].
    ^ listSelection
!

listSelection:something
    "set the 'listSelection' value holder (automatically generated)"

    listSelection := something.
!

modeHolder

    ^[#displaySelection]

    "Created: / 15-04-2010 / 20:13:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-10-2014 / 22:56:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

rulesetHolder
    "return/create the 'rulesetHolder' value holder (automatically generated)"

    rulesetHolder isNil ifTrue:[
        rulesetHolder := ValueHolder new.
        rulesetHolder addDependent:self.
    ].
    ^ rulesetHolder
!

rulesetHolder:something
    "set the 'rulesetHolder' value holder (automatically generated)"

    |oldValue newValue|

    rulesetHolder notNil ifTrue:[
        oldValue := rulesetHolder value.
        rulesetHolder removeDependent:self.
    ].
    rulesetHolder := something.
    rulesetHolder notNil ifTrue:[
        rulesetHolder addDependent:self.
    ].
    newValue := rulesetHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:rulesetHolder.
    ].
!

rulesetList
    "return/create the 'rulesetList' value holder (automatically generated)"

    rulesetList isNil ifTrue:[
        rulesetList := List new.
        rulesetList addAll: RBCompositeLintRule rulesetsBuiltin.
        rulesetList addAll: RBCompositeLintRule rulesetsUserDefined.
        rulesetList addDependent:self.
    ].
    ^ rulesetList

    "Modified: / 16-10-2014 / 10:51:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

rulesetList:something
    "set the 'rulesetList' value holder (automatically generated)"

    |oldValue newValue|

    rulesetList notNil ifTrue:[
        oldValue := rulesetList value.
        rulesetList removeDependent:self.
    ].
    rulesetList := something.
    rulesetList notNil ifTrue:[
        rulesetList addDependent:self.
    ].
    newValue := rulesetList value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:rulesetList.
    ].
!

rulesetNameHolder
    "return/create the 'rulesetNameHolder' value holder (automatically generated)"

    rulesetNameHolder isNil ifTrue:[
        | ruleset |

        ruleset := self rulesetHolder value.
        rulesetNameHolder := ValueHolder with: (ruleset notNil ifTrue:[ ruleset displayString ] ifFalse:[ nil ]).
        rulesetNameHolder addDependent:self.
    ].
    ^ rulesetNameHolder

    "Modified: / 13-10-2014 / 20:49:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

rulesetNameHolder:something
    "set the 'rulesetNameHolder' value holder (automatically generated)"

    |oldValue newValue|

    rulesetNameHolder notNil ifTrue:[
        oldValue := rulesetNameHolder value.
        rulesetNameHolder removeDependent:self.
    ].
    rulesetNameHolder := something.
    rulesetNameHolder notNil ifTrue:[
        rulesetNameHolder addDependent:self.
    ].
    newValue := rulesetNameHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:rulesetNameHolder.
    ].
!

rulesetNameList
    "return/create the 'rulesetNameList' value holder (automatically generated)"

    rulesetNameList isNil ifTrue:[
        rulesetNameList := ValueHolder new.
    ].
    ^ rulesetNameList
!

rulesetNameList:something
    "set the 'rulesetNameList' value holder (automatically generated)"

    rulesetNameList := something.
!

selectionHolder
    "return/create the 'selectionHolder' value holder (automatically generated)"

    selectionHolder isNil ifTrue:[
        selectionHolder := ValueHolder new.
    ].
    ^ selectionHolder
! !

!LintRuleSelectionDialog methodsFor:'callbacks - post build'!

postBuildVariablePanel: aPanel

    variablePanel := aPanel.

    "Created: / 24-07-2010 / 15:05:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "Invoked when an object that I depend upon sends a change notification."

    "stub code automatically generated - please change as required"

    changedObject == rulesetList ifTrue:[
        self updateRulesetNameList.
         ^ self.
    ].
    changedObject == rulesetHolder ifTrue:[
        | ruleset |

        ruleset := self rulesetHolder value.
        ruleset notNil ifTrue:[
            self rulesetNameHolder value: ruleset value name withoutNotifying: self.
            self selection: ruleset value flattened.
            self canAcceptHolder value: true.
        ] ifFalse:[ 
            self rulesetNameHolder value: nil withoutNotifying: self.
            self selection: nil.
            self canAcceptHolder value: false.
        ].
         ^ self.
    ].
    changedObject == rulesetNameHolder ifTrue:[
        self updateRulesetHolder.
         ^ self.
    ].
    super update:something with:aParameter from:changedObject

    "Modified: / 13-10-2014 / 21:05:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateRulesetHolder
    | ruleset |    

    self rulesetHolder value name == self rulesetNameHolder value ifTrue:[
        ^self.
    ].

    (self rulesetNameList value notNil and:[self rulesetNameHolder value asString = self rulesetNameList value last asString]) ifTrue:[
        ruleset := RBCompositeLintRule new.
        ruleset name: ('New Rule Set ' , (self rulesetList size + 1) printString).
        self rulesetList add: ruleset.
        RBCompositeLintRule rulesetsUserDefined add: ruleset.
        self rulesetNameHolder value: ruleset name.
    ] ifFalse:[
        | idx |
        idx := self rulesetNameList value indexOf: self rulesetNameHolder value.
        ruleset := self rulesetList at: idx.
    ].
    self rulesetHolder value: ruleset.

    "Created: / 27-02-2013 / 23:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateRulesetNameList

    self rulesetNameList value: 
        ((self rulesetList collect:[:e|e displayString])
"/            add: 'New Ruleset...' asText allItalic;
            yourself)

    "Created: / 27-02-2013 / 23:08:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-10-2014 / 20:46:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog methodsFor:'hooks'!

commonPostBuild
    self updateRulesetNameList.
    self canAcceptHolder value: self rulesetHolder value notNil

    "Created: / 27-02-2013 / 23:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-10-2014 / 21:05:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!LintRuleSelectionDialog class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintRuleSelectionDialog.st,v 1.11 2014-11-21 14:02:14 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/Tools__LintRuleSelectionDialog.st,v 1.11 2014-11-21 14:02:14 cg Exp $'
!

version_SVN
    ^ '$Id: Tools__LintRuleSelectionDialog.st,v 1.11 2014-11-21 14:02:14 cg Exp $'
! !