/**
   * {@inheritDoc}
   *
   * @see
   *     org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener#firePropertiesChanged(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
   */
  public void firePropertiesChanged(IPropertiesEditionEvent event) {
    if (!isInitializing()) {
      Diagnostic valueDiagnostic = validateValue(event);
      if (PropertiesEditionEvent.COMMIT == event.getState()
          && IPropertiesEditionComponent.LIVE_MODE.equals(editing_mode)
          && valueDiagnostic.getSeverity() == Diagnostic.OK) {
        CompoundCommand command = new CompoundCommand();
        if (TarotViewsRepository.GamePlayers.players == event.getAffectedEditor()) {
          if (PropertiesEditionEvent.SET == event.getKind()) {
            Player oldValue = (Player) event.getOldValue();
            Player newValue = (Player) event.getNewValue();
            // TODO: Complete the game update command
            for (EStructuralFeature feature : newValue.eClass().getEAllStructuralFeatures()) {
              if (feature.isChangeable()
                  && !(feature instanceof EReference && ((EReference) feature).isContainer())) {
                command.append(
                    SetCommand.create(
                        liveEditingDomain, oldValue, feature, newValue.eGet(feature)));
              }
            }
          } else if (PropertiesEditionEvent.ADD == event.getKind())
            command.append(
                AddCommand.create(
                    liveEditingDomain,
                    game,
                    TarotPackage.eINSTANCE.getGame_Players(),
                    event.getNewValue()));
          else if (PropertiesEditionEvent.REMOVE == event.getKind())
            command.append(DeleteCommand.create(liveEditingDomain, event.getNewValue()));
          else if (PropertiesEditionEvent.MOVE == event.getKind())
            command.append(
                MoveCommand.create(
                    liveEditingDomain,
                    game,
                    TarotPackage.eINSTANCE.getPlayer(),
                    event.getNewValue(),
                    event.getNewIndex()));
        }

        if (!command.isEmpty() && !command.canExecute()) {
          EEFRuntimePlugin.getDefault().logError("Cannot perform model change command.", null);
        } else {
          liveEditingDomain.getCommandStack().execute(command);
        }
      }
      if (valueDiagnostic.getSeverity() != Diagnostic.OK
          && valueDiagnostic instanceof BasicDiagnostic)
        super.firePropertiesChanged(new PropertiesValidationEditionEvent(event, valueDiagnostic));
      else {
        Diagnostic validate = validate();
        super.firePropertiesChanged(new PropertiesValidationEditionEvent(event, validate));
      }
      super.firePropertiesChanged(event);
    }
  }
