function update(h,varargin)

%% Find the time series in the view and retain their selected status so
%% that it can be reproduced when the table is rebuilt

if ~isempty(h.ViewNode) && ishandle(h.ViewNode)
    timePlot = h.ViewNode.Plot;
else
    return % All views deleted
end

%% If the viewNode has just been created there will not yet be a timePlot.
%% In this case open an empty table
if ~isempty(timePlot) && ishandle(timePlot)
    tsList = timePlot.getTimeSeries;
    isSelected = true(size(tsList));
    tsNames = cell(size(tsList));
    tableData = cell(size(h.Handles.tsTable.Data));
    
    %% Preserve de-selected time series in the table    
    for k=1:length(tsList)
        tsNames{k} = tsList{k}.Name;
        if size(tableData,2)==3 && size(tableData,1)>0 && ...
                (nargin==1 || isempty(varargin{1}))
            I = find(strcmp(tsNames{k},tableData(:,2)));
            if ~isempty(I)
                isSelected(k) = tableData{I(1),1};
            end
        elseif nargin>=2 && ~isempty(varargin{1}) % Single specified timeseries selects by a @tsnode
            isSelected(k) = (varargin{1}==tsList{k});
        end
    end

    tableData = [num2cell(isSelected(:)) tsNames(:)];
    % Set the resample time vector units to match the time plot
    ind = find(strcmpi(timePlot.TimeUnits,get(h.Handles.COMBunits,'String')));
    if ~isempty(ind)
        set(h.Handles.COMBunits,'Value',ind(1));
    end
else
    tableData = cell(0,3);
end

%% Rebuild the table and refresh the dialog so that the state of the
%% components reflects the selected time series
h.Handles.tsTable.setData(tableData);

%% Make the time series column take up all the extra space
colswidth0 = h.Handles.tsTable.getColumnWidth(0);
h.Handles.tsTable.setColumnWidth(1,h.Handles.tsTable.getTableScrollPane.getWidth-...
    colswidth0-5);
h.refresh
