How add "Show In" navigation to a view? [message #334848] |
Tue, 03 March 2009 11:21 |
Eclipse User |
|
|
|
Originally posted by: eclipse.kfdd.mine.nu
Hi,
I'm having problems figuring out how to add a "Show In" context menu for
a view.
My view lists various resources and I would like to add the "Show In"
menu enabling navigation based on the selected resources to the
Navigator and Project Explorer views.
Anyone who can help point me to examples on how to implement this?
TIA!
--Fredrik
|
|
|
|
Re: How add "Show In" navigation to a view? [message #334969 is a reply to message #334853] |
Thu, 12 March 2009 20:45 |
Eclipse User |
|
|
|
Originally posted by: eclipse.kfdd.mine.nu
Thanks!
Did the trick.
Also added some code to hook into the context menu of my view:
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("Show In");
showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.crea te(getViewSite().getWorkbenchWindow()));
manager.add(showInSubMenu);
}
}
}
Thanks,
--Fredrik
Hitesh wrote:
> This is how a view.views.SampleView would add the show view menu to itself.
> Adapt to your view suitably.
>
>
>
> The menu :
>
> <extension
> point="org.eclipse.ui.menus"> <menuContribution
> locationURI="popup:view.views.SampleView">
> <menu
> commandId="org.eclipse.ui.navigate.showInQuickMenu"
> id="view.views.SampleView.showInMenu"
> label="Show In">
> <!--Use the one in platform,ShowInMenu, see
> org.eclipse.ui.ExtensionFactory-->
> <dynamic
> class="org.eclipse.ui.ExtensionFactory:showInContribution"
> id="org.eclipse.ui.menus.dynamicShowInMenu">
> </dynamic>
> </menu>
> </menuContribution>
> </extension>
>
>
>
> The ShowIn Adapter :
> <extension
> point="org.eclipse.core.runtime.adapters">
> <!--IAdapterFactory that returns instance of IShowInSource-->
> <!--not needed if the view can adpat to
> org.eclipse.ui.part.IShowInSource-->
> <factory
> adaptableType="view.views.SampleView"
> class="view.views.ShowInAdapter">
> <adapter
> type="org.eclipse.ui.part.IShowInSource">
> </adapter>
> </factory>
> </extension>
>
>
> public class ShowInAdapter implements IAdapterFactory {
>
> private static Class[] classes = new Class[] { IShowInSource.class };
>
> public Object getAdapter(Object adaptableObject, Class adapterType) {
> if (!(adaptableObject instanceof SampleView))
> return null;
>
> final SampleView view = (SampleView) adaptableObject;
>
> return new IShowInSource() {
> public ShowInContext getShowInContext() {
> return new ShowInContext(null, new StructuredSelection(
> view.getSelectedResources()));
> }
>
> };
>
> }
> public Class[] getAdapterList() {
> return classes;
> }
> }
>
>
>
> Hitesh
>
|
|
|
Powered by
FUDForum. Page generated in 0.03134 seconds