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.ui;
|
10
|
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.context.ApplicationEventPublisher;
|
13
|
import org.springframework.context.annotation.Lazy;
|
14
|
|
15
|
import com.vaadin.annotations.Theme;
|
16
|
import com.vaadin.annotations.Title;
|
17
|
import com.vaadin.annotations.Viewport;
|
18
|
import com.vaadin.annotations.Widgetset;
|
19
|
import com.vaadin.navigator.ViewDisplay;
|
20
|
import com.vaadin.server.ExternalResource;
|
21
|
import com.vaadin.server.FontAwesome;
|
22
|
import com.vaadin.server.Page;
|
23
|
import com.vaadin.server.Resource;
|
24
|
import com.vaadin.server.Responsive;
|
25
|
import com.vaadin.server.VaadinRequest;
|
26
|
import com.vaadin.spring.annotation.SpringUI;
|
27
|
import com.vaadin.spring.navigator.SpringViewProvider;
|
28
|
import com.vaadin.ui.Component;
|
29
|
import com.vaadin.ui.Label;
|
30
|
import com.vaadin.ui.UI;
|
31
|
import com.vaadin.ui.themes.ValoTheme;
|
32
|
|
33
|
import eu.etaxonomy.cdm.dataInserter.RegistrationRequiredDataInserter;
|
34
|
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView;
|
35
|
import eu.etaxonomy.cdm.vaadin.view.registration.DashBoardView;
|
36
|
import eu.etaxonomy.cdm.vaadin.view.registration.ListViewBean;
|
37
|
import eu.etaxonomy.cdm.vaadin.view.registration.StartRegistrationViewBean;
|
38
|
import eu.etaxonomy.vaadin.ui.MainMenu;
|
39
|
import eu.etaxonomy.vaadin.ui.UIInitializedEvent;
|
40
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
41
|
|
42
|
/**
|
43
|
* @author a.kohlbecker
|
44
|
* @since Feb 24, 2017
|
45
|
*
|
46
|
*/
|
47
|
@Theme("edit-valo")
|
48
|
@Title("Registration")
|
49
|
@SpringUI(path="registration")
|
50
|
@Viewport("width=device-width, initial-scale=1")
|
51
|
@Widgetset("eu.etaxonomy.cdm.vaadin.AppWidgetSet")
|
52
|
// @PreserveOnRefresh
|
53
|
// @Push
|
54
|
public class RegistrationUI extends UI {
|
55
|
|
56
|
private static final long serialVersionUID = -8626236111335323691L;
|
57
|
|
58
|
@Autowired
|
59
|
private ViewDisplay viewDisplay;
|
60
|
|
61
|
/**
|
62
|
* The RegistrationDefaultDataInserter is not used in the ui directly
|
63
|
* but will as a ApplicationListener for ContextRefreshedEvents insert
|
64
|
* data required for the registration application into the database.
|
65
|
*/
|
66
|
@SuppressWarnings("unused")
|
67
|
@Autowired
|
68
|
@Lazy
|
69
|
private RegistrationRequiredDataInserter dataInserter;
|
70
|
|
71
|
//---- pull into abstract super class ? ---------
|
72
|
@Autowired
|
73
|
SpringViewProvider viewProvider;
|
74
|
|
75
|
protected void configureAccessDeniedView() {
|
76
|
viewProvider.setAccessDeniedViewClass(RedirectToLoginView.class);
|
77
|
}
|
78
|
//---------------------------------------------
|
79
|
|
80
|
public static final String INITIAL_VIEW = DashBoardView.NAME;
|
81
|
|
82
|
|
83
|
/*
|
84
|
* this HACKY solution forces the bean to be instantiated, TODO do it properly
|
85
|
*/
|
86
|
// @Autowired
|
87
|
// MenuBeanDiscoveryBean bean;
|
88
|
|
89
|
@Autowired
|
90
|
private MainMenu mainMenu;
|
91
|
|
92
|
@Autowired
|
93
|
ApplicationEventPublisher eventBus;
|
94
|
|
95
|
public RegistrationUI() {
|
96
|
|
97
|
}
|
98
|
|
99
|
@Override
|
100
|
protected void init(VaadinRequest request) {
|
101
|
|
102
|
configureAccessDeniedView();
|
103
|
|
104
|
addStyleName(ValoTheme.UI_WITH_MENU);
|
105
|
Responsive.makeResponsive(this);
|
106
|
|
107
|
setContent((Component) viewDisplay);
|
108
|
Label phycoBankLogo = new Label("PhycoBank");
|
109
|
phycoBankLogo.addStyleName("phycobank-green");
|
110
|
phycoBankLogo.addStyleName(ValoTheme.LABEL_HUGE);
|
111
|
mainMenu.addMenuComponent(phycoBankLogo);
|
112
|
|
113
|
mainMenu.addMenuItem("New", FontAwesome.EDIT, StartRegistrationViewBean.NAME );
|
114
|
mainMenu.addMenuItem("Continue", FontAwesome.ARROW_RIGHT, ListViewBean.NAME + "/" + ListViewBean.OPTION_IN_PROGRESS);
|
115
|
mainMenu.addMenuItem("List", FontAwesome.TASKS, ListViewBean.NAME + "/" + ListViewBean.OPTION_ALL);
|
116
|
|
117
|
eventBus.publishEvent(new UIInitializedEvent());
|
118
|
|
119
|
String brand = "phycobank";
|
120
|
//TODO create annotation:
|
121
|
// @Styles(files={""}, branding="brand")
|
122
|
//
|
123
|
// the branding can either be specified or can be read from the properties file in .cdmLibrary/remote-webapp/{instance-name}-app.properties
|
124
|
// See CdmUtils for appropriate methods to access this folder
|
125
|
// the 'vaadin://' protocol refers to the VAADIN folder
|
126
|
Resource registryCssFile = new ExternalResource("vaadin://branding/" + brand + "/css/branding.css");
|
127
|
Page.getCurrent().getStyles().add(registryCssFile);
|
128
|
|
129
|
//navigate to initial view
|
130
|
String state = pageFragmentAsState();
|
131
|
|
132
|
if(state == null){
|
133
|
// the case when state != null is handled in the UI base class
|
134
|
eventBus.publishEvent(new NavigationEvent(INITIAL_VIEW));
|
135
|
}
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* @return
|
140
|
*/
|
141
|
private String pageFragmentAsState() {
|
142
|
Page page = Page.getCurrent();
|
143
|
String fragment = page.getUriFragment();
|
144
|
String state = null;
|
145
|
if(fragment != null && fragment.startsWith("!")){
|
146
|
state = fragment.substring(1, fragment.length());
|
147
|
}
|
148
|
return state;
|
149
|
}
|
150
|
}
|