% EnvironmentVariables - Used for formatting the display of environment
% variables for Job class

%   Copyright 2017-2018 The MathWorks, Inc.

classdef (Hidden) EnvironmentVariables < parallel.internal.display.CollapsibleList
    
    methods
        function obj = EnvironmentVariables(displayHelper, list, job)
            obj@parallel.internal.display.CollapsibleList(displayHelper, list, job);
        end
    end
    
    methods (Access = protected)
        function value = getDisplayValue(~, numFiles)
            value = getString(message('parallel:job:EnvironmentVariablesLink', numFiles));
        end
        
        function link = getDisplayLink(obj, job, displayValue)
            if obj.DisplayHelper.ShowLinks
                matlabFunction = sprintf( ...
                    'parallel.internal.display.EnvironmentVariables.displayEnvironmentVariables(''%s'')', ...
                    serialize( parallel.internal.display.JobMemento(job)));
                link = parallel.internal.display.HTMLDisplayType(displayValue, matlabFunction);
            else
                link = parallel.internal.display.HTMLDisplayType(displayValue);
            end
        end
    end
    
    methods (Static)
        function displayEnvironmentVariables(serializedMemento)
            try
                job = createObjectFromMemento( ...
                    parallel.internal.display.Memento.deserialize(serializedMemento));
                disp(getString(message('parallel:job:EnvironmentVariablesList', job.ID, ...
                    sprintf('  %s\n', job.EnvironmentVariables{:}))));
            catch err
                dctSchedulerMessage(1, ...
                    'Failed to create Job from memento, original error: %s', err.getReport());
                if feature('hotlinks')
                    helpString = '<a href="matlab: helpPopup parallel.Job">help parallel.Job</a>';
                else
                    helpString = 'help parallel.Job';
                end
                error(message('parallel:cluster:LinkDispFailure', 'EnvironmentVariables', ...
                    getString(message('parallel:cluster:Job')), helpString));
            end
        end
    end
end
