org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel Java Examples

The following examples show how to use org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpellChecker.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the actual position of <i>marker</i> or null if the marker was
 * deleted. Code inspired by 
 * @param marker
 * @param sourceViewer
 * @return
 */
private static int[] getMarkerPosition(IMarker marker, ISourceViewer sourceViewer) {
    int[] p = new int[2];
    p[0] = marker.getAttribute(IMarker.CHAR_START, -1);
    p[1] = marker.getAttribute(IMarker.CHAR_END, -1);
 // look up the current range of the marker when the document has been edited
    IAnnotationModel model= sourceViewer.getAnnotationModel();
    if (model instanceof AbstractMarkerAnnotationModel) {

        AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
        Position pos= markerModel.getMarkerPosition(marker);
        if (pos != null && !pos.isDeleted()) {
            // use position instead of marker values
            p[0] = pos.getOffset();
            p[1] = pos.getOffset() + pos.getLength();
        }

        if (pos != null && pos.isDeleted()) {
            // do nothing if position has been deleted
            return null;
        }
    }
    return p;
}
 
Example #2
Source File: XBookmarksUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fetches the marker annotation model for the currently edited document.
 * Note, that I would prefer to declare this as returning e.g.
 * IAnnotationModel, but the method to call somewhere else is
 * <code>updateMarkers(IDocument document)</code> which is not specified by
 * IAnnotationModel (the only interface implemented by
 * AbstractMarkerAnnotationModel).
 * 
 * @return the marker annotation model or <code>null</code>
 */
public static AbstractMarkerAnnotationModel getMarkerAnnotationModel() {
    IDocumentProvider provider = WorkbenchUtils.getActiveDocumentProvider();
    IDocument document = WorkbenchUtils.getActiveDocument();
    if ((provider != null) && (document != null)) {
        IAnnotationModel model = provider.getAnnotationModel(document);
        if (model instanceof AbstractMarkerAnnotationModel) {
            return (AbstractMarkerAnnotationModel) model;
        }
    }
    return null;
}
 
Example #3
Source File: MarkerRulerAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Fills markers field with all of the FindBugs markers associated with the
 * current line in the text editor's ruler marign.
 */
protected void obtainFindBugsMarkers() {
    // Delete old markers
    markers.clear();
    if (editor == null || ruler == null) {
        return;
    }

    // Obtain all markers in the editor
    IResource resource = (IResource) editor.getEditorInput().getAdapter(IFile.class);
    if (resource == null) {
        return;
    }
    IMarker[] allMarkers = MarkerUtil.getMarkers(resource, IResource.DEPTH_ZERO);
    if (allMarkers.length == 0) {
        return;
    }
    // Discover relevant markers, i.e. FindBugsMarkers
    AbstractMarkerAnnotationModel model = getModel();
    IDocument document = getDocument();
    for (int i = 0; i < allMarkers.length; i++) {
        if (includesRulerLine(model.getMarkerPosition(allMarkers[i]), document)) {
            if (MarkerUtil.isFindBugsMarker(allMarkers[i])) {
                markers.add(allMarkers[i]);
            }
        }
    }
}
 
Example #4
Source File: MarkerRulerAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Retrieves the AbstractMarkerAnnontationsModel from the editor.
 *
 * @return AbstractMarkerAnnotatiosnModel from the editor
 */
@CheckForNull
protected AbstractMarkerAnnotationModel getModel() {
    if (editor == null) {
        return null;
    }
    IDocumentProvider provider = editor.getDocumentProvider();
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (model instanceof AbstractMarkerAnnotationModel) {
        return (AbstractMarkerAnnotationModel) model;
    }
    return null;
}
 
Example #5
Source File: DecoratedScriptEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void saveDocument( )
{
	ScriptDocumentProvider provider = (ScriptDocumentProvider) getDocumentProvider( );
	try
	{
		( (AbstractMarkerAnnotationModel) provider.getAnnotationModel( getEditorInput( ) ) ).commit( provider.getDocument( getEditorInput( ) ) );
	}
	catch ( CoreException e )
	{
		// do nothing
	}
}
 
Example #6
Source File: PyMarkerUIUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the position for a marker.
 */
