|
Lines 14-25
Link Here
|
| 14 |
|
14 |
|
| 15 |
package org.eclipse.mylyn.internal.tasks.ui.views; |
15 |
package org.eclipse.mylyn.internal.tasks.ui.views; |
| 16 |
|
16 |
|
| 17 |
import java.net.URL; |
|
|
| 18 |
import java.text.DateFormat; |
17 |
import java.text.DateFormat; |
| 19 |
import java.util.Calendar; |
18 |
import java.util.Calendar; |
| 20 |
import java.util.Date; |
19 |
import java.util.Date; |
| 21 |
|
20 |
|
| 22 |
import org.eclipse.core.runtime.IAdaptable; |
21 |
import org.eclipse.core.runtime.IAdaptable; |
|
|
22 |
import org.eclipse.core.runtime.IStatus; |
| 23 |
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer; |
23 |
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer; |
| 24 |
import org.eclipse.mylyn.internal.tasks.ui.ITaskListNotification; |
24 |
import org.eclipse.mylyn.internal.tasks.ui.ITaskListNotification; |
| 25 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages; |
25 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages; |
|
Lines 58-206
Link Here
|
| 58 |
* @author Mik Kersten |
58 |
* @author Mik Kersten |
| 59 |
* @author Eric Booth |
59 |
* @author Eric Booth |
| 60 |
* @author Leo Dos Santos - multi-monitor support |
60 |
* @author Leo Dos Santos - multi-monitor support |
|
|
61 |
* @author Steffen Pingel |
| 61 |
*/ |
62 |
*/ |
| 62 |
public class TaskListToolTipHandler { |
63 |
public class TaskListToolTipHandler { |
| 63 |
|
64 |
|
| 64 |
private static final String SEPARATOR = "\n\n"; |
|
|
| 65 |
|
| 66 |
private static final String UNITS_HOURS = " hours"; |
| 67 |
|
| 68 |
private static final String NO_MINUTES = "0 minutes"; |
| 69 |
|
| 70 |
private Shell tipShell; |
65 |
private Shell tipShell; |
| 71 |
|
66 |
|
| 72 |
private Label tipLabelImage; |
|
|
| 73 |
|
| 74 |
private Label tipLabelText; |
| 75 |
|
| 76 |
private Label scheduledTipLabelImage; |
| 77 |
|
| 78 |
private Label scheduledTipLabelText; |
| 79 |
|
| 80 |
private Label incommingTipLabelImage; |
| 81 |
|
| 82 |
private Label incommingTipLabelText; |
| 83 |
|
| 84 |
private WorkweekProgressBar taskProgressBar; |
| 85 |
|
| 86 |
private Widget tipWidget; |
67 |
private Widget tipWidget; |
| 87 |
|
68 |
|
| 88 |
protected Point tipPosition; |
69 |
public TaskListToolTipHandler() { |
| 89 |
|
|
|
| 90 |
protected Point widgetPosition; |
| 91 |
|
| 92 |
public TaskListToolTipHandler(Shell parentShell) { |
| 93 |
if (parentShell != null) { |
| 94 |
tipShell = createTipShell(parentShell, null, true, true); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
private Shell createTipShell(Shell parent, Widget widget, boolean showScheduled, boolean showIncomming) { |
| 99 |
Shell tipShell = new Shell(parent.getDisplay(), SWT.TOOL | SWT.NO_FOCUS | SWT.MODELESS | SWT.ON_TOP); |
| 100 |
GridLayout gridLayout = new GridLayout(); |
| 101 |
gridLayout.numColumns = 2; |
| 102 |
gridLayout.marginWidth = 2; |
| 103 |
gridLayout.marginHeight = 2; |
| 104 |
tipShell.setLayout(gridLayout); |
| 105 |
tipShell.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 106 |
|
| 107 |
tipLabelImage = new Label(tipShell, SWT.NONE); |
| 108 |
tipLabelImage.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 109 |
tipLabelImage.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 110 |
|
| 111 |
GridData imageGridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); |
| 112 |
tipLabelImage.setLayoutData(imageGridData); |
| 113 |
|
| 114 |
tipLabelText = new Label(tipShell, SWT.NONE); |
| 115 |
tipLabelText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 116 |
tipLabelText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 117 |
|
| 118 |
GridData textGridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); |
| 119 |
tipLabelText.setLayoutData(textGridData); |
| 120 |
|
| 121 |
if (showScheduled) { |
| 122 |
|
| 123 |
scheduledTipLabelImage = new Label(tipShell, SWT.NONE); |
| 124 |
scheduledTipLabelImage.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 125 |
scheduledTipLabelImage.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 126 |
|
| 127 |
imageGridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); |
| 128 |
scheduledTipLabelImage.setLayoutData(imageGridData); |
| 129 |
|
| 130 |
scheduledTipLabelText = new Label(tipShell, SWT.NONE); |
| 131 |
scheduledTipLabelText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 132 |
scheduledTipLabelText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 133 |
|
| 134 |
textGridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); |
| 135 |
scheduledTipLabelText.setLayoutData(textGridData); |
| 136 |
} |
| 137 |
|
| 138 |
if (showIncomming) { |
| 139 |
incommingTipLabelImage = new Label(tipShell, SWT.NONE); |
| 140 |
incommingTipLabelImage.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 141 |
incommingTipLabelImage.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 142 |
|
| 143 |
imageGridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); |
| 144 |
incommingTipLabelImage.setLayoutData(imageGridData); |
| 145 |
|
| 146 |
incommingTipLabelText = new Label(tipShell, SWT.NONE); |
| 147 |
incommingTipLabelText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 148 |
incommingTipLabelText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 149 |
|
| 150 |
textGridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); |
| 151 |
incommingTipLabelText.setLayoutData(textGridData); |
| 152 |
} |
| 153 |
|
| 154 |
AbstractTaskContainer element = getTaskListElement(widget); |
| 155 |
if (element instanceof AbstractTaskContainer) { |
| 156 |
Composite progressComposite = new Composite(tipShell, SWT.NONE); |
| 157 |
GridLayout progressLayout = new GridLayout(1, false); |
| 158 |
progressLayout.marginWidth = 2; |
| 159 |
progressLayout.marginHeight = 0; |
| 160 |
progressLayout.marginBottom = 2; |
| 161 |
progressLayout.horizontalSpacing = 0; |
| 162 |
progressLayout.verticalSpacing = 0; |
| 163 |
progressComposite.setLayout(progressLayout); |
| 164 |
progressComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 4, 1)); |
| 165 |
|
| 166 |
taskProgressBar = new WorkweekProgressBar(progressComposite); |
| 167 |
taskProgressBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 168 |
} |
| 169 |
|
| 170 |
return tipShell; |
| 171 |
} |
| 172 |
|
| 173 |
private String updateContainerProgressBar(WorkweekProgressBar taskProgressBar, Object object) { |
| 174 |
if (taskProgressBar != null && !taskProgressBar.isDisposed() && object instanceof AbstractTaskContainer) { |
| 175 |
String text = ""; |
| 176 |
AbstractTaskContainer container = (AbstractTaskContainer) object; |
| 177 |
|
| 178 |
int total = container.getChildren().size(); |
| 179 |
int completed = 0; |
| 180 |
for (AbstractTask task : container.getChildren()) { |
| 181 |
if (task.isCompleted()) { |
| 182 |
completed++; |
| 183 |
} |
| 184 |
} |
| 185 |
String suffix = ""; |
| 186 |
if (container instanceof AbstractRepositoryQuery) { |
| 187 |
AbstractRepositoryQuery query = ((AbstractRepositoryQuery) container); |
| 188 |
total = 0; |
| 189 |
completed = 0; |
| 190 |
total += query.getChildren().size(); |
| 191 |
for (AbstractTask hit : query.getChildren()) { |
| 192 |
if (hit.isCompleted()) { |
| 193 |
completed++; |
| 194 |
} |
| 195 |
} |
| 196 |
// suffix = " (query max: " + query.getMaxHits() + ")"; |
| 197 |
} |
| 198 |
taskProgressBar.reset(completed, total); |
| 199 |
text += "Completed " + completed + " of " + total + suffix; |
| 200 |
return text; |
| 201 |
} else { |
| 202 |
return ""; |
| 203 |
} |
| 204 |
} |
70 |
} |
| 205 |
|
71 |
|
| 206 |
private AbstractTaskContainer getTaskListElement(Object hoverObject) { |
72 |
private AbstractTaskContainer getTaskListElement(Object hoverObject) { |
|
Lines 217-341
Link Here
|
| 217 |
return null; |
83 |
return null; |
| 218 |
} |
84 |
} |
| 219 |
|
85 |
|
| 220 |
protected String getBasicToolTextTip(Object object) { |
86 |
private String getTitleText(AbstractTaskContainer element) { |
| 221 |
AbstractTaskContainer element = getTaskListElement(object); |
|
|
| 222 |
String tooltip = ""; |
| 223 |
String priority = ""; |
| 224 |
|
| 225 |
if (element instanceof ScheduledTaskContainer) { |
87 |
if (element instanceof ScheduledTaskContainer) { |
| 226 |
ScheduledTaskContainer container = (ScheduledTaskContainer) element; |
88 |
Calendar start = ((ScheduledTaskContainer) element).getStart(); |
| 227 |
tooltip += "Estimate: " + container.getTotalEstimated() + UNITS_HOURS; |
89 |
return DateFormat.getDateInstance(DateFormat.LONG).format(start.getTime()); |
| 228 |
String elapsedTimeString = NO_MINUTES; |
90 |
} else { |
| 229 |
try { |
91 |
return element.getSummary(); |
| 230 |
elapsedTimeString = DateUtil.getFormattedDurationShort(container.getTotalElapsed()); |
|
|
| 231 |
if (elapsedTimeString.equals("")) { |
| 232 |
elapsedTimeString = NO_MINUTES; |
| 233 |
} |
| 234 |
} catch (RuntimeException e) { |
| 235 |
// ignore |
| 236 |
} |
| 237 |
tooltip += " Elapsed: " + elapsedTimeString + "\n"; |
| 238 |
return tooltip; |
| 239 |
} |
92 |
} |
|
|
93 |
} |
| 240 |
|
94 |
|
| 241 |
if (element instanceof AbstractRepositoryQuery) { |
95 |
private String getDetailsText(AbstractTaskContainer element) { |
|
|
96 |
if (element instanceof ScheduledTaskContainer) { |
| 97 |
ScheduledTaskContainer container = (ScheduledTaskContainer) element; |
| 98 |
StringBuilder sb = new StringBuilder(); |
| 99 |
sb.append("Estimate: "); |
| 100 |
sb.append(container.getTotalEstimated()); |
| 101 |
sb.append(" hours"); |
| 102 |
sb.append("\n"); |
| 103 |
sb.append("Elapsed: "); |
| 104 |
sb.append(DateUtil.getFormattedDurationShort(container.getTotalElapsed())); |
| 105 |
sb.append("\n"); |
| 106 |
return sb.toString(); |
| 107 |
} else if (element instanceof AbstractRepositoryQuery) { |
| 242 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) element; |
108 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) element; |
| 243 |
|
109 |
StringBuilder sb = new StringBuilder(); |
| 244 |
try { |
110 |
sb.append(getRepositoryLabel(query.getRepositoryKind(), query.getRepositoryUrl())); |
| 245 |
tooltip += new URL(query.getRepositoryUrl()).getHost(); |
|
|
| 246 |
} catch (Exception e) { |
| 247 |
// ignore |
| 248 |
} |
| 249 |
|
| 250 |
String syncStamp = query.getLastRefreshTimeStamp(); |
111 |
String syncStamp = query.getLastRefreshTimeStamp(); |
| 251 |
if (syncStamp != null) { |
112 |
if (syncStamp != null) { |
| 252 |
tooltip += " (synched: " + syncStamp + ")\n"; |
113 |
sb.append("Last Synchronization: " + syncStamp + "\n"); |
| 253 |
} |
|
|
| 254 |
if (query.getStatus() != null) { |
| 255 |
tooltip += "\n" + "Last Error: " + query.getStatus().getMessage(); |
| 256 |
if (query.getStatus() instanceof RepositoryStatus && ((RepositoryStatus) query.getStatus()).isHtmlMessage()) { |
| 257 |
tooltip += " Please synchronize manually for full error message."; |
| 258 |
} |
| 259 |
tooltip += "\n"; |
| 260 |
} |
114 |
} |
| 261 |
return tooltip; |
115 |
return sb.toString(); |
|
|
116 |
} else if (element instanceof AbstractTask) { |
| 117 |
AbstractTask task = (AbstractTask) element; |
| 118 |
StringBuilder sb = new StringBuilder(); |
| 119 |
sb.append(getRepositoryLabel(task.getRepositoryKind(), task.getRepositoryUrl())); |
| 120 |
sb.append(TasksUiPlugin.getRepositoryUi(task.getRepositoryKind()).getTaskKindLabel(task)); |
| 121 |
sb.append(", "); |
| 122 |
sb.append(task.getPriority()); |
| 123 |
sb.append("\n"); |
| 124 |
return sb.toString(); |
| 262 |
} |
125 |
} |
|
|
126 |
return null; |
| 127 |
} |
| 263 |
|
128 |
|
| 264 |
if (element instanceof AbstractTask) { |
129 |
private String getRepositoryLabel(String repositoryKind, String repositoryUrl) { |
| 265 |
|
130 |
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(repositoryKind, repositoryUrl); |
| 266 |
AbstractTask repositoryTask = (AbstractTask) element; |
131 |
if (repository != null) { |
| 267 |
|
132 |
String label = repository.getRepositoryLabel(); |
| 268 |
tooltip += (element).getSummary(); |
133 |
if (label.indexOf("//") != -1) { |
| 269 |
if (repositoryTask != null) { |
134 |
return label.substring((repository.getUrl().indexOf("//") + 2)) + "\n"; |
| 270 |
|
|
|
| 271 |
String taskKindLabel = TasksUiPlugin.getRepositoryUi(repositoryTask.getRepositoryKind()) |
| 272 |
.getTaskKindLabel(repositoryTask); |
| 273 |
|
| 274 |
tooltip += "\n" + taskKindLabel + ", " + repositoryTask.getPriority(); |
| 275 |
|
| 276 |
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository( |
| 277 |
repositoryTask.getRepositoryKind(), repositoryTask.getRepositoryUrl()); |
| 278 |
if (repository != null) { |
| 279 |
tooltip += " [" + repository.getRepositoryLabel() + "]"; |
| 280 |
} |
| 281 |
|
| 282 |
if (repositoryTask.getStatus() != null) { |
| 283 |
tooltip += SEPARATOR + "Last Error: " + repositoryTask.getStatus().getMessage(); |
| 284 |
} |
| 285 |
} |
135 |
} |
| 286 |
return tooltip; |
136 |
return label + "\n"; |
| 287 |
} else if (element != null) { |
|
|
| 288 |
tooltip += (element).getSummary(); |
| 289 |
return tooltip + priority; |
| 290 |
} else if (object instanceof Control) { |
| 291 |
return (String) ((Control) object).getData("TIP_TEXT"); |
| 292 |
} |
137 |
} |
| 293 |
return null; |
138 |
return ""; |
| 294 |
} |
139 |
} |
| 295 |
|
140 |
|
| 296 |
private String getActivityText(AbstractTaskContainer element) { |
141 |
private String getActivityText(AbstractTaskContainer element) { |
|
|
142 |
if (element instanceof AbstractTask) { |
| 143 |
AbstractTask task = (AbstractTask) element; |
| 297 |
|
144 |
|
| 298 |
if (element != null && element instanceof AbstractTask) { |
145 |
StringBuilder sb = new StringBuilder(); |
| 299 |
try { |
146 |
Date date = task.getScheduledForDate(); |
| 300 |
String result = ""; |
147 |
if (date != null) { |
| 301 |
Date date = ((AbstractTask) element).getScheduledForDate(); |
148 |
sb.append("Scheduled for: "); |
| 302 |
if (date != null) { |
149 |
sb.append(DateFormat.getDateInstance(DateFormat.LONG).format(date)); |
| 303 |
result += "Scheduled for: " + DateFormat.getDateInstance(DateFormat.LONG).format(date) + " (" |
150 |
sb.append(" ("); |
| 304 |
+ DateFormat.getTimeInstance(DateFormat.SHORT).format(date) + ")\n"; |
151 |
sb.append(DateFormat.getTimeInstance(DateFormat.SHORT).format(date)); |
| 305 |
} |
152 |
sb.append(")\n"); |
|
|
153 |
} |
| 154 |
|
| 155 |
long elapsed = TasksUiPlugin.getTaskListManager().getElapsedTime(task); |
| 156 |
String elapsedTimeString = DateUtil.getFormattedDurationShort(elapsed); |
| 157 |
sb.append("Elapsed: "); |
| 158 |
sb.append(elapsedTimeString); |
| 159 |
sb.append("\n"); |
| 306 |
|
160 |
|
| 307 |
long elapsed = TasksUiPlugin.getTaskListManager().getElapsedTime((AbstractTask) element); |
161 |
return sb.toString(); |
| 308 |
String elapsedTimeString = DateUtil.getFormattedDurationShort(elapsed); |
|
|
| 309 |
if (!elapsedTimeString.equals("")) { |
| 310 |
result += "Elapsed: " + elapsedTimeString + "\n"; |
| 311 |
} |
| 312 |
return result; |
| 313 |
} catch (Exception e) { |
| 314 |
// ignore |
| 315 |
} |
| 316 |
} |
162 |
} |
| 317 |
return null; |
163 |
return null; |
| 318 |
} |
164 |
} |
| 319 |
|
165 |
|
| 320 |
private String getIncommingText(AbstractTaskContainer element) { |
166 |
private String getIncommingText(AbstractTaskContainer element) { |
| 321 |
if (element instanceof AbstractTask) { |
167 |
if (element instanceof AbstractTask) { |
| 322 |
|
168 |
AbstractTask task = (AbstractTask) element; |
| 323 |
AbstractTask repositoryTask = (AbstractTask) element; |
169 |
if (task.getSyncState() == RepositoryTaskSyncState.INCOMING) { |
| 324 |
|
|
|
| 325 |
if (repositoryTask != null && repositoryTask.getSyncState() == RepositoryTaskSyncState.INCOMING) { |
| 326 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
170 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
| 327 |
repositoryTask); |
171 |
task); |
| 328 |
if (connector != null) { |
172 |
if (connector != null) { |
| 329 |
ITaskListNotification notification = TasksUiPlugin.getIncommingNotification(connector, |
173 |
ITaskListNotification notification = TasksUiPlugin.getIncommingNotification(connector, task); |
| 330 |
repositoryTask); |
|
|
| 331 |
if (notification != null) { |
174 |
if (notification != null) { |
| 332 |
String descriptionText = null; |
|
|
| 333 |
if (notification.getDescription() != null) { |
175 |
if (notification.getDescription() != null) { |
| 334 |
descriptionText = notification.getDescription(); |
176 |
String descriptionText = notification.getDescription(); |
| 335 |
} |
177 |
if (descriptionText != null && descriptionText.length() > 0) { |
| 336 |
|
178 |
return descriptionText; |
| 337 |
if (descriptionText != null && !descriptionText.equals("")) { |
179 |
} |
| 338 |
return descriptionText; |
|
|
| 339 |
} |
180 |
} |
| 340 |
} |
181 |
} |
| 341 |
} |
182 |
} |
|
Lines 344-355
Link Here
|
| 344 |
return null; |
185 |
return null; |
| 345 |
} |
186 |
} |
| 346 |
|
187 |
|
| 347 |
protected Image getImage(Object object) { |
188 |
private String getStatusText(AbstractTaskContainer element) { |
| 348 |
AbstractTaskContainer element = getTaskListElement(object); |
189 |
IStatus status = null; |
| 349 |
if (object instanceof Control) { |
190 |
if (element instanceof AbstractTask) { |
| 350 |
return (Image) ((Control) object).getData("TIP_IMAGE"); |
191 |
AbstractTask task = (AbstractTask) element; |
|
|
192 |
status = task.getStatus(); |
| 351 |
} else if (element instanceof AbstractRepositoryQuery) { |
193 |
} else if (element instanceof AbstractRepositoryQuery) { |
| 352 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) element; |
194 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) element; |
|
|
195 |
status = query.getStatus(); |
| 196 |
} |
| 197 |
|
| 198 |
if (status != null) { |
| 199 |
StringBuilder sb = new StringBuilder(); |
| 200 |
sb.append("Last Error: "); |
| 201 |
sb.append(status.getMessage()); |
| 202 |
if (status instanceof RepositoryStatus && ((RepositoryStatus) status).isHtmlMessage()) { |
| 203 |
sb.append(" Please synchronize manually for full error message."); |
| 204 |
} |
| 205 |
return sb.toString(); |
| 206 |
} |
| 207 |
|
| 208 |
return null; |
| 209 |
} |
| 210 |
|
| 211 |
private ProgressData getProgressData(AbstractTaskContainer element) { |
| 212 |
if (element instanceof AbstractTask && element.getChildren().isEmpty()) { |
| 213 |
return null; |
| 214 |
} |
| 215 |
|
| 216 |
int total = element.getChildren().size(); |
| 217 |
int completed = 0; |
| 218 |
for (AbstractTask task : element.getChildren()) { |
| 219 |
if (task.isCompleted()) { |
| 220 |
completed++; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
String text = "Completed " + completed + " of " + total; |
| 225 |
return new ProgressData(completed, total, text); |
| 226 |
} |
| 227 |
|
| 228 |
private Image getImage(AbstractTaskContainer element) { |
| 229 |
if (element instanceof AbstractRepositoryQuery) { |
| 230 |
AbstractRepositoryQuery query = (AbstractRepositoryQuery) element; |
| 353 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
231 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
| 354 |
query.getRepositoryKind()); |
232 |
query.getRepositoryKind()); |
| 355 |
if (connector != null) { |
233 |
if (connector != null) { |
|
Lines 357-363
Link Here
|
| 357 |
} |
235 |
} |
| 358 |
} else if (element instanceof AbstractTask) { |
236 |
} else if (element instanceof AbstractTask) { |
| 359 |
AbstractTask repositoryTask = (AbstractTask) element; |
237 |
AbstractTask repositoryTask = (AbstractTask) element; |
| 360 |
|
|
|
| 361 |
if (repositoryTask != null) { |
238 |
if (repositoryTask != null) { |
| 362 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
239 |
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector( |
| 363 |
repositoryTask.getRepositoryKind()); |
240 |
repositoryTask.getRepositoryKind()); |
|
Lines 369-443
Link Here
|
| 369 |
return null; |
246 |
return null; |
| 370 |
} |
247 |
} |
| 371 |
|
248 |
|
| 372 |
protected Object getToolTipHelp(Object object) { |
|
|
| 373 |
if (object instanceof Control) { |
| 374 |
return ((Control) object).getData("TIP_HELPTEXT"); |
| 375 |
} |
| 376 |
return null; |
| 377 |
} |
| 378 |
|
| 379 |
/** |
249 |
/** |
| 380 |
* Enables customized hover help for a specified control |
250 |
* Enables customized hover help for a specified control |
| 381 |
* |
251 |
* |
| 382 |
* @control the control on which to enable hoverhelp |
252 |
* @control the control on which to enable hoverhelp |
| 383 |
*/ |
253 |
*/ |
| 384 |
public void activateHoverHelp(final Control control) { |
254 |
public void activateHoverHelp(final Control control) { |
| 385 |
|
255 |
// hide tooltip if any window is deactivated |
| 386 |
PlatformUI.getWorkbench().addWindowListener(new IWindowListener() { |
256 |
PlatformUI.getWorkbench().addWindowListener(new IWindowListener() { |
| 387 |
|
257 |
|
| 388 |
public void windowActivated(IWorkbenchWindow window) { |
258 |
public void windowActivated(IWorkbenchWindow window) { |
| 389 |
// ignore |
|
|
| 390 |
|
| 391 |
} |
259 |
} |
| 392 |
|
260 |
|
| 393 |
public void windowClosed(IWorkbenchWindow window) { |
261 |
public void windowClosed(IWorkbenchWindow window) { |
| 394 |
// ignore |
|
|
| 395 |
|
| 396 |
} |
262 |
} |
| 397 |
|
263 |
|
| 398 |
public void windowDeactivated(IWorkbenchWindow window) { |
264 |
public void windowDeactivated(IWorkbenchWindow window) { |
| 399 |
hideTooltip(); |
265 |
hideTooltip(); |
| 400 |
|
|
|
| 401 |
} |
266 |
} |
| 402 |
|
267 |
|
| 403 |
public void windowOpened(IWorkbenchWindow window) { |
268 |
public void windowOpened(IWorkbenchWindow window) { |
| 404 |
// ignore |
|
|
| 405 |
|
| 406 |
} |
269 |
} |
| 407 |
}); |
270 |
}); |
| 408 |
|
271 |
|
| 409 |
/* |
272 |
// hide tooltip if control underneath is activated |
| 410 |
* Get out of the way if we attempt to activate the control underneath |
|
|
| 411 |
* the tooltip |
| 412 |
*/ |
| 413 |
control.addMouseListener(new MouseAdapter() { |
273 |
control.addMouseListener(new MouseAdapter() { |
| 414 |
|
274 |
|
| 415 |
@Override |
275 |
@Override |
| 416 |
public void mouseDown(MouseEvent e) { |
276 |
public void mouseDown(MouseEvent e) { |
| 417 |
hideTooltip(); |
277 |
hideTooltip(); |
|
|
278 |
tipWidget = null; |
| 418 |
} |
279 |
} |
| 419 |
}); |
280 |
}); |
| 420 |
/* |
281 |
|
| 421 |
* Trap hover events to pop-up tooltip |
282 |
// trap hover events to pop-up tooltip |
| 422 |
*/ |
|
|
| 423 |
control.addMouseTrackListener(new MouseTrackAdapter() { |
283 |
control.addMouseTrackListener(new MouseTrackAdapter() { |
| 424 |
|
284 |
|
| 425 |
@Override |
285 |
@Override |
| 426 |
public void mouseExit(MouseEvent e) { |
286 |
public void mouseExit(MouseEvent e) { |
| 427 |
// TODO: can these conditions be simplified? see bug 131776 |
287 |
hideTooltip(); |
| 428 |
if (tipShell != null && !tipShell.isDisposed() && tipShell.getDisplay() != null |
|
|
| 429 |
&& !tipShell.getDisplay().isDisposed() && tipShell.isVisible()) { |
| 430 |
tipShell.setVisible(false); |
| 431 |
} |
| 432 |
tipWidget = null; |
288 |
tipWidget = null; |
| 433 |
} |
289 |
} |
| 434 |
|
290 |
|
| 435 |
@Override |
291 |
@Override |
| 436 |
public void mouseHover(MouseEvent event) { |
292 |
public void mouseHover(MouseEvent event) { |
| 437 |
if (tipShell.isDisposed()) { |
293 |
Point widgetPosition = new Point(event.x, event.y); |
| 438 |
return; |
|
|
| 439 |
} |
| 440 |
widgetPosition = new Point(event.x, event.y); |
| 441 |
Widget widget = event.widget; |
294 |
Widget widget = event.widget; |
| 442 |
if (widget instanceof ToolBar) { |
295 |
if (widget instanceof ToolBar) { |
| 443 |
ToolBar w = (ToolBar) widget; |
296 |
ToolBar w = (ToolBar) widget; |
|
Lines 451-513
Link Here
|
| 451 |
Tree w = (Tree) widget; |
304 |
Tree w = (Tree) widget; |
| 452 |
widget = w.getItem(widgetPosition); |
305 |
widget = w.getItem(widgetPosition); |
| 453 |
} |
306 |
} |
| 454 |
if (widget == null && !tipShell.isDisposed()) { |
307 |
|
| 455 |
tipShell.setVisible(false); |
308 |
if (widget == null) { |
|
|
309 |
hideTooltip(); |
| 456 |
tipWidget = null; |
310 |
tipWidget = null; |
| 457 |
return; |
311 |
return; |
| 458 |
} |
312 |
} |
| 459 |
if (widget == tipWidget) |
|
|
| 460 |
return; |
| 461 |
tipWidget = widget; |
| 462 |
tipPosition = control.toDisplay(widgetPosition); |
| 463 |
String baseText = getBasicToolTextTip(widget); |
| 464 |
String scheduledText = getActivityText(getTaskListElement(widget)); |
| 465 |
String incommingText = getIncommingText(getTaskListElement(widget)); |
| 466 |
|
| 467 |
Image repositoryImage = getImage(widget); |
| 468 |
Image activityImage = TasksUiImages.getImage(TasksUiImages.CALENDAR); // TODO |
| 469 |
// Fixme |
| 470 |
Image incommingImage = TasksUiImages.getImage(TasksUiImages.OVERLAY_INCOMMING); |
| 471 |
|
| 472 |
if (baseText == null) { // HACK: don't check length |
| 473 |
return; |
| 474 |
} |
| 475 |
|
| 476 |
if (!tipShell.isDisposed() && tipShell.getShell() != null |
| 477 |
&& PlatformUI.getWorkbench().getDisplay().getActiveShell() != null) { |
| 478 |
tipShell.close(); |
| 479 |
tipShell = createTipShell(PlatformUI.getWorkbench().getDisplay().getActiveShell(), widget, |
| 480 |
scheduledText != null, incommingText != null); |
| 481 |
} |
| 482 |
|
313 |
|
| 483 |
AbstractTaskContainer element = getTaskListElement(widget); |
314 |
if (widget == tipWidget) { |
| 484 |
String progressText = updateContainerProgressBar(taskProgressBar, element); |
315 |
// already displaying tooltip |
| 485 |
|
316 |
return; |
| 486 |
String dateText = ""; |
|
|
| 487 |
if (element instanceof ScheduledTaskContainer) { |
| 488 |
Calendar start = ((ScheduledTaskContainer)element).getStart(); |
| 489 |
dateText += DateFormat.getDateInstance(DateFormat.LONG).format(start.getTime()) + "\n"; |
| 490 |
} |
| 491 |
|
| 492 |
tipLabelText.setText(dateText + baseText + progressText); |
| 493 |
tipLabelImage.setImage(repositoryImage); // accepts null |
| 494 |
|
| 495 |
if (scheduledText != null) { |
| 496 |
scheduledTipLabelText.setText(scheduledText); |
| 497 |
scheduledTipLabelImage.setImage(activityImage); // accepts |
| 498 |
// null |
| 499 |
} |
| 500 |
|
| 501 |
if (incommingText != null) { |
| 502 |
incommingTipLabelText.setText(incommingText); |
| 503 |
incommingTipLabelImage.setImage(incommingImage); // accepts |
| 504 |
// null |
| 505 |
} |
317 |
} |
| 506 |
|
318 |
|
| 507 |
tipShell.pack(); |
319 |
tipWidget = widget; |
| 508 |
setHoverLocation(tipShell, tipPosition); |
320 |
showTooltip(control.toDisplay(widgetPosition)); |
| 509 |
tipShell.setVisible(true); |
|
|
| 510 |
} |
321 |
} |
|
|
322 |
|
| 511 |
}); |
323 |
}); |
| 512 |
} |
324 |
} |
| 513 |
|
325 |
|
|
Lines 539-545
Link Here
|
| 539 |
shellBounds.x = displayBounds.x + displayBounds.width - shellBounds.width; |
351 |
shellBounds.x = displayBounds.x + displayBounds.width - shellBounds.width; |
| 540 |
else |
352 |
else |
| 541 |
shellBounds.x = position.x; |
353 |
shellBounds.x = position.x; |
| 542 |
|
354 |
|
| 543 |
if ((position.y + 10 + shellBounds.height) > (displayBounds.y + displayBounds.height)) |
355 |
if ((position.y + 10 + shellBounds.height) > (displayBounds.y + displayBounds.height)) |
| 544 |
shellBounds.y = displayBounds.y + displayBounds.height - shellBounds.height; |
356 |
shellBounds.y = displayBounds.y + displayBounds.height - shellBounds.height; |
| 545 |
else |
357 |
else |
|
Lines 549-555
Link Here
|
| 549 |
} |
361 |
} |
| 550 |
|
362 |
|
| 551 |
private void hideTooltip() { |
363 |
private void hideTooltip() { |
| 552 |
if (tipShell != null && !tipShell.isDisposed() && tipShell.isVisible()) |
364 |
// TODO: can these conditions be simplified? see bug 131776 |
| 553 |
tipShell.setVisible(false); |
365 |
if (tipShell != null && !tipShell.isDisposed() && tipShell.getDisplay() != null |
|
|
366 |
&& !tipShell.getDisplay().isDisposed() && tipShell.isVisible()) { |
| 367 |
// tipShell.setVisible(false); |
| 368 |
tipShell.close(); |
| 369 |
tipShell = null; |
| 370 |
} |
| 554 |
} |
371 |
} |
|
|
372 |
|
| 373 |
private void showTooltip(Point location) { |
| 374 |
hideTooltip(); |
| 375 |
|
| 376 |
AbstractTaskContainer element = getTaskListElement(tipWidget); |
| 377 |
String detailsText = getDetailsText(element); |
| 378 |
if (detailsText == null) { |
| 379 |
return; |
| 380 |
} |
| 381 |
|
| 382 |
Shell parent = PlatformUI.getWorkbench().getDisplay().getActiveShell(); |
| 383 |
if (parent == null) { |
| 384 |
return; |
| 385 |
} |
| 386 |
|
| 387 |
tipShell = new Shell(parent.getDisplay(), SWT.TOOL | SWT.NO_FOCUS | SWT.MODELESS | SWT.ON_TOP); |
| 388 |
GridLayout gridLayout = new GridLayout(); |
| 389 |
gridLayout.numColumns = 2; |
| 390 |
gridLayout.marginWidth = 2; |
| 391 |
gridLayout.marginHeight = 2; |
| 392 |
tipShell.setLayout(gridLayout); |
| 393 |
tipShell.setBackground(tipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 394 |
|
| 395 |
addIconAndLabel(tipShell, getImage(element), getTitleText(element)); |
| 396 |
|
| 397 |
addIconAndLabel(tipShell, null, detailsText); |
| 398 |
|
| 399 |
String statusText = getStatusText(element); |
| 400 |
if (statusText != null) { |
| 401 |
addIconAndLabel(tipShell, TasksUiImages.getImage(TasksUiImages.WARNING), statusText); |
| 402 |
} |
| 403 |
|
| 404 |
String activityText = getActivityText(element); |
| 405 |
if (activityText != null) { |
| 406 |
addIconAndLabel(tipShell, TasksUiImages.getImage(TasksUiImages.CALENDAR), activityText); |
| 407 |
} |
| 408 |
|
| 409 |
String incommingText = getIncommingText(element); |
| 410 |
if (incommingText != null) { |
| 411 |
addIconAndLabel(tipShell, TasksUiImages.getImage(TasksUiImages.OVERLAY_INCOMMING), incommingText); |
| 412 |
} |
| 413 |
|
| 414 |
ProgressData progress = getProgressData(element); |
| 415 |
if (progress != null) { |
| 416 |
addLabel(tipShell, progress.text); |
| 417 |
|
| 418 |
Composite progressComposite = new Composite(tipShell, SWT.NONE); |
| 419 |
GridLayout progressLayout = new GridLayout(1, false); |
| 420 |
progressLayout.marginWidth = 2; |
| 421 |
progressLayout.marginHeight = 0; |
| 422 |
progressLayout.marginBottom = 2; |
| 423 |
progressLayout.horizontalSpacing = 0; |
| 424 |
progressLayout.verticalSpacing = 0; |
| 425 |
progressComposite.setLayout(progressLayout); |
| 426 |
progressComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 4, 1)); |
| 427 |
|
| 428 |
WorkweekProgressBar taskProgressBar = new WorkweekProgressBar(progressComposite); |
| 429 |
taskProgressBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 430 |
taskProgressBar.reset(progress.completed, progress.total); |
| 431 |
} |
| 432 |
|
| 433 |
tipShell.pack(); |
| 434 |
setHoverLocation(tipShell, location); |
| 435 |
tipShell.setVisible(true); |
| 436 |
} |
| 437 |
|
| 438 |
private void addLabel(Shell parent, String text) { |
| 439 |
Label textLabel = new Label(parent, SWT.NONE); |
| 440 |
textLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 441 |
textLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 442 |
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); |
| 443 |
gd.horizontalSpan = 2; |
| 444 |
textLabel.setLayoutData(gd); |
| 445 |
textLabel.setText(removeTrailingNewline(text)); |
| 446 |
} |
| 447 |
|
| 448 |
private String removeTrailingNewline(String text) { |
| 449 |
if (text.endsWith("\n")) { |
| 450 |
return text.substring(0, text.length() - 1); |
| 451 |
} |
| 452 |
return text; |
| 453 |
} |
| 454 |
|
| 455 |
private void addIconAndLabel(Composite parent, Image image, String text) { |
| 456 |
Label imageLabel = new Label(parent, SWT.NONE); |
| 457 |
imageLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 458 |
imageLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 459 |
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); |
| 460 |
imageLabel.setLayoutData(gd); |
| 461 |
imageLabel.setImage(image); |
| 462 |
|
| 463 |
Label textLabel = new Label(parent, SWT.NONE); |
| 464 |
textLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 465 |
textLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 466 |
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER); |
| 467 |
textLabel.setLayoutData(gd); |
| 468 |
textLabel.setText(removeTrailingNewline(text)); |
| 469 |
} |
| 470 |
|
| 471 |
private static class ProgressData { |
| 472 |
|
| 473 |
int completed; |
| 474 |
|
| 475 |
int total; |
| 476 |
|
| 477 |
String text; |
| 478 |
|
| 479 |
public ProgressData(int completed, int total, String text) { |
| 480 |
this.completed = completed; |
| 481 |
this.total = total; |
| 482 |
this.text = text; |
| 483 |
} |
| 484 |
|
| 485 |
} |
| 486 |
|
| 555 |
} |
487 |
} |