Project

General

Profile

Download (12.4 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.beans.factory.annotation.Autowired;
17
import org.springframework.security.core.GrantedAuthority;
18

    
19
import com.vaadin.navigator.View;
20
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
21
import com.vaadin.server.FontAwesome;
22
import com.vaadin.server.GenericFontIcon;
23
import com.vaadin.server.Page;
24
import com.vaadin.spring.annotation.SpringView;
25
import com.vaadin.ui.Alignment;
26
import com.vaadin.ui.Button;
27
import com.vaadin.ui.Component;
28
import com.vaadin.ui.CssLayout;
29
import com.vaadin.ui.GridLayout;
30
import com.vaadin.ui.Label;
31
import com.vaadin.ui.Notification;
32
import com.vaadin.ui.Panel;
33
import com.vaadin.ui.TabSheet;
34
import com.vaadin.ui.TabSheet.Tab;
35
import com.vaadin.ui.themes.ValoTheme;
36

    
37
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
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.Type;
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.registration.RegistrationWorkflowEvent;
48
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
49
import eu.etaxonomy.cdm.vaadin.model.registration.WorkflowStep;
50
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
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
        workflow = new CssLayout();
91
        workflow.setSizeFull();
92
        workflow.setId(DOM_ID_WORKFLOW);
93
        getLayout().addComponent(workflow);
94
    }
95

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

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

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

    
117
    /**
118
     * {@inheritDoc}
119
     */
120
    @Override
121
    public void setWorkingset(RegistrationWorkingSet workingset) {
122

    
123
        CssLayout registration = new CssLayout();
124
        registration.setId(DOM_ID_WORKINGSET);
125
        registration.setWidth(100, Unit.PERCENTAGE);
126

    
127
        Panel namesTypesPanel = createRegistrationsList(workingset);
128
        namesTypesPanel.setStyleName("registration-list");
129
        namesTypesPanel.setCaption("Registrations");
130

    
131

    
132
        registration.addComponent(createWorkflowTabSheet(workingset, null));
133
        registration.addComponent(new RegistrationItem(workingset, this));
134
        registration.addComponent(namesTypesPanel);
135

    
136
        registrations.add(registration);
137
        workflow.removeAllComponents();
138
        workflow.addComponent(registration);
139
    }
140

    
141
    /**
142
     * {@inheritDoc}
143
     */
144
    @Override
145
    public void addBlockingRegistration(RegistrationDTO blocking) {
146
        if(registrations == null) {
147
            throw new RuntimeException("A Workingset must be present prior adding blocking registrations.");
148
        }
149
        // add the blocking registration
150

    
151
    }
152

    
153
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
154

    
155
        if(namesTypesPanel == null){
156
            namesTypesPanel = new CssLayout();
157
        }
158
        Component citationComponent = new CssLayout(); // new Label(workingset.getCitation());
159
        Component curationComponent = new CssLayout(); // new Label("Curation in progress ...")
160
        Component releaseComponent = new CssLayout(); // new Label("Not yet published")
161

    
162
        GenericFontIcon tabIcon = new GenericFontIcon("IcoMoon", 0xe900);
163
        TabSheet tabsheet = new TabSheet();
164
        // tabsheet.addStyleName(ValoTheme.TABSHEET_FRAMED);
165
        //tabsheet.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
166
        tabsheet.addStyleName("workflow-tabsheet");
167

    
168
        Tab pubDetailsTab = tabsheet.addTab(citationComponent, WorkflowStep.PUBLICATION_DETAILS.getRepresentation(), tabIcon);
169
        Tab namesTypesTab = tabsheet.addTab(namesTypesPanel, WorkflowStep.NAMES_N_TYPES.getRepresentation(), tabIcon);
170
        Tab curationTab = tabsheet.addTab(curationComponent, WorkflowStep.CURATION.getRepresentation(), tabIcon);
171
        Tab awaitingPubTab = tabsheet.addTab(releaseComponent, WorkflowStep.AWAITING_PUBLICATION.getRepresentation(), tabIcon);
172

    
173
        pubDetailsTab.setStyleName("bg-status-" + WorkflowStep.PUBLICATION_DETAILS.name());
