use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class ReferenceSelectionAction method getDiffer.
/**
* Fetches the differ installed with the current editor's document's annotation model. If none
* is installed yet, and <code>createIfNeeded</code> is true, one is created and attached to the
* model.
*
* @param createIfNeeded when set to <code>true</code>, a new differ will be created if needed.
* @return the differ installed with the annotation model, or <code>null</code>.
*/
private DocumentLineDiffer getDiffer(boolean createIfNeeded) {
// get annotation model
if (fEditor == null)
return null;
IDocumentProvider provider = fEditor.getDocumentProvider();
IEditorInput editorInput = fEditor.getEditorInput();
if (provider == null || editorInput == null)
return null;
IAnnotationModel m = provider.getAnnotationModel(editorInput);
IAnnotationModelExtension model = null;
if (m instanceof IAnnotationModelExtension) {
model = (IAnnotationModelExtension) m;
} else {
return null;
}
// get differ
DocumentLineDiffer differ = (DocumentLineDiffer) model.getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
// create if needed
if (differ == null && createIfNeeded) {
differ = new DocumentLineDiffer();
model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
}
return differ;
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class HighlightTest method getAnnotationModel.
private IAnnotationModel getAnnotationModel() {
IDocumentProvider dp = editor.getDocumentProvider();
IAnnotationModel am = dp.getAnnotationModel(editor.getEditorInput());
return am;
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class DefaultEncodingSupport method setEncoding.
/**
* Sets the encoding of the editor's input to the given value. If <code>overwrite</code> is
* <code>true</code> the value is set even if the encoding is already set.
*
* @param encoding the new encoding
* @param overwrite <code>true</code> if current encoding should be overwritten
*/
protected void setEncoding(String encoding, boolean overwrite) {
IDocumentProvider p = fTextEditor.getDocumentProvider();
if (p instanceof IStorageDocumentProvider) {
final IEditorInput input = fTextEditor.getEditorInput();
IStorageDocumentProvider provider = (IStorageDocumentProvider) p;
String current = provider.getEncoding(input);
if (!fTextEditor.isDirty()) {
// $NON-NLS-1$
String internal = encoding == null ? "" : encoding;
boolean apply = (overwrite || current == null) && !internal.equals(current);
if (apply) {
provider.setEncoding(input, encoding);
Runnable encodingSetter = new Runnable() {
@Override
public void run() {
fTextEditor.doRevertToSaved();
}
};
Display display = fTextEditor.getSite().getShell().getDisplay();
if (display != null && !display.isDisposed())
BusyIndicator.showWhile(display, encodingSetter);
else
encodingSetter.run();
}
}
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class FileHyperlink method linkActivated.
@Override
public void linkActivated() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = null;
try {
editorPart = IDE.openEditorOnFileStore(page, file);
if (line > 0) {
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor) {
textEditor = (ITextEditor) editorPart;
} else {
textEditor = editorPart.getAdapter(ITextEditor.class);
}
if (textEditor != null) {
IEditorInput input = editorPart.getEditorInput();
IDocumentProvider provider = textEditor.getDocumentProvider();
try {
provider.connect(input);
} catch (CoreException e) {
// unable to link
return;
}
IDocument document = provider.getDocument(input);
int offset = -1;
int length = -1;
try {
IRegion region = document.getLineInformation(line - 1);
offset = region.getOffset();
length = region.getLength();
} catch (BadLocationException e) {
// unable to link
}
provider.disconnect(input);
if (offset >= 0 && length >= 0) {
textEditor.selectAndReveal(offset, length);
}
}
}
} catch (PartInitException e) {
// Put your exception handler here if you wish to
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class JavaParserTest method tearDown.
@After
public void tearDown() throws Exception {
// content to the empty string).
if (javaSourceEditorPart != null) {
AbstractTextEditor castEditor = (AbstractTextEditor) javaSourceEditorPart;
IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
changelogContentDoc.set("");
javaSourceEditorPart.doSave(null);
// Also close open editor in order for default content to work.
// I.e. avoid spill over from previous test runs
closeEditor(javaSourceEditorPart);
}
// dispose
project.getTestProject().delete(true, true, null);
}
Aggregations