1

通过将以下块添加到 org.eclipse.ui.menus 扩展点,我成功地将特定于视图的工具栏添加到我的 RCP 应用程序:

  <menuContribution
        allPopups="false"
        locationURI="toolbar:my.package.path.views.ClassOfMyView">
     <dynamic
           class="my.package.path.toolbars.ViewToolBar"
           id="MyViewToolbar">
     </dynamic>
  </menuContribution>

但是,尝试对我的编辑器部分执行相同操作似乎不起作用:

  <menuContribution
        allPopups="false"
        locationURI="toolbar:my.package.path.views.ClassOfMyEditorPart">
     <dynamic
           class="my.package.path.toolbars.EditorPartToolBar"
           id="MyEditorpartToolbar">
     </dynamic>
  </menuContribution>

是否有明显的我遗漏的东西,或者这在 RCP 中根本不支持?

4

2 回答 2

4

根据 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;
  }
}

这会在我的编辑器区域中添加一个带有三个按钮的工具栏。

我仍然需要摆弄一些更精细的点(放置等),但首先它满足了我对编辑器区域中工具栏的需求。

于 2013-04-16T08:28:57.890 回答
3

这些是编辑器和视图之间的一些重要的视觉差异:

  • 编辑器为顶级菜单和工具栏提供额外的操作;意见不*
  • 视图有独立的菜单栏和工具栏;编辑不
  • 在一个透视图中最多有一个活动编辑器;可以有任意数量的活动视图
  • 每个“类型”最多有一个视图;可以有任意数量的编辑器*
  • 编辑器全部放置在“编辑器区”;视图被放置在许多“视图堆栈”中</li>

可以使用 RCP 平台的各种功能消除其中一些差异(上面标有 *):

  • 该界面ISaveblePart可以为视图提供与编辑器相同的生命周期。
  • menues视图处于活动状态时,扩展点可以将项目添加到主菜单和工具栏。
  • views扩展点可用于允许同一类型的多个视图。

使用 Eclipse 4,您还可以在同一个堆栈或文件夹中组合编辑器和视图。

但是添加视图中的菜单或工具栏需要更多的工作!但它可以使用 Presentation API 来完成,其中大部分视觉差异都可以消除。

另一条评论:不是 toolbar:my.package.path.views.ClassOfMyView但是toolbar:id-of-the-view

于 2013-04-11T18:17:53.767 回答