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.application;
7   
8   import java.util.List;
9   
10  import org.apache.commons.logging.Log;
11  import org.apache.commons.logging.LogFactory;
12  
13  import thinwire.ui.Frame;
14  import thinwire.ui.Menu;
15  import thinwire.ui.Panel;
16  import thinwire.ui.layout.TableLayout;
17  
18  import com.hack23.cia.model.application.dto.common.ApplicationProperties;
19  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
20  import com.hack23.cia.model.application.impl.common.Agency;
21  import com.hack23.cia.model.application.impl.common.Portal;
22  import com.hack23.cia.model.application.impl.common.UserSession;
23  import com.hack23.cia.model.application.impl.user.UserActionEvent;
24  import com.hack23.cia.model.sweden.impl.CommitteeReport;
25  import com.hack23.cia.model.sweden.impl.PoliticalParty;
26  import com.hack23.cia.web.action.application.ApplicationAction;
27  import com.hack23.cia.web.action.user.UserAction;
28  import com.hack23.cia.web.common.ImageConstants;
29  import com.hack23.cia.web.viewfactory.api.application.ApplicationModelAndView;
30  import com.hack23.cia.web.viewfactory.impl.common.AbstractViewFactoryImpl;
31  import com.hack23.cia.web.viewfactory.impl.user.MenuFactory;
32  import com.hack23.cia.web.views.common.ActiveUserView;
33  import com.hack23.cia.web.views.user.ActionBarPanel;
34  import com.hack23.cia.web.views.user.PositionBarPanel;
35  import com.hack23.cia.web.views.user.WelcomePanel;
36  
37  /***
38   * The Class ApplicationViewFactoryImpl.
39   */
40  public class ApplicationViewFactoryImpl extends
41          AbstractViewFactoryImpl<ApplicationModelAndView> {
42  
43  
44      /*** The Constant LOGGER. */
45      private static final Log LOGGER = LogFactory
46              .getLog(ApplicationViewFactoryImpl.class);
47  
48      /*** The menufactory. */
49      private final MenuFactory menufactory;
50  
51      /*** The top number. */
52      private final int topNumber;
53  
54      /***
55       * Instantiates a new application view factory impl.
56       *
57       * @param menufactory the menufactory
58       * @param topNumber the top number
59       */
60      public ApplicationViewFactoryImpl(final MenuFactory menufactory,
61              final int topNumber) {
62          super();
63          this.menufactory = menufactory;
64          this.topNumber = topNumber;
65      }
66  
67      /*
68       * (non-Javadoc)
69       * 
70       * @see
71       * com.hack23.cia.web.controller.ViewFactoryService#createFrame(thinwire
72       * .ui.Frame)
73       */
74      /***
75       * Creates the frame.
76       *
77       * @param frame the frame
78       * @param userSessionDTO the user session dto
79       * @param agency the agency
80       * @param committeeReports the committee reports
81       * @param politicalParties the political parties
82       */
83      public final void createFrame(final Frame frame,
84              final UserSessionDTO userSessionDTO, final Agency agency,
85              final List<CommitteeReport> committeeReports,final List<PoliticalParty> politicalParties) {
86      	LOGGER.info("createFrame " + userSessionDTO.getUserSession().getUser().getUserRole());
87          final UserSession userSession = userSessionDTO.getUserSession();
88          final ApplicationProperties applicationProperties = new ApplicationProperties();
89          final Portal portal = userSession.getPortal();
90          String portalName = null;
91          String portalTitleDescription = null;
92  
93          if (portal != null) {
94              portalName = portal.getName();
95              portalTitleDescription = portal.getTitleDescription();
96          } else {
97              portalName = applicationProperties.getName();
98              portalTitleDescription = userSessionDTO
99                      .getLanguageResource(Agency.LanguageContentKey.TRACKING_POLITICIANS_LIKE_BUGS);
100             final Portal defaultPortal = new Portal();
101             defaultPortal.setName(portalName);
102             defaultPortal.setTitleDescription(portalTitleDescription);
103         }
104 
105         frame.setTitle(portalName + " -::- " //$NON-NLS-1$
106                 + portalTitleDescription + " " + applicationProperties.getVersion());
107         frame.setLayout(new TableLayout(new double[][] { { 0.15, 0.85 }, // Column
108                 // Widths
109                 { 0.08, 0.92 } }, // Row Heights
110                 1, // Margin around edge of container
111                 0)); // Spacing between cells
112 
113         final Menu menu = this.menufactory.createApplicationMenu(userSessionDTO,politicalParties,
114                 topNumber);
115         frame.setMenu(menu);
116 
117         final PositionBarPanel positionBarPanel = new PositionBarPanel(userSessionDTO);
118         positionBarPanel.setLimit("0,0,2,1"); //$NON-NLS-1$
119         frame.getChildren().add(positionBarPanel);
120         ActiveUserView.getCurrentPositionAndHistoryView().set(positionBarPanel);
121 
122         final Panel actionBarPanel = new ActionBarPanel(userSessionDTO,ImageConstants.HOME_ICON,
123                 userSessionDTO.getLanguageResource(Agency.LanguageContentKey.HOME_PAGE),
124                 new UserAction(UserActionEvent.Operation.StartPage),
125                 committeeReports);
126         actionBarPanel.setLimit("0,1,1,1"); //$NON-NLS-1$
127         frame.getChildren().add(actionBarPanel);
128 
129         final Panel contentView = new WelcomePanel(userSessionDTO);
130         contentView.setLimit("1,1,1,1"); //$NON-NLS-1$
131         frame.getChildren().add(contentView);
132 
133         ActiveUserView.getActiveContentView().set(contentView);
134     }
135 
136     /*
137      * (non-Javadoc)
138      * 
139      * @seecom.hack23.cia.web.viewfactory.impl.common.ViewFactory#
140      * getSupportedModelAndView()
141      */
142     @SuppressWarnings("unchecked")
143     @Override
144     public final Class getSupportedModelAndView() {
145         return ApplicationModelAndView.class;
146     }
147 
148     /*
149      * (non-Javadoc)
150      * 
151      * @seecom.hack23.cia.web.viewfactory.impl.common.AbstractViewFactoryImpl#
152      * processSpecificView
153      * (com.hack23.cia.web.viewfactory.api.common.AbstractModelAndView)
154      */
155     @Override
156     public final void processSpecificView(
157             final ApplicationModelAndView modelAndView) {
158         final ApplicationAction action = (ApplicationAction) modelAndView
159                 .getControllerAction();
160 
161         final ApplicationModelAndView newApplicationInstanceModelAndView = modelAndView;
162         createFrame(action.getFrame(), newApplicationInstanceModelAndView
163                 .getUserSessionDTO(), newApplicationInstanceModelAndView
164                 .getAgency(), newApplicationInstanceModelAndView
165                 .getCommitteeReports(),newApplicationInstanceModelAndView.getPoliticalParties());
166     }
167 
168 }