Java Code Examples for org.eclipse.emf.transaction.util.TransactionUtil#getEditingDomain()
The following examples show how to use
org.eclipse.emf.transaction.util.TransactionUtil#getEditingDomain() .
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: ModelHelper.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
public static Diagram getDiagramFor(final EObject element, EditingDomain domain) { if (element == null) { return null; } Resource resource = element.eResource(); if (resource == null) { if (domain == null) { domain = TransactionUtil.getEditingDomain(element); if (domain != null) { resource = domain.getResourceSet().getResource(element.eResource().getURI(), true); } } else if (domain.getResourceSet() != null) { resource = domain.getResourceSet().getResource(element.eResource().getURI(), true); } } if (resource == null) { throw new IllegalStateException(String.format("No resource attached to EObject %s", element)); } return getDiagramFor(element, resource); }
Example 2
Source File: BatchValidationHandler.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
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 3
Source File: CreateParameterProposalListener.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@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 4
Source File: BPMNDataExportImportTest.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
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 5
Source File: CustomEMFEditObservables.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
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 6
Source File: DiagramFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * 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 7
Source File: ExpressionCollectionViewer.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private ListExpression addLineInTableExpression(final Object expressionInput) { final ListExpression rowExp = createListExpressionForNewLineInTable(); if (editingDomain == null) { editingDomain = TransactionUtil.getEditingDomain(expressionInput); } if (editingDomain != null) { editingDomain .getCommandStack() .execute( AddCommand .create(editingDomain, expressionInput, ExpressionPackage.Literals.TABLE_EXPRESSION__EXPRESSIONS, rowExp)); } else { ((TableExpression) expressionInput).getExpressions().add(rowExp); } return rowExp; }
Example 8
Source File: DocumentWizard.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public boolean performFinish() { final Pool pool = (Pool) ModelHelper.getParentProcess(context); final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(context); if (document == null) { editingDomain.getCommandStack() .execute(new AddCommand(editingDomain, pool.getDocuments(), EcoreUtil.copy(documentWorkingCopy))); } else { if (!performFinishOnEdition(editingDomain)) { return false; } } refreshProject(); return true; }
Example 9
Source File: ProcessDataViewer.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
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 10
Source File: ValidateAction.java From scava with Eclipse Public License 2.0 | 5 votes |
/** * @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 11
Source File: EnumDataTypeDialog.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected void okPressed() { getShell().setFocus(); final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(mainProc); for (final EnumType orignialType : ModelHelper.getAllUserDatatype(mainProc)) { if (!enumTypes.values().contains(orignialType)) { editingDomain.getCommandStack().execute( DeleteCommand.create(editingDomain, orignialType)); } } for (final Entry<EnumType, EnumType> type : enumTypes.entrySet()) { final EnumType workingCopy = type.getKey(); final EnumType existingCopy = type.getValue(); if (existingCopy == null) {//New Type editingDomain.getCommandStack().execute( AddCommand.create(editingDomain, mainProc, ProcessPackage.Literals.ABSTRACT_PROCESS__DATATYPES, workingCopy)); } else { //Update Type final CompoundCommand cc = new CompoundCommand(); cc.append(SetCommand.create(editingDomain, existingCopy, ProcessPackage.Literals.ELEMENT__NAME, workingCopy.getName())); cc.append(SetCommand.create(editingDomain, existingCopy, ProcessPackage.Literals.ELEMENT__DOCUMENTATION, workingCopy.getDocumentation())); cc.append(SetCommand.create(editingDomain, existingCopy, ProcessPackage.Literals.ENUM_TYPE__LITERALS, workingCopy.getLiterals())); editingDomain.getCommandStack().execute(cc); } } final EnumType selected = (EnumType) ((IStructuredSelection) typeList.getSelection()).getFirstElement(); if (selected != null) { for (final DataType t : mainProc.getDatatypes()) { if (t instanceof EnumType && t.getName().equals(selected.getName())) { selectedType = (EnumType) t; } } } super.okPressed(); }
Example 12
Source File: StringAttributeParser.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) { if (newString == null) { return UnexecutableCommand.INSTANCE; } EObject element = (EObject) adapter.getAdapter(EObject.class); TransactionalEditingDomain editingDomain = TransactionUtil .getEditingDomain(element); if (editingDomain == null) { return UnexecutableCommand.INSTANCE; } SetRequest request = new SetRequest(element, provider.getAttribute(), newString); return new SetValueCommand(request); }
Example 13
Source File: BPMNDataExportImportTest.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private DocumentRoot exportToBPMNProcessWithStepData(final Data data, String dataType) throws IOException { final NewDiagramCommandHandler newDiagramCommandHandler = new NewDiagramCommandHandler(); final DiagramFileStore newDiagramFileStore = newDiagramCommandHandler.newDiagram(); Resource emfResource = newDiagramFileStore.getEMFResource(); TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(emfResource); final AbstractProcess abstractProcess = newDiagramFileStore.getProcesses().get(0); abstractProcess.getElements().stream() .filter(Lane.class::isInstance) .map(Lane.class::cast) .map(Lane::getElements) .flatMap(Collection::stream) .filter(Task.class::isInstance) .findFirst() .ifPresent(task -> editingDomain.getCommandStack().execute( AddCommand.create(editingDomain, task, ProcessPackage.Literals.DATA_AWARE__DATA, data))); MainProcess mainProcess = newDiagramFileStore.getContent(); mainProcess.getDatatypes().stream() .filter(dt -> Objects.equals(NamingUtils.convertToId(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 14
Source File: EMFModelUpdater.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Applies the changes to the source object limiting UUID changes */ public T update() { TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(source); if (editingDomain != null) { editingDomain.getCommandStack().execute(createUpdateCommand(editingDomain)); } else { synched.clear(); manyFeaturesSynched.clear(); deepEObjectUpdate(source, workingCopy); } return source; }
Example 15
Source File: ValidateAction.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @generated */ public static void runValidation(DiagramEditPart diagramEditPart, View view) { final DiagramEditPart fpart = diagramEditPart; final View fview = view; TransactionalEditingDomain txDomain = TransactionUtil.getEditingDomain(view); ProcessValidationProvider.runWithConstraints(txDomain, new Runnable() { public void run() { validate(fpart, fview); } }); }
Example 16
Source File: DataRefactorIT.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @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; }
Example 17
Source File: ConfigurationSynchronizer.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public ConfigurationSynchronizer(final AbstractProcess process, final Configuration configuration) { this(); this.process = process; this.configuration = configuration; synchronizeLocalConfiguraiton = ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON.equals(configuration.getName()) || configuration.getName() == null; editingDomain = (AdapterFactoryEditingDomain) TransactionUtil.getEditingDomain(process); }
Example 18
Source File: NewGenerationWizard.java From M2Doc with Eclipse Public License 1.0 | 4 votes |
@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 19
Source File: TestTokenDispatcher.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Test public void testReturnTokenOfNonInterruptedBoudaryTimerEvent() throws Exception { /* Import a base process for the test */ final ProcessDiagramEditor processEditor = importBos("BS-10043_InfiniteLoopValidation-1.0.bos"); final MainProcess mainProcess = (MainProcess) processEditor.getDiagramEditPart().resolveSemanticElement(); final Pool parentProcess = (Pool) mainProcess.getElements().get(0); TransactionalEditingDomain domain = GMFEditingDomainFactory.getInstance() .getEditingDomain(parentProcess.eResource().getResourceSet()); if (domain == null) { domain = TransactionUtil.getEditingDomain(parentProcess); } if (domain == null) { domain = GMFEditingDomainFactory.getInstance().createEditingDomain(); } final TokenDispatcher tokenD = new TokenDispatcher(); NonInterruptingBoundaryTimerEvent boundaryEvent = null; SequenceFlow nonInterruptedOutgoingconnection = null; SequenceFlow taskOutgoingconnection = null; Task humanTask = null; for (final Connection transition : parentProcess.getConnections()) { if (transition.getSource() instanceof NonInterruptingBoundaryTimerEvent) { boundaryEvent = (NonInterruptingBoundaryTimerEvent) transition.getSource(); nonInterruptedOutgoingconnection = (SequenceFlow) transition; } else if (transition.getSource() instanceof Task) { humanTask = (Task) transition.getSource(); taskOutgoingconnection = (SequenceFlow) transition; } } assertNotNull(nonInterruptedOutgoingconnection); assertNotNull(boundaryEvent); assertNotNull(humanTask); // Test the token returned is the one of the source transition tokenD.setSequenceFlow(nonInterruptedOutgoingconnection); final String nonInterruptedToken = tokenD.getToken(); assertEquals("The token return should be the one of the NonInterruptingBoundaryTimerEvent", ModelHelper.getEObjectID(nonInterruptedOutgoingconnection.getSource()), nonInterruptedToken); // Test Non Interrupted token is different from the Task token tokenD.setSequenceFlow(taskOutgoingconnection); assertTrue("Non Interrupted token and task token must be different", !nonInterruptedToken.equals(tokenD.getToken())); }
Example 20
Source File: OperationsComposite.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected EditingDomain getEditingDomain() { return TransactionUtil.getEditingDomain(getEObject()); }