;------------------------------------------------------------------------------;
;+
; PROJECT
;           SOLARB EIS
;
; NAME
;           EIS_AUTHOR_GUI__DEFINE
;
; PURPOSE
;           eis_author class definition
;
; NOTES
;           The 
;
; CATEGORY
;           EIS technical planning
;           EIS timeline planning
;
; WRITTEN
;           John A Rainne RAL
;
; VERSION
;           v0.1 JAR 7-Jan-2007
;               Removed STO P
;-
;------------------------------------------------------------------------------;
FUNCTION eis_author_gui::Init , parentClass , tlb , parameter

Self.parentClass  = parentClass
Self.group_leader = parentClass->tlbID()
Self.parameter    = parameter
;-------------------create the main base---------------------------------------;
Self.authorBaseID           = WIDGET_BASE(tlb ,               $
                                    ROW         = 1)


CASE parameter OF
    'author'   :  list = eis_read_study_lists(/AUTHOR)
    'observer' :  list = eis_read_study_lists(/OBSERVER)
    'planner'  :  list = eis_read_study_lists(/PLANNER)
    'tohban_1' :  list = eis_read_study_lists(/TOHBAN)
    'tohban_2' :  list = eis_read_study_lists(/TOHBAN)
ENDCASE


AUTHOR_EVENT = {eis_author_gui_Event ,                                      $
                    type               : "",                                $
                    eis_author_gui   : OBJ_NEW(),                           $
                    extra              : 0 }

AUTHOR_EVENT.eis_author_gui = Self
AUTHOR_EVENT.Type           = "AUTHOR"
; Read authors file
Self.authorID               = WIDGET_DROPLIST(Self.authorBaseID        ,    $
                                    value       = list                 ,    $
                                    xSize       = 160                  ,    $
                                    Event_Pro   = 'eis_author_gui_EV'  ,    $
                                    GROUP_LEADER = Self.group_leader ,      $
                                    uValue      = AUTHOR_EVENT)

DESC_EVENT = {eis_author_gui_Event ,                                      $
                    type               : "",                                $
                    eis_author_gui   : OBJ_NEW(),                           $
                    extra              : 0 }

DESC_EVENT.eis_author_gui   = Self
DESC_EVENT.Type             = "AUTHOR_TEXT"
Self.authorTextID           = WIDGET_TEXT(Self.authorBaseID        ,        $
                                    value       = 'None'   ,              $
                                    uValue      = DESC_EVENT ,              $
                                    xSize       = 30 ,                      $
                                    Event_Pro   = 'eis_author_gui_EV'  ,    $
                                    /EDITABLE   )


RETURN, 1

END
;______________________________________________________________________________
; 
;______________________________________________________________________________
PRO eis_author_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_author_gui_Event
OBJ_DESTROY    , eis_author_gui_Event.eis_author_gui

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_author_gui::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_author_gui::setProperty , author = author

IF (N_ELEMENTS(author) GT 0) THEN BEGIN

    ; Read Author List
    author_list  = eis_read_study_lists(/AUTHOR)
    author_index = WHERE(author_list EQ STRTRIM(author,2) , count)

    IF (count EQ 0) THEN BEGIN
        index = 0
        WIDGET_CONTROL , Self.authorTextID , sensitive = 1
    ENDIF ELSE BEGIN
        index = author_index[0]
        WIDGET_CONTROL , Self.authorTextID , sensitive = 0
    ENDELSE

    WIDGET_CONTROL , Self.authorID , set_droplist_select = index

ENDIF

End
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_author_gui::GetProperty, author = author

author  = Self.author
IF (Self.author[0] EQ 0) THEN Self->author_text

END
;______________________________________________________________________________
; Event Handler wrapper
;______________________________________________________________________________
PRO eis_author_gui_EV , Event

;Get event handler structure containing eis_author_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_author_gui_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_author_gui's class member procedure "Handler"
eis_author_gui_Event.eis_author_gui->Handler,Event

END
;______________________________________________________________________________
;
; * THIS is the routine for putting in event handling NOT eis_author_gui_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_author_gui::Handler, Event

WIDGET_CONTROL, Event.ID, Get_UValue = eis_author_gui_Event
CASE eis_author_gui_Event.Type OF
    "AUTHOR"      : Self->author
    "AUTHOR_TEXT" : Self->author_text
    ELSE          : print,eis_author_gui_Event.Type
ENDCASE
END
;______________________________________________________________________________
; Edit time
;______________________________________________________________________________
PRO eis_author_gui::set_selection , author

WIDGET_CONTROL , Self.authorTextID , set_value = author

END
;______________________________________________________________________________
; Edit time
;______________________________________________________________________________
PRO eis_author_gui::author_text

; Get author from widget_text
WIDGET_CONTROL , Self.authorTextID , get_value = widValue
IF (STRLEN(widValue[0]) EQ 0) THEN BEGIN

    BEEP
    mText = "Please supply an author."
    complain = DIALOG_MESSAGE( mText ,                                      $
                                 DIALOG_PARENT = Self.authorBaseID,         $
                                 /ERROR )
    RETURN

ENDIF

author_struct = {parameter:Self.parameter , author:widValue[0]}
; Set Author Property
Self.parentClass->setProperty , author_struct = author_struct

END
;______________________________________________________________________________
; Edit time
;______________________________________________________________________________
PRO eis_author_gui::author

; Get index of currently selected item ('unknown' = 0)
droplistSelect = WIDGET_INFO(Self.authorID , /DROPLIST_SELECT)
IF (droplistSelect EQ 0) THEN BEGIN

    WIDGET_CONTROL , Self.authorTextID , sensitive = 1
    
ENDIF ELSE BEGIN

    WIDGET_CONTROL , Self.authorTextID , sensitive = 0
    ; Read Author List

    CASE Self.parameter OF
        'author'   :  list = eis_read_study_lists(/AUTHOR)
        'observer' :  list = eis_read_study_lists(/OBSERVER)
        'planner'  :  list = eis_read_study_lists(/PLANNER)
        'tohban_1' :  list = eis_read_study_lists(/TOHBAN)
        'tohban_2' :  list = eis_read_study_lists(/TOHBAN)
    ENDCASE
    
    author      = list[droplistSelect]
    author_struct = {parameter:Self.parameter , author:author}
    ; Set Author Property
    Self.parentClass->setProperty , author_struct = author_struct

ENDELSE

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO	eis_author_gui__Define

    struct          =	{ eis_author_gui                                ,     $
                                    tlbID           : 0L              ,     $
                                    parentClass     : OBJ_NEW()       ,     $
                                    group_leader    : 0L              ,     $
                                    authorBaseID    : 0L              ,     $
                                    authorID        : 0L              ,     $
                                    author          : 0L              ,     $
                                    authorTextID    : 0L              ,     $
                                    parameter       : ''                    $
                      }


END
