private MWindow createWindowWithOneView(String partName) {
    final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
    window.setHeight(300);
    window.setWidth(400);
    window.setLabel("MyWindow");
    MPartSashContainer sash = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
    window.getChildren().add(sash);
    MPartStack stack = BasicFactoryImpl.eINSTANCE.createPartStack();
    sash.getChildren().add(stack);
    MPart contributedPart = BasicFactoryImpl.eINSTANCE.createPart();
    stack.getChildren().add(contributedPart);
    contributedPart.setLabel(partName);
    contributedPart.setContributionURI(
        "bundleclass://org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView");

    return window;
  }
 private MPart createPart(MPartDescriptor descriptor) {
   if (descriptor == null) {
     return null;
   }
   MPart part = modelService.createModelElement(MPart.class);
   part.setElementId(descriptor.getElementId());
   part.getMenus().addAll(EcoreUtil.copyAll(descriptor.getMenus()));
   if (descriptor.getToolbar() != null) {
     part.setToolbar((MToolBar) EcoreUtil.copy((EObject) descriptor.getToolbar()));
   }
   part.setContributorURI(descriptor.getContributorURI());
   part.setCloseable(descriptor.isCloseable());
   part.setContributionURI(descriptor.getContributionURI());
   part.setLabel(descriptor.getLabel());
   part.setIconURI(descriptor.getIconURI());
   part.setTooltip(descriptor.getTooltip());
   part.getHandlers().addAll(EcoreUtil.copyAll(descriptor.getHandlers()));
   part.getTags().addAll(descriptor.getTags());
   part.getPersistedState().putAll(descriptor.getPersistedState());
   part.getBindingContexts().addAll(descriptor.getBindingContexts());
   return part;
 }
 private void replacePlaceholder(MPlaceholder ph) {
   MPart part = createModelElement(MPart.class);
   part.setElementId(ph.getElementId());
   part.getTransientData()
       .put(
           IPresentationEngine.OVERRIDE_ICON_IMAGE_KEY,
           ImageDescriptor.getMissingImageDescriptor().createImage());
   String label = (String) ph.getTransientData().get(TAG_LABEL);
   if (label != null) {
     part.setLabel(label);
   } else {
     part.setLabel(getLabel(ph.getElementId()));
   }
   part.setContributionURI(COMPATIBILITY_VIEW_URI);
   part.setCloseable(true);
   MElementContainer<MUIElement> curParent = ph.getParent();
   int curIndex = curParent.getChildren().indexOf(ph);
   curParent.getChildren().remove(curIndex);
   curParent.getChildren().add(curIndex, part);
   if (curParent.getSelectedElement() == ph) {
     curParent.setSelectedElement(part);
   }
 }
Ejemplo n.º 4
0
  @Before
  public void setUp() throws Exception {
    appContext = E4Application.createDefaultContext();
    appContext.set(E4Workbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI);

    ems = appContext.get(EModelService.class);

    window = ems.createModelElement(MWindow.class);
    window.setWidth(500);
    window.setHeight(500);

    MPartSashContainer sash = ems.createModelElement(MPartSashContainer.class);
    window.getChildren().add(sash);
    window.setSelectedElement(sash);

    MPartStack stack = ems.createModelElement(MPartStack.class);
    sash.getChildren().add(stack);
    sash.setSelectedElement(stack);

    part = ems.createModelElement(MPart.class);
    part.setElementId("Part");
    part.setLabel("Part");
    part.setToolbar(ems.createModelElement(MToolBar.class));
    part.setContributionURI(Activator.asURI(PartBackend.class));
    stack.getChildren().add(part);

    toolControl = ems.createModelElement(MToolControl.class);
    toolControl.setElementId("ToolControl");
    toolControl.setContributionURI(Activator.asURI(TextField.class));
    part.getToolbar().getChildren().add(toolControl);

    stack = ems.createModelElement(MPartStack.class);
    sash.getChildren().add(stack);
    sash.setSelectedElement(stack);

    otherPart = ems.createModelElement(MPart.class);
    otherPart.setElementId("OtherPart");
    otherPart.setLabel("OtherPart");
    otherPart.setContributionURI(Activator.asURI(PartBackend.class));
    stack.getChildren().add(otherPart);

    MApplication application = ems.createModelElement(MApplication.class);
    application.getChildren().add(window);
    application.setContext(appContext);
    appContext.set(MApplication.class, application);

    wb = new E4Workbench(application, appContext);
    wb.createAndRunUI(window);

    eps = window.getContext().get(EPartService.class);
    // ensure the parts are populated and the contributions instantiated
    eps.activate(part);
    eps.activate(otherPart);
    processEvents();

    // ensure our model backend objects are created
    assertNotNull(part.getObject());
    assertNotNull(toolControl.getObject());
    assertNotNull(otherPart.getObject());

    assertNotNull(part.getWidget());
    assertNotNull(toolControl.getWidget());
    assertNotNull(otherPart.getWidget());

    // ensure focus is set to otherPart.text1
    eps.activate(otherPart);
    processEvents();
    assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl());
  }