Home > m > gui > ltpdaRepoGUI > callbacks > cb_retrieveBtn.m

cb_retrieveBtn

PURPOSE ^

Callback executed when the user clicks on the retrieve button.

SYNOPSIS ^

function cb_retrieveBtn(varargin)

DESCRIPTION ^

 Callback executed when the user clicks on the retrieve button.
 
 M Hewitson
 
 $Id: cb_retrieveBtn.m,v 1.6 2008/02/29 10:53:49 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cb_retrieveBtn(varargin)
0002 
0003 % Callback executed when the user clicks on the retrieve button.
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: cb_retrieveBtn.m,v 1.6 2008/02/29 10:53:49 hewitson Exp $
0008 %
0009 
0010 % Get connection
0011 mainfig  = findobj('Tag', 'LTPDARepomainfig');
0012 conn     = getappdata(mainfig, 'connection');
0013 if isempty(conn) || ~isa(conn, 'database')
0014   errordlg('Please connect to a database first', 'No connection found');
0015   return
0016 end
0017 
0018 % Get variable name specs
0019 h = findobj('Tag', 'objPrefixTxt');
0020 prefix = get(h, 'String');
0021 if isempty(prefix)
0022   prefix = 'obj';
0023   warning('! Using default prefix (obj)');
0024 end
0025 h = findobj('Tag', 'appendObjTypeChk');
0026 appendObj = get(h, 'Value');
0027 
0028 % Get IDs from text box
0029 [ids, cids] = getIds();
0030 
0031 
0032 %---------------------------------------------------------------
0033 % Retrieve these ids
0034 objs = [];
0035 for j=1:length(ids)
0036   disp(sprintf('+ retrieving object %d', ids(j)));
0037   
0038   % determine object type
0039   tt = mysql_getObjType(conn, ids(j));
0040   objname = sprintf('%s%03d', prefix, ids(j));
0041   if ~isempty(tt)
0042     if appendObj
0043       objname = [objname '_' tt];
0044     end
0045   else
0046     warning('!!! Object type is unknown');
0047   end
0048     
0049   % Retrieve object
0050   a = regexp(conn.URL, '//(\S+)/', 'tokens');
0051   db = regexp(conn.URL, '/', 'split');
0052   db = db{end};
0053   % add history
0054   pl = plist('hostname', a{1}, 'database', db, 'ID', ids(j), 'conn', conn);
0055   obj = eval(sprintf('%s(pl);', tt));
0056   
0057   assignin('base', objname, obj);
0058   disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0059   
0060   if j==1
0061     objs = {obj};
0062   else
0063     objs = [objs {obj}];
0064   end
0065 end
0066 
0067 disp(sprintf('** Retrieved %d objects.', length(ids)));
0068 
0069 %---------------------------------------------------------------
0070 % Retrieve these Collections
0071 for k=1:length(cids)
0072   
0073   % get Ids from Cid
0074   ids = mysql_getObjIds(conn, cids(k));
0075   
0076   for j=1:length(ids)
0077     disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
0078     tt = mysql_getObjType(conn, ids(j));
0079     objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0080     if appendObj
0081       objname = [objname '_' tt];
0082     end
0083     % Retrieve object
0084     ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0085     ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0086     db = regexp(conn.URL, '/', 'split');
0087     db = db{end};
0088     % add history
0089     pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0090     obj = eval(sprintf('%s(pl);', tt));
0091 
0092     assignin('base', objname, obj);
0093     disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0094     if j==1
0095       objs = {obj};
0096     else
0097       objs = [objs {obj}];
0098     end
0099   end
0100 end
0101 
0102 disp(sprintf('** Retrieved %d objects.', length(ids)));
0103 
0104 
0105 end
0106 
0107 
0108 function [ids, cids] = getIds()
0109 
0110 ids  = [];
0111 cids = [];
0112 
0113 th = findobj('Tag', 'retrieveIDsTxt');
0114 idStr = get(th, 'String');
0115 cs = cellstr(idStr);
0116 
0117 for j=1:length(cs)
0118   disp('---------')
0119   ls = cs{j};
0120   [s,r] = strtok(ls);
0121   if ~isempty(s)
0122     if s(1) == 'c'
0123       s = s(2:end);
0124       cids = [cids round(str2num(s))];
0125     else
0126       ids = [ids round(str2num(s))];
0127     end
0128   end
0129   while ~isempty(r)
0130     [s,r] = strtok(r);
0131     if ~isempty(s)
0132       if s(1) == 'c'
0133         s = s(2:end);
0134         cids = [cids round(str2num(s))];
0135       else
0136         ids = [ids round(str2num(s))];
0137       end
0138     end
0139   end
0140 end
0141 
0142 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003