Java Code Examples for org.eclipse.ui.texteditor.IDocumentProvider#getAnnotationModel()
The following examples show how to use
org.eclipse.ui.texteditor.IDocumentProvider#getAnnotationModel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestEditor.java From ermasterr with Apache License 2.0 | 6 votes |
private void initializeSourceViewer(final IEditorInput input) { final IDocumentProvider documentProvider = getDocumentProvider(); final IAnnotationModel model = documentProvider.getAnnotationModel(input); final IDocument document = documentProvider.getDocument(input); if (document != null) { fSourceViewer.setDocument(document, model); fSourceViewer.setEditable(isEditable()); fSourceViewer.showAnnotations(model != null); } if (fElementStateListener instanceof IElementStateListenerExtension) { boolean isStateValidated = false; if (documentProvider instanceof IDocumentProviderExtension) isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input); final IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener; extension.elementStateValidationChanged(input, isStateValidated); } }
Example 2
Source File: TypeScriptEditor.java From typescript.java with MIT License | 6 votes |
private void removeOccurrenceAnnotations() { // fMarkOccurrenceModificationStamp= // IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; // fMarkOccurrenceTargetRegion= null; IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) return; IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null || fOccurrenceAnnotations == null) return; synchronized (getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension) annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); } else { for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++) annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); } fOccurrenceAnnotations = null; } }
Example 3
Source File: JavaCompilationParticipantTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private List<GWTJavaProblem> getGWTProblemsInEditor(CompilationUnitEditor editor) throws Exception { List<GWTJavaProblem> problems = new ArrayList<GWTJavaProblem>(); Field annotationProblemField = CompilationUnitDocumentProvider.ProblemAnnotation.class.getDeclaredField("fProblem"); annotationProblemField.setAccessible(true); IEditorInput editorInput = editor.getEditorInput(); IDocumentProvider documentProvider = editor.getDocumentProvider(); IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editorInput); Iterator<?> iter = annotationModel.getAnnotationIterator(); while (iter.hasNext()) { Object annotation = iter.next(); if (annotation instanceof CompilationUnitDocumentProvider.ProblemAnnotation) { CompilationUnitDocumentProvider.ProblemAnnotation problemAnnotation = (ProblemAnnotation) annotation; if (problemAnnotation.getMarkerType().equals(GWTJavaProblem.MARKER_ID)) { GWTJavaProblem problem = (GWTJavaProblem) annotationProblemField.get(problemAnnotation); problems.add(problem); } } } return problems; }
Example 4
Source File: TestEditor.java From ermaster-b with Apache License 2.0 | 6 votes |
private void initializeSourceViewer(IEditorInput input) { IDocumentProvider documentProvider = getDocumentProvider(); IAnnotationModel model = documentProvider.getAnnotationModel(input); IDocument document = documentProvider.getDocument(input); if (document != null) { fSourceViewer.setDocument(document, model); fSourceViewer.setEditable(isEditable()); fSourceViewer.showAnnotations(model != null); } if (fElementStateListener instanceof IElementStateListenerExtension) { boolean isStateValidated = false; if (documentProvider instanceof IDocumentProviderExtension) isStateValidated = ((IDocumentProviderExtension) documentProvider) .isStateValidated(input); IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener; extension.elementStateValidationChanged(input, isStateValidated); } }
Example 5
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void removeOccurrenceAnnotations() { fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; fMarkOccurrenceTargetRegion= null; IDocumentProvider documentProvider= getDocumentProvider(); if (documentProvider == null) return; IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null || fOccurrenceAnnotations == null) return; synchronized (getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); } else { for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); } fOccurrenceAnnotations= null; } }
Example 6
Source File: CommonOccurrencesUpdater.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * getAnnotationModel * * @return */ protected IAnnotationModel getAnnotationModel() { IDocumentProvider documentProvider = getDocumentProvider(); IEditorInput editorInput = getEditorInput(); IAnnotationModel result = null; if (documentProvider != null && editorInput != null) { result = documentProvider.getAnnotationModel(editorInput); } return result; }
Example 7
Source File: AnnotationModelHelper.java From saros with GNU General Public License v2.0 | 5 votes |
public IAnnotationModel retrieveAnnotationModel(IEditorPart editorPart) { IEditorInput input = editorPart.getEditorInput(); IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(input); IAnnotationModel model = provider.getAnnotationModel(input); return model; }
Example 8
Source File: AbstractBreakpointRulerAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private IAnnotationModel getAnnotationModel() { if (fTextEditor == null) { return null; } final IDocumentProvider documentProvider = fTextEditor.getDocumentProvider(); if (documentProvider == null) { return null; } return documentProvider.getAnnotationModel(fTextEditor.getEditorInput()); }
Example 9
Source File: PyEditBreakpointSync.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private void updateAnnotations() { if (edit == null) { return; } IDocumentProvider provider = edit.getDocumentProvider(); if (provider == null) { return; } IAnnotationModel model = provider.getAnnotationModel(edit.getEditorInput()); if (model == null) { return; } IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) model; List<Annotation> existing = new ArrayList<Annotation>(); Iterator<Annotation> it = model.getAnnotationIterator(); if (it == null) { return; } while (it.hasNext()) { existing.add(it.next()); } IDocument doc = edit.getDocument(); IResource resource = PyMarkerUIUtils.getResourceForTextEditor(edit); IEditorInput externalFileEditorInput = AbstractBreakpointRulerAction.getExternalFileEditorInput(edit); List<IMarker> markers = AbstractBreakpointRulerAction.getMarkersFromEditorResource(resource, doc, externalFileEditorInput, 0, false, model); Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>(); for (IMarker m : markers) { Position pos = PyMarkerUIUtils.getMarkerPosition(doc, m, model); MarkerAnnotation newAnnotation = new MarkerAnnotation(m); annotationsToAdd.put(newAnnotation, pos); } //update all in a single step modelExtension.replaceAnnotations(existing.toArray(new Annotation[0]), annotationsToAdd); }
Example 10
Source File: BaseEditor.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public IAnnotationModel getAnnotationModel() { final IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) { return null; } return documentProvider.getAnnotationModel(getEditorInput()); }
Example 11
Source File: JavaCompositeReconcilingStrategy.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the problem requestor for the editor's input element. * * @return the problem requestor for the editor's input element */ private IProblemRequestorExtension getProblemRequestorExtension() { IDocumentProvider p= fEditor.getDocumentProvider(); if (p == null) { // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522 p= JavaPlugin.getDefault().getCompilationUnitDocumentProvider(); } IAnnotationModel m= p.getAnnotationModel(fEditor.getEditorInput()); if (m instanceof IProblemRequestorExtension) return (IProblemRequestorExtension) m; return null; }
Example 12
Source File: JavaSpellingReconcileStrategy.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected IAnnotationModel getAnnotationModel() { final IDocumentProvider documentProvider= fEditor.getDocumentProvider(); if (documentProvider == null) return null; return documentProvider.getAnnotationModel(fEditor.getEditorInput()); }
Example 13
Source File: OccurrenceMarker.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected IAnnotationModel getAnnotationModel(XtextEditor editor) { if(editor != null) { IEditorInput editorInput = editor.getEditorInput(); if(editorInput != null) { IDocumentProvider documentProvider = editor.getDocumentProvider(); if(documentProvider != null) { return documentProvider.getAnnotationModel(editorInput); } } } return null; }
Example 14
Source File: TypeScriptEditor.java From typescript.java with MIT License | 5 votes |
private IAnnotationModel getAnnotationModel() { IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) { return null; } return documentProvider.getAnnotationModel(getEditorInput()); }
Example 15
Source File: XBookmarksUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Fetches the marker annotation model for the currently edited document. * Note, that I would prefer to declare this as returning e.g. * IAnnotationModel, but the method to call somewhere else is * <code>updateMarkers(IDocument document)</code> which is not specified by * IAnnotationModel (the only interface implemented by * AbstractMarkerAnnotationModel). * * @return the marker annotation model or <code>null</code> */ public static AbstractMarkerAnnotationModel getMarkerAnnotationModel() { IDocumentProvider provider = WorkbenchUtils.getActiveDocumentProvider(); IDocument document = WorkbenchUtils.getActiveDocument(); if ((provider != null) && (document != null)) { IAnnotationModel model = provider.getAnnotationModel(document); if (model instanceof AbstractMarkerAnnotationModel) { return (AbstractMarkerAnnotationModel) model; } } return null; }
Example 16
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public IStatus run(IProgressMonitor progressMonitor) { if (isCanceled(progressMonitor)) return Status.CANCEL_STATUS; ITextViewer textViewer= getViewer(); if (textViewer == null) return Status.CANCEL_STATUS; IDocument document= textViewer.getDocument(); if (document == null) return Status.CANCEL_STATUS; IDocumentProvider documentProvider= getDocumentProvider(); if (documentProvider == null) return Status.CANCEL_STATUS; IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null) return Status.CANCEL_STATUS; // Add occurrence annotations int length= fLocations.length; Map<Annotation, Position> annotationMap= new HashMap<Annotation, Position>(length); for (int i= 0; i < length; i++) { if (isCanceled(progressMonitor)) return Status.CANCEL_STATUS; OccurrenceLocation location= fLocations[i]; Position position= new Position(location.getOffset(), location.getLength()); String description= location.getDescription(); String annotationType= (location.getFlags() == IOccurrencesFinder.F_WRITE_OCCURRENCE) ? "org.eclipse.jdt.ui.occurrences.write" : "org.eclipse.jdt.ui.occurrences"; //$NON-NLS-1$ //$NON-NLS-2$ annotationMap.put(new Annotation(annotationType, false, description), position); } if (isCanceled(progressMonitor)) return Status.CANCEL_STATUS; synchronized (getLockObject(annotationModel)) { if (annotationModel instanceof IAnnotationModelExtension) { ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); } else { removeOccurrenceAnnotations(); Iterator<Entry<Annotation, Position>> iter= annotationMap.entrySet().iterator(); while (iter.hasNext()) { Entry<Annotation, Position> mapEntry= iter.next(); annotationModel.addAnnotation(mapEntry.getKey(), mapEntry.getValue()); } } fOccurrenceAnnotations= annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); } return Status.OK_STATUS; }
Example 17
Source File: HTMLEditor.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Given the offset, tries to determine if we're on an HTML close/start tag, and if so it will find the matching * open/close and highlight the pair. * * @param offset */ private void highlightTagPair(int offset) { IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) { return; } IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null) { return; } if (fTagPairOccurrences != null) { // if the offset is included by one of these two positions, we don't need to wipe and re-calculate! for (Position pos : fTagPairOccurrences.values()) { if (pos.includes(offset)) { return; } } // New position, wipe the existing annotations in preparation for re-calculating... for (Annotation a : fTagPairOccurrences.keySet()) { annotationModel.removeAnnotation(a); } fTagPairOccurrences = null; } // Calculate current pair Map<Annotation, Position> occurrences = new HashMap<Annotation, Position>(); IDocument document = getSourceViewer().getDocument(); IRegion match = TagUtil.findMatchingTag(document, offset, tagPartitions); if (match != null) { // TODO Compare versus last positions, if they're the same don't wipe out the old ones and add new ones! occurrences.put(new Annotation(IHTMLConstants.TAG_PAIR_OCCURRENCE_ID, false, null), new Position(match.getOffset(), match.getLength())); try { // The current tag we're in! ITypedRegion partition = document.getPartition(offset); occurrences.put(new Annotation(IHTMLConstants.TAG_PAIR_OCCURRENCE_ID, false, null), new Position( partition.getOffset(), partition.getLength())); } catch (BadLocationException e) { IdeLog.logError(HTMLPlugin.getDefault(), e); } for (Map.Entry<Annotation, Position> entry : occurrences.entrySet()) { annotationModel.addAnnotation(entry.getKey(), entry.getValue()); } fTagPairOccurrences = occurrences; } else { // no new pair, so don't highlight anything fTagPairOccurrences = null; } }
Example 18
Source File: XMLEditor.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Given the offset, tries to determine if we're on an HTML close/start tag, and if so it will find the matching * open/close and highlight the pair. * * @param offset */ private void highlightTagPair(int offset) { IDocumentProvider documentProvider = getDocumentProvider(); if (documentProvider == null) { return; } IAnnotationModel annotationModel = documentProvider.getAnnotationModel(getEditorInput()); if (annotationModel == null) { return; } if (fTagPairOccurrences != null) { // if the offset is included by one of these two positions, we don't need to wipe and re-calculate! for (Position pos : fTagPairOccurrences.values()) { if (pos.includes(offset)) { return; } } // New position, wipe the existing annotations in preparation for re-calculating... for (Annotation a : fTagPairOccurrences.keySet()) { annotationModel.removeAnnotation(a); } fTagPairOccurrences = null; } // Calculate current pair Map<Annotation, Position> occurrences = new HashMap<Annotation, Position>(); IDocument document = getSourceViewer().getDocument(); IParseNode node = getASTNodeAt(offset, getAST()); if (node instanceof XMLElementNode) { XMLElementNode en = (XMLElementNode) node; if (!en.isSelfClosing()) { IRegion match = TagUtil.findMatchingTag(document, offset, tagPartitions); if (match != null) { // TODO Compare versus last positions, if they're the same don't wipe out the old ones and add new // ones! occurrences.put(new Annotation(IXMLEditorConstants.TAG_PAIR_OCCURRENCE_ID, false, null), new Position(match.getOffset(), match.getLength())); try { // The current tag we're in! ITypedRegion partition = document.getPartition(offset); occurrences.put(new Annotation(IXMLEditorConstants.TAG_PAIR_OCCURRENCE_ID, false, null), new Position(partition.getOffset(), partition.getLength())); } catch (BadLocationException e) { IdeLog.logError(XMLPlugin.getDefault(), e); } for (Map.Entry<Annotation, Position> entry : occurrences.entrySet()) { annotationModel.addAnnotation(entry.getKey(), entry.getValue()); } fTagPairOccurrences = occurrences; return; } } } // no new pair, so don't highlight anything fTagPairOccurrences = null; }
Example 19
Source File: LocationAnnotationManager.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Create or update annotations related to text selections made by remote users. * * <p>Such selections consist of a highlight (one character wide, if there is no actual text * selection) and a vertical line that resembles the local text cursor. If the selection includes * multiple lines an additional element will be created to highlight the space between a line's * last character and the right margin. * * @param source The remote user who made the text selection (or to whom the text cursor belongs). * @param selection The selection itself. * @param editorPart {@link IEditorPart} that displays the opened document of which the * annotations should be updated. */ public void setSelection(IEditorPart editorPart, TextSelection selection, User source) { if (!(editorPart instanceof ITextEditor)) return; ITextEditor textEditor = (ITextEditor) editorPart; IDocumentProvider docProvider = textEditor.getDocumentProvider(); if (docProvider == null) return; IEditorInput input = textEditor.getEditorInput(); IAnnotationModel model = docProvider.getAnnotationModel(input); if (model == null) return; if (selection.isEmpty()) { clearSelectionForUser(source, editorPart); return; } ITextSelection offsetSelection = EditorAPI.calculateOffsets(editorPart, selection); int offset = offsetSelection.getOffset(); int length = offsetSelection.getLength(); boolean isCursor = length == 0; // TODO For better performance: Currently, all selection-related // annotations are created and replaced individually. Since the access // to the annotation model tends to be slow and the replacement may take // place in batches, one could first create all new selection-related // annotations and replace them at once. if (isCursor) { if (offset > 0) { /* * Highlight the character left of the cursor in the light color * of the user. */ setSelectionAnnotation(source, isCursor, new Position(offset - 1, 1), model); } else { /* * We have to draw this "highlight" even though it's not visible * at all. This is to prevent ghosting of the highlight when * jumping to the beginning of the file (offset == 0). */ setSelectionAnnotation(source, isCursor, new Position(0, 0), model); } } else { /* * Highlight the selection of a remote user in the remote user's * light color. */ setSelectionAnnotation(source, isCursor, new Position(offset, length), model); } /* * Draw a cursor at the cursor position of other user in the current * session. When there is a selection, the cursor will be shown at the * end of it. */ setRemoteCursorAnnotation(source, new Position(offset + length), model); if (fillUpEnabled) { setFillUpAnnotation(source, new Position(offset, length), model); } }
Example 20
Source File: EditorManager.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Programmatically saves the given editor IF and only if the file is registered as a connected * file. * * <p>Calling this method will trigger a call to all registered SharedEditorListeners (independent * of the success of this method) BEFORE the file is actually saved. * * <p>Calling this method will NOT trigger a {@link EditorActivity} of type Save to be sent to the * other clients. * * @param wrappedFile the file that is supposed to be saved to disk. * @swt This method must be called from the SWT thread * @nonReentrant This method cannot be called twice at the same time. */ public void saveEditor(saros.filesystem.IFile wrappedFile) { checkThreadAccess(); IFile file = ((EclipseFileImpl) wrappedFile).getDelegate(); log.trace(".saveEditor (" + file.getName() + ") invoked"); if (!file.exists()) { log.warn("File not found for saving: " + wrappedFile.toString(), new StackTrace()); return; } FileEditorInput input = new FileEditorInput(file); IDocumentProvider provider = EditorAPI.connect(input); if (provider == null) return; if (!provider.canSaveDocument(input)) { /* * This happens when a file which is already saved is saved again by * a user. */ log.debug(".saveEditor File " + file.getName() + " does not need to be saved"); provider.disconnect(input); return; } log.trace(".saveEditor File " + file.getName() + " will be saved"); final boolean isConnected = isManaged(file); /* * connect to the file so the SharedResourceManager / * ProjectDeltaVisitor will ignore the file change because it is * possible that no editor is open for this file */ if (!isConnected) connect(file); IDocument doc = provider.getDocument(input); // TODO Why do we need to connect to the annotation model here? IAnnotationModel model = provider.getAnnotationModel(input); if (model != null) model.connect(doc); log.trace(".saveEditor Annotations on the IDocument are set"); editorPool.setElementStateListenerEnabled(false); try { provider.saveDocument(new NullProgressMonitor(), input, doc, true); log.debug("Saved document: " + wrappedFile); } catch (CoreException e) { log.error("Failed to save document: " + wrappedFile, e); } editorPool.setElementStateListenerEnabled(true); if (model != null) model.disconnect(doc); provider.disconnect(input); if (!isConnected) disconnect(file); }