How to remove unwanted menu contributions in eclipse rcp application? - java

I have made a eclipse RCP application, everything is working fine but i recently noticed the Refractor option in menu. I would like to get rid of it. I have the following in ActionBarAdvisor.java:
#Override
protected void fillMenuBar(IMenuManager menu) {
menu.add(createFile());
menu.add(createEdit());
menu.add(createNavigate());
menu.add(createProject());
menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(createWindow());
menu.add(createHelp());
}
The above functions add actions to menu as:
edit.add(undoAct);
and also undoAct is defined as:
private IWorkbenchAction undoAction
makeActions function has contents as:
#Override
protected void makeActions(IWorkbenchWindow window) {
undoAction = ActionFactory.UNDO.create(window);
undoAction.setText("Undo Menu");
register(undoAction);
}
I found a suggestion which said to use hideActionSets to hide the menu. But I could not hide the entire menu but just its actions!
Remove "File, edit,...etc" menus from Eclipse RCP application
How to remove Refractor option now?
Thank you.

You can use activities, as described here.
First, you will need to find the ID of the menu:
Use the Plug-In Spy
The first way is to use the Plug-In Spy. Press alt-shift-F2 and click on a
menu item or toolbar button that you want to be hidden. If there is an ID
string under the heading "active action definition identifier" then you are
in luck. This item has been added using the Command Extension and you can
use this ID as the pattern argument for the Activities Extension. But not
all items that have been added using the Command Extension present their ID
string to the plug-in spy.
As a side note, the ID strings are period separated. For instance the ID for
a button might be "org.eclipse.ui.navigate.backwardHistory". Regular
expressions use the period to stand for any character. Luckily the period
used as a wild card matches with actual period characters so you don't need
to escape them if you don't want to. I find it makes it a bit easier to read
if they are not escaped and it is highly unlikely it will cause any
ambiguous matches.
Use the Plug-In Registry and plugin.xml files
The second way is to use the Plug-In Registry. You can open this view by
going to:
Window/Show View.../Other/Plug-in Development/Plug-In Registry
What you would like to do is to try to get a couple pieces of information:
a) the plugin that is contributing the UI element
b) information about what kind of extension the plugin is using to create
the UI element
If there is a very unique word associated with the UI element or its tool
tip then you can use this in the Plug-In Registry's filter field to try to
nail down which plug-in is contributing the UI element. The filter field is
not a very powerful tool so it can be a bit frustrating to use. It does not
allow wildcards and does not match space characters.
When you track down which plug-in is contributing the UI element then you
open the the plug-in in question from the Plug-Ins view which is found
grouped with the Package Explorer in the Plug-in Development perspective.
Then go to the Extensions tab and search for the ID string which can usually
be found in either a usage of the Command or ActionSet extension. If the UI
element is added using an ActionSet then you prefix the plug-in ID to UI ID
in the pattern argument given to the Activities Extension. For example
org.eclipse.ui.actionsets.foo becomes the pattern
org.eclipse.ui/org.eclipse.ui.actionsets.foo.
Then create a new Activity which will never be activated and a corresponding activityPatternBinding with the id you found in the last step. It will look like this in your plugin.xml:
<extension point="org.eclipse.ui.activities">
<activity id="myActivity" name="MenuHidingActivity">
<enabledWhen>
<with variable="activePartId">
<equals value="nonExistentPartId"></equals>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="myActivity" pattern="menuItemID">
</activityPatternBinding>
</extension>

Related

Eclipse : Is it possible to open one resource in two different editors as per requirement?

In my current project, there is a situation where we have one file let's say "File1.cfg" in project explorer. There is a default editor "Editor 1" registered using "*.editors" extension.
Requirement Function:
When a user double click on the File1.cfg, it should be opened with an "Editor 1" by default and all the time.
There is one more option provided in Toolbar which will be used to open "Editor 2". And this editor should use the resource "File1.cfg" and display the contents as per the UI.
How can this be achieved in the Eclipse?
A plug-in can specify the editor id to be used when opening an editor. See IWorkbenchPage.openEditor and IDE.openEditor.
Normally these APIs check for an editor (of any id) already being open on the file. If you want to force the editor with the given id to open regardless you need to use the IWorkbenchPage method:
IEditorPart openEditor(IEditorInput input, String editorId, boolean activate,
int matchFlags)
with the matchFlags value set to:
IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT
to only match an existing editor with the same id and input.

RCP visiblewhen programmatically (Java)

