use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ActiveEditorActionHandler method updateTargetAction.
private void updateTargetAction() {
if (fSite != null && fSite.getWorkbenchWindow() != null && fSite.getWorkbenchWindow().getActivePage() != null) {
IEditorPart part = fSite.getWorkbenchWindow().getActivePage().getActiveEditor();
ITextEditor editor = null;
if (part instanceof ITextEditor)
editor = (ITextEditor) part;
else
editor = part != null ? part.getAdapter(ITextEditor.class) : null;
if (editor != null) {
fTargetAction = editor.getAction(fActionId);
} else {
fTargetAction = null;
}
} else
fTargetAction = null;
}
use of org.eclipse.ui.texteditor.ITextEditor 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.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class QuickOutlinePopupDialog method gotoSelectedElement.
private void gotoSelectedElement() {
Object element = getSelectedElement();
dispose();
if (element != null) {
ITextEditor editor = getActiveTextEditor();
if (editor != null) {
editor.selectAndReveal(((IndexedRegion) element).getStartOffset(), ((IndexedRegion) element).getEndOffset() - ((IndexedRegion) element).getStartOffset());
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class PlatformStatusLineUtil method _displayTemporaryMessage.
static boolean _displayTemporaryMessage(ITextViewer viewer, String msg, boolean isError) {
boolean messageShown = false;
IEditorPart editor = getActiveEditor();
if (editor != null) {
ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
if (textEditor != null && textEditor instanceof StructuredTextEditor) {
if (((StructuredTextEditor) textEditor).getTextViewer() == viewer) {
IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
if (isError)
statusLineManager.setErrorMessage(msg);
else
statusLineManager.setMessage(msg);
new OneTimeListener(viewer.getTextWidget(), new ClearStatusLine(statusLineManager, isError));
messageShown = true;
}
}
}
if (!messageShown) {
displayErrorMessage(msg);
addOneTimeClearListener();
}
return messageShown;
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class FindOccurrencesActionDelegate method run.
public void run(IAction action) {
boolean okay = false;
if (fEditor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) fEditor;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null) {
ITextSelection textSelection = getTextSelection(textEditor);
FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
if (findOccurrenceProcessor != null) {
if (textEditor.getEditorInput() instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
}
}
}
}
if (okay) {
// clear status message
PlatformStatusLineUtil.clearStatusLine();
} else {
// $NON-NLS-1$
String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
if (fEditor instanceof StructuredTextEditor) {
PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) fEditor).getTextViewer(), errorMessage);
} else {
PlatformStatusLineUtil.displayErrorMessage(errorMessage);
PlatformStatusLineUtil.addOneTimeClearListener();
}
}
}
Aggregations