根据 Tonny Madsen 给出的关于 Presentation API 的提示,我想出了一个解决我的问题的方法。我的解决方案基于以下文章:
为了使我的解决方案有效,我最终对两个文件和一个新类进行了更改:
在 plugin.xml 文件中,我添加了以下扩展名:
<extension point="org.eclipse.ui.presentationFactories">
<factory
name="Extended Presentation Factory"
class="org.eclipse.minicrm.ui.swt.custom.ExtendedPresentationFactory"
id="org.eclipse.minicrm.ui.swt.custom.ExtendedPresentationFactory"
/>
</extension>
Eclipse 4.x 似乎忽略了这一点,因此为了满足这些情况,我在 plugin_customisation.ini 文件中添加了以下行:
org.eclipse.ui/presentationFactoryId = org.eclipse.minicrm.ui.swt.custom.ExtendedPresentationFactory
然后我创建了相应的类:
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
@SuppressWarnings("restriction")
public class ExtendedPresentationFactory extends WorkbenchPresentationFactory {
private ToolBarManager m_toolBarManager = null;
private ToolBar m_toolbar = null;
@Override
public StackPresentation createEditorPresentation(final Composite parent, final IStackPresentationSite site) {
final TabbedStackPresentation presentation = (TabbedStackPresentation) super.createViewPresentation(parent, site);
m_toolbar = new ToolBar(presentation.getTabFolder().getToolbarParent(), 0);
m_toolBarManager = new ToolBarManager(m_toolbar);
m_toolBarManager.add(new MyAction1());
m_toolBarManager.add(new MyAction2());
m_toolBarManager.add(new MyAction3());
m_toolBarManager.update(true);
presentation.getTabFolder().setToolbar(m_toolbar);
return presentation;
}
}
这会在我的编辑器区域中添加一个带有三个按钮的工具栏。
我仍然需要摆弄一些更精细的点(放置等),但首先它满足了我对编辑器区域中工具栏的需求。