Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 166406 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 166406