繁体   English   中英

为什么添加项目会弄乱Eclipse 3.2插件中的工具栏?

[英]Why does adding an item messes up toolbar in an Eclipse 3.2 Plugin?

我正在为将按钮添加到Eclipse插件的工具栏进行一项增强。 该技术是相当古老的。 我正在使用IBM Rational Application Developer 7.0.10。 这是我所看到的版本

JDK 1.5
Eclipse Platform 3.2.2
Eclipse Plugin Development 3.2.1
Eclipse RCP 3.2.2

当我的代码向工具栏添加新按钮时,它使工具栏变得混乱。 它仅显示一些按钮,而隐藏其余按钮。 但是当我调整视图的大小时,即使只有一点点,所有按钮都会显示。 屏幕面积似乎不大,因为放大视图无济于事。 我是Eclipse插件开发的新手,所以我不确定是什么原因造成的。 我似乎在做添加按钮所需的操作。 我尝试了不同的操作,例如insertBefore而不是add等。 但是似乎没有什么帮助。

我编写了一些测试代码(使用Eclipse附带的示例插件)来隔离问题,但是我没有成功。 我给了2类的代码。

// This class is generated from Elipse, to which I have added code
public class MenuBarTestView extends ViewPart {

    // Instance variables ...

   public void createPartControl(Composite parent) {
       viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
       drillDownAdapter = new DrillDownAdapter(viewer);
       viewer.setContentProvider(new ViewContentProvider());
       viewer.setLabelProvider(new ViewLabelProvider());
       viewer.setSorter(new NameSorter());
       viewer.setInput(getViewSite());

       // Selection change listener, which adds a button to tool bar
       // I added the following line
       viewer.addSelectionChangedListener(new TreeSelectionChangedListener(this));

       makeActions();
       hookContextMenu();
       hookDoubleClickAction();
       contributeToActionBars();
   }

   .
   .  // Other Eclipse generated code for the sample plugin goes here
   .
   .

   // I added this method to add a button
   public void addButton () {

       IActionBars bars = getViewSite().getActionBars();
       IToolBarManager tbm = bars.getToolBarManager();

       Action action = new Action() {
          public void run() {
              showMessage("Action 1 executed");
          }
      };
      action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
            getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER));
      tbm.add(action);
      tbm.update(false);

   }
}

我为选择更改事件编写了以下课程

package menubartest.views;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

public class TreeSelectionChangedListener implements ISelectionChangedListener {

    private MenuBarTestView view;

    public TreeSelectionChangedListener(MenuBarTestView view) {
        super();
        this.view = view;
    }

    public void selectionChanged(SelectionChangedEvent event) {
        // TODO Auto-generated method stub
        view.addButton();
    }
}

当应用程序启动时

这是应用程序首次出现的时间

这是在树上的选择

在此处输入图片说明

在经过如此微小的调整之后

在此处输入图片说明

有人可以帮忙吗?

看起来您需要在添加到工具栏后调用IActionBars.updateActionBars()方法。

看来这是Eclipse 3.2(或至少与RAD 7.0捆绑在一起的版本)的一个错误。 我在Eclipse 3.7上尝试了此操作,但未发现问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM