;+
; NAME
;          EIS_SCI_OBJ_GUI
;
; PURPOSE
;          This object
;
; INPUTS
;          parentClass    -
;          sci_obj_string -
;
; HISTORY
;          v0.1 JAR 4-Dec-2007
;              After sci_obj list was cut down to 24 entries, I've
;              increased the ySize of the list widget to that value
;          v0.2 JAR 7-Dec-2007
;              Re-jigged entire GUI. Now have 5 droplists. Much simpler
;              tool - all thanks to shortened SCI_OBJ list
;
;-
;______________________________________________________________________________
FUNCTION eis_sci_obj_gui::Init , parentClass, sci_obj_string = sci_obj_string

Self.parentClass       = parentClass
Self.group_leader      = parentClass->tlbID()
Self.sci_obj_string    = STRARR(5)
IF (N_ELEMENTS(sci_obj_string) EQ 1) THEN BEGIN

   sci_obj_split = STRSPLIT(sci_obj_string , ',' , /EXTRACT)
   FOR i = 0, N_ELEMENTS(sci_obj_split) -1 DO BEGIN
       Self.sci_obj_string[i] = STRTRIM(sci_obj_split[i],2)
   ENDFOR

ENDIF ELSE BEGIN

   Self.sci_obj_string[0] = 'QS'

ENDELSE

;-------------------create the main base---------------------------------------;
pt_version = eis_get_pt_version_number()
widTitle = 'EIS SCI_OBJ' + pt_version
TLB_EVENT                   = {eis_sci_obj_gui_Event}
TLB_EVENT.eis_sci_obj_gui     = Self
TLB_EVENT.Type              = "TLB"
Self.tlbID                  = WIDGET_BASE(                                  $
                                    TITLE       = widTitle,                 $
                                    COLUMN      = 1,                        $
                                    /FLOATING      ,                        $
                                    ;/MODAL         ,                        $
                                    GROUP_LEADER = Self.group_leader ,      $
                                    UValue      = TLB_EVENT)

; Create the GUI
Self->createGUI

RETURN, 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui::createGUI

Event_Pro   = 'eis_sci_obj_gui_EV'

; ______________________________________________________________________
;
; Top Base
;
; ______________________________________________________________________
topBase                     = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1 , /FRAME)

; ______________________________________________________________________
;
; All List Base
;
; ______________________________________________________________________
all_listBase                = WIDGET_BASE(topBase    ,                      $
                                    COLUMN      = 1)

all_list   = eis_read_study_lists(/SCI_OBJ)
main_list  = all_list[1:5]
short_list = all_list[6:*]

;
; 5 Droplists
;
FOR i = 0, 4 DO BEGIN

    CASE i OF
       0    : list = main_list
       ELSE : list = short_list
    ENDCASE

    DROP_EVENT             = {eis_sci_obj_gui_Event}
    DROP_EVENT.eis_sci_obj_gui = Self
    DROP_EVENT.Type        = "DROPLIST"
    Self.dropID[i]         = WIDGET_DROPLIST(all_listBase   ,              $
                                   value       = list       ,              $
                                   Event_Pro   = Event_Pro  ,              $
                                   ;title       = ' 5: '    ,              $
                                   uValue      = DROP_EVENT)


    sci_obj = Self.sci_obj_string[i]      ; eg: 'AR'
    IF (STRLEN(sci_obj) NE 0) THEN BEGIN
       sci_obj_search = STREGEX(list , '^' + sci_obj , /BOOLEAN)
       sci_obj_match  = WHERE(sci_obj_search EQ 1 , count)
    IF (count GT 0) THEN BEGIN
        WIDGET_CONTROL , Self.dropID[i] , set_droplist_select = sci_obj_match
    ENDIF
ENDIF
ENDFOR

; ______________________________________________________________________
;
; Bottom Base
;
; ______________________________________________________________________
bottomBase                  = WIDGET_BASE(Self.tlbID ,                      $
                                    ROW         = 1)

