Project

General

Profile

Download (19.3 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

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

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

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

    
69

    
70
    public static final String DOM_ID_WORKFLOW = "workflow-container";
71

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

    
74
    public static final String SUBHEADER_DEEFAULT = "Advance step by step through the registration workflow.";
75

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

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

    
80
    public static final String ACTION_NEW = "new";
81

    
82
    public static final String ACTION_EDIT = "edit";
83

    
84
    private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
85

    
86
    public RegistrationType regType = null;
87

    
88
    private CssLayout workflow;
89

    
90
    private List<CssLayout> registrations = new ArrayList<>();
91

    
92
    private String headerText = "-- empty --";
93
    private String subheaderText = SUBHEADER_DEEFAULT;
94

    
95
    private boolean addNameAndTypeEditButtons = false;
96

    
97

    
98
    public RegistrationWorkflowViewBean() {
99
        super();
100
    }
101

    
102
    @Override
103
    protected void initContent() {
104
        workflow = new CssLayout();
105
        workflow.setSizeFull();
106
        workflow.setId(DOM_ID_WORKFLOW);
107
        getLayout().addComponent(workflow);
108
    }
109

    
110
    /**
111
     * {@inheritDoc}
112
     */
113
    @Override
114
    public void enter(ViewChangeEvent event) {
115
        if(event.getParameters() != null){
116
           String[] params = event.getParameters().split("/");
117

    
118
           if(params[0].equals(ACTION_NEW)) {
119
               regType = RegistrationType.valueOf(params[1]);
120
               headerText = regType.name() + " ...";
121
               eventBus.publishEvent(new RegistrationWorkflowEvent(regType));
122

    
123
           } else if( params[0].equals(ACTION_EDIT)) {
124
               headerText = params[1];
125
               eventBus.publishEvent(new RegistrationWorkflowEvent(Integer.parseInt(params[1])));
126
           }
127
           updateHeader();
128
        }
129
    }
130

    
131
    /**
132
     * {@inheritDoc}
133
     */
134
    @Override
135
    public void setWorkingset(RegistrationWorkingSet workingset) {
136

    
137
        CssLayout registration = new CssLayout();
138
        registration.setId(DOM_ID_WORKINGSET);
139
        registration.setWidth(100, Unit.PERCENTAGE);
140

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

    
145

    
146
        // registration.addComponent(createWorkflowTabSheet(workingset, null));
147
        RegistrationItem registrationItem = new RegistrationItem(workingset, this);
148
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
149
            registrationItem.getSubmitterLabel().setVisible(true);
150
        };
151
        registration.addComponent(registrationItem);
152
        registration.addComponent(registrationListPanel);
153

    
154
        registrations.add(registration);
155
        workflow.removeAllComponents();
156
        workflow.addComponent(registration);
157
    }
158

    
159
    /**
160
     * {@inheritDoc}
161
     */
162
    @Override
163
    public void addBlockingRegistration(RegistrationDTO blocking) {
164
        if(registrations == null) {
165
            throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
166
        }
167
        // add the blocking registration
168

    
169
    }
170

    
171
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
172

    
173
        if(namesTypesPanel == null){
174
            namesTypesPanel = new CssLayout();
175
        }
176
        Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
177
        Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
178
        Component releaseComponent = new CssLayout(); // new Label("Not yet published")
179

    
180
        GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
181
        TabSheet tabsheet = new TabSheet();
182
        // tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
183
        //tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
184
        tabsheet.addStyleName("workflow-tabsheet");
185

    
186
        Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
187
        Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
188
        Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
189
        Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
190

    
191
        pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
192
        namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
193
        curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
194
        awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
195

    
196
        return tabsheet;
197
    }
198

    
199
    /**
200
     * @param workingset
201
     * @return
202
     */
203
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
204
        // prepare name and type list
205
        GridLayout namesTypesList = new GridLayout(3, workingset.getRegistrationDTOs().size());
206
        int row = 0;
207
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
208
            registrationListComponent(namesTypesList, row++, dto);
209
        }
210

    
211
        namesTypesList.setSizeUndefined();
212
        namesTypesList.setWidth(100, Unit.PERCENTAGE);
213
        namesTypesList.setColumnExpandRatio(0, 0.1f);
214
        namesTypesList.setColumnExpandRatio(1, 0.9f);
215
        Panel namesTypesPanel = new Panel(namesTypesList);
216
        namesTypesPanel.setHeight("300px");
217
        return namesTypesPanel;
218
    }
219

    
220
    /**
221
     * @param namesTypesList
222
     * @param row
223
     * @param dto
224
     */
