Search in sources :

Example 66 with ITextEditor

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;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 67 with ITextEditor

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;
}
Also used : IJsTranslation(org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Position(org.eclipse.jface.text.Position) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JsTranslationAdapter(org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter) IEditorPart(org.eclipse.ui.IEditorPart) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IProblem(org.eclipse.wst.jsdt.core.compiler.IProblem) Annotation(org.eclipse.jface.text.source.Annotation) AnnotationTypeLookup(org.eclipse.ui.texteditor.AnnotationTypeLookup) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ISelection(org.eclipse.jface.viewers.ISelection) UIJob(org.eclipse.ui.progress.UIJob) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Example 68 with ITextEditor

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());
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 69 with ITextEditor

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;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 70 with ITextEditor

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();
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)236 IEditorPart (org.eclipse.ui.IEditorPart)92 IDocument (org.eclipse.jface.text.IDocument)76 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)42 IFile (org.eclipse.core.resources.IFile)36 ITextSelection (org.eclipse.jface.text.ITextSelection)34 Test (org.junit.Test)33 BadLocationException (org.eclipse.jface.text.BadLocationException)28 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)25 PartInitException (org.eclipse.ui.PartInitException)23 ISelection (org.eclipse.jface.viewers.ISelection)19 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)17 IRegion (org.eclipse.jface.text.IRegion)16 Annotation (org.eclipse.jface.text.source.Annotation)16 ArrayList (java.util.ArrayList)15 CoreException (org.eclipse.core.runtime.CoreException)15 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)15 IResource (org.eclipse.core.resources.IResource)14 IEditorInput (org.eclipse.ui.IEditorInput)14 TextSelection (org.eclipse.jface.text.TextSelection)12