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

The following examples show how to use org.eclipse.emf.edit.command.SetCommand. 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: TaskPriorityPropertySection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
    ExtensibleGridPropertySection extensibleGridPropertySection) {
combo = new ComboViewer(composite);
combo.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
combo.setContentProvider(new ArrayContentProvider());
combo.setLabelProvider(new PriorityLabelProvider());
Object[] input = new Object[TaskPriority.values().length];
for (int i = 0; i < TaskPriority.values().length; i++) {
    input[i] = i;
}
combo.setInput(input);
combo.setSelection(new StructuredSelection(task.getPriority()));

combo.addPostSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(SelectionChangedEvent event) {
	IStructuredSelection selection = (IStructuredSelection) event.getSelection();
	if (!selection.isEmpty()) {
	    Command setCommand = new SetCommand(editDomain, task, ProcessPackage.Literals.TASK__PRIORITY,
		    selection.getFirstElement());
	    editDomain.getCommandStack().execute(setCommand);
	}
    }
});
   }
 
Example #2
Source File: ProcessActorsPropertySection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private Listener createSetAsInitatiorListener() {
    return e -> {
        final Actor selectedActor = (Actor) ((IStructuredSelection) actorsViewer.getSelection()).getFirstElement();
        final CompoundCommand cc = new CompoundCommand();
        final AbstractProcess process = (AbstractProcess) getEObject();
        for (final Actor a : process.getActors()) {
            cc.append(SetCommand.create(getEditingDomain(), a, ProcessPackage.Literals.ACTOR__INITIATOR, false));
        }
        cc.append(SetCommand.create(getEditingDomain(), selectedActor, ProcessPackage.Literals.ACTOR__INITIATOR, true));
        getEditingDomain().getCommandStack().execute(cc);
        Display.getDefault().asyncExec(() -> {
            if (actorsViewer != null && !actorsViewer.getControl().isDisposed()) {
                actorsViewer.refresh();
                updateButtons();
            }
        });

    };
}
 
Example #3
Source File: ApplyLabelEditOperationHandler.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 {
	ApplyLabelEditOperationAction editLabelAction = (ApplyLabelEditOperationAction) action;
	Optional<GModelElement> element = modelState.getIndex().get(editLabelAction.getLabelId());
	if (!element.isPresent() && !(element.get() instanceof GLabel)) {
		throw new IllegalArgumentException("Element with provided ID cannot be found or is not a GLabel");
	}

	GNode gNode = getParentGNode((GLabel) element.get());
	Node node = modelAccess.getNodeById(gNode.getId());
	if (!(node instanceof Task)) {
		throw new IllegalAccessError("Edited label isn't label representing a task");
	}
	
	Command setCommand = SetCommand.create(modelAccess.getEditingDomain(), node, CoffeePackage.Literals.TASK__NAME, editLabelAction.getText());
	if(!modelAccess.edit(setCommand).thenApply(res -> res.body()).get()) {
		throw new IllegalAccessError("Could not execute command: " + setCommand);
	}
}
 
Example #4
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 #5
Source File: AddActorWizard.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
	newActor = ProcessFactory.eINSTANCE.createActor();	
	newActor.setName(page.getActorName());
	newActor.setDocumentation(page.getActorDocumentation());
	if(page.isSetAsInitiator()){
		for (Actor a : process.getActors()) {
			if(a.isInitiator()){
				editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, a, ProcessPackage.Literals.ACTOR__INITIATOR, false));
				break;
			}
		}
		newActor.setInitiator(true);
	} else {
		newActor.setInitiator(false);
	}
	editingDomain.getCommandStack().execute(AddCommand.create(editingDomain, process, ProcessPackage.Literals.ABSTRACT_PROCESS__ACTORS, newActor));
	return true;
}
 
Example #6
Source File: GenerationFileNamesPage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the {@link Generation#getTemplateFileName() template URI}.
 * 
 * @param gen
 *            the {@link Generation}
 * @param templateURI
 *            the new {@link Generation#getTemplateFileName() template URI}
 */
private void updateTemplateURI(Generation gen, final URI templateURI) {
    final URI genconfURI = gen.eResource().getURI();
    final String relativeTemplatePath;
    if (!templateURI.isPlatformPlugin()) {
        relativeTemplatePath = URI.decode(templateURI.deresolve(genconfURI).toString());
    } else {
        relativeTemplatePath = URI.decode(templateURI.toString());
    }
    final EditingDomain editingDomain = TransactionUtil.getEditingDomain(gen);
    templateCustomProperties = validatePage(gen,
            GenconfUtils.getResolvedURI(gen, URI.createURI(gen.getTemplateFileName(), false)));
    editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, gen,
            GenconfPackage.Literals.GENERATION__TEMPLATE_FILE_NAME, relativeTemplatePath));
    if (gen.getResultFileName() == null || gen.getResultFileName().isEmpty()) {
        editingDomain.getCommandStack()
                .execute(SetCommand.create(editingDomain, gen, GenconfPackage.Literals.GENERATION__RESULT_FILE_NAME,
                        relativeTemplatePath.replace("." + M2DocUtils.DOCX_EXTENSION_FILE, "-generated.docx")));
    }
    if (gen.getValidationFileName() == null || gen.getValidationFileName().isEmpty()) {
        editingDomain.getCommandStack()
                .execute(SetCommand.create(editingDomain, gen,
                        GenconfPackage.Literals.GENERATION__VALIDATION_FILE_NAME,
                        relativeTemplatePath.replace("." + M2DocUtils.DOCX_EXTENSION_FILE, "-validation.docx")));
    }
}
 
Example #7
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 #8
Source File: ActorMappingConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void removeDeletedActors(Configuration configuration, AbstractProcess process, EditingDomain editingDomain, CompoundCommand cc) {
	ActorMappingsType mappings = configuration.getActorMappings() ;
	if(mappings != null){
		int removed = 0;
		for(ActorMapping mapping : mappings.getActorMapping()){
			String actorName = mapping.getName() ;
			boolean exists = false ;
			for(Actor actor : process.getActors()){
				if(actor.getName().equals(actorName)){
					exists = true ;
					break ;
				}
			}
			if(!exists){
				removed++;
				cc.append(RemoveCommand.create(editingDomain, mappings, ActorMappingPackage.Literals.ACTOR_MAPPINGS_TYPE__ACTOR_MAPPING, mapping)) ;
			}
		}
		if(removed > 0 ){
			if(mappings.getActorMapping().size() == removed + added){
				cc.append(SetCommand.create(editingDomain, configuration, ConfigurationPackage.Literals.CONFIGURATION__ACTOR_MAPPINGS,   null )) ;
			}
		}
	}

}
 
Example #9
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 #10
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 #11
Source File: RefactorDataOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void removeAllDataReferences(final CompoundCommand cc, final DataRefactorPair pairToRefactor) {
    final List<Expression> expressions = retrieveExpressionsInTheContainer(pairToRefactor);
    for (final Expression exp : expressions) {
        if (ExpressionConstants.VARIABLE_TYPE.equals(exp.getType())
                && exp.getName().equals(pairToRefactor.getOldValue().getName())) {
            // update name and content
            cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__NAME, ""));
            cc.append(
                    SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__CONTENT, ""));
            // update return type
            cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE,
                    String.class.getName()));
            cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__TYPE,
                    ExpressionConstants.CONSTANT_TYPE));
            // update referenced data
            cc.append(RemoveCommand.create(getEditingDomain(), exp,
                    ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS, exp.getReferencedElements()));
        }
    }
}
 
Example #12
Source File: ExpressionViewer.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private static CompoundCommand clearExpression(final Expression expr, final EditingDomain editingDomain) {
    if (editingDomain != null) {
        String returnType = expr.getReturnType();
        if (!expr.isReturnTypeFixed() || expr.getReturnType() == null) {
            returnType = String.class.getName();
        }
        final CompoundCommand cc = new CompoundCommand("Clear Expression");
        if (!ExpressionConstants.CONDITION_TYPE.equals(expr.getType())) {
            cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__TYPE,
                    ExpressionConstants.CONSTANT_TYPE));
        }
        cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__NAME, ""));
        cc.append(SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__CONTENT, ""));
        cc.append(
                SetCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE, returnType));
        cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS,
                expr.getReferencedElements()));
        cc.append(RemoveCommand.create(editingDomain, expr, ExpressionPackage.Literals.EXPRESSION__CONNECTORS,
                expr.getConnectors()));
        return cc;
    } else {
        ExpressionHelper.clearExpression(expr);
        return null;
    }
}
 
Example #13
Source File: NewDiagramCommandHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public DiagramFileStore execute(final ExecutionEvent event) throws ExecutionException {
    final DiagramFileStore diagramFileStore = newDiagram();
    Display.getDefault().asyncExec(() -> {
            final IEditorPart editor = (IEditorPart) diagramFileStore.open();
            if (editor instanceof DiagramEditor) {
                final String author = System.getProperty("user.name", "unknown");
                final TransactionalEditingDomain editingDomain = TransactionUtil
                        .getEditingDomain(diagramFileStore.getEMFResource());
                editingDomain.getCommandStack().execute(
                        SetCommand.create(editingDomain,
                                ((DiagramEditor) editor).getDiagramEditPart().resolveSemanticElement(),
                                ProcessPackage.Literals.ABSTRACT_PROCESS__AUTHOR, author));
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(editor);
            }
    });
    return diagramFileStore;
}
 
Example #14
Source File: DuplicateDiagramOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private DiagramFileStore copyDiagram() {
    final DiagramRepositoryStore diagramStore = RepositoryManager.getInstance()
            .getRepositoryStore(DiagramRepositoryStore.class);

    final Copier copier = new Copier(true, false);
    final Collection<EObject> copiedElements = copier.copyAll(diagram.eResource().getContents());
    copier.copyReferences();//don't forget this line otherwise we loose link between diagrams and model
    final DiagramFileStore store = diagramStore
            .createRepositoryFileStore(NamingUtils.toDiagramFilename(diagramName, diagramVersion));
    store.save(copiedElements);

    final MainProcess newDiagram = store.getContent();
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(newDiagram.eResource());
    changeProcessNameAndVersion(newDiagram, editingDomain, diagramName, diagramVersion);
    editingDomain.getCommandStack().execute(
            SetCommand.create(editingDomain, newDiagram, ProcessPackage.Literals.MAIN_PROCESS__CONFIG_ID,
                    ConfigurationIdProvider
                            .getConfigurationIdProvider().getConfigurationId(newDiagram)));
    duplicateConfigurations(diagram, newDiagram);
    return store;
}
 
Example #15
Source File: DeleteHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void removeMessage(final MessageFlow flow) {
    final MainProcess diagram = ModelHelper.getMainProcess(flow);
    Assert.isNotNull(diagram);
    final AbstractCatchMessageEvent catchEvent = flow.getTarget();
    final ThrowMessageEvent thowEvent = flow.getSource();
    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(diagram);
    Assert.isNotNull(domain);
    final CompoundCommand cc = new CompoundCommand();
    if (flow.getSource() != null) {
        final List<Message> messages = flow.getSource().getEvents();
        for (final Message message : messages) {
            if (flow.getName().equals(message.getName())) {
                cc.append(DeleteCommand.create(domain, message));
                break;
            }
        }
    }
    cc.append(SetCommand.create(domain, catchEvent, ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT, null));
    domain.getCommandStack().execute(cc);
}
 
Example #16
Source File: FillFieldNumbersHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute ( final ExecutionEvent event ) throws ExecutionException
{

    final IEditorPart editor = getActivePage ().getActiveEditor ();

    byte b = (byte)1;
    for ( final Attribute attribute : SelectionHelper.iterable ( getSelection (), Attribute.class ) )
    {
        EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor ( attribute );

        if ( domain == null && editor instanceof IEditingDomainProvider )
        {
            domain = ( (IEditingDomainProvider)editor ).getEditingDomain ();
        }

        SetCommand.create ( domain, attribute, ProtocolPackage.Literals.ATTRIBUTE__FIELD_NUMBER, b ).execute ();

        b++;
    }

    return null;
}
 
