1
|
package eu.etaxonomy.cdm.remote.vaadin.components;
|
2
|
|
3
|
import java.io.Serializable;
|
4
|
|
5
|
import javax.annotation.PostConstruct;
|
6
|
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.context.annotation.Scope;
|
9
|
import org.springframework.security.core.context.SecurityContext;
|
10
|
import org.springframework.security.core.context.SecurityContextHolder;
|
11
|
import org.springframework.stereotype.Component;
|
12
|
|
13
|
import com.vaadin.server.ThemeResource;
|
14
|
import com.vaadin.ui.Alignment;
|
15
|
import com.vaadin.ui.Button;
|
16
|
import com.vaadin.ui.Button.ClickEvent;
|
17
|
import com.vaadin.ui.Button.ClickListener;
|
18
|
import com.vaadin.ui.HorizontalLayout;
|
19
|
import com.vaadin.ui.Image;
|
20
|
import com.vaadin.ui.Label;
|
21
|
|
22
|
import eu.etaxonomy.cdm.remote.vaadin.service.VaadinAuthenticationService;
|
23
|
|
24
|
/**
|
25
|
*
|
26
|
* This component creates a simple toolbar. It also makes use of the AuthenticationController.
|
27
|
*
|
28
|
* @author a.oppermann
|
29
|
*
|
30
|
*/
|
31
|
|
32
|
@Component
|
33
|
@Scope("request")
|
34
|
public class HorizontalToolbar extends HorizontalLayout implements Serializable{
|
35
|
|
36
|
|
37
|
/**
|
38
|
* automatically generated ID
|
39
|
*/
|
40
|
private static final long serialVersionUID = 5344340511582993289L;
|
41
|
|
42
|
@Autowired
|
43
|
private transient VaadinAuthenticationService authenticationController;
|
44
|
|
45
|
private final Button editButton = new Button("Edit");
|
46
|
|
47
|
private final Button saveButton = new Button("Save");
|
48
|
|
49
|
private final Button detailButton = new Button("Detail");
|
50
|
|
51
|
private final Button logoutButton= new Button("Logout");
|
52
|
|
53
|
// private ExcelExporter exporter = new ExcelExporter();
|
54
|
|
55
|
|
56
|
@PostConstruct
|
57
|
public void PostConstruct() {
|
58
|
if(authenticationController.isAuthenticated()){
|
59
|
setMargin(true);
|
60
|
setSpacing(true);
|
61
|
setStyleName("toolbar");
|
62
|
setWidth("100%");
|
63
|
setHeight("75px");
|
64
|
|
65
|
addComponent(editButton);
|
66
|
addComponent(saveButton);
|
67
|
addComponent(detailButton);
|
68
|
// addComponent(exporter);
|
69
|
|
70
|
// exporter.setCaption("Export");
|
71
|
// exporter.setIcon(new ThemeResource("icons/32/document-xsl.png"));
|
72
|
|
73
|
saveButton.setIcon(new ThemeResource("icons/32/document-save.png"));
|
74
|
editButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
|
75
|
detailButton.setIcon(new ThemeResource("icons/32/document-txt.png"));
|
76
|
logoutButton.setIcon(new ThemeResource("icons/32/cancel.png"));
|
77
|
|
78
|
// SecurityContext context = (SecurityContext)VaadinService.getCurrentRequest().getWrappedSession().getAttribute("context");
|
79
|
SecurityContext context = SecurityContextHolder.getContext();
|
80
|
Label loginName = new Label(authenticationController.getUserName());
|
81
|
loginName.setIcon(new ThemeResource("icons/32/user.png"));
|
82
|
|
83
|
HorizontalLayout rightLayout = new HorizontalLayout();
|
84
|
Image image = new Image(null, new ThemeResource("icons/32/vseparator1.png"));
|
85
|
rightLayout.addComponent(logoutButton);
|
86
|
rightLayout.addComponent(image);
|
87
|
rightLayout.addComponent(loginName);
|
88
|
|
89
|
addComponent(rightLayout);
|
90
|
setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT);
|
91
|
setExpandRatio(rightLayout, 1);
|
92
|
|
93
|
logoutButton.addClickListener(new ClickListener() {
|
94
|
|
95
|
/**
|
96
|
* automatically generated ID
|
97
|
*/
|
98
|
private static final long serialVersionUID = 8380401487511285303L;
|
99
|
|
100
|
public void buttonClick(ClickEvent event) {
|
101
|
|
102
|
authenticationController.logout();
|
103
|
|
104
|
}
|
105
|
});
|
106
|
}
|
107
|
}
|
108
|
|
109
|
public Button getEditButton() {
|
110
|
return editButton;
|
111
|
}
|
112
|
|
113
|
public Button getSaveButton() {
|
114
|
return saveButton;
|
115
|
}
|
116
|
|
117
|
public Button getDetailButton() {
|
118
|
return detailButton;
|
119
|
}
|
120
|
}
|