Skip to main content
summaryrefslogtreecommitdiffstats
blob: 00e754a125fc83c45e560e1efc4dea0b92cff99a (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
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * 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 org.eclipse.osee.framework.logging.IHealthStatus;
import org.eclipse.osee.framework.logging.IStatusListener;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.plugin.OseeStatusContributionItem;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.framework.ui.swt.OverlayImage;
import org.eclipse.swt.graphics.Image;

/**
 * @author Roberto E. Escobar
 */
public class OseeServicesStatusContributionItem extends OseeStatusContributionItem implements IStatusListener {
   private static final String ID = "osee.service.status";
   private static final Image DISABLED_IMAGE = new OverlayImage(
      ImageManager.getImage(FrameworkImage.APPLICATION_SERVER),
      ImageManager.getImageDescriptor(FrameworkImage.SLASH_RED_OVERLAY)).createImage();

   private static String errorMessage;
   private static String okMessage;

   public OseeServicesStatusContributionItem() {
      super(ID);
      errorMessage = null;
      okMessage = null;
      updateStatus(true);
      OseeLog.register(this);
   }

   @Override
   public void dispose() {
      OseeLog.deregister(this);
      super.dispose();
   }

   @Override
   protected Image getDisabledImage() {
      return DISABLED_IMAGE;
   }

   @Override
   protected String getDisabledToolTip() {
      return errorMessage;
   }

   @Override
   protected Image getEnabledImage() {
      return ImageManager.getImage(FrameworkImage.APPLICATION_SERVER);
   }

   @Override
   protected String getEnabledToolTip() {
      return okMessage;
   }

   @Override
   public void onStatus(final IHealthStatus status) {
      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            if (status.isOk()) {
               okMessage = status.getMessage();
            } else {
               Throwable error = status.getException();
               errorMessage = error != null ? error.getLocalizedMessage() : "Undefined Error";
            }
            updateStatus(status.isOk());
         }
      });

   }
}

Back to the top