1
|
package eu.etaxonomy.cdm.vaadin.component;
|
2
|
|
3
|
import java.io.Serializable;
|
4
|
|
5
|
import org.springframework.security.core.Authentication;
|
6
|
import org.springframework.security.core.context.SecurityContext;
|
7
|
import org.springframework.security.core.context.SecurityContextHolder;
|
8
|
|
9
|
import com.vaadin.server.Page;
|
10
|
import com.vaadin.server.ThemeResource;
|
11
|
import com.vaadin.server.VaadinServlet;
|
12
|
import com.vaadin.server.VaadinSession;
|
13
|
import com.vaadin.ui.Alignment;
|
14
|
import com.vaadin.ui.Button;
|
15
|
import com.vaadin.ui.Button.ClickEvent;
|
16
|
import com.vaadin.ui.Button.ClickListener;
|
17
|
import com.vaadin.ui.HorizontalLayout;
|
18
|
import com.vaadin.ui.Image;
|
19
|
import com.vaadin.ui.Label;
|
20
|
import com.vaadin.ui.UI;
|
21
|
|
22
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
|
23
|
|
24
|
public class HorizontalToolbar extends HorizontalLayout implements Serializable{
|
25
|
|
26
|
|
27
|
/**
|
28
|
* automatically generated ID
|
29
|
*/
|
30
|
private static final long serialVersionUID = 5344340511582993289L;
|
31
|
|
32
|
|
33
|
private final Button editButton = new Button("Edit");
|
34
|
|
35
|
private final Button saveButton = new Button("Save");
|
36
|
|
37
|
private final Button detailButton = new Button("Detail");
|
38
|
|
39
|
private final Button settingsButton = new Button("Settings");
|
40
|
|
41
|
private final Button logoutButton= new Button("Logout");
|
42
|
|
43
|
private final Authentication authentication;
|
44
|
// private ExcelExporter exporter = new ExcelExporter();
|
45
|
|
46
|
public HorizontalToolbar() {
|
47
|
// authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
|
48
|
CdmVaadinAuthentication authentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
|
49
|
this.authentication = authentication.getAuthentication(Page.getCurrent().getLocation(), VaadinServlet.getCurrent().getServletContext().getContextPath());
|
50
|
init();
|
51
|
}
|
52
|
|
53
|
public void init() {
|
54
|
if(authentication != null && authentication.isAuthenticated()){
|
55
|
setMargin(true);
|
56
|
setSpacing(true);
|
57
|
setStyleName("toolbar");
|
58
|
setWidth("100%");
|
59
|
setHeight("75px");
|
60
|
|
61
|
// addComponent(editButton);
|
62
|
addComponent(saveButton);
|
63
|
addComponent(detailButton);
|
64
|
// addComponent(exporter);
|
65
|
|
66
|
// exporter.setCaption("Export");
|
67
|
// exporter.setIcon(new ThemeResource("icons/32/document-xsl.png"));
|
68
|
|
69
|
saveButton.setIcon(new ThemeResource("icons/32/document-save.png"));
|
70
|
editButton.setIcon(new ThemeResource("icons/32/document-edit.png"));
|
71
|
detailButton.setIcon(new ThemeResource("icons/32/document-txt.png"));
|
72
|
settingsButton.setIcon(new ThemeResource("icons/32/settings_1.png"));
|
73
|
logoutButton.setIcon(new ThemeResource("icons/32/cancel.png"));
|
74
|
|
75
|
// SecurityContext context = (SecurityContext)VaadinService.getCurrentRequest().getWrappedSession().getAttribute("context");
|
76
|
SecurityContext context = SecurityContextHolder.getContext();
|
77
|
Label loginName = new Label(authentication.getName().toString());
|
78
|
loginName.setIcon(new ThemeResource("icons/32/user.png"));
|
79
|
|
80
|
HorizontalLayout rightLayout = new HorizontalLayout();
|
81
|
Image image = new Image(null, new ThemeResource("icons/32/vseparator1.png"));
|
82
|
rightLayout.addComponent(settingsButton);
|
83
|
rightLayout.addComponent(logoutButton);
|
84
|
rightLayout.addComponent(image);
|
85
|
rightLayout.addComponent(loginName);
|
86
|
|
87
|
addComponent(rightLayout);
|
88
|
setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT);
|
89
|
setExpandRatio(rightLayout, 1);
|
90
|
|
91
|
logoutButton.addClickListener(new ClickListener() {
|
92
|
|
93
|
/**
|
94
|
* automatically generated ID
|
95
|
*/
|
96
|
private static final long serialVersionUID = 8380401487511285303L;
|
97
|
|
98
|
@Override
|
99
|
public void buttonClick(ClickEvent event) {
|
100
|
|
101
|
authentication.setAuthenticated(false);
|
102
|
UI.getCurrent().getNavigator().navigateTo("abstractAuthenticatedUI");
|
103
|
}
|
104
|
});
|
105
|
}
|
106
|
}
|
107
|
|
108
|
public Button getSettingsButton(){
|
109
|
return settingsButton;
|
110
|
}
|
111
|
|
112
|
public Button getEditButton() {
|
113
|
return editButton;
|
114
|
}
|
115
|
|
116
|
public Button getSaveButton() {
|
117
|
return saveButton;
|
118
|
}
|
119
|
|
120
|
public Button getDetailButton() {
|
121
|
return detailButton;
|
122
|
}
|
123
|
}
|