How to remove a menu itme from menubar in eclipse rcp - eclipse

I am trying to remove "project" menu from menubar dynamically, means using code. Please help me out. It will be really helpful if someone can provide the exact code.

If you are writing an RCP application you can control what goes into the main menu. If you are adding plugins that you didn't write yourself and they are using extension points to contribute to the main menu, you can use Activities/Capabilities to remove them.
You cannot remove things from the main menu programmatically, unless your code contributed it.

Related

Extend an existing Context Menu inside Eclipse Outline View for Xtext

We have an eclipse plugin which has been created using Xtext. And now I want to add a context menu to an Element inside the Outline View inside Eclipse. I understand that I need to have a menuContribution which will invoke a Command. But what I dont understand is, do I have to create (define) a command in some way or the other.
My plugin.xml contains an extension point for "org.eclipse.ui.menus".
Menu Contribution is something like this:
I find tutorials that talk about creating menu contributions, but there is nothing which will tie up my menuContribution to a command I want to define.
Typically you will need three extensions:
org.eclipse.ui.command
org.eclipse.ui.handlers
org.eclipse.ui.menu
It requires some fidling to get them right. I suggest you look at some open source code and starts from there.
Introduction article: http://www.vogella.com/tutorials/EclipseCommands/article.html
The locationUri of the context menu you like to contribute to should be popup:org.eclipse.xtext.ui.outline.OutlinePageContextMenu. Found here: https://github.com/eclipse/xtext-eclipse/blob/master/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/outline/impl/OutlinePage.java

Hide UI element (C/C++ category) via eclipse activities

I'm trying to hide UI-elements via the eclipse activities. I implemented the activities successfully for the following issues:
menu item
context menu item
toolbar icon
Unfortunately I don't make it for the project wizards of the category C/C++ ("Data -> New -> Other..." what you can actually see in the attachment)
I tried the following pattern,
<activityPatternBinding activityId="random" pattern="org.eclipse.cdt.ui.*"/>
with success, but this pattern hides a lot of other things too. So I tried to hide the org.eclipse.cdt.ui.wizards.*, but that didn't work, probably the wrong pattern plugin id.
So am I on the right way to hide the C/C++ category with the activityPatternBinding or should I use the categoryActivityBinding? But therefore I need a valid categoryId. I tried the plugin-spy, I searched inside the jar files, I googled it, but I don't find the right pattern to hide the C/C++ category in the project builder.
Thanks a lot for your help!
Finally the following pattern solved my problem:
pattern="org.eclipse.cdt.ui/org.eclipse.cdt.ui.wizards.*"

How to add views to Show In menu for particular file types

I use an older plugin called Veloeclipse for editing Velocity templates in Eclipse. There's been no development on this since 2009, which isn't a problem because it's mainly just for syntax highlighting and format validation. The really annoying thing about it, however, is that when I try to do Show In to view the current Velocity template within my Package Explorer or Project Explorer, the only available option is Properties. That's not really useful. I really need to be able to get to the file in one of the regular explorer views.
So I have sort of two questions:
Is there a way to configure this without having to monkey with any code? A configuration file or something? I've grepped through my Eclipse installation and haven't seen anything, but I'm hoping that there's something I'm missing.
So assuming that the answer to my first question is no, how do I go about modifying the plugin code so that it will show more than the Properties view in the Show In menu? Most of what I found on the plugin development wiki comes from the other direction: how to make your view or perspective appear in the Show In menu.
Any help with this would be hugely appreciated!
Try to check the plugin source code. it might do something different than other editors. What I mean is that the show in menu item that you have there is not the usual extension point but a hard coded context menu option.

Activate the activator class

