org.eclipse.emf.edit.command.AddCommand Java Examples

The following examples show how to use org.eclipse.emf.edit.command.AddCommand. 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: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
@Deprecated
public void addConnectorParameter(final String parameterKey, final String valueContent) throws ProcBuilderException {

    if (!(currentConnector instanceof org.bonitasoft.studio.model.process.Connector)) {
        String name = "null";
        if (currentConnector != null) {
            name = ((Element) currentConnector).getName();
        }
        throw new ProcBuilderException("Impossible to add a connector parameter on Current connector : " + name);
    }

    final ConnectorParameter parameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
    parameter.setKey(parameterKey);
    parameter.setExpression(createExpression(valueContent, "java.lang.String", ExpressionConstants.GROOVY, ExpressionConstants.SCRIPT_TYPE));

    commandStack.append(AddCommand.create(editingDomain, currentConnector.getConfiguration(),
            ConnectorConfigurationPackage.eINSTANCE.getConnectorConfiguration_Parameters(), parameter));
    execute();
}
 
Example #2
Source File: SelectionCopier.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds the pasted elements to the graph editor via a single EMF command.
 *
 * @param pastedNodes the pasted nodes to be added
 * @param pastedConnections the pasted connections to be added
 * @param consumer a consumer to allow custom commands to be appended to the paste command
 */
private void addPastedElements(final List<GNode> pastedNodes, final List<GConnection> pastedConnections,
        final BiConsumer<List<GNode>, CompoundCommand> consumer) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model);
    final CompoundCommand command = new CompoundCommand();

    for (final GNode pastedNode : pastedNodes) {
        command.append(AddCommand.create(editingDomain, model, NODES, pastedNode));
    }

    for (final GConnection pastedConnection : pastedConnections) {
        command.append(AddCommand.create(editingDomain, model, CONNECTIONS, pastedConnection));
    }

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }

    if (consumer != null) {
        consumer.accept(pastedNodes, command);
    }

}
 
Example #3
Source File: AbstractCreateNodeHandler.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doExecute(AbstractOperationAction action, GraphicalModelState modelState,
		WorkflowModelServerAccess modelAccess) throws Exception {
	CreateNodeOperationAction createNodeOperationAction = (CreateNodeOperationAction) action;
	WorkflowFacade workflowFacade = modelAccess.getWorkflowFacade();
	Workflow workflow = workflowFacade.getCurrentWorkflow();

	Node node = initializeNode((Node) CoffeeFactory.eINSTANCE.create(eClass), modelState);

	Command addCommand = AddCommand.create(modelAccess.getEditingDomain(), workflow,
			CoffeePackage.Literals.WORKFLOW__NODES, node);

	createDiagramElement(workflowFacade, workflow, node, createNodeOperationAction);

	if (!modelAccess.edit(addCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + addCommand);
	}

}
 
Example #4
Source File: JointCommands.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes any existing joints from the connection and creates a new set of joints at the given positions.
 *
 * <p>
 * This is executed as a single compound command and is therefore a single element in the undo-redo stack.
 * </p>
 *
 * @param positions a list of {@link Point2D} instances speciying the x and y positions of the new joints
 * @param connection the connection in which the joints will be set
 */
public static void setNewJoints(final List<Point2D> positions, final GConnection connection) {

    final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(connection);
    final CompoundCommand command = new CompoundCommand();

    command.append(RemoveCommand.create(editingDomain, connection, JOINTS, connection.getJoints()));

    for (final Point2D position : positions) {

        final GJoint newJoint = GraphFactory.eINSTANCE.createGJoint();
        newJoint.setX(position.getX());
        newJoint.setY(position.getY());

        command.append(AddCommand.create(editingDomain, connection, JOINTS, newJoint));
    }

    if (command.canExecute()) {
        editingDomain.getCommandStack().execute(command);
    }
}
 
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: DocumentWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
    final Pool pool = (Pool) ModelHelper.getParentProcess(context);
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(context);
    if (document == null) {
        editingDomain.getCommandStack()
                .execute(new AddCommand(editingDomain, pool.getDocuments(), EcoreUtil.copy(documentWorkingCopy)));
    } else {
        if (!performFinishOnEdition(editingDomain)) {
            return false;
        }
    }

    refreshProject();
    return true;
}
 
Example #7
Source File: ExpressionCollectionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private ListExpression addLineInTableExpression(final Object expressionInput) {
    final ListExpression rowExp = createListExpressionForNewLineInTable();
    if (editingDomain == null) {
        editingDomain = TransactionUtil.getEditingDomain(expressionInput);
    }
    if (editingDomain != null) {
        editingDomain
                .getCommandStack()
                .execute(
                        AddCommand
                                .create(editingDomain,
                                        expressionInput,
                                        ExpressionPackage.Literals.TABLE_EXPRESSION__EXPRESSIONS,
                                        rowExp));
    } else {
        ((TableExpression) expressionInput).getExpressions().add(rowExp);
    }

    return rowExp;
}
 
Example #8
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 #9
Source File: ConnectorsConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void addNewKPIConnectorDefinition(Configuration configuration, AbstractProcess process, CompoundCommand cc,	EditingDomain editingDomain) {
	final List<DatabaseKPIBinding> kpiBindings = ModelHelper.getAllItemsOfType(process, KpiPackage.Literals.DATABASE_KPI_BINDING) ;
	if(!kpiBindings.isEmpty()){
		final String defId = DB_CONNECTOR_FOR_KPI_ID ;
		final String defVersion = DB_CONNECTOR_VERSION ;
		boolean exists = false ;
		for(final DefinitionMapping association : configuration.getDefinitionMappings()){
			if(FragmentTypes.CONNECTOR.equals(association.getType()) && association.getDefinitionId().equals(defId) && association.getDefinitionVersion().equals(defVersion)){
				exists = true ;
				updateAssociation(configuration,association,cc,editingDomain);
				break ;
			}
		}
		if(!exists){
			final DefinitionMapping newAssociation = ConfigurationFactory.eINSTANCE.createDefinitionMapping() ;
			newAssociation.setDefinitionId(defId) ;
			newAssociation.setDefinitionVersion(defVersion) ;
			newAssociation.setType(getFragmentContainerId()) ;
			editingDomain.getCommandStack().execute(AddCommand.create(editingDomain, configuration, ConfigurationPackage.Literals.CONFIGURATION__DEFINITION_MAPPINGS, newAssociation)) ;
			updateAssociation(configuration, newAssociation, cc, editingDomain) ;
		}
	}
}
 
Example #10
Source File: AbstractConnectorConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void updateJarDependencies(final FragmentContainer connectorContainer, final ConnectorImplementation implementation,
        final EditingDomain editingDomain, final CompoundCommand cc, final boolean forceDriver) {
    for (final String jar : jarDependencies(implementation)) {
        boolean exists = false;
        for (final Fragment dep : connectorContainer.getFragments()) {
            if (dep.getValue().equals(jar)) {
                exists = true;
                break;
            }
        }
        if (!exists) {
            final Fragment depFragment = ConfigurationFactory.eINSTANCE.createFragment();
            depFragment.setExported(true);
            depFragment.setKey(implementation.getImplementationId() + " -- " + implementation.getImplementationVersion());
            depFragment.setValue(jar);
            depFragment.setType(getFragmentContainerId());
            editingDomain.getCommandStack().execute(
                    AddCommand.create(editingDomain, connectorContainer, ConfigurationPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS, depFragment));
        }
    }
}
 
