用日食如何导入java项目,如何将工具栏添加到Java文本悬停日食

I am tring to create my own text hover plugin for eclipse.

I success to write my own code in my hover, but I try to add a toolbar to the hover (inside the new tooltip opened).

I read that I need to use the getHoverControlCreator function, and I managed to add the toolbar manager that I see when the text hover is opened while running the plugin,in the debbuger I can see that the ToolBarManger has the ToolBar that has the ToolItems, but I can't see them in the real text hover when I opened it.

this is my code:

public IInformationControlCreator getHoverControlCreator() {

return new IInformationControlCreator() {

public IInformationControl createInformationControl(Shell parent) {

ToolBar tb = new ToolBar(parent, SWT.HORIZONTAL);

ToolBarManager tbm = new ToolBarManager(tb);

DefaultInformationControl dic = new DefaultInformationControl(parent, tbm);

ToolItem ti = new ToolItem(tb, SWT.PUSH);

ti.setText("hello");

tb.update();

tb.redraw();

tbm.update(true);

parent.update();

parent.redraw();

parent.layout();

return dic;

}

解决方案

This is what one of the Eclipse hover controls does:

@Override

public IInformationControl doCreateInformationControl(Shell parent) {

ToolBarManager tbm = new ToolBarManager(SWT.FLAT);

DefaultInformationControl iControl = new DefaultInformationControl(parent, tbm);

IAction action = new MyAction();

tbm.add(action);

tbm.update(true);

return iControl;

}

So it does not create the ToolBar - leave that up to DefaultInformationControl. It uses an Action in the tool bar and adds it after creating the DefaultInformationControl. It just calls update(true) at the end.

(This is a modified version of parts of org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover)

MyAction would be something like:

private class MyAction extends Action

{

MyAction()

{

super("Title", .. image descriptor ..);

setToolTipText("Tooltip");

}

@Override

public void run()

{

// TODO your code for the action

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值