org.eclipse.ui.texteditor.AnnotationPreference Java Examples

The following examples show how to use org.eclipse.ui.texteditor.AnnotationPreference. 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: BaseEditor.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IOverviewRuler createOverviewRuler(ISharedTextColors sharedColors) {
    // Note: create the minimap overview ruler regardless of whether it should be shown or not
    // (the setting to show it will control what's drawn).
    if (MinimapOverviewRulerPreferencesPage.useMinimap()) {
        IOutlineModel outlineModel = (IOutlineModel) this.getAdapter(IOutlineModel.class);
        IOverviewRuler ruler = new MinimapOverviewRuler(getAnnotationAccess(), sharedColors, outlineModel);

        Iterator e = getAnnotationPreferences().getAnnotationPreferences().iterator();
        while (e.hasNext()) {
            AnnotationPreference preference = (AnnotationPreference) e.next();
            if (preference.contributesToHeader()) {
                ruler.addHeaderAnnotationType(preference.getAnnotationType());
            }
        }
        return ruler;
    } else {
        return super.createOverviewRuler(sharedColors);
    }
}
 
Example #2
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether override indicators are shown.
 *
 * @return <code>true</code> if the override indicators are shown
 * @since 3.0
 */
protected boolean isShowingOverrideIndicators() {
	AnnotationPreference preference= getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
	IPreferenceStore store= getPreferenceStore();
	return getBoolean(store, preference.getHighlightPreferenceKey())
		|| getBoolean(store, preference.getVerticalRulerPreferenceKey())
		|| getBoolean(store, preference.getOverviewRulerPreferenceKey())
		|| getBoolean(store, preference.getTextPreferenceKey());
}
 
Example #3
Source File: AbstractAnnotationHover.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the annotation preference for the given annotation.
 *
 * @param annotation the annotation
 * @return the annotation preference or <code>null</code> if none
 */
private static AnnotationPreference getAnnotationPreference(Annotation annotation) {

	if (annotation.isMarkedDeleted())
		return null;
	return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
}
 
Example #4
Source File: SarosAnnotation.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads the default colors from the plugin.xml and overwrites possible errors in the EditorsUI
 * preference store.
 */
public static void resetColors() {

  log.debug("resetting annotation colors");

  final IPreferenceStore preferenceStore = EditorsUI.getPreferenceStore();

  final AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup();

  final String[] annotationTypesToReset = {
    SelectionAnnotation.TYPE, ViewportAnnotation.TYPE, ContributionAnnotation.TYPE
  };

  for (int i = 0; i <= SIZE; ++i) {

    for (String annotationType : annotationTypesToReset) {

      final String annotationTypeToLookup = getNumberedType(annotationType, i);

      final AnnotationPreference preference =
          lookup.getAnnotationPreference(annotationTypeToLookup);

      if (preference == null) {
        log.warn("could not reset color for annotation type: " + annotationTypeToLookup);
        continue;
      }

      preferenceStore.setToDefault(preference.getColorPreferenceKey());

      if (log.isTraceEnabled()) {
        log.trace(
            "reset "
                + annotationTypeToLookup
                + " to: "
                + preferenceStore.getString(preference.getColorPreferenceKey()));
      }
    }
  }
}
 
Example #5
Source File: SarosAnnotation.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color for the given annotation type and user color id.
 *
 *<p>E.g: <code>getColor("saros.annotations.viewport", 2)
 * <p><b>Important notice:</b> Every returned color instance allocates OS resources that need to
 * be disposed with {@link Color#dispose()}!
 *
 * @see Annotation#getType()
 * @param type annotation type as defined in the plugin.xml
 * @param colorId the color id
 * @return the corresponding color or a default one if no color is stored
 */
public static Color getColor(final String type, final int colorId) {

  final String typeToLookup = getNumberedType(type, colorId);

  final AnnotationPreference ap =
      EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(typeToLookup);

  if (ap == null)
    throw new IllegalArgumentException(
        "could not read color value of annotation '"
            + typeToLookup
            + "' because it does not exists");

  RGB rgb =
      PreferenceConverter.getColor(EditorsUI.getPreferenceStore(), ap.getColorPreferenceKey());

  if (rgb == PreferenceConverter.COLOR_DEFAULT_DEFAULT) { // NOPMD
    rgb = ap.getColorPreferenceValue();
  }

  if (rgb == null)
    throw new IllegalArgumentException(
        "annotation '" + typeToLookup + "' does not have a default color");

  return new Color(Display.getDefault(), rgb);
}
 
Example #6
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the annotation preference for the given annotation.
 *
 * @param annotation the annotation
 * @return the annotation preference or <code>null</code> if none
 */
private static AnnotationPreference getAnnotationPreference(Annotation annotation) {

	if (annotation.isMarkedDeleted())
		return null;
	return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
}
 
Example #7
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

	Object data= null;
	AnnotationPreference preference= getAnnotationPreference(fAnnotation);
	if (preference != null)
		data= preference.getPreferenceLabel();

	fInfoControl.dispose(); //FIXME: should have protocol to hide, rather than dispose
	PreferencesUtil.createPreferenceDialogOn(shell, "org.eclipse.ui.editors.preferencePages.Annotations", null, data).open(); //$NON-NLS-1$
}
 
