View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.web.viewfactory.impl.user;
7   
8   import org.apache.commons.logging.Log;
9   import org.apache.commons.logging.LogFactory;
10  
11  import com.hack23.cia.web.viewfactory.api.user.UserModelAndView;
12  import com.hack23.cia.web.views.common.ActiveUserView;
13  import com.hack23.cia.web.views.user.LoginPanel;
14  import com.hack23.cia.web.views.user.WelcomePanel;
15  
16  /***
17   * The Class UserViewFactoryImpl.
18   */
19  public class UserViewFactoryImpl extends
20          AbstractUserViewFactoryImpl<UserModelAndView> {
21  
22      /*** The Constant LOGGER. */
23      private static final Log LOGGER = LogFactory
24              .getLog(UserViewFactoryImpl.class);
25  
26      /*** The menu factory. */
27      private final MenuFactory menuFactory;
28  
29      /*** The top number. */
30      private final int topNumber;
31  
32      /***
33       * Instantiates a new user view factory impl.
34       *
35       * @param menuFactory the menu factory
36       * @param topNumber the top number
37       */
38      public UserViewFactoryImpl(final MenuFactory menuFactory,
39              final int topNumber) {
40          super();
41          this.menuFactory = menuFactory;
42          this.topNumber = topNumber;
43      }
44  
45      /*
46       * (non-Javadoc)
47       * 
48       * @seecom.hack23.cia.web.viewfactory.impl.common.ViewFactory#
49       * getSupportedModelAndView()
50       */
51      @SuppressWarnings("unchecked")
52      @Override
53      public final Class getSupportedModelAndView() {
54          return UserModelAndView.class;
55      }
56  
57      /*
58       * (non-Javadoc)
59       * 
60       * @seecom.hack23.cia.web.viewfactory.impl.common.AbstractViewFactoryImpl#
61       * processSpecificView
62       * (com.hack23.cia.web.viewfactory.api.common.AbstractModelAndView)
63       */
64      @Override
65      public final void processSpecificView(final UserModelAndView modelAndView) {
66          switch (modelAndView.getUserViewSpecification()) {
67          case WelcomePageView:
68              ActiveUserView.changeContentView(new WelcomePanel(modelAndView.getUserSessionDTO()));
69              return;
70          case LoginView: 
71              ActiveUserView.changeContentView(new LoginPanel(modelAndView.getUserSessionDTO()));
72              return;           
73          case LogoutView:
74              ActiveUserView.changeContentView(new WelcomePanel(modelAndView.getUserSessionDTO()));
75              ActiveUserView.changeActiveMenu(menuFactory.createApplicationMenu(
76                      modelAndView.getUserSessionDTO(),modelAndView.getPoliticalParties(), topNumber));
77              return;
78          case UserHomeView:
79              ActiveUserView.changeContentView(new WelcomePanel(modelAndView.getUserSessionDTO()));
80              ActiveUserView.changeActiveMenu(menuFactory.createApplicationMenu(
81                      modelAndView.getUserSessionDTO(),modelAndView.getPoliticalParties(), topNumber));
82              return;
83          default:
84              LOGGER
85                      .warn("Not implemented :" + modelAndView.getUserViewSpecification()); //$NON-NLS-1$
86              return;
87          }
88      }
89  }