1
1
package life.qbic.portal.sampletracking.components.projectoverview
2
2
3
-
4
3
import com.vaadin.data.provider.DataProvider
5
4
import com.vaadin.data.provider.ListDataProvider
6
5
import com.vaadin.event.selection.SingleSelectionEvent
7
6
import com.vaadin.icons.VaadinIcons
8
7
import com.vaadin.server.FileDownloader
9
8
import com.vaadin.server.StreamResource
10
9
import com.vaadin.shared.ui.ContentMode
10
+ import com.vaadin.shared.ui.MarginInfo
11
11
import com.vaadin.shared.ui.grid.HeightMode
12
12
import com.vaadin.ui.*
13
13
import com.vaadin.ui.Grid.Column
14
14
import com.vaadin.ui.themes.ValoTheme
15
15
import groovy.util.logging.Log4j2
16
16
import life.qbic.portal.sampletracking.Constants
17
17
import life.qbic.portal.sampletracking.communication.notification.NotificationService
18
+ import life.qbic.portal.sampletracking.components.GridUtils
18
19
import life.qbic.portal.sampletracking.components.projectoverview.download.DownloadProjectController
19
20
import life.qbic.portal.sampletracking.components.projectoverview.samplelist.FailedQCSamplesView
20
21
import life.qbic.portal.sampletracking.components.projectoverview.samplelist.ProjectOverviewController
@@ -32,7 +33,7 @@ import life.qbic.portal.sampletracking.components.projectoverview.subscribe.Subs
32
33
*
33
34
*/
34
35
@Log4j2
35
- class ProjectOverviewView extends VerticalLayout {
36
+ class ProjectOverviewView extends VerticalLayout {
36
37
37
38
private final ProjectOverviewViewModel viewModel
38
39
private final DownloadProjectController downloadProjectController
@@ -42,6 +43,8 @@ class ProjectOverviewView extends VerticalLayout{
42
43
private final ProjectOverviewController projectOverviewController
43
44
44
45
private Grid<ProjectSummary > projectGrid
46
+ private HorizontalSplitPanel splitPanel
47
+ private static final Collection<String > columnIdsWithFilters = [" ProjectCode" , " ProjectTitle" ]
45
48
46
49
final static int MAX_CODE_COLUMN_WIDTH = 400
47
50
final static int MAX_STATUS_COLUMN_WIDTH = 200
@@ -61,12 +64,40 @@ class ProjectOverviewView extends VerticalLayout{
61
64
62
65
private void initLayout (){
63
66
Label titleLabel = new Label (" Project Overview" )
64
- titleLabel. addStyleName(ValoTheme . LABEL_LARGE )
67
+ titleLabel. addStyleName(ValoTheme . LABEL_HUGE )
68
+
69
+ Label spacerLabel = new Label (" " , ContentMode . HTML )
70
+
65
71
setupProjects()
66
- HorizontalLayout buttonBar = setupButtonLayout()
67
- failedQCSamplesView. setVisible(false )
72
+
73
+ HorizontalLayout projectButtonBar = setupButtonLayout()
74
+ VerticalLayout projectLayout = new VerticalLayout (projectButtonBar,projectGrid)
75
+ projectLayout. setMargin(false )
76
+
77
+ splitPanel = createSplitLayout(projectLayout,failedQCSamplesView)
78
+ failedQCSamplesView. addVisibilityChangeListener({ splitPanel. splitPosition = it. newValue ? 65 : 100 })
79
+
80
+ connectFailedQcSamplesView()
68
81
bindManifestToProjectSelection()
69
- this . addComponents(titleLabel,buttonBar, projectGrid, failedQCSamplesView)
82
+
83
+ this . addComponents(titleLabel, spacerLabel, splitPanel)
84
+ }
85
+
86
+ private void connectFailedQcSamplesView () {
87
+ FailedQCSamplesView samplesView = failedQCSamplesView
88
+ showWhenFailingSamplesExist(samplesView)
89
+
90
+ viewModel. addPropertyChangeListener(" selectedProject" , {
91
+ Optional<ProjectSummary > selectedProject = Optional . ofNullable(viewModel. selectedProject)
92
+ selectedProject. ifPresent({
93
+ if (failingSamplesExist()){
94
+ loadFailedQcSamples(it)
95
+ }
96
+ })
97
+ if (! selectedProject. isPresent()) {
98
+ samplesView. reset()
99
+ }
100
+ })
70
101
}
71
102
72
103
private HorizontalLayout setupButtonLayout () {
@@ -75,37 +106,17 @@ class ProjectOverviewView extends VerticalLayout{
75
106
76
107
Button postmanLink = setUpLinkButton()
77
108
Button downloadManifestAction = setupDownloadButton()
78
- Button showDetails = setupShowDetails()
79
109
CheckBox subscriptionCheckBox = setupSubscriptionCheckBox()
80
- buttonBar. addComponents(showDetails, downloadManifestAction, postmanLink, subscriptionCheckBox)
110
+
111
+ buttonBar. addComponents(downloadManifestAction, postmanLink, subscriptionCheckBox)
81
112
buttonBar. setComponentAlignment(postmanLink, Alignment . MIDDLE_CENTER )
82
113
buttonBar. setComponentAlignment(subscriptionCheckBox, Alignment . MIDDLE_CENTER )
83
114
return buttonBar
84
115
}
85
116
86
- private Button setupShowDetails (){
87
- Button detailsButton = new Button (" Show Details" )
88
- detailsButton. setIcon(VaadinIcons . INFO_CIRCLE )
89
- detailsButton. setEnabled(false )
90
-
91
- projectGrid. addSelectionListener({
92
- failedQCSamplesView. setVisible(false )
93
-
94
- if (viewModel. selectedProject && viewModel. selectedProject. samplesQc. failingSamples > 0 ){
95
- detailsButton. setEnabled(true )
96
- }else {
97
- detailsButton. setEnabled(false )
98
- }
99
- })
100
-
101
- detailsButton. addClickListener({
102
- if (viewModel. selectedProject){
103
- projectOverviewController. getFailedQcSamples(viewModel. selectedProject. code)
104
- failedQCSamplesView. setVisible(true )
105
- }
106
- })
107
-
108
- return detailsButton
117
+ private void loadFailedQcSamples (ProjectSummary projectSummary ) {
118
+ String code = projectSummary. getCode()
119
+ projectOverviewController. getFailedQcSamples(code)
109
120
}
110
121
111
122
private Button setUpLinkButton (){
@@ -145,7 +156,7 @@ class ProjectOverviewView extends VerticalLayout{
145
156
146
157
CheckBox subscriptionCheckBox = new CheckBox (" Subscribe" )
147
158
subscriptionCheckBox. setVisible(false )
148
- enableWhenProjectIsSelected (subscriptionCheckBox)
159
+ showWhenProjectIsSelected (subscriptionCheckBox)
149
160
subscriptionCheckBox. setValue(false )
150
161
viewModel. addPropertyChangeListener(" selectedProject" , {
151
162
Optional<ProjectSummary > selectedProjectSummary = Optional . ofNullable(it. newValue as ProjectSummary )
@@ -201,7 +212,6 @@ class ProjectOverviewView extends VerticalLayout{
201
212
selectedItem. ifPresent({
202
213
selectProject(it)
203
214
})
204
-
205
215
}
206
216
})
207
217
viewModel. updatedProjectsChannel. subscribe({updatedProjectCode ->
@@ -229,12 +239,18 @@ class ProjectOverviewView extends VerticalLayout{
229
239
}
230
240
}
231
241
242
+ private static HorizontalSplitPanel createSplitLayout (Layout leftComponent , VerticalLayout rightComponent ){
243
+ HorizontalSplitPanel splitPanel = new HorizontalSplitPanel (leftComponent,rightComponent)
244
+ splitPanel. setSplitPosition(100 )
245
+ rightComponent. setMargin(new MarginInfo (false ,false ,false ,true ))
246
+
247
+ return splitPanel
248
+ }
249
+
232
250
private void bindManifestToProjectSelection () {
233
251
viewModel. addPropertyChangeListener(" selectedProject" , { tryToDownloadManifest() })
234
252
}
235
253
236
-
237
-
238
254
private void clearProjectSelection () {
239
255
viewModel. selectedProject = null
240
256
}
@@ -285,9 +301,9 @@ class ProjectOverviewView extends VerticalLayout{
285
301
if ( viewModel. selectedProject ) {
286
302
projectGrid. select(viewModel. selectedProject)
287
303
}
304
+ GridUtils . setupFilters(projectGrid, columnIdsWithFilters)
288
305
}
289
306
290
-
291
307
private void tryToDownloadManifest () {
292
308
Optional<ProjectSummary > selectedSummary = Optional . empty()
293
309
try {
@@ -323,14 +339,29 @@ class ProjectOverviewView extends VerticalLayout{
323
339
return isAvailable
324
340
}
325
341
326
- private void enableWhenProjectIsSelected (CheckBox checkBox ) {
327
- viewModel. addPropertyChangeListener(" selectedProject" ) {
342
+ private void showWhenProjectIsSelected (CheckBox checkBox ) {
343
+ viewModel. addPropertyChangeListener(" selectedProject" , {
328
344
if (viewModel. selectedProject){
329
345
checkBox. setVisible(true )
330
346
}else {
331
347
checkBox. setVisible(false )
332
348
}
333
- }
349
+ })
350
+ }
351
+
352
+ private void showWhenFailingSamplesExist (Component component ) {
353
+ component. setVisible(failingSamplesExist())
354
+ viewModel. addPropertyChangeListener(" selectedProject" , {
355
+ component. setVisible(failingSamplesExist())
356
+ })
357
+ }
358
+
359
+ private boolean failingSamplesExist () {
360
+ Optional<ProjectSummary > selectedProject = Optional . ofNullable(viewModel. selectedProject)
361
+ boolean hasFailingSamples = selectedProject
362
+ .map({ it. samplesQc. failingSamples > 0 })
363
+ .orElse(false )
364
+ return hasFailingSamples
334
365
}
335
366
336
367
private void subscribeToProject (String projectCode ) {
@@ -354,16 +385,13 @@ class ProjectOverviewView extends VerticalLayout{
354
385
* @param sampleCount The total number of samples registered
355
386
*/
356
387
private static State determineCompleteness (SampleCount sampleCount ) {
357
- if (sampleCount. failingSamples > 0 ){
388
+ if (sampleCount. failingSamples > 0 ) {
358
389
return State . FAILED
359
- }
360
- else if (sampleCount. passingSamples == sampleCount. totalSampleCount) {
390
+ } else if (sampleCount. passingSamples == sampleCount. totalSampleCount) {
361
391
return State . COMPLETED
362
- }
363
- else if (sampleCount. passingSamples < sampleCount. totalSampleCount) {
392
+ } else if (sampleCount. passingSamples < sampleCount. totalSampleCount) {
364
393
return State . IN_PROGRESS
365
- }
366
- else {
394
+ } else {
367
395
// unexpected!!
368
396
throw new IllegalStateException (" status count $sampleCount . passingSamples must not be greater total count $sampleCount . totalSampleCount " )
369
397
}
0 commit comments