private void createModelFor(String id) {
   if (id == null) {
     id = getClass().getName() + '.' + System.identityHashCode(this);
   }
   menuModel = null;
   for (MMenu item : modelPart.getMenus()) {
     if (id.equals(item.getElementId())
         && item instanceof MPopupMenu
         && item.getTags().contains(ContributionsAnalyzer.MC_POPUP)) {
       menuModel = (MPopupMenu) item;
       break;
     }
   }
   if (menuModel == null) {
     menuModel = MenuFactoryImpl.eINSTANCE.createPopupMenu();
     menuModel.setElementId(id);
     menuModel.getTags().add(ContributionsAnalyzer.MC_POPUP);
     modelPart.getMenus().add(menuModel);
   }
   IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
   AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
   if (obj instanceof MenuManagerRenderer) {
     ((MenuManagerRenderer) obj).linkModelToManager(menuModel, menu);
   }
   registerE4Support();
   cleanUpContributionCache();
 }
  @Override
  public MPlaceholder createSharedPart(String id, boolean force) {
    MWindow sharedWindow = getWindow();
    // Do we already have the part to share?
    MPart sharedPart = null;

    // check for existing parts if necessary
    if (!force) {
      for (MUIElement element : sharedWindow.getSharedElements()) {
        if (element.getElementId().equals(id)) {
          sharedPart = (MPart) element;
          break;
        }
      }
    }

    if (sharedPart == null) {
      MPartDescriptor descriptor = modelService.getPartDescriptor(id);
      sharedPart = createPart(descriptor);
      if (sharedPart == null) {
        return null;
      }

      // Replace the id to ensure that multi-instance parts work correctly
      sharedPart.setElementId(id);

      sharedWindow.getSharedElements().add(sharedPart);
    }

    return createSharedPart(sharedPart);
  }
  @Override
  public boolean isPartVisible(MPart part) {
    if (isInContainer(part)) {
      MUIElement element = part;
      MElementContainer<?> parent = part.getParent();
      if (parent == null) {
        // might be a shared part
        element = part.getCurSharedRef();
        if (element == null) {
          return false;
        }

        parent = element.getParent();
        if (parent == null) {
          return false;
        }
      }

      if (parent instanceof MPartStack) {
        return parent.getSelectedElement() == element;
      }

      return element.isVisible();
    }
    return false;
  }
 @Test
 public void testFocusChangesOnExplicitPartActivation() {
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   eps.activate(part);
   processEvents();
   assertTrue(((PartBackend) part.getObject()).text1.isFocusControl());
 }
  @Override
  public boolean savePart(MPart part, boolean confirm) {
    if (!part.isDirty()) {
      return true;
    }

    if (saveHandler != null) {
      return saveHandler.save(part, confirm);
    }

    Object client = part.getObject();
    try {
      ContextInjectionFactory.invoke(client, Persist.class, part.getContext());
    } catch (InjectionException e) {
      log(
          "Failed to persist contents of part",
          "Failed to persist contents of part ({0})", //$NON-NLS-1$ //$NON-NLS-2$
          part.getElementId(),
          e);
      return false;
    } catch (RuntimeException e) {
      log(
          "Failed to persist contents of part via DI", //$NON-NLS-1$
          "Failed to persist contents of part ({0}) via DI",
          part.getElementId(),
          e); //$NON-NLS-1$
      return false;
    }
    return true;
  }
  public void testCreateView() {
    final MWindow window = createWindowWithOneView("Part Name");

    MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
    application.getChildren().add(window);
    application.setContext(appContext);
    appContext.set(MApplication.class.getName(), application);

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

    MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0);
    MPartStack stack = (MPartStack) container.getChildren().get(0);
    MPart part = (MPart) stack.getChildren().get(0);

    CTabFolder folder = (CTabFolder) stack.getWidget();
    CTabItem item = folder.getItem(0);
    assertEquals("Part Name", item.getText());

    assertFalse(part.isDirty());

    part.setDirty(true);
    assertEquals("*Part Name", item.getText());

    part.setDirty(false);
    assertEquals("Part Name", item.getText());
  }
  private void setComboList() {

    int index = cCombo.getSelectionIndex();
    if (index < 0) index = 0; // default selection is "NO OVERLAY"
    String text = cCombo.getText();

    ArrayList<String> itemList = new ArrayList<String>(10);
    itemList.add(IConstant.NO_OVERLAY);

    Collection<MPart> parts = partService.getParts();
    for (MPart part : parts) {
      if (isOverlayPart(part)) {
        if (part.getContext() != null) { // part is instantiated
          itemList.add(part.getLabel());
        }
      }
    }

    String[] items = itemList.toArray(new String[0]);
    cCombo.setItems(items);
    if (index > 0) {
      int newIndex = 0;
      for (int i = 1; i < items.length; i++) {
        if (text.equals(items[i])) {
          newIndex = i;
          break;
        }
      }
      index = newIndex;
    }
    cCombo.select(index);
    ((GcodeViewPart) part.getObject())
        .getGcodeViewGroup()
        .setOverlayGcodeProgram(getSelectedProgram(cCombo.getText()));
  }
  @Override
  public MPart showPart(MPart part, PartState partState) {
    Assert.isNotNull(part);
    Assert.isNotNull(partState);

    MPart addedPart = addPart(part);
    MPlaceholder localPlaceholder = getLocalPlaceholder(addedPart);
    // correct the placeholder setting if necessary
    if (localPlaceholder != null && addedPart.getCurSharedRef() != localPlaceholder) {
      addedPart.setCurSharedRef(localPlaceholder);
    }

    switch (partState) {
      case ACTIVATE:
        activate(addedPart);
        return addedPart;
      case VISIBLE:
        MPart activePart = getActivePart();
        if (activePart == null
            || (activePart != addedPart && getParent(activePart) == getParent(addedPart))) {
          delegateBringToTop(addedPart);
          activate(addedPart);
        } else {
          bringToTop(addedPart);
        }
        return addedPart;
      case CREATE:
        createElement(addedPart);
        return addedPart;
    }
    return addedPart;
  }
  protected void applyPersistedStates(MPart part) throws GkException {
    String baudrateStr =
        part.getPersistedState().get(SerialConnectionController.PERSISTED_BAUDRATE);

    if (StringUtils.isNotBlank(baudrateStr)) {
      LabeledValue<Integer> baudrate =
          GkUiUtils.getLabelledValueByKey(
              Integer.valueOf(baudrateStr), controller.getDataModel().getChoiceBaudrate());
      if (baudrate != null) {
        controller.getDataModel().setBaudrate(baudrate);
      }
    }

    String commPortStr =
        part.getPersistedState().get(SerialConnectionController.PERSISTED_COMMPORT);

    if (StringUtils.isNotBlank(baudrateStr)) {
      LabeledValue<String> commPort =
          GkUiUtils.getLabelledValueByKey(
              commPortStr, controller.getDataModel().getChoiceSerialPort());
      if (commPort != null) {
        controller.getDataModel().setSerialPort(commPort);
      }
    }
  }
