diff options
author | relves | 2009-01-15 22:32:03 +0000 |
---|---|---|
committer | relves | 2009-01-15 22:32:03 +0000 |
commit | 606fb2d59740d290fafaa9e161ab5cba929d3976 (patch) | |
tree | 831405cd2f4cbbac102883598b79d55e3508150c /org.eclipse.mylyn.bugzilla.ui | |
parent | 52b4cf06ccf08b84dcc1f21bd6f30e5e4a73b9c3 (diff) | |
download | org.eclipse.mylyn.tasks-606fb2d59740d290fafaa9e161ab5cba929d3976.tar.gz org.eclipse.mylyn.tasks-606fb2d59740d290fafaa9e161ab5cba929d3976.tar.xz org.eclipse.mylyn.tasks-606fb2d59740d290fafaa9e161ab5cba929d3976.zip |
NEW - bug 258717: address remaining nits with mark obsolete functionality
https://bugs.eclipse.org/bugs/show_bug.cgi?id=258717
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.ui')
5 files changed, 140 insertions, 39 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/plugin.xml b/org.eclipse.mylyn.bugzilla.ui/plugin.xml index 1714bc2ec..5ec74b8fe 100644 --- a/org.eclipse.mylyn.bugzilla.ui/plugin.xml +++ b/org.eclipse.mylyn.bugzilla.ui/plugin.xml @@ -78,14 +78,28 @@ id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment" objectClass="org.eclipse.mylyn.tasks.core.ITaskAttachment"> <action - class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaUpdateAttachmentAction" + class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaNotObsoleteAttachmentAction" + enablesFor="*" + id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.notobsolete" + label="Mark not obsolete" + menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions" + tooltip="Mark attachment as not obsolete"> + </action> + <action + class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaObsoleteAttachmentAction" enablesFor="*" id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.obsolete" label="Mark obsolete" - menubarPath="actions" - tooltip="Toggle the attachment as obsolete or not"> + menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions" + tooltip="Mark attachment as obsolete"> </action> + <menu + id="org.eclipse.mylyn.bugzilla.ui.attachments.mark" + label="Mark as" + path="markadditions"> + </menu> </objectContribution> </extension> + </plugin> diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaNotObsoleteAttachmentAction.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaNotObsoleteAttachmentAction.java new file mode 100644 index 000000000..9919b5cbf --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaNotObsoleteAttachmentAction.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.action; + +/** + * @author Frank Becker + */ +public class BugzillaNotObsoleteAttachmentAction extends BugzillaUpdateAttachmentAction { + + public BugzillaNotObsoleteAttachmentAction() { + super(false); + // ignore + } + +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaObsoleteAttachmentAction.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaObsoleteAttachmentAction.java new file mode 100644 index 000000000..c39f1f698 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaObsoleteAttachmentAction.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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.action; + +/** + * @author Frank Becker + */ +public class BugzillaObsoleteAttachmentAction extends BugzillaUpdateAttachmentAction { + + public BugzillaObsoleteAttachmentAction() { + super(true); + } + +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaUpdateAttachmentAction.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaUpdateAttachmentAction.java index 289ddcb22..36ba89b0d 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaUpdateAttachmentAction.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaUpdateAttachmentAction.java @@ -13,9 +13,13 @@ package org.eclipse.mylyn.internal.bugzilla.ui.action; import java.util.List; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; import org.eclipse.mylyn.tasks.core.ITaskAttachment; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; @@ -26,6 +30,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.eclipse.ui.forms.editor.IFormPage; /** * @author Frank Becker @@ -34,12 +39,11 @@ public class BugzillaUpdateAttachmentAction extends BaseSelectionListenerAction private ISelection currentSelection; - public BugzillaUpdateAttachmentAction() { - super("UpdateAttachmentAction"); //$NON-NLS-1$ - } + private final boolean obsolete; - protected BugzillaUpdateAttachmentAction(String text) { - super(text); + public BugzillaUpdateAttachmentAction(boolean obsolete) { + super("UpdateAttachmentAction"); //$NON-NLS-1$ + this.obsolete = obsolete; } public void init(IViewPart view) { @@ -52,7 +56,7 @@ public class BugzillaUpdateAttachmentAction extends BaseSelectionListenerAction IWorkbenchPage page = window.getActivePage(); IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof TaskEditor) { - TaskEditor taskEditor = (TaskEditor) activeEditor; + final TaskEditor taskEditor = (TaskEditor) activeEditor; IStructuredSelection selection = null; if (currentSelection instanceof IStructuredSelection) { selection = (IStructuredSelection) currentSelection; @@ -62,13 +66,32 @@ public class BugzillaUpdateAttachmentAction extends BaseSelectionListenerAction } List<ITaskAttachment> attachment = selection.toList(); if (attachment != null) { - UpdateAttachmentJob job = new UpdateAttachmentJob(attachment, taskEditor); + final UpdateAttachmentJob job = new UpdateAttachmentJob(attachment, taskEditor, obsolete); job.setUser(true); + job.addJobChangeListener(new JobChangeAdapter() { + + @Override + public void done(IJobChangeEvent event) { + if (job.getError() != null) { + IFormPage formPage = taskEditor.getActivePageInstance(); + if (formPage instanceof BugzillaTaskEditorPage) { + final BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage; + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + bugzillaPage.getTaskEditor().setMessage(job.getError().getMessage(), + IMessageProvider.ERROR); + } + }); + } + } + } + }); job.schedule(); } } } + @SuppressWarnings("unchecked") public void selectionChanged(IAction action, ISelection selection) { this.currentSelection = selection; IStructuredSelection sructuredSelection = null; @@ -78,12 +101,16 @@ public class BugzillaUpdateAttachmentAction extends BaseSelectionListenerAction if (sructuredSelection == null || sructuredSelection.isEmpty()) { return; } - TaskAttribute taskAttribute = ((ITaskAttachment) sructuredSelection.getFirstElement()).getTaskAttribute(); - TaskAttribute deprecated = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); - if (deprecated.getValue().equals("1")) { //$NON-NLS-1$ - action.setText(Messages.BugzillaUpdateAttachmentAction_mark_not_obsolete); - } else { - action.setText(Messages.BugzillaUpdateAttachmentAction_mark_obsolete); + List<ITaskAttachment> attachmentList = sructuredSelection.toList(); + action.setEnabled(false); + for (ITaskAttachment taskAttachment : attachmentList) { + TaskAttribute taskAttribute = taskAttachment.getTaskAttribute(); + TaskAttribute deprecated = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); + + if (deprecated.getValue().equals("1") != obsolete) { //$NON-NLS-1$ + action.setEnabled(true); + break; + } } } } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/UpdateAttachmentJob.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/UpdateAttachmentJob.java index bb14891ea..4f4e92fd5 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/UpdateAttachmentJob.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/action/UpdateAttachmentJob.java @@ -13,13 +13,14 @@ package org.eclipse.mylyn.internal.bugzilla.ui.action; import java.util.List; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage; @@ -40,19 +41,28 @@ import org.eclipse.ui.forms.widgets.Section; /** * @author Frank Becker */ +@SuppressWarnings("restriction") public class UpdateAttachmentJob extends Job { private final List<ITaskAttachment> attachment; private final TaskEditor editor; - public UpdateAttachmentJob(List<ITaskAttachment> attachment, TaskEditor editor) { + private final boolean obsolete; + + private IStatus error; + + public UpdateAttachmentJob(List<ITaskAttachment> attachment, TaskEditor editor, boolean obsolete) { super(Messages.UpdateAttachmentJob_update_attachment); this.attachment = attachment; this.editor = editor; + this.obsolete = obsolete; + } + + public IStatus getError() { + return error; } - @SuppressWarnings("restriction") @Override protected IStatus run(IProgressMonitor monitor) { final ITask task; @@ -68,15 +78,30 @@ public class UpdateAttachmentJob extends Job { for (ITaskAttachment taskAttachment : attachment) { TaskAttribute taskAttribute = taskAttachment.getTaskAttribute(); TaskAttribute deprecated = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED); - if (deprecated.getValue().equals("1")) { //$NON-NLS-1$ - deprecated.setValue("0"); //$NON-NLS-1$ - } else { - deprecated.setValue("1"); //$NON-NLS-1$ + if (deprecated.getValue().equals("1") && !obsolete) { //$NON-NLS-1$ + try { + deprecated.setValue("0"); //$NON-NLS-1$ + ((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment( + taskAttachment.getTaskRepository(), taskAttribute, "update", monitor); //$NON-NLS-1$ + } catch (CoreException e) { + error = e.getStatus(); + deprecated.setValue("1"); //$NON-NLS-1$ + return Status.OK_STATUS; + } + } else if (deprecated.getValue().equals("0") && obsolete) { //$NON-NLS-1$ + try { + deprecated.setValue("1"); //$NON-NLS-1$ + ((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment( + taskAttachment.getTaskRepository(), taskAttribute, "update", monitor); //$NON-NLS-1$ + } catch (CoreException e) { + error = e.getStatus(); + deprecated.setValue("0"); //$NON-NLS-1$ + return Status.OK_STATUS; + } } monitor.worked(10); - ((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment( - taskAttachment.getTaskRepository(), taskAttribute, "update", monitor); //$NON-NLS-1$ } + if (task != null) { if (connector != null) { TasksUiInternal.synchronizeTask(connector, task, true, new JobChangeAdapter() { @@ -97,9 +122,6 @@ public class UpdateAttachmentJob extends Job { Section section = (Section) control; EditorUtil.toggleExpandableComposite(true, section); } - bugzillaPage.getTaskEditor().setMessage( - Messages.UpdateAttachmentJob_obsolete_toggled_successfully, - IMessageProvider.INFORMATION); } } @@ -122,17 +144,8 @@ public class UpdateAttachmentJob extends Job { } }); } - } catch (Exception e) { - IFormPage formPage = editor.getActivePageInstance(); - if (formPage instanceof BugzillaTaskEditorPage) { - final BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage; - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - bugzillaPage.getTaskEditor().setMessage(Messages.UpdateAttachmentJob_obsolete_not_toggled, - IMessageProvider.ERROR); - } - }); - } + } catch (OperationCanceledException e) { + return Status.CANCEL_STATUS; } finally { monitor.done(); } |