简体   繁体   English

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

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

I am working on an enhancement to add buttons to a toolbar for an Eclipse plugin. 我正在为将按钮添加到Eclipse插件的工具栏进行一项增强。 The technology is fairly old. 该技术是相当古老的。 I am using IBM Rational Application Developer 7.0.10. 我正在使用IBM Rational Application Developer 7.0.10。 Here is what I see as far as the versions 这是我所看到的版本

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

When my code adds a new button to the toolbar, it messes up the toolbar. 当我的代码向工具栏添加新按钮时,它使工具栏变得混乱。 It only shows some of the buttons and hides the rest. 它仅显示一些按钮,而隐藏其余按钮。 But when I resize the view even the slightest bit, all the buttons show. 但是当我调整视图的大小时,即使只有一点点,所有按钮都会显示。 It does not appear to be a case of screen real estate as making the view larger does not help. 屏幕面积似乎不大,因为放大视图无济于事。 I am new to Eclipse plug-in development, so I am not sure what is causing this. 我是Eclipse插件开发的新手,所以我不确定是什么原因造成的。 I seem to be doing what is needed to add a button. 我似乎在做添加按钮所需的操作。 I have tried different things, like insertBefore instead of add and so on. 我尝试了不同的操作,例如insertBefore而不是add等。 But nothing seems to help. 但是似乎没有什么帮助。

I wrote some test code (using the sample plugins that come with Eclipse) to isolate the issue, but I have not had success. 我编写了一些测试代码(使用Eclipse附带的示例插件)来隔离问题,但是我没有成功。 I have given the code for 2 classes. 我给了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);

   }
}

I wrote the following class for the selection change event 我为选择更改事件编写了以下课程

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

When the application comes up 当应用程序启动时

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

This is upon a selection on the Tree 这是在树上的选择

在此处输入图片说明

This is after an ever so slight resize 在经过如此微小的调整之后

在此处输入图片说明

Can anyone help? 有人可以帮忙吗?

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

It would appear that this is a bug with Eclipse 3.2 (or at least the version bundled with RAD 7.0). 看来这是Eclipse 3.2(或至少与RAD 7.0捆绑在一起的版本)的一个错误。 I tried this with Eclipse 3.7 and did not see the problem. 我在Eclipse 3.7上尝试了此操作,但未发现问题。

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

相关问题 为什么我的Eclipse插件显示在Eclipse RCP版本中,而不显示在Java和Java EE等其他版本中? - Why does my Eclipse plugin show up in Eclipse RCP version, but not in other versions like Java and Java EE? 将可调整大小的文本添加到Eclipse工具栏 - Adding a resizable Text to Eclipse toolbar 通过plugin.xml将工具栏添加到org.eclipse.ui.forms.widgets.Section - Adding toolbar to org.eclipse.ui.forms.widgets.Section via plugin.xml 如果和for for Eclipse插件的Eclipse插件? - Eclipse plugin to roll up if and for? 如何将JavaDoc DocCheck设置为Eclipse插件? - How does one set up JavaDoc DocCheck as an Eclipse plugin? 将ScrollView添加到布局中会弄乱预览 - Adding ScrollView to my layout messes up my preview 为什么Eclipse 3.2在启动时抛出错误 - Why is Eclipse 3.2 throwing an error on startup 为什么Cobertura在运行Eclipse插件时报告0%的覆盖率? - Why does Cobertura report 0% coverage when run through the Eclipse plugin? 为什么Eclipse的Google Cloud Tools插件会显示“未找到项目”? - Why does Google Cloud Tools Plugin for Eclipse say “No Projects Found”? 为什么我的Eclipse插件启动可以在一个工作空间中正常运行,而不能在另一个工作空间中正常运行? - Why does my Eclipse plugin startup fine in one workspace, but not in another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM