Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Remove Import menu item(How to remove a menu item by program)
Remove Import menu item [message #1275014] Sat, 22 March 2014 10:34 Go to next message
Peter Robertson is currently offline Peter RobertsonFriend
Messages: 16
Registered: April 2012
Location: Scotland
Junior Member
I am maintaining a large Eclipse 4 project (which I did not write) where it turns out that the File/Import menu item is extremely dangerous, so I need to remove it.

I can do this by hand from the running project using Window/Customize Perspective so I know it is possible, but I need to get the same effect automatically each time the project starts.

I have searched for articles about this and have found several that give extremely complicated or esoteric methods (which I have been unable to get to work), or reference things that seem to be suggestions for future changes to Eclipse.

In there a straightforward way to remove a menu item by program?

I am by no means an expert in Eclipse.



Re: Remove Import menu item [message #1288423 is a reply to message #1275014] Tue, 08 April 2014 14:47 Go to previous message
Peter Robertson is currently offline Peter RobertsonFriend
Messages: 16
Registered: April 2012
Location: Scotland
Junior Member
I have found a way of doing this.

   private void hideMenu(MenuManager M, String main, String sub) {
      IContributionItem item = M.find(main);
      if (item != null) {
         MenuManager S = (MenuManager)item;
         item = S.find(sub);
         if (item != null) item.setVisible(false);
      }
   }
   
   private void removeMenuItems() {
      IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow();
      if (window instanceof WorkbenchWindow) {
         WorkbenchWindow WW = (WorkbenchWindow) window;
         MenuManager menuManager = WW.getMenuManager();
         hideMenu(menuManager, "file", "import");
...

It works, but comes up with a bunch of 'Discouraged access' warnings.
After a lot of internet searching I am still trying to find out exactly what they mean and how to get rid of them.

I am from the old school of programming where all warnings should be treated as errors, so simply turning them off is anathema.
Previous Topic:TrimBar maximum height
Next Topic:MultiPageEditor and FormEditor replacements
Goto Forum:
  


Current Time: Thu Apr 25 13:20:50 GMT 2024

Powered by FUDForum. Page generated in 0.02519 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top