コード例 #1
0
  @Override
  public MUIElement cloneElement(MUIElement element, MSnippetContainer snippetContainer) {
    EObject eObj = (EObject) element;
    MUIElement clone = (MUIElement) EcoreUtil.copy(eObj);

    // null out all the references
    List<MPlaceholder> phList = findElements(clone, null, MPlaceholder.class, null);
    for (MPlaceholder ph : phList) {
      // Skip placeholders in the sharedArea
      int location = getElementLocation(ph);
      if ((location & IN_SHARED_AREA) != 0) {
        continue;
      }

      ph.setRef(null);
    }

    if (snippetContainer != null) {
      MUIElement snippet = findSnippet(snippetContainer, element.getElementId());
      if (snippet != null) {
        snippetContainer.getSnippets().remove(snippet);
      }
      snippetContainer.getSnippets().add(clone);
    }

    // Cache the original element in the clone's transientData
    clone.getTransientData().put(CLONED_FROM_KEY, element);

    return clone;
  }
コード例 #2
0
  @Override
  public MUIElement cloneSnippet(
      MSnippetContainer snippetContainer, String snippetId, MWindow refWin) {
    if (snippetContainer == null || snippetId == null || snippetId.length() == 0) {
      return null;
    }

    MApplicationElement elementToClone = null;
    for (MApplicationElement snippet : snippetContainer.getSnippets()) {
      if (snippetId.equals(snippet.getElementId())) {
        elementToClone = snippet;
        break;
      }
    }
    if (elementToClone == null) {
      return null;
    }

    EObject eObj = (EObject) elementToClone;
    MUIElement element = (MUIElement) EcoreUtil.copy(eObj);

    MUIElement appElement = refWin == null ? null : refWin.getParent();
    if (appElement instanceof MApplication) {
      handleNullRefPlaceHolders(element, refWin, true);
    }

    return element;
  }
コード例 #3
0
  @Override
  public MUIElement findSnippet(MSnippetContainer snippetContainer, String id) {
    if (snippetContainer == null || id == null || id.length() == 0) {
      return null;
    }

    List<MUIElement> snippets = snippetContainer.getSnippets();
    for (MUIElement snippet : snippets) {
      if (id.equals(snippet.getElementId())) {
        return snippet;
      }
    }

    return null;
  }