Writing an Eclipse Plug-in (Part 20): Return of the Popup Menu (For an Empty Navigator)
[This is a long post. It also feels like a bit of a mess. Whoda thought that creating a popup menu when there are no resources available in a navigator could be so non-trivial?]
So what’s the problem (or as they say in marketing speak: what is the challenge)?
The challenge (or as they say in real life: the pain) is quite easy to describe: when I right click in the custom navigator the popup menu appears. When I create a custom project and right-click on it the popup menu does not appear.
That behavior has to stop or I am turning this blog around right now (I’m not kidding! I’ll turn around right now!).
Alright. I lied. We actually have two problems:
- Remove the undefined menu items from the popup when nothing is available or selected
- Enable a specific set of menus when a Custom Project has been created
What this means is we have to decide when menu items appear/disappear or are enabled/disabled based on items being selected/unselected.
Sounds like a lot of combinations. Sounds like a job for a UML State diagram which I actually like when I am writing a real application. The issue here is that I am still kinda just messing with this and the state diagram makes me become too serious (I find that even the squirrels start to complain).
So let’s list the menu items we know so far:
- New Custom Project
- New Schema File
- New Stored Procedure File
- Open Project
- Close Project
- Copy
- Paste
- Delete
- Import
- Export
- Refresh
- Properties
Looks like a lot. Let’s think about this: copy, paste and delete don’t mean what they usually do, except for projects. I expect them to only copy/paste/delete the nodes they represent not entire files. Let’s leave them for last so let’s just remove them.
Open and Close project sounds too cool to be true. They will come after we do copy, paste and delete (and while we’re at it, how about working sets? Nah.).
Import and Export are also unknown. Since importing/exporting anything but Custom Projects seems rather odd, and we don’t know what it means to import or export Custom Projects, they will have to go too.
That leaves us with:
- New Custom Project
- New Schema File
- New Stored Procedure File
- Refresh
- Properties
Much more managable. Also, we can expand what it means to be a schema and stored procedure in the Custom Navigator: the schema’s child nodes have New behavior as does the Stored Procedure node. So the list really looks like this:
- New Custom Project
- New Schema Table
- New Schema View
- New Schema Filter
- New Stored Procedure
- Refresh
- Properties
When nothing is selected the following are enabled:
- New Custom Project
- Refresh
We can’t go around randomly creating Tables, Views and Filters just because, now can we?
When a Custom Project, or any custom resource, is selected the following are enabled:
- New Custom Project
- New Schema Table
- New Schema View
- New Schema Filter
- New Stored Procedure
- Refresh
- Properties
As Richard Dreyfus once yelled into the open air: What does it mean?
What the above means is that the easiest way to control the popup menu for this custom navigator is to make one (or in this case two) rather than rely on the default popup and reconfigure it as we go. I tried desperately to avoid it, but in order to remove the default presentation of New, Import and Export it is just plain ol’ easier to make a new popup menu. Dems the breaks.
Tasks for this post and the next:
- Create a popup menu when the Custom navigator is empty
- Create a popup menu when a resource is selected in the Custom navigator
How (are we doing it?)
Time to back track. Remove the following:
- Remove all three commonWizard entries found under org.eclipse.ui.navigator.navigatorContent. That removes the menu entries under the popup menu New.
- Remove navigatorplugin –> plugin.xml –> org.eclipse.ui.menus
- Remove org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding) entry.
That was the easy stuff. The more involved steps for this post are:
- Define the popup menu and its insertionPoints
- Define the actionProvider
- Define the actionExtension
- Implement the action provider code (if not implementing the command framework)
Sounds pretty straightforward doesn’t it?
Let’s see how well we do.
- Define the popup menu and its insertionPoints
- Create a viewer entry in org.eclipse.ui.viewer
- org.eclipse.ui.navigator.viewer –> New –> viewer
- viewerId: customnavigator.navigator
- org.eclipse.ui.navigator.viewer –> New –> viewer
- Create a popupMenu entry under the viewer
- customnavigator.navigator (viewer) –> New –> popupMenu
- id: customnavigator.navigator#PopupMenu
- customnavigator.navigator (viewer) –> New –> popupMenu
- Add two insertion points under the popupMenu
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- name: group.new
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- name: group.build
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- Create a viewer entry in org.eclipse.ui.viewer
- Define the actionProviders
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
- class: customnavigator.popup.actionprovider.CustomNewActionProvider
- id: customnavigator.popup.actionprovider.CustomNewAction
- customnavigator.popup.actionprovider.CustomNewActionProvider (actionProvider) –> enablement –> New –> or
- or –> New –> adapt
- type: org.eclipse.core.resources.IResource
- or –> New –> adapt
- type: java.util.Collection
- java.util.Collection –> New –> count
- value: 0
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
- class: customnavigator.popup.actionprovider.CustomRefreshActionProvider
- id: customnavigator.popup.actionprovider.CustomRefreshAction
- customnavigator.popup.actionprovider.CustomRefreshActionProvider (actionProvider) –> enablement –> New –> or
- or –> New –> adapt
- type: org.eclipse.core.resources.IResource
- or –> New –> adapt
- type: java.util.Collection
- java.util.Collection –> New –> count
- value: 0
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
- Define the actionExtensions
- org.eclipse.ui.navigator.viewer –> New –> viewerActionBinding
- viewerId: customnavigator.navigator
- customnavigator.navigator (viewerActionBinding) –> New –> includes
- includes –> New –> actionExtension
- pattern: customnavigator.popup.actionprovider.CustomNewAction
- org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding) –> (includes) –> New –> actionExtension and change pattern to:
- pattern: customnavigator.popup.actionprovider.CustomRefreshAction
- org.eclipse.ui.navigator.viewer –> New –> viewerActionBinding
- Implement the action provider code in the customnavigator plug-in
customnavigator.popup.actionprovider.CustomNewActionProvider/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Mar 28, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; import org.eclipse.ui.navigator.WizardActionGroup; public class CustomNewActionProvider extends CommonActionProvider { private static final String NEW_MENU_NAME = "common.new.menu";//$NON-NLS-1$ private ActionFactory.IWorkbenchAction showDlgAction; private WizardActionGroup newWizardActionGroup; private boolean contribute = false; @Override public void init(ICommonActionExtensionSite anExtensionSite) { if (anExtensionSite.getViewSite() instanceof ICommonViewerWorkbenchSite) { IWorkbenchWindow window = ((ICommonViewerWorkbenchSite) anExtensionSite.getViewSite()).getWorkbenchWindow(); showDlgAction = ActionFactory.NEW.create(window); newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService()); contribute = true; } } @Override public void fillContextMenu(IMenuManager menu) { IMenuManager submenu = new MenuManager( "New", NEW_MENU_NAME); if(!contribute) { return; } // fill the menu from the commonWizard contributions newWizardActionGroup.setContext(getContext()); newWizardActionGroup.fillContextMenu(submenu); submenu.add(new Separator(ICommonMenuConstants.GROUP_ADDITIONS)); // Add other .. submenu.add(new Separator()); submenu.add(showDlgAction); // append the submenu after the GROUP_NEW group. menu.insertAfter(ICommonMenuConstants.GROUP_NEW, submenu); } @Override public void dispose() { if (showDlgAction!=null) { showDlgAction.dispose(); showDlgAction = null; } super.dispose(); } }
customnavigator.popup.actionprovider.CustomRefreshActionProvider
/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Apr 4, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.window.IShellProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.RefreshAction; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import customnavigator.Activator; /** * The bulk of this code is taken from * org.eclipse.ui.internal.navigator.resources.actions.ResourceMgmtActionProvider * which is provided with Eclipse in case you want to look up the original. * * @author carlos */ public class CustomRefreshActionProvider extends CommonActionProvider { private RefreshAction refreshAction; private Shell shell; /* * (non-Javadoc) * @see * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) */ @Override public void init(ICommonActionExtensionSite aSite) { super.init(aSite); shell = aSite.getViewSite().getShell(); makeActions(); } @Override public void fillActionBars(IActionBars actionBars) { actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); updateActionBars(); } /** * Adds the refresh resource actions to the context menu. * * @param menu * context menu to add actions to */ @SuppressWarnings("rawtypes") @Override public void fillContextMenu(IMenuManager menu) { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); boolean hasClosedProjects = false; Iterator resources = selection.iterator(); while (resources.hasNext() && (!hasClosedProjects)) { Object next = resources.next(); IProject project = null; if (next instanceof IProject) { project = (IProject) next; } else if (next instanceof IAdaptable) { project = (IProject) ((IAdaptable) next).getAdapter(IProject.class); } if (project == null) { continue; } if (!project.isOpen()) { hasClosedProjects = true; } } if (!hasClosedProjects) { refreshAction.selectionChanged(selection); menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, refreshAction); } } protected void makeActions() { IShellProvider sp = new IShellProvider() { @SuppressWarnings("synthetic-access") @Override public Shell getShell() { return shell; } }; refreshAction = new RefreshAction(sp) { @Override public void run() { final IStatus[] errorStatus = new IStatus[1]; errorStatus[0] = Status.OK_STATUS; final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus); WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$ @SuppressWarnings("synthetic-access") @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { op.run(monitor); if (shell != null && !shell.isDisposed()) { shell.getDisplay().asyncExec(new Runnable() { @Override public void run() { StructuredViewer viewer = getActionSite().getStructuredViewer(); if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) { viewer.refresh(); } } }); } } catch (InvocationTargetException e) { String msg = NLS.bind("Exception in {0}. run: {1}", getClass().getName(), e.getTargetException()); throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, msg, e .getTargetException())); } catch (InterruptedException e) { return Status.CANCEL_STATUS; } return errorStatus[0]; } }; ISchedulingRule rule = op.getRule(); if (rule != null) { job.setRule(rule); } job.setUser(true); job.schedule(); } }; refreshAction.setDisabledImageDescriptor(getImageDescriptor("icons/refresh_nav_disabled.gif"));//$NON-NLS-1$ refreshAction.setImageDescriptor(getImageDescriptor("icons/refresh_nav_enabled.gif"));//$NON-NLS-1$ refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH); } /** * Returns the image descriptor with the given relative path. */ protected ImageDescriptor getImageDescriptor(String relativePath) { return Activator.getIDEImageDescriptor(relativePath); } @Override public void updateActionBars() { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); refreshAction.selectionChanged(selection); } }
Add the following to customnavigator.Activator:
public class Activator extends AbstractUIPlugin { ... public static ImageDescriptor getIDEImageDescriptor(String imagePath) { return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, imagePath); } }
Add the following icons to the customnavigator icons folder:
refresh_nav_enabled.gif:
Don’t forget:
- Fix the warnings in MANIFEST.MF and plugin.xml.
- Open the Externalize Strings Wizard and move the two strings to messages.properties in the folder with the action provider code.
Why (did we do it that way?)
To do today’s tasks it is necessary to clean the deck. That means removing all the wonderous things that took advantage of all the default GUI hooks and basically putting them back with new hooks. Think of it like spring cleaning…without spring or the cleaning.
Since we have already decided to have only the menu entries we really need we have to remove the commonWizard and org.eclipse.ui.menus entries for now. Don’t worry, we’ll put them back. It will be easier and cleaner to add them in sequence rather than removing some pieces, moving things around and hoping they work eventually.
- Remove all three commonWizard entries found under org.eclipse.ui.navigator.navigatorContent. That removes the menu entries under the popup menu New.
- Remove navigatorplugin –> plugin.xml –> org.eclipse.ui.menus
As you should already know from the last post, the menuContribution entry found under org.eclipse.ui.menus let’s you directly add new menu items to an existing popup by giving Eclipse the path to the menu being affected. We’ll use this again later. Some things are too good to give up for long.
- Remove org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding) entry.The value of actionExtension –> pattern refers to the ids of the actionProvider classes that execute the default behavior when a popup menu item is selected. For example, the value we just removed, org.eclipse.ui.navigator.resources.*, refers to the actionProvider ids found in the org.eclipse.ui.navigator.resources plug-in. Remember how the default popup menu displays New, Import, Export and Refresh? Well, if you open org.eclipse.ui.navigator.resources –> plugin.xml you will find an actionProvider entry for the following classes (there are others, but additional actionProvider do not concern me):
- org.eclipse.ui.internal.navigator.resources.actions.NewActionProvider
- org.eclipse.ui.internal.navigator.resources.actions.PortingActionProvider
- org.eclipse.ui.internal.navigator.resources.actions.ResourceMgmtActionProvider
The ids for the above classes are:
- org.eclipse.ui.navigator.resources.NewActions
- org.eclipse.ui.navigator.resources.PortingActions
- org.eclipse.ui.navigator.resources.ResourceMgmtActions
Notice that the above ids fit the pattern org.eclipse.ui.navigator.resources.*. Eclipse doesn’t care about the class name; it cares about the id. Yes, there are other actionProviders, but they have enablement criteria that keeps them from being displayed when nothing is selected.
- Define the new popup menu and the insertionPoints.Time to make the donuts.
Let’s create the popup and add one menu item. In order to do that we have to
- Create a viewer entry in org.eclipse.ui.viewer
- Create a popupMenu entry under the viewer
- Add an insertion point under the popupMenu
- Create a viewerActionBinding and actionExtension entry in org.eclipse.ui.navigator.viewer
Do the following in the customnavigator plugin.xml Extensions tab:
- Create a viewer entry in org.eclipse.ui.viewer
- org.eclipse.ui.navigator.viewer –> New –> viewer
- viewerId: customnavigator.navigator
- org.eclipse.ui.navigator.viewer –> New –> viewer
- Create a popupMenu entry under the viewer
- customnavigator.navigator (viewer) –> New –> popupMenu
- id: customnavigator.navigator#PopupMenu
- customnavigator.navigator (viewer) –> New –> popupMenu
- Add an insertion point under the popupMenu
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- name: group.new
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- Create a viewerActionBinding and actionExtension entry in org.eclipse.ui.navigator.viewer
- org.eclipse.ui.navigator.viewer –> New –> viewerActionBinding
- viewerId: customnavigator.navigator
- customnavigator.navigator (viewerActionBinding) –> New –> includes
- includes –> New –> actionExtension
- pattern: org.eclipse.ui.navigator.resources.NewActions
- org.eclipse.ui.navigator.viewer –> New –> viewerActionBinding
Quick note: The name group.new comes from ICommonMenuConstants found in org.eclipse.ui.navigator. Whenever possible I recommend adhering to existing naming conventions just to make things easier to find.
Just for yucks we are using an existing action provider: org.eclipse.ui.internal.navigator.resources.actions.NewActionProvider whose id is org.eclipse.ui.navigator.resources.NewActions. What is interesting about the NewActionProvider is that it creates a new menu insertion point in the popup which allows menu items to be added as submenus. What is bad about NewActionProvider is that it does it programmatically.
NewActionProvider.java
public class NewActionProvider extends CommonActionProvider { ... public void fillContextMenu(IMenuManager menu) { IMenuManager submenu = new MenuManager( WorkbenchNavigatorMessages.NewActionProvider_NewMenu_label, NEW_MENU_NAME); if(!contribute) { return; } ... // THIS IS A NEW INSERTION POINT! WHODA THUNK IT? menu.insertAfter(ICommonMenuConstants.GROUP_NEW, submenu); } ... }
That’s right, we cannot declare an insertion point for submenus in plugin.xml; the insertion point for a submenu has to be declared programmatically. Yes, code will have to be written, but we are going to
stealcopy most of it anyway. - Start the runtime workbench and check that the popup menu appears when there is nothing displayed in the navigator. Exit the runtime workbench when you are done. Let’s create our own version of this code.
- Implement a version of CustomNewActionProvider to create an insertion point for the New Wizards.
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
- class: customnavigator.popup.actionprovider.CustomNewActionProvider
- id: customnavigator.popup.actionprovider.CustomNewAction
- customnavigator.popup.actionprovider.CustomNewActionProvider (actionProvider) –> enablement –> New –> or
- or –> New –> adapt
- type: org.eclipse.core.resources.IResource
- or –> New –> adapt
- type: java.util.Collection
- java.util.Collection –> New –> count
- value: 0
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
Return to customnavigator.popup.actionprovider.CustomNewActionProvider (actionProvider). Click the class link. Create the class. Add the following code:
/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Mar 28, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; import org.eclipse.ui.navigator.WizardActionGroup; public class CustomNewActionProvider extends CommonActionProvider { private static final String NEW_MENU_NAME = "common.new.menu";//$NON-NLS-1$ private ActionFactory.IWorkbenchAction showDlgAction; private WizardActionGroup newWizardActionGroup; private boolean contribute = false; @Override public void init(ICommonActionExtensionSite anExtensionSite) { if (anExtensionSite.getViewSite() instanceof ICommonViewerWorkbenchSite) { IWorkbenchWindow window = ((ICommonViewerWorkbenchSite) anExtensionSite.getViewSite()).getWorkbenchWindow(); showDlgAction = ActionFactory.NEW.create(window); newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService()); contribute = true; } } @Override public void fillContextMenu(IMenuManager menu) { IMenuManager submenu = new MenuManager( "New", NEW_MENU_NAME); if(!contribute) { return; } // fill the menu from the commonWizard contributions newWizardActionGroup.setContext(getContext()); newWizardActionGroup.fillContextMenu(submenu); submenu.add(new Separator(ICommonMenuConstants.GROUP_ADDITIONS)); // Add other .. submenu.add(new Separator()); submenu.add(showDlgAction); // append the submenu after the GROUP_NEW group. menu.insertAfter(ICommonMenuConstants.GROUP_NEW, submenu); } @Override public void dispose() { if (showDlgAction!=null) { showDlgAction.dispose(); showDlgAction = null; } super.dispose(); } }
Now associate (bind) the actionProvider to the popup through the viewerActionBinding:
- Go to org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding) –> (includes) –> org.eclipse.ui.navigator.resources.NewActions and change pattern to:
- pattern: customnavigator.popup.actionprovider.CustomNewAction
Notice the use of the id, not the class name.
Let’s put back one of the pieces we removed earlier:
- org.eclipse.ui.navigator.navigatorContent –> New –> commonWizard
- type: new
- wizardId: customplugin.wizard.new.custom
Let’s add the Refresh menu without the functionality…just to maintain purity of thought. Besides, I confuse easily. We’ll add the code in a few steps.First, add a new insertionPoint for the Refresh menu:
- customnavigator.navigator#PopupMenu (popupMenu) –> New –> insertionPoint
- name: group.build
- separator: true
The name group.build comes from ICommonMenuConstants found in org.eclipse.ui.navigator.
Let’s define the actionProvider for the Refresh menu:
- org.eclipse.ui.navigator.navigatorContent –> New –> actionProvider
- class: customnavigator.popup.actionprovider.CustomRefreshActionProvider
- id: customnavigator.popup.actionprovider.CustomRefreshAction
- customnavigator.popup.actionprovider.CustomRefreshActionProvider –> enablement –> New –> or
- or –> New –> adapt
- type: org.eclipse.core.resources.IResource
- or –> New –> adapt
- type: java.util.Collection
- java.util.Collection –> New –> count
- value: 0
Next, let’s steal copy, the existing code from ResourceMgmtActionProvider to create CustomRefreshActionProvider.
Return to customnavigator.popup.actionprovider.CustomRefreshActionProvider (actionProvider). Click the class link, create the class and insert this code:
/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Apr 4, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.window.IShellProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.RefreshAction; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import customnavigator.Activator; /** * The bulk of this code is taken from * org.eclipse.ui.internal.navigator.resources.actions.ResourceMgmtActionProvider * which is provided with Eclipse in case you want to look up the original. * * @author carlos */ public class CustomRefreshActionProvider extends CommonActionProvider { private RefreshAction refreshAction; private Shell shell; /* * (non-Javadoc) * @see * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) */ @Override public void init(ICommonActionExtensionSite aSite) { super.init(aSite); shell = aSite.getViewSite().getShell(); makeActions(); } @Override public void fillActionBars(IActionBars actionBars) { actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); updateActionBars(); } /** * Adds the refresh resource actions to the context menu. * * @param menu * context menu to add actions to */ @SuppressWarnings("rawtypes") @Override public void fillContextMenu(IMenuManager menu) { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); boolean hasClosedProjects = false; Iterator resources = selection.iterator(); while (resources.hasNext() && (!hasClosedProjects)) { Object next = resources.next(); IProject project = null; if (next instanceof IProject) { project = (IProject) next; } else if (next instanceof IAdaptable) { project = (IProject) ((IAdaptable) next).getAdapter(IProject.class); } if (project == null) { continue; } if (!project.isOpen()) { hasClosedProjects = true; } } if (!hasClosedProjects) { refreshAction.selectionChanged(selection); menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, refreshAction); } } protected void makeActions() { IShellProvider sp = new IShellProvider() { @SuppressWarnings("synthetic-access") @Override public Shell getShell() { return shell; } }; refreshAction = new RefreshAction(sp) { @Override public void run() { final IStatus[] errorStatus = new IStatus[1]; errorStatus[0] = Status.OK_STATUS; final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus); WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$ @SuppressWarnings("synthetic-access") @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { op.run(monitor); if (shell != null && !shell.isDisposed()) { shell.getDisplay().asyncExec(new Runnable() { @Override public void run() { StructuredViewer viewer = getActionSite().getStructuredViewer(); if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) { viewer.refresh(); } } }); } } catch (InvocationTargetException e) { String msg = NLS.bind("Exception in {0}. run: {1}", getClass().getName(), e.getTargetException()); throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, msg, e .getTargetException())); } catch (InterruptedException e) { return Status.CANCEL_STATUS; } return errorStatus[0]; } }; ISchedulingRule rule = op.getRule(); if (rule != null) { job.setRule(rule); } job.setUser(true); job.schedule(); } }; refreshAction.setDisabledImageDescriptor(getImageDescriptor("icons/refresh_nav_disabled.gif"));//$NON-NLS-1$ refreshAction.setImageDescriptor(getImageDescriptor("icons/refresh_nav_enabled.gif"));//$NON-NLS-1$ refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH); } /** * Returns the image descriptor with the given relative path. */ protected ImageDescriptor getImageDescriptor(String relativePath) { return Activator.getIDEImageDescriptor(relativePath); } @Override public void updateActionBars() { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); refreshAction.selectionChanged(selection); } }
I removed any code that did not contribute to the goal: make RefreshAction work. I changed comments as well.
Yes, there is a compile error in CustomRefreshActionProvider.getImageDescriptor(). To fix that we have to add the following method to customnavigator.Activator:
public class Activator extends AbstractUIPlugin { ... public static ImageDescriptor getIDEImageDescriptor(String imagePath) { return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, imagePath); } }
Compile error fixed.
In order for the CustomRefreshActionProvider to be called we have to add an entry under org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding):
- org.eclipse.ui.navigator.viewer –> customnavigator.navigator (viewerActionBinding) –> (includes) –> New –> actionExtension and change pattern to:
- pattern: customnavigator.popup.actionprovider.CustomRefreshAction
Again, notice the use of the id, not the class name. Could I simple have one entry for all of these action providers by putting in a pattern of customnavigator.popup.actionprovider.*? Of course, but where’s the fun in that (in other words, use that kind of pattern once you understand why you are using it. Until then, create individual entries)?
For those of you wondering when we added support for F5: the key binding is added by RefreshAction.
method makeActions() is looking for an enabled and a disabled image for Refresh. Add the following images to your customnavigator icon folder:

