0001 function varargout = ui_et_edit_cb(D, action, varargin)
0002
0003
0004
0005
0006
0007 if nargin < 2
0008 error('Need action');
0009 end
0010
0011 F = gcbf;
0012 action = lower(action);
0013 switch action
0014 case 'ok'
0015
0016 hName = findobj(F, 'Tag', 'ui_et_name');
0017 new_name = get(hName, 'String');
0018 old_name = get(hName, 'UserData');
0019 new_name = deblank(fliplr(deblank(fliplr(new_name))));
0020 if isempty(new_name) | strcmp(new_name, 'New event')
0021 msgbox('Need a name for this event type'); return
0022 end
0023
0024 if ~strcmp(new_name, old_name)
0025
0026 ets = event_types(D);
0027 if ~isempty(ets)
0028 if ismember(new_name, {ets(:).name})
0029 msgbox(['Event type ' new_name ' already exists']); return
0030 end
0031 end
0032 end
0033
0034 if isempty(get(findobj(F, 'Tag', 'ui_et_IN'), 'String'))
0035 msgbox('Need events for this event type'); return
0036 end
0037
0038 set(hName, 'String', new_name);
0039 set(findobj(F,'Tag','ui_et_done'),'UserData',1);
0040 case 'cancel'
0041 set(findobj(F,'Tag','ui_et_done'),'UserData',0);
0042 case {'add', 'remove'}
0043 switch action
0044 case 'add'
0045 hListTO = findobj(F, 'Tag', 'ui_et_IN');
0046 hListFROM = findobj(F, 'Tag', 'ui_et_OUT');
0047 case 'remove'
0048 hListFROM = findobj(F, 'Tag', 'ui_et_IN');
0049 hListTO = findobj(F, 'Tag', 'ui_et_OUT');
0050 end
0051 TO_evs = get(hListTO, 'UserData');
0052 FROM_evs = get(hListFROM, 'UserData');
0053 if isempty(FROM_evs), msgbox(['No events to ' action]); end
0054 es_to_add = get(hListFROM, 'Value');
0055 if isempty(es_to_add)
0056 msgbox(['Please select events to ' action]); return
0057 end
0058 TO_evs.names = [TO_evs.names; FROM_evs.names(es_to_add)];
0059 FROM_evs.names(es_to_add) = [];
0060 TO_evs.e_spec = [TO_evs.e_spec FROM_evs.e_spec(:, es_to_add)];
0061 FROM_evs.e_spec(:, es_to_add) = [];
0062 set(hListTO, 'UserData', TO_evs);
0063 set(hListFROM, 'UserData', FROM_evs);
0064 set(hListFROM, 'Value', []);
0065 ui_et_edit_cb(D, 'sort');
0066 case 'sort'
0067 sort_obj = findobj(F, 'Tag', 'ui_et_sort');
0068 sort_strs = cellstr(get(sort_obj, 'String'));
0069 sort_type = sort_strs{get(sort_obj, 'Value')};
0070 for H = [findobj(F, 'Tag', 'ui_et_IN') findobj(F, 'Tag', 'ui_et_OUT')]
0071 evs = pr_sort_evs(get(H, 'UserData'), sort_type);
0072 set(H, 'String', evs.names);
0073 set(H, 'UserData', evs);
0074 end
0075 otherwise
0076 error([ action ' is deviant' ]);
0077 end
0078
0079 return
0080
0081
0082
0083