org.eclipse.emf.transaction.RecordingCommand Java Examples

The following examples show how to use org.eclipse.emf.transaction.RecordingCommand. 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: VariableAndOptionPage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Edits the given {@link Option}.
 * 
 * @param genEditingDomain
 *            the {@link TransactionalEditingDomain}
 * @param gen
 *            the {@link Generation}
 * @param option
 *            the {@link Option} to edit
 */
private void editOption(final TransactionalEditingDomain genEditingDomain, final Generation gen,
        final Option option) {
    final M2DocOptionDialog dialog = new M2DocOptionDialog(getShell(), gen, option);
    final int dialogResult = dialog.open();
    if (dialogResult == IDialogConstants.OK_ID) {
        genEditingDomain.getCommandStack().execute(new RecordingCommand(genEditingDomain) {

            @Override
            protected void doExecute() {
                option.setName(dialog.getOptionName());
                option.setValue(dialog.getOptionValue());
            }
        });
    }
}
 
Example #2
Source File: VariableAndOptionPage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Initializes {@link Generation#getDefinitions() variable definition} for the given {@link Generation}.
 * 
 * @param gen
 *            the {@link Generation}
 */
private void initializeGenerationVariableDefinition(final Generation gen) {
    final TemplateCustomProperties properties = templateCustomPropertiesProvider.getTemplateCustomProperties();
    ((IQueryEnvironment) queryEnvironment).registerEPackage(EcorePackage.eINSTANCE);
    ((IQueryEnvironment) queryEnvironment).registerCustomClassMapping(
            EcorePackage.eINSTANCE.getEStringToStringMapEntry(), EStringToStringMapEntryImpl.class);
    if (properties != null) {
        properties.configureQueryEnvironmentWithResult((IQueryEnvironment) queryEnvironment);
    }

    final TransactionalEditingDomain generationDomain = TransactionUtil.getEditingDomain(gen);
    generationDomain.getCommandStack().execute(new RecordingCommand(generationDomain) {

        @Override
        protected void doExecute() {
            GenconfUtils.initializeVariableDefinition(gen, queryEnvironment, properties,
                    getEditingDomain(gen).getResourceSet());
        }
    });
}
 
Example #3
Source File: DiagramFileStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Remove the migration report from the proc file.
 *
 * @param save , Whether we save the resoruce after deletion or not
 * @throws IOException
 */
public void clearMigrationReport(final boolean save) throws IOException {
    final EObject toRemove = null;
    final Resource emfResource = getEMFResource();
    final Report report = getMigrationReport();
    if (report != null) {
        final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(toRemove);
        if (domain != null) {
            domain.getCommandStack().execute(new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                    emfResource.getContents().remove(report);
                }
            });
            if (save) {
                emfResource.save(Collections.emptyMap());
            }
        }
    }
}
 
Example #4
Source File: CustomCutCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(
		IProgressMonitor progressMonitor, IAdaptable info)
		throws ExecutionException {
	
	Clipboard.setToCopyEditParts(toCopyElement);
	TransactionalEditingDomain domain = (TransactionalEditingDomain) AdapterFactoryEditingDomain.getEditingDomainFor(toCopyElement);
	domain.getCommandStack().execute(new RecordingCommand(domain) {
		protected void doExecute() {
			for (IGraphicalEditPart part : toCopyElement) {
				EcoreUtil.delete(part.resolveSemanticElement());
			}
		}
	});		
	
	return CommandResult.newOKCommandResult();
}
 
Example #5
Source File: DataRefactorIT.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNameRefactorWithLocalDataReferencedInMultiInstanciation() {
    final String newDataName = "newDataName";
    final AbstractProcess process = initTestForLocalDataRefactor(newDataName);

    // Data referenced in multi-instanciation
    final Activity activity = getActivity(process);
    editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

        @Override
        protected void doExecute() {
            activity.setIteratorExpression(ExpressionHelper.createVariableExpression(localData));
            activity.setOutputData(localData);
            localData.setName(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.getOutputData().getName());
}
 
Example #6
Source File: GenerationFileNamesPage.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the generation URI.
 * 
 * @param gen
 *            the {@link Generation}
 * @param newGenconfURI
 *            the new generation URI
 */
private void updateGenconfURI(final Generation gen, final URI newGenconfURI) {
    final URI templateAbsolutURI;
    if (gen.getTemplateFileName() != null) {
        templateAbsolutURI = GenconfUtils.getResolvedURI(gen, URI.createURI(gen.getTemplateFileName(), false));
    } else {
        templateAbsolutURI = null;
    }
    final URI validationAbsolutURI;
    if (gen.getValidationFileName() != null) {
        validationAbsolutURI = GenconfUtils.getResolvedURI(gen, URI.createURI(gen.getValidationFileName(), false));
    } else {
        validationAbsolutURI = null;
    }
    final URI resultAbsolutURI;
    if (gen.getResultFileName() != null) {
        resultAbsolutURI = GenconfUtils.getResolvedURI(gen, URI.createURI(gen.getResultFileName()));
    } else {
        resultAbsolutURI = null;
    }

    gen.eResource().setURI(newGenconfURI);

    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(gen);
    editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

        @Override
        protected void doExecute() {
            if (templateAbsolutURI != null) {
                gen.setTemplateFileName(URI.decode(templateAbsolutURI.deresolve(newGenconfURI).toString()));
            }
            if (validationAbsolutURI != null) {
                gen.setValidationFileName(URI.decode(validationAbsolutURI.deresolve(newGenconfURI).toString()));
            }
            if (resultAbsolutURI != null) {
                gen.setResultFileName(URI.decode(resultAbsolutURI.deresolve(newGenconfURI).toString()));
            }
        }
    });
}
 
