<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers 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
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.actions;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.bindings.keys.IKeyLookup;
import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;

/**
 * @author <NAME>
 */
public class ToggleWorkingSetAction extends Action {

	private IWorkingSet workingSet;

	public ToggleWorkingSetAction(IWorkingSet set) {
		super(set.getLabel(), IAction.AS_CHECK_BOX);
		setImageDescriptor(set.getImageDescriptor());
		this.workingSet = set;
		setChecked(TaskWorkingSetUpdater.isWorkingSetEnabled(set));
	}

	@Override
	public void run() {
		runWithEvent(null);
	}
	
	@Override
	public void runWithEvent(Event event) {
		Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));

		boolean modified = false;
		if (event != null) {
			modified = (event.stateMask & KeyLookupFactory.getDefault().formalModifierLookup(IKeyLookup.M1_NAME)) != 0;
		}

		if (!modified) {
			// Default behavior is to act as a radio button.
			Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
			Iterator<IWorkingSet> iter = newList.iterator();
			while (iter.hasNext()) {
				IWorkingSet workingSet = iter.next();
				if (workingSet != null
						&& workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
					tempList.add(workingSet);
				}
			}
			newList.removeAll(tempList);

			if (isChecked()) {
				newList.add(workingSet);
			} else {
				// If multiples were previously selected, make this action active
				if (!TaskWorkingSetUpdater.isOnlyTaskWorkingSetEnabled(workingSet)) {
					newList.add(workingSet);
				}
			}
		} else {
			// If modifier key is pressed, de/selections are additive.
			if (isChecked()) {
				newList.add(workingSet);
			} else {
				newList.remove(workingSet);<commit_msg>Version update<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers 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
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.actions;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.bindings.keys.IKeyLookup;
import org.eclipse.jface.bindings.keys.KeyLookupFactory;
import org.eclipse.mylyn.internal.tasks.ui.workingsets.TaskWorkingSetUpdater;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;

/**
 * @author <NAME>
 */
public class ToggleWorkingSetAction extends Action {

	private IWorkingSet workingSet;

	public ToggleWorkingSetAction(IWorkingSet set) {
		super(set.getLabel(), IAction.AS_CHECK_BOX);
		setImageDescriptor(set.getImageDescriptor());
		this.workingSet = set;
		setChecked(TaskWorkingSetUpdater.isWorkingSetEnabled(set));
	}

	@Override
	public void run() {
		runWithEvent(null);
	}
	
	@Override
	public void runWithEvent(Event event) {
		Set<IWorkingSet> newList = new HashSet<IWorkingSet>(Arrays.asList(TaskWorkingSetUpdater.getEnabledSets()));

		boolean modified = false;
		if (event != null) {
			modified = (event.stateMask & KeyLookupFactory.getDefault().formalModifierLookup(IKeyLookup.M1_NAME)) != 0;
		}

		if (!modified) {
			// Default behavior is to act as a radio button.
			Set<IWorkingSet> tempList = new HashSet<IWorkingSet>();
			Iterator<IWorkingSet> iter = newList.iterator();
			while (iter.hasNext()) {
				IWorkingSet workingSet = iter.next();
				if (workingSet != null
						&& workingSet.getId() != null
						&& workingSet.getId().equalsIgnoreCase(TaskWorkingSetUpdater.ID_TASK_WORKING_SET)) {
					tempList.add(workingSet);
				}
			}
			newList.removeAll(tempList);

			if (isChecked()) {
				newList.add(workingSet);
			} else {
				// If multiples were previously selected, make this action active
				if (!TaskWorkingSetUpdater.isOnlyTaskWorkingSetEnabled(workingSet)) {
					newList.add(workingSet);
				}
			}
		} else {
			// If modifier key is pressed, de/selections are additive.
			if (isChecked()) {
				newList.add(workingSet);
			} else {
				newList.remove(workingSet);
{'fraction_non_alphanumeric': 0.16701264389507453, 'fraction_numerical': 0.005284015852047556, 'mean_word_length': 4.767138193688792, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5837169', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1564, 'n_words': 338}