225
    protected void registrationListComponent(GridLayout namesTypesList, int row, RegistrationDTO dto) {
226
        CssLayout buttonGroup = new CssLayout();
227
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
228

    
229
        Button messageButton = new Button(FontAwesome.COMMENT);
230
        messageButton.setStyleName(ValoTheme.BUTTON_TINY); //  + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
231
        if(dto.getMessages().isEmpty()){
232
            messageButton.setEnabled(false);
233
        } else {
234
            messageButton.addClickListener(e -> eventBus.publishEvent(
235
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
236
                        e,
237
                        RegistrationDTO.class,
238
                        dto.getId(),
239
                        "messages"
240
                        )
241
                    )
242
                );
243
        }
244
        messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
245
        messageButton.setCaptionAsHtml(true);
246
        buttonGroup.addComponent(messageButton);
247

    
248
        RegistrationStateLabel stateLabel = new RegistrationStateLabel().update(dto.getStatus());
249

    
250

    
251
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
252
            Button editRegistrationButton = new Button(FontAwesome.COG);
253
            editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
254
            editRegistrationButton.setDescription("Edit registration");
255
            editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
256
                AbstractEditorAction.Action.EDIT,
257
                dto.getId(),
258
                null,
259
                this
260
                )));
261
            buttonGroup.addComponent(editRegistrationButton);
262
        }
263

    
264
        if(addNameAndTypeEditButtons ){
265
            Button editNameButton = new Button(FontAwesome.TAG);
266
            editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
267
            editNameButton.setDescription("Edit name");
268
            if(dto.getName() != null){
269
                editNameButton.addClickListener(e -> {
270
                        Integer nameId = dto.getName().getId();
271
                        getEventBus().publishEvent(new TaxonNameEditorAction(
272
                            AbstractEditorAction.Action.EDIT,
273
                            nameId
274
                            )
275
                        );
276
                    });
277
            } else {
278
                editNameButton.setEnabled(false);
279
            }
280

    
281
            Button editTypesButton = new Button(FontAwesome.LEAF);
282
            editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
283
            editTypesButton.setDescription("Edit type designations");
284
            if(dto.getOrderdTypeDesignationWorkingSets() != null && !dto.getOrderdTypeDesignationWorkingSets().isEmpty()){
285
//                editTypesButton.addClickListener(e -> {
286
//                    int regId = dto.getId();
287
//                        getEventBus().publishEvent(new TypeDesignationSetEditorAction(
288
//                            AbstractEditorAction.Action.EDIT,
289
//                            regId
290
//                            )
291
//                        );
292
//                    });
293
            } else {
294
                editTypesButton.setEnabled(false);
295
            }
296
            buttonGroup.addComponents(editNameButton, editTypesButton);
297
        }
298

    
299
        Component regItem;
300
        if(REG_ITEM_AS_BUTTON_GROUP){
301
            RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
302
            if(editButtonGroup.getNameButton() != null){
303

    
304
                editButtonGroup.getNameButton().getButton().addClickListener(e -> {
305
                    Integer nameId = editButtonGroup.getNameButton().getId();
306
                    getEventBus().publishEvent(new TaxonNameEditorAction(
307
                        AbstractEditorAction.Action.EDIT,
308
                        nameId,
309
                        null, //e.getButton(), the listener method expects this to be null
310
                        this
311
                        )
312
                    );
313
                });
314

    
315
                for(TypeDesignationWorkingSetButton workingsetButton : editButtonGroup.getTypeDesignationButtons()){
316
                    workingsetButton.getButton().addClickListener(e -> {
317
                        Integer typeDesignationWorkingsetId = workingsetButton.getId();
318
                        TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
319
                        Integer registrationEntityID = dto.getId();
320
                        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
321
                                AbstractEditorAction.Action.EDIT,
322
                                typeDesignationWorkingsetId,
323
                                workingsetType,
324
                                registrationEntityID,
325
                                null, //e.getButton(), the listener method expects this to be null
326
                                this
327
                                )
328
                            );
329
                    });
330
                }
331

    
332
                editButtonGroup.getAddTypeDesignationButton().addClickListener(
333
                        e -> chooseNewTypeRegistrationWorkingset(e.getButton(), dto.getId())
334
                        );
335
            }
336
            regItem = editButtonGroup;
337
        } else {
338
            regItem = new Label(dto.getSummary());
339
        }
340

    
341
        namesTypesList.addComponent(stateLabel, 0, row);
342
        namesTypesList.setComponentAlignment(stateLabel, Alignment.TOP_LEFT);
