Search in sources :

Example 1 with SourceViewerDecorationSupport

use of org.eclipse.ui.texteditor.SourceViewerDecorationSupport in project mylyn.docs by eclipse.

the class MarkupTaskEditorExtension method createEditor.

@SuppressWarnings("unchecked")
@Override
public SourceViewer createEditor(TaskRepository taskRepository, Composite parent, int style, IAdaptable context) {
    final MarkupLanguageType markupLanguageCopy = createRepositoryMarkupLanguage(taskRepository);
    configureMarkupLanguage(taskRepository, markupLanguageCopy);
    SourceViewer viewer = new MarkupSourceViewer(parent, null, style | SWT.WRAP, markupLanguageCopy);
    // configure the viewer
    MarkupSourceViewerConfiguration configuration = createSourceViewerConfiguration(taskRepository, viewer, context);
    configuration.setEnableSelfContainedIncrementalFind(true);
    configuration.setMarkupLanguage(markupLanguageCopy);
    configuration.setShowInTarget(new ShowInTargetBridge(viewer));
    viewer.configure(configuration);
    // we want the viewer to show annotations
    viewer.showAnnotations(true);
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    MarkerAnnotationPreferences annotationPreferences = new MarkerAnnotationPreferences();
    // configure viewer annotation/decoration support
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess, EditorsUI.getSharedTextColors());
    // hook the support up to the preference store
    Iterator<AnnotationPreference> e = annotationPreferences.getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        AnnotationPreference preference = e.next();
        support.setAnnotationPreference(preference);
    }
    support.setCursorLinePainterPreferenceKeys(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
    support.setMarginPainterPreferenceKeys(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN);
    support.install(new EditorExtensionPreferenceStore(EditorsUI.getPreferenceStore(), viewer.getControl()));
    viewer.getControl().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            support.dispose();
        }
    });
    IFocusService focusService = PlatformUI.getWorkbench().getService(IFocusService.class);
    if (focusService != null) {
        focusService.addFocusTracker(viewer.getTextWidget(), MarkupEditor.EDITOR_SOURCE_VIEWER);
    }
    viewer.getTextWidget().setData(MarkupLanguage.class.getName(), markupLanguageCopy);
    viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
    return viewer;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) MarkupSourceViewer(org.eclipse.mylyn.wikitext.ui.editor.MarkupSourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IFocusService(org.eclipse.ui.swt.IFocusService) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) MarkupSourceViewer(org.eclipse.mylyn.wikitext.ui.editor.MarkupSourceViewer) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) ShowInTargetBridge(org.eclipse.mylyn.wikitext.ui.editor.ShowInTargetBridge) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) MarkupSourceViewerConfiguration(org.eclipse.mylyn.wikitext.ui.editor.MarkupSourceViewerConfiguration)

Example 2 with SourceViewerDecorationSupport

use of org.eclipse.ui.texteditor.SourceViewerDecorationSupport in project egit by eclipse.

the class SpellcheckableMessageArea method configureAnnotationPreferences.

private SourceViewerDecorationSupport configureAnnotationPreferences() {
    ISharedTextColors textColors = EditorsUI.getSharedTextColors();
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(sourceViewer, null, annotationAccess, textColors);
    List annotationPreferences = new MarkerAnnotationPreferences().getAnnotationPreferences();
    Iterator e = annotationPreferences.iterator();
    while (e.hasNext()) support.setAnnotationPreference((AnnotationPreference) e.next());
    support.install(EditorsUI.getPreferenceStore());
    return support;
}
Also used : ISharedTextColors(org.eclipse.jface.text.source.ISharedTextColors) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) Iterator(java.util.Iterator) IntList(org.eclipse.jgit.util.IntList) List(java.util.List) ArrayList(java.util.ArrayList) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport)

Example 3 with SourceViewerDecorationSupport

use of org.eclipse.ui.texteditor.SourceViewerDecorationSupport in project eclipse-integration-commons by spring-projects.

the class EditorToolkit method createTextEditor.

public TextViewer createTextEditor(Composite composite, String text, boolean spellCheck, int style) {
    AnnotationModel annotationModel = new AnnotationModel();
    final SourceViewer textViewer = new SourceViewer(composite, null, null, true, style);
    textViewer.showAnnotations(false);
    textViewer.showAnnotationsOverview(false);
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(textViewer, null, annotationAccess, EditorsUI.getSharedTextColors());
    @SuppressWarnings("unchecked") Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        support.setAnnotationPreference((AnnotationPreference) e.next());
    }
    support.install(EditorsUI.getPreferenceStore());
    textViewer.getTextWidget().setIndent(2);
    textViewer.getTextWidget().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            support.uninstall();
        }
    });
    IThemeManager themeManager = editorSite.getWorkbenchWindow().getWorkbench().getThemeManager();
    textViewer.getTextWidget().setFont(themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT));
    final ActionContributorProxy actionContributor = getContributor();
    if (actionContributor.getSelectionChangedListener() != null) {
        textViewer.addSelectionChangedListener(actionContributor.getSelectionChangedListener());
    }
    textViewer.getTextWidget().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }

        public void focusLost(FocusEvent e) {
            StyledText st = (StyledText) e.widget;
            st.setSelectionRange(st.getCaretOffset(), 0);
            actionContributor.forceActionsEnabled();
        }
    });
    textViewer.addTextListener(new ITextListener() {

        public void textChanged(TextEvent event) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }
    });
    Document document = new Document(text);
    StsTextViewerConfiguration viewerConfig = new StsTextViewerConfiguration(spellCheck, false);
    textViewer.configure(viewerConfig);
    textViewer.setDocument(document, annotationModel);
    EditorUtil.setTextViewer(textViewer.getControl(), textViewer);
    configureContextMenuManager(textViewer.getControl());
    return textViewer;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TextEvent(org.eclipse.jface.text.TextEvent) ITextListener(org.eclipse.jface.text.ITextListener) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) IThemeManager(org.eclipse.ui.themes.IThemeManager) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) FocusEvent(org.eclipse.swt.events.FocusEvent) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) Iterator(java.util.Iterator) FocusListener(org.eclipse.swt.events.FocusListener)

