summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Groeger <groeger@itestra.de>2013-09-05 10:03:51 +0200
committerFlorian Groeger <groeger@itestra.de>2013-09-11 13:38:35 +0200
commit92e55306dc23cffefc3becf74cd2343835a7bd9a (patch)
tree4bd65a30b068515cff1ac99b2a1e415664394a3c
parentdaec531a1522adebc839d981fb12d45de3c46809 (diff)
downloadgenivi-common-api-runtime-92e55306dc23cffefc3becf74cd2343835a7bd9a.tar.gz
Pop-up if generating fails or would fail
If generating throws an exception or error, a pop-up occurs. If there is an error-marker in the .fidl, no generating process will be initiated and a pop-up occurs. Change-Id: I8a793dd74f2c75a4b181d30d4aec6507fedf3f8c
-rw-r--r--org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java193
1 files changed, 149 insertions, 44 deletions
diff --git a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java
index 2322706..ae7eb7a 100644
--- a/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java
+++ b/org.genivi.commonapi.core.ui/src/org/genivi/commonapi/core/ui/handler/GenerationCommand.java
@@ -9,7 +9,6 @@
package org.genivi.commonapi.core.ui.handler;
import java.util.Iterator;
-import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
@@ -17,8 +16,10 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
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.NullProgressMonitor;
@@ -27,9 +28,11 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;
@@ -70,41 +73,68 @@ public class GenerationCommand extends AbstractHandler {
if (activeEditor instanceof XtextEditor)
executeGeneratorForXtextEditor((XtextEditor) activeEditor);
else
- throw new ExecutionException("Cannot handle ExecutionEvent: " + event);
+ throw new ExecutionException("Cannot handle ExecutionEvent: "
+ + event);
}
return null;
}
- private void executeGeneratorForSelection(final IStructuredSelection structuredSelection) {
+ private void executeGeneratorForSelection(
+ final IStructuredSelection structuredSelection) {
IProject project = null;
- for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
+ for (Iterator<?> iterator = structuredSelection.iterator(); iterator
+ .hasNext();) {
final Object selectiobObject = iterator.next();
if (selectiobObject instanceof IFile) {
final IFile file = (IFile) selectiobObject;
- final URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
- final ResourceSet rs = resourceSetProvider.get(file.getProject());
+ final URI uri = URI.createPlatformResourceURI(file
+ .getFullPath().toString(), true);
+ final ResourceSet rs = resourceSetProvider.get(file
+ .getProject());
final Resource r = rs.getResource(uri, true);
project = file.getProject();
FieldEditorOverlayPage page = new CommonAPIPreferencePage();
page.setElement(project);
page.createControl(null);
- FPreferences.init(page.getPreferenceStore(), CommonApiUiPlugin.getDefault().getPreferenceStore(),
- project);
+ FPreferences.init(page.getPreferenceStore(), CommonApiUiPlugin
+ .getDefault().getPreferenceStore(), project);
final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(project);
fileSystemAccess.setProject(project);
Job job = new Job("validation and generation") {
@Override
protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask("handle " + file.getName(), IProgressMonitor.UNKNOWN);
+ monitor.beginTask("handle " + file.getName(),
+ IProgressMonitor.UNKNOWN);
monitor.subTask("validation");
- if (r.getErrors().size() == 0) {
+ int i = 0;
+ try {
+ for (IMarker m : ((IResource) file).findMarkers(
+ IMarker.PROBLEM, true, 2)) {
+ if ((Integer) m.getAttribute(IMarker.SEVERITY) == IMarker.SEVERITY_ERROR) {
+ i++;
+ break;
+ }
+ }
+
+ } catch (CoreException ce) {
+ }
+ if (r.getErrors().size() == 0 && i == 0) {
monitor.subTask("Generate");
- francaGenerator.doGenerate(r, fileSystemAccess);
+ try {
+ francaGenerator.doGenerate(r, fileSystemAccess);
+ } catch (Exception e) {
+ exceptionPopUp(e, file);
+ return Status.CANCEL_STATUS;
+ } catch (Error e) {
+ errorPopUp(e, file);
+ return Status.CANCEL_STATUS;
+ }
return Status.OK_STATUS;
} else {
+ markerPopUp(file);
return Status.CANCEL_STATUS;
}
@@ -117,57 +147,132 @@ public class GenerationCommand extends AbstractHandler {
}
private void executeGeneratorForXtextEditor(final XtextEditor xtextEditor) {
- final Object fileObject = xtextEditor.getEditorInput().getAdapter(IFile.class);
+ final Object fileObject = xtextEditor.getEditorInput().getAdapter(
+ IFile.class);
if (fileObject instanceof IFile) {
IProject project = ((IResource) fileObject).getProject();
final EclipseResourceFileSystemAccess2 fileSystemAccess = createFileSystemAccess(project);
fileSystemAccess.setProject(project);
- xtextEditor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {
- @Override
- public Boolean exec(XtextResource xtextResource) throws Exception {
- final XtextResource xtextRes = xtextResource;
- Job job = new Job("validation and generation") {
-
+ xtextEditor.getDocument().readOnly(
+ new IUnitOfWork<Boolean, XtextResource>() {
@Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
+ public Boolean exec(XtextResource xtextResource)
+ throws Exception {
+ final XtextResource xtextRes = xtextResource;
+ Job job = new Job("validation and generation") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask("handle " + ((IResource) fileObject).getName(),
- IProgressMonitor.UNKNOWN);
- TimeUnit.SECONDS.sleep(1);
- monitor.subTask("validation");
- if (xtextRes.getErrors().size() == 0) {
- monitor.subTask("Generate");
- francaGenerator.doGenerate(xtextRes, fileSystemAccess);
- return Status.OK_STATUS;
- } else {
- return Status.CANCEL_STATUS;
+ monitor.beginTask(
+ "handle "
+ + ((IResource) fileObject)
+ .getName(),
+ IProgressMonitor.UNKNOWN);
+ monitor.subTask("validation");
+ int i = 0;
+ try {
+ for (IMarker m : ((IResource) fileObject)
+ .findMarkers(IMarker.PROBLEM,
+ true, 2)) {
+ if ((Integer) m
+ .getAttribute(IMarker.SEVERITY) == IMarker.SEVERITY_ERROR) {
+ i++;
+ break;
+ }
+ }
+ } catch (CoreException ce) {
+ }
+ if (xtextRes.getErrors().size() == 0
+ && i == 0) {
+ monitor.subTask("Generate");
+ try {
+ francaGenerator.doGenerate(
+ xtextRes, fileSystemAccess);
+ } catch (Exception e) {
+ exceptionPopUp(e,
+ (IFile) fileObject);
+ return Status.CANCEL_STATUS;
+ } catch (Error e) {
+ errorPopUp(e, (IFile) fileObject);
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ } else {
+ markerPopUp((IFile) fileObject);
+ return Status.CANCEL_STATUS;
+ }
}
- } catch (InterruptedException ie) {
- return Status.CANCEL_STATUS;
- }
- }
- };
- job.schedule();
- return Boolean.TRUE;
- }
- });
+ };
+ job.schedule();
+ return Boolean.TRUE;
+ }
+ });
}
}
- private EclipseResourceFileSystemAccess2 createFileSystemAccess(IProject project) {
- IPreferenceStore store = CommonApiUiPlugin.getDefault().getPreferenceStore();
+ private void exceptionPopUp(Exception e, IFile f) {
+ final Exception ex = e;
+ final IFile file = f;
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ ex.printStackTrace();
+ MessageDialog.openError(
+ null,
+ "Error by generating file " + file.getName(),
+ "Couldn't generate file. Exception occured:\n"
+ + ex.toString()
+ + "\n\nSee console for stack trace.");
+ }
+ });
+ }
+
+ private void markerPopUp(IFile f) {
+ final IFile file = f;
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openError(
+ null,
+ "Error in file " + file.getName(),
+ "Couldn't generate file. File still holds errors!\n\nSee Problems view for details.");
+ }
+ });
+ }
+
+ private void errorPopUp(Error e, IFile f) {
+ final Error er = e;
+ final IFile file = f;
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ er.printStackTrace();
+ MessageDialog.openError(
+ null,
+ "Error by generating file " + file.getName(),
+ "Couldn't generate file. Error occured:\n"
+ + er.toString()
+ + "\n\nSee console for stack trace.");
+ }
+ });
+ }
+
+ private EclipseResourceFileSystemAccess2 createFileSystemAccess(
+ IProject project) {
+ IPreferenceStore store = CommonApiUiPlugin.getDefault()
+ .getPreferenceStore();
String outputDir = store.getString(PreferenceConstants.P_OUTPUT);
- if (FPreferences.getInstance().getPreference(PreferenceConstants.P_OUTPUT, null,
+ if (FPreferences.getInstance().getPreference(
+ PreferenceConstants.P_OUTPUT, null,
project.getFullPath().toPortableString()) != null)
- outputDir = FPreferences.getInstance().getPreference(PreferenceConstants.P_OUTPUT, null,
+ outputDir = FPreferences.getInstance().getPreference(
+ PreferenceConstants.P_OUTPUT, null,
project.getFullPath().toPortableString());
final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
fsa.setOutputPath(outputDir);
- fsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT).setCreateOutputDirectory(true);
+ fsa.getOutputConfigurations().get(IFileSystemAccess.DEFAULT_OUTPUT)
+ .setCreateOutputDirectory(true);
fsa.setMonitor(new NullProgressMonitor());
return fsa;