;+
; PROJECT
;          SOLARB EIS
;
; NAME
;          EIS_RP_OBJ__DEFINE
;
; PURPOSE
;          This object simply invokes a list widget, listing progress of
;          the RP setup.
;
; NOTES
;          The
;
; CATEGORY
;          EIS timeline planning
;          Remote Planning
;
; WRITTEN
;          John A Rainne RAL 26-Aug-2008
;
; VERSION
;          v0.1 JAR 7-Aug-2007
;          v0.2 JAR 6-May-2009
;               Now log_file name is MS Windoze-proof.
;
;
;______________________________________________________________________________
FUNCTION eis_rp_obj::Init

;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = 'EIS Make Plan Log' + pt_version
TLB_EVENT                   = {eis_rp_obj_Event}
TLB_EVENT.eis_rp_obj = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE(                                  $
                                    TITLE       = widTitle,                 $
                                    COLUMN      = 1,                        $
                                    UValue      = TLB_EVENT)

;-------------------create the GUI------------------------------;
; Get eis_fonts
fonts = eis_fonts()

; ______________________________________________________________________
;
; RP Log List Base
;
; ______________________________________________________________________
TEXT_EVENT                 = {eis_rp_obj_Event}
TEXT_EVENT.eis_rp_obj      = Self
TEXT_EVENT.Type            = "TEXT"
value    = STRARR(4)
value[0] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
value[1] = "EIS_MK_PLAN REMOTE PLANNING startup log"
value[2] = "Created on " + SYSTIME()
value[3] = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
Self.textID                = WIDGET_TEXT(Self.tlbID                  ,      $
                                   ySize       = 30 ,                      $
                                   xSize       = 60 ,                     $
                                   uValue      = TEXT_EVENT,               $
                                   value       = value              ,     $
                                   font        = fonts.mono          ,     $
                                   /SCROLL)

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_rp_obj_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_rp_obj_Event
OBJ_DESTROY    , eis_rp_obj_Event.eis_rp_obj

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_rp_obj::CleanUp

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_rp_obj::setProperty, textID = textID

IF (N_ELEMENTS(textID) GT 0) THEN BEGIN
    stop
ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_rp_obj::GetProperty, tlbID   = tlbID , textID = textID

tlbID  = Self.tlbID
textID = Self.textID

END
;______________________________________________________________________________
; Return widget id
;______________________________________________________________________________
FUNCTION eis_rp_obj::tlbID

RETURN , Self.tlbID

END
;______________________________________________________________________________
; Widget_Control wrapper
;______________________________________________________________________________
PRO eis_rp_obj::Control, _Ref_Extra=Widget_Control_Keywords

Widget_Control, Self.tlbID, _Extra=Widget_Control_Keywords

End

;______________________________________________________________________________
; Widget_Info wrapper
;______________________________________________________________________________
Function eis_rp_obj::Info, _Ref_Extra=Widget_Info_Keywords

Return, Widget_Info(Self.tlbID, _Extra=Widget_Info_Keywords)

End

;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_rp_obj::Realize

Widget_Control, Self.tlbID, /Realize

End

;______________________________________________________________________________
; XManager wrapper
;______________________________________________________________________________
PRO eis_rp_obj::XManager

XMANAGER , "eis_rp_obj" ,   Self.tlbID ,                                 $
    Event_Handler  = "eis_rp_obj_EV",                                    $
    cleanup        = "eis_rp_obj_Cleanup",                               $
    GROUP_LEADER   = Self.group_leader ,                                   $
    /NO_BLOCK

END

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_rp_obj_Event__Define

    struct = {  eis_rp_obj_Event,                                         $
                Type                 : "",         $ ;Unique identifier for event
                eis_rp_obj   : OBJ_NEW(),  $ ;Reference to object passed
                extra                : 0           $ ;to - often object associated
             }
END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_rp_obj_EV , Event

;Get event handler structure containing eis_rp_obj type object
Widget_CONTROL,Event.ID,get_uvalue = eis_rp_obj_Event
;If a WIDGET_TAB event , just quit
IF (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_TAB') THEN BEGIN
    ;print,'tab event'
    RETURN
ENDIF

;Call eis_rp_obj's class member procedure "Handler"
eis_rp_obj_Event.eis_rp_obj->Handler,Event

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_rp_obj_Ev above.
;
; Event Handler - handle events.  Derived classes must
; contain their own implementation in order to handle events or else pass in an
; procedure name/function name using the Event_Pro/Event_Func keywords to
; CWidget::Init()
;______________________________________________________________________________
PRO eis_rp_obj::Handler, Event

WIDGET_CONTROL, Event.ID, Get_UValue = eis_rp_obj_Event
CASE eis_rp_obj_Event.Type OF
    "TEXT"      :
    ELSE        : print,eis_rp_obj_Event.Type
ENDCASE

END
;______________________________________________________________________________
; Writes log output to a file
;______________________________________________________________________________
PRO eis_rp_obj::write_file , valid

plus_line = "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
IF (valid NE 1) THEN BEGIN
   WIDGET_CONTROL , Self.textID, set_value = plus_line , /APPEND
   value = STRING(format="(A-50)","Remote Planning not setup correctly.")
   WIDGET_CONTROL , Self.textID, set_value = value , /APPEND
   value = STRING(format="(A-50)","Aborting!'")
   WIDGET_CONTROL , Self.textID, set_value = value , /APPEND
   value = "See log file: " + EXPAND_PATH("$HOME/eis_mk_plan_rp.log")
   WIDGET_CONTROL , Self.textID, set_value = value , /APPEND
   WIDGET_CONTROL , Self.textID, set_value = plus_line , /APPEND
ENDIF ELSE BEGIN
   WIDGET_CONTROL , Self.textID, set_value = plus_line , /APPEND
   value = STRING(format="(A-50)","Remote Planning is setup correctly.")
   WIDGET_CONTROL , Self.textID, set_value = value , /APPEND
   value = STRING(format="(A-50)","Starting the Planning Tools...'")
   WIDGET_CONTROL , Self.textID, set_value = value , /APPEND
   WIDGET_CONTROL , Self.textID, set_value = plus_line , /APPEND
ENDELSE

; JAR 6-May-2009 - create log file name
log_file = CONCAT_DIR(GETENV('HOME') , 'eis_mk_plan_rp.log')

WIDGET_CONTROL , Self.textID , get_value = log_contents
;OPENW   , lun , "$HOME/eis_mk_plan_rp.log" , /GET_LUN , width = 70
OPENW    , lun , log_file , /GET_LUN , width = 70
PRINTF   , lun , log_contents
FREE_LUN , lun

IF (valid NE 1) THEN print,TRANSPOSE(log_contents)

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_rp_obj__define

    struct          =   { eis_rp_obj                                  ,     $
                                    tlbID           : 0L              ,     $
                                    group_leader    : 0L              ,     $
                                    textID          : 0L                    $
                      }

END
