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 229294 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/progress/DetailedProgressViewer.java (-39 / +98 lines)
Lines 43-50 Link Here
43
 */
43
 */
44
public class DetailedProgressViewer extends AbstractProgressViewer {
44
public class DetailedProgressViewer extends AbstractProgressViewer {
45
45
46
	//Maximum number of entries to display so that the view does not flood the UI with events
46
	// Maximum number of entries to display so that the view does not flood the
47
	private static final int MAX_DISPLAYED = 20;
47
	// UI with events
48
	private static final int MAX_DISPLAYED = 100;
48
49
49
	Composite control;
50
	Composite control;
50
51
Lines 52-57 Link Here
52
53
53
	private Composite noEntryArea;
54
	private Composite noEntryArea;
54
55
56
	private Composite currentlyActiveControl;
57
55
	/**
58
	/**
56
	 * Create a new instance of the receiver with a control that is a child of
59
	 * Create a new instance of the receiver with a control that is a child of
57
	 * parent with style style.
60
	 * parent with style style.
Lines 61-79 Link Here
61
	 */
64
	 */
62
	public DetailedProgressViewer(Composite parent, int style) {
65
	public DetailedProgressViewer(Composite parent, int style) {
63
		scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | style);
66
		scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | style);
64
		int height = JFaceResources.getDefaultFont().getFontData()[0]
67
		int height = JFaceResources.getDefaultFont().getFontData()[0].getHeight();
65
				.getHeight();
66
		scrolled.getVerticalBar().setIncrement(height * 2);
68
		scrolled.getVerticalBar().setIncrement(height * 2);
67
		scrolled.setExpandHorizontal(true);
69
		scrolled.setExpandHorizontal(true);
68
		scrolled.setExpandVertical(true);
70
		scrolled.setExpandVertical(true);
69
71
70
		control = new Composite(scrolled, SWT.NONE);
72
		control = new Composite(scrolled, SWT.BORDER);
71
		GridLayout layout = new GridLayout();
73
		GridLayout layout = new GridLayout();
72
		layout.marginHeight = 0;
74
		layout.marginHeight = 0;
73
		layout.marginWidth = 0;
75
		layout.marginWidth = 0;
74
		control.setLayout(layout);
76
		control.setLayout(layout);
75
		control.setBackground(parent.getDisplay().getSystemColor(
77
		control.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
76
				SWT.COLOR_LIST_BACKGROUND));
77
78
78
		control.addFocusListener(new FocusAdapter() {
79
		control.addFocusListener(new FocusAdapter() {
79
80
Lines 95-109 Link Here
95
			}
96
			}
96
		});
97
		});
97
98
98
		control.addControlListener(new ControlListener() {
99
		scrolled.addControlListener(new ControlListener() {
100
			
101
99
			/*
102
			/*
100
			 * (non-Javadoc)
103
			 * (non-Javadoc)
101
			 * 
104
			 * 
102
			 * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
105
			 * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
103
			 */
106
			 */
104
			public void controlMoved(ControlEvent e) {
107
			public void controlMoved(ControlEvent e) {
105
				updateVisibleItems();
108
				updateSizes();
106
107
			}
109
			}
108
110
109
			/*
111
			/*
Lines 112-125 Link Here
112
			 * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
114
			 * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
113
			 */
115
			 */
114
			public void controlResized(ControlEvent e) {
116
			public void controlResized(ControlEvent e) {
115
				updateVisibleItems();
117
				updateSizes();
116
			}
118
			}
117
		});
119
		});
118
120
121
		
122
119
		PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
123
		PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
120
				IWorkbenchHelpContextIds.RESPONSIVE_UI);
124
				IWorkbenchHelpContextIds.RESPONSIVE_UI);
121
125
122
		scrolled.setContent(control);
123
		hookControl(control);
126
		hookControl(control);
124
127
125
		noEntryArea = new Composite(scrolled, SWT.NONE);
128
		noEntryArea = new Composite(scrolled, SWT.NONE);
Lines 136-141 Link Here
136
		PlatformUI.getWorkbench().getHelpSystem().setHelp(noEntryLabel,
139
		PlatformUI.getWorkbench().getHelpSystem().setHelp(noEntryLabel,
137
				IWorkbenchHelpContextIds.RESPONSIVE_UI);
140
				IWorkbenchHelpContextIds.RESPONSIVE_UI);
138
141
142
		updateForShowingProgress();
143
	}
144
145
	int doit = 0;
146
147
	 void updateSizes() {
148
		if (doit == 0) {
149
			doit--;
150
			scrolled.setRedraw(false);
151
152
			updateVisibleItems();
153
			
154
			if (currentlyActiveControl != null) {
155
				Point size = currentlyActiveControl.computeSize(scrolled.getClientArea().width,
156
						SWT.DEFAULT);
157
				size.x -= IDialogConstants.HORIZONTAL_SPACING;
158
				size.y -= IDialogConstants.VERTICAL_SPACING;
159
//				Rectangle r = currentlyActiveControl.getBounds();
160
//				r.getClass();
161
				scrolled.setMinHeight(size.y);
162
//				scrolled.setMinSize(size);
163
164
				scrolled.layout(true);
165
			}
166
167
168
			scrolled.setRedraw(true);
169
			doit++;
170
		}
139
	}
171
	}
140
172
141
	/*
173
	/*
Lines 167-172 Link Here
167
			sorter.sort(this, infos);
199
			sorter.sort(this, infos);
168
		}
200
		}
169
201
202
		control.setRedraw(false);
170
		// Update with the new elements to prevent flash
203
		// Update with the new elements to prevent flash
171
		for (int i = 0; i < existingChildren.length; i++) {
204
		for (int i = 0; i < existingChildren.length; i++) {
172
			((ProgressInfoItem) existingChildren[i]).dispose();
205
			((ProgressInfoItem) existingChildren[i]).dispose();
Lines 174-196 Link Here
174
207
175
		int totalSize = Math.min(newItems.size(), MAX_DISPLAYED);
208
		int totalSize = Math.min(newItems.size(), MAX_DISPLAYED);
176
209
210
		List newInfoItems = new ArrayList();
177
		for (int i = 0; i < totalSize; i++) {
211
		for (int i = 0; i < totalSize; i++) {
178
			ProgressInfoItem item = createNewItem(infos[i]);
212
			ProgressInfoItem item = createNewItem(infos[i]);
179
			item.setColor(i);
213
			item.setColor(i);
214
			newInfoItems.add(item);
180
		}
215
		}
181
216
182
		control.layout(true);
183
		updateForShowingProgress();
217
		updateForShowingProgress();
218
		
219
		updateSizes();
220
		
221
		updateVisibleItems();
222
		
223
		control.setRedraw(true);
184
	}
224
	}
185
225
186
	/**
226
	/**
187
	 * Update for the progress being displayed.
227
	 * Update for the progress being displayed.
188
	 */
228
	 */