What Just Happened?
So we took a few steps back and a few steps forward.
- We removed the plugin.xml entries that reconfigured the default popup.
- We created a new popup menu definition with insertion points.
- We declared and implemented two action providers: New and Refresh.
- We declared two action extensions that referred to the action providers.
- We declared a commonWizard entry to add the New Custom Project Wizard to the New popup menu.
Not bad for a post that I just couldn’t find the time for. For some reason it felt like a lot to do to create a new default menu. Adding the other items will be much simpler. I hope.
In other news: some of you may have noticed that in past posts I occasionally mentioned Deployment files as a feature. I am easily confused. The only things we are going to do are Custom Projects, Schemas and Stored Procedures. Any references to anything else are red herrings, blind alleys, and otherwise dead ends. Avoid them unless you are intent on finding a place to sleep.
References
Building a Common Navigator based viewer, Part III: Configuring Menus
Code
Activator.java
package customnavigator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "customnavigator"; //$NON-NLS-1$ // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { // empty for now } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } public static Image getImage(String imagePath) { ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, imagePath); Image image = imageDescriptor.createImage(); return image; } public static ImageDescriptor getIDEImageDescriptor(String imagePath) { return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, imagePath); } }
CustomNewActionProvider.java
/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Mar 28, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; import org.eclipse.ui.navigator.WizardActionGroup; /** * Provides the new (artifact creation) menu options for a context menu. * * <p> * The added submenu has the following structure * </p> * * <ul> * <li>a set of context sensitive wizard shortcuts (as defined by * <b>org.eclipse.ui.navigator.commonWizard</b>), </li> * <li>another separator, </li> * <li>a generic "Other" new wizard shortcut action</li> * </ul> * * @since 3.2 * */ public class CustomNewActionProvider extends CommonActionProvider { private static final String NEW_MENU_NAME = "common.new.menu";//$NON-NLS-1$ private ActionFactory.IWorkbenchAction showDlgAction; private WizardActionGroup newWizardActionGroup; private boolean contribute = false; @Override public void init(ICommonActionExtensionSite anExtensionSite) { if (anExtensionSite.getViewSite() instanceof ICommonViewerWorkbenchSite) { IWorkbenchWindow window = ((ICommonViewerWorkbenchSite) anExtensionSite.getViewSite()).getWorkbenchWindow(); showDlgAction = ActionFactory.NEW.create(window); newWizardActionGroup = new WizardActionGroup(window, PlatformUI.getWorkbench().getNewWizardRegistry(), WizardActionGroup.TYPE_NEW, anExtensionSite.getContentService()); contribute = true; } } /** * Adds a submenu to the given menu with the name "group.new" see * {@link ICommonMenuConstants#GROUP_NEW}). The submenu contains the following structure: * * <ul> * <li>a set of context sensitive wizard shortcuts (as defined by * <b>org.eclipse.ui.navigator.commonWizard</b>), </li> * <li>another separator, </li> * <li>a generic "Other" new wizard shortcut action</li> * </ul> */ @Override public void fillContextMenu(IMenuManager menu) { IMenuManager submenu = new MenuManager( Messages.CustomNewActionProvider_popupNewLabel, NEW_MENU_NAME); if(!contribute) { return; } // fill the menu from the commonWizard contributions newWizardActionGroup.setContext(getContext()); newWizardActionGroup.fillContextMenu(submenu); submenu.add(new Separator(ICommonMenuConstants.GROUP_ADDITIONS)); // Add other .. submenu.add(new Separator()); submenu.add(showDlgAction); // append the submenu after the GROUP_NEW group. menu.insertAfter(ICommonMenuConstants.GROUP_NEW, submenu); } /* (non-Javadoc) * @see org.eclipse.ui.actions.ActionGroup#dispose() */ @Override public void dispose() { if (showDlgAction!=null) { showDlgAction.dispose(); showDlgAction = null; } super.dispose(); } }
CustomRefreshActionProvider.java
/** * Coder beware: this code is not warranted to do anything. * Some or all of this code is taken from the Eclipse code base. * * Copyright Apr 4, 2010 Carlos Valcarcel */ package customnavigator.popup.actionprovider; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.window.IShellProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.RefreshAction; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import customnavigator.Activator; /** * The bulk of this code is taken from * org.eclipse.ui.internal.navigator.resources.actions.ResourceMgmtActionProvider * which is provided with Eclipse in case you want to look up the original. * * @author carlos */ public class CustomRefreshActionProvider extends CommonActionProvider { private RefreshAction refreshAction; private Shell shell; /* * (non-Javadoc) * @see * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) */ @Override public void init(ICommonActionExtensionSite aSite) { super.init(aSite); shell = aSite.getViewSite().getShell(); makeActions(); } @Override public void fillActionBars(IActionBars actionBars) { actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction); updateActionBars(); } /** * Adds the refresh resource actions to the context menu. * * @param menu * context menu to add actions to */ @SuppressWarnings("rawtypes") @Override public void fillContextMenu(IMenuManager menu) { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); boolean hasClosedProjects = false; Iterator resources = selection.iterator(); while (resources.hasNext() && (!hasClosedProjects)) { Object next = resources.next(); IProject project = null; if (next instanceof IProject) { project = (IProject) next; } else if (next instanceof IAdaptable) { project = (IProject) ((IAdaptable) next).getAdapter(IProject.class); } if (project == null) { continue; } if (!project.isOpen()) { hasClosedProjects = true; } } if (!hasClosedProjects) { refreshAction.selectionChanged(selection); menu.appendToGroup(ICommonMenuConstants.GROUP_BUILD, refreshAction); } } protected void makeActions() { IShellProvider sp = new IShellProvider() { @SuppressWarnings("synthetic-access") @Override public Shell getShell() { return shell; } }; refreshAction = new RefreshAction(sp) { @Override public void run() { final IStatus[] errorStatus = new IStatus[1]; errorStatus[0] = Status.OK_STATUS; final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus); WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$ @SuppressWarnings("synthetic-access") @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { op.run(monitor); if (shell != null && !shell.isDisposed()) { shell.getDisplay().asyncExec(new Runnable() { @Override public void run() { StructuredViewer viewer = getActionSite().getStructuredViewer(); if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) { viewer.refresh(); } } }); } } catch (InvocationTargetException e) { String msg = NLS.bind(Messages.CustomRefreshActionProvider_invocationTargetExceptionMessage, getClass().getName(), e.getTargetException()); throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, msg, e .getTargetException())); } catch (InterruptedException e) { return Status.CANCEL_STATUS; } return errorStatus[0]; } }; ISchedulingRule rule = op.getRule(); if (rule != null) { job.setRule(rule); } job.setUser(true); job.schedule(); } }; refreshAction.setDisabledImageDescriptor(getImageDescriptor("icons/refresh_nav_disabled.gif"));//$NON-NLS-1$ refreshAction.setImageDescriptor(getImageDescriptor("icons/refresh_nav_enabled.gif"));//$NON-NLS-1$ refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH); } /** * Returns the image descriptor with the given relative path. */ protected ImageDescriptor getImageDescriptor(String relativePath) { return Activator.getIDEImageDescriptor(relativePath); } @Override public void updateActionBars() { IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); refreshAction.selectionChanged(selection); } }
Messages.java
package customnavigator.popup.actionprovider; import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "customnavigator.popup.actionprovider.messages"; //$NON-NLS-1$ public static String CustomNewActionProvider_popupNewLabel; public static String CustomRefreshActionProvider_invocationTargetExceptionMessage; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); } private Messages() { } }
messages.properties
CustomNewActionProvider_popupNewLabel=New CustomRefreshActionProvider_invocationTargetExceptionMessage=Exception in {0}. run: {1}
plugin.xml
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.ui.views"> <category id="customnavigator.category" name="%category.name"> </category> <view allowMultiple="false" category="customnavigator.category" class="org.eclipse.ui.navigator.CommonNavigator" icon="icons/navigator.png" id="customnavigator.navigator" name="%view.name"> </view> </extension> <extension point="org.eclipse.ui.navigator.viewer"> <viewer viewerId="customnavigator.navigator"> <popupMenu id="customnavigator.navigator#PopupMenu"> <insertionPoint name="group.new"> </insertionPoint> <insertionPoint name="group.build" separator="true"> </insertionPoint> </popupMenu> </viewer> <viewerContentBinding viewerId="customnavigator.navigator"> <includes> <contentExtension pattern="customnavigator.navigatorContent"> </contentExtension> </includes> </viewerContentBinding> <viewerActionBinding viewerId="customnavigator.navigator"> <includes> <actionExtension pattern="customnavigator.popup.actionprovider.CustomNewAction"> </actionExtension> <actionExtension pattern="customnavigator.popup.actionprovider.CustomRefreshAction"> </actionExtension> </includes> </viewerActionBinding> </extension> <extension point="org.eclipse.ui.navigator.navigatorContent"> <navigatorContent activeByDefault="true" contentProvider="customnavigator.navigator.ContentProvider" id="customnavigator.navigatorContent" labelProvider="customnavigator.navigator.LabelProvider" name="%navigatorContent.name"> <triggerPoints> <instanceof value="org.eclipse.core.resources.IWorkspaceRoot"> </instanceof> </triggerPoints> <commonSorter class="customnavigator.sorter.SchemaCategorySorter" id="customnavigator.sorter.schemacategorysorter"> <parentExpression> <or> <instanceof value="customnavigator.navigator.CustomProjectSchema"> </instanceof> </or> </parentExpression> </commonSorter> </navigatorContent> <actionProvider class="customnavigator.popup.actionprovider.CustomNewActionProvider" id="customnavigator.popup.actionprovider.CustomNewAction"> <enablement> <or> <adapt type="org.eclipse.core.resources.IResource"> </adapt> <adapt type="java.util.Collection"> <count value="0"> </count> </adapt> </or> </enablement> </actionProvider> <actionProvider class="customnavigator.popup.actionprovider.CustomRefreshActionProvider" id="customnavigator.popup.actionprovider.CustomRefreshAction"> <enablement> <or> <adapt type="org.eclipse.core.resources.IResource"> </adapt> <adapt type="java.util.Collection"> <count value="0"> </count> </adapt> </or> </enablement> </actionProvider> <commonWizard type="new" wizardId="customplugin.wizard.new.custom"> <enablement></enablement> </commonWizard> </extension> </plugin>
MANIFEST.MF
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: customnavigator;singleton:=true Bundle-Version: 1.0.2.0 Bundle-Activator: customnavigator.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.ui.ide;bundle-version="3.6.0", org.eclipse.ui.navigator, customplugin;bundle-version="1.0.1" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: customnavigator, customnavigator.navigator, customnavigator.popup.actionprovider, customnavigator.sorter
Leave a Reply Cancel reply
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 |
Top Posts
Archives
- January 2012 (1)
- February 2011 (1)
- January 2011 (1)
- August 2010 (2)
- June 2010 (1)
- May 2010 (2)
- April 2010 (1)
- March 2010 (1)
- February 2010 (4)
- January 2010 (2)
- December 2009 (5)
- November 2009 (2)
- October 2009 (6)
- September 2009 (6)
- August 2009 (4)
- July 2009 (6)
- April 2009 (2)
- February 2009 (2)
- December 2008 (1)
- October 2008 (2)
- September 2008 (2)
- August 2008 (1)
Top Rated
Blog Stats
- 484,940 hits
Hi,
This piece of code is not working. Got following error while launching the plugin. Could you please share the working source code with me? I am stuck with the customization of pop-up menu using CNF framework. Got following error stack.
Thanks
Nikhil
org.eclipse.core.runtime.CoreException: Plug-in customnavigator was unable to load class customnavigator.popup.actionprovider.CustomRefreshActionProvider.
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.throwException(RegistryStrategyOSGI.java:194)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:176)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:905)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at org.eclipse.ui.internal.navigator.actions.CommonActionProviderDescriptor$1.run(CommonActionProviderDescriptor.java:197)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.navigator.actions.CommonActionProviderDescriptor.createActionProvider(CommonActionProviderDescriptor.java:194)
at org.eclipse.ui.navigator.NavigatorActionService$5.run(NavigatorActionService.java:349)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.navigator.NavigatorActionService.getActionProviderInstance(NavigatorActionService.java:347)
at org.eclipse.ui.navigator.NavigatorActionService$3.run(NavigatorActionService.java:257)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.navigator.NavigatorActionService.fillActionBars(NavigatorActionService.java:253)
at org.eclipse.ui.navigator.CommonNavigatorManager$2.run(CommonNavigatorManager.java:92)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.navigator.CommonNavigatorManager$UpdateActionBarsJob.runInUIThread(CommonNavigatorManager.java:87)
at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:95)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ClassNotFoundException: customnavigator.popup.actionprovider.CustomRefreshActionProvider
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1207)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
… 41 more
I resolved the above stack , now getting ‘can not find labelprovider’
I don’t wnat ot define my own label provider, can not we use the CNF label Provider class. Even though its not required element, its throwing error:
MESSAGE Executable extension definition for “labelProvider” not found.
!STACK 1
org.eclipse.core.runtime.CoreException: Executable extension definition for “labelProvider” not found.
at org.eclipse.core.internal.registry.ConfigurationElement.throwException(ConfigurationElement.java:62)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:222)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor.createLabelProvider(NavigatorContentDescriptor.java:394)
at org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension$2.run(NavigatorContentExtension.java:172)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension.getLabelProvider(NavigatorContentExtension.java:169)
at org.eclipse.ui.internal.navigator.NavigatorContentServiceLabelProvider.findStyledText(NavigatorContentServiceLabelProvider.java:163)
at org.eclipse.ui.internal.navigator.NavigatorContentServiceLabelProvider.getStyledText(NavigatorContentServiceLabelProvider.java:151)
at org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider$StyledLabelProviderAdapter.getStyledText(NavigatorDecoratingLabelProvider.java:68)
at org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.getStyledText(DelegatingStyledCellLabelProvider.java:195)
at org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.getStyledText(DecoratingStyledCellLabelProvider.java:192)
at org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider.getText(NavigatorDecoratingLabelProvider.java:222)
at org.eclipse.ui.internal.navigator.framelist.TreeFrame.(TreeFrame.java:74)
at org.eclipse.ui.internal.navigator.framelist.TreeViewerFrameSource.createFrame(TreeViewerFrameSource.java:59)
at org.eclipse.ui.internal.navigator.CommonNavigatorFrameSource.createFrame(CommonNavigatorFrameSource.java:40)
at org.eclipse.ui.internal.navigator.framelist.TreeViewerFrameSource.getCurrentFrame(TreeViewerFrameSource.java:84)
at org.eclipse.ui.internal.navigator.framelist.TreeViewerFrameSource.getFrame(TreeViewerFrameSource.java:98)
at org.eclipse.ui.internal.navigator.framelist.FrameList.init(FrameList.java:166)
at org.eclipse.ui.internal.navigator.framelist.FrameList.(FrameList.java:55)
at org.eclipse.ui.navigator.CommonViewer.createFrameList(CommonViewer.java:571)
Getting following error too… This has been asked in many forums, but never answered clearly 😦
!MESSAGE Problems occurred when invoking code from plug-in: “org.eclipse.ui.navigator”.
!STACK 0
java.lang.IllegalArgumentException: Group not found: group.reorganize
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.RefactorActionGroup.fillContextMenu(RefactorActionGroup.java:66)
at org.eclipse.ui.internal.navigator.resources.actions.RefactorActionProvider.fillContextMenu(RefactorActionProvider.java:49)
at org.eclipse.ui.navigator.NavigatorActionService$2.run(NavigatorAction
Hi,
I am trying to customize the cotext menu in navigator view.
I created a new view using Common Navigator framewrok, and successfully removed few command from RMB. I am seeing only , new, open, import/export. I removed edit and refactor group etc.
But when I am selecting the file and RMB, it is showing me poper commands, but in console its throwing the exception like:
group.build, group.edit, group.reorganize etc not found.
I have used the viewerActionBinding and viewerContentBinding for
Attaching the plugin.xml
the error stck is:
MESSAGE Problems occurred when invoking code from plug-in: “org.eclipse.ui.navigator”.
!STACK 0
java.lang.IllegalArgumentException: Group not found: group.reorganize
at org.eclipse.jface.action.ContributionManager.addToGroup(ContributionManager.java:131)
at org.eclipse.jface.action.ContributionManager.appendToGroup(ContributionManager.java:138)
at org.eclipse.ui.internal.navigator.resources.actions.RefactorActionGroup.fillContextMenu(RefactorActionGroup.java:66)
at