Project

General

Profile

Download (19.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

    
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.model.name.NameTypeDesignation;
40
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
41
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
42
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
43
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
44
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup.IdButton;
45
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
46
import eu.etaxonomy.cdm.vaadin.component.registration.TypeStateLabel;
47
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
48
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
49
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
50
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
51
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
52
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
53
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
54
import eu.etaxonomy.cdm.vaadin.event.TypeDesignationWorkingsetEditorAction;
55
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
56
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
57
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
58
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
59
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
60
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
61

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

    
71

    
72
    public static final String DOM_ID_WORKFLOW = "workflow-container";
73

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

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

    
78
    private static final long serialVersionUID = -213040114015958970L;
79

    
80
    public static final String NAME = "workflow";
81

    
82
    public static final String ACTION_NEW = "new";
83

    
84
    public static final String ACTION_EDIT = "edit";
85

    
86
    private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
87

    
88
    public RegistrationType regType = null;
89

    
90
    private CssLayout workflow;
91

    
92
    private List<CssLayout> registrations = new ArrayList<>();
93

    
94
    private String headerText = "-- empty --";
95
    private String subheaderText = SUBHEADER_DEEFAULT;
96

    
97
    private boolean addNameAndTypeEditButtons = false;
98

    
99

    
100
    public RegistrationWorkflowViewBean() {
101
        super();
102
    }
103

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

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

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

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

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

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

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

    
147

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

    
156
        registrations.add(registration);
157
        workflow.removeAllComponents();
158
        workflow.addComponent(registration);
159
    }
160

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

    
171
    }
172

    
173
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
174

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

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

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

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

    
198
        return tabsheet;
199
    }
200

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

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

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

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

    
250
        TypeStateLabel typeStateLabel = new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus());
251

    
252

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

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

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

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

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

    
317
                for(IdButton idButton : editButtonGroup.getTypeDesignationButtons()){
318
                    idButton.getButton().addClickListener(e -> {
319
                        Integer typeDesignationWorkingsetId = idButton.getId();
320
                        Integer registrationEntityID = dto.getId();
321
                        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
322
                                AbstractEditorAction.Action.EDIT,
323
                                typeDesignationWorkingsetId,
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(typeStateLabel, 0, row);
342
        namesTypesList.setComponentAlignment(typeStateLabel, 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(SpecimenTypeDesignation.class, registrationEntityId, typeDesignationTypeCooser));
362
        Button newNameTypeDesignationButton = new Button("Name type designation",
363
                e -> addNewTypeRegistrationWorkingset(NameTypeDesignation.class, 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(Class<? extends TypeDesignationBase<?>> newEntityType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
380
        UI.getCurrent().removeWindow(typeDesignationTypeCooser);
381
        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
382
                AbstractEditorAction.Action.ADD,
383
                newEntityType,
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)