Skip to main content
summaryrefslogtreecommitdiffstats
blob: f16da8d8887d3558e449584afa5718caa7ab6c8a (plain) (blame)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * 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.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.operation.IRunnableContext;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationModel;

import org.eclipse.ui.editors.text.WorkspaceOperationRunner;
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 {
	
	/** 
	 * The runnable context for that provider.
	 * @since 3.0
	 */
	private WorkspaceOperationRunner fOperationRunner;

	/**
	 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createDocument(java.lang.Object)
	 */
	protected IDocument createDocument(Object element) {
		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) {
		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) {
	}

	/**
	 * @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();
	}
	
	/*
	 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#getOperationRunner(org.eclipse.core.runtime.IProgressMonitor)
	 */
	protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
		if (fOperationRunner == null)
			fOperationRunner = new WorkspaceOperationRunner();
		fOperationRunner.setProgressMonitor(monitor);
		return fOperationRunner;
	}
}

Back to the top