plugins - How to update a drop down list of a pull down button in the Eclipse toolbar? -
i have added drop down list dynamically pull down button in eclipse toolbar, following instructions: programmatically add options pulldown button in eclipse
now, need update drop down list. idea remove old list , add new list pull down button. tried methods: removecontributionfactory(abstractcontributionfactory factory) , dispose() of imenuservice, none of them works. give me tips of how achieve goal?
here code used:
(1) in class a, invoke method add drop down list pull down button (command)
class { public static contextswitchcontributionfactory contextfactory = new contextswitchcontributionfactory("menu:"+"switchcontext", null); public static imenuservice menuservice = (imenuservice)platformui.getworkbench().getservice(imenuservice.class); ... method () { ... contextswitchcontributionfactory.updatecontextmenu(menuservice, contextfactory, "switchcontext"); ... }
(2) definition of contextswitchcontributionfactory:
public class contextswitchcontributionfactory extends abstractcontributionfactory { private contextdata contextdata = new contextdata(); private contextscollector contextlist; } static public void updatecontextmenu (imenuservice service, final abstractcontributionfactory factory, final string menuid) { service.dispose(); service.addcontributionfactory(factory); } public contextswitchcontributionfactory(string location, string namespace) { super(location, namespace); // read file , update data creating drop down list contextdata.readcontextsfile(); contextlist = contextdata.getcontextscollector(); } @override public void createcontributionitems(iservicelocator servicelocator, icontributionroot additions) { set<icontext> cxtset = contextlist.getcontextlist(); iterator<icontext> iterator = cxtset.iterator(); while (iterator.hasnext()) { icontext context = iterator.next(); commandcontributionitemparameter menuitem = new commandcontributionitemparameter( servicelocator, null, "coms.sample.command.context", commandcontributionitem.style_push); menuitem.label = context.getname(); menuitem.visibleenabled = true; if (context.isselected()) { imagedescriptor image = mechanicplugin.getimagedescriptor("icons/ticking_icon.png"); menuitem.icon = image; } additions.addcontributionitem(new commandcontributionitem(menuitem), null); } } }
(3) in method c of class c, want update drop down list:
class c { ... method c { ... // a.menuservice.dispose(); (doesn't work) // remove old 1 a.menuservice.removecontributionfactory(a.contextfactory); // create new 1 a.contextfactory = new contextswitchcontributionfactory("menu:"+"switchcontext", null); // after executing statement, old drop down list still there, , new 1 added after old list. a.menuservice.addcontributionfactory(a.contextfactory); contextswitchcontributionfactory.updatecontextmenu(menuservice, contextfactory, "switchcontext"); ..
i think have found answer, method used, nature, drop down list cannot updated. add drop down list can refreshed, dynamic elements should used: static , dynamic pulldown menus
Comments
Post a Comment