Search in sources :

Example 1 with ShowInContext

use of org.eclipse.ui.part.ShowInContext in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentOutlinePage method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent event) {
    super.selectionChanged(event);
    showInTarget.show(new ShowInContext(null, event.getSelection()));
}
Also used : ShowInContext(org.eclipse.ui.part.ShowInContext)

Example 2 with ShowInContext

use of org.eclipse.ui.part.ShowInContext in project KaiZen-OpenAPI-Editor by RepreZen.

the class DocumentUtils method openAndReveal.

/**
     * Opens the editor for the file located at the given path and reveal the selection.
     * 
     * @param path
     * @param selection
     */
public static void openAndReveal(IPath path, ISelection selection) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IFile file = root.getFile(path);
    final IEditorPart editor = openEditor(file);
    if (editor instanceof IShowInTarget) {
        IShowInTarget showIn = (IShowInTarget) editor;
        showIn.show(new ShowInContext(null, selection));
    }
}
Also used : IShowInTarget(org.eclipse.ui.part.IShowInTarget) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ShowInContext(org.eclipse.ui.part.ShowInContext) IEditorPart(org.eclipse.ui.IEditorPart)

Example 3 with ShowInContext

use of org.eclipse.ui.part.ShowInContext in project eclipse.platform.text by eclipse.

the class FileSearchPage method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
    if (IShowInTargetList.class.equals(adapter)) {
        return (T) SHOW_IN_TARGET_LIST;
    }
    if (adapter == IShowInSource.class) {
        ISelectionProvider selectionProvider = getSite().getSelectionProvider();
        if (selectionProvider == null)
            return null;
        ISelection selection = selectionProvider.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = ((StructuredSelection) selection);
            final Set<Object> newSelection = new HashSet<>(structuredSelection.size());
            Iterator<?> iter = structuredSelection.iterator();
            while (iter.hasNext()) {
                Object element = iter.next();
                if (element instanceof LineElement)
                    element = ((LineElement) element).getParent();
                newSelection.add(element);
            }
            return (T) (IShowInSource) () -> new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection)));
        }
        return null;
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ShowInContext(org.eclipse.ui.part.ShowInContext) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashSet(java.util.HashSet)

Example 4 with ShowInContext

use of org.eclipse.ui.part.ShowInContext in project eclipse.platform.text by eclipse.

the class SearchView method fillContextMenu.

@Override
public void fillContextMenu(IMenuManager menuManager) {
    ISearchResult result = getCurrentSearchResult();
    if (result != null) {
        // first check if we have a selection for the show in mechanism, bugzilla 127718
        IShowInSource showInSource = getAdapter(IShowInSource.class);
        if (showInSource != null) {
            ShowInContext context = showInSource.getShowInContext();
            if (context != null) {
                ISelection sel = context.getSelection();
                if (sel != null && !sel.isEmpty()) {
                    MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
                    showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getViewSite().getWorkbenchWindow()));
                    menuManager.appendToGroup(IContextMenuConstants.GROUP_OPEN, showInSubMenu);
                }
            }
        }
    }
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) ShowInContext(org.eclipse.ui.part.ShowInContext) IShowInSource(org.eclipse.ui.part.IShowInSource) ISelection(org.eclipse.jface.viewers.ISelection) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

ShowInContext (org.eclipse.ui.part.ShowInContext)4 ISelection (org.eclipse.jface.viewers.ISelection)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ISearchResult (org.eclipse.search.ui.ISearchResult)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IShowInSource (org.eclipse.ui.part.IShowInSource)1 IShowInTarget (org.eclipse.ui.part.IShowInTarget)1