Eclipseplugins
ConsistencyChecksImageProvider.java
1 package com.proalpha.pds.checks;
2 
3 import java.net.MalformedURLException;
4 import java.net.URISyntaxException;
5 import java.util.List;
6 
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.swt.graphics.Image;
9 
10 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck;
11 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck;
12 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntryRepos;
13 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntrySrc;
14 
15 class ConsistencyChecksImageProvider {
16 
17  private enum BugPriority {
18  GREY(0, "/images/bug_grey.png"), RED(1, "/images/bug_red.png"), YELLOW(2, "/images/bug_yellow.png"),
19  GREEN(3, "/images/bug_green.png");
20 
21  public static BugPriority getBugPriority(Integer value) {
22  BugPriority[] priorities = values();
23 
24  for (int i = 0; i < priorities.length; i++) {
25  if (priorities[i].getValue().equals(value)) {
26  return priorities[i];
27  }
28  }
29 
30  return GREY;
31  }
32 
33  private Integer value;
34  private String imagePath;
35 
36  private BugPriority(Integer value, String imagePath) {
37  this.value = value;
38  this.imagePath = imagePath;
39  }
40 
41  public String getImagePath() {
42  return imagePath;
43  }
44 
45  public Integer getValue() {
46  return value;
47  }
48  }
49 
50  public Image getDefaultImage() {
51  return getImageByPriority(BugPriority.YELLOW);
52  }
53 
54  public Image getImage(Object element) {
55 
56  Integer priority = 0;
57 
58  if (element instanceof TtDSSubCheck) {
59  priority = getPriority((TtDSSubCheck) element);
60  }
61  if (element instanceof TtDSCheck) {
62  priority = getPriority((TtDSCheck) element);
63  }
64 
65  return getImageByPriority(BugPriority.getBugPriority(priority));
66 
67  }
68 
69  private Image getImageByPriority(BugPriority priority) {
70  Image image = null;
71  try {
72  image = ImageDescriptor.createFromURL(getClass().getResource(priority.getImagePath()).toURI().toURL())
73  .createImage();
74  } catch (MalformedURLException | URISyntaxException e) {
75  // TODO Auto-generated catch block
76  e.printStackTrace();
77  }
78  return image;
79  }
80 
81  private Integer getPriority(TtDSCheck element) {
82  Integer priority = -1;
83 
84  for (TtDSSubCheck subCheck : element.getTtDSSubCheck()) {
85 
86  Integer tempPriority = getPriority(subCheck);
87 
88  if (priority == -1) {
89  priority = tempPriority;
90  } else if (tempPriority < priority) {
91  priority = tempPriority;
92  }
93 
94  }
95 
96  return priority;
97  }
98 
99  private Integer getPriority(TtDSSubCheck subCheck) {
100 
101  Integer priority = 0;
102  List<TtDSLogEntrySrc> entriesSrc = subCheck.getTtDSLogEntrySrc();
103 
104  if (entriesSrc.size() > 0) {
105  priority = entriesSrc.get(0).getLogEntryPriority();
106  } else {
107  List<TtDSLogEntryRepos> entriesRepos = subCheck.getTtDSLogEntryRepos();
108  if (entriesRepos.size() > 0) {
109  priority = entriesRepos.get(0).getLogEntryPriority();
110  }
111  }
112 
113  return priority;
114  }
115 
116 }