classdef (Hidden) ExportModelDialog < controllib.ui.internal.dialog.AbstractExportDialog
    % Export model dialog for Model Reducer

    % Author(s): A. Ouellette
    % Copyright 2015-2023 The MathWorks, Inc.

    properties (SetAccess = private)
        AppData
        TableData
    end
    
    methods      
        %% constructor
        function this = ExportModelDialog(data)
            Name = 'ExportModelDialog';
            Title = getString(message('Control:mrtool:TitleExportModelDialog'));
            this = this@controllib.ui.internal.dialog.AbstractExportDialog(Name,Title);
            this.AllowColumnSorting = true;
            this.AddTagsToWidgets = true;
            this.AppData = data;
            this.TableTitle  = getString(message('Control:mrtool:ExportModelTableLabel'));
            this.DialogSize = [410 270];
        end
        
        function show(this,varargin)
            show@controllib.ui.internal.dialog.AbstractExportDialog(this,varargin{:});
        end
    end    
    %% Implementation of protected abstract or overloaded methods
    methods(Access = protected)                            
        % Get Table Data
        function TableData = getTableData(this)
            % set table size
            TableLength = length(this.AppData.Models);
            TableWidth = 1;
            TableData = cell(TableLength,TableWidth);
            %SelectedModels = getSelectedModelinDataBrowser(this.AppData);
            % set table data
            for ct = 1:length(this.AppData.Models)
                % variable column
                TableData{ct,1} = this.AppData.Models(ct).Name;
            end
            TableData = cell2table(TableData,'VariableNames',...
                            {getString(message('Control:mrtool:ModelsExportModelDialog'))});
            this.TableData = TableData;
        end
        
        function postUpdateUI(this)
            selectedModels = this.AppData.SelectedModel;
            if ~isempty(selectedModels)
                selectVariables(this,{selectedModels.Name});
            end
        end
        
        function val = getValueAt(this,array)
            val = this.AppData.Models(array).System;
        end
        
        function callbackHelpButton(this) %#ok<*MANU>
            helpview('control','ModelReducerExport','CSHelpWindow');            
        end                
    end 
    methods (Hidden)
        function Widgets = getWidgets(this)
            Widgets = qeGetWidgets(this);
            Widgets.ColumnNames = this.TableData.Properties.VariableNames;
            Widgets.TableData = this.TableData;
            Widgets.DialogName = this.Name;
            Widgets.DialogTitle = this.Title;
            Widgets.DialogTableTitle = this.TableTitle;
        end     
        function qeCallbackHelpButton(this)
            callbackHelpButton(this);            
        end        
    end
end
