function changehdlconfigtab(hDlg, tag, index)
%CHANGEHDLCONFIGTAB TabChangedCallback for the SLHDLC Configuration Dialog

% This utility is based on the file:
% toolbox\simulink\simulink\changeSimPrmTab.m
%
% This is a private utility required to ensure that the tab index(i.e, when
% viewed in ME) is maintained when a refresh is issued.

%   Author(s): P. Costa
%   Copyright 2005-2012 The MathWorks, Inc.
%     

if isequal(tag, 'Tag_ConfigSet_HDLCoder_tabs')
    hSrc = getDialogSource(hDlg);
    set(hSrc, 'HDLCActiveTab', index);

    if hSrc.isActive
        hMdl = hSrc.getModel;
        hSrc = getActiveConfigSet(hMdl);
%       set the Simulink.ConfigSet ActiveTab property
        set(hSrc, 'ActiveTab', index);
    end        
elseif isequal(tag, 'ConfigSet_HDLCoder_GlbSettingsPanel_Body')
    % find the belonging dialog handle
    hdlccomp =  gethdlcconfigset(hDlg.getSource);
    hGLBDialogObj = getsubcomponent(hdlccomp,'hdlcoderui.hdlglblsettings');
    set(hGLBDialogObj, 'HDLGSActiveTab', index);
end



