1
+ /*
2
+ * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.utplsql.sqldev.ui.runner
17
+
18
+ import java.awt.Color
19
+ import java.awt.Component
20
+ import java.awt.GridBagConstraints
21
+ import java.awt.GridBagLayout
22
+ import java.awt.Insets
23
+ import javax.swing.JLabel
24
+ import javax.swing.JPanel
25
+ import javax.swing.JProgressBar
26
+ import javax.swing.plaf.basic.BasicProgressBarUI
27
+ import org.utplsql.sqldev.model.LimitedLinkedHashMap
28
+ import org.utplsql.sqldev.model.runner.Run
29
+ import org.utplsql.sqldev.resources.UtplsqlResources
30
+
31
+ class RunnerPanel {
32
+ LimitedLinkedHashMap<String , Run > runs = new LimitedLinkedHashMap<String , Run > (10 )
33
+ JPanel basePanel
34
+ JLabel statusLabel
35
+ JLabel testCounterValueLabel
36
+ JLabel errorCounterValueLabel
37
+ JLabel failureCounterValueLabel
38
+ JProgressBar progressBar;
39
+
40
+ def Component getGUI () {
41
+ if (basePanel == = null ) {
42
+ initializeGUI()
43
+ }
44
+ return basePanel
45
+ }
46
+
47
+ def setStatus (String text ) {
48
+ statusLabel. text = text
49
+ }
50
+
51
+ def setModel (Run run ) {
52
+ runs. put(run. reporterId, run)
53
+ }
54
+
55
+ def updateCounter () {
56
+ val run = currentRun
57
+ testCounterValueLabel. text = ' ' ' «run.totalNumberOfCompletedTests»/«run.totalNumberOfTests»' ' '
58
+ errorCounterValueLabel. text = ' ' ' «run.counter.error»' ' '
59
+ failureCounterValueLabel. text = ' ' ' «run.counter.failure»' ' '
60
+ if (run. totalNumberOfTests == 0 ) {
61
+ progressBar. value = 100
62
+ } else {
63
+ progressBar. value = 100 * run. totalNumberOfCompletedTests / run. totalNumberOfTests
64
+ }
65
+ if (run. counter. error > 0 || run. counter. failure > 0 ) {
66
+ progressBar. foreground = Color . RED
67
+ } else {
68
+ progressBar. foreground = Color . GREEN
69
+ }
70
+ }
71
+
72
+ private def getCurrentRun () {
73
+ return runs. values. get(runs. values. length - 1 )
74
+ }
75
+
76
+ private def initializeGUI () {
77
+ // Base panel containing all components
78
+ basePanel = new JPanel ()
79
+ basePanel. setLayout(new GridBagLayout ())
80
+ var GridBagConstraints c = new GridBagConstraints ()
81
+
82
+ // Status line
83
+ statusLabel = new JLabel
84
+ c. gridx = 0
85
+ c. gridy = 0
86
+ c. gridwidth = 6
87
+ c. gridheight = 1
88
+ c. insets = new Insets (10 , 10 , 10 , 10 ) // top, left, bottom, right
89
+ c. anchor = GridBagConstraints :: WEST
90
+ c. fill = GridBagConstraints :: HORIZONTAL
91
+ c. weightx = 1
92
+ c. weighty = 0
93
+ basePanel. add(statusLabel, c)
94
+
95
+ // Test counter
96
+ val testCounterLabel = new JLabel (UtplsqlResources . getString(" RUNNER_TESTS_LABEL" ) + " :" ,
97
+ UtplsqlResources . getIcon(" UTPLSQL_ICON" ), JLabel :: LEADING )
98
+ c. gridx = 0
99
+ c. gridy = 1
100
+ c. gridwidth = 1
101
+ c. gridheight = 1
102
+ c. insets = new Insets (10 , 10 , 10 , 5 ) // top, left, bottom, right
103
+ c. anchor = GridBagConstraints :: WEST
104
+ c. fill = GridBagConstraints :: NONE
105
+ c. weightx = 0
106
+ c. weighty = 0
107
+ basePanel. add(testCounterLabel, c)
108
+ testCounterValueLabel = new JLabel
109
+ c. gridx = 1
110
+ c. gridy = 1
111
+ c. gridwidth = 1
112
+ c. gridheight = 1
113
+ c. insets = new Insets (10 , 0 , 10 , 10 ) // top, left, bottom, right
114
+ c. anchor = GridBagConstraints :: WEST
115
+ c. fill = GridBagConstraints :: NONE
116
+ c. weightx = 0
117
+ c. weighty = 0
118
+ basePanel. add(testCounterValueLabel, c)
119
+
120
+ // Error counter
121
+ val errorCounterLabel = new JLabel (UtplsqlResources . getString(" RUNNER_ERRORS_LABEL" ) + " :" ,
122
+ UtplsqlResources . getIcon(" ERROR_ICON" ), JLabel :: LEADING )
123
+ c. gridx = 2
124
+ c. gridy = 1
125
+ c. gridwidth = 1
126
+ c. gridheight = 1
127
+ c. insets = new Insets (10 , 10 , 10 , 5 ) // top, left, bottom, right
128
+ c. anchor = GridBagConstraints :: WEST
129
+ c. fill = GridBagConstraints :: NONE
130
+ c. weightx = 0
131
+ c. weighty = 0
132
+ basePanel. add(errorCounterLabel, c)
133
+ errorCounterValueLabel = new JLabel
134
+ c. gridx = 3
135
+ c. gridy = 1
136
+ c. gridwidth = 1
137
+ c. gridheight = 1
138
+ c. insets = new Insets (10 , 0 , 10 , 10 ) // top, left, bottom, right
139
+ c. anchor = GridBagConstraints :: WEST
140
+ c. fill = GridBagConstraints :: NONE
141
+ c. weightx = 0
142
+ c. weighty = 0
143
+ basePanel. add(errorCounterValueLabel, c)
144
+
145
+ // Failure counter
146
+ val failureCounterLabel = new JLabel (UtplsqlResources . getString(" RUNNER_FAILURES_LABEL" ) + " :" ,
147
+ UtplsqlResources . getIcon(" FAILURE_ICON" ), JLabel :: LEADING )
148
+ c. gridx = 4
149
+ c. gridy = 1
150
+ c. gridwidth = 1
151
+ c. gridheight = 1
152
+ c. insets = new Insets (10 , 10 , 10 , 5 ) // top, left, bottom, right
153
+ c. anchor = GridBagConstraints :: WEST
154
+ c. fill = GridBagConstraints :: NONE
155
+ c. weightx = 0
156
+ c. weighty = 0
157
+ basePanel. add(failureCounterLabel, c)
158
+ failureCounterValueLabel = new JLabel
159
+ c. gridx = 5
160
+ c. gridy = 1
161
+ c. gridwidth = 1
162
+ c. gridheight = 1
163
+ c. insets = new Insets (10 , 0 , 10 , 10 ) // top, left, bottom, right
164
+ c. anchor = GridBagConstraints :: WEST
165
+ c. fill = GridBagConstraints :: NONE
166
+ c. weightx = 0
167
+ c. weighty = 0
168
+ basePanel. add(failureCounterValueLabel, c)
169
+
170
+ // Progress bar
171
+ progressBar = new JProgressBar
172
+ progressBar. stringPainted = false
173
+ progressBar. foreground = Color . GREEN
174
+ progressBar. UI = new BasicProgressBarUI
175
+ c. gridx = 0
176
+ c. gridy = 2
177
+ c. gridwidth = 6
178
+ c. gridheight = 1
179
+ c. insets = new Insets (10 , 10 , 10 , 10 ) // top, left, bottom, right
180
+ c. anchor = GridBagConstraints :: WEST
181
+ c. fill = GridBagConstraints :: HORIZONTAL
182
+ c. weightx = 1
183
+ c. weighty = 0
184
+ basePanel. add(progressBar, c)
185
+
186
+ // Vertical spring
187
+ val spring = new JLabel
188
+ c. gridx = 0
189
+ c. gridy = 3
190
+ c. gridwidth = 6
191
+ c. gridheight = 1
192
+ c. insets = new Insets (10 , 10 , 10 , 10 ) // top, left, bottom, right
193
+ c. anchor = GridBagConstraints :: WEST
194
+ c. fill = GridBagConstraints :: BOTH
195
+ c. weightx = 1
196
+ c. weighty = 1
197
+ basePanel. add(spring, c)
198
+ }
199
+ }
0 commit comments