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 4382072
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:43:55+00:00 2026-05-21T12:43:55+00:00

I am trying configure visibility of a command within the context menu using ‘visibleWhen’

  • 0

I am trying configure visibility of a command within the context menu using ‘visibleWhen’ expression within a menuContribution. What I am trying to do is make the command visible in the context menu only if you:

  1. Right-click certain file types(resources) in the resource view (or package view)
  2. Right-click the appropriate editor that has the file type open. It can detect that my editor is open or that the editor has a certain resource open.

I’ve accomplished the first using ‘visibleWhen’>’selection(with)’>’iterate’>’org.eclipse.core.resources.IResource(adapt)’ then checking the file extension for the resource. The code is listed below. However, I’m not sure how to get the same command to only appear when you right-click the correct editor that has a file open with the correct extensions – ext1, ext2.

Checking if my editor is active resolves the second issue but doesn’t seem to help since if I click on files that are not my type, it will still show the command in the context menu.

Any recommendations?
The “Eclipse Plug-ins (3rd Edition)” shows some example for editor context menu but it uses actions and I want to stick with commands.

Thanks!!


  <menuContribution
        allPopups="false"
        locationURI="popup:org.eclipse.ui.popup.any?before=additions">
     <separator
           name="com.test.ide.separator1"
           visible="true">
     </separator>
     <menu
           icon="icons/sample.gif"
           label="Test Menu">
        <command
              commandId="com.test.commands.testCommand1"
              icon="icons/sample.gif"
              label="testCommand1"
              style="push"
              tooltip="This is a test command">
           <visibleWhen
                 checkEnabled="false">
              <with
                    variable="selection">
                 <iterate
                       ifEmpty="false"
                       operator="or">
                    <adapt
                          type="org.eclipse.core.resources.IResource">
                       <or>
                          <test
                                property="org.eclipse.core.resources.extension"
                                value="ext1">
                          </test>
                          <test
                                property="org.eclipse.core.resources.extension"
                                value="ext2">
                          </test>
                       </or>
                    </adapt>
                 </iterate>
              </with>
           </visibleWhen>
        </command>
     </menu>
  </menuContribution>
  • 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-05-21T12:43:56+00:00Added an answer on May 21, 2026 at 12:43 pm

    I was able to get it done with a with variable that I came across. Using the same code example above:

    • Add an <or> block within the <iterate> block
    • Place the existing <adapt> block in the new <or> block
    • Add a new with variable called activeEditorInput

    Here is the new code example.

    <iterate ifEmpty="false" operator="or">
      <or>
        <adapt type="org.eclipse.core.resources.IResource">
          <or>
            ...test extensions
          </or>
        </adapt>
        <with variable="activeEditorInput">
          <adapt type="org.eclipse.core.resources.IResource">
            <or>
              ...test extensions
            </or>
          </adapt>
        </with>
      </or>
    </iterate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to configure the Quick Launch menu to only display the ancestors and
I'm trying to configure an installer for some software we use within the company.
I am trying to configure a network connection using ConfigurationManager.ProcessConfiguration, with the configuration file
I am trying to configure SSL on my localhost using apache and phusion passenger.
I am trying to configure Spring3 + JPA using Hibernate, but I am getting
I am trying to configure an application for my client and I am using
I am trying to configure Entity Framework 4 in the Web.config file using this
I'm trying to configure a dedicated server that runs ASP.NET to send mail through
I'm trying to configure Windows Powershell to work with Visual Studio. Nothing fancy, just
I'm trying to configure NAnt to automate my build process - once I've got

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.