Search in sources :

Example 96 with IAnnotationModel

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

the class MarkerResoltionQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    IAnnotationModel annotationModel = invocationContext.getSourceViewer().getAnnotationModel();
    Collection<MarkerAnnotation> annotations = new HashSet<>();
    annotationModel.getAnnotationIterator().forEachRemaining(annotation -> {
        Position position = annotationModel.getPosition(annotation);
        if (invocationContext.getOffset() >= position.getOffset() && invocationContext.getOffset() + Math.max(0, invocationContext.getLength()) <= position.getOffset() + position.getLength() && annotation instanceof MarkerAnnotation) {
            annotations.add((MarkerAnnotation) annotation);
        }
    });
    Collection<MarkerResolutionCompletionProposal> resolutions = new ArrayList<>();
    for (MarkerAnnotation annotation : annotations) {
        IMarker marker = annotation.getMarker();
        for (IMarkerResolution resolution : IDE.getMarkerHelpRegistry().getResolutions(marker)) {
            resolutions.add(new MarkerResolutionCompletionProposal(marker, resolution));
        }
    }
    return resolutions.toArray(new ICompletionProposal[resolutions.size()]);
}
Also used : MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) IMarkerResolution(org.eclipse.ui.IMarkerResolution) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IMarker(org.eclipse.core.resources.IMarker) HashSet(java.util.HashSet)

Example 97 with IAnnotationModel

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

the class LineNumberColumn method ensureQuickDiffProvider.

/**
 * Ensures that quick diff information is displayed and the quick diff provider is the one with
 * the specified id. If a different quick diff provider is in use, the user may be asked whether
 * he wants to switch.
 *
 * @param diffProviderId the quick diff provider id to use
 * @return <code>true</code> if quick diff could be enabled for the given id,
 *         <code>false</code> otherwise
 */
private boolean ensureQuickDiffProvider(String diffProviderId) {
    if (!isShowingChangeInformation())
        // FIXME pass provider id
        installChangeRulerModel(fDelegate);
    IAnnotationModel annotationModel = fViewer.getAnnotationModel();
    IAnnotationModel oldDiffer = getDiffer();
    if (oldDiffer == null && annotationModel != null)
        // quick diff is enabled, but no differ? not working for whatever reason
        return false;
    if (annotationModel == null)
        annotationModel = new AnnotationModel();
    if (!(annotationModel instanceof IAnnotationModelExtension))
        return false;
    QuickDiff util = new QuickDiff();
    Object oldDifferId = util.getConfiguredQuickDiffProvider(oldDiffer);
    if (oldDifferId.equals(diffProviderId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // Check whether the desired provider is available at all
    IAnnotationModel newDiffer = util.createQuickDiffAnnotationModel(getEditor(), diffProviderId);
    if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // quick diff is showing with the wrong provider - ask the user whether he wants to switch
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) {
        MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openOkCancelConfirm(fViewer.getTextWidget().getShell(), RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, true, store, REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY);
        if (toggleDialog.getReturnCode() != Window.OK)
            return false;
    }
    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
    modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer);
    if (fDelegate instanceof IChangeRulerColumn)
        // picks up the new model attachment
        ((IChangeRulerColumn) fDelegate).setModel(annotationModel);
    return true;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) IChangeRulerColumn(org.eclipse.jface.text.source.IChangeRulerColumn) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 98 with IAnnotationModel

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

the class LineNumberColumn method uninstallChangeRulerModel.

/**
 * Uninstalls the differ annotation model from the current quick diff display.
 *
 * @param column the column to remove the model from
 */
private void uninstallChangeRulerModel(IVerticalRulerColumn column) {
    if (column instanceof IChangeRulerColumn)
        ((IChangeRulerColumn) column).setModel(null);
    IAnnotationModel model = getDiffer();
    if (model instanceof ILineDifferExtension)
        ((ILineDifferExtension) model).suspend();
    ISourceViewer viewer = fViewer;
    if (viewer != null && viewer.getAnnotationModel() == null)
        viewer.showAnnotations(false);
}
Also used : IChangeRulerColumn(org.eclipse.jface.text.source.IChangeRulerColumn) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Example 99 with IAnnotationModel

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

the class FileBufferFunctions method testGetFileStoreAnnotationModel.

/*
	 * Tests isSynchronized.
	 */
@Test
public void testGetFileStoreAnnotationModel() throws Exception {
    IFileStore fileStore = EFS.getNullFileSystem().getStore(new Path("/dev/null"));
    assertNotNull(fileStore);
    fManager.connectFileStore(fileStore, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fileStore);
        IAnnotationModel model = fileBuffer.getAnnotationModel();
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null)
            assertTrue(clazz.isInstance(model));
        else
            assertNotNull(model);
    } finally {
        fManager.disconnectFileStore(fileStore, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Test(org.junit.Test)

Example 100 with IAnnotationModel

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

the class FileBufferFunctions method test18.

/*
	 * Test annotation model existence.
	 * ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle.
	 */
@Test
public void test18() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertNotNull(buffer);
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null) {
            IAnnotationModel model = buffer.getAnnotationModel();
            assertTrue(clazz.isInstance(model));
        }
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Test(org.junit.Test)

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