Example 4 with SourceViewerDecorationSupport

use of org.eclipse.ui.texteditor.SourceViewerDecorationSupport in project xtext-xtend by eclipse.

the class DerivedSourceView method createSourceViewer.

@Override
protected SourceViewer createSourceViewer(Composite parent) {
    IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
    IOverviewRuler overviewRuler = new OverviewRuler(defaultMarkerAnnotationAccess, OVERVIEW_RULER_WIDTH, getSharedTextColors());
    AnnotationRulerColumn annotationRulerColumn = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, defaultMarkerAnnotationAccess);
    List<AnnotationPreference> annotationPreferences = markerAnnotationPreferences.getAnnotationPreferences();
    for (AnnotationPreference annotationPreference : annotationPreferences) {
        String key = annotationPreference.getVerticalRulerPreferenceKey();
        boolean showAnnotation = true;
        if (key != null && store.contains(key)) {
            showAnnotation = store.getBoolean(key);
        }
        if (showAnnotation) {
            annotationRulerColumn.addAnnotationType(annotationPreference.getAnnotationType());
        }
    }
    annotationRulerColumn.addAnnotationType(Annotation.TYPE_UNKNOWN);
    lineNumberRulerColumn = new LineNumberRulerColumn();
    CompositeRuler compositeRuler = new CompositeRuler();
    compositeRuler.addDecorator(0, annotationRulerColumn);
    compositeRuler.addDecorator(1, lineNumberRulerColumn);
    javaSourceViewer = new JavaSourceViewer(parent, compositeRuler, overviewRuler, true, SWT.V_SCROLL | SWT.H_SCROLL, store);
    javaSourceViewerConfiguration = new SimpleJavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true) {

        @Override
        public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
            return new IInformationControlCreator() {

                @Override
                public IInformationControl createInformationControl(final Shell parent) {
                    return new DefaultInformationControl(parent, true);
                }
            };
        }

        @Override
        public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
            return new DefaultAnnotationHover();
        }
    };
    javaSourceViewer.configure(javaSourceViewerConfiguration);
    javaSourceViewer.setEditable(false);
    javaSourceViewer.showAnnotations(true);
    sourceViewerDecorationSupport = new SourceViewerDecorationSupport(javaSourceViewer, overviewRuler, defaultMarkerAnnotationAccess, getSharedTextColors());
    for (AnnotationPreference annotationPreference : annotationPreferences) {
        sourceViewerDecorationSupport.setAnnotationPreference(annotationPreference);
    }
    sourceViewerDecorationSupport.install(preferenceStoreAccess.getPreferenceStore());
    return javaSourceViewer;
}
Also used : LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) SimpleJavaSourceViewerConfiguration(org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration) DefaultInformationControl(org.eclipse.jface.text.DefaultInformationControl) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) IAnnotationHover(org.eclipse.jface.text.source.IAnnotationHover) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) IInformationControlCreator(org.eclipse.jface.text.IInformationControlCreator) AnnotationRulerColumn(org.eclipse.jface.text.source.AnnotationRulerColumn) Shell(org.eclipse.swt.widgets.Shell) IInformationControl(org.eclipse.jface.text.IInformationControl) JavaSourceViewer(org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer) OverviewRuler(org.eclipse.jface.text.source.OverviewRuler) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) DefaultAnnotationHover(org.eclipse.jface.text.source.DefaultAnnotationHover)

Example 5 with SourceViewerDecorationSupport

use of org.eclipse.ui.texteditor.SourceViewerDecorationSupport in project tdi-studio-se by Talend.

the class ReconcilerViewer method getSourceViewerDecorationSupport.

protected SourceViewerDecorationSupport getSourceViewerDecorationSupport() {
    if (fSourceViewerDecorationSupport == null) {
        fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(this, fOverviewRuler, annotationAccess, sharedColors);
        configureSourceViewerDecorationSupport(fSourceViewerDecorationSupport);
    }
    return fSourceViewerDecorationSupport;
}
Also used : SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport)

Aggregations

SourceViewerDecorationSupport (org.eclipse.ui.texteditor.SourceViewerDecorationSupport)7 AnnotationPreference (org.eclipse.ui.texteditor.AnnotationPreference)5 DefaultMarkerAnnotationAccess (org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess)3 MarkerAnnotationPreferences (org.eclipse.ui.texteditor.MarkerAnnotationPreferences)3 Iterator (java.util.Iterator)2 IAnnotationAccess (org.eclipse.jface.text.source.IAnnotationAccess)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 SourceViewer (org.eclipse.jface.text.source.SourceViewer)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JavaSourceViewer (org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer)1 SimpleJavaSourceViewerConfiguration (org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 DefaultInformationControl (org.eclipse.jface.text.DefaultInformationControl)1 Document (org.eclipse.jface.text.Document)1 IInformationControl (org.eclipse.jface.text.IInformationControl)1 IInformationControlCreator (org.eclipse.jface.text.IInformationControlCreator)1 ITextListener (org.eclipse.jface.text.ITextListener)1