Filter popup on project nature [message #806232] |
Fri, 24 February 2012 13:22  |
Eclipse User |
|
|
|
Hi,
How can I filter a menu contribution for popup menus so that it only
appears when a project contains a particular project nature?
Thanks
Charlie
|
|
|
Re: Filter popup on project nature [message #806327 is a reply to message #806232] |
Fri, 24 February 2012 15:48  |
Eclipse User |
|
|
|
Solved problem by using a class the implements
ExtensionContributionFactory using the following method
@Override
public void createContributionItems(IServiceLocator iServiceLocator,
IContributionRoot iContributionRoot)
{
try
{
ISelection iSelection =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
if (null == iSelection)
throw new Exception ("iSelection is null");
if (! (iSelection instanceof TreeSelection))
throw new Exception ("iSelection is NOT instanceof TreeSelection");
TreeSelection treeSelection = (TreeSelection) iSelection;
@SuppressWarnings("rawtypes")
List tempList = treeSelection.toList();
Object tempObject = tempList.get(0);
IFile iFile = null;
if (! (tempObject instanceof IFile) )
return;
iFile = (IFile) tempObject;
IProject iProject = iFile.getProject();
boolean propellerNatureFlag = iProject.hasNature(PropellerNature.ID);
if (! propellerNatureFlag )
return;
// IPath fullPath = iFile.getFullPath();
String fileExtension = iFile.getFileExtension();
String properEndingString =
PropellerConstants.CONFIGURATION_EDITOR_EXTENSION;
boolean properExtensionFlag = fileExtension.equals(properEndingString);
if (! properExtensionFlag)
return;
CommandContributionItemParameter commandContributionItemParameter =
new CommandContributionItemParameter(iServiceLocator, null,
"com.parallax.propeller.gcc.ui.commands.generate_scripts.GenerateCompileScriptHandler",
CommandContributionItem.STYLE_PUSH);
CommandContributionItem commandContributionItem = new
CommandContributionItem(commandContributionItemParameter);
iContributionRoot.addContributionItem(commandContributionItem, null);
int tempDebug = 0;
}// try
catch (Exception e)
{
@SuppressWarnings("unused")
int tempDebug2 = 1;
}// catch (Exception e)
}// public void createContributionItems(IServiceLocator
iServiceLocator, IContributionRoot iContributionRoot)
On 2/24/2012 10:22 AM, Charlie Kelly wrote:
> Hi,
>
> How can I filter a menu contribution for popup menus so that it only
> appears when a project contains a particular project nature?
>
> Thanks
>
> Charlie
|
|
|
Powered by
FUDForum. Page generated in 0.28055 seconds