Project

General

Profile

Download (15.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.themes.ValoTheme;
35

    
36
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
37
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItemEditButtonGroup;
38
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
39
import eu.etaxonomy.cdm.vaadin.component.registration.TypeStateLabel;
40
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
41
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
42
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction.Action;
43
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
44
import eu.etaxonomy.cdm.vaadin.event.RegistrationEditorAction;
45
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
46
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
47
import eu.etaxonomy.cdm.vaadin.event.TypedesignationsEditorAction;
48
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
49
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
50
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
51
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
52
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
53
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView;
54

    
55
/**
56
 * @author a.kohlbecker
57
 * @since Mar 2, 2017
58
 *
59
 */
60
@SpringView(name=RegistrationWorkflowViewBean.NAME)
61
public class RegistrationWorkflowViewBean extends AbstractPageView<RegistrationWorkflowPresenter>
62
    implements RegistrationWorkflowView, View, AccessRestrictedView {
63

    
64

    
65
    public static final String DOM_ID_WORKFLOW = "workflow-container";
66

    
67
    public static final String DOM_ID_WORKINGSET = "workingset";
68

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

    
71
    private static final long serialVersionUID = -213040114015958970L;
72

    
73
    public static final String NAME = "workflow";
74

    
75
    public static final String ACTION_NEW = "new";
76

    
77
    public static final String ACTION_EDIT = "edit";
78

    
79
    private static final boolean REG_ITEM_AS_BUTTON_GROUP = true;
80

    
81
    public RegistrationType regType = null;
82

    
83
    private CssLayout workflow;
84

    
85
    private List<CssLayout> registrations = new ArrayList<>();
86

    
87
    private String headerText = "-- empty --";
88
    private String subheaderText = SUBHEADER_DEEFAULT;
89

    
90

    
91
    public RegistrationWorkflowViewBean() {
92
        super();
93
    }
94

    
95
    @Override
96
    protected void initContent() {
97
        workflow = new CssLayout();
98
        workflow.setSizeFull();
99
        workflow.setId(DOM_ID_WORKFLOW);
100
        getLayout().addComponent(workflow);
101
    }
102

    
103
    /**
104
     * {@inheritDoc}
105
     */
106
    @Override
107
    public void enter(ViewChangeEvent event) {
108
        if(event.getParameters() != null){
109
           String[] params = event.getParameters().split("/");
110

    
111
           if(params[0].equals(ACTION_NEW)) {
112
               regType = RegistrationType.valueOf(params[1]);
113
               headerText = regType.name() + " ...";
114
               eventBus.publishEvent(new RegistrationWorkflowEvent(regType));
115

    
116
           } else if( params[0].equals(ACTION_EDIT)) {
117
               headerText = params[1];
118
               eventBus.publishEvent(new RegistrationWorkflowEvent(Integer.parseInt(params[1])));
119
           }
120
           updateHeader();
121
        }
122
    }
123

    
124
    /**
125
     * {@inheritDoc}
126
     */
127
    @Override
128
    public void setWorkingset(RegistrationWorkingSet workingset) {
129

    
130
        CssLayout registration = new CssLayout();
131
        registration.setId(DOM_ID_WORKINGSET);
132
        registration.setWidth(100, Unit.PERCENTAGE);
133

    
134
        Panel registrationListPanel = createRegistrationsList(workingset);
135
        registrationListPanel.setStyleName("registration-list");
136
        registrationListPanel.setCaption("Registrations");
137

    
138

    
139
        // registration.addComponent(createWorkflowTabSheet(workingset, null));
140
        RegistrationItem registrationItem = new RegistrationItem(workingset, this);
141
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
142
            registrationItem.getSubmitterLabel().setVisible(true);
143
        };
144
        registration.addComponent(registrationItem);
145
        registration.addComponent(registrationListPanel);
146

    
147
        registrations.add(registration);
148
        workflow.removeAllComponents();
149
        workflow.addComponent(registration);
150
    }
151

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

    
162
    }
163

    
164
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
165

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

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

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

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

    
189
        return tabsheet;
190
    }
191

    
192
    /**
193
     * @param workingset
194
     * @return
195
     */
196
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
197
        // prepare name and type list
198
        GridLayout namesTypesList = new GridLayout(3, workingset.getRegistrationDTOs().size());
199
        int row = 0;
200
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
201
            registrationListComponent(namesTypesList, row++, dto);
202
        }
203

    
204
        namesTypesList.setSizeUndefined();
205
        namesTypesList.setWidth(100, Unit.PERCENTAGE);
206
        namesTypesList.setColumnExpandRatio(0, 0.1f);
207
        namesTypesList.setColumnExpandRatio(1, 0.9f);
208
        Panel namesTypesPanel = new Panel(namesTypesList);
209
        namesTypesPanel.setHeight("300px");
210
        return namesTypesPanel;
211
    }
212

    
213
    /**
214
     * @param namesTypesList
215
     * @param row
216
     * @param dto
217
     */
218
    protected void registrationListComponent(GridLayout namesTypesList, int row, RegistrationDTO dto) {
219
        CssLayout buttonGroup = new CssLayout();
220
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
221

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

    
241
        TypeStateLabel typeStateLabel = new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus());
242

    
243

    
244
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
245
            Button editRegistrationButton = new Button(FontAwesome.COG);
246
            editRegistrationButton.setStyleName(ValoTheme.BUTTON_TINY);
247
            editRegistrationButton.setDescription("Edit registration");
248
            editRegistrationButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