I am using eclipse 3.6. I created one sample plugin application. It is neither a eclipse rcp nor workbench. Now when I run the eclipse I want that plugin also to be loaded. But I dont want to use IStartUp. Because what I have found out is
IStartup will be called after the workbench is loaded. I want to refresh some menu. So Is there any way to activate my plugin while the eclipse loaded?
I tried to use Bundle Activation policy. But that is also not activating my Activator class. I just put one System.out. println("Inside start()"). So that is not called. Now can I make it activate my activator?
EDIT:
what my exact requirement is, I have created one workbench application.It is not eclipse rcp application. Now I want to remove the following menu and menu items from the eclipse before the eclipe is loaded.
1. File Menu
2.) Search Menu
3.)Run Menu
4.)Help->search,Dynamic Help,Key assist,Tips and trick,Report Bug,Cheat Sheet.
These menus are inbuilt menu of eclipse. So that is the reason I have to do in this way.
So I already implemented by using startup extension point. But the early startup is called after the eclipse is started.So I need to do some refreshment on the workbench.Then only the menu item will get removed.So I thought I need startup extension point will not satisfy my requirement as it doesnot refresh the workbench.I need to activate the my plugin and refresh the workbench before it is loaded.
Thanks
Bhanu
You can set the needed start level for your plugin using touch point instruction.
You are just a plugin that expects to run in the Eclipse IDE?
Then the answer is, you cannot do what you want.
If you start before the workbench has finished initializing, most of the services that could be used won't work: The workbench itself, menu service, command service, etc.
For most plugins in eclipse, the plugin.xml should be used to add menus, views, editors, etc to eclipse. When necessary, the framework will instantiate them.
org.eclipse.ui.IStartup is available and as you mentioned it will be called after the workbench has been initialized, but before any windows have been shown. It's not to be used lightly, and not by plugins contributing to the UI as it allows all extension from that plugin to be loaded.
EDIT:
If you are an RCP app, you control the main menu. As an RCP app, you have access to the ActionBarAdvisor, WorkbenchAdvisor, WorkbenchWindowAdvisor, which all have lifecycle methods.
If you are an an eclipse plugin, you can add to the main menu ... you cannot easily remove from the main menu. This is by design. Start levels and org.eclipse.ui.startup are 2 mechanisms that won't do what you want.
You still need to answer these questions:
There might still be a way. The crux of your problem is: "I want to refresh some menu"
What kind of menu (popup, main menu,
compound list of menu items in a
menu, etc)?
Where is the menu contribution coming from?
Which specific menu item is it?
Please edit your question (do not comment) and include the information from the above 3 questions, please.

how to access package explorer element in eclipse plugin

i am making an eclipse plugin which make a ui on right clicking a project in eclipse workspce . the ui contains text fields , package explorer for the current project and directory explorer for current project.
i have successfully made a ui which appears on clicking a menu item on right clicking the project but it seems i can't make any jface or swt ui since they are not visible when we are using eclipse command hadlers .so in order to overcome it i made dialog pages but they have limited dialog like directorty dialog and file dialog and that too for entire window directory..... but i want package explorer and directory explorer for the project i just chose like it happens when u try making a new class in a project the browse buttons just show packages and directory struture w.r.t to current selection
am i doin things wrong or is there a way out please suggest .....
It seems a bit unclear to me, what the 'UI' is about. If you plan to embed the package and directory views inside a dialog next to each other, then I think you have to build similar lists on your own, since they are views with their own event logic. But if you plan to use them via the browse buttons as describes, take a look at this page. It gives a good overview of the available selection dialogs in eclipse.
It is also always a good practice to search for code in eclipse that does nearly the same you want to do.
As an example, take a look at the new class wizard from the jdt.ui plug-in (This is the wizard you mentioned in your question): Press Cmd-Shift-T and begin typing 'newclass' and open NewClassWizardPage from org.eclipse.jdt.ui.wizards. This works as expected if you imported all jdt plug-ins as (binary) projects.
Take a look at the createControl method and dive into the createXXXControls methods via F3 and try to find out how JDT is doing the job.
As an alternative, open the desired selection dialog class (again with Cmd-Shift-T) and open the call hierarchy of that class...