function sldemo_mdladv_helper(varargin)
% SLDEMO_MDLADV_HELPER is a helper function for 
% Simulink demo sldemo_mdladv.


%	Copyright 1990-2010 The MathWorks, Inc.

persistent buttonClicked

model = 'sldemo_mdladv';
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(model,'new');
switch (varargin{1})
    case 'selectACheck'
        buttonClicked = 'selectACheck';
                
        mdladvObj.deselectCheckAll;
        mdladvObj.selectCheck('mathworks.design.UnconnectedLinesPorts');
        mdladvObj.runCheck;        
        mdladvObj.displayReport([mdladvObj.getWorkDir, filesep, 'report.html']);
               
    case 'ShowCheckPassFail'                
        if isempty(buttonClicked)
            errordlg('Please run Model Advisor first.');
            return            
        end
        if strcmp(buttonClicked,'selectACheck')
            selectedCheck = mdladvObj.getSelectedCheck;
        else
            selectedCheck = mdladvObj.getSelectedCheckForTask;
        end
        messageToShow = '';
        cr=sprintf('\n');
        for i=1:length(selectedCheck)
            if mdladvObj.getCheckResultStatus(selectedCheck{i})
                messageToShow = [messageToShow cr 'Check: ' selectedCheck{i} ' Pass']; %#ok<AGROW>
            else
                messageToShow = [messageToShow cr 'Check: ' selectedCheck{i} ' Fail']; %#ok<AGROW>
            end
        end
        msgbox(messageToShow,'Check running status');
        
    otherwise
        errordlg('Unknown methods.');
end
