Tools__InlineMessageDialog.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 10 Feb 2012 11:02:29 +0000
branchjv
changeset 12151 ac18977416c2
parent 12128 a7ff7d66ee85
child 12153 9ee558dfe859
permissions -rw-r--r--
Added (experimental) support for inline message panel

"
 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 }"

ApplicationModel subclass:#InlineMessageDialog
	instanceVariableNames:'messageHolder progressHolder progressView specHolder worker
		layout'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Tools'
!

!InlineMessageDialog 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.
"
! !

!InlineMessageDialog class methodsFor:'interface specs'!

messageInfoSpec
    "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::NewSystemBrowser andSelector:#messageInfoSpec
     Tools::NewSystemBrowser new openInterface:#messageInfoSpec
    "

    <resource: #canvas>

    ^ 
     #(FullSpec
        name: messageInfoSpec
        window: 
       (WindowSpec
          label: 'MessageInfo'
          name: 'MessageInfo'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 800 40)
          backgroundColor: (Color 100.0 78.0392156862745 22.7450980392157)
          forceRecursiveBackgroundOfDefaultBackground: true
        )
        component: 
       (SpecCollection
          collection: (
           (LabelSpec
              label: 'Label'
              name: 'Message'
              layout: (LayoutFrame 10 0 -10 0.5 -90 1 10 0.5)
              backgroundColor: (Color 100.0 78.0392156862745 22.7450980392157)
              translateLabel: true
              labelChannel: messageHolder
              adjust: left
            )
           (ActionButtonSpec
              label: 'OK'
              name: 'OK'
              layout: (LayoutFrame -80 1 -12 0.5 -12 1 12 0.5)
              translateLabel: true
              model: doOK
            )
           )
         
        )
      )

    "Modified: / 28-10-2010 / 18:30:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

progressInfoSpec
    "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::InlineMessageDialog andSelector:#progressInfoSpec
     Tools::InlineMessageDialog new openInterface:#progressInfoSpec
    "

    <resource: #canvas>

    ^ 
     #(FullSpec
        name: progressInfoSpec
        window: 
       (WindowSpec
          label: 'ProgressInfo'
          name: 'ProgressInfo'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 800 40)
          backgroundColor: (Color 100.0 78.0392156862745 22.7450980392157)
          forceRecursiveBackgroundOfDefaultBackground: true
        )
        component: 
       (SpecCollection
          collection: (
           (LabelSpec
              label: 'Label'
              name: 'Message'
              layout: (LayoutFrame 10 0 0 0 -90 1 20 0)
              backgroundColor: (Color 100.0 78.0392156862745 22.7450980392157)
              translateLabel: true
              labelChannel: messageHolder
              adjust: left
            )
           (ProgressIndicatorSpec
              name: 'ProgressIndicator'
              layout: (LayoutFrame 10 0 -20 1 -133 1 -3 1)
              model: progressHolder
              foregroundColor: (Color 52.156862745098 37.2549019607843 0.0)
              backgroundColor: (Color 100.0 91.3725490196078 70.1960784313726)
              postBuildCallback: postBuildProgressView:
            )
           (ActionButtonSpec
              label: 'Abort'
              name: 'Abort'
              layout: (AlignmentOrigin -12 1 0 0.5 1 0.5)
              translateLabel: true
              resizeForLabel: true
              model: doAbort
            )
           )
         
        )
      )
!

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::InlineMessageDialog andSelector:#windowSpec
     Tools::InlineMessageDialog new openInterface:#windowSpec
     Tools::InlineMessageDialog open
    "

    <resource: #canvas>

    ^ 
     #(FullSpec
        name: windowSpec
        window: 
       (WindowSpec
          label: 'Tools::InlineMessageDialog'
          name: 'Tools::InlineMessageDialog'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 800 40)
          backgroundColor: (Color 100.0 78.0392156862745 22.7450980392157)
          forceRecursiveBackgroundOfDefaultBackground: true
        )
        component: 
       (SpecCollection
          collection: (
           (SubCanvasSpec
              name: 'InfoSpec'
              layout: (LayoutFrame 0 0 0 0 0 1 0 1)
              hasHorizontalScrollBar: false
              hasVerticalScrollBar: false
              miniScrollerHorizontal: false
              specHolder: specHolder
              createNewBuilder: false
            )
           )
         
        )
      )