Example #11
Source File: ComparisonExpressionValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void updateDependencies(final Resource resource) {
	if(domain != null && inputExpression != null){
		domain.getCommandStack().execute(new RemoveCommand(domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS, inputExpression.getReferencedElements()));
		final Operation_Compare compareOp = (Operation_Compare) resource.getContents().get(0);
		if(compareOp != null){
			final List<Expression_ProcessRef> references = ModelHelper.getAllItemsOfType(compareOp, ConditionModelPackage.Literals.EXPRESSION_PROCESS_REF);
			for(final Expression_ProcessRef ref : references){
                   final EObject dep = ComparisonExpressionUtil.getResolvedDependency(context, ref);
				domain.getCommandStack().execute(new AddCommand(domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS, EcoreUtil.copy(dep)));
			}
		}
	}else if(inputExpression != null){
		inputExpression.getReferencedElements().clear();
           inputExpression.getReferencedElements().addAll(ComparisonExpressionUtil.computeReferencedElement(context, resource));
	}
}
 
Example #12
Source File: AddParameterWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
    editingDomain.getCommandStack().execute(
            AddCommand.create(editingDomain, container,
                    ProcessPackage.Literals.ABSTRACT_PROCESS__PARAMETERS,
                    parameterWorkingCopy));

    try {
        RepositoryManager.getInstance().getCurrentRepository().getProject()
                .build(IncrementalProjectBuilder.FULL_BUILD, XtextProjectHelper.BUILDER_ID, Collections.<String, String> emptyMap(), null);
    } catch (final CoreException e1) {
        BonitaStudioLog.error(e1, ParameterPlugin.PLUGIN_ID);
        return false;
    }

    return true;
}
 
Example #13
Source File: ParametersConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void addNewParameters(final Configuration configuration, final AbstractProcess process, final EditingDomain editingDomain, final CompoundCommand cc) {
    for(final Parameter parameter : process.getParameters()){
        final String parameterName = parameter.getName() ;
        boolean exists = false ;
        for(final Parameter p : configuration.getParameters()){
            if(p.getName().equals(parameterName)){
                exists = true ;
                if(p.getTypeClassname() == null || !p.getTypeClassname().equals(parameter.getTypeClassname())){
                    cc.append(SetCommand.create(editingDomain, p, ParameterPackage.Literals.PARAMETER__TYPE_CLASSNAME, parameter.getTypeClassname())) ;
                }
                break ;
            }
        }
        if(!exists){
            final Parameter param = ParameterFactory.eINSTANCE.createParameter() ;
            param.setName(parameterName) ;
            param.setTypeClassname(parameter.getTypeClassname()) ;
            param.setDescription(parameter.getDescription()) ;
            cc.append(AddCommand.create(editingDomain, configuration, ConfigurationPackage.Literals.CONFIGURATION__PARAMETERS, param)) ;
        }
    }
}
 
Example #14
Source File: AbstractCreateEdgeHandler.java    From graphical-lsp with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doExecute(AbstractOperationAction action, GraphicalModelState modelState,
		WorkflowModelServerAccess modelAccess) throws Exception {
	CreateConnectionOperationAction createConnectionAction = (CreateConnectionOperationAction) action;
	WorkflowFacade workflowFacade = modelAccess.getWorkflowFacade();
	Workflow workflow = workflowFacade.getCurrentWorkflow();

	Flow flow = (Flow) CoffeeFactory.eINSTANCE.create(eClass);
	flow.setSource(modelAccess.getNodeById(createConnectionAction.getSourceElementId()));
	flow.setTarget(modelAccess.getNodeById(createConnectionAction.getTargetElementId()));

	Command addCommand = AddCommand.create(modelAccess.getEditingDomain(), workflow,
			CoffeePackage.Literals.WORKFLOW__FLOWS, flow);

	createDiagramElement(workflowFacade, workflow, flow, createConnectionAction);

	if (!modelAccess.edit(addCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + addCommand);
	}
}
 
Example #15
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addFilter(final String id, final String name, final String connectorId, final boolean ignoreError) throws ProcBuilderException {
    if (!(currentAssignable instanceof Assignable)) {
        throw new ProcBuilderException("Impossible to add a Filter on Current element :" + currentAssignable != null
                ? ((Element) currentAssignable).getName() : "null");
    }

    final org.bonitasoft.studio.model.process.Connector filter = ProcessFactory.eINSTANCE.createConnector();
    filter.setName(NamingUtils.convertToId(id));
    filter.setDefinitionId(connectorId);
    filter.setIgnoreErrors(ignoreError);
    currentConnector = filter;
    currentElement = filter;

    commandStack.append(AddCommand.create(editingDomain, currentAssignable, ProcessPackage.eINSTANCE.getAssignable_Filters(), filter));
    execute();
    updateDependencies(connectorId);
    execute();

}
 
