Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How add "Show In" navigation to a view?
How add "Show In" navigation to a view? [message #334848] Tue, 03 March 2009 11:21 Go to next message
Eclipse UserFriend
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 #334853 is a reply to message #334848] Tue, 03 March 2009 15:21 Go to previous messageGo to next message
Hitesh  is currently offline Hitesh Friend
Messages: 19
Registered: July 2009
Junior Member
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
Re: How add "Show In" navigation to a view? [message #334969 is a reply to message #334853] Thu, 12 March 2009 20:45 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:[DataBindings] validation in inline editing
Next Topic:IWorkbenchPage.STATE_RESTORED has no effect
Goto Forum:
  


Current Time: Sun Dec 22 03:01:18 GMT 2024

Powered by FUDForum. Page generated in 0.03134 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top