예제 #1
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain,
  * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
  */
 @Override
 public org.eclipse.emf.common.command.Command getSemanticCommand(
     EditingDomain domain, EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
   CompoundCommand compoundCommand =
       new CompoundCommand("Rename root paste elements"); // $NON-NLS-1$
   List<EObject> filterDescendants = EcoreUtil.filterDescendants(papyrusClipboard.getTarget());
   for (Iterator<EObject> iterator = filterDescendants.iterator(); iterator.hasNext(); ) {
     EObject target = iterator.next();
     if (target instanceof NamedElement) {
       NamedElement namedElement = (NamedElement) target;
       if (namedElement.getName() != null) {
         String defaultCopyNameWithIncrement =
             NamedElementUtil.getDefaultCopyNameWithIncrement(
                 namedElement, targetOwner.eContents());
         RenameElementCommand renameElementCommand =
             new RenameElementCommand(
                 (TransactionalEditingDomain) domain, namedElement, defaultCopyNameWithIncrement);
         compoundCommand.append(renameElementCommand);
       }
     }
   }
   // An empty can't be executed
   if (compoundCommand.getCommandList().isEmpty()) {
     return null;
   }
   return compoundCommand;
 }
 /** @generated */
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   if (request instanceof CreateConnectionRequestEx) {
     CreateConnectionRequestEx requestEx = (CreateConnectionRequestEx) request;
     if (!DiagramEditPart.MODEL_ID.equals(requestEx.getModelID())) {
       return null;
     }
     int[] visualIds = requestEx.getVisualIds();
     CompoundCommand result = new CompoundCommand();
     for (int i = 0; i < visualIds.length; i++) {
       int nextVisualId = visualIds[i];
       switch (nextVisualId) {
         case TransitionEditPart.VISUAL_ID:
           result.appendIfCanExecute(new CreateTransition4001StartCommand(requestEx));
           break;
       }
     }
     if (!result.canExecute()) {
       return null;
     }
     Command wrappedResult =
         new WrappingCommand(
             TransactionUtil.getEditingDomain(
                 ((Node) getHost().getModel()).getDiagram().getElement()),
             result);
     request.setStartCommand(wrappedResult);
     return wrappedResult;
   }
   return null;
 }
 /** @generated */
 protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
   if (request instanceof CreateConnectionRequestEx) {
     if (request.getStartCommand() == null || !request.getStartCommand().canExecute()) {
       return UnexecutableCommand.INSTANCE;
     }
     CreateConnectionRequestEx requestEx = (CreateConnectionRequestEx) request;
     if (!DiagramEditPart.MODEL_ID.equals(requestEx.getModelID())) {
       return null;
     }
     int[] visualIds = requestEx.getVisualIds();
     CompoundCommand result = new CompoundCommand();
     for (int i = 0; i < visualIds.length; i++) {
       int nextVisualId = visualIds[i];
       switch (nextVisualId) {
         case TransitionEditPart.VISUAL_ID:
           result.appendIfCanExecute(new CreateTransition4001Command(requestEx));
           break;
       }
     }
     if (result.getCommandList().size() != 1 || !result.canExecute()) {
       // Cannot create several connections at once.
       return UnexecutableCommand.INSTANCE;
     }
     return request
         .getStartCommand()
         .chain(
             new WrappingCommand(
                 TransactionUtil.getEditingDomain(
                     ((Node) getHost().getModel()).getDiagram().getElement()),
                 result));
   }
   return null;
 }
