public ShowInContext getShowInContext() { if (getEditor() != null) { IShowInSource source = (IShowInSource) getEditor().getAdapter(IShowInSource.class); if (source != null) { return source.getShowInContext(); } } return null; }
private ShowInContext getContext(IWorkbenchPart sourcePart) { IShowInSource source = getShowInSource(sourcePart); if (source != null) { ShowInContext context = source.getShowInContext(); if (context != null) { return context; } } else if (sourcePart instanceof IEditorPart) { Object input = ((IEditorPart) sourcePart).getEditorInput(); ISelectionProvider sp = sourcePart.getSite().getSelectionProvider(); ISelection sel = sp == null ? null : sp.getSelection(); return new ShowInContext(input, sel); } return null; }
@Override public ShowInContext getShowInContext() { if (isActive()) { IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); if (selection.size() == 1) { Object object = selection.getFirstElement(); if (object instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) object; IShowInSource show = adaptable.getAdapter(IShowInSource.class); if (show != null) { return show.getShowInContext(); } } } } return null; }
private ShowInContext getContext(IWorkbenchPart sourcePart) { IShowInSource source = getShowInSource(sourcePart); if (source != null) { ShowInContext context = source.getShowInContext(); if (context != null) { return context; } } else if (sourcePart instanceof IEditorPart) { Object input = ((IEditorPart) sourcePart).getEditorInput(); ISelectionProvider sp = sourcePart.getSite().getSelectionProvider(); ISelection sel = sp == null ? null : sp.getSelection(); return new ShowInContext(input, sel); } return null; }
/** * @param event * {@link ExecutionEvent} for which the * {@link PropertyShowInContext} is requested * @return a {@link PropertyShowInContext} containing the the * {@link ISelection} and {@link IWorkbenchPart} for the given * {@link ExecutionEvent} * @throws ExecutionException */ protected PropertyShowInContext getShowInContext(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePartChecked(event); if (activePart instanceof PropertySheet) { PropertySheet sheet = (PropertySheet) activePart; return (PropertyShowInContext) sheet.getShowInContext(); } IShowInSource adapter = Adapters.adapt(activePart, IShowInSource.class); if (adapter != null) { ShowInContext showInContext = adapter.getShowInContext(); return new PropertyShowInContext(activePart, showInContext); } return new PropertyShowInContext(activePart, HandlerUtil .getShowInSelection(event)); }
/** * @param event * {@link ExecutionEvent} for which the * {@link PropertyShowInContext} is requested * @return a {@link PropertyShowInContext} containing the the * {@link ISelection} and {@link IWorkbenchPart} for the given * {@link ExecutionEvent} * @throws ExecutionException */ protected PropertyShowInContext getShowInContext(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePartChecked(event); if (activePart instanceof PropertySheet) { PropertySheet sheet = (PropertySheet) activePart; return (PropertyShowInContext) sheet.getShowInContext(); } IShowInSource adapter = Adapters.adapt(activePart, IShowInSource.class); if (adapter != null) { ShowInContext showInContext = adapter.getShowInContext(); return new PropertyShowInContext(activePart, showInContext); } return new PropertyShowInContext(activePart, HandlerUtil .getShowInSelection(event)); }
/** * Returns the <code>ShowInContext</code> to show in the selected target, * or <code>null</code> if there is no valid context to show. * <p> * This implementation obtains the context from the * <code>IShowInSource</code> of the source part (if provided), or, if the * source part is an editor, it creates the context from the editor's input * and selection. * <p> * Subclasses may extend or reimplement. * * @return the <code>ShowInContext</code> to show or <code>null</code> */ protected ShowInContext getContext(IWorkbenchPart sourcePart) { if (sourcePart != null) { IShowInSource source = Adapters.adapt(sourcePart, IShowInSource.class); if (source != null) { ShowInContext context = source.getShowInContext(); if (context != null) { return context; } } else if (sourcePart instanceof IEditorPart) { Object input = ((IEditorPart) sourcePart).getEditorInput(); ISelectionProvider sp = sourcePart.getSite().getSelectionProvider(); ISelection sel = sp == null ? null : sp.getSelection(); return new ShowInContext(input, sel); } } return null; }
private void updateSelectionToMatchEditor() { if (getEditor() == null) { return; } IShowInSource source = (IShowInSource) getEditor().getAdapter(IShowInSource.class); if (source != null) { ShowInContext showInContext = source.getShowInContext(); if (showInContext != null) { if (showInContext.getSelection() instanceof IStructuredSelection) { Object firstElement = ((IStructuredSelection) showInContext.getSelection()).getFirstElement(); if (firstElement instanceof OutlineItem) { setSelection(new StructuredSelection(firstElement)); } } } } } }
@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); } } } } }
public void fillContextMenu(IMenuManager menuManager) { ISearchResult result= getCurrentSearchResult(); if (result != null) { menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, fSearchAgainAction); // first check if we have a selection for the show in mechanism, bugzilla 127718 IShowInSource showInSource= (IShowInSource) 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); } } } } }