use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class MarkerResoltionQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
IAnnotationModel annotationModel = invocationContext.getSourceViewer().getAnnotationModel();
Collection<MarkerAnnotation> annotations = new HashSet<>();
annotationModel.getAnnotationIterator().forEachRemaining(annotation -> {
Position position = annotationModel.getPosition(annotation);
if (invocationContext.getOffset() >= position.getOffset() && invocationContext.getOffset() + Math.max(0, invocationContext.getLength()) <= position.getOffset() + position.getLength() && annotation instanceof MarkerAnnotation) {
annotations.add((MarkerAnnotation) annotation);
}
});
Collection<MarkerResolutionCompletionProposal> resolutions = new ArrayList<>();
for (MarkerAnnotation annotation : annotations) {
IMarker marker = annotation.getMarker();
for (IMarkerResolution resolution : IDE.getMarkerHelpRegistry().getResolutions(marker)) {
resolutions.add(new MarkerResolutionCompletionProposal(marker, resolution));
}
}
return resolutions.toArray(new ICompletionProposal[resolutions.size()]);
}
use of org.eclipse.jface.text.source.IAnnotationModel 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;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class LineNumberColumn method uninstallChangeRulerModel.
/**
* Uninstalls the differ annotation model from the current quick diff display.
*
* @param column the column to remove the model from
*/
private void uninstallChangeRulerModel(IVerticalRulerColumn column) {
if (column instanceof IChangeRulerColumn)
((IChangeRulerColumn) column).setModel(null);
IAnnotationModel model = getDiffer();
if (model instanceof ILineDifferExtension)
((ILineDifferExtension) model).suspend();
ISourceViewer viewer = fViewer;
if (viewer != null && viewer.getAnnotationModel() == null)
viewer.showAnnotations(false);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method testGetFileStoreAnnotationModel.
/*
* Tests isSynchronized.
*/
@Test
public void testGetFileStoreAnnotationModel() throws Exception {
IFileStore fileStore = EFS.getNullFileSystem().getStore(new Path("/dev/null"));
assertNotNull(fileStore);
fManager.connectFileStore(fileStore, null);
try {
ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fileStore);
IAnnotationModel model = fileBuffer.getAnnotationModel();
Class<IAnnotationModel> clazz = getAnnotationModelClass();
if (clazz != null)
assertTrue(clazz.isInstance(model));
else
assertNotNull(model);
} finally {
fManager.disconnectFileStore(fileStore, null);
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test18.
/*
* Test annotation model existence.
* ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle.
*/
@Test
public void test18() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertNotNull(buffer);
Class<IAnnotationModel> clazz = getAnnotationModelClass();
if (clazz != null) {
IAnnotationModel model = buffer.getAnnotationModel();
assertTrue(clazz.isInstance(model));
}
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
Aggregations