Project

General

Profile

« Previous | Next » 

Revision eca2b6b0

Added by Andreas Kohlbecker over 6 years ago

fix #6997 toolbar with login logout and user name and icon

View differences:

src/main/java/eu/etaxonomy/cdm/service/CdmUserHelper.java
127 127
        return false;
128 128
    }
129 129

  
130
    public void logout() {
131
        SecurityContext context = SecurityContextHolder.getContext();
132
        context.setAuthentication(null);
133
        SecurityContextHolder.clearContext();
134
    }
135

  
130 136

  
131 137
    private EnumSet<CRUD> crudSetFromArgs(Object[] args) {
132 138
        EnumSet<CRUD> crudSet = EnumSet.noneOf(CRUD.class);
src/main/java/eu/etaxonomy/cdm/vaadin/event/AuthenticationSuccessEvent.java
27 27
        this.userName = userName;
28 28
    }
29 29

  
30
    public String getUserName(){
31
        return userName;
32
    }
33

  
30 34
}
src/main/java/eu/etaxonomy/cdm/vaadin/toolbar/RegistrationToolbar.java
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.toolbar;
10

  
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Qualifier;
13
import org.springframework.context.ApplicationEventPublisher;
14
import org.springframework.context.event.EventListener;
15

  
16
import com.vaadin.server.FontAwesome;
17
import com.vaadin.spring.annotation.SpringComponent;
18
import com.vaadin.spring.annotation.UIScope;
19
import com.vaadin.ui.Alignment;
20
import com.vaadin.ui.Button;
21
import com.vaadin.ui.CssLayout;
22
import com.vaadin.ui.HorizontalLayout;
23
import com.vaadin.ui.themes.ValoTheme;
24

  
25
import eu.etaxonomy.cdm.api.application.CdmRepository;
26
import eu.etaxonomy.cdm.service.CdmUserHelper;
27
import eu.etaxonomy.cdm.vaadin.event.AuthenticationSuccessEvent;
28
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
29
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
30

  
31
/**
32
 *
33
 * @author a.kohlbecker
34
 * @since Sep 28, 2017
35
 *
36
 */
37
@SpringComponent("registrationToolbar")
38
@UIScope
39
public class RegistrationToolbar extends HorizontalLayout implements Toolbar {
40

  
41
    private static final long serialVersionUID = 2594781255088231474L;
42

  
43
    @Autowired
44
    protected ApplicationEventPublisher eventBus;
45

  
46
    @Autowired
47
    @Qualifier("cdmRepository")
48
    private CdmRepository repo;
49

  
50
    @Autowired
51
    protected NavigationManager navigationManager;
52

  
53
    @Autowired
54
    CdmUserHelper userHelper;
55

  
56
    CssLayout buttonGroup = new CssLayout();
57
    Button messageButton;
58
    Button loginButton;
59
    Button logoutButton;
60
    Button userButton;
61

  
62
    public RegistrationToolbar() {
63
    }
64

  
65
    @Override
66
    public void initialize(){
67

  
68
        setWidth("100%");
69
        buttonGroup.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
70
        messageButton = new Button(FontAwesome.COMMENT);
71
        loginButton = new Button("login");
72
        userButton = new Button(FontAwesome.USER);
73
        logoutButton = new Button("logout");
74

  
75
        messageButton.setEnabled(false);
76
        logoutButton.addClickListener(e -> performLogut());
77
        loginButton.addClickListener(e -> performLogin());
78
        buttonGroup.addComponent(messageButton);
79
        buttonGroup.addComponent(loginButton);
80
        buttonGroup.addComponent(logoutButton);
81
        buttonGroup.addComponent(userButton);
82
        addComponent(buttonGroup);
83
        setComponentAlignment(buttonGroup, Alignment.MIDDLE_RIGHT);
84
        updateAuthenticationButtons();
85
    }
86

  
87

  
88
    @EventListener
89
    public void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event){
90
        updateAuthenticationButtons();
91
    }
92

  
93
    /**
94
     * @param event
95
     */
96
    protected void updateAuthenticationButtons() {
97

  
98
        if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()){
99
            userButton.setCaption(userHelper.userName());
100
            userButton.setVisible(true);
101
            messageButton.setVisible(true);
102
            logoutButton.setVisible(true);
103
            loginButton.setVisible(false);
104

  
105
        } else {
106
            userButton.setCaption(null);
107
            userButton.setVisible(false);
108
            messageButton.setVisible(false);
109
            logoutButton.setVisible(false);
110
            loginButton.setVisible(true);
111
        }
112
    }
113

  
114
    /**
115
     * @return
116
     */
117
    private void performLogin() {
118
        eventBus.publishEvent(new NavigationEvent("login", navigationManager.getCurrentViewName()));
119
    }
120

  
121

  
122
    private void performLogut() {
123

  
124
        userHelper.logout();
125
        updateAuthenticationButtons();
126
        navigationManager.reloadCurrentView();
127
    }
128

  
129
}
src/main/java/eu/etaxonomy/cdm/vaadin/toolbar/Toolbar.java
1
package eu.etaxonomy.cdm.vaadin.toolbar;
2

  
3
import eu.etaxonomy.vaadin.ui.CanCastComponent;
4

  
5
public interface Toolbar extends CanCastComponent {
6

  
7
    public void initialize();
8

  
9

  
10
}
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java
9 9
package eu.etaxonomy.cdm.vaadin.ui;
10 10

  
11 11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Qualifier;
12 13
import org.springframework.context.ApplicationEventPublisher;
13 14

  
14 15
import com.vaadin.annotations.Theme;
......
29 30
import com.vaadin.ui.UI;
30 31
import com.vaadin.ui.themes.ValoTheme;
31 32

  
33
import eu.etaxonomy.cdm.vaadin.toolbar.Toolbar;
32 34
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView;
33 35
import eu.etaxonomy.cdm.vaadin.view.registration.DashBoardView;
34 36
import eu.etaxonomy.cdm.vaadin.view.registration.ListViewBean;
......
36 38
import eu.etaxonomy.vaadin.ui.MainMenu;
37 39
import eu.etaxonomy.vaadin.ui.UIInitializedEvent;
38 40
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
41
import eu.etaxonomy.vaadin.ui.view.ToolbarDisplay;
39 42

  
40 43
/**
41 44
 * @author a.kohlbecker
......
92 95
    private MainMenu mainMenu;
93 96

  
94 97
    @Autowired
98
    @Qualifier("registrationToolbar")
99
    private Toolbar toolbar;
100

  
101
    @Autowired
95 102
    ApplicationEventPublisher eventBus;
96 103

  
97 104
    public RegistrationUI() {
......
116 123
        mainMenu.addMenuItem("Continue", FontAwesome.ARROW_RIGHT, ListViewBean.NAME + "/" + ListViewBean.OPTION_IN_PROGRESS);
117 124
        mainMenu.addMenuItem("List", FontAwesome.TASKS, ListViewBean.NAME + "/" + ListViewBean.OPTION_ALL);
118 125

  
126
        if(ToolbarDisplay.class.isAssignableFrom(viewDisplay.getClass())){
127
            ((ToolbarDisplay)viewDisplay).setToolbar(toolbar);
128
        }
129

  
119 130
        eventBus.publishEvent(new UIInitializedEvent());
120 131

  
121 132
        String brand = "phycobank";
src/main/java/eu/etaxonomy/cdm/vaadin/view/LoginPresenter.java
23 23
import com.vaadin.spring.annotation.UIScope;
24 24

  
25 25
import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
26
import eu.etaxonomy.cdm.vaadin.event.AuthenticationSuccessEvent;
26 27
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
27 28
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
28 29
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
......
70 71
            log.debug("user '" + userName + "' authenticated");
71 72
            currentSecurityContext().setAuthentication(authentication);
72 73
            if(NavigationManager.class.isAssignableFrom(getNavigationManager().getClass())){
73
               /// eventBus.publishEvent(new AuthenticationSuccessEvent(userName));
74
                eventBus.publishEvent(new AuthenticationSuccessEvent(userName));
74 75
                log.debug("redirecting to " + redirectToState);
75 76
                eventBus.publishEvent(new NavigationEvent(redirectToState));
76 77
            }
......
85 86
     */
86 87
    @Override
