eclipse rcp - Custom Perspective Switcher Toolbar: How can I dynamically update it? -
i'm trying implement custom perspective switcher toolbar replace eclipse's built-in one. couldn't toolbar display, , it shown me due a bug dynamic element in menu contribution, have use control element instead, described in the workaround dynamic bug.
i have toolbar displaying following approach, cannot figure out how update dynamically. workaround instruction call contributionitem#fill(coolbar, int)
workbenchcontrolcontributionitem
's update method instead of doing fill in createcontrol
method.
i don't know supposed call update
, never gets invoked no matter do. have perspective listener knows when update toolbar, listener's callback call fill(coolbar, int)
. wasn't sure how coolbar
pass method, created 1 on current shell.
the end result of toolbar displays correct number of items initially, when need add item, has no effect. call fill(coolbar, int)
, adds new item toolbar, i've tried make coolbar
, toolbar
update not work. when re-launch app, toolbar has added item.
i'm sure i'm doing wrong, can't figure out right way. here's elided representation of code (omitting methods, layout code, etc not related update problem).
public class perspectiveswitchertoolbar extends workbenchwindowcontrolcontribution implements iperspectivelistener { ... @override protected control createcontrol(composite parent) { this.parent = parent; iworkbenchpage page = platformui.getworkbench().getactiveworkbenchwindow().getactivepage(); page.getworkbenchwindow().addperspectivelistener(this); toolbarmanager = (toolbarmanager)parent.getparent().getdata(); ftopcontrol = new composite(parent, swt.border); fill(new coolbar(page.getworkbenchwindow().getshell(), swt.horizontal), -1); return ftopcontrol; } @override public void fill(coolbar coolbar, int index) { iperspectivedescriptor[] openperspectives = page.getopenperspectives(); string activeperspective = getperspectiveid(); toolbar toolbar = new toolbar(ftopcontrol, swt.none); for(iperspectivedescriptor descriptor : openperspectives) { toolitem item = new toolitem(toolbar, swt.radio); //overkill here, trying find way upate toolbar toolbar.update(); parent.update(); parent.layout(true); parent.getparent().update(); parent.getparent().layout(true); coolbar.layout(true); } //perspectivelistener callback @override public void perspectiveactivated(iworkbenchpage page, iperspectivedescriptor perspective) { fill(new coolbar(page.getworkbenchwindow().getshell(), swt.horizontal), -1); if (page.getworkbenchwindow() instanceof workbenchwindow){ //this non-api call doesn't either ((workbenchwindow) page.getworkbenchwindow()).updateactionbars(); } } ... }
Comments
Post a Comment