! $Id: toolConfigAndProgress_Run_ui.pvc.pvxsrc 42051 2022-03-30 00:12:45Z fmcguirk $

! Example Contributed Tool: Tool with configuration and progress - Run Action UI

 

 

def class "toolConfigAndProgress_Run_ui" create required delete required

    like "com.pvx.util.progress"

 

    ! ** Set the caption for the user interface window

    local theCaption$         = "Example - WCaP Progress"

    ! ** Override Description

    local theDescription$     = "Example - WCaP Run Action"

    ! ** Override NotificationFlag

    local theNotificationFlag = _pvxConstants'_ideNone

 

    ! ** [object] Reference to local instance of ecCommon

    local coCommon

    ! ** [string] prefix to use for data values in Eclipse data store

    local cPrefStorePfx$ = "toolConfigAndProgress"

 

    ! ** Method that is executed when the 'Special' button is pressed.

    function local b_special()                            b_special

 

    ! ** A private method that performs the tasks required by the contributed tool

    function local doWork()                                do_work

 

end def

 

 

On_Create:

 

    coCommon = new("ecCommon")

 

    return

 

 

On_Delete:

 

    drop object coCommon, err=*proceed; coCommon = 0

 

    return

 

 

 

b_special:

 

    msgbox "Woo Hoo!", "Woo Hoo!", "OK,Top,Beep"

 

    return

 

 

do_work:

 

    _obj'writeLog("Starting work...")

 

    ! Get field list and data to Eclipse preference store

    _obj'writeLog("... Load saved configuration data")

    coCommon'Prefs("Get", cPrefStorePfx$+"_Fields", dataVars$)

    coCommon'Prefs("Get", cPrefStorePfx$+"_Data",   dataRec$)

 

    if not(nul(dataRec$)) and not(nul(dataVars$)) {

        read data from dataRec$ to iol=cpl("iolist " + dataVars$)

    } else {

        workDesc$ = "work"

        workUnits = 4

        workDelay = 2

    }

 

    _obj'writeLog("... Work Description    : " + workDesc$)

    _obj'writeLog("... Work Units          : " + str(workUnits))

    _obj'writeLog("... Work Delay (seconds): " + str(workDelay))

 

    ! Disable Cancel of the process

    _obj'disable_cancel()

 

    if workUnits>0 {

        workUnitAmount = 100 / workUnits

        for loop = 1 to workUnits

 

            ! Update status

            _obj'writeLog("... " + workDesc$ + " .. " + str(workUnitAmount * loop))

 

            ! Allow for CANCEL of processing

            isCancelled = _obj'checkCancel()

            if isCancelled {

                break

            }

 

            ! Enable Cancel of the process

            if loop=1 {

                _obj'enable_cancel()

            } else {

                if loop=workUnits-1 {

                    _obj'disable_cancel()

                }

            }

 

            ! Pretend to do something

            wait workDelay

 

        next loop

 

        if isCancelled {

            _obj'writeLog(workDesc$ + " cancelled for today")

        } else {

            _obj'writeLog(workDesc$ + " complete for another day")

        }

    } else {

        _obj'writeLog(workDesc$ + " no work planned for the day")

    }

 

    if not(isCancelled) {

        _obj'enable_special("WooHoo!")

    }

 

    return