Example #8
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Determines whether the preference change encoded by the given event
 * changes the override indication.
 *
 * @param event the event to be investigated
 * @return <code>true</code> if event causes a change
 * @since 3.0
 */
protected boolean affectsOverrideIndicatorAnnotations(PropertyChangeEvent event) {
	String key= event.getProperty();
	AnnotationPreference preference= getAnnotationPreferenceLookup().getAnnotationPreference(OverrideIndicatorManager.ANNOTATION_TYPE);
	if (key == null || preference == null)
		return false;

	return key.equals(preference.getHighlightPreferenceKey())
		|| key.equals(preference.getVerticalRulerPreferenceKey())
		|| key.equals(preference.getOverviewRulerPreferenceKey())
		|| key.equals(preference.getTextPreferenceKey());
}
 
Example #9
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 #10
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 #11
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 #12
Source File: CommitCommentArea.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private Color getSpellingErrorColor(Composite composite) {
	AnnotationPreference pref = EditorsUI
			.getAnnotationPreferenceLookup().getAnnotationPreference(
					"org.eclipse.ui.workbench.texteditor.spelling"); // $NON-NLS-1$
	String preferenceKey = pref.getColorPreferenceKey();
	try {
		return fResources.createColor(PreferenceConverter.getColor(EditorsUI.getPreferenceStore(), preferenceKey));
	} catch (DeviceResourceException e) {
		SVNUIPlugin.log(IStatus.ERROR, Policy.bind("internal"), e); //$NON-NLS-1$
		return JFaceColors.getErrorText(composite.getDisplay());
	}
}
 
Example #13
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates decoration support for the sourceViewer. code is entirely copied from
 * {@link XtextEditor} and its super class {@link AbstractDecoratedTextEditor}.
 *
 */
protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {
	MarkerAnnotationPreferences annotationPreferences = new MarkerAnnotationPreferences();
	List<AnnotationPreference> prefs = annotationPreferences.getAnnotationPreferences();
	for (AnnotationPreference annotationPreference : prefs) {
		support.setAnnotationPreference(annotationPreference);
	}

	support.setCharacterPairMatcher(getCharacterPairMatcher());
	support.setMatchingCharacterPainterPreferenceKeys(BracketMatchingPreferencesInitializer.IS_ACTIVE_KEY,
			BracketMatchingPreferencesInitializer.COLOR_KEY);

	support.install(getPreferenceStoreAccess().getPreferenceStore());
}
 
Example #14
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void run() {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

	Object data = null;
	AnnotationPreference preference = getAnnotationPreference(fAnnotation);
	if (preference != null)
		data = preference.getPreferenceLabel();

	fInfoControl.dispose(); // FIXME: should have protocol to hide,
							// rather than dispose
	PreferencesUtil
			.createPreferenceDialogOn(shell, "org.eclipse.ui.editors.preferencePages.Annotations", null, data) //$NON-NLS-1$
			.open();
}
 
Example #15
Source File: MarkOccurrencesPreferencePage.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createContents(final Composite parent) {
    Composite composite= new Composite(parent, SWT.NONE);
    GridLayout layout= new GridLayout();
    layout.numColumns= 1;
    layout.marginHeight= 0;
    layout.marginWidth= 0;
    composite.setLayout(layout);

    Link link= new Link(composite, SWT.NONE);
    link.setText(Messages.MarkOccurrencesPreferencePage_LinkText);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String data= null;
            AnnotationPreference preference= EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference("org.eclipse.jdt.ui.occurrences"); //$NON-NLS-1$
            if (preference != null)
                data= preference.getPreferenceLabel();
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, data);
        }
    });
    
    SWTFactory.createLabel(composite, "", 1); //$NON-NLS-1$
    
    cboxOnOff = SWTFactory.createCheckbox(composite, Messages.MarkOccurrencesPreferencePage_MarkOccurrencesOfElement, 1);
    
    initFromStore();
    return composite;
}
 
