Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:53:48+00:00 2026-06-15T21:53:48+00:00

The issue is this: Most things I read on the web says that we

  • 0

The issue is this: Most things I read on the web says that we should avoid actions when creating popup menus because the command framework allows for more decoupling.

Example: http://wiki.eclipse.org/FAQ_What_is_the_difference_between_a_command_and_an_action%3F

Fair enough.

But I am having a heck of a time getting the command framework to add my menu when I right click on a .java file inside the editor, and only when I click inside the editor. I can get the menu to show (using ‘with’ and the activeEditor variable), but it also shows when I right click on the java file inside the package explorer, which I don’t want. I suspect it’s because the file is already open inside the editor.

I also have a menu that gets added when I right click on the java file inside the package explorer, using IComplilationUnit. That works fine.

So my problem is solved using a popup menu action for when I click inside the file. I also get access to to all the ISelection stuff there. But the coupling is to high and I lose the flexability of using handlers.

I’m looking for either:
Tell me I’m doing it the only way possible; or
Tell me how to have my popup appear only when I right click on the java file editor.

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:53:49+00:00Added an answer on June 15, 2026 at 9:53 pm

    In the end it was really straight forward. The example below uses the command framework. It doesn’t have the handlers, so just click the class hyperlink whenever you need a class generated.

    Create a new eclipse plugin project called com.test.plugin.project

    In the dependency tab of the plugin.xml file add the following dependencies

    • org.eclipse.jdt
    • org.eclipse.jdt.core
    • org.eclipse.jdt.ui
    • org.eclipse.jface.text

    Put this in the plugin.xml tab section:

    <?xml version="1.0" encoding="UTF-8"?>
    <?eclipse version="3.4"?>
    <plugin>
       <extension
             point="org.eclipse.ui.menus">
          <menuContribution
                allPopups="true"
                locationURI="popup:org.eclipse.ui.popup.any">
             <menu
                   label="Test Project Sub Menu">
                <command
                      commandId="com.test.plugin.project.command.packageexplorer"
                      id="packageexplorerId"
                      style="push">
                   <visibleWhen
                         checkEnabled="false">
                      <iterate
                            ifEmpty="false"
                            operator="or">
                         <instanceof
                               value="org.eclipse.jdt.internal.core.CompilationUnit">
                         </instanceof>
                      </iterate>
                   </visibleWhen>
                </command>
                <command
                      commandId="com.test.plugin.project.command.classfile"
                      id="classfileId"
                      style="push">
                   <visibleWhen
                         checkEnabled="false">
                      <iterate
                            ifEmpty="false"
                            operator="or">
                         <and>
                            <with
                                  variable="selection">
                               <instanceof
                                     value="org.eclipse.jface.text.TextSelection">
                               </instanceof>
                            </with>
                            <with
                                  variable="activeEditorId">
                               <equals
                                     value="org.eclipse.jdt.ui.CompilationUnitEditor">
                               </equals>
                            </with>
                         </and>
                      </iterate>
                   </visibleWhen>
                </command>
             </menu>
          </menuContribution>
       </extension>
       <extension
             point="org.eclipse.ui.commands">
          <command
                id="com.test.plugin.project.command.packageexplorer"
                name="Only Show In Package Explorer">
          </command>
          <command
                id="com.test.plugin.project.command.classfile"
                name="Only Show In Class File">
          </command>
       </extension>
    
    </plugin>
    

    What this does

    • It creates one popup menu in a sub menu when you right click on a java file inside the package explorer (and only when you click on a java file).
    • It create a different popup menu in a sub menu when you right click on a java file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never come across this issue but most recently I noticed that a
I know that this kind of issue is most discussed. But I would like
I am having this most annoying issue when I try to rebuild my solution
I read past questions but I couldn't solve my issue :( This is my
Jquery Each Json Values Issue This question is similar to above, but not the
How can I ignore the attribute error I get when I issue this command?
The URL http://www.fourmilab.ch/cgi-bin/Earth shows a live map of the Earth. If I issue this
This issue has been on/off bugging me and I've written 4 wrappers now. I'm
This issue is better demonstrated than explained, so I've set up a git repo
This issue has me baffled, it's affecting a single user (to my knowledge) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.