Example #17
Source File: ProcessElementNameContribution.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void editDiagramAndPoolNameAndVersion() {
    final MainProcess diagram = ModelHelper.getMainProcess(element);
    final DiagramRepositoryStore diagramStore = RepositoryManager.getInstance()
            .getRepositoryStore(DiagramRepositoryStore.class);
    final OpenNameAndVersionForDiagramDialog nameDialog = new OpenNameAndVersionForDiagramDialog(
            Display.getDefault().getActiveShell(), diagram,
            diagramStore);
    if (nameDialog.open() == Dialog.OK) {
        final DiagramEditor editor = (DiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getActiveEditor();
        final MainProcess newProcess = (MainProcess) editor.getDiagramEditPart().resolveSemanticElement();
        editingDomain.getCommandStack().execute(
                SetCommand.create(editingDomain, newProcess, ProcessPackage.Literals.ABSTRACT_PROCESS__AUTHOR,
                        System.getProperty("user.name", "Unknown")));
        final String oldName = newProcess.getName();
        final String oldVersion = newProcess.getVersion();
        if (new Identifier(oldName, oldVersion).equals(nameDialog.getIdentifier())) {
            renamePoolsOnly(nameDialog, editor, newProcess);
        } else {
            editor.doSave(Repository.NULL_PROGRESS_MONITOR);
            renameDiagramAndPool(nameDialog, editor, newProcess);
        }
    }
}
 
Example #18
Source File: MessageFlowFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void createMessageFlow(TransactionalEditingDomain editingDomain, Message event, ThrowMessageEvent source,
        AbstractCatchMessageEvent target, DiagramEditPart dep) {
    EditPart targetEP = findEditPart(dep, target);
    EditPart sourceEP = findEditPart(dep, source);

    CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(
            ProcessElementTypes.MessageFlow_4002, ((IHintedType) ProcessElementTypes.MessageFlow_4002).getSemanticHint(),
            dep.getDiagramPreferencesHint());
    Command createMessageFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceEP,
            targetEP);
    if (createMessageFlowCommand.canExecute()) {
        dep.getDiagramEditDomain().getDiagramCommandStack().execute(createMessageFlowCommand);
        dep.getDiagramEditDomain().getDiagramCommandStack().flush();
        dep.refresh();

        ConnectionViewAndElementDescriptor desc = (ConnectionViewAndElementDescriptor) request.getNewObject();
        MessageFlow message = desc.getElementAdapter().getAdapter(MessageFlow.class);
        SetCommand setCommand = new SetCommand(editingDomain, message, ProcessPackage.Literals.ELEMENT__NAME,
                event.getName());
        editingDomain.getCommandStack().execute(setCommand);
    }
}
 
Example #19
Source File: TestFullScenario.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws ExecutionException
 */
public void editAndSave() throws Exception {
    processEditor = getTheOnlyOneEditor();
    processEditor.getEditingDomain().getCommandStack().execute(
            new SetCommand(processEditor.getEditingDomain(),
                    task,
                    ProcessPackage.Literals.ELEMENT__NAME,
                    TESTNAME));

    final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
    final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    final Command saveCommand = commandService.getCommand("org.eclipse.ui.file.save");
    final ExecutionEvent executionEvent = new ExecutionEvent(saveCommand, Collections.EMPTY_MAP, null,
            handlerService.getClass());
    saveCommand.executeWithChecks(executionEvent);
}
 
Example #20
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 #21
Source File: OutputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private CCombo createSubprocessSourceCombo(final Composite outputMappingControl, final OutputMapping mapping) {
    final CCombo subprocessSourceCombo = getWidgetFactory().createCCombo(outputMappingControl, SWT.BORDER);
    for (final Data subprocessData : callActivityHelper.getCallActivityData()) {
        subprocessSourceCombo.add(subprocessData.getName());
    }
    subprocessSourceCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(15, 0).create());
    subprocessSourceCombo.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            getEditingDomain().getCommandStack()
                    .execute(
                            new SetCommand(getEditingDomain(), mapping,
                                    ProcessPackage.Literals.OUTPUT_MAPPING__SUBPROCESS_SOURCE, subprocessSourceCombo
                                            .getText()));
        }
    });
    if (mapping.getSubprocessSource() != null) {
        subprocessSourceCombo.setText(mapping.getSubprocessSource());
    }
    return subprocessSourceCombo;
}
 
