Java Code Examples for org.eclipse.emf.common.command.CompoundCommand#appendIfCanExecute()

The following examples show how to use org.eclipse.emf.common.command.CompoundCommand#appendIfCanExecute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorUsername(
        final org.bonitasoft.studio.actors.model.organization.Membership oldMembership,
        final org.bonitasoft.studio.actors.model.organization.Membership newMembership,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Users users = ac.getUsers();
        if (users != null) {
            if (users.getUser().contains(oldMembership.getUserName())) {
                cc.appendIfCanExecute(new ReplaceCommand(editingDomain, users.getUser(),
                        oldMembership.getUserName(), newMembership.getUserName()));
            }
        }
    }
    return cc;
}
 
Example 2
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorMembership(final Role oldRole, final Role newRole,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Membership memberships = ac.getMemberships();
        if (memberships != null) {
            for (final MembershipType membershipType : memberships.getMembership()) {
                if (membershipType.getRole().equals(oldRole.getName())) {
                    cc.appendIfCanExecute(SetCommand.create(editingDomain, membershipType,
                            ActorMappingPackage.Literals.MEMBERSHIP_TYPE__ROLE, newRole.getName()));
                }
            }
        }
    }
    return cc;
}
 
Example 3
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorMembership(final Group oldGroup, final Group newGroup,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Membership memberships = ac.getMemberships();
        if (memberships != null) {
            for (final MembershipType membershipType : memberships.getMembership()) {
                if (membershipType.getGroup().equals(GroupContentProvider.getGroupPath(oldGroup))) {
                    cc.appendIfCanExecute(SetCommand.create(editingDomain, membershipType,
                            ActorMappingPackage.Literals.MEMBERSHIP_TYPE__GROUP,
                            GroupContentProvider.getGroupPath(newGroup)));
                }
            }
        }
    }
    return cc;
}
 
Example 4
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorUsername(final User oldUser, final User newUser,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Users users = ac.getUsers();
        if (users != null) {
            if (users.getUser().contains(oldUser.getUserName())) {
                cc.appendIfCanExecute(RemoveCommand.create(editingDomain, users,
                        ActorMappingPackage.Literals.USERS__USER, oldUser.getUserName()));
                cc.appendIfCanExecute(AddCommand.create(editingDomain, users,
                        ActorMappingPackage.Literals.USERS__USER, newUser.getUserName()));
            }
        }
    }
    if (Objects.equals(configuration.getUsername(), oldUser.getUserName())) {
        cc.appendIfCanExecute(SetCommand.create(editingDomain, configuration,
                ConfigurationPackage.Literals.CONFIGURATION__USERNAME, newUser.getUserName()));
    }
    return cc;
}
 
Example 5
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Command refactorGroup(Group oldGroup, Group newGroup, Configuration configuration,
        EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Groups groups = ac.getGroups();
        if (groups != null) {
            if (groups.getGroup().contains(GroupContentProvider.getGroupPath(oldGroup))) {
                cc.appendIfCanExecute(RemoveCommand.create(editingDomain, groups,
                        ActorMappingPackage.Literals.GROUPS__GROUP, GroupContentProvider.getGroupPath(oldGroup)));
                cc.appendIfCanExecute(AddCommand.create(editingDomain, groups,
                        ActorMappingPackage.Literals.GROUPS__GROUP, GroupContentProvider.getGroupPath(newGroup)));
                //                    cc.append(new ReplaceCommand(editingDomain, groups.getGroup(), GroupContentProvider.getGroupPath(oldGroup),
                //                            GroupContentProvider.getGroupPath(newGroup)));
            }
        }
    }
    return cc;
}
 
Example 6
Source File: ContractInputGenerationWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected CompoundCommand createCommand(final RootContractInputGenerator contractInputGenerator,
        final BusinessObjectData data, List<ContractConstraint> constraints) {
    final CompoundCommand cc = new CompoundCommand();
    cc.append(AddCommand.create(editingDomain, contractContainer.getContract(),
            ProcessPackage.Literals.CONTRACT__INPUTS,
            contractInputGenerator.getRootContractInput()));
    cc.append(SetCommand.create(editingDomain, contractContainer.getContract(),
            ProcessPackage.Literals.CONTRACT__CONSTRAINTS,
            constraints));

    if (contractContainer instanceof OperationContainer
            && generationOptions.isAutoGeneratedScript()) {
        cc.appendIfCanExecute(AddCommand.create(editingDomain, contractContainer,
                ProcessPackage.Literals.OPERATION_CONTAINER__OPERATIONS,
                contractInputGenerator.getMappingOperations()));
    }
    if (contractContainer instanceof Pool && generationOptions.isAutoGeneratedScript()) {
        cc.appendIfCanExecute(SetCommand.create(editingDomain, data, ProcessPackage.Literals.DATA__DEFAULT_VALUE,
                contractInputGenerator.getInitialValueExpression()));

    }
    return cc;
}
 
Example 7
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Command refactorRole(final Role oldRole, final Role newRole,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Roles roles = ac.getRoles();
        if (roles != null) {
            if (roles.getRole().contains(oldRole.getName())) {
                cc.appendIfCanExecute(
                        new ReplaceCommand(editingDomain, roles.getRole(), oldRole.getName(), newRole.getName()));
            }
        }
    }
    return cc;
}
 
Example 8
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Command refactorGroup(final org.bonitasoft.studio.actors.model.organization.Membership oldMembership,
        final org.bonitasoft.studio.actors.model.organization.Membership newMembership,
        final Configuration configuration, EditingDomain editingDomain) {
    CompoundCommand cc = new CompoundCommand();
    for (ActorMapping ac : configuration.getActorMappings().getActorMapping()) {
        final Groups groups = ac.getGroups();
        if (groups != null) {
            if (groups.getGroup().contains(GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                    oldMembership.getGroupParentPath()))) {
                cc.appendIfCanExecute(
                        RemoveCommand.create(editingDomain, groups, ActorMappingPackage.Literals.GROUPS__GROUP,
                                GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                                        oldMembership.getGroupParentPath())));
                cc.appendIfCanExecute(
                        AddCommand.create(editingDomain, groups, ActorMappingPackage.Literals.GROUPS__GROUP,
                                GroupContentProvider.getGroupPath(newMembership.getGroupName(),
                                        newMembership.getGroupParentPath())));

                //                    cc.appendIfCanExecute(new ReplaceCommand(editingDomain, groups.getGroup(),
                //                            GroupContentProvider.getGroupPath(oldMembership.getGroupName(),
                //                                    oldMembership.getGroupParentPath()),
                //                            GroupContentProvider.getGroupPath(newMembership.getGroupName(),
                //                                    newMembership.getGroupParentPath())));
            }
        }
    }
    return cc;
}
 
Example 9
Source File: RefactorDocumentOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected CompoundCommand doBuildCompoundCommand(final CompoundCommand compoundCommand, final IProgressMonitor monitor) {
    final CompoundCommand deleteCommands = new CompoundCommand(
            "Compound commands containing all delete operations to do at last step");
    for (final DocumentRefactorPair pairToRefactor : pairsToRefactor) {
        doExecute(compoundCommand, deleteCommands, pairToRefactor);
    }
    compoundCommand.appendIfCanExecute(deleteCommands);
    return compoundCommand;
}
 
Example 10
Source File: RefactorActorMappingsOperation.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void refactorConfiguration(Configuration config, Comparison comparison,
        EditingDomain editingDomain) {
    final List<Diff> differences = comparison.getDifferences();
    for (final Diff difference : differences) {
        if (difference instanceof AttributeChange) {
            CompoundCommand cc = new CompoundCommand("Refactoring " + config.getName());
            final AttributeChange updateAttributeChange = (AttributeChange) difference;
            final Object oldElement = updateAttributeChange.getMatch().getRight();
            final Object newElement = updateAttributeChange.getMatch().getLeft();
            final EAttribute attribute = updateAttributeChange.getAttribute();
            if (OrganizationPackage.Literals.GROUP__NAME.equals(attribute)) {
                cc.appendIfCanExecute(refactorGroup((Group) oldElement, (Group) newElement, config, editingDomain));
                cc.appendIfCanExecute(
                        refactorMembership((Group) oldElement, (Group) newElement, config, editingDomain));
            } else if (OrganizationPackage.Literals.ROLE__NAME.equals(attribute)) {
                cc.appendIfCanExecute(refactorRole((Role) oldElement, (Role) newElement, config, editingDomain));
                cc.appendIfCanExecute(
                        refactorMembership((Role) oldElement, (Role) newElement, config, editingDomain));
            } else if (OrganizationPackage.Literals.USER__USER_NAME.equals(attribute)) {
                cc.appendIfCanExecute(
                        refactorUsername((User) oldElement, (User) newElement, config, editingDomain));
            } else if (OrganizationPackage.Literals.MEMBERSHIP__USER_NAME.equals(attribute)) {
                cc.appendIfCanExecute(
                        refactorUsername((org.bonitasoft.studio.actors.model.organization.Membership) oldElement,
                                (org.bonitasoft.studio.actors.model.organization.Membership) newElement, config,
                                editingDomain));
            } else if (OrganizationPackage.Literals.MEMBERSHIP__GROUP_NAME.equals(attribute)) {
                cc.appendIfCanExecute(
                        refactorGroup((org.bonitasoft.studio.actors.model.organization.Membership) oldElement,
                                (org.bonitasoft.studio.actors.model.organization.Membership) newElement, config,
                                editingDomain));
            } else if (OrganizationPackage.Literals.GROUP__PARENT_PATH.equals(attribute)) {
                cc.appendIfCanExecute(refactorGroup((Group) oldElement, (Group) newElement, config, editingDomain));
                cc.appendIfCanExecute(
                        refactorMembership((Group) oldElement, (Group) newElement, config, editingDomain));
            } else if (OrganizationPackage.Literals.MEMBERSHIP__GROUP_PARENT_PATH.equals(attribute)) {
                cc.appendIfCanExecute(
                        refactorGroup((org.bonitasoft.studio.actors.model.organization.Membership) oldElement,
                                (org.bonitasoft.studio.actors.model.organization.Membership) newElement, config,
                                editingDomain));
            }
            editingDomain.getCommandStack().execute(cc);
            cc.dispose();
        }
    }
}
 
Example 11
Source File: RefactorDataOperation.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected CompoundCommand doBuildCompoundCommand(final CompoundCommand compoundCommand,
        final IProgressMonitor monitor) {
    Assert.isNotNull(dataContainer);
    final CompoundCommand deleteCommands = new CompoundCommand(
            "Compound commands containing all delete operations to do at last step");
    for (final DataRefactorPair pairToRefactor : pairsToRefactor) {
        Assert.isNotNull(pairToRefactor.getOldValue());
        if (pairToRefactor.getNewValue() != null) {
            updateDataReferenceInVariableExpressions(compoundCommand);
            updateDataReferenceInExpressions(compoundCommand, !shouldUpdateReferencesInScripts(pairToRefactor));
            if (pairToRefactor.getNewValue() instanceof BusinessObjectData) {
                updateContractInputDataReference(compoundCommand, pairToRefactor,pairToRefactor.getNewValueName());
            }
            if (updateDataReferences) {
                updateDataReferenceInMultinstanciation(compoundCommand);
                final List<?> dataList = (List<?>) dataContainer.eGet(dataContainmentFeature);
                final int index = dataList.indexOf(pairToRefactor.getOldValue());
                compoundCommand
                        .append(RemoveCommand.create(getEditingDomain(), dataContainer, dataContainmentFeature,
                                pairToRefactor.getOldValue()));
                compoundCommand.append(AddCommand.create(getEditingDomain(), dataContainer, dataContainmentFeature,
                        pairToRefactor.getNewValue(), index));
            } else {
                if (updater != null) {
                    compoundCommand.append(updater.createUpdateCommand(getEditingDomain()));
                } else {
                    for (final EStructuralFeature feature : pairToRefactor.getOldValue().eClass()
                            .getEAllStructuralFeatures()) {
                        if (pairToRefactor.getNewValue().eClass().getEAllStructuralFeatures().contains(feature)) {
                            compoundCommand
                                    .append(SetCommand.create(getEditingDomain(), pairToRefactor.getOldValue(),
                                            feature, pairToRefactor.getNewValue()
                                                    .eGet(feature)));
                        }
                    }
                }
            }
        } else {
            removeAllDataReferences(compoundCommand, pairToRefactor);
        }
        if (RefactoringOperationType.REMOVE.equals(operationType)) {
            deleteCommands.append(DeleteCommand.create(getEditingDomain(), pairToRefactor.getOldValue()));
            if (pairToRefactor.getOldValue() instanceof BusinessObjectData) {
                updateContractInputDataReference(deleteCommands, pairToRefactor, null);
            }
        }
    }
    compoundCommand.appendIfCanExecute(deleteCommands);
    return compoundCommand;
}