Eclipse: Disable property tab contributed from navigator plugin - eclipse

I need to hide propery tab called "Resources" contributed by plugin org.eclipse.ui.navigator.resources
This tab looks like this:
The description of this tab from plugin:
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
<propertyContributor
contributorId="org.eclipse.ui.navigator.ProjectExplorer"
labelProvider="org.eclipse.ui.internal.navigator.resources.workbench.TabbedPropertySheetTitleProvider">
<propertyCategory category="general"/>
<propertyCategory category="core"/>
<propertyCategory category="appearance"/>
<propertyCategory category="resource"/>
<propertyCategory category="advanced"/>
</propertyContributor>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs contributorId="org.eclipse.ui.navigator.ProjectExplorer">
<propertyTab
label="%Resource"
category="resource"
id="CommonNavigator.tab.Resource"/>
</propertyTabs>
</extension>
I want to hide this tab, so there will be visible only tab contributed by my plugin.
Update.
I have tried activities like this, but is doesnt helps:
<activityPatternBinding
activityId="com.company.activities.hide"
isEqualityPattern="true"
pattern="org.eclipse.ui.navigator.resources/CommonNavigator.tab.Resource">
</activityPatternBinding>

On possibility is to remove unwanted contribution:
final ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
final IActionSetDescriptor[] actionSets = reg.getActionSets();
final String[] removeActionSets =
new String[] { "org.eclipse.search.searchActionSet", "org.eclipse.ui.cheatsheets.actionSet",
"org.eclipse.ui.actionSet.keyBindings", "org.eclipse.ui.edit.text.actionSet.navigation",
"org.eclipse.ui.edit.text.actionSet.annotationNavigation",
"org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo",
"org.eclipse.ui.edit.text.actionSet.openExternalFile",
"org.eclipse.ui.externaltools.ExternalToolsSet", "org.eclipse.ui.WorkingSetActionSet",
"org.eclipse.update.ui.softwareUpdates", "org.eclipse.ui.actionSet.openFiles",
"org.eclipse.mylyn.tasks.ui.navigation", };
for (IActionSetDescriptor actionSet : actionSets) {
boolean found = false;
for (String removeActionSet : removeActionSets) {
if (removeActionSet.equals(actionSet.getId())) {
found = true;
}
}
if (!found) {
continue;
}
final IExtension ext = actionSet.getConfigurationElement().getDeclaringExtension();
reg.removeExtension(ext, new Object[] { actionSet });
}

Related

Eclipse RCP Content Assist not working with auto activated characters

I define my own editor and have completion proposals like this
public IContentAssistant getContentAssistant(ISourceViewer sv) {
ContentAssistant ca = new ContentAssistant();
IContentAssistProcessor pr = new TagCompletionProcessor();
ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
return ca;
}
#Override
public char[] getCompletionProposalAutoActivationCharacters() {
String str = "._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return str.toCharArray();
}
So when I am pressing ctrl-space enter it will work, but I want it should always trigger computeCompletionProposals when any of the above characters are entered.
<extension
point="org.eclipse.ui.editors">
<editor
id="testingpluginproject.editors.XMLEditor"
name="Sample XML Editor"
icon="icons/sample.png"
extensions="xxml"
class="testingpluginproject.editors.XMLEditor"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor">
</editor>
</extension>
So what I am missing?
You must call the ContentAssistant enableAutoActivation method to enable auto activation:
ca.enableAutoActivation(true);
You might also want to look at implementing IContentAssistProcessorExtension rather than just IContentAssistProcessor as it provides a better isCompletionProposalAutoActivation method.

Not able to extend the Help menu

I want to add from an eclipse plugin a Request Support button to the Help menu.
I tried first from a *.e4xmi file and now I tried from the plugin.xml but still can't make a button to appear under the Help menu.
I got the menu URI with the help of Eclipse Spy Plug-in.
The content of plugin.xml:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false" (tried with true and same result)
locationURI="menu:help?after=about">
<menu
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support">
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="com.plugin.handlers.RequestSupportHandler"
description="Opens up default e-mail client with preset basic informations"
id="com.plugin.RequestSupport"
name="Request Support">
</command>
</extension>
What am I missing?
SOLUTION from greg's answer:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false" (tried with true and same result)
locationURI="menu:help?after=about">
<menu
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support">
</menu>
<command
commandId="com.plugin.RequestSupport"
id="requestSupport"
label="Request Support"
style="push">
</command>
</menuContribution>
</extension>
This is what 'Check for Updates' uses:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:help?after=additions">
<command
commandId="org.eclipse.equinox.p2.ui.sdk.update"
mnemonic="%Update.command.mnemonic"
id="org.eclipse.equinox.p2.ui.sdk.update"
icon="icons/obj/iu_update_obj.png">
</command>
Which is adding after the 'additions' location.
The code which creates the help menu defines a lot of locations:
private MenuManager createHelpMenu() {
MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);
addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
// See if a welcome or intro page is specified
if (introAction != null) {
menu.add(introAction);
} else if (quickStartAction != null) {
menu.add(quickStartAction);
}
menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
menu.add(helpContentsAction);
menu.add(helpSearchAction);
menu.add(dynamicHelpAction);
addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
// See if a tips and tricks page is specified
if (tipsAndTricksAction != null) {
menu.add(tipsAndTricksAction);
}
// HELP_START should really be the first item, but it was after
// quickStartAction and tipsAndTricksAction in 2.1.
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
// about should always be at the bottom
menu.add(new Separator("group.about")); //$NON-NLS-1$
ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
aboutItem.setVisible(!Util.isMac());
menu.add(aboutItem);
menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
return menu;
}
(from org.eclipse.ui.internal.ide.WorkbenchActionBuilder)
All the addSeparatorOrGroupMarker, new Separator and new GroupMaker calls define ids to can add after.