示例#10
0
 /**
  * Returns the ID to find a proper service.
  *
  * @param mPart
  * @return
  */
 protected String getServiceID(MPart mPart) {
   String id = mPart.getPersistedState().get(IOutlineViewProvider.PROPERTY);
   if (id == null || id.isEmpty()) {
     id = mPart.getElementId();
   }
   return id;
 }
示例#11
0
  protected Command computeCommand() {
    MUIElement selectedPart = model;

    if (selectedPart instanceof MPart) {
      MGenericStack<MUIElement> partStack = findParentStack();
      if (partStack != null) {
        selectedPart = partStack;
      }
    }

    MElementContainer<MUIElement> parent = partStack.getParent();
    List<MUIElement> children = parent.getChildren();
    int index = children.indexOf(partStack);
    if (parent instanceof MGenericTile<?>) {
      MGenericTile<?> genericTile = (MGenericTile<?>) parent;
      int modelIndex = children.indexOf(selectedPart);
      if (modelIndex == 0 && index == 1 && children.size() == 2 && genericTile.isHorizontal()) {
        return UnexecutableCommand.INSTANCE;
      }
    }

    CompoundCommand result = new CompoundCommand();

    MPartSashContainer newSash = MBasicFactory.INSTANCE.createPartSashContainer();
    String preferData = partStack.getContainerData();
    newSash.setContainerData(preferData);
    newSash.setHorizontal(true);

    if (selectedPart instanceof MPartStack) {
      if (selectedPart.getParent() == null) {
        selectedPart.setContainerData(preferData);
        result.add(CommandFactory.createAddChildCommand(newSash, selectedPart, 0));
      } else {
        result.add(new ChangeParentCommand(newSash, selectedPart, 0));
        if (!preferData.equals(selectedPart.getContainerData())) {
          result.add(
              new ApplyAttributeSettingCommand(
                  (EObject) selectedPart, "containerData", preferData));
        }
      }
    } else if (selectedPart instanceof MPart) {
      MPart part = (MPart) selectedPart;
      MPartStack createPartStack = MBasicFactory.INSTANCE.createPartStack();
      createPartStack.setContainerData(preferData);
      if (part.getParent() != null) {
        result.add(new ChangeParentCommand(createPartStack, part, 0));
      } else {
        result.add(CommandFactory.createAddChildCommand(createPartStack, part, 0));
      }
      result.add(CommandFactory.createAddChildCommand(newSash, createPartStack, 0));
    }

    result.add(new ChangeParentCommand(newSash, partStack, 1));

    result.add(CommandFactory.createAddChildCommand(parent, newSash, index));
    return result.unwrap();
  }
 @Override
 public Collection<MPart> getDirtyParts() {
   List<MPart> dirtyParts = new ArrayList<>();
   for (MPart part : getParts()) {
     if (part.isDirty()) {
       dirtyParts.add(part);
     }
   }
   return dirtyParts;
 }
        public void selectionChanged(MPart part, Object selection) {
          selection = createCompatibilitySelection(selection);

          Object client = part.getObject();
          if (client instanceof CompatibilityPart) {
            IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
            notifyPostSelectionListeners(
                part.getElementId(), workbenchPart, (ISelection) selection);
          }
        }
 @Ignore
 @Test
 public void XXXtestNoFocusChangeOnExplicitWidgetSelection() {
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   ((TextField) toolControl.getObject()).text.setFocus();
   processEvents();
   assertEquals(part.getElementId(), eps.getActivePart().getElementId());
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   assertTrue(((TextField) toolControl.getObject()).text.isFocusControl());
 }
