Project

General

Profile

Download (12.6 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.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.userIsRegistrationCurator() || UserHelper.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

    
198
            CssLayout buttonGroup = new CssLayout();
199
            buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
200

    
201
            Button messageButton = new Button(FontAwesome.COMMENT);
202
            messageButton.setStyleName(ValoTheme.BUTTON_TINY); //  + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
203
            if(dto.getMessages().isEmpty()){
204
                messageButton.setEnabled(false);
205
            } else {
206
                messageButton.addClickListener(e -> eventBus.publishEvent(
207
                        new ShowDetailsEvent<RegistrationDTO, Integer>(
208
                            e,
209
                            RegistrationDTO.class,
210
                            dto.getId(),
211
                            "messages"
212
                            )
213
                        )
214
                    );
215
            }
216
            messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
217
            messageButton.setCaptionAsHtml(true);
218
            buttonGroup.addComponent(messageButton);
219

    
220
            if(UserHelper.userIsRegistrationCurator() || UserHelper.userIsAdmin()) {
221
            Button editButton = new Button(FontAwesome.EDIT);
222
            editButton.setStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.BUTTON_PRIMARY);
223
            editButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
224
                AbstractEditorAction.Type.EDIT,
225
                dto.getId()
226
                )));
227
            buttonGroup.addComponent(editButton);
228
            }
229

    
230
            namesTypesList.addComponent(new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus()), 0, row);
231
            namesTypesList.addComponent(new Label(dto.getSummary()), 1, row);
232
            namesTypesList.addComponent(buttonGroup, 2, row);
233
            namesTypesList.setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
234
            row++;
235
        }
236
        namesTypesList.setSizeUndefined();
237
        namesTypesList.setWidth(100, Unit.PERCENTAGE);
238
        namesTypesList.setColumnExpandRatio(0, 0.1f);
239
        namesTypesList.setColumnExpandRatio(1, 0.9f);
240
        Panel namesTypesPanel = new Panel(namesTypesList);
241
        namesTypesPanel.setHeight("300px");
242
        return namesTypesPanel;
243
    }
244

    
245

    
246
    /**
247
    *
248
    */
249
   private void addBulletWorkflowName() {
250
       WorkflowSteps steps = new WorkflowSteps();
251
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
252
               e -> eventBus.publishEvent(new ReferenceEditorAction(Type.EDIT)));
253
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
254
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Type.EDIT)));
255
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
256
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
257
       getWorkflow().addComponent(steps);
258
   }
259

    
260
   /**
261
   *
262
   */
263
  private void addBulletWorkflowTypification() {
264
      WorkflowSteps steps = new WorkflowSteps();
265
      steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
266
              e -> eventBus.publishEvent(new ReferenceEditorAction(Type.EDIT)));
267
      steps.appendNewWorkflowItem(2, "One or multiple published typifications.",
268
              e -> eventBus.publishEvent(new TaxonNameEditorAction(Type.EDIT)));
269
      steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
270
      steps.appendNewWorkflowItem(4, "Awaiting publication", null);
271
      getWorkflow().addComponent(steps);
272
  }
273

    
274
    /**
275
     * {@inheritDoc}
276
     */
277
    @Override
278
    public void openReferenceEditor(UUID referenceUuid) {
279
        // TODO Auto-generated method stub
280

    
281
    }
282

    
283
    /**
284
     * {@inheritDoc}
285
     */
286
    @Override
287
    public void openNameEditor(UUID nameUuid) {
288
        // TODO Auto-generated method stub
289

    
290
    }
291

    
292
    /**
293
     * {@inheritDoc}
294
     */
295
    @Override
296
    protected String getHeaderText() {
297
        return headerText;
298
    }
299

    
300
    /**
301
     * {@inheritDoc}
302
     */
303
    @Override
304
    public void setHeaderText(String text) {
305
        this.headerText = text;
306

    
307
    }
308

    
309
    /**
310
     * @return the subheaderText
311
     */
312
    public String getSubheaderText() {
313
        return subheaderText;
314
    }
315

    
316
    /**
317
     * {@inheritDoc}
318
     */
319
    @Override
320
    public void setSubheaderText(String text) {
321
        subheaderText = text;
322
    }
323

    
324
    /**
325
     * {@inheritDoc}
326
     */
327
    @Override
328
    protected String getSubHeaderText() {
329
        return subheaderText;
330
    }
331

    
332
    /**
333
     * {@inheritDoc}
334
     */
335
    @Override
336
    public CssLayout getWorkflow() {
337
        return workflow;
338
    }
339

    
340
    /**
341
     * {@inheritDoc}
342
     */
343
    @Override
344
    public void openDetailsPopup(String caption, List<String> messages) {
345
        StringBuffer sb = new StringBuffer();
346
        sb.append("<div class=\"details-popup-content\">");
347
        messages.forEach(s -> sb.append(s).append("</br>"));
348
        sb.append("</div>");
349
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
350
    }
351

    
352
    /**
353
     * {@inheritDoc}
354
     */
355
    @Override
356
    public boolean allowAnonymousAccess() {
357
        return false;
358
    }
359

    
360
    /**
361
     * {@inheritDoc}
362
     */
363
    @Override
364
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
365
        return null;
366
    }
367

    
368
}
(14-14/17)