Skip to main content
summaryrefslogtreecommitdiffstats
blob: 99eff17b05d491d48722c4a9c0a0d82d9d6f032b (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*******************************************************************************
 * 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.Collection;
import java.util.logging.Level;
import org.eclipse.osee.ats.AtsOpenOption;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.data.AtsRelationTypes;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.core.client.review.AbstractReviewArtifact;
import org.eclipse.osee.ats.core.client.util.AtsUtilClient;
import org.eclipse.osee.ats.core.client.workflow.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.core.config.ActionableItems;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.ats.util.widgets.dialog.AICheckTreeDialog;
import org.eclipse.osee.framework.core.data.RelationTypeSide;
import org.eclipse.osee.framework.core.enums.Active;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.PresentationType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
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.Label;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.Hyperlink;

/**
 * @author Donald G. Dunne
 */
public class WfeRelationsHyperlinkComposite extends Composite {

   private static RelationTypeSide[] sides = new RelationTypeSide[] {
      AtsRelationTypes.TeamWorkflowToReview_Review,
      AtsRelationTypes.TeamWorkflowToReview_Team,
      CoreRelationTypes.Supercedes_Superceded,
      CoreRelationTypes.Supercedes_Supercedes,
      CoreRelationTypes.SupportingInfo_SupportedBy,
      CoreRelationTypes.SupportingInfo_SupportingInfo,
      CoreRelationTypes.Dependency__Artifact,
      CoreRelationTypes.Dependency__Dependency};
   private AbstractWorkflowArtifact awa;
   private Label actionableItemsLabel;
   private final WorkflowEditor editor;

   public WfeRelationsHyperlinkComposite(Composite parent, int style, WorkflowEditor editor) {
      super(parent, style);
      this.editor = editor;
   }

   public void create(AbstractWorkflowArtifact sma) throws OseeCoreException {
      this.awa = sma;
      setLayout(ALayout.getZeroMarginLayout(2, false));
      GridData gd = new GridData(GridData.FILL_HORIZONTAL);
      gd.widthHint = 500;
      setLayoutData(gd);
      editor.getToolkit().adapt(this);

      // Create all hyperlinks from this artifact to others of interest
      createArtifactRelationHyperlinks("This", sma, "is reviewed by", AtsRelationTypes.TeamWorkflowToReview_Review);
      createArtifactRelationHyperlinks("This", sma, "reviews", AtsRelationTypes.TeamWorkflowToReview_Team);
      createArtifactRelationHyperlinks("This", sma, "is superceded by", CoreRelationTypes.Supercedes_Superceded);
      createArtifactRelationHyperlinks("This", sma, "supercedes", CoreRelationTypes.Supercedes_Supercedes);
      createArtifactRelationHyperlinks("This", sma, "depends on", CoreRelationTypes.Dependency__Dependency);
      createArtifactRelationHyperlinks("This", sma, "is dependency of", CoreRelationTypes.Dependency__Artifact);
      createArtifactRelationHyperlinks("This", sma, "is supported info for",
         CoreRelationTypes.SupportingInfo_SupportedBy);
      createArtifactRelationHyperlinks("This", sma, "has supporting info",
         CoreRelationTypes.SupportingInfo_SupportingInfo);

      // Create label for review's related actionable items (if any)
      if (sma instanceof AbstractReviewArtifact) {
         processReviewArtifact((AbstractReviewArtifact) sma);
      }

   }

   public static boolean relationExists(AbstractWorkflowArtifact smaArt) throws OseeCoreException {
      for (RelationTypeSide side : sides) {
         if (smaArt.getRelatedArtifacts(side).size() > 0) {
            return true;
         }
      }
      if (smaArt instanceof AbstractReviewArtifact && AtsClientService.get().getWorkItemService().getActionableItemService().hasActionableItems(
         smaArt)) {
         return true;
      }
      return false;
   }

   private String getCompletedCancelledString(Artifact art) throws OseeCoreException {
      if (art instanceof AbstractWorkflowArtifact && ((AbstractWorkflowArtifact) art).isCompletedOrCancelled()) {
         return " " + ((AbstractWorkflowArtifact) art).getStateMgr().getCurrentStateName() + " ";
      }
      return "";
   }

   private void createArtifactRelationHyperlinks(String prefix, Artifact thisArt, String action, RelationTypeSide relationEnum) throws OseeCoreException {
      for (final Artifact art : thisArt.getRelatedArtifacts(relationEnum)) {
         createLink(art, prefix, action, thisArt);
      }
   }

   private void createLink(final Artifact art, String prefix, String action, Artifact thisArt) {
      try {
         editor.getToolkit().createLabel(this,
            prefix + " \"" + thisArt.getArtifactTypeName() + "\" " + action + getCompletedCancelledString(
               art) + " \"" + art.getArtifactTypeName() + "\" ");
         Hyperlink link =
            editor.getToolkit().createHyperlink(this,
               String.format("\"%s\" - %s",
                  art.getName().length() < 60 ? art.getName() : art.getName().substring(0, 60),
                  AtsUtilClient.getAtsId(art)),
               SWT.NONE);
         link.addHyperlinkListener(new IHyperlinkListener() {

            @Override
            public void linkEntered(HyperlinkEvent e) {
               // do nothing
            }

            @Override
            public void linkExited(HyperlinkEvent e) {
               // do nothing
            }

            @Override
            public void linkActivated(HyperlinkEvent e) {
               if (AtsUtil.isAtsArtifact(art)) {
                  AtsUtil.openATSAction(art, AtsOpenOption.OpenOneOrPopupSelect);
               } else {
                  try {
                     RendererManager.open(art, PresentationType.DEFAULT_OPEN);
                  } catch (OseeCoreException ex) {
                     OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
                  }
               }
            }
         });
      } catch (OseeCoreException ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
   }

   private void processReviewArtifact(final AbstractReviewArtifact reviewArt) throws OseeCoreException {
      if (!AtsClientService.get().getWorkItemService().getActionableItemService().hasActionableItems(reviewArt)) {
         return;
      }
      actionableItemsLabel = editor.getToolkit().createLabel(this, "");
      Hyperlink link = editor.getToolkit().createHyperlink(this, "(Edit)", SWT.NONE);
      link.addHyperlinkListener(new IHyperlinkListener() {

         @Override
         public void linkEntered(HyperlinkEvent e) {
            // do nothing
         }

         @Override
         public void linkExited(HyperlinkEvent e) {
            // do nothing
         }

         @Override
         public void linkActivated(HyperlinkEvent e) {
            editRelatedActionableItems(reviewArt);
         }
      });
      refreshActionableItemsLabel();
   }

   private void refreshActionableItemsLabel() throws OseeCoreException {
      if (actionableItemsLabel != null && awa instanceof AbstractReviewArtifact) {
         actionableItemsLabel.setText("This \"" + ((AbstractReviewArtifact) awa).getArtifactTypeName() +
         //
            "\" is review of Actionable Items  \"" +
            //
            AtsClientService.get().getWorkItemService().getActionableItemService().getActionableItemsStr(awa) + "\" ");
      }
   }

   public void refresh() throws OseeCoreException {
      refreshActionableItemsLabel();
   }

   private void editRelatedActionableItems(final AbstractReviewArtifact reviewArt) {
      final AICheckTreeDialog diag =
         new AICheckTreeDialog("Edit Actionable Items", "Select Actionable Items for this review", Active.Active);
      try {
         Collection<IAtsActionableItem> actionableItems = ActionableItems.getUserEditableActionableItems(
            AtsClientService.get().getWorkItemService().getActionableItemService().getActionableItems(reviewArt));

         diag.setInitialSelections(actionableItems);
         if (diag.open() != 0) {
            return;
         }
         IAtsChangeSet changes = AtsClientService.get().getStoreService().createAtsChangeSet("Edit Actionable Items",
            AtsClientService.get().getUserService().getCurrentUser());
         AtsClientService.get().getWorkItemService().getActionableItemService().setActionableItems(reviewArt,
            actionableItems, changes);
         changes.execute();
         editor.onDirtied();
         refreshActionableItemsLabel();
      } catch (Exception ex) {
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }

   }

}

Back to the top