[英]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.