Skip to main content
summaryrefslogtreecommitdiffstats
blob: db32b2242ac9aea0404ac6827d355b21dffa3b31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.osee.framework.logging.ILoggerListener;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.ui.swt.Displays;

/**
 * @author Andrew M. Finkbeiner
 */
public class DialogPopupLoggerListener implements ILoggerListener {

   @Override
   public void log(String loggerName, Level level, String message, Throwable th) {
      if (level == OseeLevel.SEVERE_POPUP) {
         final String title = "OSEE Error";
         final IStatus status;
         final String realMessageText;
         if (th != null) {
            List<IStatus> exc = new ArrayList<IStatus>();
            exceptionToString(true, loggerName, th, exc);
            status =
               new MultiStatus(loggerName, IStatus.ERROR, exc.toArray(new IStatus[exc.size()]), th.getMessage(), th);
            realMessageText = message;
         } else {
            status = new Status(IStatus.ERROR, loggerName, -20, message, th);
            realMessageText = null;
         }
         Displays.pendInDisplayThread(new Runnable() {
            @Override
            public void run() {
               ErrorDialog.openError(Displays.getActiveShell(), title, realMessageText, status);
            }
         });
      }
   }

   private static void exceptionToString(boolean firstTime, String loggerName, Throwable ex, List<IStatus> exc) {
      if (ex == null) {
         return;
      }
      if (!firstTime) {
         exc.add(new Status(IStatus.ERROR, loggerName, ex.getMessage()));
      }
      StackTraceElement st[] = ex.getStackTrace();
      for (int i = 0; i < st.length; i++) {
         StackTraceElement ste = st[i];
         exc.add(new Status(IStatus.ERROR, loggerName, ste.toString()));
      }
      Throwable cause = ex.getCause();
      if (cause != null) {
         exc.add(new Status(IStatus.ERROR, loggerName, "   caused by "));
         exceptionToString(false, loggerName, cause, exc);
      }
   }

}

Back to the top