Project

General

Profile

Revision 725d1ff2

ID725d1ff22626d3b584606a29756c4be7c750aca1
Parent bfc37f02
Child 9361ce64

Added by Andreas Kohlbecker almost 2 years ago

fix #7528 indroducing RegistrationStatusSelect to allow setting the status in the RegistrationWorkingsetEditor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/CdmBeanItemContainerFactory.java
19 19
import eu.etaxonomy.cdm.api.service.pager.Pager;
20 20
import eu.etaxonomy.cdm.model.common.CdmBase;
21 21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22
import eu.etaxonomy.cdm.model.common.IEnumTerm;
22 23
import eu.etaxonomy.cdm.model.common.TermType;
23 24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24 25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
......
112 113
        return buildBeanItemContainer(type, null);
113 114
    }
114 115

  
116
    /**
117
     * @param values
118
     * @return
119
     */
120
    public <T extends IEnumTerm<T>> BeanItemContainer<T> buildBeanItemContainer(Class<T> termType, T ... enumTerms) {
121
        BeanItemContainer<T> termItemContainer = new BeanItemContainer<>(termType);
122
        List<T> termList = Arrays.asList(enumTerms);
123
        termItemContainer.addAll(termList);
124
        return termItemContainer;
125
    }
126

  
115 127

  
116 128
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationStatusFieldInstantiator.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.component.registration;
10

  
11
import java.io.Serializable;
12

  
13
import com.vaadin.ui.AbstractField;
14

  
15
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
16

  
17
/**
18
 * @author a.kohlbecker
19
 * @since Jul 4, 2018
20
 *
21
 */
22
public interface RegistrationStatusFieldInstantiator<T> extends Serializable {
23

  
24
    public AbstractField<T> create(RegistrationDTO regDto);
25

  
26
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationStatusSelect.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.component.registration;
10

  
11
import java.util.Collection;
12

  
13
import com.vaadin.data.Container;
14
import com.vaadin.ui.ListSelect;
15

  
16
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since Jul 4, 2018
21
 *
22
 */
23
public class RegistrationStatusSelect extends ListSelect {
24

  
25

  
26
    private static final long serialVersionUID = 2400974680207121417L;
27

  
28
    Object previousValue = null;
29

  
30
    public RegistrationStatusSelect(){
31
        super();
32
        init();
33
    }
34

  
35
    /**
36
     * @param caption
37
     * @param options
38
     */
39
    public RegistrationStatusSelect(String caption, Collection<?> options) {
40
        super(caption, options);
41
        init();
42
    }
43

  
44
    /**
45
     * @param caption
46
     * @param dataSource
47
     */
48
    public RegistrationStatusSelect(String caption, Container dataSource) {
49
        super(caption, dataSource);
50
        init();
51
    }
52

  
53
    /**
54
     * @param caption
55
     */
56
    public RegistrationStatusSelect(String caption) {
57
        super(caption);
58
        init();
59
    }
60

  
61
    /**
62
     *
63
     */
64
    public void init() {
65
        addStyleName("registration-status");
66
        setRows(1);
67
        setWidth("110px");
68

  
69
        addValueChangeListener(e -> updateStyles());
70
    }
71

  
72

  
73
    /**
74
     * @param newValue
75
     * @param previousValue
76
     */
77
    public void updateStyles() {
78
        Object newValue = getValue();
79
        String styles = getStyleName();
80
        if(previousValue != null){
81
            styles = styles.replace("registration-status-" + ((RegistrationStatus)previousValue).name(), "");
82
        }
83
        if(newValue != null){
84
            setStyleName(styles + " registration-status-" + ((RegistrationStatus)newValue).name());
85
        }
86
        previousValue = newValue;
87
    }
88

  
89
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
11 11
import java.util.ArrayList;
12 12
import java.util.Arrays;
13 13
import java.util.EnumSet;
14
import java.util.HashSet;
14 15
import java.util.List;
16
import java.util.Objects;
15 17
import java.util.Set;
16 18
import java.util.Stack;
17 19
import java.util.UUID;
......
26 28
import com.vaadin.server.SystemError;
27 29
import com.vaadin.spring.annotation.SpringComponent;
28 30
import com.vaadin.spring.annotation.ViewScope;
31
import com.vaadin.ui.AbstractField;
29 32
import com.vaadin.ui.Button;
30 33
import com.vaadin.ui.Label;
31 34
import com.vaadin.ui.UI;
......
34 37

  
35 38
import eu.etaxonomy.cdm.api.service.INameService;
36 39
import eu.etaxonomy.cdm.api.service.IRegistrationService;
40
import eu.etaxonomy.cdm.api.service.config.RegistrationStatusTransitions;
37 41
import eu.etaxonomy.cdm.api.service.dto.EntityReference;
38 42
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
39 43
import eu.etaxonomy.cdm.api.service.dto.TypedEntityReference;
......
59 63
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
60 64
import eu.etaxonomy.cdm.service.CdmStore;
61 65
import eu.etaxonomy.cdm.service.IRegistrationWorkingSetService;
66
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
62 67
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
68
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStatusFieldInstantiator;
69
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStatusSelect;
63 70
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
64 71
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
65 72
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
......
209 216
    @Override
210 217
    public void handleViewEntered() {
211 218
        super.handleViewEntered();
219
        // TODO currently cannot specify type more precisely, see AbstractSelect
220
        // FIXME externalize into class file!!!!!!!!!!!!
221
        getView().setStatusComponentInstantiator(new RegistrationStatusFieldInstantiator<Object>(){
222

  
223
            private static final long serialVersionUID = 7099181280977511048L;
224

  
225
            @Override
226
            public AbstractField<Object> create(RegistrationDTO regDto) {
227

  
228
                CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
229
                // submitters have GrantedAuthorities like REGISTRATION(PREPARATION).[UPDATE]{ab4459eb-3b96-40ba-bfaa-36915107d59e}
230
                UserHelper userHelper = UserHelper.fromSession();
231
                Set<RegistrationStatus> availableStatus = new HashSet<>();
232

  
233
                boolean canChangeStatus = userHelper.userHasPermission(regDto.registration(), CRUD.UPDATE);
234
                availableStatus.add(regDto.getStatus());
235
                if(canChangeStatus){
236
                    if(userHelper.userIsAdmin()){
237
                        availableStatus.addAll(Arrays.asList(RegistrationStatus.values()));
238
                    } else {
239
                        availableStatus.addAll(RegistrationStatusTransitions.possibleTransitions(regDto.getStatus()));
240
                    }
241
                }
242

  
243
                RegistrationStatusSelect select = new RegistrationStatusSelect(null, selectFieldFactory.buildBeanItemContainer(
244
                        RegistrationStatus.class,
245
                        availableStatus.toArray(new RegistrationStatus[availableStatus.size()]))
246
                        );
247
                select.addValueChangeListener(e -> saveRegistrationStatusChange(regDto.getUuid(), e.getProperty().getValue()));
248
                select.setEnabled(canChangeStatus);
249
                select.setNullSelectionAllowed(false);
250
                return select;
251
            }
252

  
253

  
254
        });
212 255
        loadWorkingSet(getView().getCitationUuid());
213 256
        applyWorkingset();
214 257

  
......
296 339
        }
297 340
    }
298 341

  
342
    private void saveRegistrationStatusChange(UUID uuid, Object value) {
343
        Registration reg = getRepo().getRegistrationService().load(uuid);
344
        if(value != null && value instanceof RegistrationStatus && !Objects.equals(value, reg.getStatus())){
345
            reg.setStatus((RegistrationStatus)value);
346
            getRegistrationStore().saveBean(reg, (AbstractView)getView());
347
            refreshView(true);
348
        } else {
349
            // only log an error here!
350
            logger.error("Ivalid attempt to set RegistrationStatus to " + Objects.toString(value.toString(), "NULL"));
351
        }
352
    }
353

  
299 354

  
300 355
    @EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
301 356
    public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetView.java
19 19

  
20 20
import eu.etaxonomy.cdm.api.service.dto.RegistrationDTO;
21 21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStatusFieldInstantiator;
22 23
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
23 24
import eu.etaxonomy.vaadin.mvp.ApplicationView;
24 25

  
......
106 107
     */
107 108
    Map<UUID, RegistrationDetailsItem> getRegistrationItemMap();
108 109

  
110
    void setStatusComponentInstantiator(RegistrationStatusFieldInstantiator statusComponentInstantiator);
111

  
109 112

  
110 113
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorksetViewBean.java
31 31
import com.vaadin.server.Page;
32 32
import com.vaadin.shared.ui.label.ContentMode;
33 33
import com.vaadin.spring.annotation.SpringView;
34
import com.vaadin.ui.AbstractField;
34 35
import com.vaadin.ui.Alignment;
35 36
import com.vaadin.ui.Button;
37
import com.vaadin.ui.Component;
36 38
import com.vaadin.ui.CssLayout;
37 39
import com.vaadin.ui.GridLayout;
38 40
import com.vaadin.ui.HorizontalLayout;
......
58 60
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemNameAndTypeButtons;
59 61
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemNameAndTypeButtons.TypeDesignationWorkingSetButton;
60 62
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemsPanel;
63
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStatusFieldInstantiator;
61 64
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStatusLabel;
62 65
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
63 66
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.EditorActionContext;
......
135 138
     */
136 139
    private Map<UUID, EntityReference> typifiedNamesMap = new HashMap<>();
137 140

  
141
    private RegistrationStatusFieldInstantiator statusFieldInstantiator;
142

  
143

  
138 144
    public RegistrationWorksetViewBean() {
139 145
        super();
140 146
    }
......
386 392
                );
387 393
        messageButton.setStyleName(ValoTheme.BUTTON_TINY);
