<commit_before>/**
 * 
 */
package org.teagle.vcttool.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabItem;
import org.teagle.vcttool.app.ValidateActions;
import org.teagle.vcttool.control.RootController;
import org.teagle.vcttool.view.dialogs.InputDialog;
import org.teagle.vcttool.view.dialogs.MessageDialog;

import teagle.vct.model.ModelManager;
import teagle.vct.model.RepositoryException;
import teagle.vct.model.Vct;
import teagle.vct.tssg.impl.TSSGVct;
import teagle.vct.util.Util;
import de.fhg.fokus.ngni.openpe.pem1.EvaluationHandler;

/**
 * @author sim
 * 
 */
public class CommandAdapter implements CommandListener {
	RootController rootController;

	public CommandAdapter(RootController rootController) {
		this.rootController = rootController;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onNew()
	 */
	public void onNew() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onSave()
	 */
	public boolean onSave(VctToolView vctView, Vct data) {
		if (data.isModified()) {
			if (!data.isPersisted())
				return onSaveAs(vctView, data);
			else
				data = (Vct) data.persist();
		} else {
			System.out.println("wasn't changed");
		}

		return true;
	}

	public void onOpen() {
		System.out.println("open");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onSaveAs()
	 */
	public boolean onSaveAs(VctToolView vctView, Vct data) {

		EvaluationHandler handler = new EvaluationHandler();
		if (!ValidateActions.validateVCT(data, handler)) {
			Util.showMsg(vctView.getShell(), SWT.ERROR,
					"VCT failed to be saved", handler.getMessage());
			System.out.println("Failed to save VCT");
		} else {

			InputDialog dialog = new InputDialog(vctView.getShell(),
					"Save VCT as...");
			dialog.addInputField("Name", "", "VCT-Name");
			switch (dialog.show()) {
			case SWT.OK:
				// String vctName = ((TSSGVct)data).getPerson().getUserName() +
				// "_"
				// + dialog.getName();

				String vctName = dialog.getName();
				if (dialog.getName().equals("")) {
					vctView.showError("No name given.");
					System.out.println("no name given");
				} else if (!ModelManager.getInstance().vctExists(vctName,
						((TSSGVct) data).getPerson().getUserName())) {
					((TSSGVct) data).setCommonName(dialog.getName());
					data = ((TSSGVct) data).persist();
					rootController.reloadVcts();
					return true;
				} else
					vctView.showError("VCT name already taken.");

				break;
			case SWT.CANCEL:
				break;
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onExit()
	 */
	public void onExit() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onPreferences()
	 */
	public void onPreferences() {
	}

	// @Override<commit_msg>added some debug info<commit_after>/**
 * 
 */
package org.teagle.vcttool.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabItem;
import org.teagle.client.TeagleClient;
import org.teagle.vcttool.app.ValidateActions;
import org.teagle.vcttool.control.RootController;
import org.teagle.vcttool.view.dialogs.InputDialog;
import org.teagle.vcttool.view.dialogs.MessageDialog;

import teagle.vct.model.ModelManager;
import teagle.vct.model.RepositoryException;
import teagle.vct.model.Vct;
import teagle.vct.tssg.impl.TSSGVct;
import teagle.vct.util.Util;
import de.fhg.fokus.ngni.openpe.pem1.EvaluationHandler;

/**
 * @author sim
 * 
 */
public class CommandAdapter implements CommandListener {
	RootController rootController;

	public CommandAdapter(RootController rootController) {
		this.rootController = rootController;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onNew()
	 */
	public void onNew() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onSave()
	 */
	public boolean onSave(VctToolView vctView, Vct data) {
		if (data.isModified()) {
			if (!data.isPersisted())
				return onSaveAs(vctView, data);
			else
				data = (Vct) data.persist();
		} else {
			System.out.println("wasn't changed");
		}

		return true;
	}

	public void onOpen() {
		System.out.println("open");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onSaveAs()
	 */
	public boolean onSaveAs(VctToolView vctView, Vct data) {

		EvaluationHandler handler = new EvaluationHandler();
		if (!ValidateActions.validateVCT(data, handler)) {
			Util.showMsg(vctView.getShell(), SWT.ERROR,
					"VCT failed to be saved", handler.getMessage());
			System.out.println("Failed to save VCT");
		} else {

			InputDialog dialog = new InputDialog(vctView.getShell(),
					"Save VCT as...");
			dialog.addInputField("Name", "", "VCT-Name");
			switch (dialog.show()) {
			case SWT.OK:
				// String vctName = ((TSSGVct)data).getPerson().getUserName() +
				// "_"
				// + dialog.getName();

				String vctName = dialog.getName();
				if (dialog.getName().equals("")) {
					vctView.showError("No name given.");
					System.out.println("no name given");
				} else if (!ModelManager.getInstance().vctExists(vctName,
						((TSSGVct) data).getPerson().getUserName())) {
					((TSSGVct) data).setCommonName(dialog.getName());
					System.out.println("DEBUG: Booking (really): " +  TeagleClient.toString(data));
					data = ((TSSGVct) data).persist();
					rootController.reloadVcts();
					return true;
				} else
					vctView.showError("VCT name already taken.");

				break;
			case SWT.CANCEL:
				break;
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onExit()
	 */
	public void onExit() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.teagle.vcttool.view.CommandListener#onPreferences()
	 */
	public void onPreferences() {
	}

	// @Override
{'fraction_non_alphanumeric': 0.15362169584620666, 'fraction_numerical': 0.00034328870580157915, 'mean_word_length': 3.5809748427672954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5933509', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2038, 'n_words': 348}