Skip to main content
summaryrefslogtreecommitdiffstats
blob: 42e70677ad05954a8b539c9238509b202c212ccd (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*******************************************************************************
 * 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.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.osee.ats.artifact.ATSArtifact;
import org.eclipse.osee.ats.artifact.ATSLog;
import org.eclipse.osee.ats.artifact.ATSLog.LogType;
import org.eclipse.osee.ats.artifact.LogItem;
import org.eclipse.osee.ats.artifact.StateMachineArtifact;
import org.eclipse.osee.ats.artifact.TaskArtifact;
import org.eclipse.osee.ats.artifact.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.internal.AtsPlugin;
import org.eclipse.osee.ats.util.widgets.SMAState;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.IRelationEnumeration;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.jdk.core.util.AHTML.CellItem;
import org.eclipse.osee.framework.jdk.core.util.DateUtil;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationLink;
import org.eclipse.osee.framework.skynet.core.utility.Artifacts;
import org.eclipse.osee.framework.ui.skynet.results.XResultData;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultBrowserHyperCmd;

public class Overview {

   public final static String normalColor = "#EEEEEE";
   private final static String activeColor = "#9CCCFF";
   public final static String errorColor = "#FFD6AC";
   public final static String subscribedColor = "#FFCCAA";
   public final static String labelColor = "darkcyan";
   public static enum PreviewStyle {
      NONE,
      MAP,
      TASKS,
      NOTES,
      LOG,
      HYPEROPEN,
      NO_SUBSCRIBE_OR_FAVORITE;

      public static boolean contains(PreviewStyle[] styles, PreviewStyle style) {
         for (PreviewStyle st : styles) {
            if (st.equals(style)) {
               return true;
            }
         }
         return false;
      }
   };
   private StringBuilder html;
   public final static String labelFont = "<font color=\"darkcyan\" face=\"Arial\" size=\"-1\">";
   public final static int TABLE_WIDTH = 95;
   public boolean showTasks = false;

   public Overview() {
      clearHtml();
   }

   public void clearHtml() {
      html = new StringBuilder(1000);
   }

   /**
    * @return HTML page for browser display
    */
   public String getPage() {
      return "<html><body>\n" + html + "\n</body></html>";
   }

   /**
    * Return label with value converted to show html reserved characters
    * 
    * @return string to embed into html
    */
   public String getLabelValue(String label, String value) {
      String valueStr = AHTML.textToHtml(value);
      return getLabel(label) + valueStr;
   }

   /**
    * Return label and value WITHOUT conversion to handle html reserved characters. Value will be as-is
    * 
    * @return string to embed into html
    */
   public String getLabelValueNoConvert(String label, String value) {
      return getLabel(label) + value;
   }

   public static String getLabel(String label) {
      return AHTML.getLabelStr(labelFont, label + ": ");
   }

   public void addTable(String str) {
      addTable(new String[] {str});
   }

   public void addTable(String str, String str2) {
      addTable(new String[] {str, str2});
   }

   public void addTable(String str, String str2, String str3) {
      addTable(new String[] {str, str2, str3});
   }

   public void addTable(String[] strs) {
      addTable(strs, 100);
   }

   public void addHtml(String html) {
      this.html.append(html);
   }

   public void addTable(String[] strs, int width) {
      if (strs.length == 1) {
         this.html.append(AHTML.simpleTable(strs[0]));
      } else {
         this.html.append(AHTML.multiColumnTable(strs, width));
      }
   }

   public void addHeader(StateMachineArtifact sma, PreviewStyle... styles) throws OseeCoreException {
      startBorderTable(100, false, "");
      addTable(getLabelValue("Title", sma.getName()));
      this.html.append(AHTML.multiColumnTable(new String[] {
         AHTML.getLabelStr(labelFont, "State: ") + sma.getStateMgr().getCurrentStateName(),
         AHTML.getLabelStr(labelFont, "Type: ") + sma.getArtifactTypeName(),
         AHTML.getLabelStr(labelFont, "Id: ") + sma.getHumanReadableId()}));
      addTable(getLabelValue("Originator", sma.getOriginator().getName()),
         getLabelValue("Creation Date", DateUtil.getMMDDYYHHMM(sma.getLog().getCreationDate())));
      if (sma.isTeamWorkflow()) {
         addTable(getLabelValue("Team", ((TeamWorkFlowArtifact) sma).getTeamName()),
            getLabelValue("Assignees", Artifacts.toString("; ", sma.getStateMgr().getAssignees())));
      } else {
         addTable(getLabelValue("Assignees", Artifacts.toString("; ", sma.getStateMgr().getAssignees())));
      }
      addTable(getLabelValue("Description", sma.getDescription()));
      if (sma.isCancelled()) {
         LogItem item = sma.getLog().getStateEvent(LogType.StateCancelled);
         addTable(getLabelValue("Cancelled From", item.getState()));
         addTable(getLabelValue("Cancellation Reason", item.getMsg()));
      }
      if (sma instanceof TaskArtifact) {
         StateMachineArtifact parentArt = ((TaskArtifact) sma).getParentSMA();
         if (parentArt != null) {
            this.html.append(AHTML.multiColumnTable(new String[] {AHTML.getLabelStr(labelFont, "Parent Workflow: ") + parentArt.getName()}));
            this.html.append(AHTML.multiColumnTable(new String[] {AHTML.getLabelStr(labelFont, "Parent State: ") + ((TaskArtifact) sma).getStateMgr().getCurrentStateName()}));
         }
         this.html.append(AHTML.multiColumnTable(new String[] {AHTML.getLabelStr(labelFont, "Task Owner: ") + Artifacts.toString(
            "; ", sma.getStateMgr().getAssignees())}));
      }
      endBorderTable();
   }

   public void addFooter(StateMachineArtifact sma, PreviewStyle... styles) {
      this.html.append(AHTML.newline());

      if (PreviewStyle.contains(styles, PreviewStyle.HYPEROPEN)) {
         this.html.append("Start OSEE, select the ATS perspective and search by the Id shown.");
      }
   }

   public void addRelationsBlock(ATSArtifact artifact) {
      addRelationTable("Is Superceded By", CoreRelationTypes.Supercedes_Supercedes, artifact);
      addRelationTable("Supercedes", CoreRelationTypes.Supercedes_Superceded, artifact);
      addRelationTable("Supports", CoreRelationTypes.SupportingInfo_SupportedBy, artifact);
      addRelationTable("Is Supported By", CoreRelationTypes.SupportingInfo_SupportingInfo, artifact);
   }

   public void addNotes(Artifact artifact) {
      if (artifact instanceof StateMachineArtifact) {
         String notesHtml = ((StateMachineArtifact) artifact).getNotes().getTable(null);
         if (notesHtml.equals("")) {
            return;
         }
         this.html.append(notesHtml);
      }
   }

   public static String getGenericArtifactTable(String name, Collection<Artifact> arts) {
      return getGenericArtifactTable(name, arts, 100);
   }

   public static String getGenericArtifactTable(String name, Collection<Artifact> arts, int width) {
      StringBuilder builder = new StringBuilder();
      builder.append(AHTML.addSpace(1) + Overview.getLabel(name));
      if (arts.size() > 0) {
         builder.append("<TABLE BORDER=\"1\" align=\"center\" cellspacing=\"1\" cellpadding=\"3%\" width=\"" + width + "%\"><THEAD><TR><TH>Type</TH>" + "<TH>Name</TH></THEAD></TR>");
         for (Artifact art : arts) {
            builder.append("<TR>");
            builder.append("<TD>" + art.getArtifactTypeName() + "</TD>");
            builder.append("<TD>" + Overview.getOpenHyperlinkHtml(art) + "</TD>");
            builder.append("</TR>");
         }
         builder.append("</TABLE>");
      }
      return builder.toString();
   }

   @SuppressWarnings("deprecation")
   public void addRelationTable(String name, IRelationEnumeration side, Artifact parent) {
      try {
         List<Artifact> arts = parent.getRelatedArtifacts(side);
         if (arts.isEmpty()) {
            return;
         }
         startBorderTable(false, name);
         html.append(AHTML.addHeaderRowMultiColumnTable(new String[] {"Type", "Name", "Rationale"}));
         for (Artifact art : arts) {
            String rationale = "";
            RelationLink link = parent.getRelations(side, art).iterator().next();
            if (!link.getRationale().equals("")) {
               rationale = link.getRationale();
            }
            String hyperStr = Overview.getOpenHyperlinkHtml(art);
            html.append(AHTML.addRowMultiColumnTable(new String[] {art.getArtifactTypeName(), hyperStr, rationale}));
         }
         endBorderTable();
      } catch (OseeCoreException ex) {
         OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
      }
   }

   public void addTeams(Collection<TeamWorkFlowArtifact> teams) throws OseeCoreException {
      startBorderTable(TABLE_WIDTH, false, "Team Workflows");
      StringBuffer sb = new StringBuffer(AHTML.beginMultiColumnTable(100, 1));
      sb.append(AHTML.addHeaderRowMultiColumnTable(new String[] {"Type", "State"}, new Integer[] {70, 150}));
      ArrayList<CellItem> cells = new ArrayList<CellItem>();
      for (TeamWorkFlowArtifact team : teams) {
         cells.add(new AHTML.CellItem(team.getHyperlinkHtml()));
         cells.add(new AHTML.CellItem(team.getStateMgr().getCurrentStateName()));
         sb.append(AHTML.addRowMultiColumnTable(cells));
         cells.clear();
      }
      sb.append(AHTML.endMultiColumnTable());
      html.append(sb.toString());

      endBorderTable();
   }

   public static String getOpenHyperlinkHtml(Artifact art) {
      return getOpenHyperlinkHtml(art.getName(), art);
   }

   public static String getOpenHyperlinkHtml(String name, String hrid) {
      return AHTML.getHyperlink(XResultBrowserHyperCmd.getHyperCmdStr(XResultBrowserHyperCmd.openAction, hrid), name);
   }

   public static String getOpenArtEditHyperlinkHtml(String name, String hrid) {
      return AHTML.getHyperlink(XResultBrowserHyperCmd.getHyperCmdStr(XResultBrowserHyperCmd.openArtifactEditor, hrid),
         name);
   }

   public static String getOpenHyperlinkHtml(String name, String guidOrHrid, int branchId) {
      return XResultData.getHyperlink(name, guidOrHrid, branchId);
   }

   public static String getOpenHyperlinkHtml(String name, Artifact art) {
      return AHTML.getHyperlink(
         XResultBrowserHyperCmd.getHyperCmdStr(XResultBrowserHyperCmd.openAction, art.getGuid()), name);
   }

   public void addLog(StateMachineArtifact artifact) throws OseeCoreException {
      ATSLog artifactLog = artifact.getLog();
      if (artifactLog != null && artifactLog.getLogItems().size() > 0) {
         addTable(artifact.getLog().getTable());
      }
   }

   public void startStateBorderTable(StateMachineArtifact sma, SMAState state) throws OseeCoreException {
      String caption = state.getName();
      String assgn = Artifacts.toString("; ", state.getAssignees());
      startStateBorderTable(sma.getStateMgr().getCurrentStateName().equals(state.getName()), caption, assgn);
   }

   public void startStateBorderTable(boolean active, String name, String assignee) {
      if (Strings.isValid(assignee)) {
         startBorderTable(active, String.format("%s (%s)", name, assignee));
      } else {
         startBorderTable(active, String.format("%s", name));
      }
   }

   public void startBorderTable(boolean active, String caption) {
      this.html.append(AHTML.startBorderTable(TABLE_WIDTH, active ? activeColor : normalColor, caption));
   }

   public void startBorderTable(int width, boolean active, String caption) {
      this.html.append(AHTML.startBorderTable(width, active ? activeColor : normalColor, caption));
   }

   public void startBorderTable(int width, String caption, String backgroundColor) {
      this.html.append(AHTML.startBorderTable(width, backgroundColor, caption));
   }

   public void endBorderTable() {
      this.html.append(AHTML.endBorderTable());
   }

   public boolean isShowTasks() {
      return showTasks;
   }

   public void setShowTasks(boolean showTasks) {
      this.showTasks = showTasks;
   }
}

Back to the top