Project

General

Profile

Download (13.5 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.Notification;
30
import com.vaadin.ui.Panel;
31
import com.vaadin.ui.TabSheet;
32
import com.vaadin.ui.TabSheet.Tab;
33
import com.vaadin.ui.themes.ValoTheme;
34

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

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

    
62

    
63
    public static final String DOM_ID_WORKFLOW = "workflow-container";
64

    
65
    public static final String DOM_ID_WORKINGSET = "workingset";
66

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

    
69
    private static final long serialVersionUID = -213040114015958970L;
70

    
71
    public static final String NAME = "workflow";
72

    
73
    public static final String ACTION_NEW = "new";
74

    
75
    public static final String ACTION_EDIT = "edit";
76

    
77
    public RegistrationType regType = null;
78

    
79
    private CssLayout workflow;
80

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

    
83
    private String headerText = "-- empty --";
84
    private String subheaderText = SUBHEADER_DEEFAULT;
85

    
86

    
87
    public RegistrationWorkflowViewBean() {
88
        super();
89
    }
90

    
91
    @Override
92
    protected void initContent() {
93
        workflow = new CssLayout();
94
        workflow.setSizeFull();
95
        workflow.setId(DOM_ID_WORKFLOW);
96
        getLayout().addComponent(workflow);
97
    }
98

    
99
    /**
100
     * {@inheritDoc}
101
     */
102
    @Override
103
    public void enter(ViewChangeEvent event) {
104
        if(event.getParameters() != null){
105
           String[] params = event.getParameters().split("/");
106

    
107
           if(params[0].equals(ACTION_NEW)) {
108
               regType = RegistrationType.valueOf(params[1]);
109
               headerText = regType.name() + " ...";
110
               eventBus.publishEvent(new RegistrationWorkflowEvent(regType));
111

    
112
           } else if( params[0].equals(ACTION_EDIT)) {
113
               headerText = params[1];
114
               eventBus.publishEvent(new RegistrationWorkflowEvent(Integer.parseInt(params[1])));
115
           }
116
           updateHeader();
117
        }
118
    }
119

    
120
    /**
121
     * {@inheritDoc}
122
     */
123
    @Override
124
    public void setWorkingset(RegistrationWorkingSet workingset) {
125

    
126
        CssLayout registration = new CssLayout();
127
        registration.setId(DOM_ID_WORKINGSET);
128
        registration.setWidth(100, Unit.PERCENTAGE);
129

    
130
        Panel registrationListPanel = createRegistrationsList(workingset);
131
        registrationListPanel.setStyleName("registration-list");
132
        registrationListPanel.setCaption("Registrations");
133

    
134

    
135
        registration.addComponent(createWorkflowTabSheet(workingset, null));
136
        RegistrationItem registrationItem = new RegistrationItem(workingset, this);
137
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()){
138
            registrationItem.getSubmitterLabel().setVisible(true);
139
        };
140
        registration.addComponent(registrationItem);
141
        registration.addComponent(registrationListPanel);
142

    
143
        registrations.add(registration);
144
        workflow.removeAllComponents();
145
        workflow.addComponent(registration);
146
    }
147

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

    
158
    }
159

    
160
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
161

    
162
        if(namesTypesPanel == null){
163
            namesTypesPanel = new CssLayout();
164
        }
165
        Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
166
        Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
167
        Component releaseComponent = new CssLayout(); // new Label("Not yet published")
168

    
169
        GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
170
        TabSheet tabsheet = new TabSheet();
171
        // tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
172
        //tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
173
        tabsheet.addStyleName("workflow-tabsheet");
174

    
175
        Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
176
        Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
177
        Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
178
        Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
179

    
180
        pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
181
        namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
182
        curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
183
        awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
184

    
185
        return tabsheet;
186
    }
187

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

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

    
209
    /**
210
     * @param namesTypesList
211
     * @param row
212
     * @param dto
213
     */
214
    protected void registrationListComponent(GridLayout namesTypesList, int row, RegistrationDTO dto) {
215
        CssLayout buttonGroup = new CssLayout();
216
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
217

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

    
237
        if(UserHelper.fromSession().userIsRegistrationCurator() || UserHelper.fromSession().userIsAdmin()) {
238
        Button editButton = new Button(FontAwesome.EDIT);
239
        editButton.setStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.BUTTON_PRIMARY);
240
        editButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
241
            AbstractEditorAction.Type.EDIT,
242
            dto.getId()
243
            )));
