comparison m-toolbox/classes/@repogui/cb_saveBtn.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % Callback executed when the user clicks on the save button.
2 %
3 % M Hewitson
4 %
5 % $Id: cb_saveBtn.m,v 1.4 2009/09/11 18:23:37 ingo Exp $
6 %
7 function cb_saveBtn(varargin)
8
9 myh = varargin{1};
10 mainfig = varargin{end};
11 % Get connection
12 % mainfig = findobj('Tag', 'LTPDARepomainfig');
13 conn = mainfig.connection;
14 if isempty(conn) || ~isa(conn, 'database')
15 utils.helper.errorDlg('Please connect to a database first', 'No connection found');
16 return
17 end
18
19 % Get variable name specs
20 h = findobj(mainfig.handle, 'Tag', 'objPrefixTxt');
21 prefix = get(h, 'String');
22 if isempty(prefix)
23 prefix = 'obj';
24 warning('! Using default prefix (obj)');
25 end
26 h = findobj(mainfig.handle, 'Tag', 'appendObjTypeChk');
27 appendObj = get(h, 'Value');
28 h = findobj(mainfig.handle, 'Tag', 'retrieveBinaryChk');
29 retrieveBinary = get(h, 'Value');
30 % Get IDs from text box
31 [ids, cids] = getIds(mainfig);
32
33
34 %---------------------------------------------------------------
35 % Retrieve these ids
36 objs = [];
37 for j=1:length(ids)
38 disp(sprintf('+ retrieving object %d', ids(j)));
39
40 % determine object type
41 tt = utils.mysql.getObjType(conn, ids(j));
42 objname = sprintf('%s%03d', prefix, ids(j));
43 if ~isempty(tt) && ~strcmp(tt, 'No Data')
44 if appendObj
45 objname = [objname '_' tt];
46 end
47 else
48 error('!!! Object type is unknown. Does this object really exist?');
49 end
50 % add file extension
51 objname = [objname '.xml'];
52
53 % Retrieve object
54 a = regexp(conn.URL, '//(\S+)/', 'tokens');
55 db = regexp(conn.URL, '/', 'split');
56 db = db{end};
57 % add history
58 pl = plist('hostname', a{1}, 'database', db, 'ID', ids(j), 'conn', conn);
59 if retrieveBinary
60 pl.append('Binary', 'yes');
61 disp(sprintf('*** performing binary retrieval.'));
62 end
63 obj = eval(sprintf('%s(pl);', tt));
64
65 % write to disk
66 save(obj, objname)
67
68 % assignin('base', objname, obj);
69 disp(sprintf('** Retrieve object %d to disk [%s]', ids(j), objname));
70
71 if j==1
72 objs = {obj};
73 else
74 objs = [objs {obj}];
75 end
76 end
77
78 disp(sprintf('** Retrieved %d objects.', length(ids)));
79
80 %---------------------------------------------------------------
81 % Retrieve these Collections
82 for k=1:length(cids)
83
84 % get Ids from Cid
85 ids = mysql_getObjIds(conn, cids(k));
86 if isempty(ids)
87 error('### This collection doesn''t seem to exist.');
88 end
89
90 for j=1:length(ids)
91 disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
92 tt = utils.mysql.getObjType(conn, ids(j));
93 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
94 if appendObj
95 objname = [objname '_' tt];
96 end
97 % Retrieve object
98 ipbits = regexp(conn.URL, '([0-9]+)', 'match');
99 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
100 db = regexp(conn.URL, '/', 'split');
101 db = db{end};
102 % add history
103 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
104 obj = eval(sprintf('%s(pl);', tt));
105
106 assignin('base', objname, obj);
107 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
108 if j==1
109 objs = {obj};
110 else
111 objs = [objs {obj}];
112 end
113 end
114 end
115
116 disp(sprintf('** Retrieved %d objects.', length(ids)));
117
118
119 end
120
121
122 function [ids, cids] = getIds(mainfig)
123
124 ids = [];
125 cids = [];
126
127 th = findobj(mainfig.handle, 'Tag', 'retrieveIDsTxt');
128 idStr = get(th, 'String');
129 cs = cellstr(idStr);
130
131 for j=1:length(cs)
132 disp('---------')
133 ls = cs{j};
134 [s,r] = strtok(ls);
135 if ~isempty(s)
136 if s(1) == 'c'
137 s = s(2:end);
138 cids = [cids round(str2num(s))];
139 else
140 ids = [ids round(str2num(s))];
141 end
142 end
143 while ~isempty(r)
144 [s,r] = strtok(r);
145 if ~isempty(s)
146 if s(1) == 'c'
147 s = s(2:end);
148 cids = [cids round(str2num(s))];
149 else
150 ids = [ids round(str2num(s))];
151 end
152 end
153 end
154 end
155 end