Example #22
Source File: InputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected CCombo createInputMappingTargetCombo(final Composite outputMappingControl, final InputMapping mapping) {
    final CCombo targetCombo = getWidgetFactory().createCCombo(outputMappingControl, SWT.BORDER);
    final InputMappingAssignationType assignationType = mapping.getAssignationType();
    updateAvailableValuesInputMappingTargetCombo(targetCombo, assignationType);
    final GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    targetCombo.setLayoutData(layoutData);
    targetCombo.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            getEditingDomain().getCommandStack().execute(
                    new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__SUBPROCESS_TARGET,
                            targetCombo.getText()));
        }
    });
    if (mapping.getSubprocessTarget() != null) {
        targetCombo.setText(mapping.getSubprocessTarget());
    }
    targetCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
            SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_CALLEDTARGET);
    return targetCombo;
}
 
Example #23
Source File: InputParametersMappingSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private ExpressionViewer createInputMappingExpressionViewer(final Composite outputMappingControl,
        final InputMapping mapping) {
    final ExpressionViewer srcCombo = new ExpressionViewer(outputMappingControl, SWT.BORDER, getWidgetFactory());
    srcCombo.getControl().setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
            .hint(250, SWT.DEFAULT).create());
    srcCombo.addFilter(
            new AvailableExpressionTypeFilter(ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.PARAMETER_TYPE,
                    ExpressionConstants.DOCUMENT_TYPE));

    dbc.bindValue(ViewersObservables.observeInput(srcCombo),
            ViewersObservables.observeSingleSelection(selectionProvider));
    if (mapping.getProcessSource() == null) {
        getEditingDomain().getCommandStack().execute(
                SetCommand.create(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE,
                        ExpressionHelper.createConstantExpression("", String.class.getName())));
    }
    dbc.bindValue(ViewersObservables.observeSingleSelection(srcCombo),
            EMFObservables.observeValue(mapping, ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE));
    return srcCombo;
}
 
Example #24
Source File: RefactorDataOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void updateDataReferenceInVariableExpression(final CompoundCommand cc,
        final DataRefactorPair pairToRefactor,
        final Expression exp) {
    if (isReturnFixedOnExpressionWithUpdatedType(pairToRefactor, exp)) {
        cc.append(clearExpression(exp, getEditingDomain()));
        setAskConfirmation(true);
    } else {
        // update name and content
        final Data newValue = pairToRefactor.getNewValue();
        final String newValueName = newValue.getName();
        cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__NAME,
                newValueName));
        cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__CONTENT,
                newValueName));
        // update return type
        cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE,
                DataUtil.getTechnicalTypeFor(newValue)));
    }
}
 
Example #25
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addCallActivityTargetProcess(final String targetProcessId, final String targetProcessVersion) throws ProcBuilderException {
    if (currentStep instanceof CallActivity) {
        String targetProcessIdForExpression = targetProcessId;
        final AbstractProcess targetProcess = processes.get(targetProcessId);
        if (targetProcess != null) {
            targetProcessIdForExpression = targetProcess.getName();
        }
        commandStack.append(SetCommand.create(editingDomain, currentStep, ProcessPackage.Literals.CALL_ACTIVITY__CALLED_ACTIVITY_NAME,
                createExpression(targetProcessIdForExpression, String.class.getName(), null, ExpressionConstants.CONSTANT_TYPE)));
        commandStack.append(SetCommand.create(editingDomain, currentStep, ProcessPackage.Literals.CALL_ACTIVITY__CALLED_ACTIVITY_VERSION,
                createExpression(targetProcessVersion, String.class.getName(), null, ExpressionConstants.CONSTANT_TYPE)));
        execute();
    } else {
        throw new ProcBuilderException("Can't add target process on current element");
    }
}
 
