|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 Frank Becker and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Frank Becker - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.mylyn.internal.bugzilla.ui; |
| 13 |
|
| 14 |
import java.text.MessageFormat; |
| 15 |
|
| 16 |
import org.eclipse.core.runtime.Assert; |
| 17 |
import org.eclipse.jface.text.IRegion; |
| 18 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
| 19 |
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; |
| 20 |
import org.eclipse.mylyn.tasks.core.TaskRepository; |
| 21 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
| 22 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
| 23 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
| 24 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
| 25 |
import org.eclipse.ui.IEditorPart; |
| 26 |
import org.eclipse.ui.IWorkbenchPage; |
| 27 |
import org.eclipse.ui.PlatformUI; |
| 28 |
import org.eclipse.ui.forms.editor.IFormPage; |
| 29 |
|
| 30 |
/** |
| 31 |
* @since 3.2 |
| 32 |
*/ |
| 33 |
public final class TaskAttachmentTableEditorHyperlink implements IHyperlink { |
| 34 |
|
| 35 |
private final IRegion region; |
| 36 |
|
| 37 |
private final TaskRepository repository; |
| 38 |
|
| 39 |
private final String attachmentId; |
| 40 |
|
| 41 |
public TaskAttachmentTableEditorHyperlink(IRegion region, TaskRepository repository, String attachmentId) { |
| 42 |
Assert.isNotNull(repository); |
| 43 |
this.region = region; |
| 44 |
this.repository = repository; |
| 45 |
this.attachmentId = attachmentId; |
| 46 |
} |
| 47 |
|
| 48 |
public IRegion getHyperlinkRegion() { |
| 49 |
return region; |
| 50 |
} |
| 51 |
|
| 52 |
public String getHyperlinkText() { |
| 53 |
return MessageFormat.format(Messages.TaskAttachmentTableEditorHyperlink_Show_Attachment_X_in_Y, attachmentId, |
| 54 |
repository.getRepositoryLabel()); |
| 55 |
} |
| 56 |
|
| 57 |
public String getTypeLabel() { |
| 58 |
return null; |
| 59 |
} |
| 60 |
|
| 61 |
public void open() { |
| 62 |
AbstractTaskEditorPage page = getTaskEditorPage(); |
| 63 |
if (page != null) { |
| 64 |
if (!page.selectReveal(TaskAttribute.PREFIX_ATTACHMENT + attachmentId)) { |
| 65 |
String url = repository.getUrl() + IBugzillaConstants.URL_GET_ATTACHMENT_SUFFIX + attachmentId; |
| 66 |
TasksUiUtil.openUrl(url); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
@Override |
| 72 |
public int hashCode() { |
| 73 |
final int prime = 31; |
| 74 |
int result = 1; |
| 75 |
result = prime * result + ((attachmentId == null) ? 0 : attachmentId.hashCode()); |
| 76 |
result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 77 |
result = prime * result + ((repository == null) ? 0 : repository.hashCode()); |
| 78 |
return result; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public boolean equals(Object obj) { |
| 83 |
if (this == obj) { |
| 84 |
return true; |
| 85 |
} |
| 86 |
if (obj == null) { |
| 87 |
return false; |
| 88 |
} |
| 89 |
if (getClass() != obj.getClass()) { |
| 90 |
return false; |
| 91 |
} |
| 92 |
TaskAttachmentTableEditorHyperlink other = (TaskAttachmentTableEditorHyperlink) obj; |
| 93 |
if (attachmentId == null) { |
| 94 |
if (other.attachmentId != null) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
} else if (!attachmentId.equals(other.attachmentId)) { |
| 98 |
return false; |
| 99 |
} |
| 100 |
if (region == null) { |
| 101 |
if (other.region != null) { |
| 102 |
return false; |
| 103 |
} |
| 104 |
} else if (!region.equals(other.region)) { |
| 105 |
return false; |
| 106 |
} |
| 107 |
if (repository == null) { |
| 108 |
if (other.repository != null) { |
| 109 |
return false; |
| 110 |
} |
| 111 |
} else if (!repository.equals(other.repository)) { |
| 112 |
return false; |
| 113 |
} |
| 114 |
return true; |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public String toString() { |
| 119 |
return "TaskAttachmentHyperlink [attachmentId=" + attachmentId + ", region=" + region + ", repository=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 120 |
+ repository + "]"; //$NON-NLS-1$ |
| 121 |
} |
| 122 |
|
| 123 |
protected AbstractTaskEditorPage getTaskEditorPage() { |
| 124 |
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 125 |
if (activePage == null) { |
| 126 |
return null; |
| 127 |
} |
| 128 |
IEditorPart editorPart = activePage.getActiveEditor(); |
| 129 |
AbstractTaskEditorPage taskEditorPage = null; |
| 130 |
if (editorPart instanceof TaskEditor) { |
| 131 |
TaskEditor taskEditor = (TaskEditor) editorPart; |
| 132 |
IFormPage formPage = taskEditor.getActivePageInstance(); |
| 133 |
if (formPage instanceof AbstractTaskEditorPage) { |
| 134 |
taskEditorPage = (AbstractTaskEditorPage) formPage; |
| 135 |
} |
| 136 |
} |
| 137 |
return taskEditorPage; |
| 138 |
} |
| 139 |
|
| 140 |
} |