示例#15
0
 private MMenu getPopupMenu(final MApplication inApplication, final EModelService inModel) {
   if (popupStyles == null) {
     final MPart lPart = (MPart) inModel.find(RelationsConstants.PART_INSPECTOR, inApplication);
     for (final MMenu lMenu : lPart.getMenus()) {
       if (RelationsConstants.POPUP_INSPECTOR.equals(lMenu.getElementId())) {
         popupStyles = lMenu;
         break;
       }
     }
   }
   return popupStyles;
 }
示例#16
0
 @Execute
 public void execute(@Named(PARAMTER_ID) String param, EPartService partService) {
   //	public void execute(EPartService partService) {
   //		String param="next";
   MPart part = partService.getActivePart();
   Object obj = part.getObject();
   if (obj instanceof WaveformViewer) {
     if ("next".equalsIgnoreCase(param)) ((WaveformViewer) obj).moveCursor(GotoDirection.NEXT);
     else if ("prev".equalsIgnoreCase(param))
       ((WaveformViewer) obj).moveCursor(GotoDirection.PREV);
   }
 }
 @PersistState
 public void persist(MPart part) {
   if (controller.getDataModel() != null) {
     part.getPersistedState()
         .put(
             SerialConnectionController.PERSISTED_BAUDRATE,
             String.valueOf(controller.getDataModel().getBaudrate().getValue()));
     part.getPersistedState()
         .put(
             SerialConnectionController.PERSISTED_COMMPORT,
             controller.getDataModel().getSerialPort().getValue());
   }
 }
 /**
  * Records the specified parent part's selected element in the activation history if the parent is
  * a stack.
  *
  * @param part the part whose parent's selected element should be checked for activation history
  *     recording
  */
 private void recordStackActivation(MPart part) {
   MElementContainer<? extends MUIElement> parent = part.getParent();
   if (parent instanceof MGenericStack) {
     recordSelectedActivation(parent);
   } else if (parent == null) {
     MPlaceholder placeholder = part.getCurSharedRef();
     if (placeholder != null) {
       parent = placeholder.getParent();
       if (parent instanceof MGenericStack) {
         recordSelectedActivation(parent);
       }
     }
   }
 }
 private void adjustPlaceholder(MPart part) {
   if (isShared(part)) {
     MPlaceholder placeholder = part.getCurSharedRef();
     // if this part doesn't have any placeholders, we need to make one
     if (placeholder == null
         // alternatively, if it has one but it's not in the current container, then we
         // need to spawn another one as we don't want to reuse the same one and end up
         // shifting that placeholder to the current container during the add operation
         || (placeholder.getParent() != null && !isInContainer(placeholder))) {
       placeholder = createSharedPart(part);
       part.setCurSharedRef(placeholder);
     }
   }
 }
        public void selectionChanged(MPart part, Object selection) {
          selection = createCompatibilitySelection(selection);
          context.set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);

          IEclipseContext applicationContext = application.getContext();
          if (applicationContext.getActiveChild() == context) {
            application.getContext().set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
          }

          Object client = part.getObject();
          if (client instanceof CompatibilityPart) {
            IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
            notifyListeners(part.getElementId(), workbenchPart, (ISelection) selection);
          }
        }
 @Inject
 void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) final MPart part) {
   activePart = null;
   if (part != null) {
     Object client = part.getObject();
     if (client instanceof CompatibilityPart) {
       IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
       activePart = workbenchPart;
     } else if (client != null) {
       if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) {
         activePart = (IWorkbenchPart) part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY);
       }
     }
   }
 }
  private void cleanUpContributionCache() {
    if (!actionContributionCache.isEmpty()) {
      PluginActionContributionItem[] items =
          actionContributionCache.toArray(
              new PluginActionContributionItem[actionContributionCache.size()]);
      actionContributionCache.clear();
      for (int i = 0; i < items.length; i++) {
        items[i].dispose();
      }
    }

    if (modelPart == null || menuModel == null) {
      return;
    }
    IEclipseContext modelContext = modelPart.getContext();
    if (modelContext != null) {
      IRendererFactory factory = modelContext.get(IRendererFactory.class);
      if (factory != null) {
        AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
        if (obj instanceof MenuManagerRenderer) {
          MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
          renderer.cleanUp(menuModel);
        }
      }
    }
  }
  private void showStandaloneViewMenu(
      ExecutionEvent event, MPart model, MMenu menuModel, Composite partContainer) {
    Shell shell = partContainer.getShell();
    Menu menu = (Menu) menuModel.getWidget();
    if (menu == null) {
      IPresentationEngine engine =
          (IPresentationEngine) HandlerUtil.getVariable(event, IPresentationEngine.class.getName());
      menu = (Menu) engine.createGui(menuModel, shell, model.getContext());
      if (menu != null) {
        final Menu tmpMenu = menu;
        partContainer.addDisposeListener(
            new DisposeListener() {
              public void widgetDisposed(DisposeEvent e) {
                tmpMenu.dispose();
              }
            });
      }
    }

    Display display = menu.getDisplay();
    Point location = display.map(partContainer, null, partContainer.getLocation());
    Point size = partContainer.getSize();
    menu.setLocation(location.x + size.x, location.y);
    menu.setVisible(true);

    while (!menu.isDisposed() && menu.isVisible()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    if (!(menu.getData() instanceof MenuManager)) {
      menu.dispose();
    }
  }
 @PostConstruct
 public void init() {
   text1 = new Text(parent, SWT.SINGLE);
   text2 = new Text(parent, SWT.SINGLE);
   text1.setText(part.getLabel() + " text1");
   text1.setText(part.getLabel() + " text2");
 }
 private MPlaceholder createSharedPart(MPart sharedPart) {
   // Create and return a reference to the shared part
   MPlaceholder sharedPartRef = modelService.createModelElement(MPlaceholder.class);
   sharedPartRef.setElementId(sharedPart.getElementId());
   sharedPartRef.setRef(sharedPart);
   return sharedPartRef;
 }
  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 IGcodeProgram getSelectedProgram(String text) {

    LOG.debug("getSelectedProgram: text=" + text);

    Collection<MPart> parts = partService.getParts();
    for (MPart part : parts) {
      if (isOverlayPart(part)) {
        if (text.equals(part.getLabel())) {
          final IEclipseContext context = part.getContext();
          if (context != null) return context.get(IGcodeProgram.class);
        }
      }
    }

    // if part is not instantiated and therefore gcode program is not loaded, then we are here
    return null;
  }
  @Override
  public void switchPerspective(MPerspective perspective) {
    Assert.isNotNull(perspective);
    MWindow window = getWindow();
    if (window != null && isInContainer(window, perspective)) {
      perspective.getParent().setSelectedElement(perspective);
      List<MPart> newPerspectiveParts =
          modelService.findElements(perspective, null, MPart.class, null);
      // if possible, keep the same active part across perspective switches
      if (newPerspectiveParts.contains(activePart)
          && partActivationHistory.isValid(perspective, activePart)) {
        MPart target = activePart;
        IEclipseContext activeChild = activePart.getContext().getParent().getActiveChild();
        if (activeChild != null) {
          activeChild.deactivate();
        }
        if (target.getContext() != null
            && target.getContext().get(MPerspective.class) != null
            && target.getContext().get(MPerspective.class).getContext()
                == perspective.getContext()) {
          target.getContext().activateBranch();
        } else {
          perspective.getContext().activate();
        }

        modelService.bringToTop(target);
        activate(target, true, false);
        return;
      }

      MPart newActivePart = perspective.getContext().getActiveLeaf().get(MPart.class);
      if (newActivePart == null) {
        // whatever part was previously active can no longer be found, find another one
        MPart candidate = partActivationHistory.getActivationCandidate(perspective);
        if (candidate != null) {
          modelService.bringToTop(candidate);
          activate(candidate, true, false);
          return;
        }
      }

      // there seems to be no parts in this perspective, just activate it as is then
      if (newActivePart == null) {
        modelService.bringToTop(perspective);
        perspective.getContext().activate();
      } else {
        if ((modelService.getElementLocation(newActivePart) & EModelService.IN_SHARED_AREA) != 0) {
          if (newActivePart.getParent().getSelectedElement() != newActivePart) {
            newActivePart = (MPart) newActivePart.getParent().getSelectedElement();
          }
        }
        activate(newActivePart, true, false);
      }
    }
  }
示例#29
0
  @SuppressWarnings("unchecked")
  public void exchange() {
    MPart activeEditor = partService.getActivePart();

    MElementContainer<MUIElement> oldEditorStack = activeEditor.getParent();
    MElementContainer<MUIElement> splitSash = oldEditorStack.getParent();
    if (splitSash.getChildren().size() != 2) {
      return;
    }

    int oldStackIndex = splitSash.getChildren().indexOf(oldEditorStack);
    MElementContainer<MUIElement> newEditorStack =
        (MElementContainer<MUIElement>) splitSash.getChildren().get(oldStackIndex == 1 ? 0 : 1);

    exchange_editor_with_selected_in_new_stack(activeEditor, oldEditorStack, newEditorStack);

    activate(activeEditor);
  }
  @Override
  public void disposeWidget(MUIElement element) {
    if (element instanceof MPart) {
      MPart part = (MPart) element;
      MToolBar toolBar = part.getToolbar();
      if (toolBar != null) {
        Widget widget = (Widget) toolBar.getWidget();
        if (widget != null) {
          unbindWidget(toolBar);
          widget.dispose();
        }
      }

      for (MMenu menu : part.getMenus()) {
        engine.removeGui(menu);
      }
    }
    super.disposeWidget(element);
  }