KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > console > ConsoleDocumentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.console;
12
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.debug.core.model.IProcess;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.ui.console.ConsoleColorProvider;
18 import org.eclipse.debug.ui.console.IConsoleColorProvider;
19
20 import org.eclipse.jface.operation.IRunnableContext;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.source.IAnnotationModel;
23
24 import org.eclipse.ui.texteditor.AbstractDocumentProvider;
25
26 /**
27  * Default document provider for the processes. By default a document is created
28  * which is connected to the streams proxy of the associated process.
29  */

30 public class ConsoleDocumentProvider extends AbstractDocumentProvider {
31     
32     /**
33      * The runnable context for that provider.
34      * @since 3.0
35      */

36     private WorkspaceOperationRunner fOperationRunner;
37
38     /**
39      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createDocument(java.lang.Object)
40      */

41     protected IDocument createDocument(Object JavaDoc element) {
42         if (element instanceof IProcess) {
43             IProcess process = (IProcess)element;
44             IConsoleColorProvider colorProvider = getColorProvider(process);
45             ConsoleDocument doc= new ConsoleDocument(colorProvider);
46             ConsoleDocumentPartitioner partitioner = new ConsoleDocumentPartitioner(process, colorProvider);
47             ConsoleLineNotifier lineNotifier = getLineNotifier(process);
48             partitioner.connect(doc);
49             if (lineNotifier != null) {
50                 partitioner.connectLineNotifier(lineNotifier);
51             }
52             return doc;
53         }
54         return null;
55     }
56
57     /**
58      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createAnnotationModel(java.lang.Object)
59      */

60     protected IAnnotationModel createAnnotationModel(Object JavaDoc element) {
61         return null;
62     }
63
64     /**
65      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
66      */

67     protected void doSaveDocument(IProgressMonitor monitor, Object JavaDoc element, IDocument document, boolean overwrite) {
68     }
69
70     /**
71      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#disposeElementInfo(java.lang.Object, org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo)
72      */

73     protected void disposeElementInfo(Object JavaDoc element, ElementInfo info) {
74         ConsoleDocument document = (ConsoleDocument)info.fDocument;
75         document.getDocumentPartitioner().disconnect();
76         super.disposeElementInfo(element, info);
77     }
78
79     /**
80      * Returns a color provider for the given process.
81      *
82      * @param process
83      * @return IConsoleColorProvider
84      */

85     protected IConsoleColorProvider getColorProvider(IProcess process) {
86         String JavaDoc type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE);
87         IConsoleColorProvider colorProvider = null;
88         if (type != null) {
89             colorProvider = getConsoleDocumentManager().getColorProvider(type);
90         }
91         if (colorProvider == null) {
92             colorProvider = new ConsoleColorProvider();
93         }
94         return colorProvider;
95     }
96     
97     /**
98      * Returns the line notifier for this console, or <code>null</code> if none.
99      *
100      * @param process
101      * @return line notifier, or <code>null</code>
102      */

103     protected ConsoleLineNotifier getLineNotifier(IProcess process) {
104         String JavaDoc type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE);
105         if (type != null) {
106             return getConsoleDocumentManager().newLineNotifier(type);
107         }
108         return null;
109     }
110     
111     /**
112      * Convenience accessor
113      *
114      * @return ConsoleDocumentManager
115      */

116     private ConsoleDocumentManager getConsoleDocumentManager() {
117         return DebugUIPlugin.getDefault().getConsoleDocumentManager();
118     }
119     
120     /*
121      * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#getOperationRunner(org.eclipse.core.runtime.IProgressMonitor)
122      */

123     protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
124         if (fOperationRunner == null)
125             fOperationRunner = new WorkspaceOperationRunner();
126         fOperationRunner.setProgressMonitor(monitor);
127         return fOperationRunner;
128     }
129 }
130
Popular Tags