use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class LastSaveReferenceProvider method readDocument.
/**
* Reads in the saved document into <code>fReference</code>.
*
* @param monitor a progress monitor, or <code>null</code>
* @param force <code>true</code> if the reference document should also
* be read if the current document is <code>null</code>,<code>false</code>
* if it should only be updated if it already existed.
*/
private void readDocument(IProgressMonitor monitor, boolean force) {
// protect against concurrent disposal
IDocumentProvider prov = fDocumentProvider;
IEditorInput inp = fEditorInput;
IDocument doc = fReference;
ITextEditor editor = fEditor;
if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput) inp;
IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
if (doc == null)
if (force || fDocumentRead)
doc = new Document();
else
return;
IJobManager jobMgr = Job.getJobManager();
try {
IStorage storage = input.getStorage();
// check for null for backward compatibility (we used to check before...)
if (storage == null)
return;
fProgressMonitor = monitor;
ISchedulingRule rule = getSchedulingRule(storage);
// delay for any other job requiring the lock on file
try {
lockDocument(monitor, jobMgr, rule);
String encoding;
if (storage instanceof IEncodedStorage)
encoding = ((IEncodedStorage) storage).getCharset();
else
encoding = null;
boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
} finally {
unlockDocument(jobMgr, rule);
fProgressMonitor = null;
}
} catch (CoreException e) {
return;
}
if (monitor != null && monitor.isCanceled())
return;
// update state
synchronized (fLock) {
if (fDocumentProvider == provider && fEditorInput == input) {
// only update state if our provider / input pair has not
// been updated in between (dispose or setActiveEditor)
fReference = doc;
fDocumentRead = true;
addElementStateListener(editor, prov);
}
}
}
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class QuickDiffRestoreAction method getModel.
/**
* Returns the annotation model of the document displayed in this action's editor, if it
* implements the {@link IAnnotationModelExtension IAnnotationModelExtension} interface.
*
* @return the displayed document's annotation model if it is an <code>IAnnotationModelExtension</code>, or <code>null</code>
*/
private IAnnotationModelExtension getModel() {
if (getTextEditor() == null)
return null;
IDocumentProvider provider = getTextEditor().getDocumentProvider();
IEditorInput editorInput = getTextEditor().getEditorInput();
IAnnotationModel m = provider.getAnnotationModel(editorInput);
if (m instanceof IAnnotationModelExtension)
return (IAnnotationModelExtension) m;
return null;
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class EncodingActionGroup method getDefaultEncodingText.
/*
* @since 3.0
*/
private static String getDefaultEncodingText(ITextEditor editor, String defaultText) {
IEditorInput input = (editor.getEditorInput());
if (!(input instanceof IFileEditorInput))
return defaultText;
IFile file = ((IFileEditorInput) input).getFile();
String format = FILE_CONTENT_ENCODING_FORMAT;
String encoding;
try {
encoding = getEncodingFromContent(file);
if (encoding == null) {
format = FILE_CONTAINER_ENCODING_FORMAT;
encoding = file.getParent().getDefaultCharset();
}
} catch (CoreException ex) {
return defaultText;
}
return NLSUtility.format(format, encoding);
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class FileBufferOperationHandler method computeSelectedResources.
/**
* Computes the selected resources.
*/
protected final void computeSelectedResources() {
if (fResources != null || fLocation != null)
return;
ISelection selection = getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
ArrayList<Object> resources = new ArrayList<>(structuredSelection.size());
Iterator<?> e = structuredSelection.iterator();
while (e.hasNext()) {
Object element = e.next();
if (element instanceof IResource)
resources.add(element);
else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
Object adapter = adaptable.getAdapter(IResource.class);
if (adapter instanceof IResource)
resources.add(adapter);
}
}
if (!resources.isEmpty())
fResources = resources.toArray(new IResource[resources.size()]);
} else if (selection instanceof ITextSelection) {
IWorkbenchWindow window = getWorkbenchWindow();
if (window != null) {
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
if (workbenchPart instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) workbenchPart;
IEditorInput input = editorPart.getEditorInput();
Object adapter = input.getAdapter(IResource.class);
if (adapter instanceof IResource)
fResources = new IResource[] { (IResource) adapter };
else {
adapter = input.getAdapter(ILocationProvider.class);
if (adapter instanceof ILocationProvider) {
ILocationProvider provider = (ILocationProvider) adapter;
fLocation = provider.getPath(input);
}
}
}
}
}
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class EditorOpener method showWithReuse.
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException {
IEditorInput input = new FileEditorInput(file);
IEditorPart editor = page.findEditor(input);
if (editor != null) {
page.bringToTop(editor);
if (activate) {
page.activate(editor);
}
return editor;
}
IEditorReference reusedEditorRef = fReusedEditor;
if (reusedEditorRef != null) {
boolean isOpen = reusedEditorRef.getEditor(false) != null;
boolean canBeReused = isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
if (canBeReused) {
boolean showsSameInputType = reusedEditorRef.getId().equals(editorId);
if (!showsSameInputType) {
page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
fReusedEditor = null;
} else {
editor = reusedEditorRef.getEditor(true);
if (editor instanceof IReusableEditor) {
((IReusableEditor) editor).setInput(input);
page.bringToTop(editor);
if (activate) {
page.activate(editor);
}
return editor;
}
}
}
}
editor = page.openEditor(input, editorId, activate);
if (editor instanceof IReusableEditor) {
IEditorReference reference = (IEditorReference) page.getReference(editor);
fReusedEditor = reference;
} else {
fReusedEditor = null;
}
return editor;
}
Aggregations