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   package com.hack23.cia.web.views.admin;
6   
7   import thinwire.ui.Button;
8   import thinwire.ui.GridBox;
9   import thinwire.ui.Label;
10  import thinwire.ui.TabSheet;
11  import thinwire.ui.TextField;
12  import thinwire.ui.event.ActionEvent;
13  import thinwire.ui.event.ActionListener;
14  import thinwire.ui.layout.TableLayout;
15  
16  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
17  import com.hack23.cia.model.application.impl.admin.LanguageAgencyActionEvent;
18  import com.hack23.cia.model.application.impl.common.Agency;
19  import com.hack23.cia.model.application.impl.common.Language;
20  import com.hack23.cia.web.action.admin.LanguageAgencyAction;
21  import com.hack23.cia.web.common.BeanLocator;
22  import com.hack23.cia.web.views.components.gridboxes.LanguageContentGridBox;
23  
24  /***
25   * The Class ConfigureLanguagePanel.
26   */
27  public class ConfigureLanguagePanel extends AbstractAdminPanel {
28  
29      /*** The active by default field. */
30      private final TextField activeByDefaultField = new TextField();
31  
32  
33      /*** The cancel language action listener. */
34      private final ActionListener cancelLanguageActionListener = new ActionListener() {
35          @Override
36  		public void actionPerformed(final ActionEvent ev) {
37              languageNameField.setText(language.getName());
38              languageShortCodeField.setText(language.getShortCode());
39              activeByDefaultField.setText("" + language.getActiveByDefault());
40              usageOrderField.setText("" +language.getUsageOrder());
41          }
42      };
43  
44  
45      /*** The delete language action listener. */
46      private final ActionListener deleteLanguageActionListener = new ActionListener() {
47          @Override
48  		public void actionPerformed(final ActionEvent ev) {
49              ((Button) ev.getSource()).setUserObject(new LanguageAgencyAction(
50                      LanguageAgencyActionEvent.Operation.Delete, getAgency(),
51                      language));
52              BeanLocator.getApplicationActionListener().actionPerformed(ev);
53          }
54      };
55  
56      /*** The language. */
57      private final Language language;
58  
59      /*** The language name field. */
60      private final TextField languageNameField = new TextField();
61  
62      /*** The language short code field. */
63      private final TextField languageShortCodeField = new TextField();
64  
65      /*** The ok language action listener. */
66      private final ActionListener okLanguageActionListener = new ActionListener() {
67          @Override
68  		public void actionPerformed(final ActionEvent ev) {
69              language.setName(languageNameField.getText());
70              language.setShortCode(languageShortCodeField.getText());
71              language.setUsageOrder(Integer.valueOf(usageOrderField.getText()));
72              language.setActiveByDefault(Boolean.valueOf(activeByDefaultField.getText()));
73              ((Button) ev.getSource()).setUserObject(new LanguageAgencyAction(
74                      LanguageAgencyActionEvent.Operation.Update, getAgency(),
75                      language));
76              BeanLocator.getApplicationActionListener().actionPerformed(ev);
77          }
78      };
79  
80  
81      /*** The usage order field. */
82      private final TextField usageOrderField = new TextField();
83  
84      /***
85       * Instantiates a new configure language panel.
86       *
87       * @param userSessionDTO the user session dto
88       * @param agency the agency
89       * @param language the language
90       */
91      public ConfigureLanguagePanel(final UserSessionDTO userSessionDTO,final Agency agency, final Language language) {
92          super(userSessionDTO,agency);
93          this.language = new Language();
94          this.language.setId(language.getId());
95          this.language.setShortCode(language.getShortCode());
96          this.language.setName(language.getName());
97          this.language.setActiveByDefault(language.getActiveByDefault());
98          this.language.setUsageOrder(language.getUsageOrder());
99          final TabSheet gridBoxTabSheet = createLanguageTabSheet(agency,language);
100         getTabFolder().getChildren().add(gridBoxTabSheet);
101         getTabFolder().setCurrentIndex(1);
102 
103     }
104 
105     /***
106      * Creates the language tab sheet.
107      *
108      * @param agency the agency
109      * @param language the language
110      * @return the tab sheet
111      */
112     private TabSheet createLanguageTabSheet(final Agency agency,final Language language) {
113         final TabSheet tabSheet = new TabSheet();
114         tabSheet.setText(getUserSessionDTO()
115                 .getLanguageResource(Agency.LanguageContentKey.CONFIGURE_LANGUAGE));
116         tabSheet.setLayout(new TableLayout(new double[][] { { 0, 0, 0 }, // Column
117                 // Widths
118                 { 0, 0, 0, 0, 0,0,0,0,0,0 } }, // Row Heights
119                 10, // Margin around edge of container
120                 5));
121 
122         final Label nameLabel = new Label(getUserSessionDTO()
123                 .getLanguageResource(Agency.LanguageContentKey.NAME));
124         nameLabel.setLimit("0,0"); //$NON-NLS-1$
125         tabSheet.getChildren().add(nameLabel);
126 
127         languageNameField.setLimit("1,0,2,1"); //$NON-NLS-1$
128         languageNameField.setText(language.getName());
129         tabSheet.getChildren().add(languageNameField);
130 
131         final Label languageShortCodeLabel = new Label(getUserSessionDTO()
132                 .getLanguageResource(Agency.LanguageContentKey.LANGUAGE_SHORTCODE));
133         languageShortCodeLabel.setLimit("0,1"); //$NON-NLS-1$
134         tabSheet.getChildren().add(languageShortCodeLabel);
135 
136         languageShortCodeField.setLimit("1,1,2,1"); //$NON-NLS-1$
137         languageShortCodeField.setText(language.getShortCode());
138         tabSheet.getChildren().add(languageShortCodeField);
139         
140         final Label activeByDefaultLabel = new Label(getUserSessionDTO()
141                 .getLanguageResource(Agency.LanguageContentKey.ACTIVE_BY_DEFAULT));
142         activeByDefaultLabel.setLimit("0,2"); //$NON-NLS-1$
143         tabSheet.getChildren().add(activeByDefaultLabel);
144 
145         activeByDefaultField.setLimit("1,2,2,1"); //$NON-NLS-1$
146         activeByDefaultField.setText("" + language.getActiveByDefault());
147         tabSheet.getChildren().add(activeByDefaultField);
148 
149         final Label usageOrderLabel = new Label(getUserSessionDTO()
150                 .getLanguageResource(Agency.LanguageContentKey.USAGE_ORDER));
151         usageOrderLabel.setLimit("0,3"); //$NON-NLS-1$
152         tabSheet.getChildren().add(usageOrderLabel);
153 
154         usageOrderField.setLimit("1,3,2,1"); //$NON-NLS-1$
155         usageOrderField.setText("" + language.getUsageOrder());
156         tabSheet.getChildren().add(usageOrderField);
157         
158         final GridBox portalGridBox = new LanguageContentGridBox(getUserSessionDTO(),agency,agency.getLanguageContentByLanguage(language));
159         portalGridBox.setLimit("0,4,3,3"); //$NON-NLS-1$
160         tabSheet.getChildren().add(portalGridBox);
161         
162         
163         final Button deleteButton = new Button(getUserSessionDTO()
164                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_DELETE));
165         deleteButton.setLimit("0,7"); //$NON-NLS-1$
166         deleteButton.addActionListener(ACTION_CLICK,
167                 deleteLanguageActionListener);
168         tabSheet.getChildren().add(deleteButton);
169 
170         final Button cancelButton = new Button(getUserSessionDTO()
171                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_CANCEL));
172         cancelButton.setLimit("1,7"); //$NON-NLS-1$
173         cancelButton.addActionListener(ACTION_CLICK,
174                 cancelLanguageActionListener);
175         tabSheet.getChildren().add(cancelButton);
176 
177         final Button okButton = new Button(getUserSessionDTO()
178                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_OK));
179         okButton.setLimit("2,7"); //$NON-NLS-1$
180         okButton.addActionListener(ACTION_CLICK, okLanguageActionListener);
181         tabSheet.getChildren().add(okButton);
182         return tabSheet;
183     }
184 
185 }