Project

General

Profile

Download (21.1 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.view.registration;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.UUID;
15

    
16
import org.springframework.security.core.GrantedAuthority;
17
import org.vaadin.viritin.fields.LazyComboBox;
18

    
19
import com.vaadin.navigator.View;
20
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
21
import com.vaadin.server.FontAwesome;
22
import com.vaadin.server.GenericFontIcon;
23
import com.vaadin.server.Page;
24
import com.vaadin.spring.annotation.SpringView;
25
import com.vaadin.ui.AbstractLayout;
26
import com.vaadin.ui.Alignment;
27
import com.vaadin.ui.Button;
28
import com.vaadin.ui.Component;
29
import com.vaadin.ui.CssLayout;
30
import com.vaadin.ui.GridLayout;
31
import com.vaadin.ui.HorizontalLayout;
32
import com.vaadin.ui.Label;
33
import com.vaadin.ui.Notification;
34
import com.vaadin.ui.Panel;
35
import com.vaadin.ui.TabSheet;
36
import com.vaadin.ui.TabSheet.Tab;
37
import com.vaadin.ui.UI;
38
import com.vaadin.ui.VerticalLayout;
39
import com.vaadin.ui.Window;
40
import com.vaadin.ui.themes.ValoTheme;
41

    
42
import eu.etaxonomy.cdm.model.name.TaxonName;
43
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
44
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
45
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.TypeDesignationWorkingSetButton;
46
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStateLabel;
47
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
48
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
49
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
50
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
51
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
52
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
53
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
54
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
55
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
56
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
57
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
58
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
59
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
60
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
61
import eu.etaxonomy.cdm.vaadin.util.converter.TypeDesignationSetManager.TypeDesignationWorkingSetType;
62
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
63

    
64
/**
65
 * @author a.kohlbecker
66
 * @since Mar 2, 2017
67
 *
68
 */
69
@SpringView(name=RegistrationWorkflowViewBean.NAME)
70
public class RegistrationWorkflowViewBean extends AbstractPageView<RegistrationWorkflowPresenter>
71
    implements RegistrationWorkflowView, View, AccessRestrictedView {
72

    
73
    public static final String DOM_ID_WORKINGSET = "workingset";
74

    
75
    private static final long serialVersionUID = -213040114015958970L;
76

    
77
    public static final String NAME = "workflow";
78

    
79
    private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
80

    
81
    public RegistrationType regType = null;
82

    
83
    private List<CssLayout> registrations = new ArrayList<>();
84

    
85
    private String headerText = "-- empty --";
86
    private String subheaderText = "";
87

    
88
    private boolean addNameAndTypeEditButtons = false;
89

    
90
    private Integer citationID;
91

    
92
    private Button addNewNameRegistrationButton;
93

    
94
    private LazyComboBox<TaxonName> existingNameCombobox;
95

    
96
    private GridLayout registrationsGrid;
97

    
98
    private Button addExistingNameButton;
99

    
100
    private RegistrationItem workingsetHeader;
101

    
102
    private Panel registrationListPanel;
103

    
104
    public RegistrationWorkflowViewBean() {
105
        super();
106
    }
107

    
108

    
109
    /**
110
     * {@inheritDoc}
111
     */
112
    @Override
113
    protected void initContent() {
114
        getLayout().setId(NAME);
115
        // all content is added in createRegistrationsList()
116
    }
117

    
118

    
119
    /**
120
     * {@inheritDoc}
121
     */
122
    @Override
123
    public void enter(ViewChangeEvent event) {
124
        if(event.getParameters() != null){
125
            this.citationID = Integer.valueOf(event.getParameters());
126

    
127
            getPresenter().handleViewEntered();
128
        }
129
    }
130

    
131
    /**
132
     * {@inheritDoc}
133
     */
134
    @Override
135
    public void setWorkingset(RegistrationWorkingSet workingset) {
136
        if(workingsetHeader != null){
137
            getLayout().removeComponent(workingsetHeader);
138
            getLayout().removeComponent(registrationListPanel);
139
        }
140

    
141
        registrationListPanel = createRegistrationsList(workingset);
142
        registrationListPanel.setStyleName("registration-list");
143
        registrationListPanel.setCaption("Registrations");
144

    
145
        workingsetHeader = new RegistrationItem(workingset, this);
146
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
147
            workingsetHeader.getSubmitterLabel().setVisible(true);
148
        }
149
        addContentComponent(workingsetHeader, null);
150
        addContentComponent(registrationListPanel, 1.0f);
151

    
152
    }
153

    
154
    /**
155
     * {@inheritDoc}
156
     */
157
    @Override
158
    public void addBlockingRegistration(RegistrationDTO blocking) {
159
        if(registrations == null) {
160
            throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
161
        }
162
        // add the blocking registration
163

    
164
    }
165

    
166
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
167

    
168
        if(namesTypesPanel == null){
169
            namesTypesPanel = new CssLayout();
170
        }
171
        Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
172
        Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
173
        Component releaseComponent = new CssLayout(); // new Label("Not yet published")
174

    
175
        GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
176
        TabSheet tabsheet = new TabSheet();
177
        // tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
178
        //tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
179
        tabsheet.addStyleName("workflow-tabsheet");
180

    
181
        Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
182
        Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
183
        Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
184
        Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
185

    
186
        pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
187
        namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
188
        curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
189
        awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
190

    
191
        return tabsheet;
192
    }