174
        namesTypesTab.setStyleName("bg-status-" + WorkflowStep.NAMES_N_TYPES.name());
175
        curationTab.setStyleName("bg-status-" + WorkflowStep.CURATION.name());
176
        awaitingPubTab.setStyleName("bg-status-" + WorkflowStep.AWAITING_PUBLICATION.name());
177

    
178
        return tabsheet;
179
    }
180

    
181
    /**
182
     * @param workingset
183
     * @return
184
     */
185
    public Panel createRegistrationsList(RegistrationWorkingSet workingset) {
186
        // prepare name and type list
187
        GridLayout namesTypesList = new GridLayout(3, workingset.getRegistrationDTOs().size());
188
        int row = 0;
189
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()) {
190

    
191
            Button messageButton = new Button(FontAwesome.COMMENT);
192
            messageButton.setStyleName(ValoTheme.BUTTON_TINY); //  + " " + RegistrationStyles.STYLE_FRIENDLY_FOREGROUND);
193
            if(dto.getMessages().isEmpty()){
194
                messageButton.setEnabled(false);
195
            } else {
196
                messageButton.addClickListener(e -> eventBus.publishEvent(
197
                        new ShowDetailsEvent<RegistrationDTO, Integer>(
198
                            e,
199
                            RegistrationDTO.class,
200
                            dto.getId(),
201
                            "messages"
202
                            )
203
                        )
204
                    );
205
            }
206
            messageButton.setCaption("<span class=\"" + RegistrationStyles.BUTTON_BADGE +"\"> " + dto.getMessages().size() + "</span>");
207
            messageButton.setCaptionAsHtml(true);
208

    
209
            Button editButton = new Button(FontAwesome.EDIT);
210
            editButton.setStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.BUTTON_PRIMARY);
211
            editButton.addClickListener(e -> getEventBus().publishEvent(new RegistrationEditorAction(
212
                AbstractEditorAction.Type.EDIT,
213
                dto.getId()
214
                )));
215

    
216
            namesTypesList.addComponent(new TypeStateLabel().update(dto.getRegistrationType(), dto.getStatus()), 0, row);
217
            namesTypesList.addComponent(new Label(dto.getSummary()), 1, row);
218
            CssLayout buttonGroup = new CssLayout();
219
            buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
220
            buttonGroup.addComponent(messageButton);
221
            buttonGroup.addComponent(editButton);
222
            namesTypesList.addComponent(buttonGroup, 2, row);
223
            namesTypesList.setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
224
            row++;
225
        }
226
        namesTypesList.setSizeUndefined();
227
        namesTypesList.setWidth(100, Unit.PERCENTAGE);
228
        namesTypesList.setColumnExpandRatio(0, 0.1f);
229
        namesTypesList.setColumnExpandRatio(1, 0.9f);
230
        Panel namesTypesPanel = new Panel(namesTypesList);
231
        namesTypesPanel.setHeight("300px");
232
        return namesTypesPanel;
233
    }
234

    
235

    
236
    /**
237
    *
238
    */
239
   private void addBulletWorkflowName() {
240
       WorkflowSteps steps = new WorkflowSteps();
241
       steps.appendNewWorkflowItem(1, "Publication details including the publisher.",
242
               e -> eventBus.publishEvent(new ReferenceEditorAction(Type.EDIT)));
243
       steps.appendNewWorkflowItem(2, "One or multiple published scientific new names.",
244
               e -> eventBus.publishEvent(new TaxonNameEditorAction(Type.EDIT)));
245
       steps.appendNewWorkflowItem(3, "Request for data curation and await approval.", null);
246
       steps.appendNewWorkflowItem(4, "Awaiting publication", null);
247
       getWorkflow().addComponent(steps);
248
   }
249

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

    
264
    /**
265
     * {@inheritDoc}
266
     */
267
    @Autowired
268
    @Override
269
    protected void injectPresenter(RegistrationWorkflowPresenter presenter) {
270
        setPresenter(presenter);
271
    }
272

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

    
280
    }
281

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

    
289
    }
290

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

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

    
306
    }
307

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

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

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

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

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

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

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

    
367
}
(14-14/17)