public static Position getMarkerPosition(IDocument document, IMarker marker, IAnnotationModel model) {
    if (model instanceof AbstractMarkerAnnotationModel) {
        Position ret = ((AbstractMarkerAnnotationModel) model).getMarkerPosition(marker);
        if (ret != null) {
            return ret;
        }
    }
    int start = MarkerUtilities.getCharStart(marker);
    int end = MarkerUtilities.getCharEnd(marker);

    if (start > end) {
        end = start + end;
        start = end - start;
        end = end - start;
    }

    if (start == -1 && end == -1) {
        // marker line number is 1-based
        int line = MarkerUtilities.getLineNumber(marker);
        if (line > 0 && document != null) {
            try {
                start = document.getLineOffset(line - 1);
                end = start;
            } catch (BadLocationException x) {
            }
        }
    }

    if (start > -1 && end > -1) {
        return new Position(start, end - start);
    }

    return null;
}
 
Example #7
Source File: JavaSelectAnnotationRulerAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void findJavaAnnotation() {
	fPosition= null;
	fAnnotation= null;
	fHasCorrection= false;

	AbstractMarkerAnnotationModel model= getAnnotationModel();
	IAnnotationAccessExtension annotationAccess= getAnnotationAccessExtension();

	IDocument document= getDocument();
	if (model == null)
		return ;

	boolean hasAssistLightbulb= fStore.getBoolean(PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB);

	Iterator<Annotation> iter= model.getAnnotationIterator();
	int layer= Integer.MIN_VALUE;

	while (iter.hasNext()) {
		Annotation annotation= iter.next();
		if (annotation.isMarkedDeleted())
			continue;

		int annotationLayer= layer;
		if (annotationAccess != null) {
			annotationLayer= annotationAccess.getLayer(annotation);
			if (annotationLayer < layer)
				continue;
		}

		Position position= model.getPosition(annotation);
		if (!includesRulerLine(position, document))
			continue;

		AnnotationPreference preference= fAnnotationPreferenceLookup.getAnnotationPreference(annotation);
		if (preference == null)
			continue;

		String key= preference.getVerticalRulerPreferenceKey();
		if (key == null)
			continue;

		if (!fStore.getBoolean(key))
			continue;

		boolean isReadOnly= fTextEditor instanceof ITextEditorExtension && ((ITextEditorExtension)fTextEditor).isEditorInputReadOnly();
		if (!isReadOnly
				&& (
					((hasAssistLightbulb && annotation instanceof AssistAnnotation)
					|| JavaCorrectionProcessor.hasCorrections(annotation)))) {
			fPosition= position;
			fAnnotation= annotation;
			fHasCorrection= true;
			layer= annotationLayer;
			continue;
		} else if (!fHasCorrection) {
				fPosition= position;
				fAnnotation= annotation;
				layer= annotationLayer;
		}
	}
}
 
Example #8
Source File: ReportXMLSourceEditorFormPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean selectReveal( Object marker )
{
	int start = MarkerUtilities.getCharStart( (IMarker) marker );
	int end = MarkerUtilities.getCharEnd( (IMarker) marker );

	boolean selectLine = start < 0 || end < 0;

	// look up the current range of the marker when the document has been
	// edited
	IAnnotationModel model = reportXMLEditor.getDocumentProvider( )
			.getAnnotationModel( reportXMLEditor.getEditorInput( ) );
	if ( model instanceof AbstractMarkerAnnotationModel )
	{
		AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
		Position pos = markerModel.getMarkerPosition( (IMarker) marker );
		if ( pos != null )
		{
			if ( !pos.isDeleted( ) )
			{
				// use position instead of marker values
				start = pos.getOffset( );
				end = pos.getOffset( ) + pos.getLength( );
			}
			else
			{
				return false;
			}
		}
	}

	IDocument document = reportXMLEditor.getDocumentProvider( )
			.getDocument( reportXMLEditor.getEditorInput( ) );
	if ( selectLine )
	{
		int line;
		try
		{
			if ( start >= 0 )
				line = document.getLineOfOffset( start );
			else
			{
				line = MarkerUtilities.getLineNumber( (IMarker) marker );
				// Marker line numbers are 1-based
				if ( line >= 1 )
				{
					line--;
				}
				start = document.getLineOffset( line );
			}
			end = start + document.getLineLength( line ) - 1;
		}
		catch ( BadLocationException e )
		{
			return false;
		}
	}

	int length = document.getLength( );
	if ( end - 1 < length && start < length )
		reportXMLEditor.selectAndReveal( start, end - start );
	return true;
}