如何将工具栏添加到Java文本悬停日食 [英] How to add toolbar to java text hover eclipse

查看:149
本文介绍了如何将工具栏添加到Java文本悬停日食的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算为eclipse创建自己的文本悬停插件。
我成功地在自己的悬停中编写自己的代码,但我尝试添加一个工具栏到悬停(在打开的新工具提示中)。
我读到需要使用getHoverControlCreator函数,并且我设法添加了我在运行插件时打开文本悬停时看到的工具栏管理器,在debbuger中我可以看到ToolBarManger具有ToolBar有ToolItems,但当我打开它时,我无法在真正的文本悬停中看到它们。



这是我的代码:



$ pre $ public $ I $ B $ $ $ $ public IInformationControl createInformationControl(Shell parent){
ToolBar tb =新的ToolBar(父,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;


解决方案

这就是其中之一Eclipse的悬停控件确实如下:

$ $ $ $ $ $ $ $ $ $ b $ public IInformationControl doCreateInformationControl(Shell父类){
ToolBarManager tbm =新的ToolBarManager(SWT.FLAT);

DefaultInformationControl iControl = new DefaultInformationControl(parent,tbm);

IAction action = new MyAction();
tbm.add(action);

tbm.update(true);

返回iControl;

$ / code>

所以它不会创建 ToolBar - 将其保留至 DefaultInformationControl 。它在工具栏中使用 Action 并在创建DefaultInformationControl之后添加它。它只是在最后调用 update(true)



(这是 org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover



MyAction 类似于:

  private class MyAction extends Action 
{
MyAction()
{
super(Title,..图像描述符..);

setToolTipText(Tooltip);
}

@Override
public void run()
{
// TODO您的代码用于操作
}
}


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

这篇关于如何将工具栏添加到Java文本悬停日食的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