org.eclipse.jface.text.source.IAnnotationAccessExtension Java Examples

The following examples show how to use org.eclipse.jface.text.source.IAnnotationAccessExtension. 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: SourceCodeTextEditor.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int getLayer(Annotation annotation) {
       if (annotation instanceof MarkerAnnotation) {
           MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
           IMarker im = markerAnnotation.getMarker();
           try {
                  if (XdsMarkerConstants.BUILD_PROBLEM_MARKER_TYPE.equals(im.getType()) &&
                      im.getAttribute(XdsMarkerConstants.MARKER_GRAY_STATE, false)) 
                  {
                      markerAnnotation.markDeleted(true);
                      return IAnnotationAccessExtension.DEFAULT_LAYER; // place gray markers under all other 
                  }
              } catch (Exception e) { // hz
              }
       }
          return super.getLayer(annotation);
}
 
Example #2
Source File: XtextAnnotation.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public XtextAnnotation(String type, boolean isPersistent, IXtextDocument document, Issue issue, boolean isQuickfixable) {
	super(type, isPersistent, issue.getMessage());
	
	AnnotationPreference preference= lookup.getAnnotationPreference(this);
	if (preference != null)
		this.layer = preference.getPresentationLayer() + 1;
	else
		this.layer = IAnnotationAccessExtension.DEFAULT_LAYER + 1;
	
	this.document = document;
	this.issue = issue;
	this.isQuickfixable = isQuickfixable;
}
 
Example #3
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IAnnotationAccess createAnnotationAccess() {
	return new DefaultMarkerAnnotationAccess() {
		@Override
		public int getLayer(Annotation annotation) {
			if (annotation.isMarkedDeleted()) {
				return IAnnotationAccessExtension.DEFAULT_LAYER;
			}
			return super.getLayer(annotation);
		}
	};
}
 
Example #4
Source File: ProblemAnnotation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup)
{
	Annotation annotation = new Annotation(annotationType, false, null);
	AnnotationPreference preference = lookup.getAnnotationPreference(annotation);
	if (preference != null)
	{
		return preference.getPresentationLayer() + 1;
	}
	else
	{
		return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
	}
}
 
Example #5
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
	Annotation annotation= new Annotation(annotationType, false, null);
	AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
	if (preference != null)
		return preference.getPresentationLayer() + 1;
	else
		return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
}
 
Example #6
Source File: AnnotationExpandHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected int getOrder(Annotation annotation) {
	if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
		IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
		return extension.getLayer(annotation);
	}
	return IAnnotationAccessExtension.DEFAULT_LAYER;
}
 
Example #7
Source File: CopiedOverviewRuler.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isSubtype(Object annotationType) {
    if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
        IAnnotationAccessExtension extension = (IAnnotationAccessExtension) fAnnotationAccess;
        return extension.isSubtype(annotationType, fType);
    }
    return fType.equals(annotationType);
}
 
Example #8
Source File: CopiedOverviewRuler.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Computes whether the annotations of the given type are covered by the given <code>configured</code>
 * set. This is the case if either the type of the annotation or any of its
 * super types is contained in the <code>configured</code> set.
 *
 * @param annotationType the annotation type
 * @param configured the set with configured annotation types
 * @return <code>true</code> if annotation is covered, <code>false</code>
 *         otherwise
 * @since 3.0
 */
private boolean isCovered(Object annotationType, Set configured) {
    if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
        IAnnotationAccessExtension extension = (IAnnotationAccessExtension) fAnnotationAccess;
        Iterator e = configured.iterator();
        while (e.hasNext()) {
            if (extension.isSubtype(annotationType, e.next())) {
                return true;
            }
        }
        return false;
    }
    return configured.contains(annotationType);
}
 
Example #9
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 #10
Source File: AnnotationExpansionControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
	 * Creates a new control.
	 *
	 * @param parent parent shell
	 * @param shellStyle additional style flags
	 * @param access the annotation access
	 */
	public AnnotationExpansionControl(Shell parent, int shellStyle, IAnnotationAccess access) {
		fPaintListener= new MyPaintListener();
		fMouseTrackListener= new MyMouseTrackListener();
		fMouseListener= new MyMouseListener();
		fMenuDetectListener= new MyMenuDetectListener();
		fDisposeListener= new MyDisposeListener();
		fViewportListener= new IViewportListener() {

			public void viewportChanged(int verticalOffset) {
				dispose();
			}

		};
		fLayouter= new LinearLayouter();

		if (access instanceof IAnnotationAccessExtension)
			fAnnotationAccessExtension= (IAnnotationAccessExtension) access;

		fShell= new Shell(parent, shellStyle | SWT.NO_FOCUS | SWT.ON_TOP);
		Display display= fShell.getDisplay();
		fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
		fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM);
