
%

%   Copyright 2013-2017 The MathWorks, Inc.

classdef (Hidden) PoolAttachedFiles < parallel.internal.display.CollapsibleList
    
    methods
        
        function obj = PoolAttachedFiles(displayHelper, list, aPool)
            obj@parallel.internal.display.CollapsibleList(displayHelper, list, aPool);
        end
        
    end
    
    methods (Access = protected)
        function value = getDisplayValue(~, ~)
            value = getString(message('parallel:lang:pool:AttachedFilesLink'));
        end
        
        function link = getDisplayLink(obj, toDisp, displayValue)
            if obj.DisplayHelper.ShowLinks
                
                matlabFunc = sprintf('parallel.internal.display.PoolAttachedFiles.displayAttachedFiles(''%s'')', ...
                    serialize(parallel.internal.display.PoolMemento(toDisp)));
                link = parallel.internal.display.HTMLDisplayType(displayValue, matlabFunc);
            else
                link = parallel.internal.display.HTMLDisplayType(displayValue);
            end
        end
    end
    
    methods (Hidden, Static)
        function displayAttachedFiles(serializedMemento)
            try
                pool = createObjectFromMemento(parallel.internal.display.Memento.deserialize(serializedMemento));
                % Relative paths are used where possible to reduce the
                % horizontal extent of the display.
                formattedFiles = parallel.internal.apishared.AttachedFiles.formatAttachedFilesForDisplay(pool.AttachedFiles);
                messageObj = message('parallel:lang:pool:AttachedFilesList');
                disp(messageObj.getString());
                disp(formattedFiles);
            catch err
                dctSchedulerMessage( 1, ...
                    'Failed to create pool from memento, original error: %s', err.getReport() );
                throw(err);
            end
        end
    end
end