388 394

  
389
        RegistrationStatusLabel stateLabel = new RegistrationStatusLabel().update(dto.getStatus());
395
        Component statusComponent;
396
        if(statusFieldInstantiator != null){
397
            AbstractField<Object> statusField = statusFieldInstantiator.create(dto);
398
            statusField.setValue(dto.getStatus());
399
            statusComponent = statusField;
400
        } else {
401
            statusComponent = new RegistrationStatusLabel().update(dto.getStatus());
402
        }
390 403
        Label submitterLabel = new Label(dto.getSubmitterUserName());
391 404
        submitterLabel.setStyleName(LABEL_NOWRAP + " submitter");
392 405
        submitterLabel.setIcon(FontAwesome.USER);
393 406
        submitterLabel.setContentMode(ContentMode.HTML);
394
        CssLayout stateAndSubmitter = new CssLayout(stateLabel, submitterLabel);
407
        CssLayout stateAndSubmitter = new CssLayout(statusComponent, submitterLabel);
395 408

  
396 409

  
397 410
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
......
588 601
    }
589 602

  
590 603

  
604
    /**
605
     * @param statusFieldInstantiator the statusFieldInstantiator to set
606
     */
607
    @Override
608
    public void setStatusComponentInstantiator(RegistrationStatusFieldInstantiator statusComponentInstantiator) {
609
        this.statusFieldInstantiator = statusComponentInstantiator;
610
    }
611

  
612

  
591 613
}
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss
74 74
}
75 75

  
76 76
// ========================================== //
77
// Status colors for the redistration
77
// Status colors for the registration
78 78
// 
79 79
// change-color cant be used since this is not fully supported by the vaadin sass-compiler
80 80
// see https://github.com/vaadin/sass-compiler/issues/147
......
88 88
$status-ready-color: adjust-color($plain-red, $hue: 180deg);
89 89
// ========================================== //
90 90

  
91
@mixin registration-status-colors($sub-selector: '') {
92
    .registration-status-REJECTED #{$sub-selector} {
93
        color: $status-rejected-color;
94
    }
95
    .registration-status-CURATION #{$sub-selector} {
96
        color: $status-curation-color;
97
    }
98
    .registration-status-PREPARATION #{$sub-selector} {
99
        color: $status-preparation-color;
100
    }
101
    .registration-status-PUBLISHED #{$sub-selector} {
102
        color: $status-published-color;
103
    }
104
    .registration-status-READY #{$sub-selector} {
105
        color: $status-ready-color;
106
    }
107
}
108

  
109
@mixin registration-status-bg-colors($sub-selector: '') {
110
    .bg-status-REJECTED #{$sub-selector} {
111
        background-color: $status-rejected-color;
112
    }
113
    .bg-status-CURATION #{$sub-selector} {
114
        background-color: $status-curation-color;
115
    }
116
    .bg-status-PREPARATION #{$sub-selector}  {
117
        background-color: $status-preparation-color;
118
    }
119
    .bg-status-PUBLISHED #{$sub-selector} {
120
        background-color: $status-published-color;
121
    }
122
    .bg-status-READY #{$sub-selector} {
123
        background-color: $status-ready-color;
124
    }
125
}
126

  
127

  
91 128

  
92 129
@mixin edit-valo {
93 130
  @include valo;
......
361 398
        display: block;
362 399
    }
363 400
    
364
   // status colors --------------------------------- //
365
    .registration-status-REJECTED {
366
        color: $status-rejected-color;
367
    }
368
    .registration-status-CURATION {
369
        color: $status-curation-color;
370
    }
371
    .registration-status-PREPARATION {
372
        color: $status-preparation-color;
373
    }
374
    .registration-status-PUBLISHED {
375
        color: $status-published-color;
376
    }
377
    .registration-status-READY {
378
        color: $status-ready-color;
379
    }
380

  
381
    .bg-status-REJECTED {
382
        background-color: $status-rejected-color;
383
    }
384
    .bg-status-CURATION {
385
        background-color: $status-curation-color;
386
    }
387
    .bg-status-PREPARATION {
388
        background-color: $status-preparation-color;
389
    }
390
    .bg-status-PUBLISHED {
391
        background-color: $status-published-color;
392
    }
393
    .bg-status-READY {
394
        background-color: $status-ready-color;
395
    }
401
   @include registration-status-colors();
402
   @include registration-status-bg-colors(); // TODO still needed?
403
   @include registration-status-colors(.v-select-select);
404
   
396 405
    // ----------------------------------------------- //
397 406
    
398 407
    #registration-list {
......
405 414
        border: valo-border($border: $v-border, $color: $v-background-color, $strength: 1.4);
406 415
        border-radius: $v-border-radius - first-number($v-border) $v-border-radius - first-number($v-border) 0 0;
407 416
        /* ----------------------------------------------- */
408
        
417
        // TODO can the mixin registration-status-colors() be used here?
409 418
        // for grid rows
410 419
        .status-REJECTED {
411 420
            color: $status-rejected-color;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)