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.Label;
9   import thinwire.ui.TabSheet;
10  import thinwire.ui.TextField;
11  import thinwire.ui.event.ActionEvent;
12  import thinwire.ui.event.ActionListener;
13  import thinwire.ui.layout.TableLayout;
14  
15  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
16  import com.hack23.cia.model.application.impl.admin.LanguageContentActionEvent;
17  import com.hack23.cia.model.application.impl.common.Agency;
18  import com.hack23.cia.model.application.impl.common.LanguageContent;
19  import com.hack23.cia.web.action.admin.LanguageContentAction;
20  import com.hack23.cia.web.common.BeanLocator;
21  
22  /***
23   * The Class ConfigureLanguageContentPanel.
24   */
25  public class ConfigureLanguageContentPanel extends AbstractAdminPanel {
26  
27      /*** The cancel language content action listener. */
28      private final ActionListener cancelLanguageContentActionListener = new ActionListener() {
29          @Override
30  		public void actionPerformed(final ActionEvent ev) {
31              contentPropertyNameField.setText(languageContent.getContentPropertyName());
32              contentField.setText(languageContent.getContentPropertyName());
33          }
34      };
35  
36  
37      /*** The content field. */
38      private final TextField contentField = new TextField();
39  
40  
41      /*** The content property name field. */
42      private final TextField contentPropertyNameField = new TextField();
43  
44      /*** The delete language content action listener. */
45      private final ActionListener deleteLanguageContentActionListener = new ActionListener() {
46          @Override
47  		public void actionPerformed(final ActionEvent ev) {
48              ((Button) ev.getSource()).setUserObject(new LanguageContentAction(
49                      LanguageContentActionEvent.Operation.Delete,getAgency(),languageContent));
50              BeanLocator.getApplicationActionListener().actionPerformed(ev);
51          }
52      };
53  
54      /*** The language content. */
55      private final LanguageContent languageContent;
56  
57  
58  
59      /*** The ok language content action listener. */
60      private final ActionListener okLanguageContentActionListener = new ActionListener() {
61          @Override
62  		public void actionPerformed(final ActionEvent ev) {
63              languageContent.setContentPropertyName(contentPropertyNameField.getText());
64              languageContent.setContent(contentField.getText());
65              ((Button) ev.getSource()).setUserObject(new LanguageContentAction(
66                      LanguageContentActionEvent.Operation.Update,getAgency(),languageContent));
67              BeanLocator.getApplicationActionListener().actionPerformed(ev);
68          }
69      };
70  
71      /***
72       * Instantiates a new configure language content panel.
73       *
74       * @param userSessionDTO the user session dto
75       * @param agency the agency
76       * @param languageContent the language content
77       */
78      public ConfigureLanguageContentPanel(final UserSessionDTO userSessionDTO,final Agency agency, final LanguageContent languageContent) {
79          super(userSessionDTO,agency);
80          this.languageContent = new LanguageContent();
81          this.languageContent.setId(languageContent.getId());
82          this.languageContent.setContentPropertyName(languageContent.getContentPropertyName());
83          this.languageContent.setContent(languageContent.getContent());
84          this.languageContent.setLanguage(languageContent.getLanguage());
85          final TabSheet gridBoxTabSheet = createLanguageContentTabSheet(languageContent);
86          getTabFolder().getChildren().add(gridBoxTabSheet);
87          getTabFolder().setCurrentIndex(1);
88  
89      }
90  
91      /***
92       * Creates the language content tab sheet.
93       *
94       * @param languageContent the language content
95       * @return the tab sheet
96       */
97      private TabSheet createLanguageContentTabSheet(final LanguageContent languageContent) {
98          final TabSheet tabSheet = new TabSheet();
99          tabSheet.setText(getUserSessionDTO()
100                 .getLanguageResource(Agency.LanguageContentKey.CONFIGURE_LANGUAGE));
101         tabSheet.setLayout(new TableLayout(new double[][] { { 0, 0, 0 }, // Column
102                 // Widths
103                 { 0, 0, 0, 0, 0 } }, // Row Heights
104                 10, // Margin around edge of container
105                 5));
106 
107         final Label languageContentKeyLabel = new Label(getUserSessionDTO()
108                 .getLanguageResource(Agency.LanguageContentKey.LANGUAGE_CONTENT_KEY));
109         languageContentKeyLabel.setLimit("0,0"); //$NON-NLS-1$
110         tabSheet.getChildren().add(languageContentKeyLabel);
111 
112         contentPropertyNameField.setLimit("1,0,2,1"); //$NON-NLS-1$
113         contentPropertyNameField.setText(languageContent.getContentPropertyName());
114         tabSheet.getChildren().add(contentPropertyNameField);
115 
116         final Label languageContentLabel = new Label(getUserSessionDTO()
117                 .getLanguageResource(Agency.LanguageContentKey.LANGUAGE_CONTENT_VALUE));
118         languageContentLabel.setLimit("0,1"); //$NON-NLS-1$
119         tabSheet.getChildren().add(languageContentLabel);
120 
121         contentField.setLimit("1,1,2,1"); //$NON-NLS-1$
122         contentField.setText(languageContent.getContent());
123         tabSheet.getChildren().add(contentField);
124 
125         final Button deleteButton = new Button(getUserSessionDTO()
126                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_DELETE));
127         deleteButton.setLimit("0,3"); //$NON-NLS-1$
128         deleteButton.addActionListener(ACTION_CLICK,
129                 deleteLanguageContentActionListener);
130         tabSheet.getChildren().add(deleteButton);
131 
132         final Button cancelButton = new Button(getUserSessionDTO()
133                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_CANCEL));
134         cancelButton.setLimit("1,3"); //$NON-NLS-1$
135         cancelButton.addActionListener(ACTION_CLICK,
136                 cancelLanguageContentActionListener);
137         tabSheet.getChildren().add(cancelButton);
138 
139         final Button okButton = new Button(getUserSessionDTO()
140                 .getLanguageResource(Agency.LanguageContentKey.BUTTON_OK));
141         okButton.setLimit("2,3"); //$NON-NLS-1$
142         okButton.addActionListener(ACTION_CLICK, okLanguageContentActionListener);
143         tabSheet.getChildren().add(okButton);
144         return tabSheet;
145     }
146 
147 }