189
	private void updateForShowingProgress() {
229
	private void updateForShowingProgress() {
230
		Composite oldActive = currentlyActiveControl;
190
		if (control.getChildren().length > 0) {
231
		if (control.getChildren().length > 0) {
191
			scrolled.setContent(control);
232
			currentlyActiveControl = control;
192
		} else {
233
		}
193
			scrolled.setContent(noEntryArea);
234
		else {
235
			currentlyActiveControl = noEntryArea;
236
		}
237
		if (oldActive != currentlyActiveControl) {
238
			scrolled.setContent(currentlyActiveControl);
194
		}
239
		}
195
	}
240
	}
196
241
Lines 201-208 Link Here
201
	 * @return ProgressInfoItem
246
	 * @return ProgressInfoItem
202
	 */
247
	 */
203
	private ProgressInfoItem createNewItem(JobTreeElement info) {
248
	private ProgressInfoItem createNewItem(JobTreeElement info) {
204
		final ProgressInfoItem item = new ProgressInfoItem(control, SWT.NONE,
249
		final ProgressInfoItem item = new ProgressInfoItem(control, SWT.NONE, info);
205
				info);
206
250
207
		item.setIndexListener(new ProgressInfoItem.IndexListener() {
251
		item.setIndexListener(new ProgressInfoItem.IndexListener() {
208
			/*
252
			/*
Lines 244-251 Link Here
244
			}
288
			}
245
		});
289
		});
246
290
247
		// Refresh to populate with the current tasks
248
		item.refresh();
249
		return item;
291
		return item;
250
	}
292
	}
251
293
Lines 262-268 Link Here
262
				ProgressInfoItem previous;
304
				ProgressInfoItem previous;
263
				if (i == 0) {
305
				if (i == 0) {
264
					previous = (ProgressInfoItem) children[children.length - 1];
306
					previous = (ProgressInfoItem) children[children.length - 1];
265
				} else {
307
				}
308
				else {
266
					previous = (ProgressInfoItem) children[i - 1];
309
					previous = (ProgressInfoItem) children[i - 1];
267
				}
310
				}
268
311
Lines 286-292 Link Here
286
				ProgressInfoItem next;
329
				ProgressInfoItem next;
287
				if (i == children.length - 1) {
330
				if (i == children.length - 1) {
288
					next = (ProgressInfoItem) children[0];
331
					next = (ProgressInfoItem) children[0];
289
				} else {
332
				}
333
				else {
290
					next = (ProgressInfoItem) children[i + 1];
334
					next = (ProgressInfoItem) children[i + 1];
291
				}
335
				}
292
				item.selectWidgets(false);
336
				item.selectWidgets(false);
Lines 315-322 Link Here
315
	protected Widget doFindItem(Object element) {
359
	protected Widget doFindItem(Object element) {
316
		Control[] existingChildren = control.getChildren();
360
		Control[] existingChildren = control.getChildren();
317
		for (int i = 0; i < existingChildren.length; i++) {
361
		for (int i = 0; i < existingChildren.length; i++) {
318
			if (existingChildren[i].isDisposed()
362
			if (existingChildren[i].isDisposed() || existingChildren[i].getData() == null) {
319
					|| existingChildren[i].getData() == null) {
320
				continue;
363
				continue;
321
			}
364
			}
322
			if (existingChildren[i].getData().equals(element)) {
365
			if (existingChildren[i].getData().equals(element)) {
Lines 337-343 Link Here
337
			unmapElement(item);
380
			unmapElement(item);
338
		}
381
		}
339
		item.dispose();
382
		item.dispose();
340
		add(new Object[] { element });
383
		add(new Object[] {
384
			element
385
		});
341
	}
386
	}
342
387
343
	/*
388
	/*
Lines 376-381 Link Here
376
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
421
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
377
	 */
422
	 */
378
	protected void internalRefresh(Object element) {
423
	protected void internalRefresh(Object element) {
424
379
		if (element == null) {
425
		if (element == null) {
380
			return;
426
			return;
381
		}
427
		}
Lines 386-402 Link Here
386
		}
432
		}
387
		Widget widget = findItem(element);
433
		Widget widget = findItem(element);
388
		if (widget == null) {
434
		if (widget == null) {
389
			add(new Object[] { element });
435
			add(new Object[] {
436
				element
437
			});
390
			return;
438
			return;
391
		}
439
		}
392
		((ProgressInfoItem) widget).refresh();
440
		
393
441
394
		// Update the minimum size
442
		// Update the minimum size
395
		Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
443
		updateSizes();
396
		size.x += IDialogConstants.HORIZONTAL_SPACING;
397
		size.y += IDialogConstants.VERTICAL_SPACING;
398
444
399
		scrolled.setMinSize(size);
445
		((ProgressInfoItem) widget).refresh();
446
		
447
		updateVisibleItems();
400
	}
448
	}
401
449
402
	/*
450
	/*
Lines 406-411 Link Here
406
	 */
454
	 */
407
	public void remove(Object[] elements) {
455
	public void remove(Object[] elements) {
408
456
457
		control.setRedraw(false);
409
		for (int i = 0; i < elements.length; i++) {
458
		for (int i = 0; i < elements.length; i++) {
410
			JobTreeElement treeElement = (JobTreeElement) elements[i];
459
			JobTreeElement treeElement = (JobTreeElement) elements[i];
411
			// Make sure we are not keeping this one
460
			// Make sure we are not keeping this one
Lines 415-421 Link Here
415
					((ProgressInfoItem) item).refresh();
464
					((ProgressInfoItem) item).refresh();
416
				}
465
				}
417
466
418
			} else {
467
			}
468
			else {
419
				Widget item = doFindItem(treeElement);
469
				Widget item = doFindItem(treeElement);
420
				if (item == null) {
470
				if (item == null) {
421
					// Is the parent showing?
471
					// Is the parent showing?
Lines 435-442 Link Here
435
			ProgressInfoItem item = (ProgressInfoItem) existingChildren[i];
485
			ProgressInfoItem item = (ProgressInfoItem) existingChildren[i];
436
			item.setColor(i);
486
			item.setColor(i);
437
		}
487
		}
438
		control.layout(true);
439
		updateForShowingProgress();
488
		updateForShowingProgress();
489
		control.layout(true);
490
491
		control.setRedraw(true);
440
	}
492
	}
441
493
442
	/*
494
	/*
Lines 478-484 Link Here
478
				item.setButtonFocus();
530
				item.setButtonFocus();
479
				return;
531
				return;
480
			}
532
			}
481
		} else
533
		}
534
		else
482
			noEntryArea.setFocus();
535
			noEntryArea.setFocus();
483
	}
536
	}
484
537
Lines 487-510 Link Here
487
	 */
540
	 */
488
	private void refreshAll() {
541
	private void refreshAll() {
489
542
543
		control.setRedraw(false);
490
		Object[] infos = getSortedChildren(getRoot());
544
		Object[] infos = getSortedChildren(getRoot());
491
		Control[] existingChildren = control.getChildren();
545
		Control[] existingChildren = control.getChildren();
492
546
493
		for (int i = 0; i < existingChildren.length; i++) {
547
		for (int i = 0; i < existingChildren.length; i++) {
494
			existingChildren[i].dispose();
548
			existingChildren[i].dispose();
495
496
		}
549
		}
497
		
550
498
		int maxLength = Math.min(infos.length,MAX_DISPLAYED);
551
		int maxLength = Math.min(infos.length, MAX_DISPLAYED);
499
		// Create new ones if required
552
		// Create new ones if required
500
		for (int i = 0; i < maxLength; i++) {
553
		for (int i = 0; i < maxLength; i++) {
501
			ProgressInfoItem item = createNewItem((JobTreeElement) infos[i]);
554
			ProgressInfoItem item = createNewItem((JobTreeElement) infos[i]);
502
			item.setColor(i);
555
			item.setColor(i);
503
		}
556
		}
504
557
505
		control.layout(true);
506
		updateForShowingProgress();
507
558
559
//		updateForShowingProgress();
560
		scrolled.setContent(currentlyActiveControl);
561
		
562
		updateSizes();
563
		
564
		updateVisibleItems();
565
		
566
		control.setRedraw(true);
508
	}
567
	}
509
568
510
	/**
569
	/**
(-)Eclipse UI/org/eclipse/ui/internal/progress/ProgressInfoItem.java (-293 / +318 lines)
Lines 11-21 Link Here
11
 *     IBM Corporation - initial API and implementation
11
 *     IBM Corporation - initial API and implementation
12
 *******************************************************************************/
12
 *******************************************************************************/
13
import java.net.URL;
13
import java.net.URL;
14
import com.ibm.icu.text.DateFormat;
15
import java.util.ArrayList;
16
import java.util.Date;
14
import java.util.Date;
17
import java.util.Iterator;
15
import java.util.Iterator;
18
import java.util.List;
16
import java.util.LinkedList;
17
import java.util.ListIterator;
19
18
20
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
Lines 23-28 Link Here
23
import org.eclipse.jface.action.IAction;
22
import org.eclipse.jface.action.IAction;
24
import org.eclipse.jface.dialogs.Dialog;
23
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.dialogs.IDialogConstants;
24
import org.eclipse.jface.dialogs.IDialogConstants;
25
import org.eclipse.jface.layout.GridDataFactory;
26
import org.eclipse.jface.layout.GridLayoutFactory;
26
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.resource.JFaceResources;
28
import org.eclipse.jface.resource.JFaceResources;
28
import org.eclipse.jface.resource.LocalResourceManager;
29
import org.eclipse.jface.resource.LocalResourceManager;
Lines 33-43 Link Here
33
import org.eclipse.swt.events.MouseEvent;
34
import org.eclipse.swt.events.MouseEvent;
34
import org.eclipse.swt.events.SelectionAdapter;
35
import org.eclipse.swt.events.SelectionAdapter;
35
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.graphics.*;
37
import org.eclipse.swt.graphics.Color;
37
import org.eclipse.swt.layout.FormAttachment;
38
import org.eclipse.swt.graphics.Image;
38
import org.eclipse.swt.layout.FormData;
39
import org.eclipse.swt.graphics.Point;
39
import org.eclipse.swt.layout.FormLayout;
40
import org.eclipse.swt.graphics.RGB;
41
import org.eclipse.swt.graphics.Rectangle;
40
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.RowLayout;
41
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Composite;
42
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.Event;
46
import org.eclipse.swt.widgets.Event;
Lines 51-56 Link Here
51
import org.eclipse.ui.internal.WorkbenchImages;
54
import org.eclipse.ui.internal.WorkbenchImages;
52
import org.eclipse.ui.progress.IProgressConstants;
55
import org.eclipse.ui.progress.IProgressConstants;
53
56
57
import com.ibm.icu.text.DateFormat;
58
54
/**
59
/**
55
 * ProgressInfoItem is the item used to show jobs.
60
 * ProgressInfoItem is the item used to show jobs.
56
 * 
61
 * 
Lines 79-85 Link Here
79
84
80
	ToolItem actionButton;
85
	ToolItem actionButton;
81
86
82
	List taskEntries = new ArrayList(0);
87
	LinkedList taskEntries = new LinkedList();
83
88
84
	private ProgressBar progressBar;
89
	private ProgressBar progressBar;
85
90
Lines 89-98 Link Here
89
94
90
	static final int MIN_ICON_SIZE = 16;
95
	static final int MIN_ICON_SIZE = 16;
91
96
97
	private static final int DIRECTION = SWT.VERTICAL;
98
92
	private static final String TEXT_KEY = "Text"; //$NON-NLS-1$
99
	private static final String TEXT_KEY = "Text"; //$NON-NLS-1$
93
100
94
	private static final String ACTION_KEY = "Action";//$NON-NLS-1$
101
	private static final String ACTION_KEY = "Action";//$NON-NLS-1$
95
102
103
	private static final String JOB = "Job";//$NON-NLS-1$
104
96
	interface IndexListener {
105
	interface IndexListener {
97
		/**
106
		/**
98
		 * Select the item previous to the receiver.
107
		 * Select the item previous to the receiver.
Lines 122-174 Link Here
122
131
123
	private ResourceManager resourceManager;
132
	private ResourceManager resourceManager;
124
133
134
	private Composite linkComposite;
135
125
	static {
136
	static {
126
		JFaceResources
137
		JFaceResources.getImageRegistry().put(STOP_IMAGE_KEY,
127
				.getImageRegistry()
138
				WorkbenchImages.getWorkbenchImageDescriptor("elcl16/progress_stop.gif"));//$NON-NLS-1$
128
				.put(
139
129
						STOP_IMAGE_KEY,
140
		JFaceResources.getImageRegistry().put(DISABLED_STOP_IMAGE_KEY,
130
						WorkbenchImages
141
				WorkbenchImages.getWorkbenchImageDescriptor("dlcl16/progress_stop.gif"));//$NON-NLS-1$
131
								.getWorkbenchImageDescriptor("elcl16/progress_stop.gif"));//$NON-NLS-1$
142
132
143
		JFaceResources.getImageRegistry().put(DEFAULT_JOB_KEY,
133
		JFaceResources
144
				WorkbenchImages.getWorkbenchImageDescriptor("progress/progress_task.gif")); //$NON-NLS-1$
134
				.getImageRegistry()
145
135
				.put(
146
		JFaceResources.getImageRegistry().put(CLEAR_FINISHED_JOB_KEY,
136
						DISABLED_STOP_IMAGE_KEY,
147
				WorkbenchImages.getWorkbenchImageDescriptor("elcl16/progress_rem.gif")); //$NON-NLS-1$
137
						WorkbenchImages
148
138
								.getWorkbenchImageDescriptor("dlcl16/progress_stop.gif"));//$NON-NLS-1$
149
		JFaceResources.getImageRegistry().put(DISABLED_CLEAR_FINISHED_JOB_KEY,
139
150
				WorkbenchImages.getWorkbenchImageDescriptor("dlcl16/progress_rem.gif")); //$NON-NLS-1$
140
		JFaceResources
141
				.getImageRegistry()
142
				.put(
143
						DEFAULT_JOB_KEY,
144
						WorkbenchImages
145
								.getWorkbenchImageDescriptor("progress/progress_task.gif")); //$NON-NLS-1$
146
147
		JFaceResources
148
				.getImageRegistry()
149
				.put(
150
						CLEAR_FINISHED_JOB_KEY,
151
						WorkbenchImages
152
								.getWorkbenchImageDescriptor("elcl16/progress_rem.gif")); //$NON-NLS-1$
153
154
		JFaceResources
155
				.getImageRegistry()
156
				.put(
157
						DISABLED_CLEAR_FINISHED_JOB_KEY,
158
						WorkbenchImages
159
								.getWorkbenchImageDescriptor("dlcl16/progress_rem.gif")); //$NON-NLS-1$
160
151
161
		// Mac has different Gamma value
152
		// Mac has different Gamma value
162
		int shift = "carbon".equals(SWT.getPlatform()) ? -25 : -10;//$NON-NLS-1$ 
153
		int shift = "carbon".equals(SWT.getPlatform()) ? -25 : -10;//$NON-NLS-1$ 
163
154
164
		Color lightColor = PlatformUI.getWorkbench().getDisplay()
155
		Color lightColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(
165
				.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
156
				SWT.COLOR_LIST_BACKGROUND);
166
157
167
		// Determine a dark color by shifting the list color
158
		// Determine a dark color by shifting the list color
168
		RGB darkRGB = new RGB(Math.max(0, lightColor.getRed() + shift), Math
159
		RGB darkRGB = new RGB(Math.max(0, lightColor.getRed() + shift), Math.max(0, lightColor
169
				.max(0, lightColor.getGreen() + shift), Math.max(0, lightColor
160
				.getGreen()
170
				.getBlue()
161
				+ shift), Math.max(0, lightColor.getBlue() + shift));
171
				+ shift));
172
		JFaceResources.getColorRegistry().put(DARK_COLOR_KEY, darkRGB);
162
		JFaceResources.getColorRegistry().put(DARK_COLOR_KEY, darkRGB);
173
	}
163
	}
174
164
Lines 180-192 Link Here
180
	 * @param style
170
	 * @param style
181
	 * @param progressInfo
171
	 * @param progressInfo
182
	 */
172
	 */
183
	public ProgressInfoItem(Composite parent, int style,
173
	public ProgressInfoItem(Composite parent, int style, JobTreeElement progressInfo) {
184
			JobTreeElement progressInfo) {
185
		super(parent, style);
174
		super(parent, style);
175
		setBackgroundMode(SWT.INHERIT_FORCE);
186
		info = progressInfo;
176
		info = progressInfo;
187
		createChildren();
177
		createChildren();
188
		setData(info);
178
		setData(info);
189
		setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
179
		setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
180
		addListener(SWT.Resize, new Listener() {
181
182
			public void handleEvent(Event event) {
183
184
				refresh();
185
186
				Point p = new Point(SWT.DEFAULT, SWT.DEFAULT);
187
				if (linkComposite != null) {
188
					Rectangle area = linkComposite.getClientArea();
189
					p = new Point(area.width, area.height);
190
				}
191
				updateSizes(p, true);
192
			}
193
		});
194
	}
195
196
	private int doit = 0;
197
198
	private void updateSizes(Point contraints, boolean performLayout) {
199
200
		if (doit == 0) {
201
			setMainText();
202
203
			if (linkComposite != null) {
204
205
				if (DIRECTION == SWT.HORIZONTAL) {
206
					Point preferred = linkComposite.computeSize(contraints.x, SWT.DEFAULT);
207
					GridData data = (GridData) linkComposite.getLayoutData();
208
					data.heightHint = preferred.y;
209
				}
210
				else {
211
					Point preferred = linkComposite.computeSize(SWT.DEFAULT, contraints.y);
212
					GridData data = (GridData) linkComposite.getLayoutData();
213
					data.widthHint = preferred.x;
214
				}
215
216
			}
217
218
			doit--;
219
			if (performLayout) {
220
				layout(true);
221
			}
222
			doit++;
223
		}
190
	}
224
	}
191
225
192
	/**
226
	/**
Lines 197-228 Link Here
197
	 */
231
	 */
198
	protected void createChildren() {
232
	protected void createChildren() {
199
233
200
		FormLayout layout = new FormLayout();
234
		GridLayoutFactory.fillDefaults().numColumns(3).extendedMargins(
201
		setLayout(layout);
235
				IDialogConstants.HORIZONTAL_SPACING / 2, IDialogConstants.HORIZONTAL_SPACING / 2,
236
				IDialogConstants.VERTICAL_SPACING / 2, IDialogConstants.VERTICAL_SPACING / 2)
237
				.applyTo(this);
202
238
203
		jobImageLabel = new Label(this, SWT.NONE);
239
		jobImageLabel = new Label(this, SWT.NONE);
204
		jobImageLabel.setImage(getInfoImage());
240
		jobImageLabel.setImage(getInfoImage());
205
		FormData imageData = new FormData();
241
		GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).span(1, 3).hint(20, 20)
206
		imageData.top = new FormAttachment(IDialogConstants.VERTICAL_SPACING);
242
				.applyTo(jobImageLabel);
207
		imageData.left = new FormAttachment(
208
				IDialogConstants.HORIZONTAL_SPACING / 2);
209
		jobImageLabel.setLayoutData(imageData);
210
243
211
		progressLabel = new Label(this, SWT.NONE);
244
		progressLabel = new Label(this, SWT.NONE);
212
		setMainText();
245
		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(
246
				progressLabel);
247
248
		actionBar = new ToolBar(this, SWT.NONE);
249
		GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).span(1, 3).applyTo(actionBar);
213
250
214
		actionBar = new ToolBar(this, SWT.FLAT);
215
		actionBar.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); // set
251
		actionBar.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); // set
216
		// cursor
252
		// cursor to overwrite any busy
217
		// to
218
		// overwrite
219
		// any
220
		// busy
221
253
222
		// cursor we might have
254
		// cursor we might have
223
		actionButton = new ToolItem(actionBar, SWT.NONE);
255
		actionButton = new ToolItem(actionBar, SWT.NONE);
224
		actionButton
256
		actionButton.setToolTipText(ProgressMessages.NewProgressView_CancelJobToolTip);
225
				.setToolTipText(ProgressMessages.NewProgressView_CancelJobToolTip);
226
		actionButton.addSelectionListener(new SelectionAdapter() {
257
		actionButton.addSelectionListener(new SelectionAdapter() {
227
			public void widgetSelected(SelectionEvent e) {
258
			public void widgetSelected(SelectionEvent e) {
228
				actionButton.setEnabled(false);
259
				actionButton.setEnabled(false);
Lines 252-265 Link Here
252
		});
283
		});
253
		updateToolBarValues();
284
		updateToolBarValues();
254
285
255
		FormData progressData = new FormData();
256
		progressData.top = new FormAttachment(IDialogConstants.VERTICAL_SPACING);
257
		progressData.left = new FormAttachment(jobImageLabel,
258
				IDialogConstants.HORIZONTAL_SPACING / 2);
259
		progressData.right = new FormAttachment(actionBar,
260
				IDialogConstants.HORIZONTAL_SPACING);
261
		progressLabel.setLayoutData(progressData);
262
263
		mouseListener = new MouseAdapter() {
286
		mouseListener = new MouseAdapter() {
264
			/*
287
			/*
265
			 * (non-Javadoc)
288
			 * (non-Javadoc)
Lines 276-283 Link Here
276
		jobImageLabel.addMouseListener(mouseListener);
299
		jobImageLabel.addMouseListener(mouseListener);
277
		progressLabel.addMouseListener(mouseListener);
300
		progressLabel.addMouseListener(mouseListener);
278
301
279
		setLayoutsForNoProgress();
280
281
		refresh();
302
		refresh();
282
	}
303
	}
283
304
Lines 285-315 Link Here
285
	 * Set the main text of the receiver. Truncate to fit the available space.
306
	 * Set the main text of the receiver. Truncate to fit the available space.
286
	 */
307
	 */
287
	private void setMainText() {
308
	private void setMainText() {
288
		progressLabel
309
		progressLabel.setText(Dialog.shortenText(getMainTitle(), progressLabel));
289
				.setText(Dialog.shortenText(getMainTitle(), progressLabel));
290
	}
291
292
	/**
293
	 * Set the layout of the widgets for the no progress case.
294
	 * 
295
	 */
296
	private void setLayoutsForNoProgress() {
297
298
		FormData buttonData = new FormData();
299
		buttonData.top = new FormAttachment(progressLabel, 0, SWT.TOP);
300
		buttonData.right = new FormAttachment(100,
301
				IDialogConstants.HORIZONTAL_SPACING * -1);
302
303
		actionBar.setLayoutData(buttonData);
304
		if (taskEntries.size() > 0) {
305
			FormData linkData = new FormData();
306
			linkData.top = new FormAttachment(progressLabel,
307
					IDialogConstants.VERTICAL_SPACING);
308
			linkData.left = new FormAttachment(progressLabel, 0, SWT.LEFT);
309
			linkData.right = new FormAttachment(actionBar, 0, SWT.LEFT);
310
			((Link) taskEntries.get(0)).setLayoutData(linkData);
311
312
		}
313
	}
310
	}
314
311
315
	/**
312
	/**
Lines 317-326 Link Here
317
	 * 
314
	 * 
318
	 */
315
	 */
319
	protected void cancelOrRemove() {
316
	protected void cancelOrRemove() {
320
317
		JobInfo[] infos = getJobInfos();
321
		if (FinishedJobs.getInstance().isKept(info) && isCompleted()) {
318
		if (FinishedJobs.getInstance().isKept(info) && isCompleted(infos)) {
322
			FinishedJobs.getInstance().remove(info);
319
			FinishedJobs.getInstance().remove(info);
323
		} else {
320
		}
321
		else {
324
			info.cancel();
322
			info.cancel();
325
		}
323
		}
326
324
Lines 340-358 Link Here
340
		JobInfo jobInfo = (JobInfo) info;
338
		JobInfo jobInfo = (JobInfo) info;
341
339
342
		ImageDescriptor descriptor = null;
340
		ImageDescriptor descriptor = null;
343
		Object property = jobInfo.getJob().getProperty(
341
		Object property = jobInfo.getJob().getProperty(IProgressConstants.ICON_PROPERTY);
344
				IProgressConstants.ICON_PROPERTY);
345
342
346
		if (property instanceof ImageDescriptor) {
343
		if (property instanceof ImageDescriptor) {
347
			descriptor = (ImageDescriptor) property;
344
			descriptor = (ImageDescriptor) property;
348
		} else if (property instanceof URL) {
345
		}
346
		else if (property instanceof URL) {
349
			descriptor = ImageDescriptor.createFromURL((URL) property);
347
			descriptor = ImageDescriptor.createFromURL((URL) property);
350
		}
348
		}
351
349
352
		Image image = null;
350
		Image image = null;
353
		if (descriptor == null) {
351
		if (descriptor == null) {
354
			image = ProgressManager.getInstance().getIconFor(jobInfo.getJob());
352
			image = ProgressManager.getInstance().getIconFor(jobInfo.getJob());
355
		} else {
353
		}
354
		else {
356
			image = getResourceManager().createImageWithDefault(descriptor);
355
			image = getResourceManager().createImageWithDefault(descriptor);
357
		}
356
		}
358
357
Lines 369-376 Link Here
369
	 */
368
	 */
370
	private ResourceManager getResourceManager() {
369
	private ResourceManager getResourceManager() {
371
		if (resourceManager == null)
370
		if (resourceManager == null)
372
			resourceManager = new LocalResourceManager(JFaceResources
371
			resourceManager = new LocalResourceManager(JFaceResources.getResources());
373
					.getResources());
374
		return resourceManager;
372
		return resourceManager;
375
	}
373
	}
376
374
Lines 407-421 Link Here
407
405
408
		if (jobInfo.isCanceled()) {
406
		if (jobInfo.isCanceled()) {
409
			if (job.getState() == Job.RUNNING)
407
			if (job.getState() == Job.RUNNING)
410
				return NLS
408
				return NLS.bind(ProgressMessages.JobInfo_Cancel_Requested, name);
411
						.bind(ProgressMessages.JobInfo_Cancel_Requested, name);
412
			return NLS.bind(ProgressMessages.JobInfo_Cancelled, name);
409
			return NLS.bind(ProgressMessages.JobInfo_Cancelled, name);
413
		}
410
		}
414
411
415
		if (jobInfo.isBlocked()) {
412
		if (jobInfo.isBlocked()) {
416
			IStatus blockedStatus = jobInfo.getBlockedStatus();
413
			IStatus blockedStatus = jobInfo.getBlockedStatus();
417
			return NLS.bind(ProgressMessages.JobInfo_Blocked, name,
414
			return NLS.bind(ProgressMessages.JobInfo_Blocked, name, blockedStatus.getMessage());
418
					blockedStatus.getMessage());
419
		}
415
		}
420
416
421
		switch (job.getState()) {
417
		switch (job.getState()) {
Lines 446-453 Link Here
446
			time = getTimeString();
442
			time = getTimeString();
447
		}
443
		}
448
		if (time != null) {
444
		if (time != null) {
449
			return NLS.bind(ProgressMessages.JobInfo_FinishedAt, job.getName(),
445
			return NLS.bind(ProgressMessages.JobInfo_FinishedAt, job.getName(), time);
450
					time);
451
		}
446
		}
452
		return NLS.bind(ProgressMessages.JobInfo_Finished, job.getName());
447
		return NLS.bind(ProgressMessages.JobInfo_Finished, job.getName());
453
	}
448
	}
Lines 476-481 Link Here
476
		if (isDisposed() || !isShowing)
471
		if (isDisposed() || !isShowing)
477
			return;
472
			return;
478
473
474
		setRedraw(false);
475
479
		jobImageLabel.setImage(getInfoImage());
476
		jobImageLabel.setImage(getInfoImage());
480
		int percentDone = getPercentDone();
477
		int percentDone = getPercentDone();
481
478
Lines 493-499 Link Here
493
							break;
490
							break;
494
						}
491
						}
495
					}
492
					}
496
				} else {
493
				}
494
				else {
497
					createProgressBar(SWT.NONE);
495
					createProgressBar(SWT.NONE);
498
					progressBar.setMinimum(0);
496
					progressBar.setMinimum(0);
499
					progressBar.setMaximum(100);
497
					progressBar.setMaximum(100);
Lines 501-519 Link Here
501
			}
499
			}
