Home > m > gui > ltpdaRepoGUI > callbacks > cb_saveBtn.m

cb_saveBtn

PURPOSE ^

Callback executed when the user clicks on the save button.

SYNOPSIS ^

function cb_saveBtn(varargin)

DESCRIPTION ^

 Callback executed when the user clicks on the save button.
 
 M Hewitson
 
 $Id: cb_saveBtn.m,v 1.3 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_saveBtn(varargin)
0002 
0003 % Callback executed when the user clicks on the save button.
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: cb_saveBtn.m,v 1.3 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   % add file extension
0049   objname = [objname '.xml'];
0050  
0051   % Retrieve object
0052   a = regexp(conn.URL, '//(\S+)/', 'tokens');
0053   db = regexp(conn.URL, '/', 'split');
0054   db = db{end};
0055   % add history
0056   pl = plist('hostname', a{1}, 'database', db, 'ID', ids(j), 'conn', conn);
0057   obj = eval(sprintf('%s(pl);', tt));
0058   
0059   % write to disk
0060   save(obj, objname)
0061   
0062 %   assignin('base', objname, obj);
0063   disp(sprintf('** Retrieve object %d to disk [%s]', ids(j), objname));
0064   
0065   if j==1
0066     objs = {obj};
0067   else
0068     objs = [objs {obj}];
0069   end
0070 end
0071 
0072 disp(sprintf('** Retrieved %d objects.', length(ids)));
0073 
0074 %---------------------------------------------------------------
0075 % Retrieve these Collections
0076 for k=1:length(cids)
0077   
0078   % get Ids from Cid
0079   ids = mysql_getObjIds(conn, cids(k));
0080   if isempty(ids)
0081     error('### This collection doesn''t seem to exist.');
0082   end
0083     
0084   for j=1:length(ids)
0085     disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
0086     tt = mysql_getObjType(conn, ids(j));
0087     objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0088     if appendObj
0089       objname = [objname '_' tt];
0090     end
0091     % Retrieve object
0092     ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0093     ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0094     db = regexp(conn.URL, '/', 'split');
0095     db = db{end};
0096     % add history
0097     pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0098     obj = eval(sprintf('%s(pl);', tt));
0099 
0100     assignin('base', objname, obj);
0101     disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0102     if j==1
0103       objs = {obj};
0104     else
0105       objs = [objs {obj}];
0106     end
0107   end
0108 end
0109 
0110 disp(sprintf('** Retrieved %d objects.', length(ids)));
0111 
0112 
0113 end
0114 
0115 
0116 function [ids, cids] = getIds()
0117 
0118 ids  = [];
0119 cids = [];
0120 
0121 th = findobj('Tag', 'retrieveIDsTxt');
0122 idStr = get(th, 'String');
0123 cs = cellstr(idStr);
0124 
0125 for j=1:length(cs)
0126   disp('---------')
0127   ls = cs{j};
0128   [s,r] = strtok(ls);
0129   if ~isempty(s)
0130     if s(1) == 'c'
0131       s = s(2:end);
0132       cids = [cids round(str2num(s))];
0133     else
0134       ids = [ids round(str2num(s))];
0135     end
0136   end
0137   while ~isempty(r)
0138     [s,r] = strtok(r);
0139     if ~isempty(s)
0140       if s(1) == 'c'
0141         s = s(2:end);
0142         cids = [cids round(str2num(s))];
0143       else
0144         ids = [ids round(str2num(s))];
0145       end
0146     end
0147   end
0148 end
0149 
0150 end

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003