function synctable(this)

import com.mathworks.toolbox.timeseries.*; 

%% Method to update the uitable so that it refelcts the @Timeseries object

%% Get data and time - return if they are out of sync since the time series
%% is being re-gridded
data = this.TimeSeries.Data;
time = this.TimeSeries.Time;
if length(time)~= size(data,1)
    return
end

%% Build the table to represent time series data
s = size(this.TimeSeries.Data);
heading{1} = 'Time';
for k=1:s(2)
    heading{k+1} = sprintf('Column:%d',k);
end

%% If there are no events create the table data from the @timeseries Data
%% and Time vectors
this.Tstable.EventRow = false([s(1) 1]); % Default no event rows
%% If absolute date format is used, show the string
if ~isempty(this.TimeSeries.TimeInfo.Startdate) || tsIsDateFormat(this.TimeSeries.TimeInfo.Format)
    tableData = [this.TimeSeries.getTimeStr num2cell(data)];
else
    tableData = num2cell([time,data]);;
end
if isempty(this.TimeSeries.Events)
    I = 1:s(1);
%% Otherwize the event rows must be integrated and sorted
else
    for k=1:length(this.TimeSeries.Events)
        this.Tstable.EventRow = [this.Tstable.EventRow; true];
        if isempty(this.TimeSeries.TimeInfo.StartDate) % abs time
            tableData = [tableData; 
                        {this.TimeSeries.Events(k).Time, ...
                        this.TimeSeries.Events(k).Name}, repmat({'  '},[1 s(2)-1])];
        else % rel time
            tableData = [tableData; 
               {this.TimeSeries.Events(k).getTimeStr{1}, ...
                this.TimeSeries.Events(k).Name}, repmat({'  '},[1 s(2)-1])];
        end
        time = [time; this.TimeSeries.Events(k).Time];
    end
    [junk, I] = sort(time);
    tableData = tableData(I,:);
    this.Tstable.EventRow = this.Tstable.EventRow(I);
end    

%% If Data quality is defined it must be added as the last column
if ~isempty(this.Timeseries.Quality)
    heading = {heading{:} 'Status'};
    qualTable = this.Timeseries.qualityInfo.Description;
    qualCodes = this.Timeseries.qualityInfo.Code;
    qualColumn = repmat({''},[length(I) 1]);
    for k=1:s(1)
        qualColumn{k} = qualTable{this.Timeseries.Quality(k)==qualCodes};
    end
    tableData = [tableData qualColumn(I)];
    if ~isequal(cell(this.Tstable.Table.ColumnNames),heading(:))
         this.Tstable.Table.ColumnNames = heading;
    end
    this.Tstable.Table.setComboBoxEditor({this.Timeseries.qualityInfo.Description},s(2)+2);
else
    if ~isequal(cell(this.Tstable.Table.ColumnNames),heading(:))
         this.Tstable.Table.ColumnNames = heading;
    end
end

%% Update the uitable. If there are events we must disable the table model
%% lock which prevents paste from overwriting events
if ~isempty(this.TimeSeries.Events)
    this.Tstable.Table.getTable.getModel.seteventrowlock(false);
end
this.Tstable.Table.setData(tableData);
if ~isempty(this.TimeSeries.Events)
    awtinvoke(this.Tstable.Table.getTable.getModel,'seteventrowlock(Z)',true);
end
Ievents = find(this.Tstable.EventRow);
customTableModel = this.Tstable.Table.getTable.getModel;
customTableModel.fnoneditrows = Ievents-1;


%% Set the column widths
if ~isempty(this.TimeSeries.TimeInfo.StartDate)
    this.Tstable.Table.setColumnWidth(0,160)
else
   this.Tstable.Table.setColumnWidth(0,70) 
end