Example #7
Source File: VariableAndOptionPage.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e) {
    final Definition def = (Definition) ((IStructuredSelection) variablesViewer.getSelection())
            .getFirstElement();
    final DefinitionValueDialog dialog = new DefinitionValueDialog(getShell(), adapterFactory, def,
            queryEnvironment, templateCustomPropertiesProvider.getTemplateCustomProperties(),
            getEditingDomain(gen).getResourceSet());
    final int dialogResult = dialog.open();
    if (dialogResult == IDialogConstants.OK_ID) {
        final TransactionalEditingDomain generationDomain = TransactionUtil.getEditingDomain(gen);
        generationDomain.getCommandStack().execute(new RecordingCommand(generationDomain) {

            @Override
            protected void doExecute() {
                if (def instanceof BooleanDefinition) {
                    ((BooleanDefinition) def).setValue((boolean) dialog.getValue());
                } else if (def instanceof IntegerDefinition) {
                    ((IntegerDefinition) def).setValue((int) dialog.getValue());
                } else if (def instanceof ModelDefinition) {
                    ((ModelDefinition) def).setValue((EObject) dialog.getValue());
                } else if (def instanceof RealDefinition) {
                    ((RealDefinition) def).setValue((double) dialog.getValue());
                } else if (def instanceof StringDefinition) {
                    ((StringDefinition) def).setValue((String) dialog.getValue());
                } else {
                    throw new IllegalStateException("don't know what to do with " + def);
                }
            }
        });
    }
}
 
Example #8
Source File: PapyrusModelCreator.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an empty Papyrus Model
 */
public void createPapyrusModel(){
	ModelSet modelSet = createModelSet();
	URI diPResURI =  URI.createPlatformResourceURI(diFilePath, true);
	RecordingCommand command = new NewPapyrusModelCommand(modelSet, diPResURI);
	modelSet.getTransactionalEditingDomain().getCommandStack().execute(command);
	initRegistry(registry);
	
	try {
		modelSet.save(new NullProgressMonitor());
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #9
Source File: EMFModelUpdater.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public RecordingCommand createUpdateCommand(TransactionalEditingDomain editingDomain) {
    return new RecordingCommand(editingDomain) {

        @Override
        protected void doExecute() {
            synched.clear();
            manyFeaturesSynched.clear();
            deepEObjectUpdate(source, workingCopy);
        }
    };
}
 
Example #10
Source File: MigrationStatusView.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void clearMigrationReport(final boolean save) throws IOException {
    final IEditorPart editorPart = (IEditorPart) tableViewer.getInput();
    if (editorPart != null && editorPart instanceof DiagramEditor) {
        final Resource emfResource = ((DiagramEditor) editorPart).getDiagramEditPart().getNotationView().eResource();
        final Report report = getMigrationReport(emfResource);
        if (report != null) {
            final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(emfResource);
            if (domain != null) {
                domain.getCommandStack().execute(new RecordingCommand(domain) {

                    @Override
                    protected void doExecute() {
                        emfResource.getContents().remove(report);
                    }
                });
                if (save) {
                    final ICommandService service = (ICommandService) getSite().getService(ICommandService.class);
                    final Command cmd = service.getCommand("org.eclipse.ui.file.save");
                    try {
                        cmd.executeWithChecks(new ExecutionEvent());
                    } catch (final Exception e) {
                        BonitaStudioLog.error(e, MigrationPlugin.PLUGIN_ID);
                    }
                }
            }
        }
    }
}
 
Example #11
Source File: NewGenerationWizard.java    From M2Doc with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void addPages() {
    super.addPages();

    final Generation loadedGeneration = getGeneration(selection);
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(generation);
    if (loadedGeneration == null) {
        final URI genconfURI = getGenconfURI(selection);
        if (genconfURI != null) {
            generation.eResource().setURI(genconfURI);
            editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

                @Override
                protected void doExecute() {
                    generation.setTemplateFileName(URI.decode(getTemplateFileName(genconfURI).toString()));
                    generation.setValidationFileName(getValidationFileName(genconfURI));
                    generation.setResultFileName(getResultFileName(genconfURI));
                    GenconfUtils.initializeOptions(generation);

                    initializeVariableDefinition(generation);
                }

            });
        }
    } else {
        generation.eResource().setURI(loadedGeneration.eResource().getURI());
        editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

            @Override
            protected void doExecute() {
                generation.setName(loadedGeneration.getName());
                generation.setTemplateFileName(loadedGeneration.getTemplateFileName());
                generation.setValidationFileName(loadedGeneration.getValidationFileName());
                generation.setResultFileName(loadedGeneration.getResultFileName());
                generation.getDefinitions().addAll(loadedGeneration.getDefinitions());
                generation.getOptions().addAll(loadedGeneration.getOptions());
                GenconfUtils.initializeOptions(generation);

                initializeVariableDefinition(generation);
            }

        });
    }

    generationListener = new GenerationListener();
    generationListener.installGenerationListener(generation);

    fileNamesPage = new GenerationFileNamesPage(generation, generationListener, canChangeTemplateFile);
    addPage(fileNamesPage);
    optionPage = new VariableAndOptionPage(generation, generationListener, fileNamesPage);
    addPage(optionPage);
}
 
