-
Notifications
You must be signed in to change notification settings - Fork 85
/
CapellaValidateComlineAction.java
86 lines (76 loc) · 2.69 KB
/
CapellaValidateComlineAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.validation.commandline;
import java.util.List;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.polarsys.capella.common.ef.ExecutionManager;
import org.polarsys.capella.common.helpers.TransactionHelper;
import org.polarsys.capella.common.helpers.cache.ModelCache;
import org.polarsys.capella.core.platform.sirius.ui.actions.CapellaValidateAction;
/**
*/
public class CapellaValidateComlineAction extends CapellaValidateAction {
private Resource resourceToValidate;
private Diagnostic diagnostic;
public void setSelectedObjects(List<EObject> selectedObjects) {
this.selectedObjects = selectedObjects;
}
/**
* {@inheritDoc}
*/
@Override
public void run() {
if(isSetEditingDomain()){
// works fine
try {
ModelCache.enable();
diagnostic = super.validate(new NullProgressMonitor());
} finally {
ModelCache.disable();
}
handleDiagnostic(diagnostic);
}
}
private boolean isSetEditingDomain(){
if(domain == null && !selectedObjects.isEmpty()){
ExecutionManager executionManager = TransactionHelper.getExecutionManager(selectedObjects);
domain = executionManager != null ? executionManager.getEditingDomain() : TransactionUtil.getEditingDomain(selectedObjects.get(0));
}
return domain != null;
}
/**
* {@inheritDoc}
*/
@Override
protected void handleDiagnostic(Diagnostic diagnostic) {
// Create markers
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
eclipseResourcesUtil.createMarkers(resourceToValidate, childDiagnostic);
}
}
/**
* @param airdSemanticModel
*/
public void setResource(Resource airdSemanticModel) {
resourceToValidate = airdSemanticModel;
}
public void deleteMarkers() {
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
eclipseResourcesUtil.deleteMarkers(childDiagnostic);
}
}
}