% SchedulerIDs - Used for formatting the display of Task scheduler
% IDs for Job class

%   Copyright 2018-2019 The MathWorks, Inc.

classdef (Hidden) SchedulerIDs < parallel.internal.display.CollapsibleList
    
    methods
        function obj = SchedulerIDs(displayHelper, list, job)
            obj@parallel.internal.display.CollapsibleList(displayHelper, list, job, 1);
        end
    end
    
    methods (Access = protected)
        function value = getDisplayValue(~, numFiles)
            value = getString(message('parallel:job:SchedulerIDLink', numFiles));
        end
        
        function link = getDisplayLink(obj, job, displayValue)
            if obj.DisplayHelper.ShowLinks
                matlabFunction = sprintf( ...
                    'parallel.internal.display.SchedulerIDs.displaySchedulerIDs(''%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 displaySchedulerIDs(serializedMemento)
            try
                job = createObjectFromMemento( ...
                    parallel.internal.display.Memento.deserialize(serializedMemento));
                disp(getString(message('parallel:job:SchedulerIDList', job.ID, ...
                    sprintf('  %s\n', job.getTaskSchedulerIDs{:}))));
            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', 'SchedulerIDs', ...
                    getString(message('parallel:cluster:Job')), helpString));
            end
        end
    end

end