예제 #4
0
  /**
   * Adds a command to move a papyrus table and the matching table2 instance, to the compound
   * command.
   */
  protected static void addMoveTableCommand(
      TransactionalEditingDomain editingDomain,
      PapyrusTableInstance papyrusTable,
      Resource target,
      CompoundCommand commandToModify) {
    // The command has to move both the table and its table2.
    TableInstance2 papyrusTable2 = papyrusTable.getTable();

    /*
     * Has the target resource been loaded, and is it in read only mode ?
     */
    if (editingDomain.isReadOnly(target)) {
      return;
    }

    /*
     * Moving both the table instance and the table2 instance.
     */
    if (target != null) {
      MoveOpenableCommand mvTabCmd =
          new MoveOpenableCommand(
              editingDomain, "moving table", papyrusTable, target); // $NON-NLS-1$
      if (mvTabCmd != null && mvTabCmd.canExecute()) {
        commandToModify.append(new GMFtoEMFCommandWrapper(mvTabCmd));
      }

      MoveOpenableCommand mvTab2Cmd =
          new MoveOpenableCommand(
              editingDomain, "moving table2", papyrusTable2, target); // $NON-NLS-1$
      if (mvTab2Cmd != null && mvTab2Cmd.canExecute()) {
        commandToModify.append(new GMFtoEMFCommandWrapper(mvTab2Cmd));
      }
    }
  }
 /**
  * Creates and returns a command to remove the interface and associated inherited interfaces if
  * they are not referenced by other ports.
  *
  * @param i the {@link Interface} to remove
  * @param removePorts the {@link Uses} or {@link Provides} to ignore when considering which
  *     interfaces to remove
  * @param removeInterfaces the {@link Set} of repIds already scheduled for removal
  * @return a {@link Command} to remove the specified {@link Interface} and {@link
  *     InheritsInterface} if they can be removed
  */
 public Command createRemoveInterfaceCommand(
     final Collection<EObject> removePorts,
     final Set<String> removeInterfaces,
     final Interface i) {
   if (!containsRepId(i.getRepid(), removePorts)) {
     final CompoundCommand command = new CompoundCommand("Remove Interfaces");
     for (final InheritsInterface inherited : i.getInheritsInterfaces()) {
       if (!containsRepId(inherited.getRepid(), removePorts)) {
         if (!removeInterfaces.contains(inherited.getRepid())) {
           // If the inherited interface isn't referenced by another port and isn't already
           // scheduled for
           // removal, make a recursive call to remove it
           if (inherited.getInterface() != null) {
             command.append(
                 this.createRemoveInterfaceCommand(
                     removePorts, removeInterfaces, inherited.getInterface()));
           }
         }
       }
     }
     // If the interface isn't already scheduled for removal, create a command to remove it
     if (removeInterfaces.add(i.getRepid())) {
       command.append(
           RemoveCommand.create(
               this.editingDomain,
               PortsHandlerUtil.getInterfaces(this.softPkg),
               ScdPackage.Literals.INTERFACES__INTERFACE,
               i));
     }
     return command;
   }
   return null;
 }
  @Override
  public Command createCommand(Collection<?> selection) {
    EStructuralFeature ef = feature;
    EObject owner = (EObject) viewer.getInput();
    if (domain.getClipboard() == null) {
      return UnexecutableCommand.INSTANCE;
    }
    Collection<Object> objs = getPasteObjs(EcoreUtil.copyAll(domain.getClipboard()), eclass);
    if (objs.size() > 0) {
      if (!MetadataViewerUtil.isShowCategory(viewer)) {
        return AddCommand.create(getEditingDomain(), owner, ef, objs);
      }
      MetadataCategory cate = MetadataViewerUtil.getSelectedCategory(viewer, false);
      if (cate instanceof UncategorizedItemsCategoryImpl) {
        return AddCommand.create(getEditingDomain(), owner, ef, objs);
      } else if (cate instanceof MetadataCategory) {
        CompoundCommand command = new CompoundCommand();
        command.append(
            AddCommand.create(
                getEditingDomain(), cate, MetadataPackage.Literals.METADATA_CATEGORY__ITEMS, objs));

        command.append(AddCommand.create(getEditingDomain(), owner, ef, objs));
        // 再添加到分组

        return command;
      }
    }
    return UnexecutableCommand.INSTANCE;
  }
  /** {@inheritDoc} */
  public void uncontrol(
      EditingDomain domain,
      final EObject selection,
      STATE_CONTROL state,
      Resource source,
      final Resource target,
      CompoundCommand commandToModify) {
    switch (state) {
      case PRE_MODEL:
        commandToModify.append(
            new ChangeCommand(
                domain,
                new Runnable() {

                  public void run() {
                    unapplyDuplicateProfiles(selection, target);
                  }
                }));
        break;
      case POST_MODEL:
        commandToModify.append(
            new ChangeCommand(
                domain,
                new Runnable() {

                  public void run() {
                    ProfileApplicationHelper.relocateStereotypeApplications(
                        (Package) selection, target);
                  }
                }));
        break;
      default:
    }
  }
 protected void createCommand(Object oldValue, Object newValue) {
   boolean equals = oldValue == null ? false : oldValue.equals(newValue);
   if (!equals) {
     EditingDomain editingDomain = getEditingDomain();
     CompoundCommand compoundCommand = new CompoundCommand(COMMAND_NAME);
     // apply the property change to all selected elements
     for (EObject nextObject : getEObjectList()) {
       compoundCommand.append(
           SetCommand.create(editingDomain, nextObject, getFeature(), newValue));
     }
     editingDomain.getCommandStack().execute(compoundCommand);
   }
 }
 /** @generated */
 protected Command createCommand() {
   TransactionalEditingDomain editingDomain =
       TransactionUtil.getEditingDomain(oldTarget.getDiagram().getElement());
   CompoundCommand result = new CompoundCommand();
   result.append(new ReconnectNotationalEdgeTargetCommand(edge, newTarget));
   result.append(
       SetCommand.create(
           editingDomain,
           edge.getElement(),
           imagindata.imagindataPackage.eINSTANCE.getTransition_End(),
           newTarget.getElement()));
   return result;
 }
  /**
   * @see
   *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    toSelect = new ArrayList<EObject>();
    IEditorPart editor = RequirementUtils.getCurrentEditor();
    IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor);
    CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage();

    if (services != null
        && ((EvaluationContext) event.getApplicationContext()).getDefaultVariable()
            instanceof List<?>) {
      EditingDomain editingDomain = services.getEditingDomain(editor);
      // Get the current selection
      List<?> elements =
          ((List<?>) ((EvaluationContext) event.getApplicationContext()).getDefaultVariable());
      CompoundCommand compoundCmd =
          new CompoundCommand(Messages.getString("AddAttributeHandler.1")); // $NON-NLS-1$
      for (Object currObject : elements) {
        EObject parent = null;
        if (currObject instanceof Attribute) {
          parent = ((Attribute) currObject).eContainer();
          int newIndex = calculateIndex(parent, (EObject) currObject);

          Attribute toDuplicate = null;
          if (currObject instanceof AttributeLink) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateAttributeLink((AttributeLink) currObject);
          } else if (currObject instanceof ObjectAttribute) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateObjectAttribute((ObjectAttribute) currObject);
          }
          if (parent != null && toDuplicate != null) {
            toSelect.add(toDuplicate);
            compoundCmd.appendIfCanExecute(
                AddCommand.create(
                    editingDomain,
                    parent,
                    RequirementPackage.eINSTANCE.getRequirement_Attribute(),
                    toDuplicate,
                    newIndex));
          }
        }
      }
      if (!compoundCmd.isEmpty() && compoundCmd.canExecute()) {
        editingDomain.getCommandStack().execute(compoundCmd);
        page.setSelection(new StructuredSelection(toSelect));
      }
    }
    return null;
  }
예제 #11
0
  /**
   * Forces this list to commit all the pending commands. Only one composite command will be
   * executed, and can be undone in a single operation.
   *
   * @see org.eclipse.papyrus.infra.widgets.editors.ICommitListener#commit(AbstractEditor)
   */
  public void commit(AbstractEditor editor) {

    if (commands.isEmpty()) {
      return;
    }

    CompoundCommand compoundCommand =
        new CompoundCommand() {

          @Override
          public void execute() {
            super.execute();
            refreshCacheList();
          }

          @Override
          public void undo() {
            super.undo();
            refreshCacheList();
          }

          @Override
          public void redo() {
            super.redo();
            refreshCacheList();
          }

          @Override
          protected boolean prepare() {
            if (commandList.isEmpty()) {
              return false;
            } else {
              // We only test the first command, as the following ones might depend
              // on the first command's execution. StrictCompoundCommands don't seem
              // to be compatible with emf transaction (execute() is called by
              // canExecute(), before the transaction is started)
              return commandList.get(0).canExecute();
            }
          }
        };

    for (Command cmd : commands) {
      compoundCommand.append(cmd);
    }

    editingDomain.getCommandStack().execute(compoundCommand);
    commands.clear();
  }
 @Override
 public void execute() {
   super.execute();
   if (this.originals != null && this.originals.size() != 0) {
     doCopyRelatedObjects();
   }
 }