Example #16
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addEnumType(final String id, final String name, final Set<String> literals) throws ProcBuilderException {
    if (datatypes.get(id) == null) {
        final EnumType enumType = ProcessFactory.eINSTANCE.createEnumType();
        enumType.setName(id);
        enumType.getLiterals().addAll(literals);

        datatypes.put(id, enumType);

        final MainProcess mainProc = ModelHelper.getMainProcess(currentContainer);
        if (mainProc == null) {
            throw new ProcBuilderException("Impossible to find the root element");
        }
        if (ModelHelper.getDataTypeForID(mainProc, id) == null) {
            commandStack.append(AddCommand.create(editingDomain, mainProc, ProcessPackage.eINSTANCE.getAbstractProcess_Datatypes(), enumType));
        }
        execute();
    }
}
 
Example #17
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addConnectorParameter(final String parameterKey, final String valueContent, final String valueReturnType, final String valueInterpreter,
        final String expressionType) throws ProcBuilderException {

    if (!(currentConnector instanceof org.bonitasoft.studio.model.process.Connector)) {
        throw new ProcBuilderException("Impossible to add a connector parameter on Current connector :" + currentConnector != null
                ? ((Element) currentConnector).getName() : "null");
    }

    final ConnectorParameter parameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
    parameter.setKey(parameterKey);
    parameter.setExpression(createExpression(valueContent, valueReturnType, valueInterpreter, expressionType));

    commandStack.append(AddCommand.create(editingDomain, currentConnector.getConfiguration(),
            ConnectorConfigurationPackage.eINSTANCE.getConnectorConfiguration_Parameters(), parameter));
    execute();
}
 
Example #18
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addConnectorOutput(final String targetDataId, final String valueContent, final String valueReturnType, final String valueInterpreter,
        final String expressionType) throws ProcBuilderException {

    if (!(currentConnector instanceof org.bonitasoft.studio.model.process.Connector)) {
        throw new ProcBuilderException("Impossible to add a connector output on Current connector :" + currentConnector != null
                ? ((Element) currentConnector).getName() : "null");
    }

    final Operation parameter = ExpressionFactory.eINSTANCE.createOperation();
    final Operator assignment = ExpressionFactory.eINSTANCE.createOperator();
    assignment.setType(ExpressionConstants.ASSIGNMENT_OPERATOR);
    parameter.setOperator(assignment);
    parameter.setRightOperand(createExpression(valueContent, valueReturnType, valueInterpreter, expressionType));
    for (final Data data : ModelHelper.getAccessibleData(currentElement, true)) {
        if (targetDataId.equals(data.getName())) {
            parameter.setLeftOperand(createExpression(targetDataId, DataUtil.getTechnicalTypeFor(data), null, ExpressionConstants.VARIABLE_TYPE));
            break;
        }
    }

    commandStack.append(AddCommand.create(editingDomain, currentConnector, ProcessPackage.eINSTANCE.getConnector_Outputs(), parameter));
    execute();
}
 
Example #19
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addCallActivityInParameter(final String sourceDataId, final String targetDataId) throws ProcBuilderException {
    if (currentStep instanceof CallActivity) {
        final InputMapping inputMapping = ProcessFactory.eINSTANCE.createInputMapping();

        if (dataByName.get(sourceDataId) != null) {
            inputMapping.setProcessSource(ExpressionHelper.createVariableExpression(dataByName.get(NamingUtils.convertToId(sourceDataId))));

        }
        if (dataByName.get(targetDataId) != null) {
            inputMapping.setSubprocessTarget(dataByName.get(NamingUtils.convertToId(targetDataId)).getName());
        }

        commandStack.append(AddCommand.create(editingDomain, currentStep, ProcessPackage.Literals.CALL_ACTIVITY__INPUT_MAPPINGS, inputMapping));
        execute();
    } else {
        throw new ProcBuilderException("Can't process input parameter on current element");
    }
}
 
