<commit_before>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

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

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylyn.core.MylarStatusHandler;
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.TaskCategory;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;

/**
 * @author <NAME>
 */
public class RemoveFromCategoryAction extends Action {
	public static final String ID = "org.eclipse.mylyn.tasklist.actions.remove";

	private final TaskListView view;

	public RemoveFromCategoryAction(TaskListView view) {
		this.view = view;
		setText("Remove From Category");
		setId(ID);
		setImageDescriptor(TasksUiImages.REMOVE);
	}

	@Override
	public void run() {
		try {
			ISelection selection = TaskListView.getFromActivePerspective().getViewer().getSelection();
			for (Object selectedObject : ((IStructuredSelection) selection).toList()) {
				if (selectedObject instanceof AbstractTask) { // && !((ITask) selectedObject).isLocal()) {
					AbstractTask task = (AbstractTask) selectedObject;
					if (task.isActive()) {
						MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
								ITasksUiConstants.TITLE_DIALOG,
								"Task must be deactivated in order to remove from category.");
						return;
					}

					TreeItem item = this.view.getViewer().getTree().getSelection()[0];
					if (item.getParentItem() != null && item.getParentItem().getData() instanceof TaskCategory) {
						TaskCategory category = (TaskCategory) item.getParentItem().getData();
						TasksUiPlugin.getTaskListManager().getTaskList().removeFromCategory(category, task);
					} 
					TasksUiPlugin.getTaskListManager().getTaskList().moveToContainer(task, TasksUiPlugin.getTaskListManager().getTaskList().getDefaultCategory()); 
					// just in case, should already be there
//					MylarTaskListPlugin.getTaskListManager().getTaskList().addTaskToArchive(task);
//					ITaskContainer cat = task.getCategory();
//					if (cat != null) {
//						String message = DeleteAction.genDeleteConfirmationMessage(task);
//						boolean deleteConfirmed = MessageDialog.openQuestion(PlatformUI.getWorkbench()
//								.getActiveWorkbenchWindow().getShell(), "Confirm delete", message);
//						if (!deleteConfirmed)
//							return;
//
//						MylarTaskListPlugin.getTaskListManager().deleteTask(task);
//						ContextCorePlugin.getContextManager().contextDeleted(task.getHandleIdentifier()); // task.getContextPath());
//					}
				}
			}
		} catch (NullPointerException npe) {
			MylarStatusHandler.fail(npe, "Could not remove task from category, it may still be refreshing.", true);
		}
	}
}<commit_msg>NEW - bug 166609: [api] improve task externalization API https://bugs.eclipse.org/bugs/show_bug.cgi?id=166609<commit_after>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

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

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.mylyn.core.MylarStatusHandler;
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.TaskCategory;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;

/**
 * @author <NAME>
 */
public class RemoveFromCategoryAction extends Action {
	public static final String ID = "org.eclipse.mylyn.tasklist.actions.remove";

	private final TaskListView view;

	public RemoveFromCategoryAction(TaskListView view) {
		this.view = view;
		setText("Remove From Category");
		setId(ID);
		setImageDescriptor(TasksUiImages.REMOVE);
	}

	@Override
	public void run() {
		try {
			ISelection selection = TaskListView.getFromActivePerspective().getViewer().getSelection();
			for (Object selectedObject : ((IStructuredSelection) selection).toList()) {
				if (selectedObject instanceof AbstractTask) { // && !((ITask) selectedObject).isLocal()) {
					AbstractTask task = (AbstractTask) selectedObject;
					if (task.isActive()) {
						MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
								ITasksUiConstants.TITLE_DIALOG,
								"Task must be deactivated in order to remove from category.");
						return;
					}

					TreeItem item = this.view.getViewer().getTree().getSelection()[0];
					if (item.getParentItem() != null && item.getParentItem().getData() instanceof TaskCategory) {
						TaskCategory category = (TaskCategory) item.getParentItem().getData();
						TasksUiPlugin.getTaskListManager().getTaskList().removeFromCategory(category, task);
					} else {
						TasksUiPlugin.getTaskListManager().getTaskList().moveToContainer(task, TasksUiPlugin.getTaskListManager().getTaskList().getArchiveContainer());
					} 
					// just in case, should already be there
//					MylarTaskListPlugin.getTaskListManager().getTaskList().addTaskToArchive(task);
//					ITaskContainer cat = task.getCategory();
//					if (cat != null) {
//						String message = DeleteAction.genDeleteConfirmationMessage(task);
//						boolean deleteConfirmed = MessageDialog.openQuestion(PlatformUI.getWorkbench()
//								.getActiveWorkbenchWindow().getShell(), "Confirm delete", message);
//						if (!deleteConfirmed)
//							return;
//
//						MylarTaskListPlugin.getTaskListManager().deleteTask(task);
//						ContextCorePlugin.getContextManager().contextDeleted(task.getHandleIdentifier()); // task.getContextPath());
//					}
				}
			}
		} catch (NullPointerException npe) {
			MylarStatusHandler.fail(npe, "Could not remove task from category, it may still be refreshing.", true);
		}
	}
}
{'fraction_non_alphanumeric': 0.15748883777567313, 'fraction_numerical': 0.005141388174807198, 'mean_word_length': 4.694915254237288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '6278057', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2026, 'n_words': 421}