I have added a control to eclipse as below
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="my.toolbar">
<control
class="myplugin.debugger.toolbaritem.DebugDayMenu"
id="my.yearmenu">
</control>
I also created a class DebugDayMenu
public class DebugDayMenu extends WorkbenchWindowControlContribution{...
I now want to access this control in another place but when I try to do so using this code below, it results in a class cast exception
IContributionItem toolbar = coolBarManager.find("my.toolbar");
IToolBarManager toolbarManager=((ToolBarContributionItem2)toolbar).getToolBarManager();
Workbenc开发者_C百科hWindowControlContribution dayMenu= (WorkbenchWindowControlContribution) toolbarManager.find("my.yearmenu");
dayMenu is instanceof DynamicToolBarContributionItem and NOT WorkbenchWindowControlContribution ? Furthermore the control is embedded in a private field in DynamicToolBarContributionItem with no public accessor method
Is there a better way to do this or am I misunderstanding something?
Normally, you would solve this in createControl()
method of your contribution either by accessing necessary information or by adding itself as a listener of some sort.
精彩评论