Skip to main content
summaryrefslogtreecommitdiffstats
blob: 82183529805065f17cca391d49db5f07a634b400 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
 * 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.jface.action.IStatusLineManager;
import org.eclipse.osee.framework.skynet.core.event.RemoteEventManager2;
import org.eclipse.osee.framework.ui.skynet.ats.IOseeAtsService;
import org.eclipse.osee.framework.ui.skynet.ats.OseeAts;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.StatusLineContributionItem;

/**
 * @author Jeff C. Phillips
 */
public abstract class OseeContributionItem extends StatusLineContributionItem {

   protected OseeContributionItem(String id) {
      this(id, 4);
   }

   protected OseeContributionItem(String id, int width) {
      super(id, true, width);
   }

   protected abstract String getEnabledToolTip();

   protected abstract String getDisabledToolTip();

   protected abstract Image getEnabledImage();

   protected abstract Image getDisabledImage();

   protected void updateStatus(final boolean isActive) {
      Displays.ensureInDisplayThread(new Runnable() {
         @Override
         public void run() {
            Image image = isActive ? getEnabledImage() : getDisabledImage();
            String toolTip = isActive ? getEnabledToolTip() : getDisabledToolTip();

            if (image != null) {
               setImage(image);
            }
            if (toolTip != null) {
               setToolTipText(toolTip);
            }
         }
      });
   }

   public static void addTo(IStatusLineManager manager) {
      OseeBuildTypeContributionItem.addTo(manager);
      ResServiceContributionItem.addTo(manager);
      IOseeAtsService atsService = OseeAts.getInstance();
      if (atsService != null && atsService.isAtsAdmin()) {
         AdminContributionItem.addTo(manager);
      }
      if (!RemoteEventManager2.isConnected()) {
         SkynetServiceContributionItem.addTo(manager);
      }
      OseeServicesStatusContributionItem.addTo(manager);
      SessionContributionItem.addTo(manager);
   }

   public static void addTo(IPageSite pageSite, boolean update) {
      addTo(pageSite.getActionBars().getStatusLineManager());

      if (update) {
         pageSite.getActionBars().updateActionBars();
      }
   }

   public static void addTo(ViewPart view, boolean update) {
      addTo(view.getViewSite().getActionBars().getStatusLineManager());

      if (update) {
         view.getViewSite().getActionBars().updateActionBars();
      }
   }

   public static void addTo(MultiPageEditorPart editorPart, boolean update) {
      addTo(editorPart.getEditorSite().getActionBars().getStatusLineManager());
      if (update) {
         editorPart.getEditorSite().getActionBars().updateActionBars();
      }
   }

}

Back to the top