ACCEPT_EVENT                = {eis_sci_obj_gui_Event}
ACCEPT_EVENT.eis_sci_obj_gui = Self
ACCEPT_EVENT.Type           = "ACCEPT"
ACCEPTbutton                = WIDGET_BUTTON(Self.tlbID,                     $
                                    value       = 'Accept',                 $
                                    Event_Pro   = Event_Pro ,               $
                                    uValue      = ACCEPT_EVENT)


END

;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui_Cleanup , wid

WIDGET_CONTROL , wid , get_uvalue = eis_sci_obj_gui_Event
OBJ_DESTROY    , eis_sci_obj_gui_Event.eis_sci_obj_gui

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_sci_obj_gui::CleanUp


END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui::setProperty, autoScaleStr  = autoScaleStr

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

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui::GetProperty, tlbID   = tlbID

tlbID = Self.tlbID

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

RETURN , Self.tlbID

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

WIDGET_CONTROL , Self.tlbID , _Extra = Widget_Control_Keywords

END
;______________________________________________________________________________
; Widget_Info wrapper
;______________________________________________________________________________
FUNCTION eis_sci_obj_gui::Info, _Ref_Extra=Widget_Info_Keywords

RETURN, WIDGET_INFO(Self.tlbID , _Extra = Widget_Info_Keywords)

END
;______________________________________________________________________________
; Realize wrapper
;______________________________________________________________________________
PRO eis_sci_obj_gui::Realize

WIDGET_CONTROL , Self.tlbID, /Realize

END
;______________________________________________________________________________
; XManager wrapper
;______________________________________________________________________________
PRO eis_sci_obj_gui::XManager

XMANAGER , "eis_sci_obj_gui" ,   Self.tlbID ,                                 $
    Event_Handler  = "eis_sci_obj_gui_EV",                                    $
    cleanup        = "eis_sci_obj_gui_Cleanup",                               $
    GROUP_LEADER   = Self.group_leader ,                                   $
    /NO_BLOCK

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui_Event__Define

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

;Get event handler structure containing eis_sci_obj_gui type object
Widget_CONTROL,Event.ID,get_uvalue = eis_sci_obj_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_sci_obj_gui's class member procedure "Handler"
eis_sci_obj_gui_Event.eis_sci_obj_gui->Handler,Event

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

WIDGET_CONTROL, Event.ID, Get_UValue = eis_sci_obj_gui_Event
CASE eis_sci_obj_gui_Event.Type OF
    "ACCEPT"    : Self->accept
    "DROPLIST"  :
    ELSE        : print,eis_sci_obj_gui_Event.Type
ENDCASE

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_sci_obj_gui::accept

; Get droplist index
FOR i = 0, 4 DO BEGIN

    index = WIDGET_INFO(Self.dropID[i] , /DROPLIST_SELECT)
    WIDGET_CONTROL , Self.dropID[i] , get_value = list

    sci_obj_acronym = STRTRIM(STRMID(list[index],0,4) ,2)
    IF (i EQ 0) THEN BEGIN
       sci_obj_string = sci_obj_acronym
    ENDIF ELSE BEGIN
       IF (sci_obj_acronym NE 'NONE') THEN sci_obj_string =                $
                      STRJOIN([sci_obj_string,sci_obj_acronym],',',/SINGLE)
    ENDELSE

ENDFOR

Self.parentClass->setProperty , sci_obj = sci_obj_string

; And finally kill the widget
Self->Control , /DESTROY

END
;______________________________________________________________________________
; Define Data members
;______________________________________________________________________________
PRO eis_sci_obj_gui__define

    struct          =	{ eis_sci_obj_gui                      ,           $
                           tlbID             : 0L              ,           $
                           group_leader      : 0L              ,           $
                           parentClass       : OBJ_NEW()       ,           $
                           sci_obj_string    : STRARR(5)       ,           $
                           dropID            : LONARR(5)                   $
                        }

END
