% DISPLAY overloads display functionality for collection objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: DISPLAY overloads display functionality for collection objects.
%
% CALL:        txt    = display(collection)
%
% INPUT:       collection - collection object
%
% OUTPUT:      txt    - cell array with strings which displays the matrix object
%
% <a href="matlab:utils.helper.displayMethodInfo('collection', 'display')">Parameters Description</a>
%
% VERSION:     $Id: display.m,v 1.10 2011/04/08 08:56:22 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = display(varargin)

  %%% Check if this is a call for parameters
  if utils.helper.isinfocall(varargin{:})
    varargout{1} = getInfo(varargin{3});
    return
  end

  colls = utils.helper.collect_objects(varargin(:), 'collection');

  txt = {};

  % Print emtpy object
  if isempty(colls)
    hdr = sprintf('------ %s -------', class(colls));
    ftr(1:length(hdr)) = '-';
    txt = [txt; {hdr}];
    txt = [txt; sprintf('empty-object [%d,%d]',size(colls))];
    txt = [txt; {ftr}];
  end
  
  for i=1:numel(colls)
    banner = sprintf('---- collection %d ----', i);
    txt{end+1} = banner;

    % get key and value
    name  = colls(i).name;

    % display
    txt{end+1} = ['       name: ' name];
    txt{end+1} = ['   num objs: ' num2str(numel(colls(i).objs)) ];
    for kk=1:numel(colls(i).objs)
      if isempty(colls(i).objs{kk})
        txt{end+1} = [sprintf('         %02d: %s | ', kk, class(colls(i).objs{kk})), 'empty-object'];
      else
        desc = utils.helper.val2str(colls(i).objs{kk});
        Dlen = 1000;
        if length(desc) > Dlen
          desc = [desc(1:Dlen) '...'];
        end
        txt{end+1} = [sprintf('         %02d: %s | ', kk, class(colls(i).objs{kk})) desc];
      end
    end

    txt{end+1} = ['description: ' colls(i).description];
    txt{end+1} = ['       UUID: ' colls(i).UUID];
    banner_end(1:length(banner)) = '-';
    txt{end+1} = banner_end;
  end

  if nargout == 0
    for ii=1:length(txt)
      disp(txt{ii});
    end
  else
    varargout{1} = txt;
  end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                               Local Functions                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    getInfo
%
% DESCRIPTION: Get Info Object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function ii = getInfo(varargin)
  if nargin == 1 && strcmpi(varargin{1}, 'None')
    sets = {};
    pl   = [];
  else
    sets = {'Default'};
    pl   = getDefaultPlist;
  end
  % Build info object
  ii = minfo(mfilename, 'collection', 'ltpda', utils.const.categories.output, '$Id: display.m,v 1.10 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
  ii.setModifier(false);
  ii.setOutmin(0);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    getDefaultPlist
%
% DESCRIPTION: Get Default Plist
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function plout = getDefaultPlist()
  persistent pl;  
  if exist('pl', 'var')==0 || isempty(pl)
    pl = buildplist();
  end
  plout = pl;  
end

function pl = buildplist()
  pl = plist.EMPTY_PLIST;
end

