Revision cac8806b
Added by Andreas Kohlbecker over 2 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/ui/RegistrationUI.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 12 |
import org.springframework.beans.factory.annotation.Qualifier; |
13 |
import org.vaadin.spring.events.EventBus.UIEventBus; |
|
14 | 13 |
|
15 | 14 |
import com.flowingcode.vaadin.addons.errorwindow.WindowErrorHandler; |
16 | 15 |
import com.vaadin.annotations.Theme; |
... | ... | |
18 | 17 |
import com.vaadin.annotations.Viewport; |
19 | 18 |
import com.vaadin.annotations.Widgetset; |
20 | 19 |
import com.vaadin.navigator.ViewDisplay; |
21 |
import com.vaadin.server.ExternalResource; |
|
22 | 20 |
import com.vaadin.server.FontAwesome; |
23 |
import com.vaadin.server.Page; |
|
24 |
import com.vaadin.server.Resource; |
|
25 |
import com.vaadin.server.Responsive; |
|
26 | 21 |
import com.vaadin.server.VaadinRequest; |
27 | 22 |
import com.vaadin.server.VaadinSession; |
28 | 23 |
import com.vaadin.spring.annotation.SpringUI; |
29 |
import com.vaadin.spring.navigator.SpringViewProvider; |
|
30 |
import com.vaadin.ui.Component; |
|
31 | 24 |
import com.vaadin.ui.Label; |
32 |
import com.vaadin.ui.UI; |
|
33 | 25 |
import com.vaadin.ui.themes.ValoTheme; |
34 | 26 |
|
35 | 27 |
import eu.etaxonomy.cdm.database.PermissionDeniedException; |
... | ... | |
38 | 30 |
import eu.etaxonomy.cdm.vaadin.event.error.ErrorTypeErrorHandlerWrapper; |
39 | 31 |
import eu.etaxonomy.cdm.vaadin.event.error.PermissionDeniedErrorHandler; |
40 | 32 |
import eu.etaxonomy.cdm.vaadin.toolbar.Toolbar; |
41 |
import eu.etaxonomy.cdm.vaadin.view.RedirectToLoginView; |
|
42 | 33 |
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor; |
43 | 34 |
import eu.etaxonomy.cdm.vaadin.view.registration.DashBoardView; |
44 | 35 |
import eu.etaxonomy.cdm.vaadin.view.registration.ListView; |
... | ... | |
46 | 37 |
import eu.etaxonomy.cdm.vaadin.view.registration.StartRegistrationViewBean; |
47 | 38 |
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor; |
48 | 39 |
import eu.etaxonomy.vaadin.ui.MainMenu; |
49 |
import eu.etaxonomy.vaadin.ui.UIInitializedEvent; |
|
50 |
import eu.etaxonomy.vaadin.ui.navigation.NavigationManagerBean; |
|
51 | 40 |
import eu.etaxonomy.vaadin.ui.view.ToolbarDisplay; |
52 | 41 |
|
53 | 42 |
/** |
... | ... | |
62 | 51 |
@Widgetset("eu.etaxonomy.cdm.vaadin.AppWidgetSet") |
63 | 52 |
// @PreserveOnRefresh |
64 | 53 |
// @Push |
65 |
public class RegistrationUI extends UI implements PopupEditorDefaultStatusMessageSource { |
|
54 |
public class RegistrationUI extends AbstractUI implements PopupEditorDefaultStatusMessageSource {
|
|
66 | 55 |
|
67 | 56 |
private static final long serialVersionUID = -8626236111335323691L; |
68 | 57 |
|
... | ... | |
71 | 60 |
private ViewDisplay viewDisplay; |
72 | 61 |
|
73 | 62 |
//---- pull into abstract super class ? --------- |
74 |
@Autowired |
|
75 |
SpringViewProvider viewProvider; |
|
76 |
|
|
77 |
@Autowired |
|
78 |
NavigationManagerBean navigator; |
|
79 |
|
|
80 |
@Autowired(required = false) |
|
81 |
EntityCacheDebugger entityCacheDebugger = null; |
|
82 |
|
|
83 |
@Autowired |
|
84 |
UIEventBus uiEventBus; |
|
85 |
|
|
86 | 63 |
|
87 | 64 |
@Autowired |
88 | 65 |
private MainMenu mainMenu; |
... | ... | |
91 | 68 |
@Qualifier("registrationToolbar") |
92 | 69 |
private Toolbar toolbar; |
93 | 70 |
|
71 |
@Autowired(required = false) |
|
72 |
EntityCacheDebugger entityCacheDebugger = null; |
|
73 |
|
|
94 | 74 |
//--------------------------------------------- |
95 | 75 |
|
96 |
public static final String INITIAL_VIEW = DashBoardView.NAME;
|
|
76 |
public static final String BRAND_NAME = "phycobank";
|
|
97 | 77 |
|
98 |
protected void configureAccessDeniedView() { |
|
99 |
viewProvider.setAccessDeniedViewClass(RedirectToLoginView.class); |
|
100 |
} |
|
78 |
public static final String INITIAL_VIEW = DashBoardView.NAME; |
|
101 | 79 |
|
102 |
/** |
|
103 |
* @return |
|
104 |
*/ |
|
105 |
private String pageFragmentAsState() { |
|
106 |
Page page = Page.getCurrent(); |
|
107 |
String fragment = page.getUriFragment(); |
|
108 |
String state = null; |
|
109 |
if(fragment != null && fragment.startsWith("!")){ |
|
110 |
state = fragment.substring(1, fragment.length()); |
|
111 |
} |
|
112 |
return state; |
|
113 |
} |
|
114 | 80 |
|
115 | 81 |
//--------------------------------------------- |
116 | 82 |
|
... | ... | |
121 | 87 |
@Override |
122 | 88 |
protected void init(VaadinRequest request) { |
123 | 89 |
|
124 |
DelegatingErrorHandler delegatingErrorHander = new DelegatingErrorHandler(); |
|
125 |
WindowErrorHandler errorHandler = new WindowErrorHandler(this, RegistrationUIDefaults.ERROR_CONTACT_MESSAGE_LINE + "</br></br>" |
|
126 |
+ "<i>To help analyzing the problem please describe your actions that lead to this error and provide the error details from below in your email. " |
|
127 |
+ "You also might want to add a sreenshot of the browser page in error.</i>"); |
|
128 |
delegatingErrorHander.registerHandler(new ErrorTypeErrorHandlerWrapper<PermissionDeniedException>(PermissionDeniedException.class, new PermissionDeniedErrorHandler(this))); |
|
129 |
delegatingErrorHander.registerHandler(new ErrorTypeErrorHandlerWrapper<Exception>(Exception.class, errorHandler)); |
|
130 |
setErrorHandler(delegatingErrorHander); |
|
131 |
VaadinSession.getCurrent().setErrorHandler(delegatingErrorHander); |
|
90 |
super.init(request); |
|
132 | 91 |
|
133 |
navigator.setViewDisplay(viewDisplay); |
|
134 |
configureAccessDeniedView(); |
|
92 |
if(entityCacheDebugger != null){ |
|
93 |
addShortcutListener(entityCacheDebugger.getShortcutListener()); |
|
94 |
} |
|
95 |
//navigate to initial view |
|
96 |
// String state = pageFragmentAsState(); |
|
135 | 97 |
|
136 |
addStyleName(ValoTheme.UI_WITH_MENU); |
|
137 |
Responsive.makeResponsive(this); |
|
138 | 98 |
|
139 |
setContent((Component) viewDisplay); |
|
99 |
// if(state == null){ |
|
100 |
// // the case when state != null is handled in the UI base class |
|
101 |
// eventBus.publishEvent(new NavigationEvent(INITIAL_VIEW)); |
|
102 |
// } |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
protected ViewDisplay getViewDisplay() { |
|
107 |
return viewDisplay; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
protected void initContent() { |
|
140 | 112 |
Label phycoBankLogo = new Label("PhycoBank"); |
141 | 113 |
phycoBankLogo.addStyleName("phycobank-green"); |
142 | 114 |
phycoBankLogo.addStyleName(ValoTheme.LABEL_HUGE); |
... | ... | |
146 | 118 |
mainMenu.addMenuItem("Continue", FontAwesome.ARROW_RIGHT, ListViewBean.NAME + "/" + ListView.Mode.inProgress.name()); |
147 | 119 |
mainMenu.addMenuItem("List", FontAwesome.TASKS, ListViewBean.NAME + "/" + ListView.Mode.all.name()); |
148 | 120 |
|
149 |
if(ToolbarDisplay.class.isAssignableFrom(viewDisplay.getClass())){ |
|
150 |
((ToolbarDisplay)viewDisplay).setToolbar(toolbar); |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
uiEventBus.publish(this, new UIInitializedEvent()); |
|
155 |
|
|
156 |
String brand = "phycobank"; |
|
157 |
//TODO create annotation: |
|
158 |
// @Styles(files={""}, branding="brand") |
|
159 |
// |
|
160 |
// the branding can either be specified or can be read from the properties file in .cdmLibrary/remote-webapp/{instance-name}-app.properties |
|
161 |
// See CdmUtils for appropriate methods to access this folder |
|
162 |
// the 'vaadin://' protocol refers to the VAADIN folder |
|
163 |
Resource registryCssFile = new ExternalResource("vaadin://branding/" + brand + "/css/branding.css"); |
|
164 |
Page.getCurrent().getStyles().add(registryCssFile); |
|
165 |
|
|
166 |
navigator.setDefaultViewName(INITIAL_VIEW); |
|
167 |
|
|
168 |
if(entityCacheDebugger != null){ |
|
169 |
addShortcutListener(entityCacheDebugger.getShortcutListener()); |
|
121 |
if(ToolbarDisplay.class.isAssignableFrom(getViewDisplay().getClass())){ |
|
122 |
((ToolbarDisplay)getViewDisplay()).setToolbar(toolbar); |
|
170 | 123 |
} |
171 |
//navigate to initial view |
|
172 |
// String state = pageFragmentAsState(); |
|
173 |
|
|
124 |
} |
|
174 | 125 |
|
175 |
// if(state == null){ |
|
176 |
// // the case when state != null is handled in the UI base class |
|
177 |
// eventBus.publishEvent(new NavigationEvent(INITIAL_VIEW)); |
|
178 |
// } |
|
126 |
@Override |
|
127 |
protected void registerErrorHandlers() { |
|
128 |
DelegatingErrorHandler delegatingErrorHander = new DelegatingErrorHandler(); |
|
129 |
WindowErrorHandler errorHandler = new WindowErrorHandler(this, RegistrationUIDefaults.ERROR_CONTACT_MESSAGE_LINE + "</br></br>" |
|
130 |
+ "<i>To help analyzing the problem please describe your actions that lead to this error and provide the error details from below in your email. " |
|
131 |
+ "You also might want to add a sreenshot of the browser page in error.</i>"); |
|
132 |
delegatingErrorHander.registerHandler(new ErrorTypeErrorHandlerWrapper<PermissionDeniedException>(PermissionDeniedException.class, new PermissionDeniedErrorHandler(this))); |
|
133 |
delegatingErrorHander.registerHandler(new ErrorTypeErrorHandlerWrapper<Exception>(Exception.class, errorHandler)); |
|
134 |
setErrorHandler(delegatingErrorHander); |
|
135 |
VaadinSession.getCurrent().setErrorHandler(delegatingErrorHander); |
|
179 | 136 |
} |
180 | 137 |
|
181 | 138 |
@Override |
Also available in: Unified diff
ref #8503 creating abstract base UI class