Project

General

Profile

Download (17.9 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.EnumSet;
14
import java.util.List;
15
import java.util.UUID;
16

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

    
20
import com.vaadin.navigator.View;
21
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
22
import com.vaadin.server.FontAwesome;
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.UI;
36
import com.vaadin.ui.VerticalLayout;
37
import com.vaadin.ui.Window;
38
import com.vaadin.ui.themes.ValoTheme;
39

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

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

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

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

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

    
80
    public RegistrationType regType = null;
81

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

    
84
    private String headerText = "Registration Workingset Editor";
85
    private String subheaderText = "";
86

    
87
    private Integer citationID;
88

    
89
    private Button addNewNameRegistrationButton;
90

    
91
    private LazyComboBox<TaxonName> existingNameCombobox;
92

    
93
    private GridLayout registrationsGrid;
94

    
95
    private Button addExistingNameButton;
96

    
97
    private RegistrationItem workingsetHeader;
98

    
99
    private Panel registrationListPanel;
100

    
101
    public RegistrationWorksetViewBean() {
102
        super();
103
    }
104

    
105

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

    
116

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

    
125
            getPresenter().handleViewEntered();
126
        }
127
    }
128

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

    
135
        if(workingsetHeader != null){
136
            getLayout().removeComponent(workingsetHeader);
137
            getLayout().removeComponent(registrationListPanel);
138
        }
139
        workingsetHeader = new RegistrationItem(workingset, this);
140
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
141
            workingsetHeader.getSubmitterLabel().setVisible(true);
142
        }
143
        addContentComponent(workingsetHeader, null);
144

    
145
        registrationListPanel = createRegistrationsList(workingset);
146
        registrationListPanel.setHeight("100%");
147
        registrationListPanel.setStyleName("registration-list");
148
        registrationListPanel.setCaption("Registrations");
149
        addContentComponent(registrationListPanel, 1.0f);
150

    
151
    }
152

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

    
163
    }
164

    
165
    /**
166
     * @param workingset
167
     * @return
168
     */
169
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
170

    
171
        registrationsGrid = new GridLayout(3, 1);
172
        registrationsGrid.setWidth("100%");
173
        // allow vertical scrolling:
174
        registrationsGrid.setHeightUndefined();
175

    
176
        //registrationsGrid.setColumnExpandRatio(0, 0.1f);
177
        registrationsGrid.setColumnExpandRatio(1, 1f);
178

    
179
        int row = 0;
180
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
181
            putRegistrationListComponent(registrationsGrid, row++, dto);
182
        }
183

    
184
        Label addRegistrationLabel_1 = new Label("Add a new registration for a");
185
        Label addRegistrationLabel_2 = new Label("or an");
186

    
187
        addNewNameRegistrationButton = new Button("new name");
188
        addNewNameRegistrationButton.setDescription("A name which is newly published in this publication.");
189
        addNewNameRegistrationButton.addClickListener(
190
                e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.ADD, addNewNameRegistrationButton))
191
                );
192

    
193
        addExistingNameButton = new Button("existing name:");
194
        addExistingNameButton.setDescription("A name which was previously published in a earlier publication.");
195
        addExistingNameButton.setEnabled(false);
196
        addExistingNameButton.addClickListener(
197
                e -> eventBus.publishEvent(new RegistrationWorkingsetAction(citationID, RegistrationWorkingsetAction.Action.start))
198
                );
199

    
200
        existingNameCombobox = new LazyComboBox<TaxonName>(TaxonName.class);
201
        existingNameCombobox.addValueChangeListener(
202
                e -> addExistingNameButton.setEnabled(e.getProperty().getValue() != null)
203
                );
204

    
205
        HorizontalLayout buttonContainer = new HorizontalLayout(addRegistrationLabel_1, addNewNameRegistrationButton, addRegistrationLabel_2, addExistingNameButton, existingNameCombobox);
206
        buttonContainer.setSpacing(true);
207
//        buttonContainer.setWidth(100, Unit.PERCENTAGE);
208
        buttonContainer.setComponentAlignment(addRegistrationLabel_1, Alignment.MIDDLE_LEFT);
209
        buttonContainer.setComponentAlignment(addRegistrationLabel_2, Alignment.MIDDLE_LEFT);
