Search in sources :

Example 76 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class ViewerTestJSP method getActiveEditor.

/**
 * Returns the current active text editor if possible
 *
 * @return ITextEditor
 */
private ITextEditor getActiveEditor() {
    ITextEditor editor = null;
    IEditorPart editorPart = getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
    if (editorPart instanceof ITextEditor)
        editor = (ITextEditor) editorPart;
    if (editor == null && editorPart != null)
        editor = editorPart.getAdapter(ITextEditor.class);
    return editor;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 77 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class XSDMultiPageEditorContributor method setActivePage.

/*
   * (non-JavaDoc) Method declared in
   * AbstractMultiPageEditorActionBarContributor.
   */
public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part)
        return;
    activeEditorPart = part;
    IActionBars actionBars = getActionBars();
    boolean isSource = false;
    if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
        isSource = true;
        zoomInRetargetAction.setEnabled(false);
        zoomOutRetargetAction.setEnabled(false);
        captureScreenAction.setEnabled(false);
        activateSourcePage(activeEditorPart, true);
    } else {
        activateSourcePage(xsdEditor, false);
        if (part instanceof InternalXSDMultiPageEditor) {
            xsdEditor = (InternalXSDMultiPageEditor) part;
        }
        if (xsdEditor != null) {
            // cs: here's we ensure the UNDO and REDO actions are available when
            // the design view is active
            IWorkbenchPartSite site = xsdEditor.getSite();
            if (site instanceof IEditorSite) {
                ITextEditor textEditor = xsdEditor.getTextEditor();
                IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
                siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
                siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
                siteActionBars.updateActionBars();
            }
            Object adapter = xsdEditor.getAdapter(ActionRegistry.class);
            if (adapter instanceof ActionRegistry) {
                ActionRegistry registry = (ActionRegistry) adapter;
                actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), registry.getAction(DeleteAction.ID));
                actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_IN, registry.getAction(GEFActionConstants.ZOOM_IN));
                actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_OUT, registry.getAction(GEFActionConstants.ZOOM_OUT));
                actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), registry.getAction(ActionFactory.PRINT.getId()));
                actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), registry.getAction(ActionFactory.SELECT_ALL.getId()));
                zoomInRetargetAction.setEnabled(true);
                zoomOutRetargetAction.setEnabled(true);
                captureScreenAction.setEnabled(true);
            }
        }
    }
    if (actionBars != null) {
        // update menu bar and tool bar
        actionBars.updateActionBars();
    }
    if (zoomComboContributionItem != null) {
        zoomComboContributionItem.setVisible(!isSource);
        zoomComboContributionItem.update();
        // Bug 254772 - parent contribution manager should not be null.  We added this item already.
        // Force the ToolBarManager to update/redraw the items
        zoomComboContributionItem.getParent().update(true);
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) IActionBars(org.eclipse.ui.IActionBars) IEditorSite(org.eclipse.ui.IEditorSite)

Example 78 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class AbstractCommentActionXMLDelegate method run.

public void run(IAction action) {
    if (fEditor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) fEditor;
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null) {
            // get current text selection
            ITextSelection textSelection = getCurrentSelection();
            if (textSelection.isEmpty()) {
                return;
            }
            processAction(document, textSelection);
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 79 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class CleanupdocumentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        final ITextEditor finalTextEditor = textEditor;
        Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {

                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(finalTextEditor.getDocumentProvider().getDocument(finalTextEditor.getEditorInput()));
                            if (model != null) {
                                cleanupProcessor.cleanupModel(model);
                            }
                        } finally {
                            if (model != null) {
                                model.releaseFromEdit();
                            }
                        }
                    }
                }
            };
            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()));
                if (model != null) {
                    // begin recording
                    ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
                    model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
                    // tell the model that we are about to make a big
                    // model change
                    model.aboutToChangeModel();
                    // run
                    BusyIndicator.showWhile(textEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // tell the model that we are done with the big
                    // model
                    // change
                    model.changedModel();
                    // end recording
                    ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
                    model.endRecording(this, selection.getOffset(), selection.getLength());
                    model.releaseFromEdit();
                }
            }
        }
    }
    return null;
}
Also used : IStructuredCleanupProcessor(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Dialog(org.eclipse.jface.dialogs.Dialog) CleanupDialogXML(org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 80 with ITextEditor

use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.

the class WorkspaceFileHyperlink method open.

public void open() {
    if ((fFile != null) && fFile.exists()) {
        try {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IEditorPart editor = IDE.openEditor(page, fFile, true);
            // highlight range in editor if possible
            if ((fHighlightRange != null) && (editor instanceof ITextEditor)) {
                ((ITextEditor) editor).setHighlightRange(fHighlightRange.getOffset(), fHighlightRange.getLength(), true);
            }
        } catch (PartInitException pie) {
            Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie);
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

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