use of org.eclipse.ui.ide.IGotoMarker in project eclipse.platform.text by eclipse.
the class SelectMarkerRulerAction method gotoMarker.
private void gotoMarker(IMarker marker) {
// Use the provided adapter if any
IGotoMarker gotoMarkerAdapter = fTextEditor.getAdapter(IGotoMarker.class);
if (gotoMarkerAdapter != null) {
gotoMarkerAdapter.gotoMarker(marker);
return;
}
int start = MarkerUtilities.getCharStart(marker);
int end = MarkerUtilities.getCharEnd(marker);
boolean selectLine = start < 0 || end < 0;
IDocumentProvider documentProvider = fTextEditor.getDocumentProvider();
IEditorInput editorInput = fTextEditor.getEditorInput();
// look up the current range of the marker when the document has been edited
IAnnotationModel model = documentProvider.getAnnotationModel(editorInput);
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 = documentProvider.getDocument(editorInput);
if (selectLine) {
int line;
try {
if (start >= 0)
line = document.getLineOfOffset(start);
else {
line = MarkerUtilities.getLineNumber(marker);
// Marker line numbers are 1-based
--line;
}
end = start + document.getLineLength(line) - 1;
} catch (BadLocationException e) {
return;
}
}
int length = document.getLength();
if (end - 1 < length && start < length)
fTextEditor.selectAndReveal(start, end - start);
}
use of org.eclipse.ui.ide.IGotoMarker in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method revealInEditor.
/**
* Selects and reveals the given offset and length in the given editor part.
*
* @param editor the editor part
* @param offset the offset
* @param length the length
* @since 3.7
*/
private static void revealInEditor(IEditorPart editor, final int offset, final int length) {
if (editor instanceof ITextEditor) {
((ITextEditor) editor).selectAndReveal(offset, length);
return;
}
// Support for non-text editor - try IGotoMarker interface
final IGotoMarker gotoMarkerTarget;
if (editor instanceof IGotoMarker)
gotoMarkerTarget = (IGotoMarker) editor;
else
gotoMarkerTarget = editor != null ? editor.getAdapter(IGotoMarker.class) : null;
if (gotoMarkerTarget != null) {
final IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput) {
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
IMarker marker = null;
try {
marker = ((IFileEditorInput) input).getFile().createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.CHAR_START, offset);
marker.setAttribute(IMarker.CHAR_END, offset + length);
gotoMarkerTarget.gotoMarker(marker);
} finally {
if (marker != null)
marker.delete();
}
}
};
try {
op.run(null);
} catch (InvocationTargetException ex) {
// reveal failed
} catch (InterruptedException e) {
// $NON-NLS-1$
Assert.isTrue(false, "this operation can not be canceled");
}
}
return;
}
}
use of org.eclipse.ui.ide.IGotoMarker in project yamcs-studio by yamcs.
the class OPIEditor method getAdapter.
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
if (type == IPropertySheetPage.class)
return getPropertySheetPage();
else if (type == ZoomManager.class)
return ((ScalableFreeformRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager();
else // return getOverviewOutlinePage();
if (type == IContentOutlinePage.class) {
outlinePage = new OutlinePage(new TreeViewer());
return outlinePage;
} else if (type.equals(IContextProvider.class)) {
if (helpContextProvider == null)
helpContextProvider = new OPIHelpContextProvider(getGraphicalViewer());
return helpContextProvider;
} else if (type.equals(IGotoMarker.class)) {
return new IGotoMarker() {
@Override
public void gotoMarker(IMarker marker) {
try {
String wuid = (String) marker.getAttribute(AbstractWidgetModel.PROP_WIDGET_UID);
if (wuid == null) {
// if wuid is not stored in the marker try to find it based on character
Integer charStart = (Integer) marker.getAttribute(IMarker.CHAR_START);
if (charStart == null) {
return;
}
// Get the closest widget to charStart position
wuid = XMLUtil.findClosestWidgetUid(getInputStream(), charStart);
if (wuid == null) {
return;
}
}
AbstractWidgetModel widget = getDisplayModel().getWidgetFromWUID(wuid);
if (widget == null) {
return;
}
// Get the widget editPart
Object obj = getGraphicalViewer().getEditPartRegistry().get(widget);
if (obj != null && obj instanceof AbstractBaseEditPart) {
EditPart widgetEditPart = (AbstractBaseEditPart) obj;
// Reveal the widget
getGraphicalViewer().reveal(widgetEditPart);
// Find the closest selectable part
while (widgetEditPart != null && !widgetEditPart.isSelectable()) {
widgetEditPart = widgetEditPart.getParent();
}
if (widgetEditPart != null) {
// Select the widget in OPI
SelectionManager selectionManager = getGraphicalViewer().getSelectionManager();
selectionManager.deselectAll();
selectionManager.appendSelection(widgetEditPart);
}
}
} catch (IOException e) {
MessageDialog.openError(getSite().getShell(), "IO Error", e.getMessage());
OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
e);
} catch (CoreException e) {
MessageDialog.openError(getSite().getShell(), "Core Error", e.getMessage());
OPIBuilderPlugin.getLogger().log(Level.WARNING, "File open error", // $NON-NLS-1$
e);
}
}
};
}
return super.getAdapter(type);
}
Aggregations