210
        registrationsGrid.addComponent(buttonContainer, 0, row, 2, row);
211
        registrationsGrid.setComponentAlignment(buttonContainer, Alignment.MIDDLE_RIGHT);
212

    
213
        Panel namesTypesPanel = new Panel(registrationsGrid);
214
        return namesTypesPanel;
215
    }
216

    
217

    
218
    /**
219
     * @param grid
220
     * @param row If null, the new row will be inserted as last registration item, that is before the button row.
221
     * @param dto
222
     */
223
    protected void putRegistrationListComponent(GridLayout grid, int row, RegistrationDTO dto) {
224

    
225
        grid.setRows(grid.getRows() + 1);
226

    
227
        CssLayout buttonGroup = new CssLayout();
228
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
229

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

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

    
251

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

    
265
        PermissionDebugUtils.addGainPerEntityPermissionButton(buttonGroup, Registration.class, dto.getId(),
266
                EnumSet.of(CRUD.UPDATE), RegistrationStatus.PREPARATION.name());
267

    
268
        Component regItem;
269

    
270
        RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
271

    
272
        if(editButtonGroup.getNameButton() != null){
273
            editButtonGroup.getNameButton().getButton().addClickListener(e -> {
274
                Integer nameId = editButtonGroup.getNameButton().getId();
275
                getEventBus().publishEvent(new TaxonNameEditorAction(
276
                    AbstractEditorAction.Action.EDIT,
277
                    nameId,
278
                    null, //e.getButton(), the listener method expects this to be null
279
                    this
280
                    )
281
                );
282
            });
283
        }
284

    
285
        for(TypeDesignationWorkingSetButton workingsetButton : editButtonGroup.getTypeDesignationButtons()){
286
            workingsetButton.getButton().addClickListener(e -> {
287
                Integer typeDesignationWorkingsetId = workingsetButton.getId();
288
                TypeDesignationWorkingSetType workingsetType = workingsetButton.getType();
289
                Integer registrationEntityID = dto.getId();
290
                getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
291
                        AbstractEditorAction.Action.EDIT,
292
                        typeDesignationWorkingsetId,
293
                        workingsetType,
294
                        registrationEntityID,
295
                        null, //e.getButton(), the listener method expects this to be null
296
                        this
297
                        )
298
                    );
299
            });
300
        }
301

    
302
        editButtonGroup.getAddTypeDesignationButton().addClickListener(
303
                e -> chooseNewTypeRegistrationWorkingset(dto.getId())
304
                );
305
        regItem = editButtonGroup;
306

    
307

    
308
        grid.addComponent(stateLabel, 0, row);
309
        grid.setComponentAlignment(stateLabel, Alignment.TOP_LEFT);
310
        grid.addComponent(regItem, 1, row);
311
        grid.addComponent(buttonGroup, 2, row);
312
        grid.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
313
    }
314

    
315
    /**
316
     * @param button
317
     * @param registrationEntityId
318
     *
319
     */
320
    @Override
321
    public void chooseNewTypeRegistrationWorkingset(Integer registrationEntityId) {
322

    
323
        Window typeDesignationTypeCooser = new Window();
324
        typeDesignationTypeCooser.setModal(true);
325
        typeDesignationTypeCooser.setResizable(false);
326
        typeDesignationTypeCooser.setCaption("Add new type designation");
327
        Label label = new Label("Please select kind of type designation to be created.");
328
        Button newSpecimenTypeDesignationButton = new Button("Specimen type designation",
329
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.SPECIMEN_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
330
        Button newNameTypeDesignationButton = new Button("Name type designation",
331
                e -> addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType.NAME_TYPE_DESIGNATION_WORKINGSET, registrationEntityId, typeDesignationTypeCooser));
332
        newNameTypeDesignationButton.setEnabled(false);
333

    
334
        VerticalLayout layout = new VerticalLayout(label, newSpecimenTypeDesignationButton, newNameTypeDesignationButton);
335
        layout.setMargin(true);
336
        layout.setSpacing(true);
337
        layout.setComponentAlignment(newSpecimenTypeDesignationButton, Alignment.MIDDLE_CENTER);
338
        layout.setComponentAlignment(newNameTypeDesignationButton, Alignment.MIDDLE_CENTER);
339
        typeDesignationTypeCooser.setContent(layout);
340
        UI.getCurrent().addWindow(typeDesignationTypeCooser);
341
    }
