我想使用eclipse插件开发API (而不是RCP应用程序)向Eclipse的工具栏(coolbar)添加一个组合框。此组合框项应动态添加/删除。
我知道在RCP应用程序中,可以通过以下链接实现:http://www.thedeveloperspoint.com/?p=140
但我关注的是Eclipse插件API。
任何帮助都将不胜感激。
谢谢
Syam
发布于 2012-04-26 18:14:43
这可以通过使用两个步骤来完成。
步骤1:使用扩展点机制创建工具栏/将工具栏添加到全局工具栏(使用locationURI作为"toolbar:org.eclipse.ui.main.toolbar")
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.company.module.toolbar"
label="Sample">
<control
class="com.company.module.ui.ComboToolbarContribution"
id="ratata">
</control>
</toolbar>
</menuContribution>
</extension>
第2步:按如下方式实现ComboToolbarContribution。
package com.company.module.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
public class ComboToolbarContribution extends
WorkbenchWindowControlContribution {
private Combo mReader;
public ComboToolbarContribution() {
}
@Override
protected Control createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
GridLayout glContainer = new GridLayout(1, false);
glContainer.marginTop = -1;
glContainer.marginHeight = 0;
glContainer.marginWidth = 0;
container.setLayout(glContainer);
GridData glReader = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
glReader.widthHint = 280;
mReader = new Combo(container, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN);
mReader.setLayoutData(glReader);
return container;
}
@Override
protected int computeWidth(Control control) {
return 300;
} }
通过以上两个步骤,将向全局工具栏添加一个组合框,并且用户需要提供对该组合框的全局访问。
发布于 2016-10-25 17:29:32
为了避免头痛..如果有人面临这样的问题,eclipse只能绘制7px高度的控件,我想指出一个解决方法:
https://www.eclipse.org/forums/index.php/t/1076367/
向同一工具栏(即com.company.module.toolbar)添加另一个带有图标的贡献包,以保留足够的空间。
发布于 2018-05-24 21:06:15
正如@Jonny上面提到的,可能需要预留一些空间。
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="new">
<control
class="org.xy.composite.NewComposite"
id="org.xy.composite.newcomposite.id">
</control>
<command
commandId="newcomposite"
icon="resources/nothing.png"
label="nix"/>
</toolbar>
</menuContribution>
有了command
,这一切都成为可能
https://stackoverflow.com/questions/8971517
复制相似问题