Example #16
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 #17
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 #18
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void setAnnotationColorsToMatchTheme(Theme theme)
{
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors"); //$NON-NLS-1$
	if (!theme.hasEntry("override.searchResultIndication")) //$NON-NLS-1$
	{
		prefs.put("searchResultIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
	}
	// TODO Use markup.changed bg color for "decoration color" in Prefs>General>Appearance>Colors and Fonts

	// TODO Move this stuff over to theme change listeners in the XML/HTML/Ruby editor plugins?
	if (!theme.hasEntry("override.xmlTagPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("xmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("xmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("xmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("xmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	if (!theme.hasEntry("override.htmlTagPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("htmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("htmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("htmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("htmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	if (!theme.hasEntry("override.rubyBlockPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("rubyBlockPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("rubyBlockPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("rubyBlockPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("rubyBlockPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	// PyDev Occurrences (com.python.pydev.occurrences)
	// Override them if pydev is set to use our themes
	if (Platform.getPreferencesService().getBoolean("org.python.pydev.red_core", "PYDEV_USE_APTANA_THEMES", true, //$NON-NLS-1$ //$NON-NLS-2$
			null))
	{
		if (!theme.hasEntry("override.pydevOccurrenceIndication")) //$NON-NLS-1$
		{
			MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
			AnnotationPreference pydevOccurPref = null;
			for (Object obj : preferences.getAnnotationPreferences())
			{
				AnnotationPreference pref = (AnnotationPreference) obj;
				Object type = pref.getAnnotationType();
				if ("com.python.pydev.occurrences".equals(type)) //$NON-NLS-1$
				{
					pydevOccurPref = pref;
				}
			}
			if (pydevOccurPref != null)
			{
				if (pydevOccurPref.getTextStylePreferenceKey() != null)
				{
					// Now that pydev supports text style, use the box style and don't highlight.
					prefs.putBoolean("pydevOccurrenceHighlighting", false); //$NON-NLS-1$
					prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
				}
				else
				{
					// Must use highlighting, since we're against older pydev that had no text style
					prefs.putBoolean("pydevOccurrenceHighlighting", true); //$NON-NLS-1$
					prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
				}
			}
		}
	}

	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example #19
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	IPath path;
	IAnnotationModel model;
	if (textViewer instanceof ISourceViewer) {
		path= null;
		model= ((ISourceViewer)textViewer).getAnnotationModel();
	} else {
		// Get annotation model from file buffer manager
		path= getEditorInputPath();
		model= getAnnotationModel(path);
	}
	if (model == null)
		return null;

	try {
		Iterator<Annotation> parent;
		if (model instanceof IAnnotationModelExtension2)
			parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true);
		else
			parent= model.getAnnotationIterator();
		Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations);

		int layer= -1;
		Annotation annotation= null;
		Position position= null;
		while (e.hasNext()) {
			Annotation a= e.next();

			AnnotationPreference preference= getAnnotationPreference(a);
			if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey()))))
				continue;

			Position p= model.getPosition(a);

			int l= fAnnotationAccess.getLayer(a);

			if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
				String msg= a.getText();
				if (msg != null && msg.trim().length() > 0) {
					layer= l;
					annotation= a;
					position= p;
				}
			}
		}
		if (layer > -1)
			return createAnnotationInfo(annotation, position, textViewer);

	} finally {
		try {
			if (path != null) {
				ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
				manager.disconnect(path, LocationKind.NORMALIZE, null);
			}
		} catch (CoreException ex) {
			JavaPlugin.log(ex.getStatus());
		}
	}

	return null;
}
 
Example #20
Source File: MarkOccurrencesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates page for mark occurrences preferences.
 *
 * @param parent the parent composite
 * @return the control for the preference page
 */
public Control createControl(final Composite parent) {

	Composite composite= new Composite(parent, SWT.NONE);
	GridLayout layout= new GridLayout();
	layout.numColumns= 1;
	layout.marginHeight= 0;
	layout.marginWidth= 0;
	composite.setLayout(layout);

	Link link= new Link(composite, SWT.NONE);
	link.setText(PreferencesMessages.MarkOccurrencesConfigurationBlock_link);
	link.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			String data= null;
			AnnotationPreference preference= EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference("org.eclipse.jdt.ui.occurrences"); //$NON-NLS-1$
			if (preference != null)
				data= preference.getPreferenceLabel();
			PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, data);
		}
	});

	addFiller(composite);

	String label;

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markOccurrences;
	Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0);

	addFiller(composite);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
	Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markBreakContinueTargets;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, 0);
	createDependency(master, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, slave);

	addFiller(composite);

	label= PreferencesMessages.MarkOccurrencesConfigurationBlock_stickyOccurrences;
	slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0);
	createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);

	return composite;
}
 
