Skip to content

Commit 85e0a33

Browse files
convert TestOverviewTableModel to Java, removing Xtend dependencies
1 parent 1c77f81 commit 85e0a33

File tree

1 file changed

+133
-174
lines changed

1 file changed

+133
-174
lines changed
Lines changed: 133 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,197 +15,156 @@
1515
*/
1616
package org.utplsql.sqldev.ui.runner;
1717

18-
import com.google.common.base.Objects;
19-
import java.util.Collections;
18+
import java.util.ArrayList;
2019
import java.util.LinkedHashMap;
21-
import java.util.Map;
20+
import java.util.Map.Entry;
21+
2222
import javax.swing.Icon;
2323
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;
24+
2825
import org.utplsql.sqldev.model.PrefixTools;
2926
import org.utplsql.sqldev.model.runner.Test;
3027
import org.utplsql.sqldev.resources.UtplsqlResources;
3128

32-
@SuppressWarnings("all")
3329
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;
30+
private static final long serialVersionUID = -4087082648970132657L;
31+
32+
private LinkedHashMap<String, Test> tests;
33+
private String commonPrefix;
34+
private boolean commonPrefixCalculated;
35+
private boolean showDescription;
36+
private boolean useSmartTimes;
37+
38+
public TestOverviewTableModel() {
39+
super();
5840
}
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");
41+
42+
private void calcCommonPrefix() {
43+
if (!commonPrefixCalculated && tests != null && tests.size() > 0) {
44+
commonPrefix = PrefixTools.commonPrefix(new ArrayList<String>(tests.keySet()));
45+
fireTableDataChanged();
46+
commonPrefixCalculated = true;
8747
}
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;
48+
}
49+
50+
public void setModel(final LinkedHashMap<String, Test> tests, final boolean showDescription,
51+
final boolean useSmartTimes) {
52+
commonPrefixCalculated = false;
53+
this.tests = tests;
54+
this.showDescription = showDescription;
55+
this.useSmartTimes = useSmartTimes;
56+
calcCommonPrefix();
57+
fireTableDataChanged();
58+
}
59+
60+
public void updateModel(final boolean showDescription) {
61+
this.showDescription = showDescription;
62+
fireTableDataChanged();
63+
}
64+
65+
public CharSequence getTestIdColumnName() {
66+
StringBuilder sb = new StringBuilder();
67+
calcCommonPrefix();
68+
if (commonPrefix == null || commonPrefix.isEmpty()) {
69+
if (showDescription) {
70+
sb.append(UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL"));
71+
} else {
72+
sb.append(UtplsqlResources.getString("RUNNER_TEST_ID_COLUMN"));
73+
}
9974
} else {
100-
_xifexpression_2 = this.commonPrefix;
75+
if (showDescription) {
76+
sb.append(UtplsqlResources.getString("RUNNER_DESCRIPTION_LABEL"));
77+
sb.append(" (");
78+
sb.append(commonPrefix);
79+
sb.append(")");
80+
} else {
81+
sb.append(commonPrefix);
82+
}
10183
}
102-
_xifexpression = _xifexpression_2;
103-
}
104-
_xblockexpression = _xifexpression;
84+
return sb.toString();
85+
}
86+
87+
public String getTimeColumnName() {
88+
return UtplsqlResources.getString("RUNNER_TEST_EXECUTION_TIME_COLUMN") + (!useSmartTimes ? " [s]" : "");
10589
}
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-
}
90+
91+
public Test getTest(final int row) {
92+
return new ArrayList<Entry<String, Test>>(tests.entrySet()).get(row).getValue();
11793
}
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;
94+
95+
@Override
96+
public int getRowCount() {
97+
if (tests == null) {
98+
return 0;
99+
}
100+
return tests.size();
132101
}
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;
102+
103+
@Override
104+
public int getColumnCount() {
105+
return 5;
146106
}
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);
107+
108+
@Override
109+
public Object getValueAt(final int row, final int col) {
110+
final Test test = getTest(row);
111+
switch (col) {
112+
case 0:
113+
return test.getStatusIcon();
114+
case 1:
115+
return test.getWarningIcon();
116+
case 2:
117+
return test.getInfoIcon();
118+
case 3:
119+
if (showDescription && test.getDescription() != null) {
120+
return test.getDescription();
121+
} else {
122+
return test.getId().substring(commonPrefix == null ? 0 : commonPrefix.length());
123+
}
124+
case 4:
125+
return test.getExecutionTime();
126+
default:
127+
return null;
167128
}
168-
return _xifexpression;
169-
case 4:
170-
return test.getExecutionTime();
171-
default:
172-
return null;
173129
}
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";
130+
131+
@Override
132+
public String getColumnName(final int col) {
133+
switch (col) {
134+
case 0:
135+
case 1:
136+
case 2:
137+
return ""; // icons are used instead of descriptions
138+
case 3:
139+
return UtplsqlResources.getString(showDescription ? "RUNNER_DESCRIPTION_LABEL" : "RUNNER_TEST_ID_COLUMN");
140+
case 4:
141+
return getTimeColumnName();
142+
default:
143+
return null;
144+
}
145+
146+
}
147+
148+
@Override
149+
public boolean isCellEditable(final int row, final int column) {
150+
return false;
183151
}
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;
152+
153+
@Override
154+
public Class<?> getColumnClass(final int col) {
155+
switch (col) {
156+
case 0:
157+
return Icon.class;
158+
case 1:
159+
return Icon.class;
160+
case 2:
161+
return Icon.class;
162+
case 3:
163+
return String.class;
164+
case 4:
165+
return Double.class;
166+
default:
167+
return String.class;
168+
}
209169
}
210-
}
211170
}

0 commit comments

Comments
 (0)