在Eclipse中以编程方式调整视图的大小

在Eclipse中以编程方式调整视图的大小,eclipse,eclipse-rcp,e4,swtbot,Eclipse,Eclipse Rcp,E4,Swtbot,我正在使用SWTBot测试一个非e4 RCP应用程序,我需要更改视图的大小。(移动窗扇杆) 我试过了,但没有成功 使用SWTBot调整视图大小(无此类api) 使用Eclipse3API调整视图大小(不受支持) 使用基础e4模型调整视图大小(调整大小无效) e4型号的接缝看起来很有希望,但我遗漏了一些东西,所以它不起作用 我能 获取我的视图的MPart:view=ePartService.findPart(ID) 获取MTrimmedWindow:window=(作为EOObject查看)

我正在使用SWTBot测试一个非e4 RCP应用程序,我需要更改视图的大小。(移动窗扇杆)

我试过了,但没有成功

  • 使用SWTBot调整视图大小(无此类api)
  • 使用Eclipse3API调整视图大小(不受支持)
  • 使用基础e4模型调整视图大小(调整大小无效)
e4型号的接缝看起来很有希望,但我遗漏了一些东西,所以它不起作用

我能

  • 获取我的视图的MPart:
    view=ePartService.findPart(ID)
  • 获取MTrimmedWindow:
    window=(作为EOObject查看)。作为MTrimmedWindow的eContainer
我不能

  • 区域设置正确的MPartSashContainer
  • 使用
    setContainerData()移动窗扇条
我想知道

  • 如何从MPart移动到其直接父级(例如MPart堆栈)
  • 为什么像EconContainer()这样的普通EOObject方法在M上不存在。。。物体

    • 好的,我自己找到了解决办法

      问题是,视图不是E4UI树的一部分<代码>视图。eContainer
      直接是
      mWindows
      。要放置在正确的位置,视图将连接到
      MPlaceholder
      ,它是e4 UI树的一部分,具有
      getParent()!=空

      要调整视图大小,步骤如下:

      • 显示视图
      • 查找视图的
        MPlaceholder
      • 查找
        MPartStack
        和'MPartSashContainer'对象
      • 设置
        containerData
      • 重画小部件(是的,自动更新seam在这种情况下不起作用)
      例如:

      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
      

      MPart
      (以及所有其他
      MUIElement
      对象)有一个
      getParent()
      方法,该方法为您提供直接的父对象。不幸的是,它为我的“视图”MPart返回null:(然后它还没有被添加到容器中。这总是为正在显示的零件返回父对象。@greg-449我有
      page.showView(ID,…)
      ,然后等待5秒钟,然后
      ePartService.findPart(ID).getParent()
      仍然是
      null
      。有什么想法吗?我不知道在3.x兼容模式下零件ID会发生什么情况。我不确定
      IWorkbenchPage.showPage
      使用的ID是否与应用程序模型MPart ID相同。