1

I have created an eclipse plugin project. I want this plugin to be available as a popup. Therefore I have created an extension point with "org.eclipse.ui.popupMenus" (I know it is deprecated now, ours is an old project.)

I want this popup option to appear only at the file level with certain extension (say xml). Currently, it is appearing anywhere on right click.

I have looked around the internet and got to know that I can add a "visibility" tag that can set rules where this popup should be visible. However, I do not know the syntax for that.

Can someone please help me out? How to set the visibility of the popup menu so that it is visible only when I right click ON the filename with extension xml?

    <?xml version="1.0" encoding="UTF-8"?>
    <?eclipse version="3.2"?>
    <plugin>
       <extension point="org.eclipse.ui.popupMenus">
          <objectContribution
                adaptable="true"
                objectClass="org.eclipse.core.resources.IFile"
                nameFilter="*.*"
                id="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.contribution.IFile">
             <menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model Code Generator" path="additionsAcceleo">
                   <groupMarker name="acceleo"/> 
             </menu>
             <action
                   class="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.AcceleoGenerateCodegeneratorAction"
                   enablesFor="+"
                   id="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.AcceleoGenerateCodegeneratorAction"
                   icon="icons/default.gif"
                   label="Generate Java Code from Model"
                   menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
                   <visibility>
                              //what should come here?

                   </visibility>
          </objectContribution>
       </extension>
    </plugin>

(http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_popupMenus.html)

Regards, Yash

1 Answers1

2

visibility can only be a child of objectContribution not action.

In any case you can use the namefilter attribute to restrict the file name matching. You would only use visiblity to do more complex checks.

For example this is one of the JDT items:

 <objectContribution
        adaptable="true"
        objectClass="org.eclipse.core.resources.IFile"
        nameFilter="*.xml"
        id="org.eclipse.jdt.internal.ui.javadocexport.JavadocWizard">
     <visibility>
        <objectState name="contentTypeId" value="org.eclipse.ant.core.antBuildFile"/>
     </visibility>

In this

adaptable="true"
objectClass="org.eclipse.core.resources.IFile"

restricts the actions to a workspace file

nameFilter="*.xml"

restricts the actions to files ending in .xml

     <visibility>
        <objectState name="contentTypeId" value="org.eclipse.ant.core.antBuildFile"/>
     </visibility>

further restricts the actions to files with a 'content type' of 'Ant build file'

To match multiple name patterns remove the nameFilter and use a visibility like:

<visibility>
  <or>
        <objectState name="name" value="*.xml"/>
        <objectState name="name" value="*.java"/>
  </or>
</visibility>
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thank you for the answer greg. Additional question. If I want to set more than one value for nameFilter. what's the way to do that? nameFilter="*.xml, *.java" does not work. addding two nameFilter also does not work. – Yash Khatri Nov 30 '17 at 15:29
  • nameFilter accepts exactly one pattern. This is XML, you can't specify the nameFilter attribute twice. Instead remove the `nameFilter` and use the visibility - see updated answer. – greg-449 Nov 30 '17 at 15:41