Java Code Examples for org.eclipse.emf.edit.command.AddCommand#create()

The following examples show how to use org.eclipse.emf.edit.command.AddCommand#create() . 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: 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 2
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 3
Source File: Commands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds a node to the model.
 *
 * <p>
 * The node's x, y, width, and height values should be set before calling this method.
 * </p>
 *
 * @param model the {@link GModel} to which the node should be added
 * @param node the {@link GNode} to add to the model
 */
public static void addNode(final GModel model, final GNode node) {

    final EditingDomain editingDomain = getEditingDomain(model);

    if (editingDomain != null) {
        final Command command = AddCommand.create(editingDomain, model, NODES, node);

        if (command.canExecute()) {
            editingDomain.getCommandStack().execute(command);
        }
    }
}
 
Example 4
Source File: AddBusinessObjectDataWizard.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean performFinish() {
    final Command addCommand = AddCommand.create(editingDomain, container, ProcessPackage.Literals.DATA_AWARE__DATA,
            businessObjectData);
    editingDomain.getCommandStack().execute(addCommand);
    return !addCommand.getResult().isEmpty();
}
 
Example 5
Source File: GenerationFileNamesPage.java    From M2Doc with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Validates the page and gets the {@link TemplateCustomProperties} if any.
 * 
 * @param gen
 *            the {@link Generation}
 * @param templateURI
 *            the template {@link URI}
 * @return the {@link TemplateCustomProperties} if any, <code>null</code> otherwise
 */
private TemplateCustomProperties validatePage(Generation gen, URI templateURI) {
    TemplateCustomProperties res;

    final EditingDomain editingDomain = TransactionUtil.getEditingDomain(gen);

    final URI absoluteURI = templateURI.resolve(gen.eResource().getURI());
    if (URIConverter.INSTANCE.exists(absoluteURI, null)) {
        try {
            res = POIServices.getInstance().getTemplateCustomProperties(URIConverter.INSTANCE, absoluteURI);
            final List<Definition> oldDefinitions = GenconfUtils.getOldDefinitions(gen, res);
            final Command removeCommand = RemoveCommand.create(editingDomain, gen,
                    GenconfPackage.GENERATION__DEFINITIONS, oldDefinitions);
            editingDomain.getCommandStack().execute(removeCommand);

            final List<Definition> newDefinitions = GenconfUtils.getNewDefinitions(gen, res);
            final Command addCommand = AddCommand.create(editingDomain, gen, GenconfPackage.GENERATION__DEFINITIONS,
                    newDefinitions);
            editingDomain.getCommandStack().execute(addCommand);
            // CHECKSTYLE:OFF
        } catch (Exception e) {
            // CHECKSTYLE:ON
            setErrorMessage("Invalid template: " + e.getMessage());
            res = null;
        }
    } else {
        res = null;
        setErrorMessage("Template " + absoluteURI + " doesn't exist.");
    }

    if (res != null) {
        setPageComplete(true);
        if (!M2DocUtils.VERSION.equals(res.getM2DocVersion())) {
            setMessage("M2Doc version mismatch: template version is " + res.getM2DocVersion()
                + " and current M2Doc version is " + M2DocUtils.VERSION, IMessageProvider.WARNING);
        } else {
            setErrorMessage(null);
        }
    } else {
        setPageComplete(false);
    }

    return res;
}
 
Example 6
Source File: AdditionalResourcesConfigurationSyncronizer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected Command createAddCommand(EditingDomain editingDomain, Configuration configuration, Resource newResource) {
    return AddCommand.create(editingDomain, configuration,
            ConfigurationPackage.Literals.CONFIGURATION__ADDITIONAL_RESOURCES, newResource);
}