From 04b2766eb4dc58dab9754cf40044cbcd12de6b89 Mon Sep 17 00:00:00 2001 From: Jens Bendisposto <jens@bendisposto.de> Date: Tue, 3 Jul 2012 16:53:46 +0200 Subject: [PATCH] distinguish between warnings and errors. --- de.prob.core/src/de/prob/logging/Logger.java | 10 +++++++-- .../prob/ui/eventb/StartAnimationHandler.java | 22 +++++++++++++------ .../de/prob/ui/ticket/ProBLogListener.java | 9 ++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/de.prob.core/src/de/prob/logging/Logger.java b/de.prob.core/src/de/prob/logging/Logger.java index 8780aa30..678c5ddc 100644 --- a/de.prob.core/src/de/prob/logging/Logger.java +++ b/de.prob.core/src/de/prob/logging/Logger.java @@ -78,7 +78,8 @@ public final class Logger { /** * Check a property. The method notifies the user and throws an exception if * the assertion fails. <br> - * <b>Examples:</b><br>{@code Logger.assertProB(this.getClass(),"x != null", x + * <b>Examples:</b><br> + * {@code Logger.assertProB(this.getClass(),"x != null", x * != null); } <br> * {@code Logger.assertProB(this.getClass(),"x should not be null", x != null); } * <br> @@ -112,7 +113,8 @@ public final class Logger { /** * Failed assertion. The method notifies the user and throws an exception. <br> - * <b>Examples:</b><br>{@code if (!file.exists()) String message = + * <b>Examples:</b><br> + * {@code if (!file.exists()) String message = * "Called open on nonexisting file " + file; * Logger.assertProB(EditorPlugin.class, message); } * @@ -149,4 +151,8 @@ public final class Logger { private static void log(final IStatus status) { Activator.getDefault().getLog().log(status); } + + public static void notifyUserAboutWarningWithoutBugreport(String string) { + log(IStatus.WARNING, NOBUGREPORT, string, null); + } } diff --git a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java index 0a33dd17..bad71c48 100644 --- a/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java +++ b/de.prob.ui/src/de/prob/ui/eventb/StartAnimationHandler.java @@ -70,15 +70,22 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { final IEventBRoot rootElement = getRootElement(); final IFile resource = extractResource(rootElement); - List<String> errors = checkErrorMarkers(resource); + ArrayList<String> errors = new ArrayList<String>(); + boolean realError = checkErrorMarkers(resource, errors); if (!errors.isEmpty()) { - String message = "A model/context in your project contains Errors or Warnings. This can lead to unexpected behavior (e.g. missing variables) when animating.\ns\nDetails:\n"; + String message = "Some components in your project contain " + + (realError ? "errors" : "warnings") + + ". This can lead to unexpected behavior (e.g. missing variables) when animating.\n\nDetails:\n"; StringBuffer stringBuffer = new StringBuffer(message); for (String string : errors) { stringBuffer.append(string); stringBuffer.append('\n'); } - Logger.notifyUserWithoutBugreport(stringBuffer.toString()); + if (realError) + Logger.notifyUserWithoutBugreport(stringBuffer.toString()); + else + Logger.notifyUserAboutWarningWithoutBugreport(stringBuffer + .toString()); } ; @@ -99,8 +106,8 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { return null; } - private List<String> checkErrorMarkers(final IFile resource) { - List<String> errors = new ArrayList<String>(); + private boolean checkErrorMarkers(final IFile resource, List<String> errors) { + boolean result = false; IProject project = resource.getProject(); try { IMarker[] markers = project.findMarkers( @@ -111,12 +118,13 @@ public class StartAnimationHandler extends AbstractHandler implements IHandler { + ": " + iMarker .getAttribute(IMarker.MESSAGE, "unknown Error")); + result = result + || (Integer) iMarker.getAttribute(IMarker.SEVERITY) == IMarker.SEVERITY_ERROR; } } catch (CoreException e1) { } - - return errors; + return result; } private IEventBRoot getRootElement() { diff --git a/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java b/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java index 41ba4f1f..c877085a 100644 --- a/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java +++ b/de.prob.ui/src/de/prob/ui/ticket/ProBLogListener.java @@ -27,15 +27,16 @@ public final class ProBLogListener implements ILogListener { final int code = status.getCode(); if (code == Logger.BUGREPORT || code == Logger.NOBUGREPORT) { - final boolean bugreport = false; //;code == Logger.BUGREPORT; + final boolean bugreport = false; // ;code == Logger.BUGREPORT; display.asyncExec(new Runnable() { public void run() { + String title = (status.getSeverity() == IStatus.ERROR) ? "An Error occured" + : "Warning"; // Notice: ErrorTICKETDialog to provide Bugreport-Button ErrorTicketDialog.openError(display.getActiveShell(), - "Error", "An error occured.", status, bugreport); + "ProB Problem", title, status, bugreport); } - } - ); + }); } display.asyncExec(new Runnable() { -- GitLab