Example #20
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addCallActivityOutParameter(final String sourceDataId, final String targetDataId)
        throws ProcBuilderException {
    if (currentStep instanceof CallActivity) {
        final OutputMapping outputMapping = ProcessFactory.eINSTANCE.createOutputMapping();
        if (dataByName.get(sourceDataId) != null) {
            outputMapping.setSubprocessSource(dataByName.get(sourceDataId).getName());
        }
        if (dataByName.get(targetDataId) != null) {
            outputMapping.setProcessTarget(dataByName.get(targetDataId));
        }

        commandStack.append(AddCommand.create(editingDomain, currentStep, ProcessPackage.Literals.CALL_ACTIVITY__OUTPUT_MAPPINGS, outputMapping));
        execute();
    } else {
        throw new ProcBuilderException("Can't process output parameter on current element");
    }

}
 
Example #21
Source File: RefactorDataOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void updateDataInListsOfData(final CompoundCommand cc) {
    final List<Data> data = ModelHelper.getAllItemsOfType(dataContainer, ProcessPackage.Literals.DATA);
    for (final DataRefactorPair pairToRefactor : pairsToRefactor) {
        for (final Data d : data) {
            if (!d.equals(pairToRefactor.getNewValue())
                    && d.getName().equals(pairToRefactor.getOldValue().getName())) {
                final Data copy = EcoreUtil.copy(pairToRefactor.getNewValue());
                final EObject container = d.eContainer();
                final EReference eContainmentFeature = d.eContainmentFeature();
                if (container != null && container.eGet(eContainmentFeature) instanceof Collection<?>) {
                    final List<?> dataList = (List<?>) container.eGet(eContainmentFeature);
                    final int index = dataList.indexOf(d);
                    cc.append(RemoveCommand.create(getEditingDomain(), container, eContainmentFeature, d));
                    cc.append(AddCommand.create(getEditingDomain(), container, eContainmentFeature, copy, index));
                } else if (container != null && container.eGet(eContainmentFeature) instanceof Data) {
                    cc.append(SetCommand.create(getEditingDomain(), container, eContainmentFeature, copy));
                }
            }
        }
    }
}
 
Example #22
Source File: ContractInputGenerationWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private IRunnableWithProgress buildContractOperationFromDocument(Document document) {
    return monitor -> {
        monitor.beginTask("", IProgressMonitor.UNKNOWN);
        ContractInput input = createDocumentContractInput(document);
        CompoundCommand cc = new CompoundCommand();
        cc.append(AddCommand.create(editingDomain, contractContainer.getContract(),
                ProcessPackage.Literals.CONTRACT__INPUTS,
                input));
        if (contractContainer instanceof Task) {
            createDocumentUpdateOperation(document, input, cc);
        } else {
            cc.append(SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__DOCUMENT_TYPE,
                    DocumentType.CONTRACT));
            cc.append(
                    SetCommand.create(editingDomain, document, ProcessPackage.Literals.DOCUMENT__CONTRACT_INPUT,
                            input));
        }
        editingDomain.getCommandStack().execute(cc);
    };
}
 
Example #23
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 #24
Source File: ConstraintExpressionScriptContainer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public CompoundCommand updateDependencies(final TransactionalEditingDomain editingDomain,
        final List<? extends RefactorPair<? extends EObject, ? extends EObject>> pairsToRefactor) {
    final CompoundCommand compoundCommand = new CompoundCommand();
    final ContractConstraint constraint = getModelElement();
    for (final String inputName : constraint.getInputNames()) {
        for (final RefactorPair<? extends EObject, ? extends EObject> pair : pairsToRefactor) {
            final String oldValueName = pair.getOldValueName();
            if (oldValueName.equals(inputName) && !oldValueName.equals(pair.getNewValueName())) {
                compoundCommand.append(RemoveCommand.create(editingDomain, constraint,
                        ProcessPackage.Literals.CONTRACT_CONSTRAINT__INPUT_NAMES,
                        inputName));
                compoundCommand.append(AddCommand.create(editingDomain, constraint,
                        ProcessPackage.Literals.CONTRACT_CONSTRAINT__INPUT_NAMES,
                        pair.getNewValueName()));
            }
        }
    }
    return compoundCommand;
}
 
