classdef autoblksMbcApplyCalTask < autoblksBlkSetupTask
    % Apply CAGE tables to model workspace

    % Copyright 2018-2020 The MathWorks, Inc.

    properties
        BlockName
        BaseMbcProject autoblksMbcSetupProject
        BaseCageProject autoblksCageSetupProject

        BlockParamTbl  matlab.ui.control.Table;
    end

    methods
        %% Constructor
        function obj = autoblksMbcApplyCalTask(BlockName, BaseMbcProject, InputBaseCageProject)
            obj.BlockName = BlockName;
            obj.BaseMbcProject = BaseMbcProject;
            obj.BaseCageProject = InputBaseCageProject;
            obj.TaskName = getString(message('autoblks_shared:autoblkSharedMisc:updateBlkParam'));
            obj.Description =  getString(message('autoblks_shared:autoblkSharedMisc:updateBlkParamDesc'));
        end

        %% TaskFcn
        function out=TaskFcn(varargin)
            obj=varargin{1};
            obj.BaseMbcProject.GetProject;
            obj.BaseCageProject.GetProject;
            if nargin<2
                obj.BaseCageProject.ApplyCalToBlk(obj.BlockName);
            else
                flag=varargin{2};
                out=obj.BaseCageProject.ApplyCalToBlk(obj.BlockName,flag);
            end
        end

        %% GetStatusFcn
        function GetStatusFcn(varargin)
            obj=varargin{1};
            obj.BaseCageProject.GetProject;
            if nargin<2
                obj.Completed = obj.BaseCageProject.isCalApplied(obj.BlockName);
            end
            obj.ErrorMsg = [];
            obj.WarningMsg = [];
        end

        %% DrawCustomPanel
        function DrawCustomPanel(obj)
            obj.BlockParamTbl = obj.CreateTbl('Block Parameters', obj.CustomPanelObj);
            obj.DisplayParamsUITable(obj.BlockParamTbl);
        end

        %% DisplayParamsUITable
        function DisplayParamsUITable(obj, UITableHdl)
            [ParamNames, ParamPrompts] = obj.BaseCageProject.getCalBlkParamInfo(obj.BlockName);
            UITableHdl.ColumnName = {getString(message('autoblks_shared:autoblkSharedMisc:Desc')),...
                getString(message('autoblks_shared:autoblkSharedMisc:BlkParamName'))};
            UITableHdl.ColumnEditable = false(1, length(UITableHdl.ColumnName));
            UITableHdl.Data = [ParamPrompts(:), ParamNames(:)];
            UITableHdl.ColumnWidth = num2cell(max(cellfun('length', [UITableHdl.ColumnName'; UITableHdl.Data]), [], 1)*6);
            UITableHdl.ColumnWidth = {350, 150};

        end
    end

end