function status = eval(h)

%% Apply button callback

%% At least two time series must be selected
I = [];
status = false;
for row=1:h.Handles.tsTable.getRowCount
    if h.Handles.tsTable.getValueAt(row-1,1)
        I = [I;row];
    end
end
if length(I)<2
    errordlg('There must be at least two selected time series in the table for any action to occur',...
        'Time Series Tools','modal')
    return
end

%% The reference row must be selected
if ~ismember(h.Handles.tsTable.refRow+1,I)
   errordlg('The reference time series must be selected',...
       'Time Series Tools','modal')
   return
end

%% Get recorder/transaction handle
recorder = tsguis.recorder;
T = tsguis.transaction;

%% Finish editing
celleditor = h.Handles.tsTable.getCellEditor;
if ~isempty(celleditor)
    awtinvoke(celleditor,'stopCellEditing()');
    drawnow expose
end
tsList = h.ViewNode.Plot.getTimeSeries;
tsList = tsList(I);

%% TO DO: Deal with abs time
for k=1:length(I)
    row = I(k);
    if strcmp(h.ViewNode.Plot.Absolutetime,'on')
        try
            thisshift = datenum(char(h.Handles.tsTable.getValueAt(row-1,4)));
        catch
            errordlg('A valid date string must be used to specify the reference time for absolute time vectors',...
                'Time Series Tool','modal')
            return
        end
    else
         thisshift = eval(char(h.Handles.tsTable.getValueAt(row-1,4)),'[]');
    end
    if ~isempty(thisshift)
        tsshift(row) = thisshift;
    else
        errordlg('Time Series Tools',['Invalid shift for ' tsList{row}.Name])
        return
    end    
    % Save the shift applied to the anchor time series so that it can be
    % addedback
    if row==h.Handles.tsTable.refRow+1
        anchorshiftback = tsshift(row);
    end
end

%% Shift the time series
for k=1:length(tsList)     
    % Convert the time shift from the plot units to the local time series
    % units
    if strcmp(h.ViewNode.Plot.Absolutetime,'on')
        localshift = (tsshift(k)-anchorshiftback)*...
            tsunitconv(tsList{row}.TimeInfo.Units,'days');
    else
        localshift = (tsshift(k)-anchorshiftback)*...
            tsunitconv(tsList{k}.TimeInfo.Units,h.ViewNode.Plot.TimeUnits);
    end
    for j=1:length(tsList{k}.Events)
        tsList{k}.Events(j).Time = tsList{k}.Events(j).Time-localshift;
    end
    tsList{k}.Time = tsList{k}.Time-localshift;
    if strcmp(recorder.Recording,'on') && abs(tsshift(k))>eps
        T.addbuffer('%% Time shift'); 
        T.addbuffer(sprintf('%s.Time = %s.Time - %f;',...
            tsList{k}.Name,tsList{k}.Name,localshift),tsList{k});
    end

end

%% Report success
status = true;

%% Store transaction
T.commit;
recorder.pushundo(T);
    