简体   繁体   中英

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. I have a PartSashContainer with two Parts and another PartSashContainer in it. I initially set size in the containerData parameter, but these values are relative and still allow for re-sizing of the parts. 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. 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. I found no perfect way, but the vogella tutorial on custom renderers gave me some hints. 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)
  • In this Part Sash Container do the following:
    1. add "fx_fixedLayout" to "Tags" (as I don't want re-sizing the Sash)
    2. add "CUSTOM_RENDERER_UI=my.renderer.MainSashRenderer" to "Persisted State"
  • create a copy of "org.eclipse.e4.ui.workbench.renderers.swt.SashLayout" and name it "my.renderer.MainSashLayout". Change method "tileSubNodes" and set fixed height for the first and last child.
  • Extend class "SashRenderer" and call it "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).

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".

In class "MainSashLayout", method 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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