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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.views.console;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.console.ConsoleColorProvider;
import org.eclipse.debug.ui.console.IConsoleColorProvider;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.texteditor.AbstractDocumentProvider;
/**
* Default document provider for the processes. By default a document is created
* which is connected to the streams proxy of the associated process.
*/
public class ConsoleDocumentProvider extends AbstractDocumentProvider {
/**
* @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createDocument(java.lang.Object)
*/
protected IDocument createDocument(Object element) throws CoreException {
if (element instanceof IProcess) {
IProcess process = (IProcess)element;
IConsoleColorProvider colorProvider = getColorProvider(process);
ConsoleDocument doc= new ConsoleDocument(colorProvider);
ConsoleDocumentPartitioner partitioner = new ConsoleDocumentPartitioner(process, colorProvider);
ConsoleLineNotifier lineNotifier = getLineNotifier(process);
partitioner.connect(doc);
if (lineNotifier != null) {
partitioner.connectLineNotifier(lineNotifier);
}
return doc;
}
return null;
}
/**
* @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createAnnotationModel(java.lang.Object)
*/
protected IAnnotationModel createAnnotationModel(Object element)
throws CoreException {
return null;
}
/**
* @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
*/
protected void doSaveDocument(
IProgressMonitor monitor,
Object element,
IDocument document,
boolean overwrite)
throws CoreException {
}
/**
* @see org.eclipse.ui.texteditor.AbstractDocumentProvider#disposeElementInfo(java.lang.Object, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo)
*/
protected void disposeElementInfo(Object element, ElementInfo info) {
ConsoleDocument document = (ConsoleDocument)info.fDocument;
document.getDocumentPartitioner().disconnect();
super.disposeElementInfo(element, info);
}
/**
* Returns a color provider for the given process.
*
* @param process
* @return IConsoleColorProvider
*/
protected IConsoleColorProvider getColorProvider(IProcess process) {
String type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE);
IConsoleColorProvider colorProvider = null;
if (type != null) {
colorProvider = getConsoleDocumentManager().getColorProvider(type);
}
if (colorProvider == null) {
colorProvider = new ConsoleColorProvider();
}
return colorProvider;
}
/**
* Returns the line notifier for this console, or <code>null</code> if none.
*
* @param process
* @return line notifier, or <code>null</code>
*/
protected ConsoleLineNotifier getLineNotifier(IProcess process) {
String type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE);
if (type != null) {
return getConsoleDocumentManager().newLineNotifier(type);
}
return null;
}
/**
* Convenience accessor
*
* @return ConsoleDocumentManager
*/
private ConsoleDocumentManager getConsoleDocumentManager() {
return DebugUIPlugin.getDefault().getConsoleDocumentManager();
}
}
|