343
        namesTypesList.addComponent(regItem, 1, row);
344
        namesTypesList.addComponent(buttonGroup, 2, row);
345
        namesTypesList.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
346
    }
347

    
348
    /**
349
     * @param button
350
     * @param registrationEntityId
351
     *
352
     */
353
    protected void chooseNewTypeRegistrationWorkingset(Button button, Integer registrationEntityId) {
354

    
355
        Window typeDesignationTypeCooser = new Window();
356
        typeDesignationTypeCooser.setModal(true);
357
        typeDesignationTypeCooser.setResizable(false);
358
        typeDesignationTypeCooser.setCaption("Add new type designation");
359
        Label label = new Label("Please select kind of type designation to be created.");
360
        Button newSpecimenTypeDesignationButton = new Button("Specimen type designation",
361
                e -> addNewTypeRegistrationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
362
        Button newNameTypeDesignationButton = new Button("Name type designation",
363
                e -> addNewTypeRegistrationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
364
        newNameTypeDesignationButton.setEnabled(false);
365

    
366
        VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
367
        layout.setMargin(true);
368
        layout.setSpacing(true);
369
        layout.setComponentAlignment(newSpecimenTypeDesignationButton, Alignment.MIDDLE_CENTER);
370
        layout.setComponentAlignment(newNameTypeDesignationButton, Alignment.MIDDLE_CENTER);
371
        typeDesignationTypeCooser.setContent(layout);
372
        UI.getCurrent().addWindow(typeDesignationTypeCooser);
373
    }
374

    
375
    /**
376
     * @param button
377
     *
378
     */
379
    protected void addNewTypeRegistrationWorkingset(TypeDesignationWorkingSetType newWorkingsetType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
380
        UI.getCurrent().removeWindow(typeDesignationTypeCooser);
381
        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
382
                AbstractEditorAction.Action.ADD,
383
                newWorkingsetType,
384
                registrationEntityId,
385
                null,
386
                this
387
                ));
388
    }
389

    
390

    
391
    /**
392
    *
393
    */
394
   private void addBulletWorkflowName() {
395
       WorkflowSteps steps = new WorkflowSteps();
396
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
397
               e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
398
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
399
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
400
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
401
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
402
       getWorkflow().addComponent(steps);
403
   }
404

    
405
   /**
406
   *
407
   */
408
  private void addBulletWorkflowTypification() {
409
      WorkflowSteps steps = new WorkflowSteps();
410
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
411
              e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
412
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
413
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
414
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
415
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
416
      getWorkflow().addComponent(steps);
417
  }
418

    
419
    /**
420
     * {@inheritDoc}
421
     */
422
    @Override
423
    public void openReferenceEditor(UUID referenceUuid) {
424
        // TODO Auto-generated method stub
425

    
426
    }
427

    
428
    /**
429
     * {@inheritDoc}
430
     */
431
    @Override
432
    public void openNameEditor(UUID nameUuid) {
433
        // TODO Auto-generated method stub
434

    
435
    }
436

    
437
    /**
438
     * {@inheritDoc}
439
     */
440
    @Override
441
    protected String getHeaderText() {
442
        return headerText;
443
    }
444

    
445
    /**
446
     * {@inheritDoc}
447
     */
448
    @Override
449
    public void setHeaderText(String text) {
450
        this.headerText = text;
451

    
452
    }
453

    
454
    /**
455
     * @return the subheaderText
456
     */
457
    public String getSubheaderText() {
458
        return subheaderText;
459
    }
460

    
461
    /**
462
     * {@inheritDoc}
463
     */
464
    @Override
465
    public void setSubheaderText(String text) {
466
        subheaderText = text;
467
    }
468

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

    
477
    /**
478
     * {@inheritDoc}
479
     */
480
    @Override
481
    public CssLayout getWorkflow() {
482
        return workflow;
483
    }
484

    
485
    /**
486
     * {@inheritDoc}
487
     */
488
    @Override
489
    public void openDetailsPopup(String caption, List<String> messages) {
490
        StringBuffer sb = new StringBuffer();
491
        sb.append("<div class=\"details-popup-content\">");
492
        messages.forEach(s -> sb.append(s).append("</br>"));
493
        sb.append("</div>");
494
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
495
    }
496

    
497
    /**
498
     * {@inheritDoc}
499
     */
500
    @Override
501
    public boolean allowAnonymousAccess() {
502
        return false;
503
    }
504

    
505
    /**
506
     * {@inheritDoc}
507
     */
508
    @Override
509
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
510
        return null;
511
    }
512

    
513
}
(14-14/17)