/** {@inheritDoc} */
 @Override
 protected boolean isMine(final CommandParameter object) {
   if (object.getEReference() != null && (valids.size() + restricted.size() > 0)) {
     final EObject value = (EObject) object.getValue();
     return isMyTargetType(value);
   }
   return true;
 }
コード例 #2
0
  /**
   * @param manager The menu manager responsible for the context menu
   * @param descriptors The menu items to be added
   * @param domain The editing domain of the current EObject
   * @param eObject The model element
   */
  private void fillContextMenu(
      IMenuManager manager,
      Collection<?> descriptors,
      final EditingDomain domain,
      final EObject eObject) {
    for (final Object descriptor : descriptors) {

      final CommandParameter cp = (CommandParameter) descriptor;
      if (!CommandParameter.class.isInstance(descriptor)) {
        continue;
      }
      if (cp.getEReference() == null) {
        continue;
      }
      if (!cp.getEReference().isMany() && eObject.eIsSet(cp.getEStructuralFeature())) {
        continue;
      } else if (cp.getEReference().isMany()
          && cp.getEReference().getUpperBound() != -1
          && cp.getEReference().getUpperBound()
              <= ((List<?>) eObject.eGet(cp.getEReference())).size()) {
        continue;
      }

      manager.add(
          new CreateChildAction(domain, new StructuredSelection(eObject), descriptor) {
            @Override
            public void run() {
              super.run();

              final EReference reference = ((CommandParameter) descriptor).getEReference();
              // if (!reference.isContainment()) {
              // domain.getCommandStack().execute(
              // AddCommand.create(domain, eObject.eContainer(), null, cp.getEValue()));
              // }

              domain
                  .getCommandStack()
                  .execute(AddCommand.create(domain, eObject, reference, cp.getEValue()));
            }
          });
    }
  }