1 package com.proalpha.pds.checks;
3 import java.net.MalformedURLException;
4 import java.net.URISyntaxException;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.swt.graphics.Image;
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;
15 class ConsistencyChecksImageProvider {
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");
21 public static BugPriority getBugPriority(Integer value) {
22 BugPriority[] priorities = values();
24 for (
int i = 0; i < priorities.length; i++) {
25 if (priorities[i].getValue().equals(value)) {
33 private Integer value;
34 private String imagePath;
36 private BugPriority(Integer value, String imagePath) {
38 this.imagePath = imagePath;
41 public String getImagePath() {
45 public Integer getValue() {
50 public Image getDefaultImage() {
51 return getImageByPriority(BugPriority.YELLOW);
54 public Image getImage(Object element) {
58 if (element instanceof TtDSSubCheck) {
59 priority = getPriority((TtDSSubCheck) element);
61 if (element instanceof TtDSCheck) {
62 priority = getPriority((TtDSCheck) element);
65 return getImageByPriority(BugPriority.getBugPriority(priority));
69 private Image getImageByPriority(BugPriority priority) {
72 image = ImageDescriptor.createFromURL(getClass().getResource(priority.getImagePath()).toURI().toURL())
74 }
catch (MalformedURLException | URISyntaxException e) {
81 private Integer getPriority(TtDSCheck element) {
82 Integer priority = -1;
84 for (TtDSSubCheck subCheck : element.getTtDSSubCheck()) {
86 Integer tempPriority = getPriority(subCheck);
89 priority = tempPriority;
90 }
else if (tempPriority < priority) {
91 priority = tempPriority;
99 private Integer getPriority(TtDSSubCheck subCheck) {
101 Integer priority = 0;
102 List<TtDSLogEntrySrc> entriesSrc = subCheck.getTtDSLogEntrySrc();
104 if (entriesSrc.size() > 0) {
105 priority = entriesSrc.get(0).getLogEntryPriority();
107 List<TtDSLogEntryRepos> entriesRepos = subCheck.getTtDSLogEntryRepos();
108 if (entriesRepos.size() > 0) {
109 priority = entriesRepos.get(0).getLogEntryPriority();