193

    
194
    /**
195
     * @param workingset
196
     * @return
197
     */
198
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
199

    
200
        registrationsGrid = new GridLayout(3, 1);
201
        registrationsGrid.setWidth("100%");
202
        // allow vertical scrolling:
203
        registrationsGrid.setHeightUndefined();
204

    
205
        //registrationsGrid.setColumnExpandRatio(0, 0.1f);
206
        registrationsGrid.setColumnExpandRatio(1, 1f);
207

    
208
        int row = 0;
209
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
210
            putRegistrationListComponent(registrationsGrid, row++, dto);
211
        }
212

    
213
        Label addRegistrationLabel_1 = new Label("Add a new registration for a");
214
        Label addRegistrationLabel_2 = new Label("or an");
215

    
216
        addNewNameRegistrationButton = new Button("new name");
217
        addNewNameRegistrationButton.setDescription("A name which is newly published in this publication.");
218
        addNewNameRegistrationButton.addClickListener(
219
                e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.ADD, addNewNameRegistrationButton))
220
                );
221

    
222
        addExistingNameButton = new Button("existing name:");
223
        addExistingNameButton.setDescription("A name which was previously published in a earlier publication.");
224
        addExistingNameButton.setEnabled(false);
225
        addExistingNameButton.addClickListener(
226
                e -> eventBus.publishEvent(new RegistrationWorkflowEvent(citationID, RegistrationWorkflowEvent.Action.start))
227
                );
228

    
229
        existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
230
        existingNameCombobox.addValueChangeListener(
231
                e -> addExistingNameButton.setEnabled(e.getProperty().getValue() != null)
232
                );
233

    
234
        HorizontalLayout buttonContainer = new HorizontalLayout(addRegistrationLabel_1, addNewNameRegistrationButton, addRegistrationLabel_2, addExistingNameButton, existingNameCombobox);
235
        buttonContainer.setSpacing(true);
236
//        buttonContainer.setWidth(100, Unit.PERCENTAGE);
237
        buttonContainer.setComponentAlignment(addRegistrationLabel_1, Alignment.MIDDLE_LEFT);
238
        buttonContainer.setComponentAlignment(addRegistrationLabel_2, Alignment.MIDDLE_LEFT);
239
        registrationsGrid.addComponent(buttonContainer, 0, row, 2, row);
240
        registrationsGrid.setComponentAlignment(buttonContainer, Alignment.MIDDLE_RIGHT);
241

    
242
        Panel namesTypesPanel = new Panel(registrationsGrid);
243
        namesTypesPanel.setSizeFull();
244
        return namesTypesPanel;
245
    }
246

    
247

    
248
    /**
249
     * @param grid
250
     * @param row If null, the new row will be inserted as last registration item, that is before the button row.
251
     * @param dto
252
     */
253
    protected void putRegistrationListComponent(GridLayout grid, int row, RegistrationDTO dto) {
254

    
255
        grid.setRows(grid.getRows() + 1);
256

    
257
        CssLayout buttonGroup = new CssLayout();
258
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
259

    
260
        Button messageButton = new Button(FontAwesome.COMMENT);
261
        messageButton.setStyleName(ValoTheme.BUTTON_TINY); //  + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
262
        if(dto.getMessages().isEmpty()){
263
            messageButton.setEnabled(false);
264
        } else {
265
            messageButton.addClickListener(e -> eventBus.publishEvent(
266
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
267
                        e,
268
                        RegistrationDTO.class,
269
                        dto.getId(),
270
                        "messages"
271
                        )
272
                    )
273
                );
274
        }
275
        messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
276
        messageButton.setCaptionAsHtml(true);
277
        buttonGroup.addComponent(messageButton);
278

    
279
        RegistrationStateLabel stateLabel = new RegistrationStateLabel().update(dto.getStatus());
280

    
281

    
282
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
283
            Button editRegistrationButton = new Button(FontAwesome.COG);
284
            editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
285
            editRegistrationButton.setDescription("Edit registration");
286
            editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
287
                AbstractEditorAction.Action.EDIT,
288
                dto.getId(),
289
                null,
290
                this
291
                )));
292
            buttonGroup.addComponent(editRegistrationButton);
293
        }
294

    
295
        if(addNameAndTypeEditButtons ){
296
            Button editNameButton = new Button(FontAwesome.TAG);
297
            editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
298
            editNameButton.setDescription("Edit name");
299
            if(dto.getName() != null){
300
                editNameButton.addClickListener(e -> {
301
                        Integer nameId = dto.getName().getId();
302
                        getEventBus().publishEvent(new TaxonNameEditorAction(
303
                            AbstractEditorAction.Action.EDIT,
304
                            nameId
305
                            )
306
                        );
307
                    });
308
            } else {
309
                editNameButton.setEnabled(false);
310
            }
311

    
312
            Button editTypesButton = new Button(FontAwesome.LEAF);
313
            editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
314
            editTypesButton.setDescription("Edit type designations");
315
            if(dto.getOrderdTypeDesignationWorkingSets() != null && !dto.getOrderdTypeDesignationWorkingSets().isEmpty()){
316
//                editTypesButton.addClickListener(e -> {
317
//                    int regId = dto.getId();
318
//                        getEventBus().publishEvent(new TypeDesignationSetEditorAction(
319
//                            AbstractEditorAction.Action.EDIT,
320
//                            regId
321
//                            )
322
//                        );
323
//                    });
324
            } else {
325
                editTypesButton.setEnabled(false);
326
            }
327
            buttonGroup.addComponents(editNameButton, editTypesButton);
328
        }
329

    
330
        Component regItem;
331
        if(REG_ITEM_AS_BUTTON_GROUP){
332
            RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
333

    
334
            if(editButtonGroup.getNameButton() != null){
335
                editButtonGroup.getNameButton().getButton().addClickListener(e -> {
336
                    Integer nameId = editButtonGroup.getNameButton().getId();
337
                    getEventBus().publishEvent(new TaxonNameEditorAction(
338
                        AbstractEditorAction.Action.EDIT,
339
                        nameId,
340
                        null, //e.getButton(), the listener method expects this to be null
341
                        this
342
                        )
343
                    );
344
                });
345
            }
346

    
347
            for(TypeDesignationWorkingSetButton workingsetButton : editButtonGroup.getTypeDesignationButtons()){
348
                workingsetButton.getButton().addClickListener(e -> {
349
                    Integer typeDesignationWorkingsetId = workingsetButton.getId();
350
                    TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
351
                    Integer registrationEntityID = dto.getId();
352
                    getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
353
                            AbstractEditorAction.Action.EDIT,
354
                            typeDesignationWorkingsetId,
355
                            workingsetType,
356
                            registrationEntityID,
357
                            null, //e.getButton(), the listener method expects this to be null
358
                            this
359
                            )
360
                        );
361
                });
362
            }
363

    
364
            editButtonGroup.getAddTypeDesignationButton().addClickListener(
365
                    e -> chooseNewTypeRegistrationWorkingset(dto.getId())
366
                    );
367
            regItem = editButtonGroup;
368
        } else {
369
            regItem = new Label(dto.getSummary());
370
        }
371

    
372
        grid.addComponent(stateLabel, 0, row);
373
        grid.setComponentAlignment(stateLabel, Alignment.TOP_LEFT);
374
        grid.addComponent(regItem, 1, row);
375
        grid.addComponent(buttonGroup, 2, row);
376
        grid.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
377
    }
378

    
379
    /**
380
     * @param button
381
     * @param registrationEntityId
382
     *
383
     */
384
    @Override
