java - RCP: How to sync state of MMenuItem and MToolItem -


i have handler linked both menu item , toolbar icon. if menu item selected, checkmark appear left of menu item. if toolbar button pressed in icon changes 'sunken' it's pushed in.

if menu item checkmarked 'auto-push' toolbar button in (without firing toolbar button-pressed event).

if button pressed in menu item 'auto-checkmark'

is there way this? assume start here..;

@execute public void execute(     @named(iserviceconstants.active_shell) shell shell,      @optional mtoolitem toolitem,      @optional mmenuitem menuitem) {    // menu triggered coming method   if (menuitem != null ) {      if(menuitem.isselected()){     ...     }   }    // button triggered coming method   if (toolitem != null ) {      if(toolitem.isselected()){     ...     }   }  } 

you need both mtoolitem , mmenuitem before first execution. can find mtoolitem via emodelservice in @postconstruct method.

private mmenuitem menuitem; private mtoolitem toolitem;  @postconstruct protected void initcontrols(mapplication app) {     settoolitem((mtoolitem) modelservice.find("tool.item.id", app)); } 

as menu item, cannot found in such way via emodelservice (in eclipse 4.3 kepler, not sure luna). how in same @postconstruct method:

... muielement window = modelservice.find("main.window.id", app); setmenuitem((mhandledmenuitem) findmenuelement("menu.item.id", window)); ...  public static mmenuelement findmenuelement(string id, muielement searchroot) {     if (id == null) {         throw new illegalargumentexception("id null!");     }      if (id.length() == 0) {         throw new illegalargumentexception("empty string not allowed in id.");     }      if (searchroot instanceof mmenuelement && id.equals(searchroot.getelementid()))     {         return (mmenuelement) searchroot;     }      if (searchroot instanceof mtrimmedwindow)     {         mmenuelement findmenu = findmenuelement(id, ((mtrimmedwindow) searchroot).getmainmenu());         if (findmenu != null)         {             return findmenu;         }     }     else if (searchroot instanceof mpart)     {         list<mmenu> menus = ((mpart) searchroot).getmenus();         (mmenu mm : menus)         {             mmenuelement findmenu = findmenuelement(id, mm);             if (findmenu != null)             {                 return findmenu;             }         }     }     else if (searchroot instanceof mmenu)     {         list<mmenuelement> children = ((mmenu) searchroot).getchildren();         (mmenuelement me : children)         {             mmenuelement findmenu = findmenuelement(id, me);             if (findmenu != null)             {                 return findmenu;             }         }     }     return null; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -