|
@@ -16,6 +16,12 @@ import org.eclipse.core.resources.IResource;
|
|
|
import org.eclipse.core.runtime.CoreException;
|
|
|
import org.eclipse.core.runtime.IStatus;
|
|
|
import org.eclipse.core.runtime.Status;
|
|
|
+import org.eclipse.emf.common.util.Diagnostic;
|
|
|
+import org.eclipse.emf.common.util.URI;
|
|
|
+import org.eclipse.emf.ecore.resource.Resource;
|
|
|
+import org.eclipse.emf.ecore.resource.ResourceSet;
|
|
|
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
|
|
+import org.eclipse.emf.ecore.util.Diagnostician;
|
|
|
import org.eclipse.jface.action.IAction;
|
|
|
import org.eclipse.jface.dialogs.ErrorDialog;
|
|
|
import org.eclipse.jface.viewers.ISelection;
|
|
@@ -26,6 +32,7 @@ import org.eclipse.ui.IWorkbenchPart;
|
|
|
import org.eclipse.ui.PlatformUI;
|
|
|
import org.yakindu.sct.generator.core.GeneratorActivator;
|
|
|
import org.yakindu.sct.generator.core.GeneratorExecutor;
|
|
|
+import org.yakindu.sct.generator.genmodel.ui.internal.SGenActivator;
|
|
|
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
@@ -41,9 +48,11 @@ public class GenerateModelAction implements IObjectActionDelegate {
|
|
|
@Inject
|
|
|
private GeneratorExecutor generatorExecutor;
|
|
|
|
|
|
+ private IWorkbenchPart workbenchPart;
|
|
|
+
|
|
|
public void run(IAction action) {
|
|
|
IFile file = unwrap();
|
|
|
-
|
|
|
+
|
|
|
if (hasError(file)) {
|
|
|
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
|
|
.getShell();
|
|
@@ -56,7 +65,6 @@ public class GenerateModelAction implements IObjectActionDelegate {
|
|
|
generatorExecutor.executeGenerator(file);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private boolean hasError(IFile file) {
|
|
|
IMarker[] findMarkers = null;
|
|
|
try {
|
|
@@ -70,12 +78,42 @@ public class GenerateModelAction implements IObjectActionDelegate {
|
|
|
}
|
|
|
}
|
|
|
} catch (CoreException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ SGenActivator
|
|
|
+ .getInstance()
|
|
|
+ .getLog()
|
|
|
+ .log(new Status(
|
|
|
+ IStatus.WARNING,
|
|
|
+ SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN,
|
|
|
+ "Error in determine, if file contains errors", e));
|
|
|
+ }
|
|
|
+
|
|
|
+ ResourceSet rs = new ResourceSetImpl();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Resource resource = rs.getResource(URI.createPlatformResourceURI(
|
|
|
+ file.getFullPath().toString(), true), true);
|
|
|
+ if (!resource.getErrors().isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (resource != null && !resource.getContents().isEmpty()) {
|
|
|
+ Diagnostic diagnostic = Diagnostician.INSTANCE
|
|
|
+ .validate(resource.getContents().get(0));
|
|
|
+ if (diagnostic.getSeverity() == Diagnostic.ERROR) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ SGenActivator
|
|
|
+ .getInstance()
|
|
|
+ .getLog()
|
|
|
+ .log(new Status(
|
|
|
+ IStatus.INFO,
|
|
|
+ SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN,
|
|
|
+ "Error in opening Resource", e));
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private IFile unwrap() {
|
|
|
if (selection instanceof StructuredSelection) {
|
|
|
Object firstElement = ((StructuredSelection) selection)
|
|
@@ -92,6 +130,7 @@ public class GenerateModelAction implements IObjectActionDelegate {
|
|
|
}
|
|
|
|
|
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
|
|
+ this.workbenchPart = targetPart;
|
|
|
}
|
|
|
|
|
|
}
|