87 88
    public void handleViewEntered() {
89

  
88 90
        List<String> redirectToStateTokens = getNavigationManager().getCurrentViewParameters();
89
        redirectToState = String.join("/", redirectToStateTokens);
91
        String currentViewName = getNavigationManager().getCurrentViewName();
92

  
93
        if(currentViewName.equals(LoginViewBean.NAME) && redirectToStateTokens.isEmpty()){
94
            // login view is shown in turn to an explicit login request of the user (e.g. login button pressed)
95
            // use the redirectToStateTokens 1-n as redirectToState
96
            //FIXME implement : redirectToState = UserView.NAME
97

  
98
        } else {
99
            // the login view is shown instead of the requested view for which the user needs to login
100
            redirectToState = String.join("/", redirectToStateTokens);
101
        }
90 102

  
91 103
        // attempt to auto login
92 104
        if(StringUtils.isNotEmpty(System.getProperty(PROPNAME_USER)) && StringUtils.isNotEmpty(System.getProperty(PROPNAME_PASSWORD))){
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManager.java
17 17

  
18 18
	void reloadCurrentView();
19 19

  
20
	public String getCurrentViewName();
21

  
20 22
	/**
21 23
	 *
22 24
	 * @return
src/main/java/eu/etaxonomy/vaadin/ui/view/ToolbarDisplay.java
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.vaadin.ui.view;
10

  
11
import eu.etaxonomy.cdm.vaadin.toolbar.Toolbar;
12

  
13
/**
14
 * @author a.kohlbecker
15
 * @since Sep 28, 2017
16
 *
17
 */
18
public interface ToolbarDisplay {
19

  
20
    void setToolbar(Toolbar toolbar);
21

  
22
}
src/main/java/eu/etaxonomy/vaadin/ui/view/ViewAreaBean.java
10 10
import com.vaadin.ui.CssLayout;
11 11
import com.vaadin.ui.HorizontalLayout;
12 12

  
13
import eu.etaxonomy.cdm.vaadin.toolbar.Toolbar;
13 14
import eu.etaxonomy.vaadin.ui.MainMenu;
14 15

  
15 16
/**
......
23 24

  
24 25
@SpringComponent
25 26
@UIScope
26
class ViewAreaBean extends HorizontalLayout implements ViewDisplay {
27
class ViewAreaBean extends HorizontalLayout implements ViewDisplay, ToolbarDisplay {
27 28

  
28 29
    private static final long serialVersionUID = -3763800167385449693L;
29 30

  
30 31
	private MainMenu mainMenu;
31 32

  
33
	private Component toolbar = null;
34

  
32 35
	private CssLayout contentArea;
33 36

  
34
	public ViewAreaBean() {
35
		setSizeFull();
37
	private CssLayout mainArea;
36 38

  
37
		contentArea = new CssLayout();
38
		contentArea.setPrimaryStyleName("valo-content");
39
		contentArea.addStyleName("v-scrollable");
40
		contentArea.setSizeFull();
39
    public ViewAreaBean() {
41 40

  
42
		addComponent(contentArea);
43
		setExpandRatio(contentArea, 1);
44
	}
41
        setSizeFull();
42

  
43
        mainArea = new CssLayout();
44
        mainArea.setPrimaryStyleName("valo-toolbar");
45
        mainArea.setSizeFull();
46
        contentArea = new CssLayout();
47
        contentArea.setPrimaryStyleName("valo-content");
48
        contentArea.addStyleName("v-scrollable");
49
        contentArea.setSizeFull();
50

  
51
        mainArea.addComponent(contentArea);
52
        addComponent(mainArea);
53
        setExpandRatio(mainArea, 1);
54
    }
45 55

  
46 56
	@Autowired
47 57
	public void setMainMenu(MainMenu mainMenu) {
......
49 59
	    addComponentAsFirst(this.mainMenu.asComponent());
50 60
	}
51 61

  
52
// TODO was this needed to avoid bean loading problems? Otherwise remove it
53
//	private MainMenu mainMenuInstantiator;
54
//	@PostConstruct
55
//	protected void initialize() {
56
//		if (mainMenuInstantiator.isAmbiguous()) {
57
//			throw new RuntimeException("Ambiguous main menu implementations available, please refine your deployment");
58
//		}
59
//
60
//		if (!mainMenuInstantiator.isUnsatisfied()) {
61
//			mainMenu = mainMenuInstantiator.get();
62
//			addComponentAsFirst(mainMenu.asComponent());
63
//		}
64
//	}
62

  
63
    @Override
64
    public void setToolbar(Toolbar toolbar) {
65
        toolbar.initialize();
66
        this.toolbar = toolbar.asComponent();
67
        this.toolbar.setPrimaryStyleName("valo-navigation-bar");
68
        mainArea.addComponentAsFirst(this.toolbar);
69
    }
65 70

  
66 71
	@Override
67 72
	public void showView(View view) {
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss
27 27
// ================== DARK ================ //
28 28

  
29 29
// $v-app-loading-text: "Dark Valo";
30
/*
31
*/
30 32
$v-background-color: #444d50;
31 33
$v-focus-color: #07a9ca;
32 34
$v-focus-style: 0 0 3px 2px $v-focus-color;

Also available in: Unified diff