classdef DeleteDialog < viewgui.internal.BaseTableDialog
    % Class for the dialog to delete systems from a Linear System Analyzer
    % session

    % Copyright 2021 The MathWorks, Inc.

    methods
        function this = DeleteDialog(app)
            Name = 'LinearSystemAnalyzerDeleteDialog';
            Title = getString(message('Control:viewer:strLTIViewerDelete'));
            this = this@viewgui.internal.BaseTableDialog(app,Name,Title);
            this.ShowExportAsColumn = false;
            this.AllowColumnSorting = true;
            this.AddTagsToWidgets = true;
            this.TableTitle = getString(message('Control:viewer:strSelectModelsToDelete'));
            this.ActionButtonLabel = getString(message('Control:viewer:strDelete'));
            this.SelectColumnName = getString(message('Controllib:gui:strSelect'));
            this.DialogSize = [420 280];
        end
    end

    %% Implementation of protected absract or overloaded methods
    methods(Access = protected)
        function modelNames = getValueAt(this, array)
            modelNames = get(this.App.Systems(array),{'Name'});
        end

        %% Callbacks
        function callbackHelpButton(this)
            ctrlguihelp('viewer_delete');
        end

        %% overload for generating script instead of exporting
        function callbackActionButton(this)
            % Get model names to delete
            modelNames = getValueAt(this,getSelectedIdx(this));
            try
                % Delete from Viewer
                if isempty(modelNames)
                    error(getString(message('Control:viewer:errNoSystemsToDelete')));
                end
                deletesys(this.App,modelNames);
                close(this);
            catch ME
                uialert(getWidget(this),ME.message,...
                    getString(message('Control:viewer:strDeleteError')));
            end
        end

    end
end