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