简体   繁体   English

在Eclipse E4中设置固定的零件尺寸

[英]Set fixed part size in Eclipse E4

I have an application that I am building in in e4 but am having trouble getting a couple parts to be a fixed size. 我有一个要在e4中构建的应用程序,但无法将几个零件固定为固定大小。 I have a PartSashContainer with two Parts and another PartSashContainer in it. 我有一个PartSashContainer其中包含两个Parts和另一个PartSashContainer I initially set size in the containerData parameter, but these values are relative and still allow for re-sizing of the parts. 我最初在containerData参数中设置了大小,但是这些值是相对的,仍然允许重新调整零件的大小。 I want to make sure these parts are a fixed height and can not be re-sized. 我要确保这些零件的高度固定,并且无法调整大小。 Is there an easy way of doing this? 有一个简单的方法吗?

来自Application.e4xmi的列表视图

Eclipse bug 361731 is a request for this feature. Eclipse bug 361731是对此功能的请求。 Currently it has not been implemented. 目前尚未实施。

It might be possible to do with a custom renderer, but this is hard work. 可能可以使用自定义渲染器,但这是一项艰巨的工作。

我不确定在Neon之前是否可以使用此功能,但是Eclipse Neon允许您将“ NoMove”作为标签添加到要锁定且不调整大小的Part Sash Container框格Part Sash Container中。


I had a very similar task and stumbled across your question several times. 我有一个非常相似的任务,几次偶然发现了您的问题。 I need to implement a RCP application, following a Corporate Design with a fixed size application header and a fixed size footer. 我需要按照带有固定大小的应用程序标头和固定大小的页脚的企业设计来实现RCP应用程序。 I found no perfect way, but the vogella tutorial on custom renderers gave me some hints. 我没有找到完美的方法,但是有关自定义渲染器Vogella教程给了我一些提示。 I still had to duplicate some code, I didn't find a clever way around. 我仍然必须重复一些代码,但找不到聪明的方法。

My requirements: 我的要求:

  • Application Header on top with fixed height, no controls above the header 应用程序标头位于顶部,高度固定,标头上方没有控件
  • Application Header on top with fixed size, no controls above the header 应用程序标题位于顶部,具有固定大小,标题上方没有控件
  • Application Footer at the bottom, again with a fixed height 底部的应用页脚,同样具有固定高度

So what I did was: 所以我所做的是:

  • Remove everything that is rendered above the first part (Main Menu, Tool Bars...) 删除第一部分上方呈现的所有内容(主菜单,工具栏...)
  • Create the Part Sash Container with 1 Part (header), 2 whatever Control you need (content), 3 last Part (footer) 用1个零件(页眉),2个所需控件(内容),3个最后零件(页脚)创建零件窗框容器
  • In this Part Sash Container do the following: 在此部件框格容器中执行以下操作:
    1. add "fx_fixedLayout" to "Tags" (as I don't want re-sizing the Sash) 在“标签”中添加“ fx_fixedLayout”(因为我不想调整“腰带”的大小)
    2. add "CUSTOM_RENDERER_UI=my.renderer.MainSashRenderer" to "Persisted State" 将“ CUSTOM_RENDERER_UI = my.renderer.MainSashRenderer”添加到“持久状态”
  • create a copy of "org.eclipse.e4.ui.workbench.renderers.swt.SashLayout" and name it "my.renderer.MainSashLayout". 创建“ org.eclipse.e4.ui.workbench.renderers.swt.SashLayout”的副本,并将其命名为“ my.renderer.MainSashLayout”。 Change method "tileSubNodes" and set fixed height for the first and last child. 更改方法“ tileSubNodes”,并为第一个和最后一个孩子设置固定高度。
  • Extend class "SashRenderer" and call it "MainSashRenderer" 扩展类“ SashRenderer”,并将其命名为“ MainSashRenderer”
  • Create a new "MainWorkbenchRendererFactory" extending "WorkbenchRendererFactory", to hook your new renderer in. This class only attaches the "MainSashRenderer" to "MPartSashContainer" objects with a specific ID (because I want all other Sashes to be untouched). 创建一个扩展到“ WorkbenchRendererFactory”的新“ MainWorkbenchRendererFactory”,以钩住新的渲染器。此类仅将“ MainSashRenderer”附加到具有特定ID的“ MPartSashContainer”对象(因为我希望所有其他Sash都保持不变)。

public class MainWorkbenchRendererFactory extends WorkbenchRendererFactory {

    private final static String MAIN_SASH_ID = "myapp.partsashcontainer.main";

    @Override
    public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
        if (uiElement instanceof MPartSashContainer
        && MAIN_SASH_ID.equalsIgnoreCase(((MPartSashContainer)uiElement).getElementId())) {
            MainSashRenderer renderer = new MainSashRenderer();
            super.initRenderer(renderer);
            return renderer;
        }
        return super.getRenderer(uiElement, parent);
    }
}

In class "MainSashRenderer", change reference from "SashLayout" to "MainSashLayout". 在“ MainSashRenderer”类中,将引用从“ SashLayout”更改为“ MainSashLayout”。

In class "MainSashLayout", method tileSubNodes: 在“ MainSashLayout”类中,方法tileSubNodes:

    // subsctract size for header and footer:
    availableSpace -= (this.footerHeightPx + this.headerHeightPx);

    // Subtract off the room for the sashes
    availableSpace -= ((childCount - 1) * sashWidth);

    if (availableSpace < 0)
    availableSpace = 0;

    for (MUIElement subNode : visibleChildren) {

    if (childNum == 0) {
        newSize = this.headerHeightPx;
    } else if (childNum == visibleChildren.size()-1) {
        newSize = this.footerHeightPx;
    } else {
        // Calc the new size as a %'age of the total
        double ratio = getWeight(subNode) / totalWeight;
        newSize = (int) ((availableSpace * ratio) + 0.5);
    }
...

Result with different window sizes (header and footer keep their pixel height): Screenshots with different window sizes 窗口大小不同的结果(页眉和页脚保持像素高度): 窗口大小不同的屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM