Project

General

Profile

« Previous | Next » 

Revision 7a044d6b

Added by Andreas Kohlbecker about 5 years ago

ref #6169 reusing RegistrationItem for WorkflowView

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationItem.java
10 10

  
11 11
import static eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles.STYLE_LABEL_NOWRAP;
12 12

  
13
import org.joda.time.DateTime;
13 14
import org.joda.time.format.ISODateTimeFormat;
14 15

  
15 16
import com.vaadin.server.ExternalResource;
......
23 24
import com.vaadin.ui.Link;
24 25
import com.vaadin.ui.themes.ValoTheme;
25 26

  
27
import eu.etaxonomy.cdm.model.common.TimePeriod;
26 28
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
29
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
27 30
import eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO;
28 31
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationTypeConverter;
29 32
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowViewBean;
......
42 45

  
43 46
    private static final String LABEL_CAPTION_PUBLISHED = "Published";
44 47

  
45
    private static final int GRID_ROWS = 3;
48
    private static final String LABEL_CAPTION_RELEASED = "Released";
49

  
50
    private static final int GRID_ROWS = 4;
46 51

  
47 52
    private static final int GRID_COLS = 3;
48 53

  
49 54
    private static final long serialVersionUID = -211003770452173644L;
50 55

  
51
    private RegistrationDTO regDto;
52

  
53 56
    private RegistrationTypeConverter regTypeConverter = new RegistrationTypeConverter();
54 57

  
55 58
    private AbstractView<?> parentView;
......
63 66
    private Button openButton = new Button(FontAwesome.COGS);
64 67
    private Label createdLabel = new Label();
65 68
    private Label publishedLabel = new Label();
69
    private Label releasedLabel = new Label();
70

  
71
    private String citationString;
66 72
    // --------------------------------------------------
67 73

  
68 74
    /**
......
74 80
        setItem(item, parentView);
75 81
    }
76 82

  
83
    /**
84
    *
85
    */
86
   public RegistrationItem(RegistrationWorkingSet workingSet, AbstractView<?> parentView) {
87
       super(GRID_COLS, GRID_ROWS);
88
       init();
89
       setWorkingSet(workingSet, parentView);
90
   }
91

  
77 92
    public void init() {
78 93

  
79 94
        setWidth(100, Unit.PERCENTAGE);
80 95
        addStyleName("registration-list-item");
81 96

  
82 97
        typeStateLabel.setStyleName(STYLE_LABEL_NOWRAP);
98
        typeStateLabel.setVisible(false);
83 99
        addComponent(typeStateLabel, 0, 0);
84 100
        setComponentAlignment(typeStateLabel, Alignment.TOP_LEFT);
85 101

  
102
        identifierLink.setVisible(false);
86 103
        addComponent(identifierLink, 1, 0);
87 104
        setComponentAlignment(identifierLink, Alignment.TOP_CENTER);
88 105
        setColumnExpandRatio(1, 1.0f);
......
94 111
        messageButton.setEnabled(false);
95 112
        openButton.setStyleName(ValoTheme.BUTTON_TINY);
96 113
        openButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
114
        openButton.setVisible(false);
97 115

  
98 116
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
99 117
        addComponent(buttonGroup, 2, 0);
100 118
        setComponentAlignment(buttonGroup, Alignment.TOP_RIGHT);
101 119

  
102 120
        citationSummaryLabel.setContentMode(ContentMode.HTML);
103
        addComponent(citationSummaryLabel, 0, 1, 1, 2);
121
        addComponent(citationSummaryLabel, 0, 1, 1, 3);
104 122

  
105 123
        createdLabel.setStyleName(STYLE_LABEL_NOWRAP);
106 124
        createdLabel.setContentMode(ContentMode.HTML);
......
111 129
        publishedLabel.setStyleName(STYLE_LABEL_NOWRAP);
112 130
        publishedLabel.setContentMode(ContentMode.HTML);
113 131
        publishedLabel.setWidthUndefined();
132
        publishedLabel.setVisible(false);
114 133
        addComponent(publishedLabel, 2, 2);
115 134
        setComponentAlignment(publishedLabel, Alignment.BOTTOM_RIGHT);
116 135

  
136
        releasedLabel.setStyleName(STYLE_LABEL_NOWRAP);
137
        releasedLabel.setContentMode(ContentMode.HTML);
138
        releasedLabel.setWidthUndefined();
139
        releasedLabel.setVisible(false);
140
        addComponent(releasedLabel, 2, 3);
141
        setComponentAlignment(releasedLabel, Alignment.BOTTOM_RIGHT);
142

  
117 143
    }
118 144

  
119
    public void setItem(RegistrationDTO item, AbstractView<?> parentView){
120
        regDto = item;
145
    public void setItem(RegistrationDTO regDto, AbstractView<?> parentView){
121 146
        this.parentView = parentView;
122
        updateUI();
147
        updateUI(regDto.getCitationString(), regDto.getCreated(), regDto.getDatePublished(), regDto.getMessages().size(), regDto);
148
    }
149

  
150
    public void setWorkingSet(RegistrationWorkingSet workingSet, AbstractView<?> parentView){
151
        this.parentView = parentView;
152
        updateUI(workingSet.getCitation(), workingSet.getCreated(), null, workingSet.messagesCount(), null);
123 153
    }
124 154

  
125 155

  
126 156
    /**
127 157
     *
128 158
     */
129
    private void updateUI() {
130
        typeStateLabel.update(regDto.getRegistrationType(), regDto.getStatus());
131
        getCitationSummaryLabel().setValue(regDto.getCitationString() + "</br>" + regDto.getSummary());
132
        updateIdentifierLink();
133

  
134
        // Buttons
135
        getOpenButton().addClickListener(e -> publishEvent(new NavigationEvent(
136
                RegistrationWorkflowViewBean.NAME,
137
                RegistrationWorkflowViewBean.ACTION_EDIT,
138
                Integer.toString(regDto.getId())
139
                )));
140
        if(regDto.getMessages().size() > 0){
159
    private void updateUI(String citationString,  DateTime created, TimePeriod datePublished,  int messagesCount, RegistrationDTO regDto) {
160

  
161
        StringBuffer labelMarkup = new StringBuffer();
162
        DateTime registrationDate = null;
163

  
164
        if(messagesCount > 0){
141 165
            getMessageButton().setEnabled(true);
142 166
            getMessageButton().addStyleName(ValoTheme.BUTTON_FRIENDLY);
143
            getMessageButton().addClickListener(e -> publishEvent(
144
                    new ShowDetailsEvent<RegistrationDTO, Integer>(
167
            getMessageButton().addClickListener(e -> {
168
                ShowDetailsEvent detailsEvent;
169
                if(regDto != null){
170
                    detailsEvent = new ShowDetailsEvent<RegistrationDTO, Integer>(
145 171
                            e,
146 172
                            RegistrationDTO.class,
147 173
                            regDto.getId(),
148
                            "messages"))
149
                    );
174
                            "messages");
175
                } else {
176
                    detailsEvent = new ShowDetailsEvent<RegistrationWorkingSet, Integer>(
177
                            e,
178
                            RegistrationWorkingSet.class,
179
                            null,
180
                            "messages");
181
                }
182
                publishEvent(detailsEvent);
183
                }
184
            );
150 185
        }
151 186

  
152
        updateDateLabels();
153
    }
187
        labelMarkup.append(citationString);
188
        if(regDto != null){
189
            labelMarkup.append("</br>").append(regDto.getSummary());
190

  
191
            typeStateLabel.setVisible(true);
192
            typeStateLabel.update(regDto.getRegistrationType(), regDto.getStatus());
193
            getIdentifierLink().setResource(new ExternalResource(regDto.getIdentifier()));
194
            //TODO make responsive and use specificIdentifier in case the space gets too narrow
195
            getIdentifierLink().setVisible(true);
196
            getIdentifierLink().setCaption(regDto.getIdentifier());
197

  
198
            // Buttons
199
            getOpenButton().setVisible(true);
200
            getOpenButton().addClickListener(e -> publishEvent(new NavigationEvent(
201
                    RegistrationWorkflowViewBean.NAME,
202
                    RegistrationWorkflowViewBean.ACTION_EDIT,
203
                    Integer.toString(regDto.getId())
204
                    )));
205

  
206
            registrationDate = regDto.getRegistrationDate();
207
        }
154 208

  
155
    /**
156
     *
157
     */
158
    private void updateIdentifierLink() {
159
        getIdentifierLink().setResource(new ExternalResource(regDto.getIdentifier()));
160
        //TODO make responsive and use specificIdetifier in case the space gets too narrow
161
        getIdentifierLink().setCaption(regDto.getIdentifier());
209
        getCitationSummaryLabel().setValue(labelMarkup.toString());
210
        updateDateLabels(created, datePublished, registrationDate);
162 211
    }
163 212

  
213

  
164 214
    /**
165 215
     *
166 216
     */
167
    private void updateDateLabels() {
168
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + regDto.getCreated().toString(ISODateTimeFormat.yearMonthDay()));
169
        if(regDto.getRegistrationDate() != null){
170
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + regDto.getRegistrationDate().toString(ISODateTimeFormat.yearMonthDay()));
171
        } else {
172
            getPublishedLabel().setVisible(false);
217
    private void updateDateLabels(DateTime created, TimePeriod published, DateTime released) {
218
        getCreatedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_CREATED + "</span>&nbsp;" + created.toString(ISODateTimeFormat.yearMonthDay()));
219
        if(published != null){
220
            getPublishedLabel().setVisible(true);
221
            StringBuffer sb = new StringBuffer();
222
            if(published.getStart() != null){
223
                sb.append(published.getStart().toString(ISODateTimeFormat.yearMonthDay()));
224
            }
225
            if(published.getEnd() != null){
226
                if(sb.length() > 0){
227
                    sb.append('-');
228
                    sb.append(published.getEnd().toString(ISODateTimeFormat.yearMonthDay()));
229
                }
230
            }
231
            getPublishedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_PUBLISHED + "</span>&nbsp;" + sb.toString());
173 232
        }
233
        if(released != null){
234
            getReleasedLabel().setVisible(true);
235
            getReleasedLabel().setValue("<span class=\"caption\">" + LABEL_CAPTION_RELEASED + "</span>&nbsp;" + released.toString(ISODateTimeFormat.yearMonthDay()));
236
        }
237
        // LABEL_CAPTION_RELEASED
174 238
    }
175 239

  
176 240
    private void publishEvent(Object event) {
......
234 298
        return publishedLabel;
235 299
    }
236 300

  
301

  
302
    /**
303
     * @return
304
     */
305
    public Label getReleasedLabel() {
306
        return releasedLabel;
307
    }
308

  
237 309
   /* --------------------------------------- */
238 310

  
239 311
}
src/main/java/eu/etaxonomy/cdm/vaadin/event/ShowDetailsEvent.java
52 52
    /**
53 53
     * @return the type
54 54
     */
55
    public Class<T> getType() {
55
    public Class<T> getEntityType() {
56 56
        return entityType;
57 57
    }
58 58

  
src/main/java/eu/etaxonomy/cdm/vaadin/model/registration/RegistrationWorkingSet.java
13 13
import java.util.List;
14 14
import java.util.Set;
15 15

  
16
import org.joda.time.DateTime;
17

  
16 18
import eu.etaxonomy.cdm.mock.Registration;
17 19
import eu.etaxonomy.cdm.mock.RegistrationStatus;
18 20
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
......
30 32

  
31 33
    private int citationId = -1;
32 34

  
35
    private DateTime created = null;
36

  
33 37
    private String citation = null;
34 38

  
35 39
    /**
......
80 84
                    }
81 85
                }
82 86
                this.registrationDTOs.add(regDto);
87
                if(created == null || created.isAfter(regDto.getCreated())){
88
                    created = regDto.getCreated();
89
                }
83 90
        }
84 91

  
85 92
        if(!problems.isEmpty()){
......
159 166
        return citation;
160 167
    }
161 168

  
169
    public DateTime getRegistrationDate() {
170
        return registrationDTOs.get(0).getRegistrationDate();
171
    }
172

  
173
    public DateTime getCreationDate() {
174
        return registrationDTOs.get(0).getCreated();
175
    }
176

  
177
    /**
178
     * The creation time stamp of a registration set always is
179
     * the creation DateTime of the oldest Registration contained
180
     * in the set.
181
     *
182
     * @return
183
     */
184
    public DateTime getCreated(){
185
        return created;
186
    }
187

  
162 188
}
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/ListPresenter.java
47 47
        return dtos;
48 48
    }
49 49

  
50
    @EventListener(classes=ShowDetailsEvent.class) // (condition = "#event.entityType == eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO")
50
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.presenter.registration.RegistrationDTO)")
51 51
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
52 52
        RegistrationDTO regDto = serviceMock.loadDtoById((Integer)event.getIdentifier());
53 53
        if(event.getProperty().equals("messages")){
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationDTO.java
18 18

  
19 19
import eu.etaxonomy.cdm.mock.Registration;
20 20
import eu.etaxonomy.cdm.mock.RegistrationStatus;
21
import eu.etaxonomy.cdm.model.common.TimePeriod;
21 22
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 23
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
23 24
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
......
42 43

  
43 44
    private TaxonNameBase<?, ?> typifiedName;
44 45

  
46
    private TimePeriod datePublished;
47

  
45 48
    /**
46 49
     * @param reg
47 50
     * @param typifiedName should be provided in for Registrations for TypeDesignations
......
57 60
            if(citation != null){
58 61
                citationString = citation.generateTitle();
59 62
                citationID = citation.getId();
63
                datePublished = citation.getDatePublished();
60 64
            }
61 65
        } else if(registrationType.isTypification()){
62 66
            try {
......
195 199
        return reg.getRegistrationDate();
196 200
    }
197 201

  
202
    /**
203
     * @return the registrationDate
204
     */
205
    public TimePeriod getDatePublished() {
206
        return datePublished;
207
    }
208

  
198 209
    /**
199 210
     * @return the created
200 211
     */
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/registration/RegistrationWorkflowPresenter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.presenter.registration;
10 10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
11 14
import org.apache.log4j.Logger;
12 15
import org.springframework.beans.factory.annotation.Autowired;
13 16
import org.springframework.context.event.EventListener;
......
21 24
import eu.etaxonomy.cdm.model.name.Rank;
22 25
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
23 26
import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent;
27
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent;
24 28
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent;
25 29
import eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet;
26 30
import eu.etaxonomy.cdm.vaadin.view.registration.RegistrationWorkflowView;
......
90 94
        getView().openReferenceEditor(null);
91 95
    }
92 96

  
97
    @EventListener(classes=ShowDetailsEvent.class, condition = "#event.entityType == T(eu.etaxonomy.cdm.vaadin.model.registration.RegistrationWorkingSet)")
98
    public void onShowDetailsEvent(ShowDetailsEvent<?,?> event) { // WARNING don't use more specific generic type arguments
99
        List<String> messages = new ArrayList<>();
100
        for(RegistrationDTO dto : workingset.getRegistrationDTOs()){
101
            dto.getMessages().forEach(m -> messages.add(dto.getSummary() + ": " + m));
102
        }
103
        if(event.getProperty().equals("messages")){
104
            getView().openDetailsPopup("Messages", messages);
105
        }
106
    }
107

  
93 108
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowView.java
8 8
*/
9 9
package eu.etaxonomy.cdm.vaadin.view.registration;
10 10

  
11
import java.util.List;
11 12
import java.util.UUID;
12 13

  
13 14
import com.vaadin.ui.CssLayout;
......
60 61

  
61 62
    void addBlockingRegistration(RegistrationDTO blocking);
62 63

  
64
    /**
65
     * @param messages
66
     */
67
    void openDetailsPopup(String caption, List<String> messages);
68

  
63 69

  
64 70

  
65 71
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowViewBean.java
18 18
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
19 19
import com.vaadin.server.FontAwesome;
20 20
import com.vaadin.server.GenericFontIcon;
21
import com.vaadin.server.Page;
21 22
import com.vaadin.spring.annotation.SpringView;
22
import com.vaadin.ui.Alignment;
23 23
import com.vaadin.ui.Button;
24 24
import com.vaadin.ui.Component;
25 25
import com.vaadin.ui.CssLayout;
26 26
import com.vaadin.ui.GridLayout;
27 27
import com.vaadin.ui.Label;
28
import com.vaadin.ui.Notification;
28 29
import com.vaadin.ui.Panel;
29 30
import com.vaadin.ui.TabSheet;
30 31
import com.vaadin.ui.TabSheet.Tab;
31 32
import com.vaadin.ui.themes.ValoTheme;
32 33

  
33
import eu.etaxonomy.cdm.mock.RegistrationStatus;
34
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem;
34 35
import eu.etaxonomy.cdm.vaadin.component.registration.TypeStateLabel;
35 36
import eu.etaxonomy.cdm.vaadin.component.registration.WorkflowSteps;
36 37
import eu.etaxonomy.cdm.vaadin.event.EntityEventType;
......
119 120
        namesTypesPanel.setCaption("Names & Types");
120 121

  
121 122
        registration.addComponent(createWorkflowTabSheet(workingset, null));
122
        registration.addComponent(createRegistrationCaption(workingset));
123
        registration.addComponent(new RegistrationItem(workingset, this));
123 124
        registration.addComponent(namesTypesPanel);
124 125

  
125 126
        registrations.add(registration);
......
139 140

  
140 141
    }
141 142

  
142
    /**
143
     * @param workingset
144
     * @return
145
     */
146
    private Component createRegistrationCaption(RegistrationWorkingSet workingset) {
147
        String citation = workingset.getCitation();
148
        int messagesCount = workingset.messagesCount();
149
        RegistrationStatus status = workingset.lowestStatus();
150

  
151
        return createRegistrationCaption(citation, status, messagesCount);
152
    }
153

  
154
    /**
155
     * @param workingset
156
     * @return
157
     */
158
    private Component createRegistrationCaption(RegistrationDTO registrationDto) {
159
        String citation = registrationDto.getCitation();
160
        int messagesCount = registrationDto.getMessages().size();
161
        RegistrationStatus status = registrationDto.getStatus();
162

  
163
        return createRegistrationCaption(citation, status, messagesCount);
164
    }
165

  
166
    /**
167
     * @param workingset
168
     * @return
169
     */
170
    private Component createRegistrationCaption(String citation, RegistrationStatus status, int messagesCount){
171

  
172
        GridLayout grid = new GridLayout(2, 1);
173
        grid.addStyleName("registration-workflow-item");
174
        grid.setWidth(100, Unit.PERCENTAGE);
175
        Button citationButton = new Button(citation + "&nbsp;&nbsp;" + FontAwesome.EDIT.getHtml());
176
        citationButton.setHtmlContentAllowed(true);
177
        citationButton.setStyleName(ValoTheme.BUTTON_BORDERLESS);
178
        grid.addComponent(citationButton, 0, 0);
179
        grid.setComponentAlignment(citationButton, Alignment.MIDDLE_LEFT);
180
        grid.setColumnExpandRatio(0, 1.0f);
181

  
182
        CssLayout iconContainer = new CssLayout();
183
        iconContainer.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
184
        if(messagesCount > 0){
185
            Button messagesButton = new Button(FontAwesome.COMMENT);
186
            messagesButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
187
            iconContainer.addComponent(messagesButton);
188
        }
189

  
190
        WorkflowStep step = WorkflowStep.from(status, citation != null && !citation.isEmpty());
191

  
192
        Label statusIndicator = new Label(WorkflowStep.from(status, citation != null && !citation.isEmpty()).getHtml());
193
        statusIndicator.setCaptionAsHtml(true);
194
        statusIndicator.setStyleName("workflow-step label-nowrap");
195
        statusIndicator.setIcon(new GenericFontIcon("IcoMoon", 0xe900)); // triangle-right
196
        CssLayout statusWrap = new CssLayout(statusIndicator);
197
        statusWrap.setStyleName("workflow-step-wrap"); // bg-status-" + status.name());
198
        // iconContainer.addComponent(statusWrap);
199

  
200
        grid.addComponent(iconContainer, 1, 0);
201
        grid.setComponentAlignment(iconContainer, Alignment.TOP_RIGHT);
202

  
203
        return grid;
204
    }
205

  
206 143
    private Component createWorkflowTabSheet(RegistrationWorkingSet workingset, Component namesTypesPanel){
207 144

  
208 145
        if(namesTypesPanel == null){
......
361 298
        return workflow;
362 299
    }
363 300

  
301
    /**
302
     * {@inheritDoc}
303
     */
304
    @Override
305
    public void openDetailsPopup(String caption, List<String> messages) {
306
        StringBuffer sb = new StringBuffer();
307
        sb.append("<div class=\"details-popup-content\">");
308
        messages.forEach(s -> sb.append(s).append("</br>"));
309
        sb.append("</div>");
310
        new Notification(caption, sb.toString(), Notification.Type.HUMANIZED_MESSAGE, true).show(Page.getCurrent());
311
    }
364 312

  
365 313
}

Also available in: Unified diff