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.2 2008/03/11 15:44:13 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.2 2008/03/11 15:44:13 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   % 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   
0081   for j=1:length(ids)
0082     disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
0083     tt = mysql_getObjType(conn, ids(j));
0084     objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0085     if appendObj
0086       objname = [objname '_' tt];
0087     end
0088     % Retrieve object
0089     ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0090     ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0091     db = regexp(conn.URL, '/', 'split');
0092     db = db{end};
0093     % add history
0094     pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0095     obj = eval(sprintf('%s(pl);', tt));
0096 
0097     assignin('base', objname, obj);
0098     disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0099     if j==1
0100       objs = {obj};
0101     else
0102       objs = [objs {obj}];
0103     end
0104   end
0105 end
0106 
0107 disp(sprintf('** Retrieved %d objects.', length(ids)));
0108 
0109 
0110 end
0111 
0112 
0113 function [ids, cids] = getIds()
0114 
0115 ids  = [];
0116 cids = [];
0117 
0118 th = findobj('Tag', 'retrieveIDsTxt');
0119 idStr = get(th, 'String');
0120 cs = cellstr(idStr);
0121 
0122 for j=1:length(cs)
0123   disp('---------')
0124   ls = cs{j};
0125   [s,r] = strtok(ls);
0126   if ~isempty(s)
0127     if s(1) == 'c'
0128       s = s(2:end);
0129       cids = [cids round(str2num(s))];
0130     else
0131       ids = [ids round(str2num(s))];
0132     end
0133   end
0134   while ~isempty(r)
0135     [s,r] = strtok(r);
0136     if ~isempty(s)
0137       if s(1) == 'c'
0138         s = s(2:end);
0139         cids = [cids round(str2num(s))];
0140       else
0141         ids = [ids round(str2num(s))];
0142       end
0143     end
0144   end
0145 end
0146 
0147 end

Generated on Tue 25-Mar-2008 23:00:00 by m2html © 2003