use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method gotoMarker.
/**
* If the editor can be saved all marker ranges have been changed according to
* the text manipulations. However, those changes are not yet propagated to the
* marker manager. Thus, when opening a marker, the marker's position in the editor
* must be determined as it might differ from the position stated in the marker.
*
* @param marker the marker to go to
* @deprecated visibility will be reduced, use <code>getAdapter(IGotoMarker.class) for accessing this method</code>
*/
@Deprecated
public void gotoMarker(IMarker marker) {
if (fIsUpdatingMarkerViews)
return;
if (getSourceViewer() == null)
return;
int start = MarkerUtilities.getCharStart(marker);
int end = MarkerUtilities.getCharEnd(marker);
boolean selectLine = start < 0 || end < 0;
// look up the current range of the marker when the document has been edited
IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
if (model instanceof AbstractMarkerAnnotationModel) {
AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
Position pos = markerModel.getMarkerPosition(marker);
if (pos != null && !pos.isDeleted()) {
// use position instead of marker values
start = pos.getOffset();
end = pos.getOffset() + pos.getLength();
}
if (pos != null && pos.isDeleted()) {
// do nothing if position has been deleted
return;
}
}
IDocument document = getDocumentProvider().getDocument(getEditorInput());
if (selectLine) {
int line;
try {
if (start >= 0)
line = document.getLineOfOffset(start);
else {
line = MarkerUtilities.getLineNumber(marker);
// Marker line numbers are 1-based
--line;
start = document.getLineOffset(line);
}
end = start + document.getLineLength(line) - 1;
} catch (BadLocationException e) {
return;
}
}
int length = document.getLength();
if (end <= length && start <= length) {
fIsComingFromGotoMarker = true;
selectAndReveal(start, end - start);
}
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class AbstractMarkerAnnotationModel method modifyMarkerAnnotation.
/**
* Updates the annotation corresponding to the given marker which has changed
* in some way.
* <p>
* Subclasses may override.</p>
*
* @param marker the marker
*/
protected void modifyMarkerAnnotation(IMarker marker) {
MarkerAnnotation a = getMarkerAnnotation(marker);
if (a != null) {
Position p = createPositionFromMarker(marker);
if (p != null) {
a.update();
modifyAnnotationPosition(a, p, false);
}
} else
addMarkerAnnotation(marker);
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class AbstractMarkerAnnotationModel method updateMarkers.
/**
* Updates the markers managed by this annotation model by calling
* all registered marker updaters (<code>IMarkerUpdater</code>).
*
* @param document the document to which this model is currently connected
* @throws CoreException if there is a problem updating the markers
*/
public void updateMarkers(IDocument document) throws CoreException {
Assert.isTrue(fDocument == document);
IAnnotationMap annotationMap = getAnnotationMap();
if (annotationMap.size() == 0 && fDeletedAnnotations.size() == 0)
return;
if (fMarkerUpdaterSpecifications == null)
installMarkerUpdaters();
listenToMarkerChanges(false);
try {
// update all markers with the positions known by the annotation model
for (Iterator<Annotation> e = getAnnotationIterator(false); e.hasNext(); ) {
Object o = e.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation a = (MarkerAnnotation) o;
IMarker marker = a.getMarker();
Position position = annotationMap.get(a);
if (!updateMarker(marker, document, position)) {
if (!fDeletedAnnotations.contains(a))
fDeletedAnnotations.add(a);
}
}
}
if (!fDeletedAnnotations.isEmpty()) {
removeAnnotations(fDeletedAnnotations, true, true);
fDeletedAnnotations.clear();
}
} finally {
listenToMarkerChanges(true);
}
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class AbstractMarkerAnnotationModel method resetMarkers.
/**
* Resets all the markers to their original state.
*/
public void resetMarkers() {
// re-initializes the positions from the markers
for (Iterator<Annotation> e = getAnnotationIterator(false); e.hasNext(); ) {
Object o = e.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation a = (MarkerAnnotation) o;
Position p = createPositionFromMarker(a.getMarker());
if (p != null) {
removeAnnotation(a, false);
try {
addAnnotation(a, p, false);
} catch (BadLocationException e1) {
// ignore invalid position
}
}
}
}
// add the markers of deleted positions back to the annotation model
for (Iterator<Annotation> e = fDeletedAnnotations.iterator(); e.hasNext(); ) {
Object o = e.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation a = (MarkerAnnotation) o;
Position p = createPositionFromMarker(a.getMarker());
if (p != null)
try {
addAnnotation(a, p, false);
} catch (BadLocationException e1) {
// ignore invalid position
}
}
}
fDeletedAnnotations.clear();
// fire annotation model changed
fireModelChanged();
}
use of org.eclipse.jface.text.Position in project eclipse.platform.text by eclipse.
the class ResourceMarkerAnnotationModel method batchedUpdate.
/**
* Updates this model to the given marker deltas.
*
* @param markerDeltas the array of marker deltas
*/
private void batchedUpdate(IMarkerDelta[] markerDeltas) {
HashSet<IMarker> removedMarkers = new HashSet<>(markerDeltas.length);
HashSet<IMarker> modifiedMarkers = new HashSet<>(markerDeltas.length);
for (int i = 0; i < markerDeltas.length; i++) {
IMarkerDelta delta = markerDeltas[i];
switch(delta.getKind()) {
case IResourceDelta.ADDED:
addMarkerAnnotation(delta.getMarker());
break;
case IResourceDelta.REMOVED:
removedMarkers.add(delta.getMarker());
break;
case IResourceDelta.CHANGED:
modifiedMarkers.add(delta.getMarker());
break;
}
}
if (modifiedMarkers.isEmpty() && removedMarkers.isEmpty())
return;
Iterator<Annotation> e = getAnnotationIterator(false);
while (e.hasNext()) {
Object o = e.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation a = (MarkerAnnotation) o;
IMarker marker = a.getMarker();
if (removedMarkers.remove(marker))
removeAnnotation(a, false);
if (modifiedMarkers.remove(marker)) {
Position p = createPositionFromMarker(marker);
if (p != null) {
a.update();
modifyAnnotationPosition(a, p, false);
}
}
if (modifiedMarkers.isEmpty() && removedMarkers.isEmpty())
return;
}
}
Iterator<IMarker> iter = modifiedMarkers.iterator();
while (iter.hasNext()) addMarkerAnnotation(iter.next());
}
Aggregations