use of org.eclipse.jface.text.IDocument in project ow by vtst.
the class ClosureContentAssistIncovationContext method computePrefixAndPathOffsets.
// **************************************************************************
// Prefix and path
/**
* Compute the prefix already present in the document at the invocation offset.
*/
private void computePrefixAndPathOffsets() {
IDocument document = context.getDocument();
invocationOffset = context.getInvocationOffset();
try {
prefixOffset = invocationOffset;
while (prefixOffset > 0 && isCharForPrefix(document.getChar(prefixOffset - 1))) --prefixOffset;
pathOffset = prefixOffset;
while (pathOffset > 0 && isCharForPath(document.getChar(pathOffset - 1))) --pathOffset;
} catch (BadLocationException e) {
assert false;
}
}
use of org.eclipse.jface.text.IDocument 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 org.eclipse.jface.text.IDocument in project bndtools by bndtools.
the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
ISourceViewer viewer = context.getSourceViewer();
@SuppressWarnings("unused") IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
@SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = (Annotation) iter.next();
if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
Position position = model.getPosition(annotation);
if (isAtPosition(context.getOffset(), position)) {
IMarker marker = ((MarkerAnnotation) annotation).getMarker();
String errorType = marker.getAttribute("$bndType", null);
if (errorType != null) {
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
if (handler != null) {
proposals.addAll(handler.getProposals(marker));
}
}
}
}
}
if (proposals.isEmpty()) {
proposals.add(new NoCompletionsProposal());
}
return proposals.toArray(new ICompletionProposal[0]);
}
use of org.eclipse.jface.text.IDocument in project bndtools by bndtools.
the class ApplyCompletionProposalAction method run.
@Override
public void run() {
assert (proposal != null);
assert (textEditor != null);
assert (mainEditor != null);
assert (switchToPageId != null);
mainEditor.setActivePage(switchToPageId);
IDocument document = textEditor.getDocumentProvider().getDocument(mainEditor.getEditorInput());
proposal.apply(document);
Point selection = proposal.getSelection(document);
if (selection != null)
textEditor.selectAndReveal(selection.x, 0);
}
use of org.eclipse.jface.text.IDocument 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);
}
}
Aggregations