Example #26
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 #27
Source File: ObservableValueWithRefactor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doSetValue(final Object value) {
    final Object oldValue = eObject.eGet(eStructuralFeature);
    if (needRefactor(oldValue, value)) {
        final AbstractRefactorOperation<? extends EObject, ? extends EObject, ? extends RefactorPair<? extends EObject, ? extends EObject>> refactorOperation = refactorOperationFactory
                .createRefactorOperation((TransactionalEditingDomain) domain, eObject, value);
        refactorOperation.getCompoundCommand().append(SetCommand.create(domain, eObject, eStructuralFeature, value));
        try {
            progressService.busyCursorWhile(refactorOperation);
        } catch (InvocationTargetException | InterruptedException e) {
            BonitaStudioLog.error(String.format("Failed to refactor %s into %s", oldValue, value), e);
            openErrorDialog(oldValue, value, e);
        }
    } else {
        super.doSetValue(value);
    }

}
 
Example #28
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addLoopCondition(final Expression loopConditionExpression, final String maxLoopExpression, final TestTimeType testTime)
        throws ProcBuilderException {
    if (!(currentStep instanceof Activity)) {
        throw new ProcBuilderException("Impossible to set duration property on " + currentStep != null ? ((Element) currentStep).getName() : "null");
    }
    commandStack.append(SetCommand.create(diagramPart.getEditingDomain(), currentStep, ProcessPackage.eINSTANCE.getMultiInstantiable_Type(),
            MultiInstanceType.STANDARD));
    if (loopConditionExpression != null && loopConditionExpression.hasContent() && !loopConditionExpression.hasName()) {
        loopConditionExpression.setName("loopCondition");
    }
    commandStack.append(SetCommand.create(diagramPart.getEditingDomain(), currentStep, ProcessPackage.eINSTANCE.getMultiInstantiable_LoopCondition(),
            loopConditionExpression));
    commandStack.append(SetCommand.create(diagramPart.getEditingDomain(), currentStep, ProcessPackage.eINSTANCE.getMultiInstantiable_LoopMaximum(),
            createExpression(maxLoopExpression, Integer.class.getName(), ExpressionConstants.GROOVY, ExpressionConstants.SCRIPT_TYPE)));
    if (testTime != null) {
        commandStack.append(SetCommand.create(diagramPart.getEditingDomain(), currentStep, ProcessPackage.eINSTANCE.getMultiInstantiable_TestBefore(),
                testTime == TestTimeType.BEFORE ? true : false));
    }
}
 
Example #29
Source File: RefactorContractInputOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void updateContractInputExpressions(final CompoundCommand cc) {
    for (final Expression exp : filter(getAllElementOfTypeIn(container, Expression.class),
            withExpressionType(ExpressionConstants.CONTRACT_INPUT_TYPE))) {
        for (final ContractInputRefactorPair pairToRefactor : filter(pairsToRefactor, matches(exp))) {
            if (pairToRefactor.getNewValue() != null) {
                cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__NAME,
                        pairToRefactor.getNewValue().getName()));
                cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__CONTENT,
                        pairToRefactor.getNewValue().getName()));
                cc.append(SetCommand.create(getEditingDomain(), exp, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE,
                        ExpressionHelper.getContractInputReturnType(pairToRefactor.getNewValue())));
                updateDependencies(cc, pairToRefactor, exp);
            } else {
                EMFModelUpdater<EObject> updater = new EMFModelUpdater<>().from(exp);
                updater.editWorkingCopy(ExpressionHelper.createDependencyFromEObject(createDefaultExpression(exp)));
                cc.append(updater.createUpdateCommand(getEditingDomain()));
            }
        }
    }

}
 
Example #30
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addMultiInstantiation(final boolean isSequential) throws ProcBuilderException {
    if (!(currentStep instanceof MultiInstantiable)) {
        throw new ProcBuilderException("Impossible to add a MultiInstantiation on Current element :" + currentStep != null
                ? ((Element) currentStep).getName() : "null");
    }
    MultiInstanceType type = MultiInstanceType.NONE;
    if (isSequential) {
        type = MultiInstanceType.SEQUENTIAL;
    } else {
        type = MultiInstanceType.PARALLEL;
    }
    currentElement = currentStep;
    commandStack.append(SetCommand.create(editingDomain, currentStep, ProcessPackage.eINSTANCE.getMultiInstantiable_Type(), type));
    execute();
}