385
    public void chooseNewTypeRegistrationWorkingset(Integer registrationEntityId) {
386

    
387
        Window typeDesignationTypeCooser = new Window();
388
        typeDesignationTypeCooser.setModal(true);
389
        typeDesignationTypeCooser.setResizable(false);
390
        typeDesignationTypeCooser.setCaption("Add new type designation");
391
        Label label = new Label("Please select kind of type designation to be created.");
392
        Button newSpecimenTypeDesignationButton = new Button("Specimen type designation",
393
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
394
        Button newNameTypeDesignationButton = new Button("Name type designation",
395
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
396
        newNameTypeDesignationButton.setEnabled(false);
397

    
398
        VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
399
        layout.setMargin(true);
400
        layout.setSpacing(true);
401
        layout.setComponentAlignment(newSpecimenTypeDesignationButton, Alignment.MIDDLE_CENTER);
402
        layout.setComponentAlignment(newNameTypeDesignationButton, Alignment.MIDDLE_CENTER);
403
        typeDesignationTypeCooser.setContent(layout);
404
        UI.getCurrent().addWindow(typeDesignationTypeCooser);
405
    }
406

    
407
    /**
408
     * @param button
409
     *
410
     */
411
    protected void addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType newWorkingsetType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
412
        UI.getCurrent().removeWindow(typeDesignationTypeCooser);
413
        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
414
                AbstractEditorAction.Action.ADD,
415
                newWorkingsetType,
416
                registrationEntityId,
417
                null,
418
                this
419
                ));
420
    }
421

    
422

    
423
    /**
424
    *
425
    */
426
   private void addBulletWorkflowName() {
427
       WorkflowSteps steps = new WorkflowSteps();
428
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
429
               e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
430
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
431
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
432
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
433
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
434
       getWorkflow().addComponent(steps);
435
   }
436

    
437
   /**
438
   *
439
   */
440
  private void addBulletWorkflowTypification() {
441
      WorkflowSteps steps = new WorkflowSteps();
442
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
443
              e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
444
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
445
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
446
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
447
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
448
      getWorkflow().addComponent(steps);
449
  }
450

    
451
    /**
452
     * {@inheritDoc}
453
     */
454
    @Override
455
    public void openReferenceEditor(UUID referenceUuid) {
456
        // TODO Auto-generated method stub
457

    
458
    }
459

    
460
    /**
461
     * {@inheritDoc}
462
     */
463
    @Override
464
    public void openNameEditor(UUID nameUuid) {
465
        // TODO Auto-generated method stub
466

    
467
    }
468

    
469
    /**
470
     * {@inheritDoc}
471
     */
472
    @Override
473
    protected String getHeaderText() {
474
        return headerText;
475
    }
476

    
477
    /**
478
     * {@inheritDoc}
479
     */
480
    @Override
481
    public void setHeaderText(String text) {
482
        this.headerText = text;
483
        updateHeader();
484

    
485
    }
486

    
487
    /**
488
     * @return the subheaderText
489
     */
490
    public String getSubheaderText() {
491
        return subheaderText;
492
    }
493

    
494
    /**
495
     * {@inheritDoc}
496
     */
497
    @Override
498
    public void setSubheaderText(String text) {
499
        subheaderText = text;
500
        updateHeader();
501
    }
502

    
503
    /**
504
     * {@inheritDoc}
505
     */
506
    @Override
507
    protected String getSubHeaderText() {
508
        return subheaderText;
509
    }
510

    
511
    /**
512
     * {@inheritDoc}
513
     */
514
    @Override
515
    public AbstractLayout getWorkflow() {
516
        return getLayout();
517
    }
518

    
519
    /**
520
     * {@inheritDoc}
521
     */
522
    @Override
523
    public void openDetailsPopup(String caption, List<String> messages) {
524
        StringBuffer sb = new StringBuffer();
525
        sb.append("<div class=\"details-popup-content\">");
526
        messages.forEach(s -> sb.append(s).append("</br>"));
527
        sb.append("</div>");
528
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
529
    }
530

    
531
    /**
532
     * {@inheritDoc}
533
     */
534
    @Override
535
    public boolean allowAnonymousAccess() {
536
        return false;
537
    }
538

    
539
    /**
540
     * {@inheritDoc}
541
     */
542
    @Override
543
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
544
        return null;
545
    }
546

    
547
    /**
548
     * @return the addNewNameRegistrationButton
549
     */
550
    @Override
551
    public Button getAddNewNameRegistrationButton() {
552
        return addNewNameRegistrationButton;
553
    }
554

    
555
    @Override
556
    public Button getAddExistingNameRegistrationButton() {
557
        return addExistingNameButton;
558
    }
559

    
560
    @Override
561
    public LazyComboBox<TaxonName> getAddExistingNameCombobox() {
562
        return existingNameCombobox;
563
    }
564

    
565
    /**
566
     * @return the citationID
567
     */
568
    @Override
569
    public Integer getCitationID() {
570
        return citationID;
571
    }
572

    
573

    
574
}
(14-14/19)