/*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2019 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - Reorganization
*******************************************************************************/
package org.simantics.issues.ui.handler;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- Runnable postValidation = null;
- run(postValidation);
+ try {
+ run();
+ } catch (DatabaseException e) {
+ throw new ExecutionException("Error while running active validations", e);
+ }
return null;
}
- public void run(Runnable postValidation) {
+ public static void run() throws DatabaseException {
+ Resource model = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+ if(model != null)
+ run(model);
+ }
+
+ public static void run(Resource model) {
+ run(model, null);
+ }
+
+ public static void run(Resource model, Runnable postValidation) {
final Session session = Simantics.getSession();
final BatchIssueValidationContext context = new BatchIssueValidationContext();
try {
- SleepingDatabaseJob dbLock = new SleepingDatabaseJob("Validation Preparation").scheduleAndWaitForRunning();
+ SleepingDatabaseJob dbLock = new SleepingDatabaseJob(Messages.RunActiveValidations_ValidationPreparation).scheduleAndWaitForRunning();
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
- Resource model = session.sync(new PossibleActiveModel(Simantics.getProjectResource()));
- if(model == null) return;
toBatchIssueSources(session,
session.syncRequest(new SelectedModelBatchIssueSources(model)),
validations);
- SubMonitor.convert(monitor, "Preparing resources for validation", 100);
+ SubMonitor.convert(monitor, Messages.RunActiveValidations_MonitorPreparingResourcesForValidation, 100);
context.contexts = Collections.singletonList(model);
context.domain = ModelTransferableGraphSourceRequest.getDomainOnly(session, monitor, model);
public static void run(Runnable postValidation, final Collection<BatchIssueSource> validations, final BatchIssueValidationContext context) {
// Run the validations for the selected composites
- SleepingDatabaseJob dbLock = new SleepingDatabaseJob("Validation");
+ SleepingDatabaseJob dbLock = new SleepingDatabaseJob(Messages.RunActiveValidations_Validation);
try {
dbLock.scheduleAndWaitForRunning();
try {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
- SubMonitor progress = SubMonitor.convert(monitor, "Validate Model", 100);
+ SubMonitor progress = SubMonitor.convert(monitor, Messages.RunActiveValidations_ValidateModel, 100);
int maxWrittenIssues = IssuePreferenceUtil.getPreferences().maxBatchIssuesToWrite;
int writtenIssues = 0;
for (BatchIssueSource source : validations) {
Resource list = graph.getSingleObject(issue, ISSUE.Issue_HasContexts);
List<Resource> l = ListUtils.toList(graph, list);
if (l.size() > 0) {
- Resource mainContext = l.get(0);
- if (!graph.hasStatement(mainContext))
+ Resource mainContext = l.get(0);
+ if (!BatchValidations.isLinkedToOtherThan(graph, mainContext, issue))
result.add(mainContext);
}
}
}
} catch (OperationCanceledException e) {
- throw e;
+ throw e;
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {