Search in sources :

Example 1 with AnnotationModel

use of org.eclipse.jface.text.source.AnnotationModel in project tdi-studio-se by Talend.

the class TalendJavaSourceViewer method initializeModel.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.viewer.ReconcilerViewer#initializeModel(IDocument document)
     */
@Override
protected void initializeModel() {
    getSourceViewerDecorationSupport().install(JavaPlugin.getDefault().getCombinedPreferenceStore());
    this.setRangeIndicator(new DefaultRangeIndicator());
    IAnnotationModel model;
    IDocument document;
    if (checkCode) {
        IDocumentProvider provider = JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
        IEditorInput ei = new FileEditorInput(file);
        try {
            provider.connect(ei);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        document = provider.getDocument(ei);
        model = provider.getAnnotationModel(ei);
    } else {
        model = new AnnotationModel();
        document = getDocument();
        model.connect(document);
    }
    if (document != null) {
        setDocument(document, model);
        showAnnotations(model != null && checkCode);
    }
    super.initializeModel();
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with AnnotationModel

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

the class AnnotationModelExtension2Test method setUp.

@Before
public void setUp() {
    fDocument = new Document("How much wood\nwould a woodchuck chuck\nif a woodchuck\ncould chuck wood?\n42");
    fAnnotationModel = new AnnotationModel();
    fNewInnerModel = new AnnotationModel();
    fAnnotationModel.addAnnotationModel("model1", fNewInnerModel);
    fOldInnerModel = new OldAnnotationModel();
    fAnnotationModel.addAnnotationModel("model2", fOldInnerModel);
    fInside = new Annotation(false);
    fInsideIn = new Annotation(false);
    fInsideOut = new Annotation(false);
    fBefore = new Annotation(false);
    fBeforeIn = new Annotation(false);
    fBoforeOut = new Annotation(false);
    fAfter = new Annotation(false);
    fAfterIn = new Annotation(false);
    fAfterOut = new Annotation(false);
    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) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) Before(org.junit.Before)

Example 3 with AnnotationModel

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

the class LineNumberColumn method getAnnotationModelWithDiffer.

/**
 * Returns the annotation model that contains the quick diff annotation model.
 * <p>
 * Extracts the line differ from the displayed document's annotation model. If none can be found,
 * a new differ is created and attached to the annotation model.</p>
 *
 * @return the annotation model that contains the line differ, or <code>null</code> if none could be found or created
 * @see IChangeRulerColumn#QUICK_DIFF_MODEL_ID
 */
private IAnnotationModel getAnnotationModelWithDiffer() {
    ISourceViewer viewer = fViewer;
    if (viewer == null)
        return null;
    IAnnotationModel m = viewer.getAnnotationModel();
    IAnnotationModelExtension model = null;
    if (m instanceof IAnnotationModelExtension)
        model = (IAnnotationModelExtension) m;
    IAnnotationModel differ = getDiffer();
    // create diff model if it doesn't
    if (differ == null) {
        IPreferenceStore store = getPreferenceStore();
        if (store != null) {
            String defaultId = store.getString(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER);
            differ = new QuickDiff().createQuickDiffAnnotationModel(getEditor(), defaultId);
            if (differ != null) {
                if (model == null)
                    model = new AnnotationModel();
                model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
            }
        }
    } else if (differ instanceof ILineDifferExtension2) {
        if (((ILineDifferExtension2) differ).isSuspended())
            ((ILineDifferExtension) differ).resume();
    } else if (differ instanceof ILineDifferExtension) {
        ((ILineDifferExtension) differ).resume();
    }
    return (IAnnotationModel) model;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) ILineDifferExtension2(org.eclipse.jface.text.source.ILineDifferExtension2) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with AnnotationModel

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

the class CodeMiningDemo method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Code Mining demo");
    ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
    sourceViewer.setDocument(new Document("// Type class & new keyword and see references CodeMining\n" + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n" + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"), new AnnotationModel());
    // Add AnnotationPainter (required by CodeMining)
    addAnnotationPainter(sourceViewer);
    // Initialize codemining providers
    ((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] { new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
    // Execute codemining in a reconciler
    MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {

        @Override
        public void setDocument(IDocument document) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }

        @Override
        public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
        }

        @Override
        public void reconcile(IRegion partition) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }
    }, false);
    reconciler.install(sourceViewer);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 5 with AnnotationModel

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

the class InlinedAnnotationDemo method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Inlined annotation demo");
    // Create source viewer and initialize the content
    ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
    sourceViewer.setDocument(new Document("\ncolor:rgb(255, 255, 0)"), new AnnotationModel());
    // Initialize inlined annotations support
    InlinedAnnotationSupport support = new InlinedAnnotationSupport();
    support.install(sourceViewer, createAnnotationPainter(sourceViewer));
    // Refresh inlined annotation in none UI Thread with reconciler.
    MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {

        @Override
        public void setDocument(IDocument document) {
            Set<AbstractInlinedAnnotation> annotations = getInlinedAnnotation(sourceViewer, support);
            support.updateAnnotations(annotations);
        }

        @Override
        public void reconcile(IRegion partition) {
            Set<AbstractInlinedAnnotation> anns = getInlinedAnnotation(sourceViewer, support);
            support.updateAnnotations(anns);
        }

        @Override
        public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
        }
    }, false);
    reconciler.setDelay(1);
    reconciler.install(sourceViewer);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) HashSet(java.util.HashSet) Set(java.util.Set) InlinedAnnotationSupport(org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

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