Usage of IAdapterFactory with popupMenus in eclipse rcp -


my requirement add new menu entry “compare with” present in 1 of 3rd party views. using “org.eclipse.ui.popupmenus” add menu entry above contribution. forced use same extension point though deprecated. able add menu entry contribution below code

<extension point="org.eclipse.ui.popupmenus">          <objectcontribution                adaptable="true"                id="test.id"                objectclass="local.change">         <action               class="compare.commparetool"               enablesfor="1"               id="id"               label="compare "               menubarpath="comparewith/group1">          </action>         <visibility>            <objectstate                  name="local.change"                  value=".txt">            </objectstate>         </visibility> </extension> 

the above configuration working fine. next requirement add property tester hide menu entries whenever file selected other .txt file. cannot add property tester object contribution, have used iadapterfactory. below code not working.

observation: have added many menu entries (“org.eclipse.ui.menus”) in different views in “compare with” not related this. if user clicks on of these commands, , try view in question, working expected expected.

below code. missing anything. need register adapters in other place also??

<extension point="org.eclipse.core.runtime.adapters">       <factory             adaptabletype="local.change"             class="localchangeadapterfactory">          <adapter                type="org.eclipse.ui.iactionfilter">          </adapter>       </factory> </extension> 
public class localchangeadapterfactory implements iadapterfactory {   @suppresswarnings("unchecked")   @override   public object getadapter(final object adaptableobject, final class adaptertype)   {     if (adaptertype == iactionfilter.class)     {       return localchangeactionfilter.getinstance();     }     return null;   }    @suppresswarnings("unchecked")   @override   public class[] getadapterlist()   {         return new class[] { localchangeactionfilter.class };   } }  public class localchangeactionfilter implements iactionfilter {    private static localchangeactionfilter instance = new localchangeactionfilter();    private localchangeactionfilter()   {   }    @override   public boolean testattribute(final object target, final string name, final string value)   {     string filename = "";     if(target.getid==1){           return true;     }else{     return false;    }    public static localchangeactionfilter getinstance()   {     return instance;   } } 

the adaptabletype attribute of adapter factory should specify type of existing object want adapt iactionfilter. resource of file:

   adaptabletype="org.eclipse.core.resources.iresource"> 

the getadapter method of iactionfactory should return class matching adapter attribute, not implementing class:

public class[] getadapterlist() {       return new class[] { iactionfilter.class }; } 

your testattribute method if action filter must test name parameter matches value in objectstate:

@override public boolean testattribute(final object target, final string name, final string value) {    if (name.equals("local.change"))     {       .... test        return true;     }    return false;  } 

Comments