I have a command into the plugin.xml which will add a new menu button. This button should not be visible all the time, hence I would like to check a complex condition from Java code to decide when it have to be visible.
I know that there is a visiblewhen and a hidewhen possibility, but I don't know how can let a Java class/method to make the decision.
For this check the enabled state of the command is used, which is determined by the return value of IHandler.isEnabled().
In the plugin.xml the contribution of the command to the menu has to have the visibleWhen element and checkEnabled="true". In Eclipse you can right click the command contribution and add visible when, in the plugin.xml it looks like this:
<command
commandId="...">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
To enable/disable the command you have to implement the isEnabled() method from org.eclipse.core.commands.IHandler (or override from AbstractHandler) in your command handler and return false, if the menu entry should be hidden.

Can I use org.eclipse.core.variables... in defining attributes of other extensions

I'm creating an RCP 3.7 editor by using org.eclipse.ui.editors extension point. What I need is to dynamically define icon path based on some conditions during editor startup.
(EDIT: The editor is actually just restored after startup, but it's not selected as active yet, so you can see only tab with title and icon)
I tried to work with getImageDescriptor() method in class implementing IEditorInput, which doesn't seem to be used. The only way that has some effect on the icon is changing the icon path in definition of editor extension.
Therefore I started to play with org.eclipse.core.variables.valueVariables and org.eclipse.core.variables.dynamicVariables for use in icon attribute (showing valueVariables just for easy example):
<extension point="org.eclipse.ui.editors">
<editor name="%Editor_TITLE"
extensions="xml"
icon="${FOO}"
class="org.example.ExampleEditor"
id="org.example.ExampleEditor">
</editor>
</extension>
<extension point="org.eclipse.core.variables.valueVariables">
<variable name="FOO"
initialValue="images/obj16/editor.png">
</variable>
</extension>
However, that doesn't work either. Is there some way to use dynamically defined variable values (based on current condition) that could change the path of icon? ...or I'll be greatfull even for a workaround suggestion, that will lead to successful changing of the icon during startup (like making the ImageDescriptor work no startup).
Variables only work in places where they are explicitly support in the code. If the documentation for an extension point does not say they are supported then they won't work.
You get use the image descriptor from the editor input to set the editor title image by doing something like the following in your editor's init method:
public void init(IEditorSite site, IEditorInput input)
throws PartInitException
{
... other code
ImageDescriptor desc = input.getImageDescriptor();
Image image = desc.createImage();
setTitleImage(image);
... other code
}

Netbeans Plugin development: #ActionReference paths reference

I am developing a Netbeans plugin which will verify a Web Project against some rules.
I am trying to add it a menu as a first item in the Projects context menu. From what I understand, this is done by specifing the path attribute in the #ActionReference annotation. Anyone knows where to find a complete reference for the possible paths?
This is what I have now, and my Menu item appears somewhere in the bottom of the Projects context menu, so I suspect I need something different than "Projects/Actions"
#ActionID(
category = "Tools",
id = "org.chain.war.WarVerifier")
#ActionRegistration(
displayName = "#CTL_WarVerifier")
#ActionReference(path = "Projects/Actions", position = 0)
public final class WarVerifier implements ActionListener
I am on Netbeans 7.2
Thanks,
Chris.
Right-click on one your package New > Other... and under Module Development choose XML Layer.
This XML Layer will show as a drop down containing 2 elements, choose this layer in context you will have the full hierarchy.

How to add navigation to a custom Magnolia CMS template?

I've managed to create a custom page template for Magnolia CMS pretty easily following this tutorial:
http://documentation.magnolia-cms.com/templates/introduction.html
However, I'm at the point where I'd like to insert the navigation into my template but I can't find a simple way to do so. It looks like other's have had this problem with no clear way to fix it. Does anyone know how to easily include the navigation? Thanks
If you're using Magnolia CE (Community Edition) 4.5.x, you need to know that basically every page template extends the one defined in /modules/standard-templating-kit/config/site/templates/prototype. There you have a node, /navigation. You can copy that node to your new custom template, and after that you can start playing with it's properties.
But before that, don't forget to include the navigation menu(s) somewhere in your main template file (.ftl) and make your template to use stk model class info.magnolia.module.templatingkit.templates.pages.STKPageModel (add an attribute to your template named modelClass, look at stkArticle (or stkSection), it's a good place to start)
Horizontal navigation:
[#if def.navigation.top]
[#include def.navigation.horizontal.template]
[/#if]
Vertical nav:
[#if def.navigation.top]
[#include def.navigation.vertical.template]
[/#if]
If you want to include your menu in another template included with a [#cms.area ...] tag,
you can use this code:
[#if model.root.def.navigation.top]
[#include model.root.def.navigation.vertical.template]
[/#if]

Categories