Example #2
0
 /**
  * This basically calls a setter via EMF reflection to set a structural feature.
  *
  * <ul>
  *   <li>If <code>value</code> is a {@link List} of elements, the feature <code>ref</code> must,
  *       of course, also be a list.
  *   <li>If <code>value</code> is a single element, then <code>ref</code> might have multiplicity
  *       <code>1</code> or it might also be a list. In the latter case, <code>value</code> is
  *       added to the list.
  * </ul>
  *
  * @param obj The object which holds the feature to set.
  * @param ref The feature which should be set.
  * @param value The value that should be set.
  * @return <code>true</code>, if the value could be set or <b>if it was already set</b>; <code>
  *     false</code> otherwise.
  */
 @SuppressWarnings("unchecked")
 public static boolean setStructuralFeature(EObject obj, EStructuralFeature ref, Object value) {
   if (!ref.isChangeable()) {
     throw new IllegalArgumentException(
         "Cannot set a non-changeable reference: " + obj.eClass().getName() + "." + ref.getName());
   }
   try {
     if (ref.isMany()) {
       final List<Object> list = (List<Object>) obj.eGet(ref);
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         for (final Object listValue : valueList) {
           if (!list.contains(listValue) && !list.add(listValue)) {
             return false;
           }
         }
       } else {
         if (!list.contains(value) && !list.add(value)) {
           return false;
         }
       }
       return true;
     } else {
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         if (valueList.size() > 1) {
           throw new IllegalArgumentException(
               "Cannot set a list of values to a non-many feature!");
         } else if (valueList.size() == 1) {
           if (obj.eGet(ref) == null || !obj.eGet(ref).equals(valueList.get(0))) {
             obj.eSet(ref, valueList.get(0));
           }
         } else {
           obj.eSet(ref, null);
         }
       } else {
         if (obj.eGet(ref) == null || !obj.eGet(ref).equals(value)) {
           obj.eSet(ref, value);
         }
       }
       return true;
     }
   } catch (final Exception e) {
     throw new IllegalArgumentException(
         "Could not set value ("
             + value
             + ") to: "
             + obj.eClass().getName()
             + "."
             + ref.getName()
             + " of object "
             + obj,
         e);
   }
 }
  public void doInstancePropertyInit(Object instance, QvtOperationalEvaluationVisitor evalVisitor) {
    if (false == instance instanceof EObject) {
      return;
    }
    EObject eInstance = (EObject) instance;

    EClass intermediateClass = eInstance.eClass();

    Map<EStructuralFeature, OCLExpression<EClassifier>> clsFeatures =
        myClassifierInitializations.get(intermediateClass);
    if (clsFeatures == null) {
      return;
    }
    for (EStructuralFeature eFeature : intermediateClass.getEAllStructuralFeatures()) {
      IntermediateStaticFieldAdapter adapter =
          (IntermediateStaticFieldAdapter)
              EcoreUtil.getAdapter(eFeature.eAdapters(), IntermediateStaticFieldAdapter.class);
      if (adapter != null && adapter.isInitialized()) {
        continue;
      }

      OCLExpression<EClassifier> expression = clsFeatures.get(eFeature);

      Object evalResult = expression != null ? evalVisitor.visitExpression(expression) : null;

      if (evalResult == null) {
        // no init expression specified for a single-valued feature, or init expression evaluated to
        // null
        EClassifier featureType =
            evalVisitor.getEnvironment().getUMLReflection().getOCLType(eFeature);
        evalResult =
            EvaluationUtil.createInitialValue(
                featureType,
                evalVisitor.getEnvironment().getOCLStandardLibrary(),
                evalVisitor.getEvaluationEnvironment());
      }

      // temporary switch off read-only property
      boolean isChangeable = eFeature.isChangeable();
      eFeature.setChangeable(true);

      boolean isUndefined =
          QvtOperationalUtil.isUndefined(evalResult, evalVisitor.getEvaluationEnvironment());
      evalVisitor
          .getOperationalEvaluationEnv()
          .callSetter(eInstance, eFeature, evalResult, isUndefined, true);

      eFeature.setChangeable(isChangeable);
    }
  }
 public static Collection<EStructuralFeature> filterByFeatureInitializer(
     Collection<EStructuralFeature> features, FeatureInitializer featureInitializer) {
   if (featureInitializer.getFeatureSeqInitializer() == null
       || featureInitializer.getFeatureSeqInitializer().getElementClass() == null) {
     return features;
   }
   EClass eClass = featureInitializer.getFeatureSeqInitializer().getElementClass();
   List<EStructuralFeature> result =
       new ArrayList<EStructuralFeature>(getEStructuralFeaturesOf(features, eClass));
   for (Iterator<EStructuralFeature> it = result.iterator(); it.hasNext(); ) {
     EStructuralFeature nextFeature = it.next();
     if (nextFeature == null || !nextFeature.isChangeable()) {
       it.remove();
     }
   }
   return result;
 }