//		fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.V_SCROLL);

		GridLayout layout= new GridLayout(1, true);
		layout.marginHeight= 0;
		layout.marginWidth= 0;
		fShell.setLayout(layout);

		GridData data= new GridData(GridData.FILL_BOTH);
		data.heightHint= fLayouter.getAnnotationSize() + 2 * fLayouter.getBorderWidth() + 4;
		fComposite.setLayoutData(data);
		fComposite.addMouseTrackListener(new MouseTrackAdapter() {

			@Override
			public void mouseExit(MouseEvent e) {
				if (fComposite == null)
						return;
				Control[] children= fComposite.getChildren();
				Rectangle bounds= null;
				for (int i= 0; i < children.length; i++) {
					if (bounds == null)
						bounds= children[i].getBounds();
					else
						bounds.add(children[i].getBounds());
					if (bounds.contains(e.x, e.y))
						return;
				}

				// if none of the children contains the event, we leave the popup
				dispose();
			}

		});

//		fComposite.getVerticalBar().addListener(SWT.Selection, new Listener() {
//
//			public void handleEvent(Event event) {
//				Rectangle bounds= fShell.getBounds();
//				int x= bounds.x - fLayouter.getAnnotationSize() - fLayouter.getBorderWidth();
//				int y= bounds.y;
//				fShell.setBounds(x, y, bounds.width, bounds.height);
//			}
//
//		});

		Cursor handCursor= getHandCursor(display);
		fShell.setCursor(handCursor);
		fComposite.setCursor(handCursor);

		setInfoSystemColor();
	}
 
Example #11
Source File: JavaExpandHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Object getHoverInfoForLine(final ISourceViewer viewer, final int line) {
	final boolean showTemporaryProblems= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
	IAnnotationModel model= viewer.getAnnotationModel();
	IDocument document= viewer.getDocument();

	if (model == null)
		return null;

	List<Annotation> exact= new ArrayList<Annotation>();
	HashMap<Position, Object> messagesAtPosition= new HashMap<Position, Object>();

	Iterator<Annotation> e= model.getAnnotationIterator();
	while (e.hasNext()) {
		Annotation annotation= e.next();

		if (fAnnotationAccess instanceof IAnnotationAccessExtension)
			if (!((IAnnotationAccessExtension)fAnnotationAccess).isPaintable(annotation))
				continue;

		if (annotation instanceof IJavaAnnotation && !isIncluded((IJavaAnnotation)annotation, showTemporaryProblems))
			continue;

		AnnotationPreference pref= fLookup.getAnnotationPreference(annotation);
		if (pref != null) {
			String key= pref.getVerticalRulerPreferenceKey();
			if (key != null && !fStore.getBoolean(key))
				continue;
		}

		Position position= model.getPosition(annotation);
		if (position == null)
			continue;

		if (compareRulerLine(position, document, line) == 1) {

			if (isDuplicateMessage(messagesAtPosition, position, annotation.getText()))
				continue;

			exact.add(annotation);
		}
	}

	sort(exact, model);

	if (exact.size() > 0)
		setLastRulerMouseLocation(viewer, line);

	if (exact.size() > 0) {
		Annotation first= exact.get(0);
		if (!isBreakpointAnnotation(first))
			exact.add(0, new NoBreakpointAnnotation());
	}

	if (exact.size() <= 1)
		return null;

	AnnotationHoverInput input= new AnnotationHoverInput();
	input.fAnnotations= exact.toArray(new Annotation[0]);
	input.fViewer= viewer;
	input.fRulerInfo= fCompositeRuler;
	input.fAnnotationListener= fgListener;
	input.fDoubleClickListener= fDblClickListener;
	input.redoAction= new AnnotationExpansionControl.ICallback() {

		public void run(IInformationControlExtension2 control) {
			control.setInput(getHoverInfoForLine(viewer, line));
		}

	};
	input.model= model;

	return input;
}
 
Example #12
Source File: CopiedOverviewRuler.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Updates the header tool tip text of this ruler.
 */
private void updateHeaderToolTipText() {
    if (fHeader == null || fHeader.isDisposed()) {
        return;
    }

    if (fHeader.getToolTipText() != null) {
        return;
    }

    String overview = ""; //$NON-NLS-1$

    for (int i = fAnnotationsSortedByLayer.size() - 1; i >= 0; i--) {

        Object annotationType = fAnnotationsSortedByLayer.get(i);

        if (skipInHeader(annotationType) || skip(annotationType)) {
            continue;
        }

        int count = 0;
        String annotationTypeLabel = null;

        Iterator e = new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY
                | FilterIterator.IGNORE_BAGS, fCachedAnnotations.iterator());
        while (e.hasNext()) {
            Annotation annotation = (Annotation) e.next();
            if (annotation != null) {
                if (annotationTypeLabel == null) {
                    annotationTypeLabel = ((IAnnotationAccessExtension) fAnnotationAccess).getTypeLabel(annotation);
                }
                count++;
            }
        }

        if (annotationTypeLabel != null) {
            if (overview.length() > 0)
            {
                overview += "\n"; //$NON-NLS-1$
            }
            overview += annotationTypeLabel + ":" + count; //$NON-NLS-1$ fabioz change; not user internal formatter
        }
    }

    if (overview.length() > 0) {
        fHeader.setToolTipText(overview);
    }
}