Search in sources :

Example 1 with StructuredMarkerAnnotation

use of org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation in project webtools.sourceediting by eclipse.

the class AbstractStructuredTextReconcilingStrategy method getAnnotationsToRemove.

protected TemporaryAnnotation[] getAnnotationsToRemove(DirtyRegion dr, List stepsRun) {
    List remove = new ArrayList();
    IAnnotationModel annotationModel = getAnnotationModel();
    // can be null when closing the editor
    if (getAnnotationModel() != null) {
        // clear validator annotations
        getMarkerAnnotations().clear();
        Iterator i = annotationModel.getAnnotationIterator();
        while (i.hasNext()) {
            Object obj = i.next();
            // if it is save it for comparision later (to "gray" icons)
            if (obj instanceof StructuredMarkerAnnotation) {
                StructuredMarkerAnnotation sma = (StructuredMarkerAnnotation) obj;
                if (sma.getAnnotationType() == TemporaryAnnotation.ANNOT_ERROR || sma.getAnnotationType() == TemporaryAnnotation.ANNOT_WARNING)
                    fMarkerAnnotations.add(sma);
            }
            if (!(obj instanceof TemporaryAnnotation))
                continue;
            TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
            ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
            // partition type
            if (canHandlePartition(key.getPartitionType()) && stepsRun.contains(key.getStep())) {
                if (key.getScope() == ReconcileAnnotationKey.PARTIAL && annotation.getPosition().overlapsWith(dr.getOffset(), dr.getLength())) {
                    remove.add(annotation);
                } else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
                    remove.add(annotation);
                }
            }
        }
    }
    return (TemporaryAnnotation[]) remove.toArray(new TemporaryAnnotation[remove.size()]);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ITemporaryAnnotation(org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation) StructuredMarkerAnnotation(org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)

Example 2 with StructuredMarkerAnnotation

use of org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation in project webtools.sourceediting by eclipse.

the class AbstractStructuredTextReconcilingStrategy method addResultToAnnotationModel.

/**
 * This is where we add results to the annotationModel, doing any special
 * "extra" processing.
 */
protected void addResultToAnnotationModel(IReconcileResult result) {
    if (!(result instanceof TemporaryAnnotation))
        return;
    // can be null when closing the editor
    if (getAnnotationModel() != null) {
        TemporaryAnnotation tempAnnotation = (TemporaryAnnotation) result;
        StructuredMarkerAnnotation sma = getCorrespondingMarkerAnnotation(tempAnnotation);
        if (sma != null) {
            // un-gray out the marker annotation
            sma.setGrayed(false);
        }
        getAnnotationModel().addAnnotation(tempAnnotation, tempAnnotation.getPosition());
    }
}
Also used : ITemporaryAnnotation(org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation) StructuredMarkerAnnotation(org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)

Example 3 with StructuredMarkerAnnotation

use of org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation in project webtools.sourceediting by eclipse.

the class AbstractStructuredTextReconcilingStrategy method getCorrespondingMarkerAnnotation.

private StructuredMarkerAnnotation getCorrespondingMarkerAnnotation(TemporaryAnnotation tempAnnotation) {
    Iterator it = getMarkerAnnotations().iterator();
    while (it.hasNext()) {
        StructuredMarkerAnnotation markerAnnotation = (StructuredMarkerAnnotation) it.next();
        // $NON-NLS-1$
        String message = "";
        try {
            message = (String) markerAnnotation.getMarker().getAttribute(IMarker.MESSAGE);
        } catch (CoreException e) {
            if (DEBUG)
                Logger.logException(e);
        }
        // it would be nice to check line number here...
        if (message != null && message.equals(tempAnnotation.getText()))
            return markerAnnotation;
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) StructuredMarkerAnnotation(org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)

Example 4 with StructuredMarkerAnnotation

use of org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation in project webtools.sourceediting by eclipse.

the class AbstractStructuredTextReconcilingStrategy method removeAnnotations.

private void removeAnnotations(TemporaryAnnotation[] annotationsToRemove) {
    IAnnotationModel annotationModel = getAnnotationModel();
    // can be null when closing the editor
    if (annotationModel != null) {
        for (int i = 0; i < annotationsToRemove.length; i++) {
            if (isCanceled()) {
                if (DEBUG)
                    // $NON-NLS-1$
                    System.out.println("[trace reconciler] >** REMOVAL WAS CANCELLED **");
                return;
            }
            StructuredMarkerAnnotation sma = getCorrespondingMarkerAnnotation(annotationsToRemove[i]);
            if (sma != null) {
                // gray out the marker annotation
                sma.setGrayed(true);
            }
            // remove the temp one
            annotationModel.removeAnnotation(annotationsToRemove[i]);
        }
    }
    if (DEBUG) {
        StringBuffer traceString = new StringBuffer();
        for (int i = 0; i < annotationsToRemove.length; i++) // $NON-NLS-1$ //$NON-NLS-2$
        traceString.append("\n (-) :" + annotationsToRemove[i] + ":\n");
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("[trace reconciler] > REMOVED (" + annotationsToRemove.length + ") annotations in AbstractStructuredTextReconcilingStrategy :" + traceString);
    }
}
Also used : IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) StructuredMarkerAnnotation(org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)

Aggregations

StructuredMarkerAnnotation (org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)4 Iterator (java.util.Iterator)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 ITemporaryAnnotation (org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1