classdef ToolstripController < handle
    % TOOLSTRIPCONTROLLER class to handle workflow actions of toolstrip
    
    % Copyright 2019 The MathWorks, Inc.
    
    methods(Static)
        function response = execute(clientData)
            handler = fxptui.Web.CallbackService.CallbackServiceFactory.getHandler(clientData.ActionID);
            response = handler.handle(clientData);
        end
        
        function state = getToolstripState(clientData)
            currentWorkflow = fxptui.Web.ToolstripController.getCurrentWorkflow();
            workflowIntent = currentWorkflow.WorkflowIntent;
            
            % build intent specific toolstrip state builder
            stateBuilderFactory = fxptui.Web.toolstrip.ToolstripStateBuilderFactory();
            tsBuilder = stateBuilderFactory.getBuilder(workflowIntent);
            
            % build toolstrip state based on client strategy
            stateStrategy = clientData.StateStrategy;
            switch stateStrategy
                case fxptui.message('tsActionStateStrategy')
                    tsBuilder.buildActionState();
                otherwise
                    % do nothing
            end
            
            state = tsBuilder.State;
        end
    end
    
    methods(Static, Hidden)
        function currentWorkflow = getCurrentWorkflow()
            fptInstance = fxptui.FixedPointTool.getExistingInstance();
            model = fptInstance.getModel;
            dataLayer = fxptds.DataLayerInterface.getInstance();
            currentWorkflow = dataLayer.getCurrentWorkflow(model);
        end
    end
end
