function refresh(h)

%% Updates the components on the dialog to reflect the selected time series
%% Specifically, enables and disables redio buttons and displays the
%% "common" time vector

import javax.swing.*; 

%% List of enable-able components 
components = {h.Handles.BTNok,h.Handles.BTNcancel,h.Handles.RADIOinplace,...
               h.Handles.RADIOnewmerged,h.Handles.RADIOunion, ...
               h.Handles.RADIOintersect,h.Handles.RADIOuniform,...
               h.Handles.RADIOtimeseries,h.Handles.EDITinterval,...
               h.Handles.COMBunits,h.Handles.COMBts};
           
%% If the timePlot has gone disable components and do nothing
if isempty(h.ViewNode.Plot) || ~ishandle(h.ViewNode.Plot)
    mask = {'off','on','off','off','off','off','off','off','off','off','off'};
else
    %% Find the selected time series
    drawnow % Ensure the table is ready
    tableData = cell(h.Handles.tsTable.Data);
    I = ~cellfun('isempty',tableData(:,2)) & cell2mat(tableData(:,1));
    tsSelected = tableData(I,2);

    %% Refresh the timeseries combo
    tsList = h.ViewNode.Plot.getTimeSeries;
    tsNames = cell(size(tsList));
    for k=1:length(tsList)
        tsNames{k} = tsList{k}.Name;
    end
    set(h.Handles.COMBts,'String',tsNames)

    %% Enable/disable components based on the number of time series selected               
    if isempty(tsSelected) % Disable all components
        mask = repmat({'off'},[1 11]);
        start = 'empty';
        finish = 'empty';
        % Select the default time vector
        set(h.Handles.RADIOtimeseries,'Value',1) 
    elseif length(tsSelected)==1
        mask = {'on','on','on','on','off','off','on','on','on','on','on'};
        % If either of the disabled radio buttons are selected then select the
        % default radio and and select this time series in the corresponding
        % time series combo
        if get(h.Handles.RADIOunion,'Value') || get(h.Handles.RADIOintersect,'Value')
            set(h.Handles.RADIOtimeseries,'Value',1)    
            set(h.Handles.COMBts,'Value',find(strcmp(tsSelected{1},tsNames)))
        end

        %% If uniform time vector is selected set the start and end time
        %% accordingly
        if get(h.Handles.RADIOuniform,'Value')
            thists = h.ViewNode.Plot.getTimeSeries(tsSelected{1});
        else % Resample using another series' time vector
            tsComboList = get(h.Handles.COMBts,'String');
            selectedTimeseriesName = tsComboList{get(h.Handles.COMBts,'Value')};
            thists = h.ViewNode.Plot.getTimeSeries(selectedTimeseriesName);
        end  
        start  = sprintf('%0.2f',thists.TimeInfo.Start);
        finish = sprintf('%0.2f',thists.TimeInfo.End);
    else
        mask = {'on','on','on','on','on','on','off','off','off','off','off'};

        %% Disabled radios must not be selected
        if get(h.Handles.RADIOtimeseries,'Value') || ...
                get(h.Handles.RADIOuniform,'Value')
            set(h.Handles.RADIOunion,'Value',true)
        end

        %% Find the start and end of the union on the overlapping interval
        if get(h.Handles.RADIOunion,'Value')
            start = inf;
            finish = -inf;
            for k=1:length(tsSelected)
                if start>h.ViewNode.Plot.getTimeSeries(tsSelected{k}).timeInfo.Start
                    start = h.ViewNode.Plot.getTimeSeries(tsSelected{k}).timeInfo.Start;
                end
                if finish<h.ViewNode.Plot.getTimeSeries(tsSelected{k}).timeInfo.End
                    finish = h.ViewNode.Plot.getTimeSeries(tsSelected{k}).timeInfo.End;
                end            
            end
            if start>finish
                start = 'empty';
                finish = 'empty';
            else 
                start = sprintf('%0.2f',start);
                finish = sprintf('%0.2f',finish);
            end
        %% Find the intersection time vector
        elseif get(h.Handles.RADIOintersect,'Value')
            time = h.ViewNode.Plot.getTimeSeries(tsSelected{1}).Time;
            for k=1:length(tsSelected)
                time = intersect(time,h.ViewNode.Plot.getTimeSeries(tsSelected{k}).Time);
                if isempty(time)
                    break
                end
            end    
            if ~isempty(time)
                start = sprintf('%0.2f',min(time));
                finish = sprintf('%0.2f',max(time));
            else
                start = 'Empty';
                finish = 'Empty';
            end
        end       
    end    

    %% Update the time vector panel
    set(h.Handles.TXTstarttime,'String',sprintf('Start time: %s',start));
    set(h.Handles.TXTendtime,'String',sprintf('End time: %s',finish));
end

%% Enable/disable the components using the mask 
for k=1:length(components)
    set(components{k},'Enable',mask{k})
end
