Java Code Examples for org.eclipse.emf.transaction.util.TransactionUtil

The following examples show how to use org.eclipse.emf.transaction.util.TransactionUtil. These examples are extracted from open source projects. 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 Project: scava   Author: crossminer   File: DiagramEditorContextMenuProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
public void buildContextMenu(final IMenuManager menu) {
	getViewer().flush();
	try {
		TransactionUtil.getEditingDomain((EObject) getViewer().getContents().getModel())
				.runExclusive(new Runnable() {

					public void run() {
						ContributionItemService.getInstance()
								.contributeToPopupMenu(DiagramEditorContextMenuProvider.this, part);
						menu.remove(ActionIds.ACTION_DELETE_FROM_MODEL);
						menu.appendToGroup("editGroup", deleteAction);
					}
				});
	} catch (Exception e) {
		CrossflowDiagramEditorPlugin.getInstance().logError("Error building context menu", e);
	}
}
 
Example #2
Source Project: M2Doc   Author: ObeoNetwork   File: VariableAndOptionPage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the {@link EditingDomain} for the given {@link Generation}.
 * 
 * @param gen
 *            the {@link Generation}
 */
private void updateEditingDomain(Generation gen) {
    final ResourceSetImpl defaultResourceSet = new ResourceSetImpl();
    defaultResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
            new XMIResourceFactoryImpl());

    if (editingDomain != null) {
        M2DocUtils.cleanResourceSetForModels(queryEnvironment, editingDomain.getResourceSet());
    }
    if (createdEditingDomaine) {
        editingDomain.dispose();
        editingDomain = null;
    }

    final ResourceSet modelResourceSet = M2DocUtils.createResourceSetForModels(new ArrayList<Exception>(),
            queryEnvironment, defaultResourceSet, GenconfUtils.getOptions(gen));
    final TransactionalEditingDomain modelEditingDomain = TransactionUtil.getEditingDomain(modelResourceSet);
    if (modelEditingDomain == null) {
        editingDomain = TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(modelResourceSet);
        createdEditingDomaine = true;
    } else {
        editingDomain = modelEditingDomain;
        createdEditingDomaine = false;
    }
}
 