Example #25
Source File: DataRefactorIT.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNameRefactorWithGlobalDataReferencedInMultiInstanciation() {
    final String newDataName = "newDataName";
    final AbstractProcess process = initTestForGlobalDataRefactor(newDataName);

    // Data referenced in multi-instanciation
    final Activity activity = ProcessFactory.eINSTANCE.createActivity();
    activity.setCollectionDataToMultiInstantiate(processData);
    activity.setListDataContainingOutputResults(processData);
    editingDomain.getCommandStack()
            .execute(AddCommand.create(editingDomain, process, ProcessPackage.Literals.CONTAINER__ELEMENTS, activity));
    editingDomain.getCommandStack()
            .execute(SetCommand.create(editingDomain, processData, ProcessPackage.Literals.ELEMENT__NAME, newDataName));

    assertEquals("There are too many datas. The old one migth not be removed.", 2, process.getData().size());
    assertEquals("Data name has not been updated correctly in multinstantiation", newDataName,
            activity.getCollectionDataToMultiInstantiate()
                    .getName());
    assertEquals("Data name has not been updated correctly in multinstantiation", newDataName,
            activity.getListDataContainingOutputResults()
                    .getName());

}
 
Example #26
Source File: DataRefactorIT.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Expression createGroovyScriptConnectortWithDataReferenced(
        final Activity activity) {
    final Connector groovyScriptConnector = ProcessFactory.eINSTANCE.createConnector();

    final ConnectorConfiguration groovyScriptConnectorConfiguration = ConnectorConfigurationFactory.eINSTANCE
            .createConnectorConfiguration();
    final ConnectorParameter connectorParameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
    final Expression scriptUsingData = ExpressionFactory.eINSTANCE.createExpression();
    scriptUsingData.setType(ExpressionConstants.SCRIPT_TYPE);
    scriptUsingData.setName(processData.getName());
    scriptUsingData.setContent(processData.getName());
    scriptUsingData.getReferencedElements().add(EcoreUtil.copy(processData));
    scriptUsingData.setReturnType(DataUtil.getTechnicalTypeFor(processData));
    connectorParameter.setExpression(scriptUsingData);
    groovyScriptConnectorConfiguration.getParameters().add(connectorParameter);
    groovyScriptConnector.setConfiguration(groovyScriptConnectorConfiguration);

    editingDomain.getCommandStack().execute(AddCommand.create(editingDomain, activity,
            ProcessPackage.Literals.CONNECTABLE_ELEMENT__CONNECTORS, groovyScriptConnector));
    return scriptUsingData;
}
 
Example #27
Source File: DataRefactorIT.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Expression addOperationOnFirstActivity(final AbstractProcess process, final Data data) {
    final Activity activity = getActivity(process);
    final Operation operationWithScriptUsingData = ExpressionFactory.eINSTANCE.createOperation();
    final Operator assignOperator = ExpressionFactory.eINSTANCE.createOperator();
    assignOperator.setType(ExpressionConstants.ASSIGNMENT_OPERATOR);
    operationWithScriptUsingData.setOperator(assignOperator);
    final Expression variableExpression = ExpressionFactory.eINSTANCE.createExpression();
    variableExpression.setType(ExpressionConstants.VARIABLE_TYPE);
    variableExpression.setName(data.getName());
    variableExpression.setContent(data.getName());
    variableExpression.getReferencedElements().add(EcoreUtil.copy(data));
    variableExpression.setReturnType(DataUtil.getTechnicalTypeFor(data));
    operationWithScriptUsingData.setLeftOperand(variableExpression);
    editingDomain.getCommandStack().execute(AddCommand.create(editingDomain, activity,
            ProcessPackage.Literals.OPERATION_CONTAINER__OPERATIONS, operationWithScriptUsingData));
    return variableExpression;
}
 
Example #28
Source File: DataRefactorIT.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Expression createConnectorWithPatternExpression(final AbstractProcess process) {
    final Connector mailConnector = ProcessFactory.eINSTANCE.createConnector();

    final ConnectorConfiguration groovyScriptConnectorConfiguration = ConnectorConfigurationFactory.eINSTANCE
            .createConnectorConfiguration();
    final ConnectorParameter connectorParameter = ConnectorConfigurationFactory.eINSTANCE.createConnectorParameter();
    final Expression patternExpr = ExpressionFactory.eINSTANCE.createExpression();
    patternExpr.setType(ExpressionConstants.PATTERN_TYPE);
    patternExpr.setName(processData.getName());
    patternExpr.setContent("${" + processData.getName() + "}");
    patternExpr.getReferencedElements().add(EcoreUtil.copy(processData));
    patternExpr.setReturnType(DataUtil.getTechnicalTypeFor(processData));
    connectorParameter.setExpression(patternExpr);
    groovyScriptConnectorConfiguration.getParameters().add(connectorParameter);
    mailConnector.setConfiguration(groovyScriptConnectorConfiguration);
    editingDomain.getCommandStack().execute(AddCommand.create(editingDomain, process,
            ProcessPackage.Literals.CONNECTABLE_ELEMENT__CONNECTORS, mailConnector));
    return patternExpr;
}
 
Example #29
Source File: BPMNDataExportImportTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected DocumentRoot exportToBPMNProcessWithData(final Data data, final String dataType) throws IOException {
    final NewDiagramCommandHandler newDiagramCommandHandler = new NewDiagramCommandHandler();
    final DiagramFileStore newDiagramFileStore = newDiagramCommandHandler.newDiagram();
    Resource emfResource = newDiagramFileStore.getEMFResource();
    TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(emfResource);
    MainProcess mainProcess = newDiagramFileStore.getContent();
    final AbstractProcess abstractProcess = newDiagramFileStore.getProcesses().get(0);
    editingDomain.getCommandStack()
            .execute(AddCommand.create(editingDomain, abstractProcess, ProcessPackage.Literals.DATA_AWARE__DATA,
                    data));
    mainProcess.getDatatypes().stream()
            .filter(dt -> Objects.equals(NamingUtils.convertToId(dataType), dt.getName()))
            .findFirst()
            .ifPresent(dt -> editingDomain.getCommandStack()
                    .execute(SetCommand.create(editingDomain, data, ProcessPackage.Literals.DATA__DATA_TYPE, dt)));
    assertThat(data.getDataType())
            .overridingErrorMessage("No datatype '%s' set on data %s", NamingUtils.convertToId(dataType), data)
            .isNotNull();
    newDiagramFileStore.save(mainProcess);
    return BPMNTestUtil.exportToBpmn(emfResource);
}
 
Example #30
Source File: RefactorDocumentOperationTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDeleteSeveralDocumentBasic() throws InvocationTargetException, InterruptedException {

    final Document secondDocument = ProcessFactory.eINSTANCE.createDocument();
    secondDocument.setName("secondDocument");
    secondDocument.setMimeType(ExpressionHelper.createConstantExpression("octet/stream", String.class.getName()));
    domain.getCommandStack().execute(new AddCommand(domain, parentProcess.getDocuments(), secondDocument));

    final RefactorDocumentOperation rdo = new RefactorDocumentOperation(RefactoringOperationType.REMOVE);
    rdo.addItemToRefactor(null, document);
    rdo.addItemToRefactor(null, secondDocument);
    rdo.setEditingDomain(domain);
    rdo.setAskConfirmation(false);
    rdo.run(null);

    assertThat(parentProcess.getDocuments()).hasSize(0);

    domain.getCommandStack().undo();
    assertThat(parentProcess.getDocuments()).hasSize(2);
}