@@ -10,7 +10,6 @@ import com.vaadin.server.StreamResource
10
10
import com.vaadin.shared.data.sort.SortDirection
11
11
import com.vaadin.shared.ui.ContentMode
12
12
import com.vaadin.shared.ui.grid.HeightMode
13
- import com.vaadin.ui.Alignment
14
13
import com.vaadin.ui.Component
15
14
import com.vaadin.ui.Grid
16
15
import com.vaadin.ui.TextField
@@ -20,6 +19,7 @@ import groovy.util.logging.Log4j2
20
19
import life.qbic.business.project.subscribe.Subscriber
21
20
import life.qbic.portal.sampletracking.Constants
22
21
import life.qbic.portal.sampletracking.communication.notification.NotificationService
22
+ import life.qbic.portal.sampletracking.components.Responsive
23
23
import life.qbic.portal.sampletracking.components.ViewModel
24
24
import life.qbic.portal.sampletracking.components.projectoverview.download.DownloadProjectController
25
25
import life.qbic.portal.sampletracking.components.projectoverview.statusdisplay.SampleCount
@@ -30,7 +30,7 @@ import life.qbic.portal.sampletracking.components.projectoverview.subscribe.Subs
30
30
import java.util.function.Consumer
31
31
32
32
@Log4j2
33
- class ProjectView extends ProjectDesign {
33
+ class ProjectView extends ProjectDesign implements Responsive {
34
34
35
35
private final ViewModel viewModel
36
36
private final DownloadProjectController downloadProjectController
@@ -45,13 +45,18 @@ class ProjectView extends ProjectDesign {
45
45
this . subscriptionCheckboxFactory = new SubscriptionCheckboxFactory (subscribeProjectController, subscriber, notificationService)
46
46
this . downloadProjectController = downloadProjectController
47
47
this . notificationService = notificationService
48
+ init()
49
+ }
50
+
51
+ private void init (){
48
52
bindData()
49
53
addClickListener()
50
54
setupDownloadButton()
51
55
bindManifestToProjectSelection()
52
- makeProjectLayoutResponsive()
53
- makeProjectGridResponsive(projectGrid)
54
- setProjectGridStyles(projectGrid)
56
+ setupLayoutResponsiveness()
57
+ setProjectGridStyles()
58
+ disableResizableColumns()
59
+ enableDynamicResizing()
55
60
addSorting()
56
61
enableUserProjectFiltering()
57
62
}
@@ -84,12 +89,7 @@ class ProjectView extends ProjectDesign {
84
89
85
90
refreshDataProvider()
86
91
// specify size of grid and layout
87
- projectGrid. getColumn(" ProjectTitle" ). setExpandRatio(5 )
88
- projectGrid. getColumn(" SamplesReceived" ). setExpandRatio(1 )
89
- projectGrid. getColumn(" SamplesPassedQc" ). setExpandRatio(1 )
90
- projectGrid. getColumn(" LibraryPrepFinished" ). setExpandRatio(1 )
91
- projectGrid. getColumn(" SampleDataAvailable" ). setExpandRatio(1 )
92
-
92
+ projectGrid. setWidthFull()
93
93
projectGrid. setHeightMode(HeightMode . ROW )
94
94
95
95
// remove manual sorting - any sorting in the code should probably done before disabling it
@@ -98,81 +98,42 @@ class ProjectView extends ProjectDesign {
98
98
}
99
99
}
100
100
101
- private void setProjectGridStyles (Grid projectGrid ) {
102
- setHeaderRowStyle(projectGrid . getDefaultHeaderRow() )
103
- addTooltips(projectGrid . getDefaultHeaderRow() )
104
- setColumnsStyle(projectGrid )
101
+ private void setProjectGridStyles () {
102
+ setHeaderRowStyle()
103
+ addTooltips()
104
+ setColumnsStyle()
105
105
}
106
106
107
- private void makeProjectLayoutResponsive () {
108
- // The layout has to be set responsive for the media breakpoints to function
109
- this . addStyleName(" responsive-project-layout" )
110
- this . setResponsive(true )
111
- }
112
-
113
- private static void addTooltips (HeaderRow headerRow ) {
107
+ private void addTooltips () {
108
+ HeaderRow headerRow = projectGrid. getDefaultHeaderRow()
114
109
headerRow. getCell(" Subscription" ). setDescription(" Select a project to get status updates per email." )
115
110
headerRow. getCell(" SamplesReceived" ). setDescription(" Number of samples that arrived in the processing facility." )
116
111
headerRow. getCell(" SamplesPassedQc" ). setDescription(" Number of samples that passed quality control." )
117
112
headerRow. getCell(" LibraryPrepFinished" ). setDescription(" Number of samples where library prep has been finished." )
118
113
headerRow. getCell(" SampleDataAvailable" ). setDescription(" Number of available raw datasets." )
119
114
}
120
115
121
- private static void setHeaderRowStyle (HeaderRow headerRow ) {
122
- headerRow. getCell(" Subscription" ). setStyleName(" project-cell-min-width header-with-tooltip" )
123
- headerRow. getCell(" SamplesReceived" ). setStyleName(" project-cell-min-width header-with-tooltip" )
124
- headerRow. getCell(" SamplesPassedQc" ). setStyleName(" project-cell-min-width header-with-tooltip" )
125
- headerRow. getCell(" LibraryPrepFinished" ). setStyleName(" project-cell-min-width header-with-tooltip" )
126
- headerRow. getCell(" SampleDataAvailable" ). setStyleName(" project-cell-min-width header-with-tooltip" )
127
- headerRow. getCell(" ProjectTitle" ). setStyleName(" project-cell-min-width project-title-cell" )
128
- headerRow. getCell(" ProjectCode" ). setStyleName(" project-cell-min-width" )
116
+ private void setHeaderRowStyle () {
117
+ HeaderRow headerRow = projectGrid. getDefaultHeaderRow()
118
+ headerRow. getCell(" Subscription" ). setStyleName(" cell-min-width header-with-tooltip" )
119
+ headerRow. getCell(" SamplesReceived" ). setStyleName(" cell-min-width header-with-tooltip" )
120
+ headerRow. getCell(" SamplesPassedQc" ). setStyleName(" cell-min-width header-with-tooltip" )
121
+ headerRow. getCell(" LibraryPrepFinished" ). setStyleName(" cell-min-width header-with-tooltip" )
122
+ headerRow. getCell(" SampleDataAvailable" ). setStyleName(" cell-min-width header-with-tooltip" )
123
+ headerRow. getCell(" ProjectTitle" ). setStyleName(" cell-min-width cell-max-width" )
124
+ headerRow. getCell(" ProjectCode" ). setStyleName(" cell-min-width" )
129
125
headerRow. getCell(" Subscription" ). setStyleName(" subscription-cell" )
130
126
}
131
127
132
- private void setColumnsStyle (Grid projectGrid ) {
133
- setComponentAlignment(projectGrid, Alignment . TOP_LEFT )
134
- projectGrid. setWidthFull()
128
+ private void setColumnsStyle () {
135
129
projectGrid. getColumn(" ProjectTitle" ). setStyleGenerator(projectTitleColumn -> {
136
- return " project- cell-min-width project-title-cell "
130
+ return " cell-min-width cell-max-width "
137
131
})
138
132
projectGrid. getColumn(" Subscription" ). setStyleGenerator(projectTitleColumn -> {
139
133
return " subscription-cell"
140
134
})
141
135
}
142
136
143
- private void makeProjectGridResponsive (Grid projectGrid ) {
144
- /*
145
- Defines the lower end on how small columns can be resized manually.
146
- Necessary to avoid overlapping the project/samples button with the download manifest button
147
- */
148
- int browserWindowWidth = 0
149
- int maximumGridWidth = 0
150
- // add padding width for left and right side of grid
151
- final int gridPaddingWidth = 74
152
- addAttachListener(attachedEvent -> {
153
- browserWindowWidth = super . getUI(). getPage(). getBrowserWindowWidth()
154
- maximumGridWidth = browserWindowWidth - gridPaddingWidth
155
- })
156
-
157
- // The grid width should adjust to the resizing preferences of the user
158
- projectGrid. addColumnResizeListener(columnListener -> {
159
-
160
- double columnsWidth = 0
161
- projectGrid. getColumns(). each { column ->
162
- columnsWidth + = column. getWidth()
163
- }
164
- if (columnsWidth <= maximumGridWidth) {
165
- projectGrid. setWidth(Math . floor(columnsWidth). toString())
166
- hotbarLayout. setWidth(Math . floor(columnsWidth). toString())
167
- } else {
168
- // If projectGrid width is bigger than screen adjust grid to max screen size
169
- this . setWidth(maximumGridWidth. toString())
170
- projectGrid. setWidth(maximumGridWidth. toString())
171
- hotbarLayout. setWidth(maximumGridWidth. toString())
172
- }
173
- })
174
- }
175
-
176
137
private void addSorting (){
177
138
sort. setItems([" Newest Changes" , " Oldest Changes" , " Subscribed" , " Not Subscribed" ])
178
139
@@ -338,7 +299,7 @@ class ProjectView extends ProjectDesign {
338
299
})
339
300
}
340
301
341
- void enableUserProjectFiltering () {
302
+ private void enableUserProjectFiltering () {
342
303
TextField searchField = this . searchField
343
304
searchField. addValueChangeListener({
344
305
if (it. getValue()) {
@@ -354,4 +315,52 @@ class ProjectView extends ProjectDesign {
354
315
DataProvider<ProjectSummary , ?> dataProvider = this . projectGrid. getDataProvider()
355
316
return dataProvider
356
317
}
318
+
319
+ /**
320
+ * Adds responsiveness to an abstractComponent
321
+ *
322
+ * <p >This applies the css class style .responsive-grid-layout to the provided abstractComponent allowing it to display it's content in a responsive manner</p>
323
+ *
324
+ * @param AbstractComponent the {@link com.vaadin.ui.AbstractComponent}, where the css style and responsiveness should be added
325
+ * @since 1.0.2
326
+ */
327
+ private void setupLayoutResponsiveness () {
328
+ this . addStyleName(" responsive-grid-layout" )
329
+ this . setWidthFull()
330
+ }
331
+
332
+ @Override
333
+ void enableResizableColumns () {
334
+ projectGrid. getColumns(). each { it ->
335
+ {
336
+ it. setResizable(true )
337
+ }
338
+ }
339
+ }
340
+
341
+ @Override
342
+ void disableResizableColumns () {
343
+ projectGrid. getColumns(). each { it ->
344
+ {
345
+ it. setResizable(false )
346
+ }
347
+ }
348
+ }
349
+
350
+ @Override
351
+ void enableDynamicResizing () {
352
+ projectGrid. addAttachListener(attachEvent -> {
353
+ projectGrid. getUI(). getCurrent(). getPage(). addBrowserWindowResizeListener(resizeEvent -> {
354
+ projectGrid. recalculateColumnWidths()
355
+ })
356
+ })
357
+ }
358
+
359
+ @Override
360
+ void disableDynamicResizing () {
361
+ Collection<AttachListener > attachListeners = projectGrid. getListeners(AttachListener ) as Collection<AttachListener >
362
+ attachListeners. each {attachListener -> {
363
+ projectGrid. removeAttachListener(attachListener)
364
+ }}
365
+ }
357
366
}
0 commit comments