Example #5
0
  protected void convertContent(EObject eObject) {
    final Object target = objectMapping.get(eObject);

    final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(target);
    for (final EStructuralFeature eStructuralFeature :
        modelObject.eClass().getEAllStructuralFeatures()) {
      if (!eStructuralFeature.isChangeable() || eStructuralFeature.isVolatile()) {
        continue;
      }

      // not set, not convert
      if (!eStructuralFeature.isMany() && !eObject.eIsSet(eStructuralFeature)) {
        continue;
      }

      if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) {
        convertFeatureMap(eObject, modelObject, eStructuralFeature);
      } else if (eStructuralFeature.isMany()) {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertManyEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertManyEReference(eObject, modelObject, eReference);
        }
      } else {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertSingleEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertSingleEReference(eObject, modelObject, eReference);
        }
      }
    }
  }
 /**
  * Returns whether an EStructuralFeature is valid for an EObject or not. A reference is valid, if
  * it can be set or added to.
  *
  * @param feature the EStructuralFeature in question
  * @param eObject the EObject to check the feature for
  * @param exceptionLog the current log of exceptions
  * @param ignoreAndLog should exceptions be ignored and added to <code>exceptionLog</code>?
  * @return if the feature can be set or added to
  */
 public static boolean isValid(
     EStructuralFeature feature,
     EObject eObject,
     Set<RuntimeException> exceptionLog,
     boolean ignoreAndLog) {
   boolean result = false;
   try {
     if (feature.isMany()) {
       // has the maximum amount of referenced objects been reached?
       Collection<?> referencedItems = (Collection<?>) eObject.eGet(feature);
       if (feature.getUpperBound() >= 0 && referencedItems.size() >= feature.getUpperBound()) {
         return false;
       }
     }
     // can the feature be changed reflectively?
     result = feature.isChangeable() && !feature.isVolatile() && !feature.isDerived();
   } catch (RuntimeException e) {
     handle(e, exceptionLog, ignoreAndLog);
   }
   return result;
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#getPropertiesEditionCommand
  *     (org.eclipse.emf.edit.domain.EditingDomain)
  */
 public CompoundCommand getPropertiesEditionCommand(EditingDomain editingDomain) {
   CompoundCommand cc = new CompoundCommand();
   if ((game != null) && (gamePlayersPart != null)) {
     List playersToAddFromPlayers = gamePlayersPart.getPlayersToAdd();
     for (Iterator iter = playersToAddFromPlayers.iterator(); iter.hasNext(); )
       cc.append(
           AddCommand.create(
               editingDomain, game, TarotPackage.eINSTANCE.getGame_Players(), iter.next()));
     Map playersToRefreshFromPlayers = gamePlayersPart.getPlayersToEdit();
     for (Iterator iter = playersToRefreshFromPlayers.keySet().iterator(); iter.hasNext(); ) {
       Player nextElement = (Player) iter.next();
       Player players = (Player) playersToRefreshFromPlayers.get(nextElement);
       for (EStructuralFeature feature : nextElement.eClass().getEAllStructuralFeatures()) {
         if (feature.isChangeable()
             && !(feature instanceof EReference && ((EReference) feature).isContainer())) {
           cc.append(
               SetCommand.create(editingDomain, nextElement, feature, players.eGet(feature)));
         }
       }
     }
     List playersToRemoveFromPlayers = gamePlayersPart.getPlayersToRemove();
     for (Iterator iter = playersToRemoveFromPlayers.iterator(); iter.hasNext(); )
       cc.append(DeleteCommand.create(editingDomain, iter.next()));
     List playersToMoveFromPlayers = gamePlayersPart.getPlayersToMove();
     for (Iterator iter = playersToMoveFromPlayers.iterator(); iter.hasNext(); ) {
       org.eclipse.emf.eef.runtime.impl.utils.EMFListEditUtil.MoveElement moveElement =
           (org.eclipse.emf.eef.runtime.impl.utils.EMFListEditUtil.MoveElement) iter.next();
       cc.append(
           MoveCommand.create(
               editingDomain,
               game,
               TarotPackage.eINSTANCE.getPlayer(),
               moveElement.getElement(),
               moveElement.getIndex()));
     }
   }
   if (!cc.isEmpty()) return cc;
   cc.append(IdentityCommand.INSTANCE);
   return cc;
 }
Example #8
0
  protected void convertContent(Object target) {
    // if a proxy then do no feature conversions as this may load
    // the object
    InternalEObject eObject = objectMapping.get(target);
    final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(target);
    if (getProxyObjects().contains(target)) {
      final URI proxyURI = getProxyId(modelObject);
      if (proxyURI != null) {
        eObject.eSetProxyURI(proxyURI);
      }
      return;
    }

    for (final EStructuralFeature eStructuralFeature :
        eObject.eClass().getEAllStructuralFeatures()) {
      if (!eStructuralFeature.isChangeable() || eStructuralFeature.isVolatile()) {
        continue;
      }

      if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) {
        convertFeatureMap(modelObject, eObject, eStructuralFeature);
      } else if (eStructuralFeature.isMany()) {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertManyEAttribute(modelObject, eObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          convertManyEReference(modelObject, eObject, eReference);
        }
      } else {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertSingleEAttribute(modelObject, eObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          convertSingleEReference(modelObject, eObject, eReference);
        }
      }
    }
  }
