Search in sources :

Example 6 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel in project xtext-eclipse by eclipse.

the class EmbeddedEditorModelAccess method setModel.

protected void setModel(XtextDocument document, String prefix, String editablePart, String suffix) {
    if (this.insertLineBreaks) {
        String delimiter = document.getDefaultLineDelimiter();
        prefix = prefix + delimiter;
        suffix = delimiter + suffix;
    }
    String model = prefix + editablePart + suffix;
    document.set(model);
    XtextResource resource = createResource(model);
    document.setInput(resource);
    AnnotationModel annotationModel = new AnnotationModel();
    if (document instanceof ISynchronizable) {
        Object lock = ((ISynchronizable) document).getLockObject();
        if (lock == null) {
            lock = new Object();
            ((ISynchronizable) document).setLockObject(lock);
        }
        ((ISynchronizable) annotationModel).setLockObject(lock);
    }
    this.viewer.setDocument(document, annotationModel, prefix.length(), editablePart.length());
}
Also used : ISynchronizable(org.eclipse.jface.text.ISynchronizable) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) XtextResource(org.eclipse.xtext.resource.XtextResource) EObject(org.eclipse.emf.ecore.EObject)

Example 7 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel in project mylyn.docs by eclipse.

the class HtmlViewer method parse.

protected ParseResult parse(String htmlText) {
    initPainter();
    ParseResult result = new ParseResult();
    result.textPresentation = new TextPresentation();
    HtmlTextPresentationParser parser = new HtmlTextPresentationParser();
    if (stylesheet != null) {
        parser.setStylesheet(stylesheet);
    }
    if (displayImages) {
        parser.setImageCache(imageCache);
        parser.setEnableImages(displayImages);
    }
    parser.setPresentation(result.textPresentation);
    parser.setDefaultFont(getTextWidget().getFont());
    parser.setDefaultMonospaceFont(defaultMonospaceFont);
    result.annotationModel = new AnnotationModel();
    parser.setAnnotationModel(result.annotationModel);
    GC gc = new GC(getTextWidget());
    try {
        parser.setGC(gc);
        parser.parse(htmlText);
    } catch (SAXException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        gc.dispose();
    }
    result.text = parser.getText();
    return result;
}
Also used : HtmlTextPresentationParser(org.eclipse.mylyn.internal.wikitext.ui.viewer.HtmlTextPresentationParser) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IOException(java.io.IOException) GC(org.eclipse.swt.graphics.GC) TextPresentation(org.eclipse.jface.text.TextPresentation) SAXException(org.xml.sax.SAXException)

Example 8 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel 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 9 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel in project eclipse.platform.text by eclipse.

the class LineNumberColumn method ensureQuickDiffProvider.

/**
 * Ensures that quick diff information is displayed and the quick diff provider is the one with
 * the specified id. If a different quick diff provider is in use, the user may be asked whether
 * he wants to switch.
 *
 * @param diffProviderId the quick diff provider id to use
 * @return <code>true</code> if quick diff could be enabled for the given id,
 *         <code>false</code> otherwise
 */
private boolean ensureQuickDiffProvider(String diffProviderId) {
    if (!isShowingChangeInformation())
        // FIXME pass provider id
        installChangeRulerModel(fDelegate);
    IAnnotationModel annotationModel = fViewer.getAnnotationModel();
    IAnnotationModel oldDiffer = getDiffer();
    if (oldDiffer == null && annotationModel != null)
        // quick diff is enabled, but no differ? not working for whatever reason
        return false;
    if (annotationModel == null)
        annotationModel = new AnnotationModel();
    if (!(annotationModel instanceof IAnnotationModelExtension))
        return false;
    QuickDiff util = new QuickDiff();
    Object oldDifferId = util.getConfiguredQuickDiffProvider(oldDiffer);
    if (oldDifferId.equals(diffProviderId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // Check whether the desired provider is available at all
    IAnnotationModel newDiffer = util.createQuickDiffAnnotationModel(getEditor(), diffProviderId);
    if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // quick diff is showing with the wrong provider - ask the user whether he wants to switch
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) {
        MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openOkCancelConfirm(fViewer.getTextWidget().getShell(), RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, true, store, REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY);
        if (toggleDialog.getReturnCode() != Window.OK)
            return false;
    }
    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
    modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer);
    if (fDelegate instanceof IChangeRulerColumn)
        // picks up the new model attachment
        ((IChangeRulerColumn) fDelegate).setModel(annotationModel);
    return true;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) IChangeRulerColumn(org.eclipse.jface.text.source.IChangeRulerColumn) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 10 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel in project eclipse.platform.text by eclipse.

the class AnnotationModelStressTest method setUp.

@Before
public void setUp() throws Exception {
    fDocument = new Document(RANDOM_CONTENT);
    fAnnotationModel = new AnnotationModel();
    fInnerModel1 = new AnnotationModel();
    fAnnotationModel.addAnnotationModel("model1", fInnerModel1);
    fInnerModel2 = new AnnotationModel();
    fAnnotationModel.addAnnotationModel("model2", fInnerModel2);
    fAnnotationModel.connect(fDocument);
}
Also used : AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Document(org.eclipse.jface.text.Document) Before(org.junit.Before)

Aggregations

AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)13 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)7 Document (org.eclipse.jface.text.Document)5 IDocument (org.eclipse.jface.text.IDocument)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 SourceViewer (org.eclipse.jface.text.source.SourceViewer)3 HashSet (java.util.HashSet)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IRegion (org.eclipse.jface.text.IRegion)2 TextPresentation (org.eclipse.jface.text.TextPresentation)2 DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)2 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)2 MonoReconciler (org.eclipse.jface.text.reconciler.MonoReconciler)2 Annotation (org.eclipse.jface.text.source.Annotation)2 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)2 ILineDifferExtension (org.eclipse.jface.text.source.ILineDifferExtension)2 GC (org.eclipse.swt.graphics.GC)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2