<commit_before>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 *******************************************************************************/
package org.testeditor.ui.parts.inputparts.scenarioselection;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.testeditor.core.constants.TestEditorCoreEventConstants;
import org.testeditor.core.exceptions.SystemException;
import org.testeditor.core.model.teststructure.TestData;
import org.testeditor.core.model.teststructure.TestDataRow;
import org.testeditor.core.model.teststructure.TestScenario;
import org.testeditor.core.model.teststructure.TestScenarioParameterTable;
import org.testeditor.core.model.teststructure.TestStructure;
import org.testeditor.core.services.interfaces.TestProjectService;
import org.testeditor.core.services.interfaces.TestScenarioService;
import org.testeditor.ui.constants.TestEditorEventConstants;
import org.testeditor.ui.handlers.OpenTestStructureHandler;
import org.testeditor.ui.parts.commons.tree.filter.TestScenarioRecursiveFilter;
import org.testeditor.ui.parts.editor.ITestEditorController;
import org.testeditor.ui.parts.inputparts.AbstractTestEditorInputPartController;

/**
 * 
 * this class is the controller for the edit view part.
 * 
 */
public class TestEditorScenarioSelectionController extends AbstractTestEditorInputPartController implements
		ITestScenarioSelectionController {

	public static final String ID = "org.testeditor.ui.partdescriptor.testStructureEditor.ScenarioSelection";

	@Inject
	private IEclipseContext context;
	@Inject
	private TestScenarioService scenarioService;
	@Inject
	private TestProjectService testProjectService;

	private TestEditorScenarioSelectionView editArea;

	private ITestEditorController testEditorController;

	private TestScenarioTreeInput testScenarioTreeInput;

	@Inject
	private IEventBroker eventBroker;

	private Composite parent;
	private static final Logger LOGGER = Logger.getLogger(TestEditorScenarioSelectionController.class);

	/**
	 * this method is called when this part gets the focus. This method is
	 * necessary to handle the CTRL+Enter-Event. Don't delete the empty method.
	 */
	@Focus
	public void onFocus() {
		editArea.setCommitToDefaultButton();
	}

	/**
	 * 
	 * @param parent
	 *            composite
	 */
	@PostConstruct
	public void createControls(Composite parent) {
		this.parent = parent;
		editArea = ContextInjectionFactory.make(TestEditorScenarioSelectionView.class, context);
	}

	/**
	 * this method is called, when the TestCaseView-part is changed.
	 * 
	 * @param testEditorController
	 *            ITestEditorController
	 */
	public void setTestCaseController(ITestEditorController testEditorController) {
		this.testEditorController = testEditorController;
		if (!editArea.isNewTestEditorController(testEditorController)) {
			if (testScenarioTreeInput == null
					|| (testScenarioTreeInput != null && testScenarioTreeInput.getTestProject() == null || !testScenarioTreeInput
							.getTestProject().equals(testEditorController.getTestFlow().getRootElement()))) {

				testScenarioTreeInput = new TestScenarioTreeInput(
						testProjectService.getProjectWithName(testEditorController.getTestFlow().getRootElement()
								.getName()));

				editArea.changeTreeInput(testScenarioTreeInput);
				editArea.removeTreeFilter();
				if (testEditorController.getTestFlow() instanceof TestScenario) {
					editArea.setRecursiveFilter(new TestScenarioRecursiveFilter((TestScenario) testEditorController
							.getTestFlow()));
				}
			}
			editArea.createUI(parent);
			editArea.setTestScenarioSelectionController(this);
			editArea.setTestCaseControler(testEditorController);
			editArea.cleanInput();
			setAddMode(true);

		}
		editArea.enableViews();
	}

	/**
	 * put the text from the view area to the edit area.
	 * <commit_msg>TE-243 Fixing Nullpointer<commit_after>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 *******************************************************************************/
package org.testeditor.ui.parts.inputparts.scenarioselection;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.testeditor.core.constants.TestEditorCoreEventConstants;
import org.testeditor.core.exceptions.SystemException;
import org.testeditor.core.model.teststructure.TestData;
import org.testeditor.core.model.teststructure.TestDataRow;
import org.testeditor.core.model.teststructure.TestScenario;
import org.testeditor.core.model.teststructure.TestScenarioParameterTable;
import org.testeditor.core.model.teststructure.TestStructure;
import org.testeditor.core.services.interfaces.TestProjectService;
import org.testeditor.core.services.interfaces.TestScenarioService;
import org.testeditor.ui.constants.TestEditorEventConstants;
import org.testeditor.ui.handlers.OpenTestStructureHandler;
import org.testeditor.ui.parts.commons.tree.filter.TestScenarioRecursiveFilter;
import org.testeditor.ui.parts.editor.ITestEditorController;
import org.testeditor.ui.parts.inputparts.AbstractTestEditorInputPartController;

/**
 * 
 * this class is the controller for the edit view part.
 * 
 */
public class TestEditorScenarioSelectionController extends AbstractTestEditorInputPartController implements
		ITestScenarioSelectionController {

	public static final String ID = "org.testeditor.ui.partdescriptor.testStructureEditor.ScenarioSelection";

	@Inject
	private IEclipseContext context;
	@Inject
	private TestScenarioService scenarioService;
	@Inject
	private TestProjectService testProjectService;

	private TestEditorScenarioSelectionView editArea;

	private ITestEditorController testEditorController;

	private TestScenarioTreeInput testScenarioTreeInput;

	@Inject
	private IEventBroker eventBroker;

	private Composite parent;
	private static final Logger LOGGER = Logger.getLogger(TestEditorScenarioSelectionController.class);

	/**
	 * this method is called when this part gets the focus. This method is
	 * necessary to handle the CTRL+Enter-Event. Don't delete the empty method.
	 */
	@Focus
	public void onFocus() {
		editArea.setCommitToDefaultButton();
	}

	/**
	 * 
	 * @param parent
	 *            composite
	 */
	@PostConstruct
	public void createControls(Composite parent) {
		this.parent = parent;
		editArea = ContextInjectionFactory.make(TestEditorScenarioSelectionView.class, context);
	}

	/**
	 * this method is called, when the TestCaseView-part is changed.
	 * 
	 * @param testEditorController
	 *            ITestEditorController
	 */
	public void setTestCaseController(ITestEditorController testEditorController) {
		this.testEditorController = testEditorController;
		if (!editArea.isNewTestEditorController(testEditorController)) {
			if (testScenarioTreeInput == null
					|| (testScenarioTreeInput != null && testScenarioTreeInput.getTestProject() == null || (testScenarioTreeInput
							.getTestProject() != null && !testScenarioTreeInput.getTestProject().equals(
							testEditorController.getTestFlow().getRootElement())))) {

				testScenarioTreeInput = new TestScenarioTreeInput(
						testProjectService.getProjectWithName(testEditorController.getTestFlow().getRootElement()
								.getName()));

				editArea.changeTreeInput(testScenarioTreeInput);
				editArea.removeTreeFilter();
				if (testEditorController.getTestFlow() instanceof TestScenario) {
					editArea.setRecursiveFilter(new TestScenarioRecursiveFilter((TestScenario) testEditorController
							.getTestFlow()));
				}
			}
			editArea.createUI(parent);
			editArea.setTestScenarioSelectionController(this);
			editArea.setTestCaseControler(testEditorController);
			editArea.cleanInput();
			setAddMode(true);

		}
		editArea.enableViews();
	}

	/**
	 * put the text from the view area to the edit area.
	 * 
{'fraction_non_alphanumeric': 0.11757322175732217, 'fraction_numerical': 0.0042887029288702925, 'mean_word_length': 5.589248793935217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1572286', 'n_tokens_mistral': 2806, 'n_tokens_neox': 2567, 'n_words': 531}