1 package com.stateofflow.eclipse.metrics.configuration;
2
3 import java.text.MessageFormat;
4 import java.util.MissingResourceException;
5 import java.util.ResourceBundle;
6
7 import com.stateofflow.eclipse.metrics.metric.MetricId;
8
9 public class MetricPresentations {
10 private static final String TASK_LIST_MESSAGE_SUFFIX = "taskListMessage";
11 private static final String PRESENTATION_NAME_SUFFIX = "presentationName";
12 private static final String SHORT_PRESENTATION_NAME_SUFFIX = "shortPresentationName";
13 private static final String DESCRIPTION_FILE_SUFFIX = "descriptionFile";
14 private static final String DESCRIPTION_DIRECTORY_URL = "descriptionDirectoryUrl";
15
16 private final ResourceBundle resourceBundle;
17
18 public MetricPresentations(final ResourceBundle resourceBundle) {
19 this.resourceBundle = resourceBundle;
20 }
21
22 public String getDescriptionUrl(final MetricId metricId) {
23 return getResourceString(DESCRIPTION_DIRECTORY_URL) + getResourceString(metricId, DESCRIPTION_FILE_SUFFIX);
24 }
25
26 public String getPresentationName(final MetricId metricId) {
27 return getResourceString(metricId, PRESENTATION_NAME_SUFFIX);
28 }
29
30 private String getResourceString(final MetricId id, final String subKey) {
31 return getResourceString(id + "." + subKey);
32 }
33
34 private String getResourceString(final String key) {
35 try {
36 return resourceBundle.getString(key);
37 } catch (final MissingResourceException e) {
38 return key;
39 }
40 }
41
42 public String getShortPresentationName(final MetricId metricId) {
43 return getResourceString(metricId, SHORT_PRESENTATION_NAME_SUFFIX);
44 }
45
46 public String getViolationMessage(final MetricId metricId, final int metricValue) {
47 return new MessageFormat(getResourceString(metricId, TASK_LIST_MESSAGE_SUFFIX)).format(new Integer[]{new Integer(metricValue)});
48 }
49 }
50