|
1 | | -/* |
| 1 | +/** |
2 | 2 | * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - package org.utplsql.sqldev.ui.runner |
| 16 | +package org.utplsql.sqldev.ui.runner; |
17 | 17 |
|
18 | | -import java.util.LinkedHashMap |
19 | | -import javax.swing.Icon |
20 | | -import javax.swing.table.DefaultTableModel |
21 | | -import org.utplsql.sqldev.model.PrefixTools |
22 | | -import org.utplsql.sqldev.model.runner.Test |
23 | | -import org.utplsql.sqldev.resources.UtplsqlResources |
| 18 | +import com.google.common.base.Objects; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.LinkedHashMap; |
| 21 | +import java.util.Map; |
| 22 | +import javax.swing.Icon; |
| 23 | +import javax.swing.table.DefaultTableModel; |
| 24 | +import org.eclipse.xtend2.lib.StringConcatenation; |
| 25 | +import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| 26 | +import org.eclipse.xtext.xbase.lib.Conversions; |
| 27 | +import org.eclipse.xtext.xbase.lib.IterableExtensions; |
| 28 | +import org.utplsql.sqldev.model.PrefixTools; |
| 29 | +import org.utplsql.sqldev.model.runner.Test; |
| 30 | +import org.utplsql.sqldev.resources.UtplsqlResources; |
24 | 31 |
|
25 | | -class TestOverviewTableModel extends DefaultTableModel { |
26 | | - LinkedHashMap<String, Test> tests |
27 | | - String commonPrefix |
28 | | - boolean commonPrefixCalculated |
29 | | - boolean showDescription |
30 | | - boolean useSmartTimes |
31 | | - |
32 | | - new() { |
33 | | - super() |
34 | | - } |
35 | | - |
36 | | - private def calcCommonPrefix() { |
37 | | - if (!commonPrefixCalculated && tests !== null && tests.size > 0) { |
38 | | - this.commonPrefix = PrefixTools.commonPrefix(tests.keySet.toList) |
39 | | - fireTableDataChanged() |
40 | | - commonPrefixCalculated = true |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - def setModel(LinkedHashMap<String, Test> tests, boolean showDescription, boolean useSmartTimes) { |
45 | | - commonPrefixCalculated = false |
46 | | - this.tests = tests |
47 | | - this.showDescription = showDescription |
48 | | - this.useSmartTimes = useSmartTimes |
49 | | - calcCommonPrefix |
50 | | - fireTableDataChanged() |
51 | | - } |
52 | | - |
53 | | - def updateModel(boolean showDescription) { |
54 | | - this.showDescription = showDescription |
55 | | - fireTableDataChanged() |
56 | | - } |
57 | | - |
58 | | - def getTestIdColumnName() { |
59 | | - calcCommonPrefix |
60 | | - if (commonPrefix === null || commonPrefix == "") { |
61 | | - if (showDescription) { |
62 | | - UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL") |
63 | | - } else { |
64 | | - UtplsqlResources.getString("RUNNER_TEST_ID_COLUMN") |
65 | | - } |
66 | | - } else { |
67 | | - if (showDescription) { |
68 | | - '''«UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL")» («commonPrefix»)''' |
69 | | - } else { |
70 | | - commonPrefix |
71 | | - } |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - def getTimeColumnName() { |
76 | | - val timeColumnName = '''«UtplsqlResources.getString("RUNNER_TEST_EXECUTION_TIME_COLUMN")»«IF !useSmartTimes» [s]«ENDIF»''' |
77 | | - return timeColumnName |
78 | | - } |
79 | | - |
80 | | - def getTest(int row) { |
81 | | - val entry = tests.entrySet.get(row) |
82 | | - val test = tests.get(entry.key) |
83 | | - return test |
84 | | - } |
85 | | - |
86 | | - override getRowCount() { |
87 | | - if (tests === null) { |
88 | | - return 0 |
89 | | - } |
90 | | - return tests.size() |
91 | | - } |
92 | | - |
93 | | - override getColumnCount() { |
94 | | - return 5 |
95 | | - } |
96 | | - |
97 | | - override getValueAt(int row, int col) { |
98 | | - val test = tests.entrySet.get(row).value |
99 | | - if (test === null) { |
100 | | - return null |
101 | | - } |
102 | | - switch (col) { |
103 | | - case 0: { |
104 | | - return test.statusIcon |
105 | | - } |
106 | | - case 1: { |
107 | | - return test.warningIcon |
108 | | - } |
109 | | - case 2: { |
110 | | - return test.infoIcon |
111 | | - } |
112 | | - case 3: { |
113 | | - return if(showDescription && test.description !== null) { |
114 | | - test.description |
115 | | - } else { |
116 | | - test.id.substring(if(commonPrefix === null) {0} else {commonPrefix.length}) |
117 | | - } |
118 | | - } |
119 | | - case 4: { |
120 | | - return test.executionTime |
121 | | - } |
122 | | - default: { |
123 | | - return null |
124 | | - } |
125 | | - } |
126 | | - } |
127 | | - |
128 | | - override getColumnName(int col) { |
129 | | - return #["", "", "", UtplsqlResources.getString(if (showDescription) {"RUNNER_DESCRIPTION_LABEL"} else {"RUNNER_TEST_ID_COLUMN"}), |
130 | | - timeColumnName].get(col) |
131 | | - } |
132 | | - |
133 | | - override isCellEditable(int row, int column) { |
134 | | - return false |
135 | | - } |
136 | | - |
137 | | - override getColumnClass(int col) { |
138 | | - switch (col) { |
139 | | - case 0: { |
140 | | - return Icon |
141 | | - } |
142 | | - case 1: { |
143 | | - return Icon |
144 | | - } |
145 | | - case 2: { |
146 | | - return Icon |
147 | | - } |
148 | | - case 3: { |
149 | | - return String |
150 | | - } |
151 | | - case 4: { |
152 | | - return Double |
153 | | - } |
154 | | - default: { |
155 | | - return String |
156 | | - } |
157 | | - } |
158 | | - } |
| 32 | +@SuppressWarnings("all") |
| 33 | +public class TestOverviewTableModel extends DefaultTableModel { |
| 34 | + private LinkedHashMap<String, Test> tests; |
| 35 | + |
| 36 | + private String commonPrefix; |
| 37 | + |
| 38 | + private boolean commonPrefixCalculated; |
| 39 | + |
| 40 | + private boolean showDescription; |
| 41 | + |
| 42 | + private boolean useSmartTimes; |
| 43 | + |
| 44 | + public TestOverviewTableModel() { |
| 45 | + super(); |
| 46 | + } |
| 47 | + |
| 48 | + private boolean calcCommonPrefix() { |
| 49 | + boolean _xifexpression = false; |
| 50 | + if ((((!this.commonPrefixCalculated) && (this.tests != null)) && (this.tests.size() > 0))) { |
| 51 | + boolean _xblockexpression = false; |
| 52 | + { |
| 53 | + this.commonPrefix = PrefixTools.commonPrefix(IterableExtensions.<String>toList(this.tests.keySet())); |
| 54 | + this.fireTableDataChanged(); |
| 55 | + _xblockexpression = this.commonPrefixCalculated = true; |
| 56 | + } |
| 57 | + _xifexpression = _xblockexpression; |
| 58 | + } |
| 59 | + return _xifexpression; |
| 60 | + } |
| 61 | + |
| 62 | + public void setModel(final LinkedHashMap<String, Test> tests, final boolean showDescription, final boolean useSmartTimes) { |
| 63 | + this.commonPrefixCalculated = false; |
| 64 | + this.tests = tests; |
| 65 | + this.showDescription = showDescription; |
| 66 | + this.useSmartTimes = useSmartTimes; |
| 67 | + this.calcCommonPrefix(); |
| 68 | + this.fireTableDataChanged(); |
| 69 | + } |
| 70 | + |
| 71 | + public void updateModel(final boolean showDescription) { |
| 72 | + this.showDescription = showDescription; |
| 73 | + this.fireTableDataChanged(); |
| 74 | + } |
| 75 | + |
| 76 | + public CharSequence getTestIdColumnName() { |
| 77 | + CharSequence _xblockexpression = null; |
| 78 | + { |
| 79 | + this.calcCommonPrefix(); |
| 80 | + CharSequence _xifexpression = null; |
| 81 | + if (((this.commonPrefix == null) || Objects.equal(this.commonPrefix, ""))) { |
| 82 | + String _xifexpression_1 = null; |
| 83 | + if (this.showDescription) { |
| 84 | + _xifexpression_1 = UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL"); |
| 85 | + } else { |
| 86 | + _xifexpression_1 = UtplsqlResources.getString("RUNNER_TEST_ID_COLUMN"); |
| 87 | + } |
| 88 | + _xifexpression = _xifexpression_1; |
| 89 | + } else { |
| 90 | + CharSequence _xifexpression_2 = null; |
| 91 | + if (this.showDescription) { |
| 92 | + StringConcatenation _builder = new StringConcatenation(); |
| 93 | + String _string = UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL"); |
| 94 | + _builder.append(_string); |
| 95 | + _builder.append(" ("); |
| 96 | + _builder.append(this.commonPrefix); |
| 97 | + _builder.append(")"); |
| 98 | + _xifexpression_2 = _builder; |
| 99 | + } else { |
| 100 | + _xifexpression_2 = this.commonPrefix; |
| 101 | + } |
| 102 | + _xifexpression = _xifexpression_2; |
| 103 | + } |
| 104 | + _xblockexpression = _xifexpression; |
| 105 | + } |
| 106 | + return _xblockexpression; |
| 107 | + } |
| 108 | + |
| 109 | + public String getTimeColumnName() { |
| 110 | + StringConcatenation _builder = new StringConcatenation(); |
| 111 | + String _string = UtplsqlResources.getString("RUNNER_TEST_EXECUTION_TIME_COLUMN"); |
| 112 | + _builder.append(_string); |
| 113 | + { |
| 114 | + if ((!this.useSmartTimes)) { |
| 115 | + _builder.append(" [s]"); |
| 116 | + } |
| 117 | + } |
| 118 | + final String timeColumnName = _builder.toString(); |
| 119 | + return timeColumnName; |
| 120 | + } |
| 121 | + |
| 122 | + public Test getTest(final int row) { |
| 123 | + final Map.Entry<String, Test> entry = ((Map.Entry<String, Test>[])Conversions.unwrapArray(this.tests.entrySet(), Map.Entry.class))[row]; |
| 124 | + final Test test = this.tests.get(entry.getKey()); |
| 125 | + return test; |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public int getRowCount() { |
| 130 | + if ((this.tests == null)) { |
| 131 | + return 0; |
| 132 | + } |
| 133 | + return this.tests.size(); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public int getColumnCount() { |
| 138 | + return 5; |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public Object getValueAt(final int row, final int col) { |
| 143 | + final Test test = ((Map.Entry<String, Test>[])Conversions.unwrapArray(this.tests.entrySet(), Map.Entry.class))[row].getValue(); |
| 144 | + if ((test == null)) { |
| 145 | + return null; |
| 146 | + } |
| 147 | + switch (col) { |
| 148 | + case 0: |
| 149 | + return test.getStatusIcon(); |
| 150 | + case 1: |
| 151 | + return test.getWarningIcon(); |
| 152 | + case 2: |
| 153 | + return test.getInfoIcon(); |
| 154 | + case 3: |
| 155 | + String _xifexpression = null; |
| 156 | + if ((this.showDescription && (test.getDescription() != null))) { |
| 157 | + _xifexpression = test.getDescription(); |
| 158 | + } else { |
| 159 | + String _id = test.getId(); |
| 160 | + int _xifexpression_1 = (int) 0; |
| 161 | + if ((this.commonPrefix == null)) { |
| 162 | + _xifexpression_1 = 0; |
| 163 | + } else { |
| 164 | + _xifexpression_1 = this.commonPrefix.length(); |
| 165 | + } |
| 166 | + _xifexpression = _id.substring(_xifexpression_1); |
| 167 | + } |
| 168 | + return _xifexpression; |
| 169 | + case 4: |
| 170 | + return test.getExecutionTime(); |
| 171 | + default: |
| 172 | + return null; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + @Override |
| 177 | + public String getColumnName(final int col) { |
| 178 | + String _xifexpression = null; |
| 179 | + if (this.showDescription) { |
| 180 | + _xifexpression = "RUNNER_DESCRIPTION_LABEL"; |
| 181 | + } else { |
| 182 | + _xifexpression = "RUNNER_TEST_ID_COLUMN"; |
| 183 | + } |
| 184 | + String _string = UtplsqlResources.getString(_xifexpression); |
| 185 | + String _timeColumnName = this.getTimeColumnName(); |
| 186 | + return Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("", "", "", _string, _timeColumnName)).get(col); |
| 187 | + } |
| 188 | + |
| 189 | + @Override |
| 190 | + public boolean isCellEditable(final int row, final int column) { |
| 191 | + return false; |
| 192 | + } |
| 193 | + |
| 194 | + @Override |
| 195 | + public Class<?> getColumnClass(final int col) { |
| 196 | + switch (col) { |
| 197 | + case 0: |
| 198 | + return Icon.class; |
| 199 | + case 1: |
| 200 | + return Icon.class; |
| 201 | + case 2: |
| 202 | + return Icon.class; |
| 203 | + case 3: |
| 204 | + return String.class; |
| 205 | + case 4: |
| 206 | + return Double.class; |
| 207 | + default: |
| 208 | + return String.class; |
| 209 | + } |
| 210 | + } |
159 | 211 | } |
0 commit comments