% QUERYDIALOG a visual query builder for querying an LTPDA repository.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: QUERYDIALOG a visual query builder for querying an LTPDA
%              repository.
%
% CALL:        utils.jmysql.queryDialog();
%              utils.jmysql.queryDialog(conn);
%
% INPUTS:
%              conn - a connection object like that returned from
%                     utils.jmysql.connect.
%
%
% VERSION:     $Id: queryDialog.m,v 1.2 2009/09/22 14:40:07 ingo Exp $
%
% HISTORY:     24-05-2007 M Hewitson
%                 Creation
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



function  queryDialog(varargin)
  
  if nargin == 1 && ~isa(varargin{1}, 'mpipeline.repository.RepositoryConnection')
    error('### The first argument should be empty or a RepositoryConnection');
  end
  
  
  % Inputs
  conn = [];
  if nargin > 0
    conn  = varargin{1};
  end
  
  if isempty(conn)
    conn = utils.jmysql.connect();
  end
  
  if ~conn.isConnected
    conn.openConnection
  end
  
  if ~conn.isConnected
    error('### Failed to connect to repository.');
  end
  
  % open a query dialog
  if nargin == 0
    closeConnectionOnExit = true;
  else
    closeConnectionOnExit = false;
  end
  warning('off', 'MATLAB:JavaEDTAutoDelegation');
  qrd = mpipeline.repository.RepositoryQueryDialog([], false, conn, false, closeConnectionOnExit);
  qrd.setVisible(true)
  warning('off', 'MATLAB:JavaEDTAutoDelegation');
  
  
  
end

