Home > m > gui > ltpdaRepoGUI > callbacks > cb_importBtn.m

cb_importBtn

PURPOSE ^

Callback executed when the user clicks on the import button.

SYNOPSIS ^

function cb_importBtn(varargin)

DESCRIPTION ^

 Callback executed when the user clicks on the import button.
 
 M Hewitson
 
 $Id: cb_importBtn.m,v 1.2 2008/03/27 10:32:07 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cb_importBtn(varargin)
0002 
0003 % Callback executed when the user clicks on the import button.
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: cb_importBtn.m,v 1.2 2008/03/27 10:32:07 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) && ~strcmp(tt, 'No Data')
0042     if appendObj
0043       objname = [objname '_' tt];
0044     end
0045   else
0046     error('!!! Object type is unknown. Does this object really exist?');
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   if isempty(ids)
0076     error('### This collection doesn''t seem to exist.');
0077   end
0078   
0079   for j=1:length(ids)
0080     disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
0081     tt = mysql_getObjType(conn, ids(j));
0082     objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0083     if appendObj
0084       objname = [objname '_' tt];
0085     end
0086     % Retrieve object
0087     ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0088     ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0089     db = regexp(conn.URL, '/', 'split');
0090     db = db{end};
0091     % add history
0092     pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0093     obj = eval(sprintf('%s(pl);', tt));
0094 
0095     assignin('base', objname, obj);
0096     disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0097     if j==1
0098       objs = {obj};
0099     else
0100       objs = [objs {obj}];
0101     end
0102   end
0103 end
0104 
0105 disp(sprintf('** Retrieved %d objects.', length(ids)));
0106 
0107 
0108 end
0109 
0110 
0111 function [ids, cids] = getIds()
0112 
0113 ids  = [];
0114 cids = [];
0115 
0116 th = findobj('Tag', 'retrieveIDsTxt');
0117 idStr = get(th, 'String');
0118 cs = cellstr(idStr);
0119 
0120 for j=1:length(cs)
0121   disp('---------')
0122   ls = cs{j};
0123   [s,r] = strtok(ls);
0124   if ~isempty(s)
0125     if s(1) == 'c'
0126       s = s(2:end);
0127       cids = [cids round(str2num(s))];
0128     else
0129       ids = [ids round(str2num(s))];
0130     end
0131   end
0132   while ~isempty(r)
0133     [s,r] = strtok(r);
0134     if ~isempty(s)
0135       if s(1) == 'c'
0136         s = s(2:end);
0137         cids = [cids round(str2num(s))];
0138       else
0139         ids = [ids round(str2num(s))];
0140       end
0141     end
0142   end
0143 end
0144 
0145 end

Generated on Mon 31-Mar-2008 21:41:00 by m2html © 2003