comparison m-toolbox/classes/@repogui/cb_submit.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_SUBMIT callback executed when the user clicks on the 'Submit' button
2 %
3 % M Hewitson
4 %
5 % $Id: cb_submit.m,v 1.5 2009/05/11 17:09:17 nicola Exp $
6 %
7 function cb_submit(varargin)
8
9
10 myh = varargin{1};
11 mainfig = varargin{end};
12 status = findobj(mainfig.handle, 'Tag', 'RepoguiStatusTxt');
13 submitButton = findobj('Tag', 'repoguiSubmitButton');
14
15 % get object list
16 objlist = findobj(mainfig.handle, 'Tag', 'RepoguiObjs2SubmitList');
17 objstr = get(objlist, 'String');
18
19 % Build sinfo structure
20 sinfo.conn = mainfig.connection;
21 sinfo.experiment_title = get(findobj(mainfig.handle, 'Tag', 'RepoguiExperimentTitleEdit'), 'String');
22 sinfo.experiment_description = get(findobj(mainfig.handle, 'Tag', 'RepoguiExperimentDescriptionEdit'), 'String');
23 sinfo.analysis_description = get(findobj(mainfig.handle, 'Tag', 'RepoguiAnalysisDescriptionEdit'), 'String');
24 sinfo.quantity = get(findobj(mainfig.handle, 'Tag', 'RepoguiQuantityEdit'), 'String');
25 sinfo.keywords = get(findobj(mainfig.handle, 'Tag', 'RepoguiKeywordsEdit'), 'String');
26 sinfo.reference_ids = get(findobj(mainfig.handle, 'Tag', 'RepoguiReferenceIDsEdit'), 'String');
27 sinfo.additional_comments = get(findobj(mainfig.handle, 'Tag', 'RepoguiAdditonalCommentsEdit'), 'String');
28 sinfo.additional_authors = get(findobj(mainfig.handle, 'Tag', 'RepoguiAdditionalAuthorsEdit'), 'String');
29
30 if ~isa(sinfo.conn, 'database')
31 error('### Please connect to a database before trying to submit.');
32 end
33
34 objs = [];
35 objname = '';
36
37 if isempty(objstr)
38 error('### There are no objects selected to be submitted.');
39 end
40
41 % Remove all incorrect lines
42 jj = 1;
43 while jj<=numel(objstr)
44 try
45 cmd = sprintf('obj = evalin(''base'', ''%s'');', objstr{jj});
46 eval(cmd);
47 objs = [objs ; obj];
48 jj = jj+1;
49 catch
50 warning(['### The submission ignored the input on line ' num2str(jj) ', ''' objstr{jj} ''', because there''s no such variable, or it has a different class with respect to the first object selected.' ]) %#ok<WNTAG>
51 objstr(jj) = [];
52 end
53 end
54
55 % Put together the objects to submit
56 objs = [];
57 for j=1:numel(objstr)
58 if ~isempty(objname), objname = [objname ', ']; end
59 cmd = sprintf('obj = evalin(''base'', ''%s'');', objstr{j});
60 eval(cmd);
61 objname = [objname objstr{j}];
62 objs = [objs ; obj];
63 end
64
65 % Submit objects
66 try
67 set(submitButton,'String','Submitting...')
68 set(status,'String','++ Submitting object(s)','ForeGroundcolor','r')
69 drawnow
70 [ids, cid] = submit(objs, sinfo);
71 if isempty(ids)
72 warning('!!! Failed to submit object: %s', objname);
73 set(status,'String',sprintf('!!! Failed to submit object: %s', objname),'ForeGroundcolor','r');
74 else
75 disp(sprintf('++ Submitted object(s) %s (ref id = %s, collection id = %d)', objname, mat2str(ids), cid));
76 set(status,'String',sprintf('++ Submitted object(s) %s (ref id = %s, collection id = %d)', objname, mat2str(ids), cid),'ForeGroundcolor','b');
77 end
78 set(submitButton,'String','Submit')
79 catch
80 set(status,'String',sprintf('!!! Failed to submit object: %s', objname));
81 set(submitButton,'String','Submit')
82 warning('!!! Failed to submit object: %s', objname);
83 rethrow(lasterror)
84 end
85
86 end