comparison m-toolbox/classes/@ltpda_uo/submitDialog.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children 5eb86f6881ef
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SUBMITDIALOG Creates a connection and the sinfo structure depending of the input variables.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SUBMITDIALOG Creates a connection and the sinfo structure
5 % depending of the input variables.
6 %
7 % CALL: sinfo = submitDialog(sinfo_in, pl)
8 %
9 % VERSION: $Id: submitDialog.m,v 1.19 2011/11/10 09:47:47 mauro Exp $
10 %
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13 function sinfo = submitDialog(pl)
14
15 % Copy input plist
16 pl = copy(pl, 1);
17
18 %%% Show dialog or not
19 noDialog = pl.find('no dialog');
20
21 %%% Create/fill sinfo from the plist.
22 sinfo = getDefaultStruct();
23
24 %%% Check If we should the sinfo from a file
25 if ~isempty(pl.find('sinfo filename'))
26 pl.combine(utils.xml.read_sinfo_xml(pl.find('sinfo filename')));
27 end
28
29 %%% Set the fields from the plist to the struct
30 sinfo = setField(sinfo, pl, 'experiment title');
31 sinfo = setField(sinfo, pl, 'experiment description');
32 sinfo = setField(sinfo, pl, 'analysis description');
33 sinfo = setField(sinfo, pl, 'quantity');
34 sinfo = setField(sinfo, pl, 'keywords');
35 sinfo = setField(sinfo, pl, 'reference ids');
36 sinfo = setField(sinfo, pl, 'additional comments');
37 sinfo = setField(sinfo, pl, 'additional authors');
38
39 %%% Create connection if the
40 if (allFieldsFilled(sinfo)) || ...
41 (allMandatoryFieldsFilled(sinfo) && noDialog)
42
43 %%% Return because we have all sinfo information
44 return
45 end
46
47 jsinfo = awtcreate('mpipeline.repository.SubmissionInfo', 'Lmpipeline.main.MainWindow;', []);
48
49 if ~isempty(sinfo.experiment_title), jsinfo.setExperimentTitle(sinfo.experiment_title);end
50 if ~isempty(sinfo.experiment_description), jsinfo.setExperimentDescription(sinfo.experiment_description); end
51 if ~isempty(sinfo.analysis_description), jsinfo.setAnalysisDescription(sinfo.analysis_description); end
52 if ~isempty(sinfo.quantity), jsinfo.setQuantity(sinfo.quantity); end
53 if ~isempty(sinfo.keywords), jsinfo.setKeywords(sinfo.keywords); end
54 if ~isempty(sinfo.reference_ids), jsinfo.setReferenceIDs(sinfo.reference_ids); end
55 if ~isempty(sinfo.additional_comments), jsinfo.setAdditionalComments(sinfo.additional_comments); end
56 if ~isempty(sinfo.additional_authors), jsinfo.setAdditionalAuthors(sinfo.additional_authors); end
57
58 % sid = awtcreate('mpipeline.repository.SubmitInfoDialog', 'Lmpipeline.main.MainWindow;Lmpipeline.repository.SubmissionInfo;', [], jsinfo);
59 sid = javaObjectEDT('mpipeline.repository.SubmitInfoDialog', [], jsinfo);
60
61 h1 = handle(sid.getLoadBtn,'callbackproperties');
62 h1.ActionPerformedCallback = @cb_loadSinfoFromFile;
63
64 h2 = handle(sid.getSaveBtn,'callbackproperties');
65 h2.ActionPerformedCallback = @cb_saveSinfoToFile;
66
67 h3 = handle(sid, 'callbackproperties');
68 h3.WindowClosedCallback = @cb_guiClosed;
69
70 sid.setVisible(true)
71
72 if sid.isCancelled
73 sinfo = [];
74 else
75 %%% Store the 'sinfo' of the GUI to the output sinfo
76 jsinfo = sid.getSubmissionInfo;
77 sinfo.experiment_title = char(jsinfo.getExperimentTitle);
78 sinfo.experiment_description = char(jsinfo.getExperimentDescription);
79 sinfo.analysis_description = char(jsinfo.getAnalysisDescription);
80 sinfo.quantity = char(jsinfo.getQuantity);
81 sinfo.keywords = char(jsinfo.getKeywords);
82 sinfo.reference_ids = char(jsinfo.getReferenceIDs);
83 sinfo.additional_comments = char(jsinfo.getAdditionalComments);
84 sinfo.additional_authors = char(jsinfo.getAdditionalAuthors);
85 end
86
87 jsinfo = [];
88 sid = [];
89 pl = [];
90 prefs = [];
91 java.lang.System.gc();
92
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % nested callback Function: cb_loadSinfoFromFile()
96 %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 function cb_loadSinfoFromFile(varargin)
99 [FileName, PathName, FilterIndex] = uigetfile('*.xml', 'XML File');
100
101 if (FileName)
102 try
103 sinfoPl = utils.xml.read_sinfo_xml(fullfile(PathName, FileName));
104
105 % Set the values from the PLIST to the dialog.
106 if ~isempty(sinfoPl.find('experiment title'))
107 sid.setExperimentTitleTxtField(sinfoPl.find('experiment title')); end
108 if ~isempty(sinfoPl.find('experiment_title'))
109 sid.setExperimentTitleTxtField(sinfoPl.find('experiment_title')); end
110
111 if ~isempty(sinfoPl.find('experiment description'))
112 sid.setExperimentDescriptionTxtField(sinfoPl.find('experiment description')); end
113 if ~isempty(sinfoPl.find('experiment_description'))
114 sid.setExperimentDescriptionTxtField(sinfoPl.find('experiment_description')); end
115
116 if ~isempty(sinfoPl.find('analysis description'))
117 sid.setAnalysisDescriptionTxtField(sinfoPl.find('analysis description')); end
118 if ~isempty(sinfoPl.find('analysis_description'))
119 sid.setAnalysisDescriptionTxtField(sinfoPl.find('analysis_description')); end
120
121 if ~isempty(sinfoPl.find('quantity'))
122 sid.setquantityTxtField(sinfoPl.find('quantity')); end
123
124 if ~isempty(sinfoPl.find('keywords'))
125 sid.setKeywordsTxtField(sinfoPl.find('keywords')); end
126
127 if ~isempty(sinfoPl.find('reference ids'))
128 sid.setReferenceIDsTxtField(sinfoPl.find('reference ids')); end
129 if ~isempty(sinfoPl.find('reference_ids'))
130 sid.setReferenceIDsTxtField(sinfoPl.find('reference_ids')); end
131
132 if ~isempty(sinfoPl.find('additional comments'))
133 sid.setAdditionalCommentsTxtField(sinfoPl.find('additional comments')); end
134 if ~isempty(sinfoPl.find('additional_comments'))
135 sid.setAdditionalCommentsTxtField(sinfoPl.find('additional_comments')); end
136
137 if ~isempty(sinfoPl.find('additional authors'))
138 sid.setAdditionalAuthorsTxtField(sinfoPl.find('additional authors')); end
139 if ~isempty(sinfoPl.find('additional_authors'))
140 sid.setAdditionalAuthorsTxtField(sinfoPl.find('additional_authors')); end
141
142 catch err
143 utils.helper.err(['### This file doesn''t contain any submission information.' err.message])
144 end
145
146 end
147 end
148
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %
151 % nested callback Function: cb_saveSinfoToFile()
152 %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 function cb_saveSinfoToFile(varargin)
155
156 saveBtn = varargin{1};
157 jsinfo = saveBtn.rootPane.getParent().getSubmissionInfo();
158
159 sinfo.experiment_title = char(jsinfo.getExperimentTitle());
160 sinfo.experiment_description = char(jsinfo.getExperimentDescription());
161 sinfo.analysis_description = char(jsinfo.getAnalysisDescription());
162 sinfo.quantity = char(jsinfo.getQuantity());
163 sinfo.keywords = char(jsinfo.getKeywords());
164 sinfo.reference_ids = char(jsinfo.getReferenceIDs());
165 sinfo.additional_comments = char(jsinfo.getAdditionalComments());
166 sinfo.additional_authors = char(jsinfo.getAdditionalAuthors());
167
168 [FileName, PathName, FilterIndex] = uiputfile('*.xml', 'XML File');
169
170 if (FileName)
171 try
172 utils.xml.save_sinfo_xml(fullfile(PathName, FileName), sinfo);
173 catch
174 end
175
176 end
177 end
178
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 %
181 % nested callback Function: cb_guiClosed()
182 %
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 function cb_guiClosed(varargin)
185 if ishandle(h1)
186 delete(h1);
187 end
188 if ishandle(h2)
189 delete(h2);
190 end
191 if ishandle(h3)
192 delete(h3);
193 end
194 end
195
196 end
197
198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 % Local Functions %
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 %
204 % FUNCTION: getDefaultStruct
205 %
206 % DESCRIPTION: Creates default structure for 'sinfo'
207 %
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209
210 function sinfo = getDefaultStruct()
211 sinfo = struct(...
212 'experiment_title', '', ...
213 'experiment_description', '', ...
214 'analysis_description', '', ...
215 'quantity', '', ...
216 'keywords', '', ...
217 'reference_ids', '', ...
218 'additional_comments', '', ...
219 'additional_authors', '');
220 end
221
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 %
224 % FUNCTION: allMandatoryFieldsFilled
225 %
226 % DESCRIPTION: Check if all mandatory fields are filled in 'sinfo'.
227 %
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229
230 function res = allMandatoryFieldsFilled(sinfo)
231 res = false;
232 if isstruct(sinfo)
233 if isfield(sinfo, 'experiment_title') && ~isempty(sinfo.experiment_title) && ...
234 isfield(sinfo, 'experiment_description') && ~isempty(sinfo.experiment_description) && ...
235 isfield(sinfo, 'analysis_description') && ~isempty(sinfo.analysis_description)
236 res = true;
237 end
238 end
239 end
240
241
242 function res = allFieldsFilled(sinfo)
243 res = false;
244 if isstruct(sinfo)
245 if isfield(sinfo, 'experiment_title') && ~isempty(sinfo.experiment_title) && ...
246 isfield(sinfo, 'experiment_description') && ~isempty(sinfo.experiment_description) && ...
247 isfield(sinfo, 'analysis_description') && ~isempty(sinfo.analysis_description) && ...
248 isfield(sinfo, 'quantity') && ~isempty(sinfo.quantity) && ...
249 isfield(sinfo, 'keywords') && ~isempty(sinfo.keywords) && ...
250 isfield(sinfo, 'reference_ids') && ~isempty(sinfo.reference_ids) && ...
251 isfield(sinfo, 'additional_comments') && ~isempty(sinfo.additional_comments) && ...
252 isfield(sinfo, 'additional_authors') && ~isempty(sinfo.additional_authors)
253 res = true;
254 end
255 end
256 end
257
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 %
260 % FUNCTION: setField
261 %
262 % DESCRIPTION:
263 %
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 function sinfo = setField(sinfo, pl, field)
267 struct_field = strrep(field, ' ', '_');
268
269 % if the fiels doesn't exist in the struct then create this field
270 if ~isfield(sinfo, struct_field)
271 sinfo.(struct_field) = '';
272 end
273
274 if ~isempty(pl.find(field))
275 sinfo.(struct_field) = pl.find(field);
276 end
277 if ~isempty(pl.find(strrep(field, ' ', '_')))
278 sinfo.(struct_field) = pl.find(strrep(field, ' ', '_'));
279 end
280 end
281
282
283
284