private void btnOK_Click(object sender, System.EventArgs e)
        {
            if (!LoadTemplateInfo())
            {
                return;
            }

            Visible = false;

            if (givenFilePackages == null)
            {
                SelectFilePackages();
            }
            else
            {
                filePackages = givenFilePackages; DialogResult = DialogResult.OK;
            }

            if (givenUserInput != null)
            {
                userInput = givenUserInput;
            }
            else if (DialogResult != DialogResult.Cancel && templateInfo.GetUserVariables().Count != 0)
            {
                TakeUserInput takeUserInput = new TakeUserInput(templateInfo);
                takeUserInput.ShowDialog();
                userInput    = takeUserInput.userVariables;
                DialogResult = takeUserInput.DialogResult;
            }

            // if all done, fully parse the selected template
            if (DialogResult == DialogResult.OK)
            {
                if (givenTemplate != null)
                {
                    template = givenTemplate;
                }
                else if (templatePath != "")
                {
                    if (!XML_handling.ParseTemplate(templatePath, out template, out ErrorCollector errorCollector))
                    {
                        DialogResult = DialogResult.Cancel;
                    }
                    if (errorCollector.HasErrors())
                    {
                        MessageBox.Show(errorCollector.GetErrorMessage());
                    }
                }
                else
                {
                    MessageBox.Show("Error! no template or templatepath given!");
                    DialogResult = DialogResult.Cancel;
                }
                if (template != null)
                {
                    template.info = templateInfo;
                }
            }

            if (sender != null && template != null && template.info != null && template.info.name != null)
            {
                // save selected template in session info
                TSDictionary pluginSessionInfo = new TSDictionary();
                pluginSessionInfo.SetItem(StatisticsPresenter.LAST_SELECTED_TEMPLATE, template.info.name);
                UISessionInfo.SetSessionUserSettings(StatisticsPresenter.USER_SETTINGS_ID, pluginSessionInfo);
            }

            Close();
        }