use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.
the class BlueprintXmlFileWizard method updateBundleBlueprintAndIncludeResource.
private void updateBundleBlueprintAndIncludeResource(IFile blueprintFile, IFile bndFile) throws Exception {
BndEditModel editModel;
IEditorPart editor = ResourceUtil.findEditor(workbench.getActiveWorkbenchWindow().getActivePage(), bndFile);
IDocument doc = null;
if (editor instanceof BndEditor) {
editModel = ((BndEditor) editor).getEditModel();
} else {
editModel = new BndEditModel(Central.getWorkspace());
doc = FileUtils.readFully(bndFile);
editModel.loadFrom(new IDocumentWrapper(doc));
}
String blueprintrelativePath = blueprintFile.getProjectRelativePath().toString();
updateBundleBlueprintIfNecessary(editModel, blueprintrelativePath);
updateIncludeResourceIfNecessary(editModel, blueprintrelativePath, blueprintFile);
if (editor == null) {
editModel.saveChangesTo(new IDocumentWrapper(doc));
FileUtils.writeFully(doc, bndFile, false);
}
}
use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.
the class BndEditor method loadEditModel.
private void loadEditModel() throws Exception {
// Create the bnd edit model and workspace
Workspace ws = Central.getWorkspaceIfPresent();
Project bndProject = Run.createRun(ws, inputFile);
model.setWorkspace(bndProject.getWorkspace());
model.setProject(bndProject);
// Load content into the edit model
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
// #1625: Ensure the IDocumentProvider is not null.
if (docProvider != null) {
IDocument document = docProvider.getDocument(getEditorInput());
try {
model.loadFrom(new IDocumentWrapper(document));
model.setBndResource(inputFile);
} catch (IOException e) {
logger.logError("Unable to load edit model", e);
}
for (int i = 0; i < getPageCount(); i++) {
Control control = getControl(i);
if (control instanceof ScrolledForm) {
ScrolledForm form = (ScrolledForm) control;
if (SYNC_MESSAGE.equals(form.getMessage())) {
form.setMessage(null, IMessageProvider.NONE);
}
}
}
}
}
});
}
use of bndtools.editor.model.IDocumentWrapper in project bndtools by bndtools.
the class BndSourceEditorPage method getDocument.
private IDocument getDocument() {
IDocumentProvider docProvider = getDocumentProvider();
IEditorInput input = getEditorInput();
return new IDocumentWrapper(docProvider.getDocument(input));
}
use of bndtools.editor.model.IDocumentWrapper 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