Skip to main content
summaryrefslogtreecommitdiffstats
blob: 836fe01baae543f0e0fc05d4679d57eb083ca898 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************************************************
 * 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.ats.editor;

import java.util.logging.Level;
import org.eclipse.osee.ats.artifact.StateMachineArtifact;
import org.eclipse.osee.ats.artifact.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.event.FrameworkTransactionData;
import org.eclipse.osee.framework.skynet.core.event.IFrameworkTransactionEventListener;
import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
import org.eclipse.osee.framework.skynet.core.event.Sender;
import org.eclipse.osee.framework.ui.plugin.util.Displays;
import org.eclipse.osee.framework.ui.skynet.XFormToolkit;
import org.eclipse.osee.framework.ui.swt.ALayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.Hyperlink;

/**
 * <REM2> handled through SMAEditorEventManager
 * 
 * @author Donald G. Dunne
 */
public class SMAActionableItemHeader extends Composite implements IFrameworkTransactionEventListener {

   private static String ACTION_ACTIONABLE_ITEMS = "Actionable Items: ";
   private Hyperlink link;
   private Label label;
   private final StateMachineArtifact sma;

   public SMAActionableItemHeader(Composite parent, XFormToolkit toolkit, StateMachineArtifact sma) throws OseeCoreException {
      super(parent, SWT.NONE);
      this.sma = sma;
      try {
         final TeamWorkFlowArtifact teamWf = (TeamWorkFlowArtifact) sma;

         toolkit.adapt(this);
         setLayout(ALayout.getZeroMarginLayout(2, false));
         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
         gd.horizontalSpan = 4;
         setLayoutData(gd);

         link = toolkit.createHyperlink(this, ACTION_ACTIONABLE_ITEMS, SWT.NONE);
         link.setToolTipText("Edit Actionable Items for the parent Action (this may add Team Workflows)");
         link.addHyperlinkListener(new IHyperlinkListener() {

            public void linkEntered(HyperlinkEvent e) {
            }

            public void linkExited(HyperlinkEvent e) {
            }

            public void linkActivated(HyperlinkEvent e) {
               try {
                  AtsUtil.editActionableItems(teamWf.getParentActionArtifact());
               } catch (Exception ex) {
                  OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, ex);
               }
            }
         });

         label = toolkit.createLabel(this, " ");
         refresh();

         OseeEventManager.addListener(this);
      } catch (Exception ex) {
         OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
      }
   }

   private void refresh() throws OseeCoreException {
      if (label.isDisposed()) {
         OseeEventManager.removeListener(this);
         return;
      }
      final TeamWorkFlowArtifact teamWf = (TeamWorkFlowArtifact) sma;
      if (!sma.isCancelled() && !sma.isCompleted()) {
         if (teamWf.getParentActionArtifact().getActionableItems().isEmpty()) {
            label.setText(" " + "Error: No Actionable Items identified.");
            label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
         } else {
            StringBuffer sb = new StringBuffer(teamWf.getActionableItemsDam().getActionableItemsStr());
            if (teamWf.getParentActionArtifact().getTeamWorkFlowArtifacts().size() > 1) {
               sb.append("         Other: ");
               for (TeamWorkFlowArtifact workflow : teamWf.getParentActionArtifact().getTeamWorkFlowArtifacts()) {
                  if (!workflow.equals(teamWf)) {
                     sb.append(workflow.getActionableItemsDam().getActionableItemsStr() + ", ");
                  }
               }
            }
            label.setText(sb.toString().replaceFirst(", $", ""));
            label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
         }
         label.update();
         layout();
      } else {
         if (teamWf.getParentActionArtifact().getActionableItems().isEmpty()) {
            label.setText(" " + "Error: No Actionable Items identified.");
            label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
         } else {
            label.setText(" " + teamWf.getParentActionArtifact().getWorldViewActionableItems());
            label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
         }
         label.update();
         layout();
      }
   }

   @Override
   public void handleFrameworkTransactionEvent(Sender sender, FrameworkTransactionData transData) throws OseeCoreException {
      if (sma.isInTransition()) return;
      if (transData.branchId != AtsUtil.getAtsBranch().getId()) return;
      if (sma.isDeleted()) {
         OseeEventManager.removeListener(this);
         return;
      }
      // Since SMAEditor is refreshed when a sibling workflow is changed, need to refresh this
      // list of actionable items when a sibling changes
      for (TeamWorkFlowArtifact teamWf : sma.getParentActionArtifact().getTeamWorkFlowArtifacts()) {
         if (!sma.equals(teamWf) && (transData.isChanged(teamWf) || transData.isRelAdded(teamWf.getParentActionArtifact()) || transData.isRelDeleted(teamWf.getParentActionArtifact()))) {
            Displays.ensureInDisplayThread(new Runnable() {
               @Override
               public void run() {
                  try {
                     refresh();
                  } catch (OseeCoreException ex) {
                     OseeLog.log(AtsPlugin.class, OseeLevel.SEVERE_POPUP, ex);
                  }
               }
            });
            // Only need to refresh once
            return;
         }
      }
   }

   @Override
   public void dispose() {
      OseeEventManager.removeListener(this);
      super.dispose();
   }

}

Back to the top