Example #12
Source File: DiagramElementsModifierTest.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Test initializing function. It builds up the Papyrus model for the Test
 * 
 * @param objects
 * @param links
 */
public void init(List<Pair<String, java.lang.Class<?>>> objects,
		List<Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>> links) {

	String projectname = "testproject";
	project = ProjectUtils.createProject(projectname);
	ProjectUtils.openProject(project);

	PapyrusModelCreator pmc = new PapyrusModelCreator(projectname
			+ "/model");
	try {
		pmc.createPapyrusModel();

		HashMap<String, org.eclipse.uml2.uml.Class> nodes = new HashMap<String, org.eclipse.uml2.uml.Class>();

		IFile diFile = pmc.getDi();

		IEditorInput editorInput = new FileEditorInput(diFile);
		IWorkbenchWindow window = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow();
		IEditorPart ed = null;
		ed = IDE.openEditor(window.getActivePage(), editorInput,
				"org.eclipse.papyrus.infra.core.papyrusEditor", true);

		editor = (IMultiDiagramEditor) ed;

		ModelSet modelSet = editor.getServicesRegistry().getService(
				ModelSet.class);
		Map<String, DiagramCategoryDescriptor> categories = DiagramCategoryRegistry
				.getInstance().getDiagramCategoryMap();
		IModelCreationCommand creationCommand = categories.get("uml")
				.getCommand();
		creationCommand.createModel(modelSet);
		AbstractPapyrusModelManager manager = new DefaultPapyrusModelManager(
				editor);

		EObject model = UmlUtils.getUmlModel().lookupRoot();
		org.eclipse.uml2.uml.Package modelpackage = (org.eclipse.uml2.uml.Package) model;

		TransactionalEditingDomain ted = TransactionUtil
				.getEditingDomain(model);
		ted.getCommandStack().execute(new RecordingCommand(ted) {
			@Override
			protected void doExecute() {
				for (Pair<String, java.lang.Class<?>> pair : objects) {
					java.lang.Class<?> type = pair.getSecond();
					if (type.isAssignableFrom(org.eclipse.uml2.uml.Class.class)) {
						org.eclipse.uml2.uml.Class created = modelpackage
								.createOwnedClass(pair.getFirst(), false);
						nodes.put(pair.getFirst(), created);
					} else if (type
							.isAssignableFrom(org.eclipse.uml2.uml.Package.class)) {
						modelpackage.createNestedPackage(pair.getFirst());
					} else if (type
							.isAssignableFrom(org.eclipse.uml2.uml.Interface.class)) {
						modelpackage.createOwnedInterface(pair.getFirst());
					}

				}

				for (Pair<Pair<String, Class<?>>, Pair<String, Class<?>>> link : links) {
					Pair<String, Class<?>> pairA = link.getFirst();
					Pair<String, Class<?>> pairB = link.getSecond();

					String nameA = pairA.getFirst();
					String nameB = pairB.getFirst();

					org.eclipse.uml2.uml.Class classA = nodes.get(nameA);
					org.eclipse.uml2.uml.Class classB = nodes.get(nameB);

					classA.createAssociation(false,
							AggregationKind.NONE_LITERAL, "", 1, 1, classB,
							true, AggregationKind.NONE_LITERAL, "", 1, 1);
				}
			}
		});

		manager.createAndFillDiagrams(new NullProgressMonitor());
		editor.doSave(new NullProgressMonitor());

	} catch (Throwable e) {
		e.printStackTrace();
		fail("Initialization Error");
	}
}