欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

org.eclipse.ui.trim.status显示不完整的问题

程序员文章站 2022-05-18 10:49:57
...

解决这个问题翻找了很多英文文档,但是发布以后文章被到处复制没有来源,表示十分气愤。

如需转载,请标明来源http://equalxx.iteye.com/

 

在右下角添加状态时配置的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配置如下

 

<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;
	}
}