use of org.eclipse.ui.texteditor.IDocumentProvider in project bndtools by bndtools.
the class BndEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
try {
// Work out our input file and subscribe to resource changes
final String resourceName;
IResource inputResource = ResourceUtil.getResource(input);
if (inputResource != null) {
inputResource.getWorkspace().addResourceChangeListener(this);
resourceName = inputResource.getName();
inputFile = inputResource.getLocation().toFile();
} else {
IStorage storage = (IStorage) input.getAdapter(IStorage.class);
if (storage != null) {
resourceName = storage.getName();
} else {
resourceName = input.getName();
}
inputFile = null;
}
model.setBndResourceName(resourceName);
// Initialise pages and title
initPages(site, input);
setSourcePage(sourcePage);
setPartNameForInput(input);
IDocumentProvider docProvider = sourcePage.getDocumentProvider();
// #1625: Ensure the IDocumentProvider is not null.
if (docProvider != null) {
docProvider.addElementStateListener(new ElementStateListener());
if (!Central.hasWorkspaceDirectory()) {
// default ws will be created we can load immediately
loadEditModel();
} else {
// a real ws will be resolved so we need to load async
Central.onWorkspaceInit(new Success<Workspace, Void>() {
@Override
public Promise<Void> call(Promise<Workspace> resolved) throws Exception {
try {
loadEditModel();
return Promises.resolved(null);
} catch (Exception e) {
logger.logError("Failed to load edit model", e);
return Promises.failed(e);
}
}
});
}
}
} catch (Exception e1) {
throw Exceptions.duck(e1);
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project bndtools by bndtools.
the class BndEditor method resourceChanged.
@Override
public void resourceChanged(IResourceChangeEvent event) {
IResource myResource = ResourceUtil.getResource(getEditorInput());
IResourceDelta delta = event.getDelta();
if (delta == null)
return;
IPath fullPath = myResource.getFullPath();
delta = delta.findMember(fullPath);
if (delta == null)
return;
// Delegate to any interested pages
for (Object page : pages) {
if (page instanceof IResourceChangeListener) {
((IResourceChangeListener) page).resourceChanged(event);
}
}
// Close editor if file removed or switch to new location if file moved
if (delta.getKind() == IResourceDelta.REMOVED) {
if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
final FileEditorInput newInput = new FileEditorInput(file);
setInput(newInput);
Display display = getEditorSite().getShell().getDisplay();
if (display != null) {
SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {
@Override
public void run() {
setPartNameForInput(newInput);
sourcePage.setInput(newInput);
}
});
}
} else {
close(false);
}
} else // File content updated externally => reload all pages
if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
if (!saving.get()) {
final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
// #1625: Ensure the IDocumentProvider is not null.
if (docProvider != null) {
final IDocument document = docProvider.getDocument(getEditorInput());
SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {
@Override
public void run() {
try {
model.loadFrom(new IDocumentWrapper(document));
updateIncludedPages();
} catch (IOException e) {
logger.logError("Failed to reload document", e);
}
}
});
}
}
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class RulerColumnDescriptor method getContentType.
/**
* Returns the content type of the editor's input, <code>null</code> if the editor input or
* the document provider is <code>null</code> or the content type cannot be determined.
*
* @param editor the editor to get the content type from
* @return the content type of the editor's input, <code>null</code> if it cannot be
* determined
*/
private IContentType getContentType(ITextEditor editor) {
IEditorInput input = editor.getEditorInput();
if (input == null)
return null;
IDocumentProvider provider = editor.getDocumentProvider();
if (provider instanceof IDocumentProviderExtension4) {
IDocumentProviderExtension4 ext = (IDocumentProviderExtension4) provider;
try {
return ext.getContentType(input);
} catch (CoreException x) {
// ignore and return null;
}
}
return null;
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project eclipse.platform.text by eclipse.
the class HippieCompletionEngine method computeDocuments.
/**
* Calculates the documents to be searched. Note that the first returned document is always from
* the current editor and if we have no current editor, an empty list is returned even if there
* are other documents available.
*
* @param currentTextEditor this is the currently opened text editor.
* @return A List of IDocument with the opened documents so that the first document in that list
* is always the current document.
* @since 3.6
*/
public static List<IDocument> computeDocuments(ITextEditor currentTextEditor) {
ArrayList<IDocument> documentsForSearch = new ArrayList<>();
if (currentTextEditor == null) {
return documentsForSearch;
}
IDocumentProvider provider = currentTextEditor.getDocumentProvider();
if (provider == null) {
return documentsForSearch;
}
IDocument currentDocument = provider.getDocument(currentTextEditor.getEditorInput());
if (currentDocument == null) {
return documentsForSearch;
}
List<IDocument> computedDocuments = new ArrayList<>();
IWorkbenchWindow window = currentTextEditor.getSite().getWorkbenchWindow();
IEditorReference[] editorsArray = window.getActivePage().getEditorReferences();
for (int i = 0; i < editorsArray.length; i++) {
IEditorPart realEditor = editorsArray[i].getEditor(false);
if (realEditor instanceof ITextEditor && !realEditor.equals(currentTextEditor)) {
ITextEditor textEditor = (ITextEditor) realEditor;
provider = textEditor.getDocumentProvider();
if (provider == null) {
continue;
}
IDocument doc = provider.getDocument(textEditor.getEditorInput());
if (doc == null) {
continue;
}
computedDocuments.add(doc);
}
}
// The first is always the one related to the passed currentTextEditor.
computedDocuments.add(0, currentDocument);
return computedDocuments;
}
use of org.eclipse.ui.texteditor.IDocumentProvider 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;
}
Aggregations