Search in sources :

Example 41 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project egit by eclipse.

the class SpellcheckableMessageArea method addProposals.

private void addProposals(final SubMenuManager quickFixMenu) {
    IAnnotationModel sourceModel = sourceViewer.getAnnotationModel();
    if (sourceModel == null) {
        return;
    }
    Iterator annotationIterator = sourceModel.getAnnotationIterator();
    while (annotationIterator.hasNext()) {
        Annotation annotation = (Annotation) annotationIterator.next();
        boolean isDeleted = annotation.isMarkedDeleted();
        boolean isIncluded = !isDeleted && includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset());
        boolean isFixable = isIncluded && sourceViewer.getQuickAssistAssistant().canFix(annotation);
        if (isFixable) {
            IQuickAssistProcessor processor = sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor();
            IQuickAssistInvocationContext context = sourceViewer.getQuickAssistInvocationContext();
            ICompletionProposal[] proposals = processor.computeQuickAssistProposals(context);
            for (ICompletionProposal proposal : proposals) {
                quickFixMenu.add(createQuickFixAction(proposal));
            }
        }
    }
}
Also used : IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IQuickAssistInvocationContext(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext) Annotation(org.eclipse.jface.text.source.Annotation)

Example 42 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project egit by eclipse.

the class DiffEditorPage method setOverviewAnnotations.

private void setOverviewAnnotations() {
    IDocumentProvider documentProvider = getDocumentProvider();
    IDocument document = documentProvider.getDocument(getEditorInput());
    if (!(document instanceof DiffDocument)) {
        return;
    }
    IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
    if (annotationModel == null) {
        return;
    }
    DiffRegion[] diffs = ((DiffDocument) document).getRegions();
    if (diffs == null || diffs.length == 0) {
        return;
    }
    Map<Annotation, Position> newAnnotations = new HashMap<>();
    for (DiffRegion region : diffs) {
        if (DiffRegion.Type.ADD.equals(region.getType())) {
            newAnnotations.put(new Annotation(ADD_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
        } else if (DiffRegion.Type.REMOVE.equals(region.getType())) {
            newAnnotations.put(new Annotation(REMOVE_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
        }
    }
    if (annotationModel instanceof IAnnotationModelExtension) {
        ((IAnnotationModelExtension) annotationModel).replaceAnnotations(currentOverviewAnnotations, newAnnotations);
    } else {
        if (currentOverviewAnnotations != null) {
            for (Annotation existing : currentOverviewAnnotations) {
                annotationModel.removeAnnotation(existing);
            }
        }
        for (Map.Entry<Annotation, Position> entry : newAnnotations.entrySet()) {
            annotationModel.addAnnotation(entry.getKey(), entry.getValue());
        }
    }
    currentOverviewAnnotations = newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]);
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) DiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.DiffRegion) Annotation(org.eclipse.jface.text.source.Annotation) ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) Map(java.util.Map) HashMap(java.util.HashMap) IDocument(org.eclipse.jface.text.IDocument)

Example 43 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project ecf by eclipse.

the class SyncResourcesUI method startSharing.

private void startSharing(ITextEditor editor, IFile file) {
    String projectName = file.getProject().getName();
    for (Iterator it = SyncResourcesCore.getResourceShares().iterator(); it.hasNext(); ) {
        ResourcesShare share = (ResourcesShare) it.next();
        if (share.isSharing(projectName) && share(file)) {
            DocShare docShare = getDocShare(share.getContainerID());
            try {
                IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
                docShare.startSharing(share.getLocalID(), share.getReceiverID(), file.getFullPath().toString(), annotationModel);
                ISelectionProvider provider = editor.getSelectionProvider();
                if (provider instanceof IPostSelectionProvider) {
                    ISelectionChangedListener listener = new SelectionChangedListener(share.getReceiverID(), file.getFullPath().toString(), docShare);
                    ((IPostSelectionProvider) provider).addPostSelectionChangedListener(listener);
                    sharedEditors.put(editor, listener);
                }
            } catch (ECFException e) {
                IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, // $NON-NLS-1$
                "Could not send initiation request to " + share.getReceiverID(), e);
                log(status);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            } catch (CoreException e) {
                IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, // $NON-NLS-1$
                "Could not connect to the file buffer of " + file.getFullPath(), e);
                log(status);
                StatusManager.getManager().handle(status, StatusManager.SHOW);
            }
        }
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) DocShare(org.eclipse.ecf.docshare2.DocShare) IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ECFException(org.eclipse.ecf.core.util.ECFException) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) ResourcesShare(org.eclipse.ecf.internal.sync.resources.core.ResourcesShare)

Example 44 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.

the class OccurencesMarker method removeOccurences.

/**
 * Removes the occurrence annotations of this OccurrenceMarker.
 *
 * @param force
 *                The annotations will be removed even if the keepMarks
 *                flag is set.
 */
public void removeOccurences(final boolean force) {
    if (!force && keepMarks.getValue()) {
        return;
    }
    markerJob.cancel();
    final IAnnotationModel annotationModel = getAnnotationModel();
    if (annotationModel == null) {
        return;
    }
    synchronized (getLockObject(annotationModel)) {
        if (occurrenceAnnotations == null) {
            return;
        }
        for (Annotation annotaion : occurrenceAnnotations) {
            annotationModel.removeAnnotation(annotaion);
        }
        occurrenceAnnotations = null;
    }
}
Also used : IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 45 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.

the class TextHover method getHoverInfo.

@Override
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
    if (hoverRegion == null) {
        return null;
    }
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    if (annotationModel != null) {
        Iterator<?> iterator = annotationModel.getAnnotationIterator();
        while (iterator.hasNext()) {
            Object o = iterator.next();
            if (o instanceof MarkerAnnotation) {
                MarkerAnnotation actualMarker = (MarkerAnnotation) o;
                Position markerPosition = annotationModel.getPosition(actualMarker);
                if (markerPosition.getOffset() <= hoverRegion.getOffset() && markerPosition.getOffset() + markerPosition.getLength() >= hoverRegion.getOffset()) {
                    String message = actualMarker.getText();
                    if (message != null) {
                        // Marker error text hover (or tooltip in other words) handles error message
                        // in HTML format, and there can be situation, when the message contains
                        // < and > characters, which are handled as HTML control tags, so they
                        // are not visible. So these < and > characters are removed.
                        // Example: ANTLR sends the following error message during parsing:
                        // "mismatched input 'control' expecting <EOF>"
                        message = message.replaceAll("\\<([A-Z]+)\\>", "$1");
                    } else {
                        ErrorReporter.INTERNAL_ERROR("The marker at " + markerPosition.getOffset() + " does not seem to have any text");
                    }
                    return message;
                }
            }
        }
    }
    return null;
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Aggregations

IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)148 Annotation (org.eclipse.jface.text.source.Annotation)71 Position (org.eclipse.jface.text.Position)58 IDocument (org.eclipse.jface.text.IDocument)41 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)26 Iterator (java.util.Iterator)23 ArrayList (java.util.ArrayList)20 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)20 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)19 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)19 BadLocationException (org.eclipse.jface.text.BadLocationException)18 IFile (org.eclipse.core.resources.IFile)17 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)16 IEditorInput (org.eclipse.ui.IEditorInput)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 List (java.util.List)12 CoreException (org.eclipse.core.runtime.CoreException)11 IMarker (org.eclipse.core.resources.IMarker)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10