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