use of org.eclipse.jface.text.source.IAnnotationModel in project egit by eclipse.
the class SpellcheckableMessageArea method addProposals.
private void addProposals(final SubMenuManager quickFixMenu) {
IAnnotationModel sourceModel = sourceViewer.getAnnotationModel();
if (sourceModel == null) {
return;
}
Iterator annotationIterator = sourceModel.getAnnotationIterator();
while (annotationIterator.hasNext()) {
Annotation annotation = (Annotation) annotationIterator.next();
boolean isDeleted = annotation.isMarkedDeleted();
boolean isIncluded = !isDeleted && includes(sourceModel.getPosition(annotation), getTextWidget().getCaretOffset());
boolean isFixable = isIncluded && sourceViewer.getQuickAssistAssistant().canFix(annotation);
if (isFixable) {
IQuickAssistProcessor processor = sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor();
IQuickAssistInvocationContext context = sourceViewer.getQuickAssistInvocationContext();
ICompletionProposal[] proposals = processor.computeQuickAssistProposals(context);
for (ICompletionProposal proposal : proposals) {
quickFixMenu.add(createQuickFixAction(proposal));
}
}
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project egit by eclipse.
the class DiffEditorPage method setOverviewAnnotations.
private void setOverviewAnnotations() {
IDocumentProvider documentProvider = getDocumentProvider();
IDocument document = documentProvider.getDocument(getEditorInput());
if (!(document instanceof DiffDocument)) {
return;
}
IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput());
if (annotationModel == null) {
return;
}
DiffRegion[] diffs = ((DiffDocument) document).getRegions();
if (diffs == null || diffs.length == 0) {
return;
}
Map<Annotation, Position> newAnnotations = new HashMap<>();
for (DiffRegion region : diffs) {
if (DiffRegion.Type.ADD.equals(region.getType())) {
newAnnotations.put(new Annotation(ADD_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
} else if (DiffRegion.Type.REMOVE.equals(region.getType())) {
newAnnotations.put(new Annotation(REMOVE_ANNOTATION_TYPE, true, null), new Position(region.getOffset(), region.getLength()));
}
}
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(currentOverviewAnnotations, newAnnotations);
} else {
if (currentOverviewAnnotations != null) {
for (Annotation existing : currentOverviewAnnotations) {
annotationModel.removeAnnotation(existing);
}
}
for (Map.Entry<Annotation, Position> entry : newAnnotations.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
currentOverviewAnnotations = newAnnotations.keySet().toArray(new Annotation[newAnnotations.size()]);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project ecf by eclipse.
the class SyncResourcesUI method startSharing.
private void startSharing(ITextEditor editor, IFile file) {
String projectName = file.getProject().getName();
for (Iterator it = SyncResourcesCore.getResourceShares().iterator(); it.hasNext(); ) {
ResourcesShare share = (ResourcesShare) it.next();
if (share.isSharing(projectName) && share(file)) {
DocShare docShare = getDocShare(share.getContainerID());
try {
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
docShare.startSharing(share.getLocalID(), share.getReceiverID(), file.getFullPath().toString(), annotationModel);
ISelectionProvider provider = editor.getSelectionProvider();
if (provider instanceof IPostSelectionProvider) {
ISelectionChangedListener listener = new SelectionChangedListener(share.getReceiverID(), file.getFullPath().toString(), docShare);
((IPostSelectionProvider) provider).addPostSelectionChangedListener(listener);
sharedEditors.put(editor, listener);
}
} catch (ECFException e) {
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, // $NON-NLS-1$
"Could not send initiation request to " + share.getReceiverID(), e);
log(status);
StatusManager.getManager().handle(status, StatusManager.SHOW);
} catch (CoreException e) {
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, // $NON-NLS-1$
"Could not connect to the file buffer of " + file.getFullPath(), e);
log(status);
StatusManager.getManager().handle(status, StatusManager.SHOW);
}
}
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class OccurencesMarker method removeOccurences.
/**
* Removes the occurrence annotations of this OccurrenceMarker.
*
* @param force
* The annotations will be removed even if the keepMarks
* flag is set.
*/
public void removeOccurences(final boolean force) {
if (!force && keepMarks.getValue()) {
return;
}
markerJob.cancel();
final IAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel == null) {
return;
}
synchronized (getLockObject(annotationModel)) {
if (occurrenceAnnotations == null) {
return;
}
for (Annotation annotaion : occurrenceAnnotations) {
annotationModel.removeAnnotation(annotaion);
}
occurrenceAnnotations = null;
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class TextHover method getHoverInfo.
@Override
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
if (hoverRegion == null) {
return null;
}
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
if (annotationModel != null) {
Iterator<?> iterator = annotationModel.getAnnotationIterator();
while (iterator.hasNext()) {
Object o = iterator.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation actualMarker = (MarkerAnnotation) o;
Position markerPosition = annotationModel.getPosition(actualMarker);
if (markerPosition.getOffset() <= hoverRegion.getOffset() && markerPosition.getOffset() + markerPosition.getLength() >= hoverRegion.getOffset()) {
String message = actualMarker.getText();
if (message != null) {
// Marker error text hover (or tooltip in other words) handles error message
// in HTML format, and there can be situation, when the message contains
// < and > characters, which are handled as HTML control tags, so they
// are not visible. So these < and > characters are removed.
// Example: ANTLR sends the following error message during parsing:
// "mismatched input 'control' expecting <EOF>"
message = message.replaceAll("\\<([A-Z]+)\\>", "$1");
} else {
ErrorReporter.INTERNAL_ERROR("The marker at " + markerPosition.getOffset() + " does not seem to have any text");
}
return message;
}
}
}
}
return null;
}
Aggregations