Project

General

Profile

« Previous | Next » 

Revision 7f6f8587

Added by Andreas Kohlbecker over 2 years ago

ref #9884 refactoring UI enablement:

  • ui beans never are null
  • disabled beans have state.enabled=false
  • uis throw UIDisabledException
  • ErrorView to show UIDisabledException
  • UIDisabledErrorHandle delegates to the ErrorView

View differences:

src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
148 148
    @WebServlet(name="CdmVaadinServlet", value = {"/app/*", "/VAADIN/*"}, asyncSupported = true)
149 149
    public static class CdmVaadinServlet extends SpringVaadinServlet {
150 150

  
151
        private static final long serialVersionUID = -2615042297393028775L;
151
        private static final long serialVersionUID = 1L;
152 152

  
153
        /**
154
         *
155
        @SuppressWarnings("serial")
153
        /*
156 154
        @Override
157 155
        protected void servletInitialized() throws ServletException {
158
            logger.debug("SpringVaadinServlet initialized");
159 156

  
160
        }
157
            super.servletInitialized();
158

  
161 159
            getService().addSessionInitListener(new SessionInitListener() {
162 160

  
161
                private static final long serialVersionUID = 1L;
162

  
163 163
                @Override
164 164
                public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
165 165
                    VaadinSession session = sessionInitEvent.getSession();
166 166
                    session.setErrorHandler(new DefaultErrorHandler(){
167 167

  
168
                        private static final long serialVersionUID = 1L;
169

  
168 170
                        @Override
169 171
                        public void error(ErrorEvent errorEvent) {
170
                            // ...
172
                            UIDisabledException uiDisbledException = findUIDisabledException(errorEvent.getThrowable());
173
                            if(uiDisbledException != null) {
174
                                logger.error("################## > UIDisabledException");
175
                                //throw uiDisbledException ;
176
                                doDefault(errorEvent);
177
                            } else {
178
                                doDefault(errorEvent);
179
                            }
180
                        }
181

  
182
                        private UIDisabledException findUIDisabledException(Throwable throwable) {
183
                            if(throwable instanceof UIDisabledException) {
184
                                return (UIDisabledException)throwable;
185
                            } else {
186
                                if(throwable.getCause() == null) {
187
                                    return null;
188
                                } else {
189
                                    return findUIDisabledException(throwable.getCause());
190
                                }
191
                            }
171 192
                        }
172 193

  
173 194
                    });
174
                    ).getServiceRegistry().getService
175 195

  
176 196
                }});
177 197

  
198
                logger.debug("SpringVaadinServlet initialized");
178 199
        }
179
         */
180

  
200
        */
181 201
    }
182 202

  
183 203
    public CdmVaadinConfiguration() {
......
187 207
    @Bean
188 208
    @UIScope
189 209
    public ConceptRelationshipUI conceptRelationshipUI() {
190
        if(isUIEnabled(ConceptRelationshipUI.class)){
191
            return new ConceptRelationshipUI();
192
        }
193
        return null;
210
        return applyEnableConfig(new ConceptRelationshipUI());
194 211
    }
195 212

  
196 213
    @Bean
197 214
    @UIScope
198 215
    public RegistrationUI registrationUI() {
199
        if(isUIEnabled(RegistrationUI.class)){
200
            registerRegistrationUiHibernateEventListeners();
201
            return new RegistrationUI();
202
        }
203
        return null;
216
        return applyEnableConfig(new RegistrationUI());
204 217
    }
205 218

  
206 219
    @Bean
207 220
    @UIScope
208
    public UserAccountSelfManagementUI passwordResetUI() {
209
        if(isUIEnabled(UserAccountSelfManagementUI.class)){
210
            registerRegistrationUiHibernateEventListeners();
211
            return new UserAccountSelfManagementUI();
212
        }
213
        return null;
221
    public UserAccountSelfManagementUI userAccountSelfManagementUI() {
222
        return applyEnableConfig(new UserAccountSelfManagementUI());
223
    }
224

  
225
    @Bean
226
    @UIScope
227
    public DistributionStatusUI distributionStatusUI() {
228
        return applyEnableConfig( new DistributionStatusUI());
229
    }
230

  
231
    @Bean
232
    @UIScope
233
    public StatusEditorUI statusEditorUI() {
234
        return applyEnableConfig(new StatusEditorUI());
214 235
    }
215 236

  
216 237
    /**
......
261 282
        return minter;
262 283
    }
263 284

  
264
    @Bean
265
    @UIScope
266
    public DistributionStatusUI distributionStatusUI() {
267
        if(isUIEnabled(DistributionStatusUI.class)){
268
            return new DistributionStatusUI();
269
        }
270
        return null;
271
    }
272

  
273
    @Bean
274
    @UIScope
275
    public StatusEditorUI statusEditorUI() {
276
        if(isUIEnabled(StatusEditorUI.class)){
277
            return new StatusEditorUI();
278
        }
279
        return null;
280
    }
281

  
282 285
    static final String PROPERTIES_FILE_NAME = "vaadin-apps";
283 286

  
284 287
    private Properties appProps = null;
......
338 341

  
339 342
    }
340 343

  
344
    private <T extends UI> T applyEnableConfig(T ui) {
345
        ui.setEnabled(isUIEnabled(ui.getClass()));
346
        return ui;
347
    }
341 348

  
342

  
343
    /**
344
     * {@inheritDoc}
345
     */
346 349
    @Override
347 350
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
348 351
        this.applicationContext = applicationContext;

Also available in: Unified diff