Eclipse RCP Can't Contribute to Main Toolbar

My RCP app has the coolbar visible by setting configurer.setShowCoolBar(true) in WorkbenchWindowAdvisor#preWindowOpen. But when I contribute a toolbar to the main toolbar, it never shows up. Here's my contribution code:
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="toolbar.perspectivesDynamic">
<dynamic
class="my.package.PerspectiveSwitcherToolbar"
id="perspectiveSwitcherToolbar">
</dynamic>
</toolbar>
</menuContribution>
</extension>
And the ContributionItem class:
public class PerspectiveSwitcherToolbar extends ContributionItem {
...
#Override
public void fill(final ToolBar parent, int index) {
//Does not get called
}
#Override
public void fill(CoolBar parent, int index) {
//Does not get called
}
...
}
I'm using this code for adding a custom perspective switcher. It's rather old, but I see examples everywhere on the Internet adding a toolbar like this to the main toolbar, so I'm missing something elsewher, I assume
I think that is bug 392457: <toolbar><dynamic></toolbar> doesn't work at the moment. You can work around it by using a <control> and managing the contents yourself.

How can I add submenus for pop up menu programatically?

In my plugin, I have a pop up menu with menu item 'X' and I want to add submenu to this menu item
and the number and labels of menu items in the submenu and their action will change.
I think I can';t do this from plugin.xml, so how to do this programatically?
In your plugin.xml, under org.eclipse.ui.menus, add a menuContribution that refers to the id of your "root" menu, i.e. the menu that you want to have your submenus attached to (in this case, menu:myDynamicMenuRoot):
<menuContribution
allPopups="true"
class="com.myCode.menus.MyDynamicMenuContributions"
locationURI="menu:myDynamicMenuRoot">
</menuContribution>
Note that allPopups="true" ensures that your submenus will be added to any menu with the id myDynamicMenuRoot that you add anywhere in your application.
Finally, create a class extending ExtensionContributionFactory, whose job it will be to create your dynamic submenu items. Here I add items based on commands I have defined in my plugin.xml:
public class MyDynamicMenuContributions extends ExtensionContributionFactory {
private static final ImageDescriptor GREEN_STAR = Plugin.getImageDescriptor("icons/green_star.png");
#Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
// build a couple of command-based contribution parameters
CommandContributionItemParameter pAA = new CommandContributionItemParameter(
serviceLocator,
"Submenu_CommandAA",
"my.package.command.myCommandAA",
SWT.PUSH);
pAA.icon = GREEN_STAR;
pAA.label = "Command AA";
CommandContributionItemParameter pBB = new CommandContributionItemParameter(
serviceLocator,
"Submenu_CommandBB",
"my.package.command.myCommandBB",
SWT.PUSH);
pBB.icon = GREEN_STAR;
pBB.label = "Command BB";
// create actual contribution items and add them to the given additions reference
CommandContributionItem itemAA = new CommandContributionItem(pAA);
itemAA.setVisible(true);
additions.addContributionItem(itemAA, null);
CommandContributionItem itemBB = new CommandContributionItem(pBB);
itemBB.setVisible(true);
additions.addContributionItem(itemBB, null);
}
}

Creating own toolbar leveraging existing org.eclipse.ui.menus extension

I have custom editor for eclipse. For particular reasons this editor provide two toolbar areas which are not based on standard action bars provided by eclipse for editor. This two places are dedicated for other plugins to contribute. My intention is to leverage "org.eclipse.ui.menus" extension point with custom menuContribution/locationURI so other plugins can contribute using this extension and associated toolbar:my.editor.toolbar1 and toolbar:my.editor.toolbar2 as locationURI.
My problem is how to "connect" my ToolBar with particular location. I tried following approach but result are not good. I created custom ToolbarContributionRoot event if I should not and also created CustomContributionFactory which extends ExtensionContributionFactory. It works pretty well, but problem is with pulldown commands which submenu is not resolved correctly.
toolbarManager = new ToolBarManager(SWT.FLAT);
ToolbarContributionRoot toolbarRoot = new ToolbarContributionRoot(toolbarManager);
IServiceLocator workbench = PlatformUI.getWorkbench();
IConfigurationElement[] allMenuElements
= Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.menus");
for (IConfigurationElement menuContribution : allMenuElements) {
String locationURI = menuContribution.getAttribute("locationURI");
if ("toolbar:my.editor.toolbar1".equals(locationURI)) {
try {
ExtensionContributionFactory factory = CustomContributionFactory.create(menuContribution);
factory.createContributionItems(workbench, toolbarRoot);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
toolbar = toolbarManager.createControl(root);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, false, false, 1, 1);
toolbar.setLayoutData(gridData);
toolbar.pack();
plugin.xml of "user" looks like this:
<extension point="org.eclipse.ui.menus" id="my.helper.id">
<menuContribution locationURI="toolbar:my.editor.toolbar1">
<command commandId="my.editor.special.command1" />...
Do you have any suggestions how to blend my custom toolbars and "org.eclipse.ui.menus" extension together?
Correct way how to do it is:
toolbarManager = new ToolBarManager(SWT.FLAT);
IServiceLocator workbench = PlatformUI.getWorkbench();
IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class);
menuService.populateContributionManager(toolbarManager, TOOLBAR_LOCATION);
toolbar = toolbarManager.createControl(root);