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.text.SimpleDateFormat;
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang3.StringUtils;
|
17
|
import org.springframework.context.annotation.Scope;
|
18
|
import org.springframework.security.core.GrantedAuthority;
|
19
|
|
20
|
import com.vaadin.server.FontAwesome;
|
21
|
import com.vaadin.shared.ui.label.ContentMode;
|
22
|
import com.vaadin.spring.annotation.SpringComponent;
|
23
|
import com.vaadin.ui.Alignment;
|
24
|
import com.vaadin.ui.Button;
|
25
|
import com.vaadin.ui.HorizontalLayout;
|
26
|
import com.vaadin.ui.Label;
|
27
|
import com.vaadin.ui.Panel;
|
28
|
import com.vaadin.ui.TextArea;
|
29
|
import com.vaadin.ui.VerticalLayout;
|
30
|
import com.vaadin.ui.themes.ValoTheme;
|
31
|
|
32
|
import eu.etaxonomy.cdm.ext.registration.messages.Message;
|
33
|
import eu.etaxonomy.cdm.vaadin.event.error.DelegatingErrorHandler;
|
34
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
35
|
import eu.etaxonomy.cdm.vaadin.theme.EditValoTheme;
|
36
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupView;
|
37
|
|
38
|
@SpringComponent
|
39
|
@Scope("prototype")
|
40
|
public class RegistrationMessagesPopup extends AbstractPopupView<RegistrationMessagesPresenter>
|
41
|
implements RegistrationMessagesView, AccessRestrictedView {
|
42
|
|
43
|
private static final long serialVersionUID = 713522519903334889L;
|
44
|
|
45
|
Panel messagesPanel;
|
46
|
|
47
|
TextArea newMessageField;
|
48
|
|
49
|
Button sendMessageButton;
|
50
|
|
51
|
private VerticalLayout mainLayout;
|
52
|
|
53
|
private DelegatingErrorHandler errrorHandler = new DelegatingErrorHandler();
|
54
|
|
55
|
public RegistrationMessagesPopup() {
|
56
|
|
57
|
mainLayout = new VerticalLayout();
|
58
|
// IMPORTANT: mainLayout must be set to full size otherwise the
|
59
|
// popup window may have problems with automatic resizing of its
|
60
|
// content.
|
61
|
mainLayout.setSizeFull();
|
62
|
|
63
|
setCompositionRoot(mainLayout);
|
64
|
}
|
65
|
|
66
|
|
67
|
@Override
|
68
|
protected void initContent() {
|
69
|
|
70
|
messagesPanel = new Panel();
|
71
|
messagesPanel.setStyleName(EditValoTheme.PANEL_CONTENT_PADDING_LEFT);
|
72
|
|
73
|
newMessageField = new TextArea();
|
74
|
newMessageField.setNullRepresentation("");
|
75
|
newMessageField.addTextChangeListener(e -> {
|
76
|
sendMessageButton.setEnabled(StringUtils.isNoneBlank(e.getText()));
|
77
|
});
|
78
|
newMessageField.setHeight("64px"); // height of the Submit button when ValoTheme.BUTTON_HUGE
|
79
|
newMessageField.setWidth("100%");
|
80
|
|
81
|
sendMessageButton = new Button(FontAwesome.SEND);
|
82
|
sendMessageButton.addClickListener(e -> postNewMessage());
|
83
|
sendMessageButton.setStyleName(ValoTheme.BUTTON_HUGE + " " +ValoTheme.BUTTON_PRIMARY);
|
84
|
|
85
|
HorizontalLayout sendMessagebar = new HorizontalLayout(newMessageField, sendMessageButton);
|
86
|
sendMessagebar.setComponentAlignment(sendMessageButton, Alignment.MIDDLE_RIGHT);
|
87
|
sendMessagebar.setExpandRatio(newMessageField, 1f);
|
88
|
sendMessagebar.setWidth("100%");
|
89
|
|
90
|
mainLayout.addComponents(messagesPanel, sendMessagebar);
|
91
|
|
92
|
mainLayout.setErrorHandler(errrorHandler);
|
93
|
mainLayout.setComponentAlignment(sendMessagebar, Alignment.BOTTOM_CENTER);
|
94
|
}
|
95
|
|
96
|
|
97
|
@Override
|
98
|
public int getWindowHeight() {
|
99
|
// undefined
|
100
|
return -1;
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public boolean isClosable() {
|
105
|
return true;
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public boolean isResizable() {
|
110
|
return true;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* @return
|
115
|
*/
|
116
|
private void postNewMessage() {
|
117
|
// quick and dirty implementation, better send an event
|
118
|
String text = newMessageField.getValue();
|
119
|
if(StringUtils.isNotBlank(text)){
|
120
|
getPresenter().postMessage(text);
|
121
|
newMessageField.setValue(null);
|
122
|
}
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* {@inheritDoc}
|
127
|
*/
|
128
|
@Override
|
129
|
public String getWindowCaption() {
|
130
|
return "Messages";
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* {@inheritDoc}
|
135
|
*/
|
136
|
@Override
|
137
|
public void focusFirst() {
|
138
|
// none
|
139
|
}
|
140
|
|
141
|
|
142
|
/**
|
143
|
* {@inheritDoc}
|
144
|
*/
|
145
|
@Override
|
146
|
public boolean allowAnonymousAccess() {
|
147
|
return false;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* {@inheritDoc}
|
152
|
*/
|
153
|
@Override
|
154
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
155
|
return null;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* {@inheritDoc}
|
160
|
*/
|
161
|
@Override
|
162
|
public void cancel() {
|
163
|
// not needed
|
164
|
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* @param identifier
|
169
|
*/
|
170
|
public void loadMessagesFor(UUID registrationEntityUuid) {
|
171
|
getPresenter().loadMessagesFor(registrationEntityUuid);
|
172
|
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* {@inheritDoc}
|
177
|
*/
|
178
|
@Override
|
179
|
public void showMessages(String registrationLabel, List<Message> messages) {
|
180
|
|
181
|
VerticalLayout messagesList = new VerticalLayout();
|
182
|
|
183
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
|
184
|
|
185
|
for(Message message : messages){
|
186
|
Label item = new Label("<span class=\"date-time\">(" + dateFormat.format(message.getCreatedOn()) + ")</span> <span class=\"user-name\">" + message.getFrom().getUsername() + "</span>: <span class=\"message-text\">" + message.getText() + "</span>");
|
187
|
item.setStyleName("message-item");
|
188
|
item.setContentMode(ContentMode.HTML);
|
189
|
messagesList.addComponent(item);
|
190
|
|
191
|
}
|
192
|
messagesPanel.setCaption(registrationLabel);
|
193
|
messagesPanel.setContent(messagesList);
|
194
|
|
195
|
}
|
196
|
|
197
|
// TODO move into AbstractPopupView?
|
198
|
@Override
|
199
|
public DelegatingErrorHandler getErrrorHandler(){
|
200
|
return errrorHandler;
|
201
|
}
|
202
|
|
203
|
|
204
|
}
|