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

    % Copyright 2015 The MathWorks, Inc.

    properties(GetAccess = public, SetAccess = private)
        AppData        
    end
    
    %% Public methods
    methods(Access = public)        
        %% constructor
        function this = ExportModelDialog(data)
            Name = 'ExportModelDialog';
            Title = getString(message('Control:mrtool:TitleExportModelDialog'));
            this = this@controllib.app.dialog.internal.AbstractExportDialog(Name,Title);
            this.AppData = data;
            this.TableTitle  = getString(message('Control:mrtool:ExportModelTableLabel'));
            this.VariableColumnName = getString(message('Control:mrtool:ModelsExportModelDialog'));            
            this.DisplayedTableHeight = 80; % height of displayed table
            this.DisplayedTableWidth = 250;  % width of displayed table
        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 = 3;
            TableData = cell(TableLength,TableWidth);
            SelectedModels = getSelectedModelinDataBrowser(this.AppData);
            % set table data
            for ct = 1:length(this.AppData.Models)
                % first column boolean
                TableData{ct,1} = any(arrayfun(@(x) isequal(this.AppData.Models(ct),x),SelectedModels));
                % variable column
                TableData{ct,2} = this.AppData.Models(ct).Label;
                % rename the variables
                TableData{ct,3} = matlab.lang.makeValidName(TableData{ct,2});                
            end
        end        
        function val = getValueAt(this,array)
            val = this.AppData.Models(array).System;
        end
        function callbackHelpButton(this)
            mrtool.guiutil.mrToolHelp('ModelReducerExport',true);
        end                
    end 
    methods (Hidden)
        function Widgets = getWidgets(this)
            Widgets.ColumnNames = this.VariableColumnName;
            Widgets.TableData = this.TableData;
            Widgets.DialogName = this.Name;
            Widgets.DialogTitle = this.Title;
            Widgets.DialogTableTitle = this.TableTitle;
            Widgets.Dialog = this;
        end     
        function qeCallbackHelpButton(this)
            callbackHelpButton(this);            
        end        
    end
end
