% GETCONNECTION makes a new managed repository connection.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: GETCONNECTION makes a new managed repository connection.
%
% CALL:        conn = rm.getConnection(pl);
%              conn = rm.getConnection('hostname');
%              conn = rm.getConnection('hostname', 'database');
%              conn = rm.getConnection('hostname', 'database', 'username');
%              conn = rm.getConnection('hostname', 'database', 'username', 'password');
%
% If all required connection fields are input, the connection will be
% silently created and added to the manager. Otherwise, a connection dialog
% will be presented and the resulting connection added to the manager.
%
% <a href="matlab:web(LTPDARepositoryManager.getInfo('getConnection').tohtml, '-helpbrowser')">Parameters Description</a>
%
% VERSION:    $Id: getConnection.m,v 1.4 2011/04/08 08:56:35 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

end

%--------------------------------------------------------------------------
% 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, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.gui, '$Id: getConnection.m,v 1.4 2011/04/08 08:56:35 hewitson Exp $', sets, pl);
end

%--------------------------------------------------------------------------
% Get Default Plist
%--------------------------------------------------------------------------
function pl = getDefaultPlist()
  
  % Initialise plist
  pl = plist();
  
  % hostname
  p = param({'hostname', 'The hostname of the repository to connect to.'}, paramValue.EMPTY_STRING);
  pl.append(p);
  
  % database
  p = param({'database', 'The database on the repository.'}, paramValue.EMPTY_STRING);
  pl.append(p);
  
  % username
  p = param({'username', 'The username to connect with.'}, paramValue.EMPTY_STRING);
  pl.append(p);
  
  % password
  p = param({'password', 'The password to connect with. Leave this empty to be prompted on connection.'}, paramValue.EMPTY_STRING);
  pl.append(p);
  
end
% END