502
500
503
			// Protect against bad counters
501
			// Protect against bad counters
504
			if (percentDone >= 0 && percentDone <= 100
502
			if (percentDone >= 0 && percentDone <= 100 && percentDone != progressBar.getSelection()) {
505
					&& percentDone != progressBar.getSelection()) {
506
				progressBar.setSelection(percentDone);
503
				progressBar.setSelection(percentDone);
507
			}
504
			}
508
		}
505
		}
509
506
510
		else if (isCompleted()) {
507
		else if (isCompleted(infos)) {
511
508
512
			if (progressBar != null) {
509
			if (progressBar != null) {
513
				progressBar.dispose();
510
				progressBar.dispose();
514
				progressBar = null;
511
				progressBar = null;
515
			}
512
			}
516
			setLayoutsForNoProgress();
517
513
518
		}
514
		}
519
515
Lines 525-554 Link Here
525
				String subTaskString = null;
521
				String subTaskString = null;
526
				Object[] jobChildren = jobInfo.getChildren();
522
				Object[] jobChildren = jobInfo.getChildren();
527
				if (jobChildren.length > 0) {
523
				if (jobChildren.length > 0) {
528
					subTaskString = ((JobTreeElement) jobChildren[0])
524
					subTaskString = ((JobTreeElement) jobChildren[0]).getDisplayString();
529
							.getDisplayString();
530
				}
525
				}
