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);
}
}
});
}
}
}
}
Aggregations