使用Eclipse插件开发API在eclipse的工具栏上添加组合框 [英] Adding combo box on toolbar of eclipse using Eclipse plug-in development API
问题描述
我想使用Eclipse Plug-in开发API(而不是RCP应用程序)将eclipse的工具栏(coolbar)添加到组合框中。这个组合框项目应该被动态添加/删除。
I want to add a combo box to the toolbar (coolbar) of eclipse using Eclipse Plug-in development API (not an RCP application). This combo box items should be dynamically added/removed.
我知道在RCP应用程序中可以通过以下链接: http://www.thedeveloperspoint.com/?p=140
I know that in RCP applications it is possible by following the link : http://www.thedeveloperspoint.com/?p=140
但我正在看Eclipse插件API。
but I am looking at Eclipse plugin API.
任何帮助将不胜感激。
谢谢Syam
推荐答案
这可以通过使用两个步骤完成。
This can be done by using 2 steps.
步骤1:通过使用扩展点机制创建/添加工具栏到全局工具栏(使用locationURI为工具栏:org.eclipse.ui.main.toolbar)
STEP 1: By using extension point mechanism create/add toolbar to the global toolbar (using locationURI as "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如下。
STEP 2: Implement the ComboToolbarContribution as follows.
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;
} }
使用上述2个步骤,组合框将添加到全局工具栏并且用户需要提供对组合框的全局访问。
With the above 2 steps a combo box will be added to the global toolbar and user need to provide the global access to the combo box.
这篇关于使用Eclipse插件开发API在eclipse的工具栏上添加组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!