我创建了一个ToolItem"另存为"像上面的图像,但它不显示在工具栏位置。那么如何在viewpart中创建一个工具栏(不使用plugin.xml)
这是我的代码创建工具栏:
public void createToolbar(Composite parent) {
// Create composite Toolbar and set layout
toolBarComposite = new Composite(parent, SWT.NONE);
gridLayout = new GridLayout(1, false);
toolBarComposite.setLayout(gridLayout);
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBarComposite.setLayoutData(gridData);
// Create Toolbar
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBar = new ToolBar(toolBarComposite, SWT.FLAT);
toolBar.setLayoutData(gridData);
// Create Item
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(SAVE_IMAGE);
item.setToolTipText("Save (Ctrl + S)");
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = -102212312093090431L;
@Override
public void widgetSelected(SelectionEvent e) {
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
感谢您的进步!
答案 0 :(得分:1)
您将不得不在视图网站的操作栏上使用贡献。
实施例
// Copy-pasted from an existing project, so the code can be made nicer
private void createAdditionalToolbarActions()
{
getViewSite().getActionBars().getToolBarManager().add(new GroupMarker("additions")); //$NON-NLS-1$
getViewSite().getActionBars().getToolBarManager().prependToGroup("additions", new SaveAction()); //$NON-NLS-1$
getViewSite().getActionBars().updateActionBars();
}
方法getViewSite
是ViewPart
的一部分。在创建视图的内容后调用此方法。
SaveAction
必须实施IAction
或IContributionItem
。为方便起见,只需从SaveAction
扩展org.eclipse.jface.action.Action
并调用setImageDescriptor
和setToolTipText
等方法。
让您的所有商家登录run
覆盖。