244
        buttonGroup.addComponent(editButton);
245
        }
246

    
247
        TypeStateLabel typeStateLabel = new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus());
248
        namesTypesList.addComponent(typeStateLabel, 0, row);
249
        namesTypesList.setComponentAlignment(typeStateLabel, Alignment.MIDDLE_LEFT);
250

    
251
        RegistrationItemEditButtonGroup editButtonGroup = new RegistrationItemEditButtonGroup(dto);
252
        if(editButtonGroup.getNameButton() != null){
253

    
254
            editButtonGroup.getNameButton().getButton().addClickListener(e -> {
255
                Integer nameId = editButtonGroup.getNameButton().getId();
256
                getEventBus().publishEvent(new TaxonNameEditorAction(
257
                    AbstractEditorAction.Type.EDIT,
258
                    nameId
259
                    )
260
                );
261
            });
262
        }
263
        namesTypesList.addComponent(editButtonGroup, 1, row);
264
        namesTypesList.addComponent(buttonGroup, 2, row);
265
        namesTypesList.setComponentAlignment(buttonGroup, Alignment.MIDDLE_LEFT);
266
    }
267

    
268

    
269
    /**
270
    *
271
    */
272
   private void addBulletWorkflowName() {
273
       WorkflowSteps steps = new WorkflowSteps();
274
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
275
               e -> eventBus.publishEvent(new ReferenceEditorAction(Type.EDIT)));
276
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
277
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Type.EDIT)));
278
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
279
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
280
       getWorkflow().addComponent(steps);
281
   }
282

    
283
   /**
284
   *
285
   */
286
  private void addBulletWorkflowTypification() {
287
      WorkflowSteps steps = new WorkflowSteps();
288
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
289
              e -> eventBus.publishEvent(new ReferenceEditorAction(Type.EDIT)));
290
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
291
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Type.EDIT)));
292
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
293
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
294
      getWorkflow().addComponent(steps);
295
  }
296

    
297
    /**
298
     * {@inheritDoc}
299
     */
300
    @Override
301
    public void openReferenceEditor(UUID referenceUuid) {
302
        // TODO Auto-generated method stub
303

    
304
    }
305

    
306
    /**
307
     * {@inheritDoc}
308
     */
309
    @Override
310
    public void openNameEditor(UUID nameUuid) {
311
        // TODO Auto-generated method stub
312

    
313
    }
314

    
315
    /**
316
     * {@inheritDoc}
317
     */
318
    @Override
319
    protected String getHeaderText() {
320
        return headerText;
321
    }
322

    
323
    /**
324
     * {@inheritDoc}
325
     */
326
    @Override
327
    public void setHeaderText(String text) {
328
        this.headerText = text;
329

    
330
    }
331

    
332
    /**
333
     * @return the subheaderText
334
     */
335
    public String getSubheaderText() {
336
        return subheaderText;
337
    }
338

    
339
    /**
340
     * {@inheritDoc}
341
     */
342
    @Override
343
    public void setSubheaderText(String text) {
344
        subheaderText = text;
345
    }
346

    
347
    /**
348
     * {@inheritDoc}
349
     */
350
    @Override
351
    protected String getSubHeaderText() {
352
        return subheaderText;
353
    }
354

    
355
    /**
356
     * {@inheritDoc}
357
     */
358
    @Override
359
    public CssLayout getWorkflow() {
360
        return workflow;
361
    }
362

    
363
    /**
364
     * {@inheritDoc}
365
     */
366
    @Override
367
    public void openDetailsPopup(String caption, List<String> messages) {
368
        StringBuffer sb = new StringBuffer();
369
        sb.append("<div class=\"details-popup-content\">");
370
        messages.forEach(s -> sb.append(s).append("</br>"));
371
        sb.append("</div>");
372
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
373
    }
374

    
375
    /**
376
     * {@inheritDoc}
377
     */
378
    @Override
379
    public boolean allowAnonymousAccess() {
380
        return false;
381
    }
382

    
383
    /**
384
     * {@inheritDoc}
385
     */
386
    @Override
387
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
388
        return null;
389
    }
390

    
391
}
(14-14/17)