531
526
532
				if (subTaskString != null) {
527
				if (subTaskString != null) {
533
					if (taskString == null || taskString.length() == 0) {
528
					if (taskString == null || taskString.length() == 0) {
534
						taskString = subTaskString;
529
						taskString = subTaskString;
535
					} else {
530
					}
536
						taskString = NLS.bind(
531
					else {
537
								ProgressMessages.JobInfo_DoneNoProgressMessage,
532
						taskString = NLS.bind(ProgressMessages.JobInfo_DoneNoProgressMessage,
538
								taskString, subTaskString);
533
								taskString, subTaskString);
539
					}
534
					}
540
				}
535
				}
541
				if (taskString != null) {
536
				if (taskString != null) {
542
					setLinkText(infos[i].getJob(), taskString, i);
537
					setLinkText(infos[i].getJob(), taskString, i);
543
				}
538
				}
544
			} else {// Check for the finished job state
539
			}
540
			else {// Check for the finished job state
545
				Job job = jobInfo.getJob();
541
				Job job = jobInfo.getJob();
546
				IStatus result = job.getResult();
542
				IStatus result = job.getResult();
547
543
548
				if (result == null || result.getMessage().length() == 0
544
				if (result == null || result.getMessage().length() == 0 && !info.isJobInfo()) {
549
						&& !info.isJobInfo()) {
545
					setLinkText(job, null, i);
550
					setLinkText(job, getJobNameAndStatus(jobInfo), i);
546
				}
551
				} else {
547
				else {
552
					setLinkText(job, result.getMessage(), i);
548
					setLinkText(job, result.getMessage(), i);
553
549
554
				}
550
				}
Lines 564-576 Link Here
564
560
565
			}
