-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.common;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Plugin;\r
-import org.eclipse.core.runtime.Status;\r
-import org.simantics.db.layer0.exception.InvalidVariableException;\r
-\r
-\r
-/**\r
- * ErrorLogger sends error messages to "Error log" view.\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class ErrorLogger {\r
-\r
- public static final boolean ECHO = true;\r
-\r
- private final Plugin plugin;\r
- private String pluginID;\r
-\r
- public ErrorLogger(Plugin plugin) {\r
- this.plugin = plugin;\r
- }\r
-\r
- private String getPluginID() {\r
- if (pluginID==null)\r
- pluginID = plugin.getBundle().getSymbolicName();\r
- return pluginID;\r
- }\r
-\r
- /**\r
- * Log a warning event.\r
- * \r
- * @param message message of the error\r
- * @param exception the exception, or <code>null</code>\r
- */\r
- public void logWarning(String message, Throwable exception) {\r
- log(IStatus.WARNING, IStatus.OK, message, exception);\r
- }\r
-\r
- /**\r
- * Log a message.\r
- * \r
- * @param message message of the error\r
- * @param exception the exception, or <code>null</code>\r
- */\r
- public void logMessage(String message, Throwable exception) {\r
- log(IStatus.INFO, IStatus.OK, message, exception);\r
- }\r
-\r
- /**\r
- * Log an error event.\r
- * \r
- * @param message message of the error\r
- * @param exception the exception, or <code>null</code>\r
- */\r
- public void logError(String message, Throwable exception) {\r
- // Errors are much more useful with a stack trace!\r
- if (exception == null) {\r
- exception = new RuntimeException();\r
- }\r
- log(IStatus.ERROR, IStatus.OK, message, exception);\r
- }\r
-\r
- public void log(int severity, int code, String message, Throwable exception) {\r
- IStatus status = new Status(severity, getPluginID(), code, message, exception);\r
- log(status);\r
- }\r
-\r
- public void log(IStatus status) {\r
- plugin.getLog().log(status);\r
- }\r
-\r
- public static ErrorLogger getDefault() {\r
- return Activator.getDefault().getErrorLogger();\r
- }\r
-\r
- public static void defaultLogError(String message, Throwable exception) {\r
- if (filterException(exception))\r
- return;\r
- getDefault().logError(message, exception);\r
- if(ECHO && exception != null) exception.printStackTrace();\r
- }\r
-\r
- public static void defaultLogError(Throwable exception) {\r
- if (filterException(exception))\r
- return;\r
- getDefault().logError(getUIFriendErrorMessage(exception), exception);\r
- if(ECHO && exception != null) exception.printStackTrace();\r
- }\r
-\r
- public static void defaultLogWarning(String message, Throwable exception) {\r
- if (filterException(exception))\r
- return;\r
- getDefault().logWarning(message, exception);\r
- if(ECHO && exception != null) exception.printStackTrace();\r
- }\r
-\r
- public static void defaultLogWarning(Throwable exception) {\r
- if (filterException(exception))\r
- return;\r
- getDefault().logWarning(getUIFriendErrorMessage(exception), exception);\r
- if(ECHO && exception != null) exception.printStackTrace();\r
- }\r
-\r
- public static void defaultLog(IStatus status) {\r
- getDefault().log(status);\r
- if(ECHO) System.out.println(status);\r
- }\r
-\r
- /**\r
- * This call makes verbose error message that is suitable for\r
- * UI Dialgos. The full cause hierarchy is shown with the tree.\r
- * In this case verbose includes class names.\r
- * \r
- * @param e exception\r
- * @return message\r
- */\r
- public static String getUIFriendErrorMessageVerbose(Throwable e) {\r
- String result = "";\r
- Throwable pe = null;\r
- while (e!=null && pe!=e) {\r
- result += e.getClass().getName()+": "+e.getMessage()+"\n";\r
- pe = e;\r
- e = e.getCause();\r
- }\r
- return result;\r
- }\r
-\r
- /**\r
- * This call makes error message that is suitable for\r
- * UI Dialogs. The full cause hierarchy is shown with the tree.\r
- * In this case verbose includes class names.\r
- * \r
- * @param e exception\r
- * @return message\r
- */\r
- public static String getUIFriendErrorMessage(Throwable e) {\r
- String result = "";\r
- Throwable pe = null;\r
- while (e!=null && pe!=e) {\r
- result += e.getMessage()+"\n";\r
- pe = e;\r
- e = e.getCause();\r
- }\r
- return result;\r
- }\r
-\r
- public static boolean filterException(Throwable t) {\r
- if (t instanceof InvalidVariableException)\r
- return true;\r
- return false;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.common;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.simantics.db.layer0.exception.InvalidVariableException;
+
+
+/**
+ * ErrorLogger sends error messages to "Error log" view.
+ *
+ * @author Toni Kalajainen
+ */
+public class ErrorLogger {
+
+ public static final boolean ECHO = true;
+
+ private final Plugin plugin;
+ private String pluginID;
+
+ public ErrorLogger(Plugin plugin) {
+ this.plugin = plugin;
+ }
+
+ private String getPluginID() {
+ if (pluginID==null)
+ pluginID = plugin.getBundle().getSymbolicName();
+ return pluginID;
+ }
+
+ /**
+ * Log a warning event.
+ *
+ * @param message message of the error
+ * @param exception the exception, or <code>null</code>
+ */
+ public void logWarning(String message, Throwable exception) {
+ log(IStatus.WARNING, IStatus.OK, message, exception);
+ }
+
+ /**
+ * Log a message.
+ *
+ * @param message message of the error
+ * @param exception the exception, or <code>null</code>
+ */
+ public void logMessage(String message, Throwable exception) {
+ log(IStatus.INFO, IStatus.OK, message, exception);
+ }
+
+ /**
+ * Log an error event.
+ *
+ * @param message message of the error
+ * @param exception the exception, or <code>null</code>
+ */
+ public void logError(String message, Throwable exception) {
+ // Errors are much more useful with a stack trace!
+ if (exception == null) {
+ exception = new RuntimeException();
+ }
+ log(IStatus.ERROR, IStatus.OK, message, exception);
+ }
+
+ public void log(int severity, int code, String message, Throwable exception) {
+ IStatus status = new Status(severity, getPluginID(), code, message, exception);
+ log(status);
+ }
+
+ public void log(IStatus status) {
+ plugin.getLog().log(status);
+ }
+
+ public static ErrorLogger getDefault() {
+ return Activator.getDefault().getErrorLogger();
+ }
+
+ public static void defaultLogError(String message, Throwable exception) {
+ if (filterException(exception))
+ return;
+ getDefault().logError(message, exception);
+ if(ECHO && exception != null) exception.printStackTrace();
+ }
+
+ public static void defaultLogError(Throwable exception) {
+ if (filterException(exception))
+ return;
+ getDefault().logError(getUIFriendErrorMessage(exception), exception);
+ if(ECHO && exception != null) exception.printStackTrace();
+ }
+
+ public static void defaultLogWarning(String message, Throwable exception) {
+ if (filterException(exception))
+ return;
+ getDefault().logWarning(message, exception);
+ if(ECHO && exception != null) exception.printStackTrace();
+ }
+
+ public static void defaultLogWarning(Throwable exception) {
+ if (filterException(exception))
+ return;
+ getDefault().logWarning(getUIFriendErrorMessage(exception), exception);
+ if(ECHO && exception != null) exception.printStackTrace();
+ }
+
+ public static void defaultLog(IStatus status) {
+ getDefault().log(status);
+ if(ECHO) System.out.println(status);
+ }
+
+ /**
+ * This call makes verbose error message that is suitable for
+ * UI Dialgos. The full cause hierarchy is shown with the tree.
+ * In this case verbose includes class names.
+ *
+ * @param e exception
+ * @return message
+ */
+ public static String getUIFriendErrorMessageVerbose(Throwable e) {
+ String result = "";
+ Throwable pe = null;
+ while (e!=null && pe!=e) {
+ result += e.getClass().getName()+": "+e.getMessage()+"\n";
+ pe = e;
+ e = e.getCause();
+ }
+ return result;
+ }
+
+ /**
+ * This call makes error message that is suitable for
+ * UI Dialogs. The full cause hierarchy is shown with the tree.
+ * In this case verbose includes class names.
+ *
+ * @param e exception
+ * @return message
+ */
+ public static String getUIFriendErrorMessage(Throwable e) {
+ String result = "";
+ Throwable pe = null;
+ while (e!=null && pe!=e) {
+ result += e.getMessage()+"\n";
+ pe = e;
+ e = e.getCause();
+ }
+ return result;
+ }
+
+ public static boolean filterException(Throwable t) {
+ if (t instanceof InvalidVariableException)
+ return true;
+ return false;
+ }
+
+}