コード例 #1
0
  /**
   * {@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);
    }
  }
コード例 #2
0
 /**
  * {@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;
 }