! !

!InlineMessageDialog methodsFor:'accessing'!

message: aString

    self messageHolder value: aString

    "Created: / 28-10-2010 / 18:23:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

progress: aNumberOrNil

    self progressHolder value: aNumberOrNil

    "Created: / 28-10-2010 / 18:24:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog methodsFor:'actions'!

doAbort

    worker isNil ifTrue:[ self hide. ^ self ].
    worker interruptWith:[
        NoHandlerError handle:[:ex |
            ex parameter signal == AbortOperationRequest ifTrue:[
                ex return.
            ].
            ex reject.
        ] do:[
            AbortOperationRequest raise.
        ].
    ].
    (worker notNil and:[worker isDead]) ifTrue:[
        worker := nil.
        worker terminate.
        "/ raise its prio to make it terminate quickly
        worker priority:(Processor userSchedulingPriority + 1)
    ].

    "Modified: / 10-02-2012 / 10:49:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doOK
    <resource: #uiCallback>

    self hide.

    "Modified: / 28-10-2010 / 18:21:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog methodsFor:'aspects'!

messageHolder
    <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 ;-)"

    messageHolder isNil ifTrue:[
        messageHolder := ValueHolder new.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       messageHolder addDependent:self.
"/       messageHolder onChangeSend:#messageHolderChanged to:self.
    ].
    ^ messageHolder.
!

progressHolder
    <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 ;-)"

    progressHolder isNil ifTrue:[
        progressHolder := ValueHolder new.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       progressHolder addDependent:self.
"/       progressHolder onChangeSend:#progressHolderChanged to:self.
    ].
    ^ progressHolder.
!

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

    specHolder isNil ifTrue:[
        specHolder := ValueHolder with: #messageInfoSpec.
    ].
    ^ specHolder

    "Modified: / 28-10-2010 / 18:29:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog methodsFor:'informing'!

progress: label while: block

    worker := [
        self message: label.
        self progress: nil.
        self show: #progressInfoSpec.
        [
            block value.    
        ] on: ProgressNotification do:[:ex|
            self progress: ex progressValue
        ].
    ] newProcess.
    worker addExitAction:[
        self hide.
        worker := nil.
    ].
    worker resume.

    "Created: / 10-02-2012 / 10:34:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog methodsFor:'initializing'!

postBuildProgressView: aView

    aView showBusyIndication:
        (BlockValue
            with: [:p|p value isNil]
            argument: self progressHolder)

    "Created: / 10-02-2012 / 10:42:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog methodsFor:'private'!

getMyView

    | v |

    v := builder window.
    ^(v superView isKindOf: SubCanvas)
        ifTrue:[v superView]
        ifFalse:[v]

    "Created: / 29-10-2010 / 11:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

getOtherView

    | myView |

    myView := self getMyView.
    ^myView superView subViews after: myView

    "Created: / 29-10-2010 / 11:49:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hide

    | myView otherView |
    myView := self  getMyView.
    otherView := self getOtherView.

    myView isVisible ifFalse:[^self]."/already hidden"
    myView isVisible: false.
    otherView  layout: layout

    "Created: / 29-10-2010 / 11:55:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

show: spec

    | myView otherView |
    myView := self getMyView.
    otherView := self getOtherView.
    myView isVisible ifTrue:[^self]."/already shown"
    layout := otherView layout copy.
    myView isVisible: true.
    otherView  layout: 
        (layout copy topOffset: layout topOffset + 40; yourself).
    self specHolder value: spec.

    "Created: / 29-10-2010 / 11:48:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!InlineMessageDialog class methodsFor:'documentation'!

version_CVS
    ^ '§Header: /cvs/stx/stx/libtool/Tools__InlineMessageDialog.st,v 1.3 2011/08/04 21:30:34 cg Exp §'
!

version_SVN
    ^ '$Id: Tools__InlineMessageDialog.st 7879 2012-02-10 11:02:29Z vranyj1 $'
! !