249
                AbstractEditorAction.Action.EDIT,
250
                dto.getId(),
251
                null,
252
                this
253
                )));
254
            buttonGroup.addComponent(editRegistrationButton);
255
        }
256

    
257
        Button editNameButton = new Button(FontAwesome.TAG);
258
        editNameButton.setStyleName(ValoTheme.BUTTON_TINY);
259
        editNameButton.setDescription("Edit name");
260
        if(dto.getName() != null){
261
            editNameButton.addClickListener(e -> {
262
                    Integer nameId = dto.getName().getId();
263
                    getEventBus().publishEvent(new TaxonNameEditorAction(
264
                        AbstractEditorAction.Action.EDIT,
265
                        nameId
266
                        )
267
                    );
268
                });
269
        } else {
270
            editNameButton.setEnabled(false);
271
        }
272

    
273
        Button editTypesButton = new Button(FontAwesome.LEAF);
274
        editTypesButton.setStyleName(ValoTheme.BUTTON_TINY);
275
        editTypesButton.setDescription("Edit type designations");
276
        if(!dto.getTypeDesignations().isEmpty()){
277
            editTypesButton.addClickListener(e -> {
278
                int regId = dto.getId();
279
                    getEventBus().publishEvent(new TypedesignationsEditorAction(
280
                        AbstractEditorAction.Action.EDIT,
281
                        regId
282
                        )
283
                    );
284
                });
285
        } else {
286
            editTypesButton.setEnabled(false);
287
        }
288
        buttonGroup.addComponents(editNameButton, editTypesButton);
289

    
290
        Component regItem;
291
        if(REG_ITEM_AS_BUTTON_GROUP){
292
            RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
293
            if(editButtonGroup.getNameButton() != null){
294

    
295
                editButtonGroup.getNameButton().getButton().addClickListener(e -> {
296
                    Integer nameId = editButtonGroup.getNameButton().getId();
297
                    getEventBus().publishEvent(new TaxonNameEditorAction(
298
                        AbstractEditorAction.Action.EDIT,
299
                        nameId
300
                        )
301
                    );
302
                });
303
            }
304
            regItem = editButtonGroup;
305
        } else {
306
            regItem = new Label(dto.getSummary());
307
        }
308

    
309
        namesTypesList.addComponent(typeStateLabel, 0, row);
310
        namesTypesList.setComponentAlignment(typeStateLabel, Alignment.TOP_LEFT);
311
        namesTypesList.addComponent(regItem, 1, row);
312
        namesTypesList.addComponent(buttonGroup, 2, row);
313
        namesTypesList.setComponentAlignment(buttonGroup, Alignment.TOP_LEFT);
314
    }
315

    
316

    
317
    /**
318
    *
319
    */
320
   private void addBulletWorkflowName() {
321
       WorkflowSteps steps = new WorkflowSteps();
322
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
323
               e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
324
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
325
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
326
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
327
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
328
       getWorkflow().addComponent(steps);
329
   }
330

    
331
   /**
332
   *
333
   */
334
  private void addBulletWorkflowTypification() {
335
      WorkflowSteps steps = new WorkflowSteps();
336
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
337
              e -> eventBus.publishEvent(new ReferenceEditorAction(Action.EDIT)));
338
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
339
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Action.EDIT)));
340
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
341
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
342
      getWorkflow().addComponent(steps);
343
  }
344

    
345
    /**
346
     * {@inheritDoc}
347
     */
348
    @Override
349
    public void openReferenceEditor(UUID referenceUuid) {
350
        // TODO Auto-generated method stub
351

    
352
    }
353

    
354
    /**
355
     * {@inheritDoc}
356
     */
357
    @Override
358
    public void openNameEditor(UUID nameUuid) {
359
        // TODO Auto-generated method stub
360

    
361
    }
362

    
363
    /**
364
     * {@inheritDoc}
365
     */
366
    @Override
367
    protected String getHeaderText() {
368
        return headerText;
369
    }
370

    
371
    /**
372
     * {@inheritDoc}
373
     */
374
    @Override
375
    public void setHeaderText(String text) {
376
        this.headerText = text;
377

    
378
    }
379

    
380
    /**
381
     * @return the subheaderText
382
     */
383
    public String getSubheaderText() {
384
        return subheaderText;
385
    }
386

    
387
    /**
388
     * {@inheritDoc}
389
     */
390
    @Override
391
    public void setSubheaderText(String text) {
392
        subheaderText = text;
393
    }
394

    
395
    /**
396
     * {@inheritDoc}
397
     */
398
    @Override
399
    protected String getSubHeaderText() {
400
        return subheaderText;
401
    }
402

    
403
    /**
404
     * {@inheritDoc}
405
     */
406
    @Override
407
    public CssLayout getWorkflow() {
408
        return workflow;
409
    }
410

    
411
    /**
412
     * {@inheritDoc}
413
     */
414
    @Override
415
    public void openDetailsPopup(String caption, List<String> messages) {
416
        StringBuffer sb = new StringBuffer();
417
        sb.append("<div class=\"details-popup-content\">");
418
        messages.forEach(s -> sb.append(s).append("</br>"));
419
        sb.append("</div>");
420
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
421
    }
422

    
423
    /**
424
     * {@inheritDoc}
425
     */
426
    @Override
427
    public boolean allowAnonymousAccess() {
428
        return false;
429
    }
430

    
431
    /**
432
     * {@inheritDoc}
433
     */
434
    @Override
435
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
436
        return null;
437
    }
438

    
439
}
(14-14/17)