diff options
author | fbecker | 2011-01-21 20:45:26 +0000 |
---|---|---|
committer | fbecker | 2011-01-21 20:45:26 +0000 |
commit | aab530b8ef016f32097a61f5886b3dcda7ffce40 (patch) | |
tree | 567a2f2e92b687556aff9c10dcdc4a01ded0f701 | |
parent | a75aaee8ab91132643256e3f76a60a3b5343a2bd (diff) | |
download | org.eclipse.mylyn.tasks-aab530b8ef016f32097a61f5886b3dcda7ffce40.tar.gz org.eclipse.mylyn.tasks-aab530b8ef016f32097a61f5886b3dcda7ffce40.tar.xz org.eclipse.mylyn.tasks-aab530b8ef016f32097a61f5886b3dcda7ffce40.zip |
ASSIGNED - bug 199283: [patch] [api] make attachments actionable from associated comment in task editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=199283
8 files changed, 267 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/Messages.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/Messages.java index f872cf823..fd0c68360 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/Messages.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/Messages.java @@ -16,7 +16,9 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.bugzilla.ui.messages"; //$NON-NLS-1$ - public static String TaskAttachmentHyperlink_Open_Attachment_X_in_X; + public static String TaskAttachmentHyperlink_Open_Attachment_X_in_Y; + + public static String TaskAttachmentTableEditorHyperlink_Show_Attachment_X_in_Y; static { // initialize resource bundle diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentHyperlink.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentHyperlink.java index c3e9f6651..e36251e7e 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentHyperlink.java +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentHyperlink.java @@ -43,7 +43,7 @@ public final class TaskAttachmentHyperlink implements IHyperlink { } public String getHyperlinkText() { - return MessageFormat.format(Messages.TaskAttachmentHyperlink_Open_Attachment_X_in_X, attachmentId, + return MessageFormat.format(Messages.TaskAttachmentHyperlink_Open_Attachment_X_in_Y, attachmentId, repository.getRepositoryLabel()); } diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentTableEditorHyperlink.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentTableEditorHyperlink.java new file mode 100644 index 000000000..f1cee49d4 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/TaskAttachmentTableEditorHyperlink.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2010 Frank Becker 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: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.bugzilla.ui; + +import java.text.MessageFormat; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.hyperlink.IHyperlink; +import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.ui.TasksUiUtil; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; +import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.editor.IFormPage; + +/** + * @since 3.2 + */ +public final class TaskAttachmentTableEditorHyperlink implements IHyperlink { + + private final IRegion region; + + private final TaskRepository repository; + + private final String attachmentId; + + public TaskAttachmentTableEditorHyperlink(IRegion region, TaskRepository repository, String attachmentId) { + Assert.isNotNull(repository); + this.region = region; + this.repository = repository; + this.attachmentId = attachmentId; + } + + public IRegion getHyperlinkRegion() { + return region; + } + + public String getHyperlinkText() { + return MessageFormat.format(Messages.TaskAttachmentTableEditorHyperlink_Show_Attachment_X_in_Y, attachmentId, + repository.getRepositoryLabel()); + } + + public String getTypeLabel() { + return null; + } + + public void open() { + AbstractTaskEditorPage page = getTaskEditorPage(); + if (page != null) { + if (!page.selectReveal(TaskAttribute.PREFIX_ATTACHMENT + attachmentId)) { + String url = repository.getUrl() + IBugzillaConstants.URL_GET_ATTACHMENT_SUFFIX + attachmentId; + TasksUiUtil.openUrl(url); + } + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((attachmentId == null) ? 0 : attachmentId.hashCode()); + result = prime * result + ((region == null) ? 0 : region.hashCode()); + result = prime * result + ((repository == null) ? 0 : repository.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TaskAttachmentTableEditorHyperlink other = (TaskAttachmentTableEditorHyperlink) obj; + if (attachmentId == null) { + if (other.attachmentId != null) { + return false; + } + } else if (!attachmentId.equals(other.attachmentId)) { + return false; + } + if (region == null) { + if (other.region != null) { + return false; + } + } else if (!region.equals(other.region)) { + return false; + } + if (repository == null) { + if (other.repository != null) { + return false; + } + } else if (!repository.equals(other.repository)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "TaskAttachmentHyperlink [attachmentId=" + attachmentId + ", region=" + region + ", repository=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + repository + "]"; //$NON-NLS-1$ + } + + protected AbstractTaskEditorPage getTaskEditorPage() { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (activePage == null) { + return null; + } + IEditorPart editorPart = activePage.getActiveEditor(); + AbstractTaskEditorPage taskEditorPage = null; + if (editorPart instanceof TaskEditor) { + TaskEditor taskEditor = (TaskEditor) editorPart; + IFormPage formPage = taskEditor.getActivePageInstance(); + if (formPage instanceof AbstractTaskEditorPage) { + taskEditorPage = (AbstractTaskEditorPage) formPage; + } + } + return taskEditorPage; + } + +} diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/messages.properties b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/messages.properties index 7e566285a..982593a44 100644 --- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/messages.properties +++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/messages.properties @@ -8,4 +8,5 @@ # Contributors: # Tasktop Technologies - initial API and implementation ############################################################################### -TaskAttachmentHyperlink_Open_Attachment_X_in_X=Open Attachment {0} in {1}
\ No newline at end of file +TaskAttachmentHyperlink_Open_Attachment_X_in_Y=Open Attachment {0} in {1} +TaskAttachmentTableEditorHyperlink_Show_Attachment_X_in_Y=Show Attachment {0} in {1} 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 7f7321257..ad6bbea91 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 @@ -19,6 +19,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.hyperlink.IHyperlink; @@ -30,6 +31,7 @@ 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.TaskAttachmentHyperlink; +import org.eclipse.mylyn.internal.bugzilla.ui.TaskAttachmentTableEditorHyperlink; 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; @@ -45,6 +47,8 @@ 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.RepositoryQueryWizard; +import org.osgi.framework.Bundle; +import org.osgi.framework.Version; /** * @author Mik Kersten @@ -65,6 +69,22 @@ public class BugzillaConnectorUi extends AbstractRepositoryConnectorUi { private static final Pattern PATTERN_ATTACHMENT = Pattern.compile(REGEXP_ATTACHMENT, Pattern.CASE_INSENSITIVE); + /* + * because of bug# 322293 (NPE when select Hyperlink from MultipleHyperlinkPresenter List) + * for MacOS we enable this only if running on Eclipse >= "3.7.0.v201101192000" + * + */ + private final boolean doAttachmentTableEditorHyperlink; + + public BugzillaConnectorUi() { + super(); + Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$ + String versionString = bundle.getHeaders().get("Bundle-Version"); //$NON-NLS-1$ + + Version version = new Version(versionString); + doAttachmentTableEditorHyperlink = version.compareTo(new Version("3.7.0.v201101192000")) >= 0; //$NON-NLS-1$ + } + @Override public String getAccountCreationUrl(TaskRepository taskRepository) { return taskRepository.getRepositoryUrl() + "/createaccount.cgi"; //$NON-NLS-1$ @@ -220,11 +240,14 @@ public class BugzillaConnectorUi extends AbstractRepositoryConnectorUi { if (index == -1 || (index >= ma.start() && index <= ma.end())) { // attachment Region region = new Region(textOffset + ma.start(), ma.end() - ma.start()); - TaskAttachmentHyperlink link = new TaskAttachmentHyperlink(region, repository, ma.group(1)); + TaskAttachmentHyperlink link0 = new TaskAttachmentHyperlink(region, repository, ma.group(1)); if (hyperlinksFound == null) { hyperlinksFound = new ArrayList<IHyperlink>(); } - hyperlinksFound.add(link); + hyperlinksFound.add(link0); + if (doAttachmentTableEditorHyperlink) { + hyperlinksFound.add(new TaskAttachmentTableEditorHyperlink(region, repository, ma.group(1))); + } } } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java index 8a0327815..eb924c988 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java @@ -33,6 +33,7 @@ import org.eclipse.jface.viewers.OpenEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.window.ToolTip; +import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFormUtil; import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; import org.eclipse.mylyn.internal.provisional.commons.ui.TableSorter; import org.eclipse.mylyn.internal.provisional.commons.ui.TableViewerSupport; @@ -56,10 +57,14 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.events.ExpansionAdapter; import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.forms.widgets.Section; /** @@ -117,6 +122,8 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart { private Composite attachmentsComposite; + private Table attachmentsTable; + public TaskEditorAttachmentPart() { setPartName(Messages.TaskEditorAttachmentPart_Attachments); } @@ -315,4 +322,46 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart { // canceled } } + + @Override + public boolean setFormInput(Object input) { + if (input instanceof String) { + String text = (String) input; + if (attachments != null) { + for (TaskAttribute attachmentAttribute : attachments) { + if (text.equals(attachmentAttribute.getId())) { + CommonFormUtil.setExpanded((ExpandableComposite) getControl(), true); + + return selectReveal(attachmentAttribute); + } + } + } + } + return super.setFormInput(input); + } + + public boolean selectReveal(TaskAttribute attachmentAttribute) { + if (attachmentAttribute == null || attachmentsTable == null) { + return false; + } + TableItem[] attachments = attachmentsTable.getItems(); + int index = 0; + for (TableItem attachment : attachments) { + Object data = attachment.getData(); + if (data instanceof ITaskAttachment) { + ITaskAttachment attachmentData = ((ITaskAttachment) data); + if (attachmentData.getTaskAttribute().getValue().equals(attachmentAttribute.getValue())) { + attachmentsTable.deselectAll(); + attachmentsTable.select(index); + IManagedForm mform = getManagedForm(); + ScrolledForm form = mform.getForm(); + EditorUtil.focusOn(form, attachmentsTable); + return true; + } + } + index++; + } + return false; + } + } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorOutlineNode.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorOutlineNode.java index badcedf59..b0ec29331 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorOutlineNode.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorOutlineNode.java @@ -31,6 +31,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskRelation; +import org.eclipse.mylyn.tasks.core.data.TaskRelation.Direction; import org.eclipse.mylyn.tasks.ui.TasksUi; import org.eclipse.osgi.util.NLS; @@ -144,6 +145,12 @@ public class TaskEditorOutlineNode { label = NLS.bind(Messages.TaskEditorOutlineNode_TaskRelation_Label, new Object[] { taskRelation.getTaskId(), Messages.TaskEditorOutlineNode_unknown_Label }); } + + if (taskRelation.getDirection().compareTo(Direction.INWARD) == 0) { + label = label + Messages.TaskEditorOutlineNode_ParentRelation; + } else { + label = label + Messages.TaskEditorOutlineNode_ChildRelation; + } TaskEditorOutlineNode childNode = new TaskEditorOutlineNode(label); childNode.setTaskRelation(taskRelation); 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 13de3c18a..9f20a6997 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 @@ -1732,7 +1732,46 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage implements ISe @Override public boolean selectReveal(Object object) { - if (object instanceof TaskEditorOutlineNode) { + if (object instanceof String) { + String objString = (String) object; + if (objString != null && objString.startsWith(TaskAttribute.PREFIX_ATTACHMENT)) { + AbstractTaskEditorPart actionPart = this.getPart(AbstractTaskEditorPage.ID_PART_ATTACHMENTS); + if (actionPart != null && actionPart.getControl() instanceof ExpandableComposite) { + CommonFormUtil.setExpanded((ExpandableComposite) actionPart.getControl(), true); + if (actionPart.getControl() instanceof Section) { + Control client = actionPart.getControl(); + if (client instanceof Composite) { + for (Control control : ((Composite) client).getChildren()) { + if (control instanceof Composite) { + for (Control control1 : ((Composite) control).getChildren()) { + if (control1 instanceof org.eclipse.swt.widgets.Table) { + org.eclipse.swt.widgets.Table attachmentTable = ((org.eclipse.swt.widgets.Table) control1); + TableItem[] attachments = attachmentTable.getItems(); + int index = 0; + for (TableItem attachment : attachments) { + Object data = attachment.getData(); + if (data instanceof ITaskAttachment) { + ITaskAttachment attachmentData = ((ITaskAttachment) data); + if (attachmentData.getTaskAttribute().getId().equals(objString)) { + attachmentTable.deselectAll(); + attachmentTable.select(index); + IManagedForm mform = actionPart.getManagedForm(); + ScrolledForm form = mform.getForm(); + EditorUtil.focusOn(form, attachmentTable); + return true; + } + } + index++; + } + } + } + } + } + } + } + } + } + } else if (object instanceof TaskEditorOutlineNode) { TaskEditorOutlineNode node = (TaskEditorOutlineNode) object; TaskAttribute attribute = node.getData(); if (attribute != null) { |