Search in sources :

Example 71 with IDocument

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;
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 72 with IDocument

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);
                        }
                    }
                }
            }
        }
    });
}
Also used : Project(aQute.bnd.build.Project) Control(org.eclipse.swt.widgets.Control) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument) Workspace(aQute.bnd.build.Workspace)

Example 73 with IDocument

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]);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) LinkedList(java.util.LinkedList) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 74 with IDocument

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);
}
Also used : Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument)

Example 75 with IDocument

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);
    }
}
Also used : BndEditor(bndtools.editor.BndEditor) IEditorPart(org.eclipse.ui.IEditorPart) BndEditModel(aQute.bnd.build.model.BndEditModel) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocument (org.eclipse.jface.text.IDocument)488 BadLocationException (org.eclipse.jface.text.BadLocationException)195 Document (org.eclipse.jface.text.Document)118 Test (org.junit.Test)93 IRegion (org.eclipse.jface.text.IRegion)72 Point (org.eclipse.swt.graphics.Point)63 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)54 Position (org.eclipse.jface.text.Position)51 ArrayList (java.util.ArrayList)44 CoreException (org.eclipse.core.runtime.CoreException)39 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)30 IPath (org.eclipse.core.runtime.IPath)26 IFile (org.eclipse.core.resources.IFile)25 IStatus (org.eclipse.core.runtime.IStatus)25 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)24 TextEdit (org.eclipse.text.edits.TextEdit)23 Region (org.eclipse.jface.text.Region)22 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)22 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)21 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)20