Example #9
0
  /**
   * Copies the values from one {@link VControl} to another.
   *
   * @param from the {@link VControl} holding the values
   * @param fromDomainModel The domain model belonging to the 'from control'.
   * @param to the {@link VControl} which values should be updated
   * @param toDomainModel The domain model belonging to the 'to control'.
   * @since 1.6
   */
  @SuppressWarnings("unchecked")
  public static void copyValues(
      VControl from, EObject fromDomainModel, VControl to, EObject toDomainModel) {
    final IObservableValue fromObservableValue;
    final IObservableValue toObservableValue;
    try {
      fromObservableValue =
          Activator.getDefault()
              .getEMFFormsDatabinding()
              .getObservableValue(from.getDomainModelReference(), fromDomainModel);
      toObservableValue =
          Activator.getDefault()
              .getEMFFormsDatabinding()
              .getObservableValue(to.getDomainModelReference(), toDomainModel);
    } catch (final DatabindingFailedException ex) {
      Activator.getDefault().getReportService().report(new DatabindingFailedReport(ex));
      return;
    }
    final EObject fromEObject = (EObject) ((IObserving) fromObservableValue).getObserved();
    final EStructuralFeature fromStructuralFeature =
        (EStructuralFeature) fromObservableValue.getValueType();
    final EObject toEObject = (EObject) ((IObserving) toObservableValue).getObserved();
    final EStructuralFeature toStructuralFeature =
        (EStructuralFeature) toObservableValue.getValueType();

    fromObservableValue.dispose();
    toObservableValue.dispose();

    if (!toStructuralFeature.isChangeable()) {
      return;
    }

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(toEObject);

    if (toStructuralFeature.isMany()) {
      editingDomain
          .getCommandStack()
          .execute(
              RemoveCommand.create(
                  editingDomain,
                  toEObject,
                  toStructuralFeature,
                  (Collection<?>) toEObject.eGet(toStructuralFeature, true)));
    }
    if (EAttribute.class.isInstance(toStructuralFeature)) {

      if (toStructuralFeature.isMany()) {
        editingDomain
            .getCommandStack()
            .execute(
                AddCommand.create(
                    editingDomain,
                    toEObject,
                    toStructuralFeature,
                    (Collection<?>) fromEObject.eGet(fromStructuralFeature, true)));
      } else {
        editingDomain
            .getCommandStack()
            .execute(
                SetCommand.create(
                    editingDomain,
                    toEObject,
                    toStructuralFeature,
                    fromEObject.eGet(fromStructuralFeature, true)));
      }
    }
    if (EReference.class.isInstance(toStructuralFeature)) {
      if (toStructuralFeature.isMany()) {
        for (final EObject eObject :
            (Collection<EObject>) fromEObject.eGet(fromStructuralFeature, true)) {
          editingDomain
              .getCommandStack()
              .execute(
                  AddCommand.create(
                      editingDomain, toEObject, toStructuralFeature, EcoreUtil.copy(eObject)));
        }
        return;
      }
      editingDomain
          .getCommandStack()
          .execute(
              SetCommand.create(
                  editingDomain,
                  toEObject,
                  toStructuralFeature,
                  EcoreUtil.copy((EObject) fromEObject.eGet(fromStructuralFeature, true))));
    }
  }