-
Notifications
You must be signed in to change notification settings - Fork 188
/
SourceColorerJob.java
83 lines (76 loc) · 2.83 KB
/
SourceColorerJob.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
* Copyright (c) 2008, 2015 Wind River Systems, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.DisassemblyDocument;
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model.SourceFileInfo;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.progress.UIJob;
/**
* UI job to color source code.
*/
class SourceColorerJob extends UIJob implements Runnable {
private final DisassemblyPart fDisassemblyPart;
private final ISourceViewer fViewer;
private final DisassemblyDocument fDocument;
private final IStorage fStorage;
public SourceColorerJob(Display jobDisplay, IStorage storage, DisassemblyPart disassemblyPart) {
super(DisassemblyMessages.SourceColorerJob_name);
fDisassemblyPart = disassemblyPart;
fViewer = disassemblyPart.getTextViewer();
fDocument = (DisassemblyDocument) fViewer.getDocument();
fStorage = storage;
setDisplay(fDisassemblyPart.getSite().getShell().getDisplay());
setSystem(true);
setPriority(INTERACTIVE);
}
/*
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (fViewer != null && !monitor.isCanceled()) {
monitor.beginTask(DisassemblyMessages.SourceColorerJob_name, IProgressMonitor.UNKNOWN);
SourceFileInfo fi = fDocument.getSourceInfo(fStorage);
if (fi != null) {
fi.initPresentationCreator(fViewer);
if (fi.fError != null) {
String message = DisassemblyMessages.Disassembly_log_error_readFile + fi.fFileKey;
fDisassemblyPart.logWarning(message, fi.fError);
}
}
fDisassemblyPart.updateInvalidSource();
monitor.done();
}
return Status.OK_STATUS;
}
/*
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
IWorkbenchSiteProgressService progressService = fDisassemblyPart.getSite()
.getAdapter(IWorkbenchSiteProgressService.class);
if (progressService != null) {
progressService.schedule(this, 0, true);
} else {
schedule();
}
}
}