use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class ShowTranslationHandler method execute.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
public Object execute(final ExecutionEvent event) throws ExecutionException {
// IDE.openEditor(event.getApplicationContext(), createEditorInput(),
// JavaUI.ID_CU_EDITOR, true);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List list = ((IStructuredSelection) selection).toList();
if (!list.isEmpty()) {
if (list.get(0) instanceof IDOMNode) {
final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
INodeAdapter adapter = model.getDocument().getAdapterFor(IJsTranslation.class);
if (adapter != null) {
Job opener = new UIJob("Opening JavaScript Translation") {
public IStatus runInUIThread(IProgressMonitor monitor) {
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) model.getDocument().getAdapterFor(IJsTranslation.class);
final IJsTranslation translation = translationAdapter.getJsTranslation(false);
// create an IEditorInput for the Java editor
final IStorageEditorInput input = new JSTranslationEditorInput(translation, model.getBaseLocation());
try {
IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaScriptUI.ID_CU_EDITOR, true);
// Now add the problems we found
if (editor instanceof ITextEditor) {
IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
translation.reconcileCompilationUnit();
List problemsList = translation.getProblems();
IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
AnnotationTypeLookup lookup = new AnnotationTypeLookup();
for (int i = 0; i < problems.length; i++) {
int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
Position position = new Position(problems[i].getSourceStart(), length);
Annotation annotation = null;
String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
if (problems[i].isError()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
} else if (problems[i].isWarning()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
}
annotation = new Annotation(type, false, problems[i].getMessage());
if (annotation != null) {
annotationModel.addAnnotation(annotation, position);
}
}
}
} catch (PartInitException e) {
e.printStackTrace();
Display.getCurrent().beep();
}
return Status.OK_STATUS;
}
};
opener.setSystem(false);
opener.setUser(true);
opener.schedule();
}
}
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class AnnotationHoverProcessor method getHoverInfo.
public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
IAnnotationModel model = ((SourceViewer) viewer).getAnnotationModel();
if (model != null) {
List messages = new ArrayList();
Iterator e = model.getAnnotationIterator();
while (e.hasNext()) {
Annotation a = (Annotation) e.next();
if (!isAnnotationValid(a))
continue;
Position p = model.getPosition(a);
// concerned with
if (p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
String msg = a.getText();
if ((msg != null) && msg.trim().length() > 0) {
// dups
if (a instanceof ITemporaryAnnotation) {
boolean duplicated = false;
int j = 0;
while (j < messages.size() && !duplicated) {
duplicated = messages.get(j).equals(msg);
++j;
}
if (!duplicated) {
messages.add(msg);
}
} else {
messages.add(msg);
}
}
}
}
if (messages.size() > 1) {
return formatMessages(messages);
} else if (messages.size() > 0) {
return formatMessage(messages.get(0).toString());
}
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class AnnotationHoverProcessor method getHoverRegion.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer,
* int)
*/
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IAnnotationModel model = ((SourceViewer) textViewer).getAnnotationModel();
Region hoverRegion = null;
if (model != null) {
Iterator e = model.getAnnotationIterator();
while (e.hasNext()) {
Annotation a = (Annotation) e.next();
if (!isAnnotationValid(a))
continue;
Position p = model.getPosition(a);
if (p != null && p.includes(offset)) {
// find the smallest region containing offset
if ((hoverRegion == null) || (hoverRegion.getLength() > p.getLength())) {
hoverRegion = new Region(p.getOffset(), p.getLength());
}
}
}
}
return hoverRegion;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class SpellcheckStrategy method getSpellingAnnotationsToRemove.
private TemporaryAnnotation[] getSpellingAnnotationsToRemove(IRegion region) {
List toRemove = new ArrayList();
IAnnotationModel annotationModel = getAnnotationModel();
// can be null when closing the editor
if (annotationModel != null) {
Iterator i = null;
boolean annotationOverlaps = false;
if (annotationModel instanceof IAnnotationModelExtension2) {
i = ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(region.getOffset(), region.getLength(), true, true);
annotationOverlaps = true;
} else {
i = annotationModel.getAnnotationIterator();
}
while (i.hasNext()) {
Object obj = i.next();
if (!(obj instanceof TemporaryAnnotation))
continue;
TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
// partition type
if (key != null && key.equals(fReconcileAnnotationKey)) {
if (key.getScope() == ReconcileAnnotationKey.PARTIAL && (annotationOverlaps || annotation.getPosition().overlapsWith(region.getOffset(), region.getLength()))) {
toRemove.add(annotation);
} else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
toRemove.add(annotation);
}
}
}
}
return (TemporaryAnnotation[]) toRemove.toArray(new TemporaryAnnotation[toRemove.size()]);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredTextReconcilingStrategy method getAllAnnotationsToRemove.
/**
* Remove ALL temporary annotations that this strategy can handle.
*/
protected TemporaryAnnotation[] getAllAnnotationsToRemove() {
List removals = new ArrayList();
IAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel != null) {
Iterator i = annotationModel.getAnnotationIterator();
while (i.hasNext()) {
Object obj = i.next();
if (!(obj instanceof ITemporaryAnnotation))
continue;
ITemporaryAnnotation annotation = (ITemporaryAnnotation) obj;
ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
// partition type
if (canHandlePartition(key.getPartitionType()))
/*
* &&
* containsStep(key.getStep())
*/
removals.add(annotation);
}
}
return (TemporaryAnnotation[]) removals.toArray(new TemporaryAnnotation[removals.size()]);
}
Aggregations