예제 #13
0
 protected void updateLabel(FormElement fw, String name) {
   if (headless) {
     fw.setLabel(name);
   } else {
     cc.append(SetCommand.create(domain, fw, FormPackage.eINSTANCE.getFormElement_Label(), name));
   }
 }
예제 #14
0
  public void updateModelChoiceField(
      AbstractClass srcClazz, Association ass, ModelChoiceField mcf) {

    ModelChoiceField modelChoiceFieldForAssociation =
        ClassDiagramUtils.getModelChoiceFieldForAssociation(ass, srcClazz);

    int parseInt = modelChoiceFieldForAssociation.getMax_bound();
    // at least bounds must be compatible with constraints in the dt model
    boolean b = (((ModelChoiceField) mcf).getMax_bound() > parseInt) && (parseInt != -1);
    if (headless) {
      if (b) {
        mcf.setMax_bound(parseInt);
      }
    } else {
      if (b) {
        cc.append(
            SetCommand.create(
                domain, mcf, FormPackage.eINSTANCE.getModelChoiceField_Max_bound(), parseInt));
      }
    }
    // maybe the name or Label have been changed must be based on target name/Label if exists
    String id = modelChoiceFieldForAssociation.getId();
    if (updateId && !id.equals(mcf.getId())) {
      updateId(mcf, id);
    }
    String label = modelChoiceFieldForAssociation.getLabel();
    if (updateLabel && !label.equals(mcf.getLabel())) {
      updateLabel(mcf, label);
    }
  }
예제 #15
0
  public void updateAttributeFields(
      FormContainer formContainer, FormElement formElement, Attribute att) {
    FormElement fieldForAttribute = null;
    if (formContainer instanceof FormSearch) {
      fieldForAttribute = SearchInitialization.getSearchFieldForAttribute(att);
    } else if (formContainer instanceof FormClass || formContainer instanceof FormWorkflow) {
      fieldForAttribute = ClassDiagramUtils.getFieldForAttribute(att);
    }

    if (!fieldForAttribute.getClass().isInstance(formElement)) {
      // mismatch so we replace the Field
      FormGroup eContainer = (FormGroup) formElement.eContainer();
      boolean contains = eContainer.getChildren().contains(formElement);

      if (headless) {
        EList<FormElement> children = null;
        if (contains) {
          children = eContainer.getChildren();
        } else {
          children = eContainer.getDisabled();
        }
        // add the new Field
        children.add(fieldForAttribute);
        // remove
        children.remove(formElement);
      } else {
        if (contains) {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Children(),
                  fieldForAttribute));
        } else {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Disabled(),
                  fieldForAttribute));
        }
        Command rmCmd = RemoveCommand.create(domain, formElement);
        cc.append(rmCmd);
      }
    }
  }
  /**
   * Persists components. Stores EventBComponents as an extension in a machine.
   *
   * @param document
   */
  private void doSaveComponents(IDocument document) {
    ComponentDiagram diagram =
        (ComponentDiagram) ((IDiagramDocument) document).getDiagram().getElement();
    final TransactionalEditingDomain domain = ((IDiagramDocument) document).getEditingDomain();
    CompoundCommand compoundCmd = new CompoundCommand();

    for (final Component comp : diagram.getComponents()) {
      if (comp instanceof EventBComponent && ((EventBComponent) comp).getMachine() != null) {

        // adds command to extend Event-B machine with component config
        // NOTE: replaces existing extension of the same id
        compoundCmd.append(
            new RecordingCommand(domain) {
              @Override
              protected void doExecute() {
                EventBComponent compCopy = (EventBComponent) EcoreUtil.copy(comp);
                try {
                  Resource resource =
                      domain.getResourceSet().getResource(compCopy.getMachine().getURI(), true);

                  if (resource != null && resource.isLoaded()) {
                    Machine machine = (Machine) resource.getContents().get(0);

                    // remove any existing extensions of the same id (EventB component)
                    Iterator<AbstractExtension> it = machine.getExtensions().iterator();
                    while (it.hasNext()) {
                      if (ComponentsPackage.EVENTB_COMPONENT_EXTENSION_ID.equals(
                          it.next().getExtensionId())) {
                        it.remove();
                      }
                    }
                    //								compCopy.setReference(ComponentsPackage.EVENTB_COMPONENT_EXTENSION_ID
                    //										+ "." + EcoreUtil.generateUUID());
                    machine.getExtensions().add(compCopy);
                    resource.save(Collections.EMPTY_MAP);
                  }
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            });
      }
    }
    domain.getCommandStack().execute(compoundCmd);
  }
 /**
  * Create the expected model from the input model
  *
  * @throws InputModelInvalidException error during expected model initialization
  * @throws IOException error during expected model serialization
  */
 protected void initializeRemoveExpectedModelForLinkEndCreationDataValue()
     throws InputModelInvalidException, IOException {
   // Create the expected model content by applying the attempted command on a copy of the input
   // model content
   createExpectedModel();
   EObject linkEndCreationData =
       EEFTestsModelsUtils.getFirstInstanceOf(expectedModel, linkEndCreationDataMetaClass);
   if (linkEndCreationData == null)
     throw new InputModelInvalidException(linkEndCreationDataMetaClass.getName());
   CompoundCommand cc = new CompoundCommand();
   allInstancesOf = EEFTestsModelsUtils.getAllInstancesOf(expectedModel, inputPinMetaClass);
   cc.append(
       SetCommand.create(
           editingDomain, linkEndCreationData, UMLPackage.eINSTANCE.getLinkEndData_Value(), null));
   editingDomain.getCommandStack().execute(cc);
   expectedModel.save(Collections.EMPTY_MAP);
 }
  @Override
  public ICommand getReconcileCommand(Diagram diagram) {
    try {

      CompoundCommand cc =
          new CompoundCommand("Update Internal Block Diagram From Undefined To 1.0.0");

      Command updateCommandFromUndefinedTo_081 = getUpdateCommandFromUndefinedTo_081(diagram);
      Command updateCommandFrom081To_091 = getUpdateCommandFrom081To_091(diagram);
      cc.append(updateCommandFromUndefinedTo_081);
      cc.append(updateCommandFrom081To_091);

      return EMFtoGMFCommandWrapper.wrap(cc);
    } catch (Exception e) {
      Activator.log.error(e);
      return UnexecutableCommand.INSTANCE;
    }
  }
예제 #19
0
 protected void updateId(FormElement fw, String computeFormWorkflowId) {
   if (headless) {
     fw.setId(computeFormWorkflowId);
   } else {
     cc.append(
         SetCommand.create(
             domain, fw, FormPackage.eINSTANCE.getFormElement_Id(), computeFormWorkflowId));
   }
 }
 /* (non-Javadoc)
  * @see org.bonitasoft.studio.configuration.AbstractConnectorConfigurationSynchronizer#updateJarDependencies(org.bonitasoft.studio.model.configuration.FragmentContainer, org.bonitasoft.studio.connector.model.implementation.ConnectorImplementation, org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.emf.common.command.CompoundCommand)
  */
 @Override
 protected void updateJarDependencies(
     FragmentContainer connectorContainer,
     ConnectorImplementation implementation,
     EditingDomain editingDomain,
     CompoundCommand cc,
     boolean forceDriver) {
   super.updateJarDependencies(connectorContainer, implementation, editingDomain, cc, forceDriver);
   store =
       (DatabaseConnectorPropertiesRepositoryStore)
           RepositoryManager.getInstance()
               .getRepositoryStore(DatabaseConnectorPropertiesRepositoryStore.class);
   DatabaseConnectorPropertiesFileStore fileStore =
       (DatabaseConnectorPropertiesFileStore)
           store.getChild(
               implementation.getDefinitionId()
                   + "."
                   + DatabaseConnectorPropertiesRepositoryStore.CONF_EXT);
   if (fileStore != null) {
     String defaultDriver = fileStore.getDefault();
     List<String> jars = fileStore.getJarList();
     boolean autoAddDriver = fileStore.getAutoAddDriver() || forceDriver;
     Configuration conf = (Configuration) connectorContainer.eContainer().eContainer();
     FragmentContainer otherDependencies = null;
     for (FragmentContainer c : conf.getProcessDependencies()) {
       if (FragmentTypes.OTHER.equals(c.getId())) {
         otherDependencies = c;
       }
     }
     for (String jar : jars) {
       boolean exists = false;
       for (Fragment dep : otherDependencies.getFragments()) {
         if (dep.getValue().equals(jar)) {
           exists = true;
           break;
         }
       }
       if (!exists) {
         Fragment depFragment = ConfigurationFactory.eINSTANCE.createFragment();
         if (jar.equals(defaultDriver) && autoAddDriver) {
           depFragment.setExported(true);
         } else {
           depFragment.setExported(false);
         }
         depFragment.setKey(jar);
         depFragment.setValue(jar);
         depFragment.setType(FragmentTypes.JAR);
         cc.append(
             AddCommand.create(
                 editingDomain,
                 otherDependencies,
                 ConfigurationPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS,
                 depFragment));
       }
     }
   }
 }
  private void runRevealCommand(
      final RootEditPart root, final DDiagramEditor editor, final DDiagramElement vpe) {

    final Object adapter = editor.getAdapter(IDiagramCommandFactoryProvider.class);
    final IDiagramCommandFactoryProvider cmdFactoryProvider =
        (IDiagramCommandFactoryProvider) adapter;
    final TransactionalEditingDomain transactionalEditingDomain =
        TransactionUtil.getEditingDomain(editor.getEditingDomain().getResourceSet());
    final IDiagramCommandFactory emfCommandFactory =
        cmdFactoryProvider.getCommandFactory(transactionalEditingDomain);
    final Command cmd = emfCommandFactory.buildRevealCommand(vpe);

    final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(vpe);

    CompoundCommand allInOne = new CompoundCommand(cmd.getLabel());
    allInOne.append(cmd);

    domain.getCommandStack().execute(allInOne);
  }
예제 #22
0
  /**
   * In addition to the regular functionality (creating a SpecHierarchy child object), this method
   * allows a SpecObject or a SpecType as an argument: Note that this is almost the same as {@link
   * SpecificationItemProvider#createCreateChildCommand(EditingDomain, EObject, EStructuralFeature,
   * Object, int, Collection)} .
   *
   * @param value instanceof {@link SpecType}: A new SpecObject with the given SpecType is created,
   *     and a SpecHierarchy is added that is associated with the newly created SpecObject.
   * @param value instanceof {@link SpecObject}: The SpecObject is added to a new SpecHierarchy,
   *     which is then added.
   */
  @Override
  protected Command createCreateChildCommand(
      EditingDomain domain,
      EObject owner,
      EStructuralFeature feature,
      Object value,
      int index,
      Collection<?> collection) {

    if (value instanceof SpecType) {
      ReqIFContent content = ReqIF10Util.getReqIF(owner).getCoreContent();
      SpecObject specObject = ReqIF10Factory.eINSTANCE.createSpecObject();
      SpecHierarchy specHierarchy = ReqIF10Factory.eINSTANCE.createSpecHierarchy();

      CompoundCommand cmd =
          ProrUtil.createAddTypedElementCommand(
              content,
              REQ_IF_CONTENT__SPEC_OBJECTS,
              specObject,
              SPEC_OBJECT__TYPE,
              (SpecType) value,
              -1,
              3,
              domain,
              adapterFactory);
      cmd.append(AddCommand.create(domain, owner, SPEC_HIERARCHY__CHILDREN, specHierarchy, index));
      cmd.append(SetCommand.create(domain, specHierarchy, SPEC_HIERARCHY__OBJECT, specObject));
      return cmd;
    }
    if (value instanceof SpecObject) {
      Object icon = ProrUtil.getItemProvider(adapterFactory, value).getImage(value);
      CompoundCommand cmd = ProrUtil.createCompoundCommandWithAddIcon(icon, 0);
      cmd.setLabel("Adding SpecObject");
      cmd.setDescription("Adding SpecObject");
      SpecHierarchy specHierarchy = ReqIF10Factory.eINSTANCE.createSpecHierarchy();
      cmd.append(AddCommand.create(domain, owner, SPEC_HIERARCHY__CHILDREN, specHierarchy, index));
      cmd.append(
          AddCommand.create(
              domain,
              ReqIF10Util.getReqIF(owner).getCoreContent(),
              REQ_IF_CONTENT__SPEC_OBJECTS,
              value));
      cmd.append(SetCommand.create(domain, specHierarchy, SPEC_HIERARCHY__OBJECT, value));
      return cmd;
    }

    return super.createCreateChildCommand(domain, owner, feature, value, index, collection);
  }
  /** Clear links */
  @SuppressWarnings({"rawtypes", "unchecked"})
  private static void clearLinks() {
    Collection values =
        getDiagramEditor().getDiagramGraphicalViewer().getEditPartRegistry().values();
    Iterator iterator = values.iterator();
    CompoundCommand ccModel = new CompoundCommand();
    org.eclipse.gef.commands.CompoundCommand ccView =
        new org.eclipse.gef.commands.CompoundCommand();

    while (iterator.hasNext()) {
      Object editPart = iterator.next();
      if (editPart instanceof EsbLinkEditPart) {
        EsbLinkEditPart linkEditPart = (EsbLinkEditPart) editPart;
        /*
         * We shouldn't remove EsbLinkEditParts if the target of the link is a AbstractEndpointInputConnectorEditPart.
         * Because these kind of links will not be get regenerated again according to the current implementation.
         */
        if (linkEditPart.getTarget() instanceof AbstractEndpointInputConnectorEditPart) {
          continue;
        }
        Collection linkCollection = new ArrayList();
        linkCollection.add(((ConnectorImpl) linkEditPart.getModel()).getElement());
        org.eclipse.emf.edit.command.DeleteCommand modelDeleteCommand =
            new org.eclipse.emf.edit.command.DeleteCommand(
                getDiagramEditor().getEditingDomain(), linkCollection);
        if (modelDeleteCommand.canExecute()) {
          ccModel.append(modelDeleteCommand);
        }
        DeleteCommand viewDeleteCommand = new DeleteCommand(linkEditPart.getNotationView());
        if (viewDeleteCommand.canExecute()) {
          ccView.add(new ICommandProxy(viewDeleteCommand));
        }
      }
    }

    if (ccModel.canExecute()) {
      getDiagramEditor().getEditingDomain().getCommandStack().execute(ccModel);
    }
    if (ccView.canExecute()) {
      getDiagramEditor().getDiagramEditDomain().getDiagramCommandStack().execute(ccView);
    }
  }
 /**
  * {@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 ((talk != null) && (basePart != null)) {
     cc.append(
         SetCommand.create(
             editingDomain,
             talk,
             NonregPackage.eINSTANCE.getTalk_Presenter(),
             basePart.getCombo()));
     cc.append(
         SetCommand.create(
             editingDomain,
             talk,
             NonregPackage.eINSTANCE.getTalk_Presenter(),
             basePart.getComboRO()));
   }
   if (!cc.isEmpty()) return cc;
   cc.append(IdentityCommand.INSTANCE);
   return cc;
 }
예제 #25
0
  void removeInvalide(EObject o) {
    CompoundCommand removeCommands = new CompoundCommand();
    List<EObject> validationErrors = EcoreHelper.getValidationErrors(o);
    for (EObject eObject : validationErrors) {
      if (eObject instanceof FormElement) {

        System.out.println("SynchronizeWithClass.removeInvalide() remove :" + eObject);
        if (headless) {
          EList<?> children = null;
          EObject eContainer = eObject.eContainer();
          System.out.println("SynchronizeWithClass.removeInvalide() eContainer :" + eContainer);
          if (eContainer != null) {
            if (eContainer instanceof FormGroup) {
              FormGroup fg = (FormGroup) eContainer;

              if (fg.getChildren().contains(eObject)) {
                children = fg.getChildren();
              } else if (fg.getDisabled().contains(eObject)) {
                children = fg.getDisabled();
              }
            } else if (eContainer instanceof FormCollection) {
              children = ((FormCollection) eContainer).getForms();
            }

            boolean remove = children.remove(eObject);
            System.out.println("SynchronizeWithClass.removeInvalide() removed? " + remove);
          } else {
            System.out.println("SynchronizeWithClass.removeInvalide() allready removed !");
          }

        } else {
          Command delCmd = RemoveCommand.create(domain, eObject);
          removeCommands.append(delCmd);
        }
      }
    }
    if (!headless) {
      domain.getCommandStack().execute(removeCommands);
    }
  }
  /**
   * {@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);
    }
  }
  /**
   * Creates and returns a command to remove the specified ports.
   *
   * @param ports the ports to remove from the {@link mil.jpeojtrs.sca.scd.SoftwareComponent}
   * @param ignoreIds ignore the specified repIds when considering which interfaces to remove
   * @return the {@link Command} to remove the port and all associated {@link Interface}
   */
  public Command createRemovePortCommand(
      final Collection<Object> ports, final Set<String> ignoreIds) {
    final Set<String> repIds = new HashSet<String>();
    final List<EObject> removePorts = new ArrayList<EObject>();
    final CompoundCommand command = new CompoundCommand("Remove Ports");
    for (final Object obj : ports) {
      final EObject port = (EObject) AdapterFactoryEditingDomain.unwrap(obj);
      if (port instanceof AbstractPort) {
        for (AbstractPort p : getPorts().getAllPorts()) {
          if (p.equals(port)) {
            final AbstractPort sibling = p.getSibling();
            if (sibling == null || !(p instanceof Uses)) {
              repIds.add(p.getRepID());
              command.append(
                  RemoveCommand.create(this.editingDomain, getPorts(), p.eContainingFeature(), p));
              if (sibling != null) {
                command.append(
                    RemoveCommand.create(
                        this.editingDomain, getPorts(), sibling.eContainingFeature(), sibling));
              }
              removePorts.add(p);
            }
          }
        }
      }
    }

    for (final String repId : repIds) {
      if (this.interfaceMap.containsKey(repId) && !ignoreIds.contains(repId)) {
        final Command interfaceCommand =
            this.createRemoveInterfaceCommand(removePorts, ignoreIds, this.interfaceMap.get(repId));
        if (interfaceCommand != null) {
          command.append(interfaceCommand);
          this.interfaceMap.remove(repId);
        }
      }
    }
    return command;
  }
예제 #28
0
  /** If a ReqIF has no labels yet, this method configures some smart defaults. */
  public static void setDefaultLabelsIfNecessary(
      AdapterFactory adapterFactory, EditingDomain editingDomain, ReqIF reqif) {
    CompoundCommand cmd = new CompoundCommand();

    ProrToolExtension extension = createProrToolExtension(reqif, editingDomain);
    ProrGeneralConfiguration generalConfig = extension.getGeneralConfiguration();
    if (generalConfig == null) {
      generalConfig = ConfigurationFactory.eINSTANCE.createProrGeneralConfiguration();
      cmd.append(
          SetCommand.create(
              editingDomain,
              extension,
              ConfigurationPackage.Literals.PROR_TOOL_EXTENSION__GENERAL_CONFIGURATION,
              generalConfig));
    }
    LabelConfiguration labelConfig = generalConfig.getLabelConfiguration();
    if (labelConfig == null) {
      labelConfig = ConfigurationFactory.eINSTANCE.createLabelConfiguration();
      cmd.append(
          SetCommand.create(
              editingDomain,
              generalConfig,
              ConfigurationPackage.Literals.PROR_GENERAL_CONFIGURATION__LABEL_CONFIGURATION,
              labelConfig));
    } else {
      // If there is already a label configuration, we leave it alone.
      return;
    }
    labelConfig.getDefaultLabel().add("ReqIF.ChapterNumber");
    labelConfig.getDefaultLabel().add("ReqIF.ChapterName");
    labelConfig.getDefaultLabel().add("ReqIF.Name");
    labelConfig.getDefaultLabel().add("ReqIF.Text");
    labelConfig.getDefaultLabel().add("ID");
    labelConfig.getDefaultLabel().add("Name");
    labelConfig.getDefaultLabel().add("Description");

    editingDomain.getCommandStack().execute(cmd);
  }
  /**
   * {@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 (NonregViewsRepository.Combo.combo == event.getAffectedEditor())
          command.append(
              SetCommand.create(
                  liveEditingDomain,
                  talk,
                  NonregPackage.eINSTANCE.getTalk_Presenter(),
                  event.getNewValue()));
        if (NonregViewsRepository.Combo.comboRO == event.getAffectedEditor())
          command.append(
              SetCommand.create(
                  liveEditingDomain,
                  talk,
                  NonregPackage.eINSTANCE.getTalk_Presenter(),
                  event.getNewValue()));

        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);
    }
  }
예제 #30
0
  public void synchronize(FormCollection fc) throws Exception {
    InternalModification.dontMoveToDisabled();
    removeInvalide(fc);

    EList<FormContainer> forms = fc.getForms();
    for (FormContainer formContainer : forms) {
      synchronizeFormContainer(formContainer);
    }

    // add Missing FormClass (new Class in dt model)

    if (addNewFormClass) {
      // get All Class
      Collection<AbstractClass> missing = getAllClassesFromReferedModels(fc);
      for (AbstractClass abstractClass : missing) {

        if (!(abstractClass instanceof Clazz) ^ !((Clazz) abstractClass).isAbstract()) {
          FormContainer formContainer = null;

          if (!CommonServices.isNativeModel(abstractClass) || includeAlfrescoNativeClass) {

            if (fc instanceof ClassFormCollection) {
              formContainer = FormFactory.eINSTANCE.createFormClass();
              setFormContainer(abstractClass, formContainer);
              formContainer.setId(abstractClass.getName());
              formContainer.setLabel(abstractClass.getLabel());
            } else if (fc instanceof SearchFormCollection) {
              formContainer = FormFactory.eINSTANCE.createFormSearch();
              setFormContainer(abstractClass, formContainer);
              SearchInitialization.initializeFormProperties((FormSearch) formContainer);
            } else if (fc instanceof WorkflowFormCollection) {
              formContainer = FormFactory.eINSTANCE.createFormWorkflow();
            }

            if (headless) {
              fc.getForms().add(formContainer);
            } else {
              cc.append(
                  AddCommand.create(
                      domain, fc, FormPackage.eINSTANCE.getFormCollection_Forms(), formContainer));
            }
            if (formContainer instanceof ClassReference) {
              synchronizeFormContainer(formContainer);
            }
          }
        }
      }
    }
    InternalModification.moveToDisabled();
  }