1 |
1c2f909e
|
Andreas Kohlbecker
|
/**
|
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 |
14fd703d
|
Andreas Kohlbecker
|
import java.text.SimpleDateFormat;
|
12 |
1c2f909e
|
Andreas Kohlbecker
|
import java.util.Collection;
|
13 |
|
|
import java.util.List;
|
14 |
0844524a
|
Andreas Kohlbecker
|
import java.util.UUID;
|
15 |
1c2f909e
|
Andreas Kohlbecker
|
|
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 |
14fd703d
|
Andreas Kohlbecker
|
import com.vaadin.ui.themes.ValoTheme;
|
31 |
1c2f909e
|
Andreas Kohlbecker
|
|
32 |
|
|
import eu.etaxonomy.cdm.ext.registration.messages.Message;
|
33 |
|
|
import eu.etaxonomy.cdm.vaadin.event.error.DelegatingErrorHandler;
|
34 |
877a8283
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
|
35 |
1affb934
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.vaadin.theme.EditValoTheme;
|
36 |
1c2f909e
|
Andreas Kohlbecker
|
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 |
14fd703d
|
Andreas Kohlbecker
|
|
63 |
1c2f909e
|
Andreas Kohlbecker
|
setCompositionRoot(mainLayout);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
14fd703d
|
Andreas Kohlbecker
|
|
67 |
1c2f909e
|
Andreas Kohlbecker
|
@Override
|
68 |
|
|
protected void initContent() {
|
69 |
|
|
|
70 |
|
|
messagesPanel = new Panel();
|
71 |
1affb934
|
Andreas Kohlbecker
|
messagesPanel.setStyleName(EditValoTheme.PANEL_CONTENT_PADDING_LEFT);
|
72 |
1c2f909e
|
Andreas Kohlbecker
|
|
73 |
|
|
newMessageField = new TextArea();
|
74 |
|
|
newMessageField.setNullRepresentation("");
|
75 |
|
|
newMessageField.addTextChangeListener(e -> {
|
76 |
|
|
sendMessageButton.setEnabled(StringUtils.isNoneBlank(e.getText()));
|
77 |
|
|
});
|
78 |
14fd703d
|
Andreas Kohlbecker
|
newMessageField.setHeight("64px"); // height of the Submit button when ValoTheme.BUTTON_HUGE
|
79 |
|
|
newMessageField.setWidth("100%");
|
80 |
1c2f909e
|
Andreas Kohlbecker
|
|
81 |
|
|
sendMessageButton = new Button(FontAwesome.SEND);
|
82 |
|
|
sendMessageButton.addClickListener(e -> postNewMessage());
|
83 |
14fd703d
|
Andreas Kohlbecker
|
sendMessageButton.setStyleName(ValoTheme.BUTTON_HUGE + " " +ValoTheme.BUTTON_PRIMARY);
|
84 |
1c2f909e
|
Andreas Kohlbecker
|
|
85 |
|
|
HorizontalLayout sendMessagebar = new HorizontalLayout(newMessageField, sendMessageButton);
|
86 |
|
|
sendMessagebar.setComponentAlignment(sendMessageButton, Alignment.MIDDLE_RIGHT);
|
87 |
|
|
sendMessagebar.setExpandRatio(newMessageField, 1f);
|
88 |
14fd703d
|
Andreas Kohlbecker
|
sendMessagebar.setWidth("100%");
|
89 |
1c2f909e
|
Andreas Kohlbecker
|
|
90 |
|
|
mainLayout.addComponents(messagesPanel, sendMessagebar);
|
91 |
|
|
|
92 |
|
|
mainLayout.setErrorHandler(errrorHandler);
|
93 |
14fd703d
|
Andreas Kohlbecker
|
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 |
1c2f909e
|
Andreas Kohlbecker
|
}
|
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 |
0844524a
|
Andreas Kohlbecker
|
public void loadMessagesFor(UUID registrationEntityUuid) {
|
171 |
|
|
getPresenter().loadMessagesFor(registrationEntityUuid);
|
172 |
1c2f909e
|
Andreas Kohlbecker
|
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
/**
|
176 |
|
|
* {@inheritDoc}
|
177 |
|
|
*/
|
178 |
|
|
@Override
|
179 |
14fd703d
|
Andreas Kohlbecker
|
public void showMessages(String registrationLabel, List<Message> messages) {
|
180 |
1c2f909e
|
Andreas Kohlbecker
|
|
181 |
|
|
VerticalLayout messagesList = new VerticalLayout();
|
182 |
|
|
|
183 |
14fd703d
|
Andreas Kohlbecker
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
|
184 |
|
|
|
185 |
1c2f909e
|
Andreas Kohlbecker
|
for(Message message : messages){
|
186 |
1affb934
|
Andreas Kohlbecker
|
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 |
1c2f909e
|
Andreas Kohlbecker
|
item.setStyleName("message-item");
|
188 |
|
|
item.setContentMode(ContentMode.HTML);
|
189 |
|
|
messagesList.addComponent(item);
|
190 |
|
|
|
191 |
|
|
}
|
192 |
14fd703d
|
Andreas Kohlbecker
|
messagesPanel.setCaption(registrationLabel);
|
193 |
1c2f909e
|
Andreas Kohlbecker
|
messagesPanel.setContent(messagesList);
|
194 |
|
|
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
// TODO move into AbstractPopupView?
|
198 |
|
|
@Override
|
199 |
|
|
public DelegatingErrorHandler getErrrorHandler(){
|
200 |
|
|
return errrorHandler;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
}
|