<commit_before>//
//  MD2WorkflowManager.swift
//  md2-ios-library
//
//  Created by <NAME> on 14.08.15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/// The object managing the workflow process.
class MD2WorkflowManager {
    
    /// The singleton instance
    static let instance: MD2WorkflowManager = MD2WorkflowManager()
    
    /// The current workflow element
    var currentWorkflowElement: MD2WorkflowElement?
    
    /// List of startable workflow elements to present on start screeen
    var startableWorkflowElements: Dictionary<MD2WidgetMapping, (String, MD2WorkflowElement)> = [:]
    
    /// Start screen view to fill with elements
    var startScreen: MD2ViewController?
    
    /// Singleton initializer
    private init() {
        // Private initializer for singleton object
    }
    
    /**
        Add startable workflow element.
    
        :param: workflowElement The startable workflow element
    */
    func addStartableWorkflowElement(workflowElement: MD2WorkflowElement, withCaption: String, forWidget: MD2WidgetMapping) {
        startableWorkflowElements[forWidget] = (withCaption, workflowElement)
    }
    
    /**
        Switch to another workflow element. The currently running workflow element (if existing) is properly ended beforehand.
    
        :param workflowElement The workflow element to start.
    */
    func goToWorkflow(workflowElement: MD2WorkflowElement) {
        println("[WorkflowManager] Switch workflow into '\(workflowElement.name)'")
        
        if let _ = currentWorkflowElement {
            currentWorkflowElement!.end()
        }
        currentWorkflowElement = workflowElement
        currentWorkflowElement!.start()
    }
    
    /**
        End the workflow element. To continue the app flow, the start view is invoked for a new workflow selection.
    
        :param workflowElement The workflow element to end.
    */
    func endWorkflow(workflowElement: MD2WorkflowElement) {
        println("[WorkflowManager] End workflow '\(workflowElement.name)'")

        workflowElement.end()
        currentWorkflowElement = nil
        
        // Go back to startup screen
        MD2ViewManager.instance.goToStartView()
    }
    
    /**
        Generate a view with buttons for all startable workflow elements that is shown on startup
    */
    func generateStartScreen() {
        let outerLayout = MD2FlowLayoutPane(widgetId: MD2WidgetMapping.__startScreen)
        outerLayout.orientation = MD2FlowLayoutPane.Orientation.Vertical
        
        // Add initial Label
        let label = MD2LabelWidget(widgetId: MD2WidgetMapping.__startScreen_Label)
        label.value = MD2String("Select workflow to start")
        label.fontSize = MD2Float(2.5)
        label.color = MD2String("#000000")
        label.textStyle = MD2WidgetTextStyle.Bold
        outerLayout.addWidget(label)
        MD2WidgetRegistry.instance.add(MD2WidgetWrapper(widget: label))
        <commit_msg>Fix library<commit_after>//
//  MD2WorkflowManager.swift
//  md2-ios-library
//
//  Created by <NAME> on 14.08.15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/// The object managing the workflow process.
class MD2WorkflowManager {
    
    /// The singleton instance
    static let instance: MD2WorkflowManager = MD2WorkflowManager()
    
    /// The current workflow element
    var currentWorkflowElement: MD2WorkflowElement?
    
    /// List of startable workflow elements to present on start screeen
    var startableWorkflowElements: Dictionary<MD2WidgetMapping, (String, MD2WorkflowElement)> = [:]
    
    /// Start screen view to fill with elements
    var startScreen: MD2ViewController?
    
    /// Singleton initializer
    private init() {
        // Private initializer for singleton object
    }
    
    /**
        Add startable workflow element.
    
        :param: workflowElement The startable workflow element
    */
    func addStartableWorkflowElement(workflowElement: MD2WorkflowElement, withCaption: String, forWidget: MD2WidgetMapping) {
        startableWorkflowElements[forWidget] = (withCaption, workflowElement)
    }
    
    /**
        Switch to another workflow element. The currently running workflow element (if existing) is properly ended beforehand.
    
        :param workflowElement The workflow element to start.
    */
    func goToWorkflow(workflowElement: MD2WorkflowElement) {
        println("[WorkflowManager] Switch workflow into '\(workflowElement.name)'")
        
        if let _ = currentWorkflowElement {
            currentWorkflowElement!.end()
        }
        currentWorkflowElement = workflowElement
        currentWorkflowElement!.start()
    }
    
    /**
        End the workflow element. To continue the app flow, the start view is invoked for a new workflow selection.
    
        :param workflowElement The workflow element to end.
    */
    func endWorkflow(workflowElement: MD2WorkflowElement) {
        println("[WorkflowManager] End workflow '\(workflowElement.name)'")

        workflowElement.end()
        currentWorkflowElement = nil
        
        // Go back to startup screen
        MD2ViewManager.instance.goToStartView()
    }
    
    /**
        Generate a view with buttons for all startable workflow elements that is shown on startup
    */
    func generateStartScreen() {
        let outerLayout = MD2FlowLayoutPane(widgetId: MD2WidgetMapping.__startScreen)
        outerLayout.orientation = MD2FlowLayoutPane.Orientation.Vertical
        
        // Add initial Label
        let label = MD2LabelWidget(widgetId: MD2WidgetMapping.__startScreen_Label)
        label.value = MD2String("Select workflow to start")
        label.fontSize = MD2Float(2.0)
		label.widgetElement.textAlignment = .Center
        label.color = MD2String("#000000")
        label.textStyle = MD2WidgetTextStyle.Bold
        outerLayout.addWidget(label)
        MD2WidgetRegistry.instance.add(MD2WidgetWrapper(widget: label))
        
{'fraction_non_alphanumeric': 0.0779003677699766, 'fraction_numerical': 0.014376462721497826, 'mean_word_length': 2.716149068322981, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7323471', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1535, 'n_words': 435}