我正在测试一个non-e4使用 SWTBot 的 RCP 应用程序,我需要更改视图的大小。 (移动窗框)
我尝试失败
- 使用 SWTBot 调整我的视图大小(没有这样的 api)
- 使用 Eclipse 3 API 调整我的视图大小(不支持)
- 使用底层 e4 模型调整我的视图大小(调整大小不起作用)
e4 模型看起来很有前途,但我缺少一些东西,所以它不起作用。
I can
- 获取我的部分观点:
view = ePartService.findPart(ID)
- 获取 MTrimmedWindow:
window = (view as EObject).eContainer as MTrimmedWindow
I can't
- 区域设置正确的 MPartSashContainer
- 移动窗框
setContainerData()
我想知道
- 如何从 Part 移动到其直接父级(例如 MPartStack)
- 为什么 M... 对象上不存在常见的 EObject 方法(例如 eContainer())?
好吧,我自己找到了解决方案。
问题是,该视图不是 e4 UI-Tree 的一部分。view.eContainer
直接是MWindow
。要放置在正确的位置,视图将连接到MPlaceholder
,这是 e4 UI-Tree 的一部分,并且具有getParent() != null
.
为了调整视图大小,步骤如下:
- 显示视图
- Find
MPlaceholder
视图的
- Find
MPartStack
和“MPartSashContainer”对象
- Set
containerData
- 重绘小部件(是的,自动更新接缝在这种情况下不起作用)
Example:
EModelService modelService = PlatformUI.getWorkbench().getService(EModelService.class);
EPartService partService = PlatformUI.getWorkbench().getService(EPartService.class);
// Show view
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.showView(MyView.ID, null, IWorkbenchPage.VIEW_ACTIVATE);
MPart view = partService.findPart(MyView.ID);
// view.getParent() => null, because 'view' is not a part of the e4 UI-model!
// It is connected to the Model using MPlaceholder
// Let's find the placeholder
MWindow window = (MWindow)(((EObject)eView).eContainer);
MPlaceholder placeholder = modelService.findPlaceholderFor(window, view);
MUIElement element = placeholder;
MPartStack partStack = null;
while (element != null) {
// This may not suite your configuration of views/stacks/sashes
if (element instanceof MPartStack && ((Object)element.parent) instanceof MPartSashContainer) {
partStack = (MPartStack)element;
break;
}
element = element.parent;
}
}
if (partStack == null) { /* handle error */ }
// Now let's change the width weights
for (MUIElement element : partStack.getParent().getChildren()) {
if (element == partStack) {
element.setContainerData("50"); // Width for my view
} else {
element.setContainerData("25"); // Widths for other views & editors
}
}
// Surprisingly I had to redraw tho UI manually
// There is for sure a better way to do it. Here is my (quick & very dirty):
partStack.toBeRendered = false
partStack.toBeRendered = true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)