342

    
343
    /**
344
     * @param button
345
     *
346
     */
347
    protected void addNewTypeDesignationWorkingset(TypeDesignationWorkingSetType newWorkingsetType, Integer registrationEntityId, Window typeDesignationTypeCooser) {
348
        UI.getCurrent().removeWindow(typeDesignationTypeCooser);
349
        getEventBus().publishEvent(new TypeDesignationWorkingsetEditorAction(
350
                AbstractEditorAction.Action.ADD,
351
                newWorkingsetType,
352
                registrationEntityId,
353
                null,
354
                this
355
                ));
356
    }
357

    
358

    
359
    /**
360
    *
361
    */
362
   private void addBulletWorkflowName() {
363
       WorkflowSteps steps = new WorkflowSteps();
364
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
365
               e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
366
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
367
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
368
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
369
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
370
       getWorkflow().addComponent(steps);
371
   }
372

    
373
   /**
374
   *
375
   */
376
  private void addBulletWorkflowTypification() {
377
      WorkflowSteps steps = new WorkflowSteps();
378
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
379
              e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
380
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
381
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
382
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
383
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
384
      getWorkflow().addComponent(steps);
385
  }
386

    
387
    /**
388
     * {@inheritDoc}
389
     */
390
    @Override
391
    public void openReferenceEditor(UUID referenceUuid) {
392
        // TODO Auto-generated method stub
393

    
394
    }
395

    
396
    /**
397
     * {@inheritDoc}
398
     */
399
    @Override
400
    public void openNameEditor(UUID nameUuid) {
401
        // TODO Auto-generated method stub
402

    
403
    }
404

    
405
    /**
406
     * {@inheritDoc}
407
     */
408
    @Override
409
    protected String getHeaderText() {
410
        return headerText;
411
    }
412

    
413
    /**
414
     * {@inheritDoc}
415
     */
416
    @Override
417
    public void setHeaderText(String text) {
418
        this.headerText = text;
419
        updateHeader();
420

    
421
    }
422

    
423
    /**
424
     * @return the subheaderText
425
     */
426
    public String getSubheaderText() {
427
        return subheaderText;
428
    }
429

    
430
    /**
431
     * {@inheritDoc}
432
     */
433
    @Override
434
    public void setSubheaderText(String text) {
435
        subheaderText = text;
436
        updateHeader();
437
    }
438

    
439
    /**
440
     * {@inheritDoc}
441
     */
442
    @Override
443
    protected String getSubHeaderText() {
444
        return subheaderText;
445
    }
446

    
447
    /**
448
     * {@inheritDoc}
449
     */
450
    @Override
451
    public AbstractLayout getWorkflow() {
452
        return getLayout();
453
    }
454

    
455
    /**
456
     * {@inheritDoc}
457
     */
458
    @Override
459
    public void openDetailsPopup(String caption, List<String> messages) {
460
        StringBuffer sb = new StringBuffer();
461
        sb.append("<div class=\"details-popup-content\">");
462
        messages.forEach(s -> sb.append(s).append("</br>"));
463
        sb.append("</div>");
464
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
465
    }
466

    
467
    /**
468
     * {@inheritDoc}
469
     */
470
    @Override
471
    public boolean allowAnonymousAccess() {
472
        return false;
473
    }
474

    
475
    /**
476
     * {@inheritDoc}
477
     */
478
    @Override
479
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
480
        return null;
481
    }
482

    
483
    /**
484
     * @return the addNewNameRegistrationButton
485
     */
486
    @Override
487
    public Button getAddNewNameRegistrationButton() {
488
        return addNewNameRegistrationButton;
489
    }
490

    
491
    @Override
492
    public Button getAddExistingNameRegistrationButton() {
493
        return addExistingNameButton;
494
    }
495

    
496
    @Override
497
    public LazyComboBox<TaxonName> getAddExistingNameCombobox() {
498
        return existingNameCombobox;
499
    }
500

    
501
    /**
502
     * @return the citationID
503
     */
504
    @Override
505
    public Integer getCitationID() {
506
        return citationID;
507
    }
508

    
509

    
510
}
(14-14/19)