function pControlCallback(obj,action,dlg)
%PCONTROLCALLBACK - Dispatcher method for callbacks from dialog controls

%   Copyright 2009-2017 The MathWorks, Inc.

if strcmp(action,'MsgBox')
    % Just delete the dialog.  This will cause the "waitfor" in "msgbox"
    % to return.
    delete(dlg);
elseif strncmp(action,'QuestDlg_',9)
    val = action(10:end);
    obj.pDialogData.QuestDlgValue = val;
    % This will cause the "waitfor" in "errordlg" to return.
    delete(dlg);
    % Execute the callback if there is one.
    cb = obj.pDialogData.Callback;
    if ~isempty(cb)
        if iscell(cb)
            feval(cb{:},val);
        else
            feval(cb,val);
        end
    end
elseif strcmp(action,'list')
    ind = dlg.getWidgetValue('list');
    iteminfo = obj.pDialogData.ItemInfo{ind+1};
    dlg.setWidgetValue('info',iteminfo);
else
    assert(false,'DAStudio:DialogProvider:BadInput',...
           sprintf('Unexpected action: %s',action));
end
end

