<commit_before>package org.csstudio.utility.channel.actions;

import static gov.bnl.channelfinder.api.Tag.Builder.tag;
import gov.bnl.channelfinder.api.Channel;
import gov.bnl.channelfinder.api.ChannelFinderException;
import gov.bnl.channelfinder.api.Tag;

import java.beans.ExceptionListener;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.csstudio.utility.channelfinder.Activator;
import org.csstudio.utility.channelfinder.CFClientManager;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

public class AddTagAction implements IObjectActionDelegate {

	private Shell shell;
	private Collection<Channel> channels;

	/**
	 * Constructor for AddTagAction.
	 * 
	 * @wbp.parser.entryPoint
	 */
	public AddTagAction() {
		super();
		this.channels = new HashSet<Channel>();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 * @wbp.parser.entryPoint
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 * @wbp.parser.entryPoint
	 */
	public void run(IAction action) {
		Collection<String> existingTagNames = null;
		GetAllTags getAllTags = new GetAllTags();
		getAllTags.addExceptionListener(new ExceptionListener() {

			@Override
			public void exceptionThrown(Exception e) {
				final Exception exception = e;
				PlatformUI.getWorkbench().getDisplay()
						.asyncExec(new Runnable() {

							@Override
							public void run() {
								Status status = new Status(Status.ERROR,
										Activator.PLUGIN_ID,
										((ChannelFinderException) exception)
												.getMessage(), exception
												.getCause());
								ErrorDialog.openError(shell,
										"Error retrieving all the tag names.",
										exception.getMessage(), status);
							}
						});
			}
		});
		ExecutorService executor = Executors.newSingleThreadExecutor();
		try {
			existingTagNames = executor.submit(getAllTags).get();
		} catch (InterruptedException e1) {
		} catch (ExecutionException e1) {
		}

		AddTagDialog dialog = new AddTagDialog(shell, existingTagNames);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == Window.OK) {
			String tagName = dialog.getValue();
			Tag.Builder tag = tag(tagName);
			if (existingTagNames.contains(tagName)) {
			} else if (tagName != null && !tagName.equals("")) {
				CreateTagDialog createTagDialog = new CreateTagDialog(shell,
						tagName);
				createTagDialog.setBlockOnOpen(true);
				if (createTagDialog.open() == Window.OK) {
					Job create = new CreateTagJob("Create Tag", tag(
							createTagDialog.getTagName(),
							createTagDialog.getTagOwner()));
					create.schedule();
				}
			}
			Job job = new AddTag2ChannelsJob("AddTags", channels, tag);
			job.schedule();
		}
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 * @wbp.parser.entryPoint
	 */
	@SuppressWarnings("unchecked")
	public void selectionChanged(IAction action, ISelection selection) {
		if (selection != null & selection instanceof IStructuredSelection) {
			IStructuredSelection strucSelection = (IStructuredSelection) selection;
			channels.clear();
			for (Iterator<Channel> iterator = strucSelection.iterator(); iterator
					.hasNext();) {
				channels.add(iterator.next());
			}
		}
	}

	private class GetAllTags implements Callable<Collection<String>> {
		private List<ExceptionListener> listeners = new CopyOnWriteArrayList<ExceptionListener>();

		public void addExceptionListener(ExceptionListener listener) {<commit_msg>o.c.u.channel: add tag bug when new tag creation cancelled fixed<commit_after>package org.csstudio.utility.channel.actions;

import static gov.bnl.channelfinder.api.Tag.Builder.tag;
import gov.bnl.channelfinder.api.Channel;
import gov.bnl.channelfinder.api.ChannelFinderException;
import gov.bnl.channelfinder.api.Tag;

import java.beans.ExceptionListener;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.csstudio.utility.channelfinder.Activator;
import org.csstudio.utility.channelfinder.CFClientManager;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

public class AddTagAction implements IObjectActionDelegate {

	private Shell shell;
	private Collection<Channel> channels;

	/**
	 * Constructor for AddTagAction.
	 * 
	 * @wbp.parser.entryPoint
	 */
	public AddTagAction() {
		super();
		this.channels = new HashSet<Channel>();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 * @wbp.parser.entryPoint
	 */
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 * @wbp.parser.entryPoint
	 */
	public void run(IAction action) {
		Collection<String> existingTagNames = null;
		GetAllTags getAllTags = new GetAllTags();
		getAllTags.addExceptionListener(new ExceptionListener() {

			@Override
			public void exceptionThrown(Exception e) {
				final Exception exception = e;
				PlatformUI.getWorkbench().getDisplay()
						.asyncExec(new Runnable() {

							@Override
							public void run() {
								Status status = new Status(Status.ERROR,
										Activator.PLUGIN_ID,
										((ChannelFinderException) exception)
												.getMessage(), exception
												.getCause());
								ErrorDialog.openError(shell,
										"Error retrieving all the tag names.",
										exception.getMessage(), status);
							}
						});
			}
		});
		ExecutorService executor = Executors.newSingleThreadExecutor();
		try {
			existingTagNames = executor.submit(getAllTags).get();
		} catch (InterruptedException e1) {
		} catch (ExecutionException e1) {
		}

		AddTagDialog dialog = new AddTagDialog(shell, existingTagNames);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == Window.OK) {
			String tagName = dialog.getValue();
			Tag.Builder tag = tag(tagName);
			if (existingTagNames.contains(tagName)) {
			} else if (tagName != null && !tagName.equals("")) {
				CreateTagDialog createTagDialog = new CreateTagDialog(shell,
						tagName);
				createTagDialog.setBlockOnOpen(true);
				if (createTagDialog.open() == Window.OK) {
					Job create = new CreateTagJob("Create Tag", tag(
							createTagDialog.getTagName(),
							createTagDialog.getTagOwner()));
					create.schedule();
				}else{
					return;
				}
			}
			Job job = new AddTag2ChannelsJob("AddTags", channels, tag);
			job.schedule();
		}
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 * @wbp.parser.entryPoint
	 */
	@SuppressWarnings("unchecked")
	public void selectionChanged(IAction action, ISelection selection) {
		if (selection != null & selection instanceof IStructuredSelection) {
			IStructuredSelection strucSelection = (IStructuredSelection) selection;
			channels.clear();
			for (Iterator<Channel> iterator = strucSelection.iterator(); iterator
					.hasNext();) {
				channels.add(iterator.next());
			}
		}
	}

	private class GetAllTags implements Callable<Collection<String>> {
		private List<ExceptionListener> listeners = new CopyOnWriteArrayList<ExceptionListener>();

		public void addExceptionListener(ExceptionListener listener) {
{'fraction_non_alphanumeric': 0.11359144285548192, 'fraction_numerical': 0.0006975933031042902, 'mean_word_length': 4.349502487562189, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5837433', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2551, 'n_words': 501}