1 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 30 public class ConsoleDocumentProvider extends AbstractDocumentProvider { 31 32 36 private WorkspaceOperationRunner fOperationRunner; 37 38 41 protected IDocument createDocument(Object 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 60 protected IAnnotationModel createAnnotationModel(Object element) { 61 return null; 62 } 63 64 67 protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) { 68 } 69 70 73 protected void disposeElementInfo(Object element, ElementInfo info) { 74 ConsoleDocument document = (ConsoleDocument)info.fDocument; 75 document.getDocumentPartitioner().disconnect(); 76 super.disposeElementInfo(element, info); 77 } 78 79 85 protected IConsoleColorProvider getColorProvider(IProcess process) { 86 String 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 103 protected ConsoleLineNotifier getLineNotifier(IProcess process) { 104 String type = process.getAttribute(IProcess.ATTR_PROCESS_TYPE); 105 if (type != null) { 106 return getConsoleDocumentManager().newLineNotifier(type); 107 } 108 return null; 109 } 110 111 116 private ConsoleDocumentManager getConsoleDocumentManager() { 117 return DebugUIPlugin.getDefault().getConsoleDocumentManager(); 118 } 119 120 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 |