[英]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? 有一个简单的方法吗?
我不确定在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: 我的要求:
So what I did was: 所以我所做的是:
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.