|
Lines 12-26
Link Here
|
| 12 |
|
12 |
|
| 13 |
package org.eclipse.mylyn.tasks.ui; |
13 |
package org.eclipse.mylyn.tasks.ui; |
| 14 |
|
14 |
|
|
|
15 |
import java.lang.reflect.Method; |
| 15 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
| 16 |
|
17 |
|
|
|
18 |
import org.eclipse.core.runtime.IStatus; |
| 19 |
import org.eclipse.core.runtime.Status; |
| 17 |
import org.eclipse.jface.preference.IPreferenceStore; |
20 |
import org.eclipse.jface.preference.IPreferenceStore; |
|
|
21 |
import org.eclipse.jface.text.DocumentEvent; |
| 22 |
import org.eclipse.jface.text.IDocument; |
| 18 |
import org.eclipse.jface.text.IRegion; |
23 |
import org.eclipse.jface.text.IRegion; |
| 19 |
import org.eclipse.jface.text.ITextViewer; |
24 |
import org.eclipse.jface.text.ITextViewer; |
| 20 |
import org.eclipse.jface.text.TextPresentation; |
25 |
import org.eclipse.jface.text.TextPresentation; |
| 21 |
import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter; |
26 |
import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter; |
| 22 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
27 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
| 23 |
import org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter; |
28 |
import org.eclipse.jface.text.hyperlink.MultipleHyperlinkPresenter; |
|
|
29 |
import org.eclipse.jface.util.PropertyChangeEvent; |
| 30 |
import org.eclipse.mylyn.commons.core.StatusHandler; |
| 24 |
import org.eclipse.mylyn.internal.tasks.core.TaskList; |
31 |
import org.eclipse.mylyn.internal.tasks.core.TaskList; |
| 25 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
32 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 26 |
import org.eclipse.mylyn.internal.tasks.ui.editors.Messages; |
33 |
import org.eclipse.mylyn.internal.tasks.ui.editors.Messages; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.mylyn.tasks.core.ITask; |
35 |
import org.eclipse.mylyn.tasks.core.ITask; |
| 29 |
import org.eclipse.osgi.util.NLS; |
36 |
import org.eclipse.osgi.util.NLS; |
| 30 |
import org.eclipse.swt.custom.StyleRange; |
37 |
import org.eclipse.swt.custom.StyleRange; |
|
|
38 |
import org.eclipse.swt.graphics.Color; |
| 31 |
import org.eclipse.swt.graphics.RGB; |
39 |
import org.eclipse.swt.graphics.RGB; |
| 32 |
|
40 |
|
| 33 |
/** |
41 |
/** |
|
Lines 51-61
Link Here
|
| 51 |
|
59 |
|
| 52 |
private ITextViewer textViewer; |
60 |
private ITextViewer textViewer; |
| 53 |
|
61 |
|
|
|
62 |
private String oldToolTip; |
| 63 |
|
| 64 |
private boolean restoreToolTip; |
| 65 |
|
| 66 |
// TODO e3.7 remove all references to delegate and replace with calls to super methods |
| 67 |
private final MultipleHyperlinkPresenter delegate; |
| 68 |
|
| 69 |
private boolean errorLogged; |
| 70 |
|
| 54 |
/** |
71 |
/** |
| 55 |
* @see DefaultHyperlinkPresenter#DefaultHyperlinkPresenter(IPreferenceStore) |
72 |
* @see DefaultHyperlinkPresenter#DefaultHyperlinkPresenter(IPreferenceStore) |
| 56 |
*/ |
73 |
*/ |
| 57 |
public TaskHyperlinkPresenter(IPreferenceStore store) { |
74 |
public TaskHyperlinkPresenter(IPreferenceStore store) { |
| 58 |
super(store); |
75 |
super(store); |
|
|
76 |
delegate = new MultipleHyperlinkPresenter(store); |
| 59 |
} |
77 |
} |
| 60 |
|
78 |
|
| 61 |
/** |
79 |
/** |
|
Lines 63-87
Link Here
|
| 63 |
*/ |
81 |
*/ |
| 64 |
public TaskHyperlinkPresenter(RGB color) { |
82 |
public TaskHyperlinkPresenter(RGB color) { |
| 65 |
super(color); |
83 |
super(color); |
|
|
84 |
delegate = new MultipleHyperlinkPresenter(color); |
| 66 |
} |
85 |
} |
| 67 |
|
86 |
|
| 68 |
@Override |
87 |
@Override |
| 69 |
public void install(ITextViewer textViewer) { |
88 |
public void install(ITextViewer textViewer) { |
| 70 |
this.textViewer = textViewer; |
89 |
this.textViewer = textViewer; |
| 71 |
super.install(textViewer); |
90 |
delegate.install(textViewer); |
| 72 |
} |
91 |
} |
| 73 |
|
92 |
|
| 74 |
@Override |
93 |
@Override |
| 75 |
public void uninstall() { |
94 |
public void uninstall() { |
| 76 |
hideHyperlinks(); |
95 |
hideHyperlinks(); |
| 77 |
this.textViewer = null; |
96 |
this.textViewer = null; |
| 78 |
super.uninstall(); |
97 |
delegate.uninstall(); |
| 79 |
} |
98 |
} |
| 80 |
|
99 |
|
| 81 |
@SuppressWarnings("unchecked") |
100 |
@SuppressWarnings("unchecked") |
| 82 |
@Override |
101 |
@Override |
| 83 |
public void applyTextPresentation(TextPresentation textPresentation) { |
102 |
public void applyTextPresentation(TextPresentation textPresentation) { |
| 84 |
super.applyTextPresentation(textPresentation); |
103 |
delegate.applyTextPresentation(textPresentation); |
| 85 |
// decorate hyperlink as strike-through if task is completed, this is now also handled by TaskHyperlinkTextPresentationManager |
104 |
// decorate hyperlink as strike-through if task is completed, this is now also handled by TaskHyperlinkTextPresentationManager |
| 86 |
if (activeRegion != null && currentTask != null && currentTask.isCompleted()) { |
105 |
if (activeRegion != null && currentTask != null && currentTask.isCompleted()) { |
| 87 |
Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator(); |
106 |
Iterator<StyleRange> styleRangeIterator = textPresentation.getAllStyleRangeIterator(); |
|
Lines 95-151
Link Here
|
| 95 |
} |
114 |
} |
| 96 |
} |
115 |
} |
| 97 |
|
116 |
|
|
|
117 |
// TODO e3.7 remove method |
| 98 |
@Override |
118 |
@Override |
| 99 |
public void showHyperlinks(IHyperlink[] hyperlinks) { |
119 |
public void showHyperlinks(IHyperlink[] hyperlinks) { |
| 100 |
if (hyperlinks.length > 1) { |
120 |
showHyperlinks(hyperlinks, false); |
| 101 |
super.showHyperlinks(hyperlinks); |
121 |
} |
| 102 |
} else { |
122 |
|
| 103 |
activeRegion = null; |
123 |
// TODO e3.7 add @Override annotation |
| 104 |
if (hyperlinks.length > 0 && hyperlinks[0] instanceof TaskHyperlink) { |
124 |
public void showHyperlinks(IHyperlink[] hyperlinks, boolean takesFocusWhenVisible) { |
| 105 |
TaskHyperlink hyperlink = (TaskHyperlink) hyperlinks[0]; |
125 |
activeRegion = null; |
| 106 |
|
126 |
// show task name in tooltip |
| 107 |
TaskList taskList = TasksUiPlugin.getTaskList(); |
127 |
if (hyperlinks.length == 1 && hyperlinks[0] instanceof TaskHyperlink) { |
| 108 |
String repositoryUrl = hyperlink.getRepository().getRepositoryUrl(); |
128 |
TaskHyperlink hyperlink = (TaskHyperlink) hyperlinks[0]; |
| 109 |
|
129 |
|
| 110 |
ITask task = taskList.getTask(repositoryUrl, hyperlink.getTaskId()); |
130 |
TaskList taskList = TasksUiPlugin.getTaskList(); |
| 111 |
if (task == null) { |
131 |
String repositoryUrl = hyperlink.getRepository().getRepositoryUrl(); |
| 112 |
task = taskList.getTaskByKey(repositoryUrl, hyperlink.getTaskId()); |
132 |
|
| 113 |
} |
133 |
ITask task = taskList.getTask(repositoryUrl, hyperlink.getTaskId()); |
|
|
134 |
if (task == null) { |
| 135 |
task = taskList.getTaskByKey(repositoryUrl, hyperlink.getTaskId()); |
| 136 |
} |
| 114 |
|
137 |
|
| 115 |
if (!hyperlinks[0].equals(currentTaskHyperlink)) { |
138 |
if (!hyperlinks[0].equals(currentTaskHyperlink)) { |
| 116 |
currentTaskHyperlink = (TaskHyperlink) hyperlinks[0]; |
139 |
currentTaskHyperlink = (TaskHyperlink) hyperlinks[0]; |
| 117 |
currentTask = task; |
140 |
currentTask = task; |
| 118 |
activeRegion = hyperlink.getHyperlinkRegion(); |
141 |
activeRegion = hyperlink.getHyperlinkRegion(); |
| 119 |
if (textViewer != null && textViewer.getTextWidget() != null |
142 |
if (textViewer != null && textViewer.getTextWidget() != null |
| 120 |
&& !textViewer.getTextWidget().isDisposed()) { |
143 |
&& !textViewer.getTextWidget().isDisposed()) { |
| 121 |
if (task == null) { |
144 |
oldToolTip = textViewer.getTextWidget().getToolTipText(); |
| 122 |
String taskLabel = TasksUiInternal.getTaskPrefix(hyperlink.getRepository() |
145 |
restoreToolTip = true; |
| 123 |
.getConnectorKind()); |
146 |
if (task == null) { |
| 124 |
taskLabel += currentTaskHyperlink.getTaskId(); |
147 |
String taskLabel = TasksUiInternal.getTaskPrefix(hyperlink.getRepository().getConnectorKind()); |
| 125 |
textViewer.getTextWidget().setToolTipText( |
148 |
taskLabel += currentTaskHyperlink.getTaskId(); |
| 126 |
NLS.bind(Messages.TaskHyperlinkPresenter_Not_In_Task_List, taskLabel)); |
149 |
textViewer.getTextWidget().setToolTipText( |
| 127 |
} else if (task.getTaskKey() == null) { |
150 |
NLS.bind(Messages.TaskHyperlinkPresenter_Not_In_Task_List, taskLabel)); |
| 128 |
textViewer.getTextWidget().setToolTipText(task.getSummary()); |
151 |
} else if (task.getTaskKey() == null) { |
| 129 |
} else { |
152 |
textViewer.getTextWidget().setToolTipText(task.getSummary()); |
| 130 |
textViewer.getTextWidget().setToolTipText(task.getTaskKey() + ": " + task.getSummary()); //$NON-NLS-1$ |
153 |
} else { |
| 131 |
} |
154 |
textViewer.getTextWidget().setToolTipText(task.getTaskKey() + ": " + task.getSummary()); //$NON-NLS-1$ |
| 132 |
} |
155 |
} |
| 133 |
} |
156 |
} |
| 134 |
} |
157 |
} |
| 135 |
super.showHyperlinks(hyperlinks); |
158 |
} |
|
|
159 |
|
| 160 |
// invoke super implementation |
| 161 |
|
| 162 |
try { |
| 163 |
// Eclipse 3.7 |
| 164 |
Method method = MultipleHyperlinkPresenter.class.getDeclaredMethod("showHyperlinks", //$NON-NLS-1$ |
| 165 |
IHyperlink[].class, boolean.class); |
| 166 |
method.invoke(delegate, hyperlinks, takesFocusWhenVisible); |
| 167 |
} catch (NoSuchMethodException e) { |
| 168 |
// Eclipse 3.6 and earlier |
| 169 |
delegate.showHyperlinks(hyperlinks); |
| 170 |
} catch (Exception e) { |
| 171 |
if (!errorLogged) { |
| 172 |
errorLogged = true; |
| 173 |
StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, |
| 174 |
"Unexpected error while displaying hyperlink", e)); //$NON-NLS-1$ |
| 175 |
} |
| 136 |
} |
176 |
} |
| 137 |
} |
177 |
} |
| 138 |
|
178 |
|
| 139 |
@Override |
179 |
@Override |
| 140 |
public void hideHyperlinks() { |
180 |
public void hideHyperlinks() { |
| 141 |
if (currentTaskHyperlink != null) { |
181 |
if (currentTaskHyperlink != null) { |
| 142 |
if (textViewer != null && textViewer.getTextWidget() != null && !textViewer.getTextWidget().isDisposed()) { |
182 |
if (restoreToolTip && textViewer != null && textViewer.getTextWidget() != null |
| 143 |
textViewer.getTextWidget().setToolTipText(null); |
183 |
&& !textViewer.getTextWidget().isDisposed()) { |
|
|
184 |
textViewer.getTextWidget().setToolTipText(oldToolTip); |
| 185 |
restoreToolTip = false; |
| 144 |
} |
186 |
} |
| 145 |
currentTaskHyperlink = null; |
187 |
currentTaskHyperlink = null; |
| 146 |
currentTask = null; |
188 |
currentTask = null; |
| 147 |
} |
189 |
} |
| 148 |
super.hideHyperlinks(); |
190 |
delegate.hideHyperlinks(); |
|
|
191 |
} |
| 192 |
|
| 193 |
@Override |
| 194 |
public boolean canHideHyperlinks() { |
| 195 |
return delegate.canHideHyperlinks(); |
| 196 |
} |
| 197 |
|
| 198 |
@Override |
| 199 |
public boolean canShowMultipleHyperlinks() { |
| 200 |
return delegate.canShowMultipleHyperlinks(); |
| 201 |
} |
| 202 |
|
| 203 |
@Override |
| 204 |
public void documentAboutToBeChanged(DocumentEvent event) { |
| 205 |
delegate.documentAboutToBeChanged(event); |
| 206 |
} |
| 207 |
|
| 208 |
@Override |
| 209 |
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { |
| 210 |
delegate.inputDocumentAboutToBeChanged(oldInput, newInput); |
| 211 |
} |
| 212 |
|
| 213 |
@Override |
| 214 |
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { |
| 215 |
delegate.inputDocumentChanged(oldInput, newInput); |
| 216 |
} |
| 217 |
|
| 218 |
@Override |
| 219 |
public void propertyChange(PropertyChangeEvent event) { |
| 220 |
delegate.propertyChange(event); |
| 221 |
} |
| 222 |
|
| 223 |
@Override |
| 224 |
public void setColor(Color color) { |
| 225 |
delegate.setColor(color); |
| 149 |
} |
226 |
} |
| 150 |
|
227 |
|
| 151 |
} |
228 |
} |