diff options
14 files changed, 166 insertions, 641 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java index 1c4b33f9b..5b4c13174 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTaskDataHandler.java @@ -400,12 +400,15 @@ public class BugzillaTaskDataHandler extends AbstractTaskDataHandler { } if (taskData.isNew()) { - + String product = null; if (initializationData == null) { - return false; + if (repositoryConfiguration.getProducts().size() > 0) { + product = repositoryConfiguration.getProducts().get(0); + } + } else { + product = initializationData.getProduct(); } - String product = initializationData.getProduct(); if (product == null) { return false; } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskEditorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskEditorTest.java index fc2b77d48..7d2f950e7 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskEditorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskEditorTest.java @@ -112,7 +112,7 @@ public class TaskEditorTest extends TestCase { TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(taskRepository); TaskData taskData = new TaskData(mapper, taskRepository.getConnectorKind(), taskRepository.getRepositoryUrl(), ""); - assertFalse(taskDataHandler.initializeTaskData(taskRepository, taskData, null, null)); + //assertFalse(taskDataHandler.initializeTaskData(taskRepository, taskData, null, null)); assertFalse(taskDataHandler.initializeTaskData(taskRepository, taskData, taskMappingInit, null)); assertTrue(taskDataHandler.initializeTaskData(taskRepository, taskData, taskMappingSelect, null)); } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java index 32894c913..0165b9343 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java @@ -26,7 +26,6 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin; @@ -223,18 +222,8 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage { @Override protected TaskDataModel createModel(TaskEditorInput input) throws CoreException { TaskDataModel model = super.createModel(input); - BugzillaVersion bugzillaVersion = null; - RepositoryConfiguration repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration( - input.getTaskRepository(), false, new NullProgressMonitor()); - if (repositoryConfiguration != null) { - bugzillaVersion = repositoryConfiguration.getInstallVersion(); - } else { - bugzillaVersion = BugzillaVersion.MIN_VERSION; - } - if (bugzillaVersion.compareTo(BugzillaVersion.BUGZILLA_3_0) >= 0) { - productListener = new ProductSelectionListener(); - model.addModelListener(productListener); - } + productListener = new ProductSelectionListener(); + model.addModelListener(productListener); return model; } @@ -255,7 +244,7 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage { return attributeEditorMap.get(attribute); } - public void refresh(TaskAttribute attributeComponent) { + private void refresh(TaskAttribute attributeComponent) { AbstractAttributeEditor editor = getEditorForAttribute(attributeComponent); if (editor != null) { try { diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java index 70fab643d..5147f0601 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java @@ -30,7 +30,6 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaImages; import org.eclipse.mylyn.internal.bugzilla.ui.search.BugzillaSearchPage; -import org.eclipse.mylyn.internal.bugzilla.ui.wizard.NewBugzillaTaskWizard; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.ITaskComment; @@ -42,6 +41,7 @@ import org.eclipse.mylyn.tasks.ui.LegendElement; import org.eclipse.mylyn.tasks.ui.TaskHyperlink; import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage; import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage; +import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard; import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard; /** @@ -150,7 +150,7 @@ public class BugzillaConnectorUi extends AbstractRepositoryConnectorUi { @Override public IWizard getNewTaskWizard(TaskRepository taskRepository, ITaskMapping selection) { - return new NewBugzillaTaskWizard(taskRepository, selection); + return new NewTaskWizard(taskRepository, selection); } @Override diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java deleted file mode 100644 index 6e55e01f1..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java +++ /dev/null @@ -1,472 +0,0 @@ -/******************************************************************************* - * 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 - * Eugene Kuleshov - improvements - * Willian Mitsuda - improvements - *******************************************************************************/ - -package org.eclipse.mylyn.internal.bugzilla.ui.wizard; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.InvocationTargetException; -import java.net.URLDecoder; -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.IOpenListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.OpenEvent; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; -import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; -import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; -import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.FilteredTree; -import org.eclipse.ui.dialogs.PatternFilter; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.ui.progress.UIJob; - -/** - * Product selection page of new bug wizard - * - * @author Shawn Minto - * @author Rob Elves - * @author Mik Kersten - */ -public class BugzillaProductPage extends WizardPage { - - private static final String NEW_BUGZILLA_TASK_ERROR_TITLE = Messages.BugzillaProductPage_New_Bugzilla_Task_Error; - - private static final String DESCRIPTION = Messages.BugzillaProductPage_PICK_PRODUCT_TO_OPEN_NEW_BUG_EDITOR - + Messages.BugzillaProductPage_PRESS_UPDATE_BUTTON; - - private static final String LABEL_UPDATE = Messages.BugzillaProductPage_Update_Products_from_Repository; - - /** The list of products to submit a bug report for */ - private List<String> products = null; - - /** - * Handle product selection - */ - private FilteredTree productList; - - private final TaskRepository repository; - - protected IPreferenceStore prefs = BugzillaUiPlugin.getDefault().getPreferenceStore(); - - /** - * Constructor for BugzillaProductPage - * - * @param repository - * The repository the data is coming from - * @param workbench - * The instance of the workbench - * @param selection - */ - public BugzillaProductPage(TaskRepository repository) { - super(Messages.BugzillaProductPage_PAGE_1); - setTitle(IBugzillaConstants.TITLE_NEW_BUG); - setDescription(DESCRIPTION); - this.repository = repository; - setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.mylyn.bugzilla.ui", //$NON-NLS-1$ - "icons/wizban/bug-wizard.gif")); //$NON-NLS-1$ - - } - - private class ComponentFilter extends PatternFilter { - - @Override - public void setPattern(String patternString) { - // ignore - super.setPattern(patternString); - // HACK: waiting on delayed refresh of filtered tree after setting the new pattern - new UIJob("") { //$NON-NLS-1$ - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - if (BugzillaProductPage.this.getControl() != null - && BugzillaProductPage.this.getControl().isDisposed()) { - return Status.OK_STATUS; - } - final TreeViewer productViewer = productList.getViewer(); - if (productViewer.getTree().getItemCount() == 1) { - TreeItem aq = productViewer.getTree().getItem(0); - String qq = aq.getText(); - productViewer.setSelection(new StructuredSelection(qq)); - } - return Status.OK_STATUS; - } - }.schedule(300L); - - } - } - - @SuppressWarnings("deprecation") - public void createControl(Composite parent) { - // create the composite to hold the widgets - Composite composite = new Composite(parent, SWT.NULL); - - // create the desired layout for this wizard page - composite.setLayout(new GridLayout()); - - // create the list of bug reports - // TODO e3.5 move to new FilteredTree API - productList = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER, new ComponentFilter()); - productList.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint( - SWT.DEFAULT, 200).create()); - final TreeViewer productViewer = productList.getViewer(); - productViewer.setLabelProvider(new LabelProvider()); - productViewer.setContentProvider(new ITreeContentProvider() { - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof Collection<?>) { - return ((Collection<?>) parentElement).toArray(); - } - return null; - } - - public Object getParent(Object element) { - return null; - } - - public boolean hasChildren(Object element) { - return false; - } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }); - - productViewer.addOpenListener(new IOpenListener() { - public void open(OpenEvent event) { - if (getWizard().canFinish()) { - if (getWizard().performFinish()) { - ((WizardDialog) getContainer()).close(); - } - } - } - }); - - initProducts(); - productViewer.setInput(products); - productViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - // Initialize a variable with the no error status - Status status = new Status(IStatus.OK, BugzillaUiPlugin.ID_PLUGIN, 0, "", null); //$NON-NLS-1$ - if (productViewer.getSelection().isEmpty()) { - status = new Status(IStatus.ERROR, BugzillaUiPlugin.ID_PLUGIN, 0, - Messages.BugzillaProductPage_YOU_MUST_SELECT_PRODUCT, null); - } - - // Show the most serious error - applyToStatusLine(status); - isPageComplete(); - getWizard().getContainer().updateButtons(); - } - - }); - - // HACK: waiting on delayed refresh of filtered tree - final String[] selectedProducts = getSelectedProducts(); - if (selectedProducts.length > 0) { - new UIJob("") { //$NON-NLS-1$ - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - if (BugzillaProductPage.this.getControl() != null - && BugzillaProductPage.this.getControl().isDisposed()) { - return Status.OK_STATUS; - } - productViewer.setSelection(new StructuredSelection(selectedProducts), true); - productViewer.getControl().setFocus(); - return Status.OK_STATUS; - } - }.schedule(300L); - } else { - productList.setFocus(); - } - - Button updateButton = new Button(composite, SWT.LEFT | SWT.PUSH); - updateButton.setText(LABEL_UPDATE); - updateButton.setLayoutData(new GridData()); - - updateButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - updateProdcts(); - productViewer.setInput(products); - } - }); - - Dialog.applyDialogFont(composite); - // set the composite as the control for this page - setControl(composite); - - isPageComplete(); - getWizard().getContainer().updateButtons(); - } - - private void initProducts() { - // try to get the list of products from the server - try { - products = BugzillaCorePlugin.getRepositoryConfiguration(repository, false, new NullProgressMonitor()) - .getProducts(); - - if (products.isEmpty()) { - updateProdcts(); - } - - } catch (final CoreException e) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(Display.getDefault().getActiveShell(), NEW_BUGZILLA_TASK_ERROR_TITLE, - Messages.BugzillaProductPage_Unable_to_get_products); - } - }); - } - } - - private String[] getSelectedProducts() { - IStructuredSelection selection = getSelection(); - if (selection == null) { - return new String[0]; - } - - 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), - repository.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())); - } - } - } - } - } - - return products.toArray(new String[products.size()]); - } - - private IStructuredSelection getSelection() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ISelection selection = window.getSelectionService().getSelection(); - if (selection instanceof IStructuredSelection) { - return (IStructuredSelection) selection; - } - return null; - } - - /** - * Applies the status to the status line of a dialog page. - * - * @param status - * The status to apply to the status line - */ - protected void applyToStatusLine(IStatus status) { - String message = status.getMessage(); - if (message.length() == 0) { - message = null; - } - switch (status.getSeverity()) { - case IStatus.OK: - setErrorMessage(null); - setMessage(message); - break; - case IStatus.WARNING: - setErrorMessage(null); - setMessage(message, IMessageProvider.WARNING); - break; - case IStatus.INFO: - setErrorMessage(null); - setMessage(message, IMessageProvider.INFORMATION); - break; - default: - setErrorMessage(null); - setMessage(message, IMessageProvider.ERROR); - break; - } - } - -// /** -// * Save the currently selected product to the taskData when next is clicked -// */ -// public void saveDataToModel() throws CoreException { -// RepositoryTaskData model = bugWizard.taskData; -// model.setAttributeValue(BugzillaReportElement.PRODUCT.getKey(), getSelectedProduct()); -// AbstractLegacyRepositoryConnector connector = (AbstractLegacyRepositoryConnector) TasksUi.getRepositoryManager() -// .getRepositoryConnector(repository.getConnectorKind()); -// if (connector == null) { -// throw new CoreException(new Status(IStatus.ERROR, BugzillaUiPlugin.PLUGIN_ID, -// "Error AbstractRepositoryConnector could not been retrieved.\n\n")); -// } -// AbstractTaskDataHandler taskDataHandler = connector.getLegacyTaskDataHandler(); -// if (taskDataHandler == null) { -// throw new CoreException(new Status(IStatus.ERROR, BugzillaUiPlugin.PLUGIN_ID, -// "Error AbstractTaskDataHandler could not been retrieved.\n\n")); -// } -// taskDataHandler.initializeTaskData(repository, model, null); -// -// // platform/os are now set to All/All -// BugzillaCorePlugin.getDefault().setPlatformDefaultsOrGuess(repository, model); -// } - - public String getSelectedProduct() { - return (String) ((IStructuredSelection) productList.getViewer().getSelection()).getFirstElement(); - } - - @Override - public boolean isPageComplete() { - return !productList.getViewer().getSelection().isEmpty(); -// return bugWizard.completed; - } - - private void updateProdcts() { - final AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( - repository.getConnectorKind()); - try { - getContainer().run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask(Messages.BugzillaProductPage_Updating_repository_report_options_, - IProgressMonitor.UNKNOWN); - try { - connector.updateRepositoryConfiguration(repository, monitor); - } catch (CoreException e) { - // TODO: remove exceptions from communication of connectivity errors to the user - if (e.getStatus().getException() instanceof GeneralSecurityException) { - StatusHandler.fail(new Status(IStatus.WARNING, BugzillaUiPlugin.ID_PLUGIN, - "Bugzilla could not log you in to get the information you requested since login name or password is incorrect.\n" //$NON-NLS-1$ - + "Please ensure your task repository is properly configured.", e)); //$NON-NLS-1$ - } else if (e.getStatus().getException() instanceof IOException) { - StatusHandler.fail(new Status(IStatus.WARNING, BugzillaUiPlugin.ID_PLUGIN, - "Connection Error, please ensure your task repository is properly configured.", e)); //$NON-NLS-1$ - } else { - StatusHandler.fail(new Status(IStatus.WARNING, BugzillaUiPlugin.ID_PLUGIN, - "Error updating repository attributes for " + repository.getRepositoryUrl(), e)); //$NON-NLS-1$ - } - return; - } - - RepositoryConfiguration repositoryConfiguration = null; - try { - repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(repository, false, - monitor); - } catch (final CoreException e) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(Display.getDefault().getActiveShell(), - Messages.BugzillaProductPage_Bugzilla_Search_Page, - Messages.BugzillaProductPage_Unable_to_get_configuration); - } - }); - } - products = new ArrayList<String>(); - if (repositoryConfiguration != null) { - for (String product : repositoryConfiguration.getProducts()) { - products.add(product); - } - } - } - }); - - } catch (InvocationTargetException ex) { - MessageDialog.openError(null, Messages.BugzillaProductPage_Error_updating_product_list, - Messages.BugzillaProductPage_Error_reported + ex.getCause().getMessage()); - } catch (InterruptedException ex) { - // canceled - } - } - -} 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 deleted file mode 100644 index 8964faa7d..000000000 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/NewBugzillaTaskWizard.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * 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 org.eclipse.jface.viewers.IStructuredSelection; -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; - -/** - * @author Mik Kersten - * @author Rob Elves - */ -public class NewBugzillaTaskWizard extends NewTaskWizard implements INewWizard { - - private BugzillaProductPage projectPage; - - public NewBugzillaTaskWizard(TaskRepository taskRepository, ITaskMapping taskSelection) { - super(taskRepository, taskSelection); - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - } - - @Override - public void addPages() { - projectPage = new BugzillaProductPage(getTaskRepository()); - addPage(projectPage); - } - - @Override - protected ITaskMapping getInitializationData() { - final String product = projectPage.getSelectedProduct(); - return new TaskMapping() { - @Override - public String getProduct() { - return product; - } - }; - } - -// private static final String TITLE = "New Bugzilla Task"; -// -// private IWorkbench workbenchInstance; -// -// private final TaskRepository repository; -// -// private final BugzillaProductPage productPage; -// -// /** -// * Flag to indicate if the wizard can be completed (finish button enabled) -// */ -// protected boolean completed = false; -// -// /** The taskData used to store all of the data for the wizard */ -// protected RepositoryTaskData taskData; -// -// private TaskSelection taskSelection; -// -// // TODO: Change taskData to a RepositoryTaskData -// // protected RepositoryTaskData taskData; -// -// public NewBugzillaTaskWizard(TaskRepository repository) { -// this(false, repository); -// taskData = new TaskData(new BugzillaAttributeFactory(), BugzillaCorePlugin.CONNECTOR_KIND, -// repository.getRepositoryUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId()); -// taskData.setNew(true); -// super.setDefaultPageImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( -// "org.eclipse.mylyn.internal.bugzilla.ui", "icons/wizban/bug-wizard.gif")); -// super.setWindowTitle(TITLE); -// setNeedsProgressMonitor(true); -// } -// -// public NewBugzillaTaskWizard(boolean fromDialog, TaskRepository repository) { -// super(); -// this.repository = repository; -// this.productPage = new BugzillaProductPage(workbenchInstance, this, repository); -// } -// -// /** -// * @since 2.2 -// */ -// public NewBugzillaTaskWizard(TaskRepository taskRepository, TaskSelection taskSelection) { -// this(taskRepository); -// this.taskSelection = taskSelection; -// } -// -// @Override -// public void init(IWorkbench workbench, IStructuredSelection selection) { -// this.workbenchInstance = workbench; -// } -// -// @Override -// public void addPages() { -// super.addPages(); -// addPage(productPage); -// } -// -// @Override -// public boolean canFinish() { -// return completed; -// } -// -// @Override -// public boolean performFinish() { -// try { -// productPage.saveDataToModel(); -// -// if (taskSelection != null) { -// AbstractRepositoryConnector connector = TasksUi.getRepositoryManager() -// .getRepositoryConnector(repository.getConnectorKind()); -// AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); -// if (taskDataHandler != null) { -// taskDataHandler.cloneTaskData(taskSelection.getLegacyTaskData(), taskData); -// } -// } -// -// NewTaskEditorInput editorInput = new NewTaskEditorInput(repository, taskData); -// IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); -// TasksUiUtil.openEditor(editorInput, TaskEditor.ID_EDITOR, page); -// return true; -// } catch (Exception e) { -// Status status = new Status(IStatus.ERROR, "not_used", 0, -// "Problem occurred retrieving repository configuration from " + repository.getRepositoryUrl(), e) -// productPage.applyToStatusLine(status); -// StatusHandler.log(status); -// } -// return false; -// } -} diff --git a/org.eclipse.mylyn.tasks.ui/plugin.xml b/org.eclipse.mylyn.tasks.ui/plugin.xml index 83ecb0d3f..0ee2398e2 100644 --- a/org.eclipse.mylyn.tasks.ui/plugin.xml +++ b/org.eclipse.mylyn.tasks.ui/plugin.xml @@ -285,7 +285,7 @@ menubarPath="tasks"> </action> - <action + <!-- <action class="org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction" enablesFor="*" icon="icons/etool16/task-new.gif" @@ -294,7 +294,7 @@ style="push" toolbarPath="new" tooltip="%NewTaskAction.tooltip"> - </action> + </action>--> <action class="org.eclipse.mylyn.internal.tasks.ui.actions.ShowTasksUiLegendAction" icon="icons/etool16/icons-legend.gif" diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java index cbfb56728..1a703982b 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/Messages.java @@ -139,6 +139,10 @@ public class Messages extends NLS { public static String TasksUiUtil_Could_not_open_URL_; + public static String TasksUiUtil_create_task; + + public static String TasksUiUtil_failed_to_create_new_task; + public static String TasksUiUtil_No_URL_to_open; public static String AbstractRetrieveTitleFromUrlJob_Retrieving_summary_from_URL; diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/Messages.java index 513a375e7..0a329f76b 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/Messages.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/Messages.java @@ -159,6 +159,8 @@ public class Messages extends NLS { public static String NewSubTaskAction_Unable_to_create_subtask; + public static String NewTaskAction_new_task; + public static String NewTaskFromSelectionAction_Comment_; public static String NewTaskFromSelectionAction____Created_from_Comment___; diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewTaskAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewTaskAction.java index 53f5dd0f8..f66932442 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewTaskAction.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewTaskAction.java @@ -9,23 +9,45 @@ package org.eclipse.mylyn.internal.tasks.ui.actions; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.mylyn.internal.commons.ui.CompositeElementImageDescriptor; +import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector; +import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; +import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.mylyn.tasks.ui.TasksUiUtil; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.BaseSelectionListenerAction; /** * @author Mik Kersten * @author Eugene Kuleshov * @author Steffen Pingel + * @author Rob Elves */ -public class NewTaskAction extends Action implements IViewActionDelegate, IExecutableExtension { +@SuppressWarnings("restriction") +public class NewTaskAction extends BaseSelectionListenerAction implements IMenuCreator, IViewActionDelegate, + IExecutableExtension { + + private static final String LABEL_NEW_TASK = Messages.NewTaskAction_new_task; public static final String ID = "org.eclipse.mylyn.tasklist.ui.repositories.actions.create"; //$NON-NLS-1$ @@ -33,6 +55,18 @@ public class NewTaskAction extends Action implements IViewActionDelegate, IExecu private boolean localTask = false; + private Menu dropDownMenu; + + public NewTaskAction() { + super(LABEL_NEW_TASK); + setMenuCreator(this); + setText(LABEL_NEW_TASK); + setToolTipText(LABEL_NEW_TASK); + setId(ID); + setEnabled(true); + setImageDescriptor(TasksUiImages.TASK_NEW); + } + @Override public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); @@ -69,4 +103,105 @@ public class NewTaskAction extends Action implements IViewActionDelegate, IExecu } } + public void dispose() { + if (dropDownMenu != null) { + dropDownMenu.dispose(); + dropDownMenu = null; + } + } + + public Menu getMenu(Control parent) { + if (dropDownMenu != null) { + dropDownMenu.dispose(); + } + dropDownMenu = new Menu(parent); + addActionsToMenu(); + return dropDownMenu; + } + + public Menu getMenu(Menu parent) { + if (dropDownMenu != null) { + dropDownMenu.dispose(); + } + dropDownMenu = new Menu(parent); + addActionsToMenu(); + return dropDownMenu; + } + + private void addActionsToMenu() { + + TaskRepository localRepository = TasksUi.getRepositoryManager().getRepository( + LocalRepositoryConnector.CONNECTOR_KIND, LocalRepositoryConnector.REPOSITORY_URL); + + if (localRepository != null) { + RepositorySelectionAction action = addRepositoryAction(localRepository); + if (action != null) { + action.setChecked(true); + new Separator(LocalRepositoryConnector.CONNECTOR_KIND).fill(dropDownMenu, -1); + } + } + IWorkingSet workingSet = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .getAggregateWorkingSet(); + if (workingSet != null && !workingSet.isEmpty()) { + // only add repositories in working set + for (IAdaptable iterable_element : workingSet.getElements()) { + if (iterable_element instanceof RepositoryQuery) { + String repositoryUrl = ((RepositoryQuery) iterable_element).getRepositoryUrl(); + String connectorKind = ((RepositoryQuery) iterable_element).getConnectorKind(); + TaskRepository repository = TasksUi.getRepositoryManager().getRepository(connectorKind, + repositoryUrl); + if (repository != null && !repository.isOffline()) { + addRepositoryAction(repository); + } + + } + } + } else { + // add all repositories + for (TaskRepository repository : TasksUi.getRepositoryManager().getAllRepositories()) { + if (repository != null && !repository.isOffline() + && !repository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND)) { + addRepositoryAction(repository); + } + } + } + } + + private RepositorySelectionAction addRepositoryAction(TaskRepository repository) { + if (repository == null) { + return null; + } + RepositorySelectionAction action = new RepositorySelectionAction(repository); + ActionContributionItem item = new ActionContributionItem(action); + action.setText(repository.getRepositoryLabel()); + ImageDescriptor overlay = TasksUiPlugin.getDefault().getOverlayIcon(repository.getConnectorKind()); + CompositeImageDescriptor compositeDescriptor = new CompositeElementImageDescriptor(TasksUiImages.REPOSITORY, + overlay, true); + action.setImageDescriptor(compositeDescriptor); + item.fill(dropDownMenu, -1); + return action; + } + + private class RepositorySelectionAction extends Action { + + private final TaskRepository repository; + + public RepositorySelectionAction(TaskRepository repository) { + this.repository = repository; + setText(repository.getRepositoryLabel()); + } + + @Override + public void run() { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + if (repository.getConnectorKind().equalsIgnoreCase(LocalRepositoryConnector.CONNECTOR_KIND)) { + TasksUiUtil.openNewLocalTaskEditor(shell, null); + } else { + TasksUiUtil.openNewTaskEditor(shell, null, repository); + } + } + } + } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/messages.properties index a2ac6421d..e63061dd6 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/messages.properties +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/messages.properties @@ -86,6 +86,7 @@ NewSubTaskAction_Failed_to_create_new_sub_task_=Failed to create new sub task: NewSubTaskAction_Subtask=Subtask NewSubTaskAction_Unable_to_create_subtask=Unable to create subtask +NewTaskAction_new_task=New Task NewTaskFromSelectionAction_Comment_=Comment\:\ NewTaskFromSelectionAction____Created_from_Comment___=-- Created from Comment -- NewTaskFromSelectionAction_New_Task_from_Selection=New Task from Selection diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties index efcd90cb2..75471b50e 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/messages.properties @@ -79,6 +79,8 @@ TaskHyperlink_Open_Task_X_in_X=Open Task {0} in {1} TasksUiUtil_Browser_could_not_be_initiated=Browser could not be initiated TasksUiUtil_Browser_init_error=Browser init error TasksUiUtil_Could_not_open_URL_=Could not open URL: +TasksUiUtil_create_task=Create Task +TasksUiUtil_failed_to_create_new_task=Failed to create new task:\n\n TasksUiUtil_No_URL_to_open=No URL to open. AbstractRetrieveTitleFromUrlJob_Retrieving_summary_from_URL=Retrieving summary from URL diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java index 3bef3d545..3164edab1 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java @@ -90,6 +90,7 @@ import org.eclipse.mylyn.internal.tasks.ui.actions.GoIntoAction; import org.eclipse.mylyn.internal.tasks.ui.actions.GoUpAction; import org.eclipse.mylyn.internal.tasks.ui.actions.GroupSubTasksAction; import org.eclipse.mylyn.internal.tasks.ui.actions.LinkWithEditorAction; +import org.eclipse.mylyn.internal.tasks.ui.actions.NewTaskAction; import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTaskListElementAction; import org.eclipse.mylyn.internal.tasks.ui.actions.OpenTasksUiPreferencesAction; import org.eclipse.mylyn.internal.tasks.ui.actions.OpenWithBrowserAction; @@ -398,6 +399,8 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener, I private PresentationDropDownSelectionAction presentationDropDownSelectionAction; + private NewTaskAction newTaskAction; + private LinkWithEditorAction linkWithEditorAction; private final TaskPriorityFilter filterPriority = new TaskPriorityFilter(); @@ -1258,7 +1261,7 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener, I } private void fillLocalToolBar(IToolBarManager manager) { - manager.add(new Separator(ID_SEPARATOR_NEW)); + manager.add(newTaskAction); manager.add(presentationDropDownSelectionAction); manager.add(new Separator()); manager.add(collapseAll); @@ -1490,7 +1493,8 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener, I filterOnPriorityAction = new PriorityDropDownAction(this); linkWithEditorAction = new LinkWithEditorAction(this); presentationDropDownSelectionAction = new PresentationDropDownSelectionAction(this); - + newTaskAction = new NewTaskAction(); + filteredTree.getViewer().addSelectionChangedListener(newTaskAction); filteredTree.getViewer().addSelectionChangedListener(openWithBrowser); filteredTree.getViewer().addSelectionChangedListener(copyDetailsAction); } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java index 4e39e4ed0..b07304e77 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java @@ -460,7 +460,7 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage implements ISe } public AbstractTaskEditorPage(TaskEditor editor, String connectorKind) { - this(editor, connectorKind, connectorKind + "-id", "label"); //$NON-NLS-1$ //$NON-NLS-2$ + this(editor, connectorKind + "-id", "label", connectorKind); //$NON-NLS-1$ //$NON-NLS-2$ } /** |