blob: b3124ddf8c9ee41fd145c3df2d1f134c991405e6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004, 2011 Tasktop Technologies and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.tasks.ui.actions;
import java.util.Set;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.Window;
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
/**
* @author Mik Kersten
*/
public class NewCategoryAction extends Action implements IViewActionDelegate {
public static final String ID = "org.eclipse.mylyn.tasks.ui.actions.create.category"; //$NON-NLS-1$
public NewCategoryAction() {
setText(Messages.NewCategoryAction_New_Category_);
setToolTipText(Messages.NewCategoryAction_New_Category_);
setId(ID);
setImageDescriptor(TasksUiImages.CATEGORY_NEW);
}
public void init(IViewPart view) {
}
public void run(IAction action) {
run();
}
@Override
public void run() {
createCategory();
}
public TaskCategory createCategory() {
InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.NewCategoryAction_Enter_name, Messages.NewCategoryAction_Enter_a_name_for_the_Category,
"", null); //$NON-NLS-1$
int dialogResult = dialog.open();
if (dialogResult == Window.OK) {
String name = dialog.getValue();
Set<RepositoryQuery> queries = TasksUiInternal.getTaskList().getQueries();
Set<AbstractTaskCategory> categories = TasksUiInternal.getTaskList().getCategories();
for (AbstractTaskCategory category : categories) {
if (name != null && name.equals(category.getSummary())) {
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.NewCategoryAction_New_Category,
Messages.NewCategoryAction_A_category_with_this_name_already_exists);
return null;
}
}
for (RepositoryQuery query : queries) {
if (name != null && name.equals(query.getSummary())) {
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
Messages.NewCategoryAction_New_Category,
Messages.NewCategoryAction_A_query_with_this_name_already_exists);
return null;
}
}
TaskCategory category = new TaskCategory(TasksUiPlugin.getTaskList().getUniqueHandleIdentifier(), name);
TasksUiPlugin.getTaskList().addCategory(category);
return category;
}
return null;
}
public void selectionChanged(IAction action, ISelection selection) {
}
}