561
			}
566
			if (infos.length > 1)
562
			if (infos.length > 1)
567
				taskEntries = taskEntries.subList(0, infos.length - 1);
563
				taskEntries.subList(0, infos.length - 1).clear();
568
			else
564
			else
569
				taskEntries.clear();
565
				taskEntries.clear();
570
		}
566
		}
571
567
572
		updateToolBarValues();
568
		updateToolBarValues();
573
		setMainText();
569
570
		setRedraw(true);
574
	}
571
	}
575
572
576
	/**
573
	/**
Lines 578-586 Link Here
578
	 * 
575
	 * 
579
	 * @return boolean <code>true</code> if the state is Job#NONE.
576
	 * @return boolean <code>true</code> if the state is Job#NONE.
580
	 */
577
	 */
581
	private boolean isCompleted() {
578
	private boolean isCompleted(JobInfo[] infos) {
582
579
583
		JobInfo[] infos = getJobInfos();
584
		for (int i = 0; i < infos.length; i++) {
580
		for (int i = 0; i < infos.length; i++) {
585
			if (infos[i].getJob().getState() != Job.NONE) {
581
			if (infos[i].getJob().getState() != Job.NONE) {
586
				return false;
582
				return false;
Lines 597-603 Link Here
597
	 */
593
	 */
598
	private JobInfo[] getJobInfos() {
594
	private JobInfo[] getJobInfos() {
599
		if (info.isJobInfo()) {
595
		if (info.isJobInfo()) {
600
			return new JobInfo[] { (JobInfo) info };
596
			return new JobInfo[] {
597
				(JobInfo) info
598
			};
601
		}
599
		}
602
		Object[] children = info.getChildren();
600
		Object[] children = info.getChildren();
603
		JobInfo[] infos = new JobInfo[children.length];
601
		JobInfo[] infos = new JobInfo[children.length];
Lines 650-673 Link Here
650
	 * 
648
	 * 
651
	 */
649
	 */
652
	private void updateToolBarValues() {
650
	private void updateToolBarValues() {
653
		if (isCompleted()) {
651
		JobInfo[] infos = getJobInfos();
654
			actionButton.setImage(JFaceResources
652
		if (isCompleted(infos)) {
655
					.getImage(CLEAR_FINISHED_JOB_KEY));
653
			actionButton.setImage(JFaceResources.getImage(CLEAR_FINISHED_JOB_KEY));
656
			actionButton.setDisabledImage(JFaceResources
654
			actionButton.setDisabledImage(JFaceResources.getImage(DISABLED_CLEAR_FINISHED_JOB_KEY));
657
					.getImage(DISABLED_CLEAR_FINISHED_JOB_KEY));
655
			actionButton.setToolTipText(ProgressMessages.NewProgressView_ClearJobToolTip);
658
			actionButton
656
		}
659
					.setToolTipText(ProgressMessages.NewProgressView_ClearJobToolTip);
657
		else {
660
		} else {
661
			actionButton.setImage(JFaceResources.getImage(STOP_IMAGE_KEY));
658
			actionButton.setImage(JFaceResources.getImage(STOP_IMAGE_KEY));
662
			actionButton.setDisabledImage(JFaceResources
659
			actionButton.setDisabledImage(JFaceResources.getImage(DISABLED_STOP_IMAGE_KEY));
663
					.getImage(DISABLED_STOP_IMAGE_KEY));
664
660
665
		}
661
		}
666
		JobInfo[] infos = getJobInfos();
667
662
668
		for (int i = 0; i < infos.length; i++) {
663
		for (int i = 0; i < infos.length; i++) {
669
			// Only disable if there is an unresponsive operation
664
			// Only disable if there is an unresponsive operation
670
			if (infos[i].isCanceled() && !isCompleted()) {
665
			if (infos[i].isCanceled() && !isCompleted(infos)) {
671
				actionButton.setEnabled(false);
666
				actionButton.setEnabled(false);
672
				return;
667
				return;
673
			}
668
			}
Lines 682-718 Link Here
682
	 */
677
	 */
683
	void createProgressBar(int style) {
678
	void createProgressBar(int style) {
684
679
685
		FormData buttonData = new FormData();
686
		buttonData.top = new FormAttachment(progressLabel, 0);
687
		buttonData.right = new FormAttachment(100,
688
				IDialogConstants.HORIZONTAL_SPACING * -1);
689
690
		actionBar.setLayoutData(buttonData);
691
692
		progressBar = new ProgressBar(this, SWT.HORIZONTAL | style);
680
		progressBar = new ProgressBar(this, SWT.HORIZONTAL | style);
693
		FormData barData = new FormData();
681
		progressBar.addMouseListener(mouseListener);
694
		barData.top = new FormAttachment(actionBar,
682
		if (linkComposite != null) {
695
				IDialogConstants.VERTICAL_SPACING, SWT.TOP);
683
			progressBar.moveAbove(linkComposite);
696
		barData.left = new FormAttachment(progressLabel, 0, SWT.LEFT);
697
		barData.right = new FormAttachment(actionBar,
698
				IDialogConstants.HORIZONTAL_SPACING * -1);
699
		barData.height = MAX_PROGRESS_HEIGHT;
700
		barData.width = 0;// default is too large
701
		progressBar.setLayoutData(barData);
702
703
		if (taskEntries.size() > 0) {
704
			// Reattach the link label if there is one
705
			FormData linkData = new FormData();
706
			linkData.top = new FormAttachment(progressBar,
707
					IDialogConstants.VERTICAL_SPACING);
708
			linkData.left = new FormAttachment(
709
					IDialogConstants.HORIZONTAL_SPACING);
710
			linkData.right = new FormAttachment(progressBar, 0, SWT.RIGHT);
711
			// Give an initial value so as to constrain the link shortening
712
			linkData.width = IDialogConstants.INDENT;
713
714
			((Link) taskEntries.get(0)).setLayoutData(linkData);
715
		}
684
		}
685
		GridDataFactory.swtDefaults().hint(SWT.DEFAULT, MAX_PROGRESS_HEIGHT).align(SWT.FILL,
686
				SWT.CENTER).applyTo(progressBar);
687
716
	}
688
	}
717
689
718
	/**
690
	/**
Lines 722-810 Link Here
722
	 */
694
	 */
723
	void setLinkText(Job linkJob, String taskString, int index) {
695
	void setLinkText(Job linkJob, String taskString, int index) {
724
696
725
		Link link;
697
		Control subTaskControl = null;
726
		if (index >= taskEntries.size()) {// Is it new?
698
		if (index >= taskEntries.size()) {// Is it new?
727
			link = new Link(this, SWT.NONE);
728
699
729
			FormData linkData = new FormData();
700
			if (needsLinkComposite(taskString, linkJob)) {
730
			if (index == 0 || taskEntries.size() == 0) {
701
				if (linkComposite == null) {
731
				Control top = progressBar;
702
					linkComposite = new Composite(this, SWT.NONE);
732
				if (top == null) {
703
					linkComposite.addMouseListener(mouseListener);
733
					top = progressLabel;
704
734
				}
705
					RowLayout layout = new RowLayout(DIRECTION);
735
				linkData.top = new FormAttachment(top,
706
//					layout.justify=true;
736
						IDialogConstants.VERTICAL_SPACING);
707
					layout.fill=true;
737
				linkData.left = new FormAttachment(top, 0, SWT.LEFT);
708
					layout.marginBottom = 0;
738
				linkData.right = new FormAttachment(progressBar, 0, SWT.RIGHT);
709
					layout.marginLeft = 0;
739
				// Give an initial value so as to constrain the link shortening
710
					layout.marginRight = 0;
740
				linkData.width = IDialogConstants.INDENT;
711
					layout.marginTop = 0;
741
			} else {
712
					linkComposite.setLayout(layout);
742
				Link previous = (Link) taskEntries.get(index - 1);
713
743
				linkData.top = new FormAttachment(previous,
714
					GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
744
						IDialogConstants.VERTICAL_SPACING);
715
							.applyTo(linkComposite);
745
				linkData.left = new FormAttachment(previous, 0, SWT.LEFT);
716
746
				linkData.right = new FormAttachment(previous, 0, SWT.RIGHT);
717
				}
747
				// Give an initial value so as to constrain the link shortening
718
				if (getAction(linkJob) == null) {
748
				linkData.width = IDialogConstants.INDENT;
719
					subTaskControl = new Label(linkComposite, SWT.NONE);
749
			}
720
				}
750
721
				else {
751
			link.setLayoutData(linkData);
722
					subTaskControl = new Link(linkComposite, SWT.NONE);
752
723
				}
753
			final Link finalLink = link;
724
				addControlListeners(subTaskControl);
754
725
755
			link.addSelectionListener(new SelectionAdapter() {
726
				taskEntries.add(subTaskControl);
756
				/*
727
			}
757
				 * (non-Javadoc)
728
		}
758
				 * 
729
		else {
759
				 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
730
			subTaskControl = (Control) taskEntries.get(index);
760
				 */
731
		}
761
				public void widgetSelected(SelectionEvent e) {
732
762
733
		if (subTaskControl != null) {
763
					IAction action = (IAction) finalLink.getData(ACTION_KEY);
734
			if (taskString != null) {
764
					action.run();
735
				subTaskControl.setToolTipText(taskString);
765
736
			}
766
					updateAction(action, finalLink);
737
			subTaskControl.setData(TEXT_KEY, taskString);
767
738
			subTaskControl.setData(JOB, linkJob);
768
					Object text = finalLink.getData(TEXT_KEY);
739
769
					if (text == null)
740
			// check for action property
770
						return;
741
			updateAction(linkJob, subTaskControl);
771
742
772
					// Refresh the text as enablement might have changed
743
			updateText(taskString, subTaskControl);
773
					updateText((String) text, finalLink);
744
		}
774
				}
745
775
			});
746
	}
776
747
777
			link.addListener(SWT.Resize, new Listener() {
748
	private void addControlListeners(final Control control) {
778
				/*
749
		control.addListener(SWT.Selection, new Listener() {
779
				 * (non-Javadoc)
750
			/*
780
				 * 
751
			 * (non-Javadoc)
781
				 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
752
			 * 
782
				 */
753
			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
783
				public void handleEvent(Event event) {
754
			 */
784
755
			public void handleEvent(Event e) {
785
					Object text = finalLink.getData(TEXT_KEY);
756
786
					if (text == null)
757
				IAction action = (IAction) control.getData(ACTION_KEY);
787
						return;
758
				action.run();
788
759
789
					updateText((String) text, finalLink);
760
				updateAction((Job) control.getData(JOB), control);
790
761
791
				}
762
				Object text = control.getData(TEXT_KEY);
792
			});
763
				if (text == null)
793
			taskEntries.add(link);
764
					return;
794
		} else {
765
795
			link = (Link) taskEntries.get(index);
766
				// Refresh the text as enablement might have changed
796
		}
767
				updateText((String) text, control);
797
768
			}
798
		link.setToolTipText(taskString);
769
		});
799
		link.setData(TEXT_KEY, taskString);
770
800
771
		control.addListener(SWT.Resize, new Listener() {
801
		// check for action property
772
			/*
802
		Object property = linkJob
773
			 * (non-Javadoc)
803
				.getProperty(IProgressConstants.ACTION_PROPERTY);
774
			 * 
804
		updateAction(property, link);
775
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
776
			 */
777
			public void handleEvent(Event event) {
778
779
				Object text = control.getData(TEXT_KEY);
780
				if (text == null)
781
					return;
805
782
806
		updateText(taskString, link);
783
				updateText((String) text, control);
807
784
785
			}
786
		});
808
	}
787
	}
809
788
810
	/**
789
	/**
Lines 814-827 Link Here
814
	 *            {@link Object} or <code>null</code>
793
	 *            {@link Object} or <code>null</code>
815
	 * @param link
794
	 * @param link
816
	 */
795
	 */
817
	private void updateAction(Object action, Link link) {
796
	private void updateAction(Job linkJob, Control link) {
818
797
		link.setData(ACTION_KEY, getAction(linkJob));
819
		if (action != null && action instanceof IAction
820
				&& ((IAction) action).isEnabled())
821
			link.setData(ACTION_KEY, action);
822
		else
823
			link.setData(ACTION_KEY, null);
824
825
	}
798
	}
826
799
827
	/**
800
	/**
Lines 830-841 Link Here
830
	 * @param taskString
803
	 * @param taskString
831
	 * @param link
804
	 * @param link
832
	 */
805
	 */
833
	private void updateText(String taskString, Link link) {
806
	private void updateText(String taskString, Control control) {
834
		taskString = Dialog.shortenText(taskString, link);
807
		 String processedString = Dialog.shortenText(taskString, control.getParent());
835
836
		// Put in a hyperlink if there is an action
808
		// Put in a hyperlink if there is an action
837
		link.setText(link.getData(ACTION_KEY) == null ? taskString : NLS.bind(
809
		IAction action = (IAction) control.getData(ACTION_KEY);
838
				"<a>{0}</a>", taskString));//$NON-NLS-1$
810
		if (action != null) {
811
			if (processedString == null) {
812
				processedString = NLS.bind("<a>{0}</a>", action.getText());//$NON-NLS-1$
813
			}
814
			else {
815
				processedString = NLS.bind("<a>{0}</a>", processedString);//$NON-NLS-1$
816
			}
817
		}
818
		if (processedString != null) {
819
			if (control instanceof Link) {
820
				if (action == null) {
821
					Label label = new Label(linkComposite, SWT.NONE);
822
					label.moveAbove(control);
823
					control.dispose();
824
					label.setText(processedString);
825
					addControlListeners(label);
826
					for (ListIterator taskItr = taskEntries.listIterator(); taskItr.hasNext();) {
827
						Control c = (Control) taskItr.next();
828
						if (c == control) {
829
							taskItr.set(label);
830
							break;
831
						}
832
					}
833
				}
834
				else {
835
					((Link) control).setText(processedString);
836
					control.getParent().layout(true);
837
				}
838
			}
839
			else {
840
				if (action == null) {
841
					((Label) control).setText(processedString);
842
					control.getParent().layout(true);
843
				}
844
				else {
845
					Link link = new Link(linkComposite, SWT.NONE);
846
					link.moveAbove(control);
847
					control.dispose();
848
					link.setText(processedString);
849
					addControlListeners(link);
850
					for (ListIterator taskItr = taskEntries.listIterator(); taskItr.hasNext();) {
851
						Control c = (Control) taskItr.next();
852
						if (c == control) {
853
							taskItr.set(link);
854
							break;
855
						}
856
					}
857
				}
858
			}
859
		}
860
	}
861
862
	private IAction getAction(Job linkJob) {
863
		Object action = linkJob.getProperty(IProgressConstants.ACTION_PROPERTY);
864
		if (action != null && action instanceof IAction && ((IAction) action).isEnabled()) {
865
			return (IAction) action;
866
		}
867
		return null;
868
	}
869
870
	private boolean needsLinkComposite(String taskString, Job linkJob) {
871
		if (getAction(linkJob) != null)
872
			return true;
873
		return taskString != null;
839
	}
874
	}
840
875
841
	/**
876
	/**
Lines 847-868 Link Here
847
		currentIndex = i;
882
		currentIndex = i;
848
883
849
		if (selected) {
884
		if (selected) {
850
			setAllBackgrounds(getDisplay().getSystemColor(
885
			setAllBackgrounds(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
851
					SWT.COLOR_LIST_SELECTION));
886
			setAllForegrounds(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
852
			setAllForegrounds(getDisplay().getSystemColor(
853
					SWT.COLOR_LIST_SELECTION_TEXT));
854
			return;
887
			return;
855
		}
888
		}
856
889
857
		if (i % 2 == 0) {
890
		if (i % 2 == 0) {
858
			setAllBackgrounds(JFaceResources.getColorRegistry().get(
891
			setAllBackgrounds(JFaceResources.getColorRegistry().get(DARK_COLOR_KEY));
859
					DARK_COLOR_KEY));
860
		} else {
861
			setAllBackgrounds(getDisplay().getSystemColor(
862
					SWT.COLOR_LIST_BACKGROUND));
863
		}
892
		}
864
		setAllForegrounds(getDisplay()
893
		else {
865
				.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
894
			setAllBackgrounds(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
895
		}
896
		setAllForegrounds(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
866
	}
897
	}
867
898
868
	/**
899
	/**
Lines 876-882 Link Here
876
907
877
		Iterator taskEntryIterator = taskEntries.iterator();
908
		Iterator taskEntryIterator = taskEntries.iterator();
878
		while (taskEntryIterator.hasNext()) {
909
		while (taskEntryIterator.hasNext()) {
879
			((Link) taskEntryIterator.next()).setForeground(color);
910
			((Control) taskEntryIterator.next()).setForeground(color);
880
		}
911
		}
881
912
882
	}
913
	}
Lines 887-902 Link Here
887
	 * @param color
918
	 * @param color
888
	 */
919
	 */
889
	private void setAllBackgrounds(Color color) {
920
	private void setAllBackgrounds(Color color) {
921
		// backgrounds are inherited, so only do it once
890
		setBackground(color);
922
		setBackground(color);
891
		progressLabel.setBackground(color);
892
		actionBar.setBackground(color);
893
		jobImageLabel.setBackground(color);
894
895
		Iterator taskEntryIterator = taskEntries.iterator();
896
		while (taskEntryIterator.hasNext()) {
897
			((Link) taskEntryIterator.next()).setBackground(color);
898
		}
899
900
	}
923
	}
901
924
902
	/**
925
	/**
Lines 965-977 Link Here
965
		if (refresh)
988
		if (refresh)
966
			refresh();
989
			refresh();
967
	}
990
	}
968
	
991
969
	/* (non-Javadoc)
992
	/*
993
	 * (non-Javadoc)
994
	 * 
970
	 * @see org.eclipse.swt.widgets.Widget#dispose()
995
	 * @see org.eclipse.swt.widgets.Widget#dispose()
971
	 */
996
	 */
972
	public void dispose() {
997
	public void dispose() {
973
		super.dispose();
998
		super.dispose();
974
		if(resourceManager != null)
999
		if (resourceManager != null)
975
			resourceManager.dispose();
1000
			resourceManager.dispose();
976
	}
1001
	}
977
}
1002
}

Return to bug 229294