Example #21
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	IPath path;
	IAnnotationModel model;
	if (textViewer instanceof ISourceViewer) {
		path = null;
		model = ((ISourceViewer) textViewer).getAnnotationModel();
	} else {
		// Get annotation model from file buffer manager
		path = getEditorInputPath();
		model = getAnnotationModel(path);
	}
	if (model == null)
		return null;

	try {
		Iterator<Annotation> parent;
		if (model instanceof IAnnotationModelExtension2)
			parent = ((IAnnotationModelExtension2) model).getAnnotationIterator(hoverRegion.getOffset(),
					hoverRegion.getLength() > 0 ? hoverRegion.getLength() : 1, true, true);
		else
			parent = model.getAnnotationIterator();
		Iterator<Annotation> e = new TypeScriptAnnotationIterator(parent, fAllAnnotations);

		int layer = -1;
		Annotation annotation = null;
		Position position = null;
		while (e.hasNext()) {
			Annotation a = e.next();

			AnnotationPreference preference = getAnnotationPreference(a);
			if (preference == null || !(preference.getTextPreferenceKey() != null
			/*
			 * && fStore.getBoolean(preference.getTextPreferenceKey()) ||
			 * (preference.getHighlightPreferenceKey() != null &&
			 * fStore.getBoolean(preference.getHighlightPreferenceKey()))
			 */))
				continue;

			Position p = model.getPosition(a);

			int l = fAnnotationAccess.getLayer(a);

			if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
				String msg = a.getText();
				if (msg != null && msg.trim().length() > 0) {
					layer = l;
					annotation = a;
					position = p;
				}
			}
		}
		if (layer > -1)
			return createAnnotationInfo(annotation, position, textViewer);

	} finally {
		try {
			if (path != null) {
				ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
				manager.disconnect(path, LocationKind.NORMALIZE, null);
			}
		} catch (CoreException ex) {
			TypeScriptUIPlugin.log(ex.getStatus());
		}
	}

	return null;
}
 
Example #22
Source File: AbstractAnnotationHover.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
	public Object getHoverInfo(ISourceBuffer sourceBuffer, IRegion hoverRegion, ITextViewer textViewer) {
		
		if (!(textViewer instanceof ISourceViewer)) {
			return null;
		}
		
		ISourceViewer sourceViewer = (ISourceViewer) textViewer;
//		IPath path = null;
		IAnnotationModel model = sourceViewer.getAnnotationModel();
//		if (editor.getSourceViewer_() instanceof ISourceViewer) {
//			path= null;
//			model= editor.getSourceViewer_().getAnnotationModel();
//		} else {
//			// Get annotation model from file buffer manager
//			path= getEditorInputPath();
//			model= getAnnotationModel(path);
//		}
		if (model == null)
			return null;

//		try {
			Iterator<Annotation> parent;
			if (model instanceof IAnnotationModelExtension2)
				parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true);
			else
				parent= model.getAnnotationIterator();
			Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations);

			int layer= -1;
			Annotation annotation= null;
			Position position= null;
			while (e.hasNext()) {
				Annotation a= e.next();

				AnnotationPreference preference= getAnnotationPreference(a);
				if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey()))))
					continue;

				Position p= model.getPosition(a);

				int l= fAnnotationAccess.getLayer(a);

				if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
					String msg= a.getText();
					if (msg != null && msg.trim().length() > 0) {
						layer= l;
						annotation= a;
						position= p;
					}
				}
			}
			if (layer > -1)
				return createAnnotationInfo(annotation, position, textViewer);

//		} finally {
//			try {
//				if (path != null) {
//					ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
//					manager.disconnect(path, LocationKind.NORMALIZE, null);
//				}
//			} catch (CoreException ex) {
//				LangUIPlugin.logStatus(ex);
//			}
//		}

		return null;
	}
 
Example #23
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 3 votes vote down vote up
/**
 * Returns the annotation preference for the given annotation.
 *
 * @param annotation
 *            the annotation
 * @return the annotation preference or <code>null</code> if none
 */
private static AnnotationPreference getAnnotationPreference(Annotation annotation) {

	if (annotation.isMarkedDeleted())
		return null;
	return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation);
}