classdef (Abstract) AbstractTaskView < handle & matlab.mixin.Heterogeneous
    % The AbstractTaskView class defines a common interface for live task
    % front-end/view classes. All view classes have a model. The view is
    % responsible for presenting that model.
    %
    % FOR INTERNAL USE ONLY -- This feature is intentionally undocumented.
    % Its behavior may change, or it may be removed in a future release.

    % Copyright 2022 The MathWorks, Inc.

    properties (GetAccess = public, SetAccess = protected)

        % The view's parent container
        ParentContainer % (1, 1) GridLayout or AccordionPanel

        % Identifier for the view class
        Tag % (1, 1) string

        % Row in parent container. When parent is an AccordionPanel, Row is
        % not needed and will remain empty
        Row % (1, 1) double
    end

    properties (Constant, Access = public)

        % Reference row height for a Grid when not "fit"
        RowHeight = 22; % (1, 1) double

        % Reference grid column width for an icon
        IconGridWidth = 12; % (1, 1) double
    end

    properties (Access = protected)

        % The view is responsible for presenting thid model
        Model % (1, 1) Class type varies
    end

    events

        % Notify listeners when the view has a new user input
        ValueChangedEvent
    end

    methods (Access = public)

        function this = AbstractTaskView(parentContainer, tag, row, varargin)

            % Check for input arguments
            if nargin > 0

                % Set ParentContainer and Tag property from input args
                this.ParentContainer = parentContainer;
                this.Tag = tag;

                % Set Row property if passed
                if nargin > 2
                    this.Row = row;
                end

                % Create "empty" components
                this.createComponents();
            end
        end
    end

    methods (Access = protected)

        function valueChanged(this, ~, event)

            % Listener callback for the ValueChangedEvent

            % Notify listeners of a value change
            this.notify("ValueChangedEvent", event);
        end
    end

    methods (Abstract, Access = public)

        % Sets view to the current state of the Model
        updateView(model);
    end

    methods (Abstract, Access = protected)

        % Creates the widgets/components for the view class
        createComponents(this, parentContainer);
    end
end
