|
1 | 1 | package org.joget.marketplace;
|
2 | 2 |
|
3 |
| -import java.util.ArrayList; |
4 |
| -import java.util.Collection; |
5 |
| -import java.util.HashMap; |
6 |
| -import java.util.Map; |
7 | 3 | import org.joget.apps.app.model.AppDefinition;
|
8 | 4 | import org.joget.apps.app.service.AppPluginUtil;
|
9 | 5 | import org.joget.apps.app.service.AppUtil;
|
|
12 | 8 | import org.joget.apps.datalist.model.DataListColumnFormatDefault;
|
13 | 9 | import org.joget.commons.util.LogUtil;
|
14 | 10 |
|
15 |
| -public class StatusColorDatalistFormatter extends DataListColumnFormatDefault{ |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.Collection; |
| 13 | +import java.util.HashMap; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +public class StatusColorDatalistFormatter extends DataListColumnFormatDefault { |
16 | 17 |
|
17 |
| - private final static String MESSAGE_PATH = "messages/StatusColorDatalistFormatter"; |
| 18 | + private final static String MESSAGE_PATH = "messages/StatusColorDatalistFormatter"; |
18 | 19 |
|
19 | 20 | public String getName() {
|
20 | 21 | return "Status Color Datalist Formatter";
|
21 | 22 | }
|
22 | 23 |
|
23 | 24 | public String getVersion() {
|
24 |
| - return "7.0.0"; |
| 25 | + return "8.0.0"; |
25 | 26 | }
|
26 | 27 |
|
27 | 28 | public String getDescription() {
|
28 | 29 | //support i18n
|
29 |
| - //======================================================================================================= |
| 30 | + //======================================================================================================= |
30 | 31 | return AppPluginUtil.getMessage("org.joget.marketplace.StatusColorDatalistFormatter.pluginDesc", getClassName(), MESSAGE_PATH);
|
31 | 32 | }
|
32 | 33 |
|
33 | 34 | @Override
|
34 | 35 | public String format(DataList dataList, DataListColumn column, Object row, Object value) {
|
35 | 36 | AppDefinition appDef = AppUtil.getCurrentAppDefinition();
|
36 | 37 | String result = (String) value;
|
37 |
| - |
| 38 | + |
38 | 39 | if (result != null && !result.isEmpty()) {
|
39 | 40 | try {
|
40 |
| - boolean isCaseSensitive = false; |
41 |
| - if(getPropertyString("statusCaseSensitivity") != null){ |
42 |
| - isCaseSensitive = Boolean.parseBoolean(getPropertyString("statusCaseSensitivity")); |
43 |
| - } |
44 |
| - // set options |
| 41 | + boolean isCaseSensitive = false; |
| 42 | + if (getPropertyString("statusCaseSensitivity") != null) { |
| 43 | + isCaseSensitive = Boolean.parseBoolean(getPropertyString("statusCaseSensitivity")); |
| 44 | + } |
| 45 | + // set options |
45 | 46 | Object[] options = (Object[]) getProperty("options");
|
46 |
| - Collection<Map> optionMap = new ArrayList<>(); |
47 |
| - |
48 |
| - for (Object o : options) { |
49 |
| - Map mapping = (HashMap) o; |
50 |
| - |
51 |
| - //case must match |
52 |
| - if (isCaseSensitive){ |
53 |
| - if(((String)value).equals((String)mapping.get("value"))){ |
54 |
| - result = "<p style=\"color: white; background-color: " + (String)mapping.get("backgroundColor") + |
55 |
| - "; white-space: nowrap; border-radius: 8px; padding:6px; text-align: center; margin: 0px; \">" + |
56 |
| - (String)mapping.get("label") + "</p>"; |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - //no case required |
61 |
| - else{ |
62 |
| - if(((String)value).equalsIgnoreCase((String)mapping.get("value"))){ |
63 |
| - result = "<p style=\"color: white; background-color: " + (String)mapping.get("backgroundColor") + |
64 |
| - "; white-space: nowrap; border-radius: 8px; padding:6px; text-align: center; margin: 0px; \">" + |
65 |
| - (String)mapping.get("label") + "</p>"; |
66 |
| - } |
67 |
| - } |
68 |
| - |
69 |
| - optionMap.add(mapping); |
70 |
| - } |
71 |
| - |
72 |
| - Map model = new HashMap(); |
73 |
| - model.put("options", optionMap); |
74 |
| - model.put("columnName", column.getName()); |
75 |
| - model.put("element", this); |
| 47 | + Collection<Map> optionMap = new ArrayList<>(); |
| 48 | + |
| 49 | + for (Object o : options) { |
| 50 | + Map mapping = (HashMap) o; |
| 51 | + |
| 52 | + //case must match |
| 53 | + if (isCaseSensitive) { |
| 54 | + if (value.equals(mapping.get("value"))) { |
| 55 | + result = "<p style=\"background-color: " + mapping.get("backgroundColor") + |
| 56 | + ";color: " + mapping.get("textColor") + ";white-space: nowrap; border-radius: 8px; padding:6px; text-align: center; margin: 0px; \">" + |
| 57 | + mapping.get("label") + "</p>"; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + //no case required |
| 62 | + else { |
| 63 | + if (((String) value).equalsIgnoreCase((String) mapping.get("value"))) { |
| 64 | + result = "<p style=\"background-color: " + mapping.get("backgroundColor") + |
| 65 | + ";color: " + mapping.get("textColor") + ";white-space: nowrap; border-radius: 8px; padding:6px; text-align: center; margin: 0px; \">" + |
| 66 | + mapping.get("label") + "</p>"; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + optionMap.add(mapping); |
| 71 | + } |
| 72 | + |
| 73 | + Map model = new HashMap(); |
| 74 | + model.put("options", optionMap); |
| 75 | + model.put("columnName", column.getName()); |
| 76 | + model.put("element", this); |
76 | 77 |
|
77 | 78 | } catch (Exception e) {
|
78 | 79 | LogUtil.error(getClassName(), e, "");
|
79 | 80 | }
|
80 |
| - } |
81 |
| - return result; |
| 81 | + } |
| 82 | + return result; |
82 | 83 | }
|
83 | 84 |
|
84 | 85 | public String getLabel() {
|
|
0 commit comments