在右下角添加状态时配置的control继承的类是WorkbenchWindowControlContribution,按正常步骤在createControl后发现只能调整横向大小,不能调整竖向,每次都是显示一部分,很奇怪。查了很多资料,包括eclipse登记的bug网址:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=466609#c21
https://bugs.eclipse.org/bugs/show_bug.cgi?id=186800
https://bugs.eclipse.org/bugs/show_bug.cgi?id=471313
里面都有详细的对话描述问题,总之就是这个toolItem被固定了大小,且用户不可改变。
最后其实解决办法很简单,在createControl中添加parent.getParent().setRedraw(true);以及isDynamic
?
plugin.xml配置如下
?
class="xml"><menuContribution locationURI=" toolbar:org.eclipse.ui.trim.status"> <toolbar id="test.trim.status.toolbar"> <control class="xxxxxxxx.ExampleControlContribution" id="xxxxxxxxx.ExampleControlContribution"> </control> </toolbar> </menuContribution>
?
?
类中代码如下
import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.menus.WorkbenchWindowControlContribution; public class ExampleControlContribution extends WorkbenchWindowControlContribution { // Image imgOnLine = SignInConstants.online.createImage(); // Image imgOffLine = SignInConstants.offline.createImage(); // Image imgMessage = SignInConstants.message.createImage(); WorkbenchWindowControlContribution contribution; public ExampleControlContribution() { super(); contribution = this; } protected Control createControl(Composite parent) { parent.getParent().setRedraw(true); GridLayout gridLayout = new GridLayout(1, false); gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; gridLayout.marginLeft = 0; gridLayout.marginHeight = 0; gridLayout.marginTop = 0; gridLayout.numColumns = 1; parent.setLayout(gridLayout); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); data.heightHint = 20; Button ccCtrl = new Button(parent, SWT.CENTER); // ccCtrl.setImage(imgOnLine); ccCtrl.setText("已登录"); ccCtrl.setToolTipText("已登录"); ccCtrl.setLayoutData(data); return parent; } @Override public boolean isDynamic() { return true; } }
?
?
网友 2017/1/12 9:30:01 发表
请尊重作者,转载标明来源http://equalxx.iteye.com/blog/2311543