Example #3
Source Project: statecharts   Author: Yakindu   File: AbstractPackageImportUriMapper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Optional<PackageImport> findPackageImport(Resource context, String packageImport) {
	try {
		return TransactionUtil.runExclusive(getSharedEditingDomain(),
				new RunnableWithResult.Impl<Optional<PackageImport>>() {
					@Override
					public void run() {
						Set<PackageImport> allImports = getAllImports(getContextResource(context));
						for (PackageImport currentImport : allImports) {
							if (currentImport.getName().equals(packageImport)) {
								setResult(Optional.of(currentImport));
								return;
							}
						}
						setResult(Optional.empty());
					}

				});
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	return Optional.empty();
}
 
Example #4
Source Project: statecharts   Author: Yakindu   File: SharedEditingDomainFactory.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void unloadWithReferences(Resource resource) {
	TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
	try {
		editingDomain.runExclusive(new Runnable() {
			@Override
			public void run() {
				Set<Resource> resourcesToUnload = new HashSet<>();
				collectTransitiveReferences(resource, resourcesToUnload);
				resourcesToUnload.add(resource);
				
				collectResourcesWithErrors(resource, resourcesToUnload);
				
				for (Resource current : resourcesToUnload) {
					if (current instanceof AbstractSCTResource || !current.getURI().isPlatform())
						continue;
					current.unload();
				}
			}

		});
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
Example #5
Source Project: statecharts   Author: Yakindu   File: ShadowModelValidationJob.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void cloneResource(final IProgressMonitor monitor, final Resource shadowResource)
		throws ExecutionException {
	final ByteArrayOutputStream bout = new ByteArrayOutputStream();
	try {
		TransactionUtil.getEditingDomain(resource).runExclusive(() -> {
			try {
				XMISaveImpl saver = new XMISaveImpl(new XMIHelperImpl((XMLResource) resource));
				saver.save((XMLResource) resource, bout, Collections.emptyMap());
				bout.flush();
			} catch (Throwable tt) {
				tt.printStackTrace();
			}
		});
	} catch (InterruptedException e1) {
		e1.printStackTrace();
	}
	try {
		shadowResource.load(new ByteArrayInputStream(bout.toByteArray()), Collections.emptyMap());
	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
Example #6
Source Project: statecharts   Author: Yakindu   File: ToggleSubRegionLayoutCommand.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	view = unwrap(HandlerUtil.getCurrentSelection(event));

	TransactionalEditingDomain editingDomain = TransactionUtil
			.getEditingDomain(view);
	ToggleCommand toggleCommand = new ToggleCommand(editingDomain, view);

	try {
		OperationHistoryFactory.getOperationHistory().execute(
				toggleCommand, new NullProgressMonitor(), null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}

	return null;
}
 
Example #7
Source Project: statecharts   Author: Yakindu   File: AbstractSemanticModification.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Executes the modification in a transactional command.
 */
public void modify() {
	if (! isApplicable()) throw new IllegalStateException("Modification " + getClass().getSimpleName() + " is not executable.");
	
	final EObject semanticObject = getTargetView().getElement();
	AbstractTransactionalCommand refactoringCommand = new AbstractTransactionalCommand(
			TransactionUtil.getEditingDomain(semanticObject), getClass().getName(), Collections.EMPTY_LIST) {
		@Override
		protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
				throws ExecutionException {
			try {
				AbstractSemanticModification.this.execute(semanticObject, getTargetView());
			} catch (Exception ex) {
				ex.printStackTrace();
				return CommandResult.newErrorCommandResult(ex);
			}
			return CommandResult.newOKCommandResult();
		}
	};
	executeCommand(refactoringCommand, semanticObject.eResource());
}
 
Example #8
Source Project: bonita-studio   Author: bonitasoft   File: CreateVariableProposalListener.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public String handleEvent(final EObject context, final String fixedReturnType) {
    Assert.isNotNull(context);
    final EObject dataContainer = getDataContainer(context);
    final Data dataWorkingCopy = ProcessFactory.eINSTANCE.createData();
    dataWorkingCopy.setMultiple(multipleData);
    dataWorkingCopy.setDataType(ModelHelper.getDataTypeForID(dataContainer, DataTypeLabels.stringDataType));
    final DataWizard newWizard = new DataWizard(TransactionUtil.getEditingDomain(context), dataContainer, dataWorkingCopy, feature,
            Collections.singleton(feature), true,
            fixedReturnType);
    newWizard.setIsPageFlowContext(isPageFlowContext);
    final CustomWizardDialog wizardDialog = new CustomWizardDialog(activeShell(), newWizard, IDialogConstants.FINISH_LABEL);
    if (wizardDialog.open() == Dialog.OK) {
        RepositoryManager.getInstance().getCurrentRepository().buildXtext();
        final Data newData = newWizard.getNewData();
        if (newData != null) {
            return newData.getName();
        }
    }
    return null;
}
 
Example #9
Source Project: bonita-studio   Author: bonitasoft   File: BPMNDataExportImportTest.java    License: 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 #10
Source Project: bonita-studio   Author: bonitasoft   File: TestDocumentRefactoring.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Document refactorDocumentTypeAndMultiplicity(final Pool pool, final Document document)
        throws InvocationTargetException, InterruptedException {
    final Document newDocument = EcoreUtil.copy(document);
    newDocument.setMultiple(true);
    newDocument.setDocumentType(DocumentType.EXTERNAL);
    final RefactorDocumentOperation refactorOperation = new RefactorDocumentOperation(RefactoringOperationType.UPDATE);
    refactorOperation.setEditingDomain(TransactionUtil.getEditingDomain(pool));
    refactorOperation.addItemToRefactor(newDocument, document);
    final IProgressService service = PlatformUI.getWorkbench().getProgressService();
    service.busyCursorWhile(refactorOperation);
    final Document documentRefactored = pool.getDocuments().get(0);
    assertEquals(newDocument.getName(), documentRefactored.getName());
    assertEquals(newDocument.getDocumentType(), documentRefactored.getDocumentType());
    return documentRefactored;

}
 
Example #11
Source Project: bonita-studio   Author: bonitasoft   File: ProcessDataViewer.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void moveData(final IStructuredSelection structuredSelection) {
    final DataAware container = (DataAware) getDataContainerObservable().getValue();
    final MoveDataWizard moveDataWizard = new MoveDataWizard(container);
    if (createWizardDialog(moveDataWizard, IDialogConstants.FINISH_LABEL).open() == Dialog.OK) {
        final DataAware dataAware = moveDataWizard.getSelectedDataAwareElement();
        try {
            final MoveDataCommand cmd = new MoveDataCommand(TransactionUtil.getEditingDomain(dataAware), container,
                    structuredSelection.toList(), dataAware);
            OperationHistoryFactory.getOperationHistory().execute(cmd, null, null);

            if (!(cmd.getCommandResult().getStatus().getSeverity() == Status.OK)) {
                final List<Object> data = (List<Object>) cmd.getCommandResult().getReturnValue();
                String dataNames = "";
                for (final Object d : data) {
                    dataNames = dataNames + ((Element) d).getName() + ",";
                }
                dataNames = dataNames.substring(0, dataNames.length() - 1);
                MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.PromoteDataWarningTitle,
                        Messages.bind(Messages.PromoteDataWarningMessage, dataNames));
            }

        } catch (final ExecutionException e1) {
            BonitaStudioLog.error(e1);
        }
    }
}
 
Example #12
Source Project: bonita-studio   Author: bonitasoft   File: ExpressionCollectionViewer.java    License: 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 #13
Source Project: bonita-studio   Author: bonitasoft   File: TestDocumentRefactoring.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void refactorDocument(final Pool pool) throws InvocationTargetException, InterruptedException {
    final Document documentToRefactor = pool.getDocuments().get(0);
    final RefactorDocumentOperation refactorOperation = new RefactorDocumentOperation(RefactoringOperationType.UPDATE);
    refactorOperation.setEditingDomain(TransactionUtil.getEditingDomain(pool));
    final Document newDocument = EcoreUtil.copy(documentToRefactor);
    newDocument.setName(newDocumentName);
    refactorOperation.addItemToRefactor(newDocument, documentToRefactor);
    final IProgressService service = PlatformUI.getWorkbench().getProgressService();
    service.busyCursorWhile(refactorOperation);
    final Document documentRefactored = pool.getDocuments().get(0);
    assertEquals(newDocument.getName(), documentRefactored.getName());
    testDocumentInExpressionsRefactored(documentRefactored, 2, pool);
    final Document currentDoc = refactorDocumentTypeAndMultiplicity(pool, documentRefactored);
    testRemoveDocumentRefactoring(currentDoc, pool);

}
 
Example #14
Source Project: bonita-studio   Author: bonitasoft   File: BatchValidationOperation.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void execute(final IProgressMonitor monitor)
        throws CoreException, InvocationTargetException, InterruptedException {
    Assert.isLegal(!diagramsToDiagramEditPart.isEmpty());
    buildEditPart();
    validationMarkerProvider.clearMarkers(diagramsToDiagramEditPart);
    for (final Entry<Diagram, DiagramEditPart> entry : diagramsToDiagramEditPart.entrySet()) {
        final DiagramEditPart diagramEp = entry.getValue();
        final Diagram diagram = entry.getKey();
        if (diagramEp != null && !monitor.isCanceled()) {
            monitor.setTaskName(Messages.bind(
                    Messages.validatingProcess, ((MainProcess) diagramEp.resolveSemanticElement()).getName(),
                    ((MainProcess) diagramEp.resolveSemanticElement()).getVersion()));
            final TransactionalEditingDomain txDomain = TransactionUtil.getEditingDomain(diagram);
            runWithConstraints(txDomain, () -> validate(diagramEp, diagram, monitor));
            monitor.worked(1);
        }
    }
    offscreenEditPartFactory.dispose();
}
 
Example #15
Source Project: bonita-studio   Author: bonitasoft   File: NewDiagramCommandHandler.java    License: 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 #16
Source Project: bonita-studio   Author: bonitasoft   File: DuplicateDiagramOperation.java    License: 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 #17
Source Project: bonita-studio   Author: bonitasoft   File: DiagramFileStore.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doSave(final Object content) {
    final Resource resource = getEMFResource();
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
    try {
        OperationHistoryFactory.getOperationHistory().execute(
                new SaveDiagramResourceCommand(content, editingDomain, resource),
                Repository.NULL_PROGRESS_MONITOR,
                null);
    } catch (final ExecutionException e1) {
        BonitaStudioLog.error(e1);
    }
    if (content instanceof DiagramDocumentEditor) {
        ((DiagramDocumentEditor) content).doSave(Repository.NULL_PROGRESS_MONITOR);
    }

    try {
        resource.save(ProcessDiagramEditorUtil.getSaveOptions());
    } catch (final IOException e) {
        BonitaStudioLog.error(e);
    }
}
 
Example #18
Source Project: bonita-studio   Author: bonitasoft   File: DiagramFileStore.java    License: 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 #19
Source Project: bonita-studio   Author: bonitasoft   File: BatchValidationHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void addDiagramsToValidate(final BatchValidationOperation validateOperation, final String[] files) throws IOException {
    final DiagramRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
    for (final String fName : files) {
        final String fileName = fName.trim();
        final DiagramFileStore fileStore = store.getChild(fileName, true);
        if (fileStore == null) {
            throw new IOException(fileName + " does not exists in " + store.getResource().getLocation());
        }
        currentDiagramStore = fileStore;
        fileStore.getContent();//force resource to be loaded
        final Resource eResource = fileStore.getEMFResource();
        final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(eResource);
        final FindDiagramRunnable runnable = new FindDiagramRunnable(eResource, validateOperation);
        if (editingDomain != null) {
            try {
                editingDomain.runExclusive(runnable);
            } catch (final InterruptedException e) {
                BonitaStudioLog.error(e);
            }
        } else {
            runnable.run();
        }
    }
}
 
Example #20
Source Project: bonita-studio   Author: bonitasoft   File: ModelHelper.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param form
 * @return the diagram corresponding to the form.
 */
public static Diagram getDiagramFor(final EObject element, final Resource resource) {
    if (element == null) {
        return null;
    }
    if (!resource.isLoaded()) {
        throw new IllegalStateException("EMF Resource is not loaded.");
    }

    final RunnableWithResult<Diagram> runnableWithResult = new DiagramForElementRunnable(resource, element);
    final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
    if (editingDomain != null) {
        try {
            editingDomain.runExclusive(runnableWithResult);
        } catch (final InterruptedException e) {
            BonitaStudioLog.error(e);
        }
    } else {
        runnableWithResult.run();
    }
    return runnableWithResult.getResult();
}
 
Example #21
Source Project: bonita-studio   Author: bonitasoft   File: CustomEMFEditObservables.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature) {
    return new IObservableFactory()
    {

        @Override
        public IObservable createObservable(final Object target)
        {
            if (((EObject) target).eResource() != null) {
                final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(target);
                if (domain != null) {
                    return observeList(realm, domain, (EObject) target, eStructuralFeature);
                }
            }

            return observeList(realm, (EObject) target, eStructuralFeature);

        }
    };
}
 
Example #22
Source Project: bonita-studio   Author: bonitasoft   File: CreateParameterProposalListener.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public String handleEvent(final EObject context, final String fixedReturnType) {
    Assert.isNotNull(context);
    final AbstractProcess parentProcess = ModelHelper.getParentProcess(context);
    final AddParameterWizard parameterWizard = new AddParameterWizard(parentProcess,
            TransactionUtil.getEditingDomain(context));
    final ParameterWizardDialog parameterDialog = new ParameterWizardDialog(
            Display.getDefault().getActiveShell(), parameterWizard);
    if (parameterDialog.open() == Dialog.OK) {
        final Parameter param = parameterWizard.getNewParameter();
        if (param != null) {
            return param.getName();
        }
    }
    return null;
}
 
Example #23
Source Project: bonita-studio   Author: bonitasoft   File: BonitaTreeOutlinePage.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * initialize the outline viewer
 */
protected void initializeOutlineViewer() {
    try {
        TransactionUtil.getEditingDomain(getDiagram()).runExclusive(
                new Runnable() {

                    @Override
                    public void run() {
                        getViewer().setContents(getDiagram());
                    }
                });
    } catch (final InterruptedException e) {
        Trace.catching(DiagramUIPlugin.getInstance(),
                DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "initializeOutlineViewer", e); //$NON-NLS-1$
        Log.error(DiagramUIPlugin.getInstance(),
                DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "initializeOutlineViewer", e); //$NON-NLS-1$
    }
    ((BonitaTreeViewer) getViewer())
            .setDiagramEditPart(getDiagramEditPart());
}
 
Example #24
Source Project: scava   Author: crossminer   File: OpenDiagramEditPolicy.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
OpenDiagramCommand(HintedDiagramLinkStyle linkStyle) {
	// editing domain is taken for original diagram, 
	// if we open diagram from another file, we should use another editing domain
	super(TransactionUtil.getEditingDomain(linkStyle), Messages.CommandName_OpenDiagram, null);
	diagramFacet = linkStyle;
}
 
Example #25
Source Project: scava   Author: crossminer   File: ValidateAction.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
public static void runValidation(DiagramEditPart diagramEditPart, View view) {
	final DiagramEditPart fpart = diagramEditPart;
	final View fview = view;
	TransactionalEditingDomain txDomain = TransactionUtil.getEditingDomain(view);
	CrossflowValidationProvider.runWithConstraints(txDomain, new Runnable() {

		public void run() {
			validate(fpart, fview);
		}
	});
}
 
Example #26
Source Project: scava   Author: crossminer   File: CrossflowViewProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private EObject getSemanticElement(IAdaptable semanticAdapter) {
	if (semanticAdapter == null) {
		return null;
	}
	EObject eObject = (EObject) semanticAdapter.getAdapter(EObject.class);
	if (eObject != null) {
		return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
	}
	return null;
}
 
Example #27
Source Project: bonita-studio   Author: bonitasoft   File: RefactorDocumentOperationTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    DiagramFileStore newDiagram = new NewDiagramCommandHandler().newDiagram();
    domain = TransactionUtil.getEditingDomain(newDiagram.getEMFResource());
    parentProcess = (Pool) newDiagram.getContent().getElements().get(0);
    document = ProcessFactory.eINSTANCE.createDocument();
    document.setName(INITIAL_DOC_NAME);
    document.setMimeType(ExpressionHelper.createConstantExpression("octet/stream", String.class.getName()));
    domain.getCommandStack().execute(new AddCommand(domain, parentProcess.getDocuments(), document));
}
 
Example #28
Source Project: bonita-studio   Author: bonitasoft   File: InputNameObservableEditingSupport.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected IObservableValue doCreateElementObservable(final Object element, final ViewerCell cell) {
    checkArgument(element instanceof ContractInput);
    final IObservableValue observableValue = ((ContractInput) element).eContainer() instanceof Contract ? EMFEditWithRefactorObservables
            .observeValueWithRefactor(
                    TransactionUtil.getEditingDomain(element),
                    (EObject) element,
                    ProcessPackage.Literals.CONTRACT_INPUT__NAME,
                    contractInputRefactorOperationFactory,
                    progressService) : EMFEditObservables.observeValue(TransactionUtil.getEditingDomain(element), (EObject) element,
            ProcessPackage.Literals.CONTRACT_INPUT__NAME);
    observableValue.addValueChangeListener(new ColumnViewerUpdateListener(getViewer(), element));
    return observableValue;
}
 
Example #29
Source Project: M2Doc   Author: ObeoNetwork   File: VariableAndOptionPage.java    License: 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 #30
Source Project: bonita-studio   Author: bonitasoft   File: DataRefactorIT.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return an AbstractProcess with a global data and a local data on an activity.
 */

private AbstractProcess createProcessWithData() {
    if (process == null) {
        newDiagram = new NewDiagramCommandHandler().newDiagram();
        editingDomain = TransactionUtil.getEditingDomain(newDiagram.getEMFResource());
        final MainProcess mainProcess = newDiagram.getContent();
        process = (Pool) mainProcess.getElements().get(0);
        processData = ProcessFactory.eINSTANCE.createData();
        processData.setDatasourceId("BOS");
        processData.setName("globalData");
        processData.setDataType(ModelHelper.getDataTypeForID(mainProcess, DataTypeLabels.stringDataType));
        editingDomain.getCommandStack().execute(
                AddCommand.create(editingDomain, process, ProcessPackage.Literals.DATA_AWARE__DATA, processData));

        processData2 = ProcessFactory.eINSTANCE.createData();
        processData2.setDatasourceId("BOS");
        processData2.setName("globalData2");
        processData2.setDataType(ModelHelper.getDataTypeForID(mainProcess, DataTypeLabels.stringDataType));
        editingDomain.getCommandStack().execute(
                AddCommand.create(editingDomain, process, ProcessPackage.Literals.DATA_AWARE__DATA, processData2));

        final Activity activity = new ModelSearch(Collections::emptyList).getAllItemsOfType(mainProcess, Activity.class)
                .get(0);
        localData = ProcessFactory.eINSTANCE.createData();
        localData.setDatasourceId("BOS");
        localData.setName("localData");
        localData.setDataType(ModelHelper.getDataTypeForID(mainProcess, DataTypeLabels.stringDataType));
        editingDomain.getCommandStack().execute(
                AddCommand.create(editingDomain, activity, ProcessPackage.Literals.DATA_AWARE__DATA, localData));


    }
    return process;
}