Search in sources :

Example 1 with SelectionHistory

use of org.eclipse.wst.sse.ui.internal.selection.SelectionHistory in project webtools.sourceediting by eclipse.

the class StructuredSelectHistoryHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    SelectionHistory history = editor.getAdapter(SelectionHistory.class);
    if (history != null) {
        IRegion old = history.getLast();
        if (old != null) {
            try {
                history.ignoreSelectionChanges();
                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)
                    textEditor.selectAndReveal(old.getOffset(), old.getLength());
            } finally {
                history.listenToSelectionChanges();
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion) SelectionHistory(org.eclipse.wst.sse.ui.internal.selection.SelectionHistory)

Example 2 with SelectionHistory

use of org.eclipse.wst.sse.ui.internal.selection.SelectionHistory in project webtools.sourceediting by eclipse.

the class AbstractStructuredSelectHandler 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) {
        ISelection selection = textEditor.getSelectionProvider().getSelection();
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        // determine current text selection
        if (selection instanceof ITextSelection && document != null) {
            ITextSelection textSelection = (ITextSelection) selection;
            if (textSelection.getLength() < document.getLength()) {
                // get current indexed region
                IndexedRegion cursorIndexedRegion = getCursorIndexedRegion(document, textSelection);
                // determine new selection based on current indexed region
                Region newSelectionRegion = getNewSelectionRegion(cursorIndexedRegion, textSelection);
                // select new selection
                if (newSelectionRegion != null) {
                    SelectionHistory history = editor.getAdapter(SelectionHistory.class);
                    if (history != null) {
                        history.remember(new Region(textSelection.getOffset(), textSelection.getLength()));
                        try {
                            history.ignoreSelectionChanges();
                            textEditor.selectAndReveal(newSelectionRegion.getOffset(), newSelectionRegion.getLength());
                        } finally {
                            history.listenToSelectionChanges();
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ISelection(org.eclipse.jface.viewers.ISelection) Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IEditorPart(org.eclipse.ui.IEditorPart) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) SelectionHistory(org.eclipse.wst.sse.ui.internal.selection.SelectionHistory)

Example 3 with SelectionHistory

use of org.eclipse.wst.sse.ui.internal.selection.SelectionHistory in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method getAdapter.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 */
public Object getAdapter(Class required) {
    if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) {
        startPerfTime = System.currentTimeMillis();
    }
    Object result = null;
    // text editor
    IStructuredModel internalModel = getInternalModel();
    if (ITextEditor.class.equals(required) || ITextEditorExtension5.class.equals(required) || ITextEditorExtension4.class.equals(required) || ITextEditorExtension3.class.equals(required) || ITextEditorExtension2.class.equals(required) || ITextEditorExtension.class.equals(required)) {
        result = this;
    } else if (IWorkbenchSiteProgressService.class.equals(required)) {
        return getEditorPart().getSite().getAdapter(IWorkbenchSiteProgressService.class);
    } else // content outline page
    if (IContentOutlinePage.class.equals(required)) {
        if (fOutlinePage == null && !fEditorDisposed) {
            ContentOutlineConfiguration cfg = createContentOutlineConfiguration();
            if (cfg != null) {
                ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
                outlinePage.setConfiguration(cfg);
                if (internalModel != null) {
                    outlinePage.setInputContentTypeIdentifier(internalModel.getContentTypeIdentifier());
                    outlinePage.setInput(internalModel);
                }
                if (fOutlinePageListener == null) {
                    fOutlinePageListener = new OutlinePageListener();
                }
                outlinePage.addSelectionChangedListener(fOutlinePageListener);
                outlinePage.addDoubleClickListener(fOutlinePageListener);
                fOutlinePage = outlinePage;
            }
        }
        result = fOutlinePage;
    } else // property sheet page, but only if the input's editable
    if (IPropertySheetPage.class.equals(required) && isEditable()) {
        if (fPropertySheetPage == null || fPropertySheetPage.getControl() == null || fPropertySheetPage.getControl().isDisposed()) {
            PropertySheetConfiguration cfg = createPropertySheetConfiguration();
            if (cfg != null) {
                ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage();
                propertySheetPage.setConfiguration(cfg);
                fPropertySheetPage = propertySheetPage;
            }
        }
        result = fPropertySheetPage;
    } else if (IDocument.class.equals(required)) {
        result = getDocumentProvider().getDocument(getEditorInput());
    } else if (ISourceEditingTextTools.class.equals(required)) {
        result = createSourceEditingTextTools();
    } else if (IToggleBreakpointsTarget.class.equals(required)) {
        result = ToggleBreakpointsTarget.getInstance();
    } else if (ITextEditorExtension4.class.equals(required)) {
        result = this;
    } else if (IShowInTargetList.class.equals(required)) {
        result = new ShowInTargetListAdapter();
    } else if (IVerticalRuler.class.equals(required)) {
        return getVerticalRuler();
    } else if (SelectionHistory.class.equals(required)) {
        if (fSelectionHistory == null)
            fSelectionHistory = new SelectionHistory(this);
        result = fSelectionHistory;
    } else if (IResource.class.equals(required)) {
        IEditorInput input = getEditorInput();
        if (input != null) {
            result = input.getAdapter(required);
        }
    } else {
        if (result == null && internalModel != null) {
            result = internalModel.getAdapter(required);
        }
        // others
        if (result == null)
            result = super.getAdapter(required);
    }
    if (result == null) {
    // Logger.log(Logger.INFO_DEBUG, "StructuredTextEditor.getAdapter returning null for " + required); //$NON-NLS-1$
    }
    if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) {
        long stop = System.currentTimeMillis();
        adapterRequests++;
        adapterTime += (stop - startPerfTime);
    }
    if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) {
        // $NON-NLS-1$
        System.out.println("Total calls to getAdapter: " + adapterRequests);
        // $NON-NLS-1$
        System.out.println("Total time in getAdapter: " + adapterTime);
        // $NON-NLS-1$
        System.out.println("Average time per call: " + (adapterTime / adapterRequests));
    }
    return result;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ITextEditorExtension5(org.eclipse.ui.texteditor.ITextEditorExtension5) ITextEditorExtension4(org.eclipse.ui.texteditor.ITextEditorExtension4) ITextEditorExtension3(org.eclipse.ui.texteditor.ITextEditorExtension3) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) PropertySheetConfiguration(org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration) ContentOutlineConfiguration(org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration) ConfigurableContentOutlinePage(org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage) ConfigurablePropertySheetPage(org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) ITextEditorExtension(org.eclipse.ui.texteditor.ITextEditorExtension) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput) SelectionHistory(org.eclipse.wst.sse.ui.internal.selection.SelectionHistory)

Aggregations

ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 SelectionHistory (org.eclipse.wst.sse.ui.internal.selection.SelectionHistory)3 IEditorPart (org.eclipse.ui.IEditorPart)2 IResource (org.eclipse.core.resources.IResource)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 Region (org.eclipse.jface.text.Region)1 IVerticalRuler (org.eclipse.jface.text.source.IVerticalRuler)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IWorkbenchSiteProgressService (org.eclipse.ui.progress.IWorkbenchSiteProgressService)1 ITextEditorExtension (org.eclipse.ui.texteditor.ITextEditorExtension)1 ITextEditorExtension3 (org.eclipse.ui.texteditor.ITextEditorExtension3)1 ITextEditorExtension4 (org.eclipse.ui.texteditor.ITextEditorExtension4)1 ITextEditorExtension5 (org.eclipse.ui.texteditor.ITextEditorExtension5)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1 ConfigurableContentOutlinePage (org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage)1 ConfigurablePropertySheetPage (org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage)1