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();
}
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);
}
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;
}
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();
}
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();
}
Aggregations