[英]How to add toolbar to java text hover eclipse
I am tring to create my own text hover plugin for eclipse. 我正试图为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. 我读到我需要使用getHoverControlCreator函数,并设法添加了在运行插件时打开文本悬停时看到的工具栏管理器,在调试器中我可以看到ToolBarManger的ToolBar带有ToolItems,但是当我打开它时,我无法在真实文本悬停中看到它们。
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: 这是Eclipse悬停控件之一的作用:
@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
. 因此,它不会创建ToolBar
,而是保留它为DefaultInformationControl
。 It uses an Action
in the tool bar and adds it after creating the DefaultInformationControl. 它在工具栏中使用一个Action
,并在创建DefaultInformationControl之后将其添加。 It just calls update(true)
at the end. 它只是在最后调用update(true)
。
(This is a modified version of parts of org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover
) (这是org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover
的一部分的修改版)
MyAction
would be something like: MyAction
将类似于:
private class MyAction extends Action
{
MyAction()
{
super("Title", .. image descriptor ..);
setToolTipText("Tooltip");
}
@Override
public void run()
{
// TODO your code for the action
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.