Java Code Examples for org.eclipse.emf.transaction.TransactionalEditingDomain#runExclusive()

The following examples show how to use org.eclipse.emf.transaction.TransactionalEditingDomain#runExclusive() . 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: CrossflowValidationProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
public static void runWithConstraints(TransactionalEditingDomain editingDomain, Runnable operation) {
	final Runnable op = operation;
	Runnable task = new Runnable() {
		public void run() {
			try {
				constraintsActive = true;
				op.run();
			} finally {
				constraintsActive = false;
			}
		}
	};
	if (editingDomain != null) {
		try {
			editingDomain.runExclusive(task);
		} catch (Exception e) {
			CrossflowDiagramEditorPlugin.getInstance().logError("Validation failed", e); //$NON-NLS-1$
		}
	} else {
		task.run();
	}
}
 
Example 2
Source File: AbstractPackageImportUriMapper.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected Resource getContextResource(Resource context) {
	TransactionalEditingDomain editingDomain = getSharedEditingDomain();
	try {
		return (Resource) editingDomain.runExclusive(new RunnableWithResult.Impl<Resource>() {
			@Override
			public void run() {
				final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context,
						ContextElementAdapter.class);
				if (provider != null) {
					setResult(provider.getElement().eResource());
					return;
				}
				setResult(context);
			}
		});
	} catch (InterruptedException e) {
		e.printStackTrace();
		return context;
	}
}
 
Example 3
Source File: SharedEditingDomainFactory.java    From statecharts with 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 4
Source File: BatchValidationHandler.java    From bonita-studio with 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 5
Source File: ModelHelper.java    From bonita-studio with 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 6
Source File: BonitaResourceSetInfoDelegate.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public final void stopResourceListening() {
    if (theSynchronizer != null) {
        final TransactionalEditingDomain synchonizerEditingDomain = theSynchronizer.getEditingDomain();
        if (synchonizerEditingDomain != null) {
            try {
                synchonizerEditingDomain.runExclusive(new Runnable() {

                    @Override
                    public void run() {
                        theSynchronizer.dispose();
                    }
                });
            } catch (final InterruptedException e) {
                BonitaStudioLog.error("Error while disposing the WorkspaceSynchronizer", e);
            }
        } else {
            theSynchronizer.dispose();
        }
    }
    theSynchronizer = null;
}
 
Example 7
Source File: ProcessValidationProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
public static void runWithConstraints(TransactionalEditingDomain editingDomain, Runnable operation) {
	if (!DISABLE_VALIDATION) {
		final Runnable op = operation;
		Runnable task = new Runnable() {
			public void run() {
				try {
					constraintsActive = true;
					op.run();
				} finally {
					constraintsActive = false;
				}
			}
		};
		if (editingDomain != null) {
			try {
				editingDomain.runExclusive(task);
			} catch (Exception e) {
				ProcessDiagramEditorPlugin.getInstance().logError("Validation failed", e); //$NON-NLS-1$
			}
		} else {
			task.run();
		}
	}
}