|
@@ -15,14 +15,23 @@ import java.util.List;
|
|
|
import org.eclipse.core.resources.IFile;
|
|
|
import org.eclipse.core.resources.IResource;
|
|
|
import org.eclipse.core.runtime.CoreException;
|
|
|
+import org.eclipse.core.runtime.IProgressMonitor;
|
|
|
+import org.eclipse.core.runtime.IStatus;
|
|
|
+import org.eclipse.core.runtime.Status;
|
|
|
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
|
|
+import org.eclipse.core.runtime.jobs.Job;
|
|
|
import org.eclipse.emf.common.util.BasicDiagnostic;
|
|
|
import org.eclipse.emf.common.util.Diagnostic;
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.emf.ecore.util.Diagnostician;
|
|
|
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
|
|
|
import org.eclipse.gmf.runtime.notation.Diagram;
|
|
|
+import org.eclipse.ui.IEditorPart;
|
|
|
+import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
|
|
|
+import org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor;
|
|
|
|
|
|
import de.itemis.xtext.utils.gmf.resource.InjectMembersResource;
|
|
|
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorTracker;
|
|
|
|
|
|
/**
|
|
|
* Executes the Validation and creates Problem Markers on the resource.
|
|
@@ -32,7 +41,49 @@ import de.itemis.xtext.utils.gmf.resource.InjectMembersResource;
|
|
|
*/
|
|
|
public class ValidationAction implements IMarkerType {
|
|
|
|
|
|
- public static void validate(DiagramEditPart diagramEditPart, Diagram view) {
|
|
|
+ private static ISchedulingRule IDENTITY_RULE = new ISchedulingRule() {
|
|
|
+ public boolean contains(ISchedulingRule rule) {
|
|
|
+ return rule == this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isConflicting(ISchedulingRule rule) {
|
|
|
+ return rule == this;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Perform the validation as a job to avoid blocking the UI Thread.
|
|
|
+ */
|
|
|
+ public static void validate(DiagramEditPart diagramEditPart,
|
|
|
+ final Diagram view) {
|
|
|
+
|
|
|
+ final IEditorPart editor = ActiveEditorTracker
|
|
|
+ .getLastEditor(StatechartDiagramEditor.ID);
|
|
|
+ if (editor == null) {
|
|
|
+ // should actually never happen..
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) editor
|
|
|
+ .getSite().getService(IWorkbenchSiteProgressService.class);
|
|
|
+ Job job = new Job("Diagram validation") {
|
|
|
+ @Override
|
|
|
+ protected IStatus run(IProgressMonitor monitor) {
|
|
|
+ monitor.beginTask("Validating diagram...", 4);
|
|
|
+ monitor.worked(1);
|
|
|
+ try {
|
|
|
+ doValidate(view);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ monitor.done();
|
|
|
+ return Status.OK_STATUS;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ job.setRule(IDENTITY_RULE);
|
|
|
+ service.schedule(job);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void doValidate(Diagram view) {
|
|
|
IFile target = GMFMarkerUtil.getTargetFile(view);
|
|
|
if (target != null) {
|
|
|
try {
|
|
@@ -44,7 +95,7 @@ public class ValidationAction implements IMarkerType {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// // Ecore constraints
|
|
|
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(view
|
|
|
.getElement());
|