/**
  * 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 Object execute(ExecutionEvent event) throws ExecutionException {
   ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
   if (!selection.isEmpty()) {
     IStructuredSelection sSelection = (IStructuredSelection) selection;
     boolean confirmed =
         MessageDialog.openConfirm(
             HandlerUtil.getActiveShell(event),
             "Confirm Delete",
             "Please confirm that you wish to delete this metadata.");
     if (!confirmed) return null;
     MetsProjectNature mpn =
         MetsProjectNature.getNatureForMetsObject((EObject) sSelection.getFirstElement());
     HashSet<SmLinkType> del = new HashSet<SmLinkType>();
     Iterator it = sSelection.iterator();
     while (it.hasNext()) {
       Object sel = it.next();
       if (sel instanceof SmLinkType) {
         del.add((SmLinkType) sel);
       }
     }
     Command c =
         RemoveCommand.create(
             mpn.getEditingDomain(),
             mpn.getMets().getStructLink(),
             MetsPackage.eINSTANCE.getStructLinkType_SmLink(),
             del);
     mpn.getCommandStack().execute(c);
   }
   return null;
 }
 public ICommand remove(IModelElement owner, String property, Object value) {
   return new EMFCommand(
       RemoveCommand.create(
           fEditDomain,
           ((EMFModelElement) owner).getEMFObject(),
           ((EMFModelElement) owner).getEMFFeatureForProperty(property),
           EMFModel.getEMFObjectForModel(value)));
 }
  public void testRemoveEqualValues() {
    E e = refFactory.createE();

    String s0 = "0";
    String s1 = "1";
    String s2 = "2";
    String s3 = new String(s1);

    EList<String> labels = e.getLabels();
    labels.add(s0);
    labels.add(s1);
    labels.add(s3);
    labels.add(s2);
    labels.add(s1);

    Collection<String> collection = new ArrayList<String>();
    collection.add(s1);
    collection.add(s1);
    collection.add(s1);

    Command remove = RemoveCommand.create(editingDomain, e, refPackage.getE_Labels(), collection);

    assertEquals(5, labels.size());
    assertSame(s0, labels.get(0));
    assertSame(s1, labels.get(1));
    assertSame(s3, labels.get(2));
    assertSame(s2, labels.get(3));
    assertSame(s1, labels.get(4));
    assertNotSame(s1, labels.get(2));
    assertTrue(remove.canExecute());

    CommandStack stack = editingDomain.getCommandStack();
    stack.execute(remove);

    assertEquals(2, labels.size());
    assertSame(s0, labels.get(0));
    assertSame(s2, labels.get(1));
    assertTrue(stack.canUndo());

    stack.undo();

    assertEquals(5, labels.size());
    assertSame(s0, labels.get(0));
    assertSame(s1, labels.get(1));
    assertSame(s3, labels.get(2));
    assertSame(s2, labels.get(3));
    assertSame(s1, labels.get(4));
    assertNotSame(s1, labels.get(2));
    assertTrue(stack.canRedo());

    stack.redo();

    assertEquals(2, labels.size());
    assertSame(s0, labels.get(0));
    assertSame(s2, labels.get(1));
    assertTrue(stack.canUndo());
  }
  /**
   * 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;
  }
예제 #6
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);
      }
    }
  }
예제 #7
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);
    }
  }
예제 #8
0
 public Command getRemoveAllCommand(Collection<?> values) {
   return RemoveCommand.create(editingDomain, source, feature, values);
 }
예제 #9
0
 public Command getRemoveCommand(Object value) {
   return RemoveCommand.create(editingDomain, source, feature, value);
 }
  /**
   * Drop a semantic element and create the corresponding view in the given container
   *
   * @param newContainer Semantic container
   * @param semanticElement Element to drop
   * @param containerView Container view
   * @param moveSemanticElement True to move the dropped semantic element or false to just show the
   *     element on a diagram
   */
  private void drop(
      final Element newContainer,
      final Element semanticElement,
      final DSemanticDecorator containerView,
      boolean moveSemanticElement) {
    final Session session = SessionManager.INSTANCE.getSession(newContainer);
    final Element oldContainer = semanticElement.getOwner();
    if (moveSemanticElement && oldContainer != newContainer) {
      // Manage stereotypes and profiles
      final List<Stereotype> stereotypesToApply = Lists.newArrayList();
      for (final Stereotype stereotype : semanticElement.getAppliedStereotypes()) {
        stereotypesToApply.add(stereotype);
      }

      // Move the semantic element to the selected container
      final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
      // The feature is set to null because the domain will deduce it
      Command cmd = AddCommand.create(domain, newContainer, null, semanticElement);
      if (cmd.canExecute()) {
        cmd.execute();
      }
      cmd = RemoveCommand.create(domain, oldContainer, null, semanticElement);
      if (cmd.canExecute()) {
        cmd.execute();
      }

      if (semanticElement instanceof UseCase) {
        // Reset the current element as subject
        cmd =
            SetCommand.create(
                domain,
                semanticElement,
                UMLPackage.Literals.USE_CASE__SUBJECT,
                SetCommand.UNSET_VALUE);
        if (cmd.canExecute()) {
          cmd.execute();
        }
        final List<Element> subjects = new ArrayList<Element>();
        subjects.add(newContainer);
        cmd =
            SetCommand.create(
                domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, subjects);
        if (cmd.canExecute()) {
          cmd.execute();
        }
      }
      // Apply stereotypes on dropped element and apply the necessary
      // profiles automatically
      StereotypeServices.INSTANCE.applyAllStereotypes(semanticElement, stereotypesToApply);

      // Check if profile should be unapplied
      for (final Stereotype stereotype : stereotypesToApply) {
        StereotypeServices.INSTANCE.unapplyProfile(oldContainer, stereotype);
      }
    }

    // Show the semantic element on the diagram
    showView(
        semanticElement,
        containerView,
        session,
        "[self.getContainerView(newContainerView)/]"); //$NON-NLS-1$
  }
예제 #11
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.wizard.Wizard#performFinish()
   */
  @Override
  public boolean performFinish() {
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(container);
    Data workingCopy = page.getWorkingCopy();
    setDatasourceId(workingCopy, dataContainmentFeature);
    if (editMode) {
      AbstractProcess process = ModelHelper.getParentProcess(container);
      CompoundCommand cc = new CompoundCommand();
      final RefactorDataOperation op =
          new RefactorDataOperation(BonitaGroovyRefactoringAction.REFACTOR_OPERATION);
      op.setCompoundCommand(cc);
      op.setEditingDomain(editingDomain);
      op.setContainer(process);
      op.setNewData(workingCopy);
      op.setOldData(originalData);
      op.updateReferencesInScripts();
      final boolean switchingDataeClass = !originalData.eClass().equals(workingCopy.eClass());
      op.setUpdateDataReferences(switchingDataeClass);
      if (op.isCanExecute()) {
        try {

          getContainer().run(true, false, op);

        } catch (InvocationTargetException e) {
          BonitaStudioLog.error(e);
        } catch (InterruptedException e) {
          BonitaStudioLog.error(e);
        }

        if (switchingDataeClass) {
          List<?> dataList = (List<?>) container.eGet(dataContainmentFeature);
          int index = dataList.indexOf(originalData);
          cc.append(
              RemoveCommand.create(editingDomain, container, dataContainmentFeature, originalData));
          cc.append(
              AddCommand.create(
                  editingDomain, container, dataContainmentFeature, workingCopy, index));
        } else {
          for (EStructuralFeature feature : originalData.eClass().getEAllStructuralFeatures()) {
            cc.append(
                SetCommand.create(editingDomain, originalData, feature, workingCopy.eGet(feature)));
          }
        }

        editingDomain.getCommandStack().execute(cc);
      } else {
        cc.dispose();
      }
    } else {
      editingDomain
          .getCommandStack()
          .execute(
              AddCommand.create(editingDomain, container, dataContainmentFeature, workingCopy));
    }
    try {
      RepositoryManager.getInstance()
          .getCurrentRepository()
          .getProject()
          .build(
              IncrementalProjectBuilder.FULL_BUILD,
              XtextProjectHelper.BUILDER_ID,
              Collections.EMPTY_MAP,
              null);
    } catch (CoreException e) {
      BonitaStudioLog.error(e, DataPlugin.PLUGIN_ID);
    }

    return true;
  }
예제 #12
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))));
    }
  }