diff options
author | relves | 2009-02-21 02:05:48 +0000 |
---|---|---|
committer | relves | 2009-02-21 02:05:48 +0000 |
commit | bf9a4cd19062df778fc32b2cebdcd8648643ed94 (patch) | |
tree | 0ad7f70c5e93c652cb2255aa55695295dbde44c3 /org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard | |
parent | 22b12e4425c7b6c8034524e1a0cbb3294c20acb4 (diff) | |
download | org.eclipse.mylyn.tasks-bf9a4cd19062df778fc32b2cebdcd8648643ed94.tar.gz org.eclipse.mylyn.tasks-bf9a4cd19062df778fc32b2cebdcd8648643ed94.tar.xz org.eclipse.mylyn.tasks-bf9a4cd19062df778fc32b2cebdcd8648643ed94.zip |
NEW - bug 219241: convert the New Task toolbar item to be a drop-down menu
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219241
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard')
-rw-r--r-- | org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/NewBugzillaTaskWizard.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/NewBugzillaTaskWizard.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/NewBugzillaTaskWizard.java new file mode 100644 index 000000000..492586434 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/NewBugzillaTaskWizard.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 Tasktop Technologies 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: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui.wizard; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; +import org.eclipse.mylyn.tasks.core.IRepositoryQuery; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.ITaskMapping; +import org.eclipse.mylyn.tasks.core.TaskMapping; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * @author Mik Kersten + * @author Rob Elves + */ +public class NewBugzillaTaskWizard extends NewTaskWizard implements INewWizard { + + private IStructuredSelection selection; + + public NewBugzillaTaskWizard(TaskRepository taskRepository, ITaskMapping taskSelection) { + super(taskRepository, taskSelection); + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + /** + * @since 3.0 + */ + @Override + protected ITaskMapping getInitializationData() { + if (getTaskSelection() != null) { + return getTaskSelection(); + } + + IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench != null) { + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + if (window != null) { + ISelection sel = window.getSelectionService().getSelection(); + if (sel instanceof IStructuredSelection) { + selection = (IStructuredSelection) sel; + } + } + } + if (selection == null) { + return null; + } + + final ArrayList<String> products = new ArrayList<String>(); + + Object element = (selection).getFirstElement(); + if (element instanceof ITask) { + ITask bugzillaTask = (ITask) element; + if (bugzillaTask.getAttribute(BugzillaAttribute.PRODUCT.getKey()) != null) { + products.add(bugzillaTask.getAttribute(BugzillaAttribute.PRODUCT.getKey())); + } + } else { + IRepositoryQuery query = null; + if (element instanceof IRepositoryQuery) { + query = (IRepositoryQuery) element; + } + + if (query != null && query.getConnectorKind().equals(BugzillaCorePlugin.CONNECTOR_KIND)) { + String queryUrl = query.getUrl(); + queryUrl = queryUrl.substring(queryUrl.indexOf("?") + 1); //$NON-NLS-1$ + String[] options = queryUrl.split("&"); //$NON-NLS-1$ + + for (String option : options) { + int index = option.indexOf("="); //$NON-NLS-1$ + if (index != -1) { + String key = option.substring(0, index); + if ("product".equals(key)) { //$NON-NLS-1$ + try { + products.add(URLDecoder.decode(option.substring(index + 1), + getTaskRepository().getCharacterEncoding())); + // TODO: list box only accepts a single selection so + // we break on first found + break; + } catch (UnsupportedEncodingException ex) { + // ignore + } + } + } + } + } else { + if (element instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) element; + ITask task = (ITask) adaptable.getAdapter(ITask.class); + if (task != null) { + ITask bugzillaTask = (ITask) element; + if (bugzillaTask.getAttribute(BugzillaAttribute.PRODUCT.getKey()) != null) { + products.add(bugzillaTask.getAttribute(BugzillaAttribute.PRODUCT.getKey())); + } + } + } + } + } + + if (products.size() > 0) { + return new TaskMapping() { + @Override + public String getProduct() { + return products.get(0); + } + }; + } + return null; + } + +} |